compiler-sfc.esm-browser.js 1.6 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833
  1. /**
  2. * @vue/compiler-sfc v3.5.32
  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. /** The number of characters that have been consumed in the current run. */
  2613. this.runConsumed = 0;
  2614. }
  2615. /** Resets the instance to make it reusable. */
  2616. startEntity(decodeMode) {
  2617. this.decodeMode = decodeMode;
  2618. this.state = EntityDecoderState.EntityStart;
  2619. this.result = 0;
  2620. this.treeIndex = 0;
  2621. this.excess = 1;
  2622. this.consumed = 1;
  2623. this.runConsumed = 0;
  2624. }
  2625. /**
  2626. * Write an entity to the decoder. This can be called multiple times with partial entities.
  2627. * If the entity is incomplete, the decoder will return -1.
  2628. *
  2629. * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
  2630. * entity is incomplete, and resume when the next string is written.
  2631. *
  2632. * @param input The string containing the entity (or a continuation of the entity).
  2633. * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
  2634. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2635. */
  2636. write(input, offset) {
  2637. switch (this.state) {
  2638. case EntityDecoderState.EntityStart: {
  2639. if (input.charCodeAt(offset) === CharCodes.NUM) {
  2640. this.state = EntityDecoderState.NumericStart;
  2641. this.consumed += 1;
  2642. return this.stateNumericStart(input, offset + 1);
  2643. }
  2644. this.state = EntityDecoderState.NamedEntity;
  2645. return this.stateNamedEntity(input, offset);
  2646. }
  2647. case EntityDecoderState.NumericStart: {
  2648. return this.stateNumericStart(input, offset);
  2649. }
  2650. case EntityDecoderState.NumericDecimal: {
  2651. return this.stateNumericDecimal(input, offset);
  2652. }
  2653. case EntityDecoderState.NumericHex: {
  2654. return this.stateNumericHex(input, offset);
  2655. }
  2656. case EntityDecoderState.NamedEntity: {
  2657. return this.stateNamedEntity(input, offset);
  2658. }
  2659. }
  2660. }
  2661. /**
  2662. * Switches between the numeric decimal and hexadecimal states.
  2663. *
  2664. * Equivalent to the `Numeric character reference state` in the HTML spec.
  2665. *
  2666. * @param input The string containing the entity (or a continuation of the entity).
  2667. * @param offset The current offset.
  2668. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2669. */
  2670. stateNumericStart(input, offset) {
  2671. if (offset >= input.length) {
  2672. return -1;
  2673. }
  2674. if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
  2675. this.state = EntityDecoderState.NumericHex;
  2676. this.consumed += 1;
  2677. return this.stateNumericHex(input, offset + 1);
  2678. }
  2679. this.state = EntityDecoderState.NumericDecimal;
  2680. return this.stateNumericDecimal(input, offset);
  2681. }
  2682. /**
  2683. * Parses a hexadecimal numeric entity.
  2684. *
  2685. * Equivalent to the `Hexademical character reference state` in the HTML spec.
  2686. *
  2687. * @param input The string containing the entity (or a continuation of the entity).
  2688. * @param offset The current offset.
  2689. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2690. */
  2691. stateNumericHex(input, offset) {
  2692. while (offset < input.length) {
  2693. const char = input.charCodeAt(offset);
  2694. if (isNumber$1(char) || isHexadecimalCharacter(char)) {
  2695. // Convert hex digit to value (0-15); 'a'/'A' -> 10.
  2696. const digit = char <= CharCodes.NINE
  2697. ? char - CharCodes.ZERO
  2698. : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
  2699. this.result = this.result * 16 + digit;
  2700. this.consumed++;
  2701. offset++;
  2702. }
  2703. else {
  2704. return this.emitNumericEntity(char, 3);
  2705. }
  2706. }
  2707. return -1; // Incomplete entity
  2708. }
  2709. /**
  2710. * Parses a decimal numeric entity.
  2711. *
  2712. * Equivalent to the `Decimal character reference state` in the HTML spec.
  2713. *
  2714. * @param input The string containing the entity (or a continuation of the entity).
  2715. * @param offset The current offset.
  2716. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2717. */
  2718. stateNumericDecimal(input, offset) {
  2719. while (offset < input.length) {
  2720. const char = input.charCodeAt(offset);
  2721. if (isNumber$1(char)) {
  2722. this.result = this.result * 10 + (char - CharCodes.ZERO);
  2723. this.consumed++;
  2724. offset++;
  2725. }
  2726. else {
  2727. return this.emitNumericEntity(char, 2);
  2728. }
  2729. }
  2730. return -1; // Incomplete entity
  2731. }
  2732. /**
  2733. * Validate and emit a numeric entity.
  2734. *
  2735. * Implements the logic from the `Hexademical character reference start
  2736. * state` and `Numeric character reference end state` in the HTML spec.
  2737. *
  2738. * @param lastCp The last code point of the entity. Used to see if the
  2739. * entity was terminated with a semicolon.
  2740. * @param expectedLength The minimum number of characters that should be
  2741. * consumed. Used to validate that at least one digit
  2742. * was consumed.
  2743. * @returns The number of characters that were consumed.
  2744. */
  2745. emitNumericEntity(lastCp, expectedLength) {
  2746. var _a;
  2747. // Ensure we consumed at least one digit.
  2748. if (this.consumed <= expectedLength) {
  2749. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  2750. return 0;
  2751. }
  2752. // Figure out if this is a legit end of the entity
  2753. if (lastCp === CharCodes.SEMI) {
  2754. this.consumed += 1;
  2755. }
  2756. else if (this.decodeMode === DecodingMode.Strict) {
  2757. return 0;
  2758. }
  2759. this.emitCodePoint(replaceCodePoint(this.result), this.consumed);
  2760. if (this.errors) {
  2761. if (lastCp !== CharCodes.SEMI) {
  2762. this.errors.missingSemicolonAfterCharacterReference();
  2763. }
  2764. this.errors.validateNumericCharacterReference(this.result);
  2765. }
  2766. return this.consumed;
  2767. }
  2768. /**
  2769. * Parses a named entity.
  2770. *
  2771. * Equivalent to the `Named character reference state` in the HTML spec.
  2772. *
  2773. * @param input The string containing the entity (or a continuation of the entity).
  2774. * @param offset The current offset.
  2775. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  2776. */
  2777. stateNamedEntity(input, offset) {
  2778. const { decodeTree } = this;
  2779. let current = decodeTree[this.treeIndex];
  2780. // The length is the number of bytes of the value, including the current byte.
  2781. let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  2782. while (offset < input.length) {
  2783. // Handle compact runs (possibly inline): valueLength == 0 and SEMI_REQUIRED bit set.
  2784. if (valueLength === 0 && (current & BinTrieFlags.FLAG13) !== 0) {
  2785. const runLength = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; /* 2..63 */
  2786. // If we are starting a run, check the first char.
  2787. if (this.runConsumed === 0) {
  2788. const firstChar = current & BinTrieFlags.JUMP_TABLE;
  2789. if (input.charCodeAt(offset) !== firstChar) {
  2790. return this.result === 0
  2791. ? 0
  2792. : this.emitNotTerminatedNamedEntity();
  2793. }
  2794. offset++;
  2795. this.excess++;
  2796. this.runConsumed++;
  2797. }
  2798. // Check remaining characters in the run.
  2799. while (this.runConsumed < runLength) {
  2800. if (offset >= input.length) {
  2801. return -1;
  2802. }
  2803. const charIndexInPacked = this.runConsumed - 1;
  2804. const packedWord = decodeTree[this.treeIndex + 1 + (charIndexInPacked >> 1)];
  2805. const expectedChar = charIndexInPacked % 2 === 0
  2806. ? packedWord & 0xff
  2807. : (packedWord >> 8) & 0xff;
  2808. if (input.charCodeAt(offset) !== expectedChar) {
  2809. this.runConsumed = 0;
  2810. return this.result === 0
  2811. ? 0
  2812. : this.emitNotTerminatedNamedEntity();
  2813. }
  2814. offset++;
  2815. this.excess++;
  2816. this.runConsumed++;
  2817. }
  2818. this.runConsumed = 0;
  2819. this.treeIndex += 1 + (runLength >> 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. const oldReasonCodes = {
  4564. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  4565. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  4566. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  4567. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  4568. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  4569. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  4570. };
  4571. if (oldReasonCodes[reasonCode]) {
  4572. reasonCode = oldReasonCodes[reasonCode];
  4573. }
  4574. return function constructor(loc, details) {
  4575. const error = new SyntaxError();
  4576. error.code = code;
  4577. error.reasonCode = reasonCode;
  4578. error.loc = loc;
  4579. error.pos = loc.index;
  4580. error.syntaxPlugin = syntaxPlugin;
  4581. if (hasMissingPlugin) {
  4582. error.missingPlugin = details.missingPlugin;
  4583. }
  4584. defineHidden(error, "clone", function clone(overrides = {}) {
  4585. var _overrides$loc;
  4586. const {
  4587. line,
  4588. column,
  4589. index
  4590. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  4591. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  4592. });
  4593. defineHidden(error, "details", details);
  4594. Object.defineProperty(error, "message", {
  4595. configurable: true,
  4596. get() {
  4597. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  4598. this.message = message;
  4599. return message;
  4600. },
  4601. set(value) {
  4602. Object.defineProperty(this, "message", {
  4603. value,
  4604. writable: true
  4605. });
  4606. }
  4607. });
  4608. return error;
  4609. };
  4610. }
  4611. function ParseErrorEnum(argument, syntaxPlugin) {
  4612. if (Array.isArray(argument)) {
  4613. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  4614. }
  4615. const ParseErrorConstructors = {};
  4616. for (const reasonCode of Object.keys(argument)) {
  4617. const template = argument[reasonCode];
  4618. const _ref = typeof template === "string" ? {
  4619. message: () => template
  4620. } : typeof template === "function" ? {
  4621. message: template
  4622. } : template,
  4623. {
  4624. message
  4625. } = _ref,
  4626. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  4627. const toMessage = typeof message === "string" ? () => message : message;
  4628. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  4629. code: "BABEL_PARSER_SYNTAX_ERROR",
  4630. reasonCode,
  4631. toMessage
  4632. }, syntaxPlugin ? {
  4633. syntaxPlugin
  4634. } : {}, rest));
  4635. }
  4636. return ParseErrorConstructors;
  4637. }
  4638. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  4639. function createDefaultOptions() {
  4640. return {
  4641. sourceType: "script",
  4642. sourceFilename: undefined,
  4643. startIndex: 0,
  4644. startColumn: 0,
  4645. startLine: 1,
  4646. allowAwaitOutsideFunction: false,
  4647. allowReturnOutsideFunction: false,
  4648. allowNewTargetOutsideFunction: false,
  4649. allowImportExportEverywhere: false,
  4650. allowSuperOutsideMethod: false,
  4651. allowUndeclaredExports: false,
  4652. allowYieldOutsideFunction: false,
  4653. plugins: [],
  4654. strictMode: undefined,
  4655. ranges: false,
  4656. tokens: false,
  4657. createImportExpressions: false,
  4658. createParenthesizedExpressions: false,
  4659. errorRecovery: false,
  4660. attachComment: true,
  4661. annexB: true
  4662. };
  4663. }
  4664. function getOptions(opts) {
  4665. const options = createDefaultOptions();
  4666. if (opts == null) {
  4667. return options;
  4668. }
  4669. if (opts.annexB != null && opts.annexB !== false) {
  4670. throw new Error("The `annexB` option can only be set to `false`.");
  4671. }
  4672. for (const key of Object.keys(options)) {
  4673. if (opts[key] != null) options[key] = opts[key];
  4674. }
  4675. if (options.startLine === 1) {
  4676. if (opts.startIndex == null && options.startColumn > 0) {
  4677. options.startIndex = options.startColumn;
  4678. } else if (opts.startColumn == null && options.startIndex > 0) {
  4679. options.startColumn = options.startIndex;
  4680. }
  4681. } else if (opts.startColumn == null || opts.startIndex == null) {
  4682. if (opts.startIndex != null) {
  4683. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  4684. }
  4685. }
  4686. if (options.sourceType === "commonjs") {
  4687. if (opts.allowAwaitOutsideFunction != null) {
  4688. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  4689. }
  4690. if (opts.allowReturnOutsideFunction != null) {
  4691. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  4692. }
  4693. if (opts.allowNewTargetOutsideFunction != null) {
  4694. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  4695. }
  4696. }
  4697. return options;
  4698. }
  4699. const {
  4700. defineProperty
  4701. } = Object;
  4702. const toUnenumerable = (object, key) => {
  4703. if (object) {
  4704. defineProperty(object, key, {
  4705. enumerable: false,
  4706. value: object[key]
  4707. });
  4708. }
  4709. };
  4710. function toESTreeLocation(node) {
  4711. toUnenumerable(node.loc.start, "index");
  4712. toUnenumerable(node.loc.end, "index");
  4713. return node;
  4714. }
  4715. var estree = superClass => class ESTreeParserMixin extends superClass {
  4716. parse() {
  4717. const file = toESTreeLocation(super.parse());
  4718. if (this.optionFlags & 256) {
  4719. file.tokens = file.tokens.map(toESTreeLocation);
  4720. }
  4721. return file;
  4722. }
  4723. parseRegExpLiteral({
  4724. pattern,
  4725. flags
  4726. }) {
  4727. let regex = null;
  4728. try {
  4729. regex = new RegExp(pattern, flags);
  4730. } catch (_) {}
  4731. const node = this.estreeParseLiteral(regex);
  4732. node.regex = {
  4733. pattern,
  4734. flags
  4735. };
  4736. return node;
  4737. }
  4738. parseBigIntLiteral(value) {
  4739. let bigInt;
  4740. try {
  4741. bigInt = BigInt(value);
  4742. } catch (_unused) {
  4743. bigInt = null;
  4744. }
  4745. const node = this.estreeParseLiteral(bigInt);
  4746. node.bigint = String(node.value || value);
  4747. return node;
  4748. }
  4749. parseDecimalLiteral(value) {
  4750. const decimal = null;
  4751. const node = this.estreeParseLiteral(decimal);
  4752. node.decimal = String(node.value || value);
  4753. return node;
  4754. }
  4755. estreeParseLiteral(value) {
  4756. return this.parseLiteral(value, "Literal");
  4757. }
  4758. parseStringLiteral(value) {
  4759. return this.estreeParseLiteral(value);
  4760. }
  4761. parseNumericLiteral(value) {
  4762. return this.estreeParseLiteral(value);
  4763. }
  4764. parseNullLiteral() {
  4765. return this.estreeParseLiteral(null);
  4766. }
  4767. parseBooleanLiteral(value) {
  4768. return this.estreeParseLiteral(value);
  4769. }
  4770. estreeParseChainExpression(node, endLoc) {
  4771. const chain = this.startNodeAtNode(node);
  4772. chain.expression = node;
  4773. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  4774. }
  4775. directiveToStmt(directive) {
  4776. const expression = directive.value;
  4777. delete directive.value;
  4778. this.castNodeTo(expression, "Literal");
  4779. expression.raw = expression.extra.raw;
  4780. expression.value = expression.extra.expressionValue;
  4781. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  4782. stmt.expression = expression;
  4783. stmt.directive = expression.extra.rawValue;
  4784. delete expression.extra;
  4785. return stmt;
  4786. }
  4787. fillOptionalPropertiesForTSESLint(node) {}
  4788. cloneEstreeStringLiteral(node) {
  4789. const {
  4790. start,
  4791. end,
  4792. loc,
  4793. range,
  4794. raw,
  4795. value
  4796. } = node;
  4797. const cloned = Object.create(node.constructor.prototype);
  4798. cloned.type = "Literal";
  4799. cloned.start = start;
  4800. cloned.end = end;
  4801. cloned.loc = loc;
  4802. cloned.range = range;
  4803. cloned.raw = raw;
  4804. cloned.value = value;
  4805. return cloned;
  4806. }
  4807. initFunction(node, isAsync) {
  4808. super.initFunction(node, isAsync);
  4809. node.expression = false;
  4810. }
  4811. checkDeclaration(node) {
  4812. if (node != null && this.isObjectProperty(node)) {
  4813. this.checkDeclaration(node.value);
  4814. } else {
  4815. super.checkDeclaration(node);
  4816. }
  4817. }
  4818. getObjectOrClassMethodParams(method) {
  4819. return method.value.params;
  4820. }
  4821. isValidDirective(stmt) {
  4822. var _stmt$expression$extr;
  4823. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  4824. }
  4825. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  4826. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  4827. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  4828. node.body = directiveStatements.concat(node.body);
  4829. delete node.directives;
  4830. }
  4831. parsePrivateName() {
  4832. const node = super.parsePrivateName();
  4833. if (!this.getPluginOption("estree", "classFeatures")) {
  4834. return node;
  4835. }
  4836. return this.convertPrivateNameToPrivateIdentifier(node);
  4837. }
  4838. convertPrivateNameToPrivateIdentifier(node) {
  4839. const name = super.getPrivateNameSV(node);
  4840. delete node.id;
  4841. node.name = name;
  4842. return this.castNodeTo(node, "PrivateIdentifier");
  4843. }
  4844. isPrivateName(node) {
  4845. if (!this.getPluginOption("estree", "classFeatures")) {
  4846. return super.isPrivateName(node);
  4847. }
  4848. return node.type === "PrivateIdentifier";
  4849. }
  4850. getPrivateNameSV(node) {
  4851. if (!this.getPluginOption("estree", "classFeatures")) {
  4852. return super.getPrivateNameSV(node);
  4853. }
  4854. return node.name;
  4855. }
  4856. parseLiteral(value, type) {
  4857. const node = super.parseLiteral(value, type);
  4858. node.raw = node.extra.raw;
  4859. delete node.extra;
  4860. return node;
  4861. }
  4862. parseFunctionBody(node, allowExpression, isMethod = false) {
  4863. super.parseFunctionBody(node, allowExpression, isMethod);
  4864. node.expression = node.body.type !== "BlockStatement";
  4865. }
  4866. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  4867. let funcNode = this.startNode();
  4868. funcNode.kind = node.kind;
  4869. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  4870. delete funcNode.kind;
  4871. const {
  4872. typeParameters
  4873. } = node;
  4874. if (typeParameters) {
  4875. delete node.typeParameters;
  4876. funcNode.typeParameters = typeParameters;
  4877. this.resetStartLocationFromNode(funcNode, typeParameters);
  4878. }
  4879. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  4880. node.value = valueNode;
  4881. if (type === "ClassPrivateMethod") {
  4882. node.computed = false;
  4883. }
  4884. if (type === "ObjectMethod") {
  4885. if (node.kind === "method") {
  4886. node.kind = "init";
  4887. }
  4888. node.shorthand = false;
  4889. return this.finishNode(node, "Property");
  4890. } else {
  4891. return this.finishNode(node, "MethodDefinition");
  4892. }
  4893. }
  4894. nameIsConstructor(key) {
  4895. if (key.type === "Literal") return key.value === "constructor";
  4896. return super.nameIsConstructor(key);
  4897. }
  4898. parseClassProperty(...args) {
  4899. const propertyNode = super.parseClassProperty(...args);
  4900. if (!this.getPluginOption("estree", "classFeatures")) {
  4901. return propertyNode;
  4902. }
  4903. this.castNodeTo(propertyNode, "PropertyDefinition");
  4904. return propertyNode;
  4905. }
  4906. parseClassPrivateProperty(...args) {
  4907. const propertyNode = super.parseClassPrivateProperty(...args);
  4908. if (!this.getPluginOption("estree", "classFeatures")) {
  4909. return propertyNode;
  4910. }
  4911. this.castNodeTo(propertyNode, "PropertyDefinition");
  4912. propertyNode.computed = false;
  4913. return propertyNode;
  4914. }
  4915. parseClassAccessorProperty(node) {
  4916. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  4917. if (!this.getPluginOption("estree", "classFeatures")) {
  4918. return accessorPropertyNode;
  4919. }
  4920. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  4921. delete accessorPropertyNode.abstract;
  4922. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  4923. } else {
  4924. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  4925. }
  4926. return accessorPropertyNode;
  4927. }
  4928. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  4929. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  4930. if (node) {
  4931. node.kind = "init";
  4932. this.castNodeTo(node, "Property");
  4933. }
  4934. return node;
  4935. }
  4936. finishObjectProperty(node) {
  4937. node.kind = "init";
  4938. return this.finishNode(node, "Property");
  4939. }
  4940. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  4941. return type === "Property" ? "value" : super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  4942. }
  4943. isAssignable(node, isBinding) {
  4944. if (node != null && this.isObjectProperty(node)) {
  4945. return this.isAssignable(node.value, isBinding);
  4946. }
  4947. return super.isAssignable(node, isBinding);
  4948. }
  4949. toAssignable(node, isLHS = false) {
  4950. if (node != null && this.isObjectProperty(node)) {
  4951. const {
  4952. key,
  4953. value
  4954. } = node;
  4955. if (this.isPrivateName(key)) {
  4956. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  4957. }
  4958. this.toAssignable(value, isLHS);
  4959. } else {
  4960. super.toAssignable(node, isLHS);
  4961. }
  4962. }
  4963. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  4964. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  4965. this.raise(Errors.PatternHasAccessor, prop.key);
  4966. } else if (prop.type === "Property" && prop.method) {
  4967. this.raise(Errors.PatternHasMethod, prop.key);
  4968. } else {
  4969. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  4970. }
  4971. }
  4972. finishCallExpression(unfinished, optional) {
  4973. const node = super.finishCallExpression(unfinished, optional);
  4974. if (node.callee.type === "Import") {
  4975. var _ref, _ref2;
  4976. this.castNodeTo(node, "ImportExpression");
  4977. node.source = node.arguments[0];
  4978. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  4979. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  4980. delete node.arguments;
  4981. delete node.callee;
  4982. } else if (node.type === "OptionalCallExpression") {
  4983. this.castNodeTo(node, "CallExpression");
  4984. } else {
  4985. node.optional = false;
  4986. }
  4987. return node;
  4988. }
  4989. toReferencedArguments(node) {
  4990. if (node.type === "ImportExpression") {
  4991. return;
  4992. }
  4993. super.toReferencedArguments(node);
  4994. }
  4995. parseExport(unfinished, decorators) {
  4996. const exportStartLoc = this.state.lastTokStartLoc;
  4997. const node = super.parseExport(unfinished, decorators);
  4998. switch (node.type) {
  4999. case "ExportAllDeclaration":
  5000. node.exported = null;
  5001. break;
  5002. case "ExportNamedDeclaration":
  5003. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  5004. this.castNodeTo(node, "ExportAllDeclaration");
  5005. node.exported = node.specifiers[0].exported;
  5006. delete node.specifiers;
  5007. }
  5008. case "ExportDefaultDeclaration":
  5009. {
  5010. var _declaration$decorato;
  5011. const {
  5012. declaration
  5013. } = node;
  5014. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  5015. this.resetStartLocation(node, exportStartLoc);
  5016. }
  5017. }
  5018. break;
  5019. }
  5020. return node;
  5021. }
  5022. stopParseSubscript(base, state) {
  5023. const node = super.stopParseSubscript(base, state);
  5024. if (state.optionalChainMember) {
  5025. return this.estreeParseChainExpression(node, base.loc.end);
  5026. }
  5027. return node;
  5028. }
  5029. parseMember(base, startLoc, state, computed, optional) {
  5030. const node = super.parseMember(base, startLoc, state, computed, optional);
  5031. if (node.type === "OptionalMemberExpression") {
  5032. this.castNodeTo(node, "MemberExpression");
  5033. } else {
  5034. node.optional = false;
  5035. }
  5036. return node;
  5037. }
  5038. isOptionalMemberExpression(node) {
  5039. if (node.type === "ChainExpression") {
  5040. return node.expression.type === "MemberExpression";
  5041. }
  5042. return super.isOptionalMemberExpression(node);
  5043. }
  5044. hasPropertyAsPrivateName(node) {
  5045. if (node.type === "ChainExpression") {
  5046. node = node.expression;
  5047. }
  5048. return super.hasPropertyAsPrivateName(node);
  5049. }
  5050. isObjectProperty(node) {
  5051. return node.type === "Property" && node.kind === "init" && !node.method;
  5052. }
  5053. isObjectMethod(node) {
  5054. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  5055. }
  5056. castNodeTo(node, type) {
  5057. const result = super.castNodeTo(node, type);
  5058. this.fillOptionalPropertiesForTSESLint(result);
  5059. return result;
  5060. }
  5061. cloneIdentifier(node) {
  5062. const cloned = super.cloneIdentifier(node);
  5063. this.fillOptionalPropertiesForTSESLint(cloned);
  5064. return cloned;
  5065. }
  5066. cloneStringLiteral(node) {
  5067. if (node.type === "Literal") {
  5068. return this.cloneEstreeStringLiteral(node);
  5069. }
  5070. return super.cloneStringLiteral(node);
  5071. }
  5072. finishNodeAt(node, type, endLoc) {
  5073. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  5074. }
  5075. finishNode(node, type) {
  5076. const result = super.finishNode(node, type);
  5077. this.fillOptionalPropertiesForTSESLint(result);
  5078. return result;
  5079. }
  5080. resetStartLocation(node, startLoc) {
  5081. super.resetStartLocation(node, startLoc);
  5082. toESTreeLocation(node);
  5083. }
  5084. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  5085. super.resetEndLocation(node, endLoc);
  5086. toESTreeLocation(node);
  5087. }
  5088. };
  5089. class TokContext {
  5090. constructor(token, preserveSpace) {
  5091. this.token = void 0;
  5092. this.preserveSpace = void 0;
  5093. this.token = token;
  5094. this.preserveSpace = !!preserveSpace;
  5095. }
  5096. }
  5097. const types = {
  5098. brace: new TokContext("{"),
  5099. j_oTag: new TokContext("<tag"),
  5100. j_cTag: new TokContext("</tag"),
  5101. j_expr: new TokContext("<tag>...</tag>", true)
  5102. };
  5103. types.template = new TokContext("`", true);
  5104. const beforeExpr = true;
  5105. const startsExpr = true;
  5106. const isLoop = true;
  5107. const isAssign = true;
  5108. const prefix = true;
  5109. const postfix = true;
  5110. class ExportedTokenType {
  5111. constructor(label, conf = {}) {
  5112. this.label = void 0;
  5113. this.keyword = void 0;
  5114. this.beforeExpr = void 0;
  5115. this.startsExpr = void 0;
  5116. this.rightAssociative = void 0;
  5117. this.isLoop = void 0;
  5118. this.isAssign = void 0;
  5119. this.prefix = void 0;
  5120. this.postfix = void 0;
  5121. this.binop = void 0;
  5122. this.label = label;
  5123. this.keyword = conf.keyword;
  5124. this.beforeExpr = !!conf.beforeExpr;
  5125. this.startsExpr = !!conf.startsExpr;
  5126. this.rightAssociative = !!conf.rightAssociative;
  5127. this.isLoop = !!conf.isLoop;
  5128. this.isAssign = !!conf.isAssign;
  5129. this.prefix = !!conf.prefix;
  5130. this.postfix = !!conf.postfix;
  5131. this.binop = conf.binop != null ? conf.binop : null;
  5132. this.updateContext = null;
  5133. }
  5134. }
  5135. const keywords$1 = new Map();
  5136. function createKeyword(name, options = {}) {
  5137. options.keyword = name;
  5138. const token = createToken(name, options);
  5139. keywords$1.set(name, token);
  5140. return token;
  5141. }
  5142. function createBinop(name, binop) {
  5143. return createToken(name, {
  5144. beforeExpr,
  5145. binop
  5146. });
  5147. }
  5148. let tokenTypeCounter = -1;
  5149. const tokenTypes = [];
  5150. const tokenLabels = [];
  5151. const tokenBinops = [];
  5152. const tokenBeforeExprs = [];
  5153. const tokenStartsExprs = [];
  5154. const tokenPrefixes = [];
  5155. function createToken(name, options = {}) {
  5156. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  5157. ++tokenTypeCounter;
  5158. tokenLabels.push(name);
  5159. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  5160. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  5161. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  5162. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  5163. tokenTypes.push(new ExportedTokenType(name, options));
  5164. return tokenTypeCounter;
  5165. }
  5166. function createKeywordLike(name, options = {}) {
  5167. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  5168. ++tokenTypeCounter;
  5169. keywords$1.set(name, tokenTypeCounter);
  5170. tokenLabels.push(name);
  5171. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  5172. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  5173. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  5174. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  5175. tokenTypes.push(new ExportedTokenType("name", options));
  5176. return tokenTypeCounter;
  5177. }
  5178. const tt = {
  5179. bracketL: createToken("[", {
  5180. beforeExpr,
  5181. startsExpr
  5182. }),
  5183. bracketHashL: createToken("#[", {
  5184. beforeExpr,
  5185. startsExpr
  5186. }),
  5187. bracketBarL: createToken("[|", {
  5188. beforeExpr,
  5189. startsExpr
  5190. }),
  5191. bracketR: createToken("]"),
  5192. bracketBarR: createToken("|]"),
  5193. braceL: createToken("{", {
  5194. beforeExpr,
  5195. startsExpr
  5196. }),
  5197. braceBarL: createToken("{|", {
  5198. beforeExpr,
  5199. startsExpr
  5200. }),
  5201. braceHashL: createToken("#{", {
  5202. beforeExpr,
  5203. startsExpr
  5204. }),
  5205. braceR: createToken("}"),
  5206. braceBarR: createToken("|}"),
  5207. parenL: createToken("(", {
  5208. beforeExpr,
  5209. startsExpr
  5210. }),
  5211. parenR: createToken(")"),
  5212. comma: createToken(",", {
  5213. beforeExpr
  5214. }),
  5215. semi: createToken(";", {
  5216. beforeExpr
  5217. }),
  5218. colon: createToken(":", {
  5219. beforeExpr
  5220. }),
  5221. doubleColon: createToken("::", {
  5222. beforeExpr
  5223. }),
  5224. dot: createToken("."),
  5225. question: createToken("?", {
  5226. beforeExpr
  5227. }),
  5228. questionDot: createToken("?."),
  5229. arrow: createToken("=>", {
  5230. beforeExpr
  5231. }),
  5232. template: createToken("template"),
  5233. ellipsis: createToken("...", {
  5234. beforeExpr
  5235. }),
  5236. backQuote: createToken("`", {
  5237. startsExpr
  5238. }),
  5239. dollarBraceL: createToken("${", {
  5240. beforeExpr,
  5241. startsExpr
  5242. }),
  5243. templateTail: createToken("...`", {
  5244. startsExpr
  5245. }),
  5246. templateNonTail: createToken("...${", {
  5247. beforeExpr,
  5248. startsExpr
  5249. }),
  5250. at: createToken("@"),
  5251. hash: createToken("#", {
  5252. startsExpr
  5253. }),
  5254. interpreterDirective: createToken("#!..."),
  5255. eq: createToken("=", {
  5256. beforeExpr,
  5257. isAssign
  5258. }),
  5259. assign: createToken("_=", {
  5260. beforeExpr,
  5261. isAssign
  5262. }),
  5263. slashAssign: createToken("_=", {
  5264. beforeExpr,
  5265. isAssign
  5266. }),
  5267. xorAssign: createToken("_=", {
  5268. beforeExpr,
  5269. isAssign
  5270. }),
  5271. moduloAssign: createToken("_=", {
  5272. beforeExpr,
  5273. isAssign
  5274. }),
  5275. incDec: createToken("++/--", {
  5276. prefix,
  5277. postfix,
  5278. startsExpr
  5279. }),
  5280. bang: createToken("!", {
  5281. beforeExpr,
  5282. prefix,
  5283. startsExpr
  5284. }),
  5285. tilde: createToken("~", {
  5286. beforeExpr,
  5287. prefix,
  5288. startsExpr
  5289. }),
  5290. doubleCaret: createToken("^^", {
  5291. startsExpr
  5292. }),
  5293. doubleAt: createToken("@@", {
  5294. startsExpr
  5295. }),
  5296. pipeline: createBinop("|>", 0),
  5297. nullishCoalescing: createBinop("??", 1),
  5298. logicalOR: createBinop("||", 1),
  5299. logicalAND: createBinop("&&", 2),
  5300. bitwiseOR: createBinop("|", 3),
  5301. bitwiseXOR: createBinop("^", 4),
  5302. bitwiseAND: createBinop("&", 5),
  5303. equality: createBinop("==/!=/===/!==", 6),
  5304. lt: createBinop("</>/<=/>=", 7),
  5305. gt: createBinop("</>/<=/>=", 7),
  5306. relational: createBinop("</>/<=/>=", 7),
  5307. bitShift: createBinop("<</>>/>>>", 8),
  5308. bitShiftL: createBinop("<</>>/>>>", 8),
  5309. bitShiftR: createBinop("<</>>/>>>", 8),
  5310. plusMin: createToken("+/-", {
  5311. beforeExpr,
  5312. binop: 9,
  5313. prefix,
  5314. startsExpr
  5315. }),
  5316. modulo: createToken("%", {
  5317. binop: 10,
  5318. startsExpr
  5319. }),
  5320. star: createToken("*", {
  5321. binop: 10
  5322. }),
  5323. slash: createBinop("/", 10),
  5324. exponent: createToken("**", {
  5325. beforeExpr,
  5326. binop: 11,
  5327. rightAssociative: true
  5328. }),
  5329. _in: createKeyword("in", {
  5330. beforeExpr,
  5331. binop: 7
  5332. }),
  5333. _instanceof: createKeyword("instanceof", {
  5334. beforeExpr,
  5335. binop: 7
  5336. }),
  5337. _break: createKeyword("break"),
  5338. _case: createKeyword("case", {
  5339. beforeExpr
  5340. }),
  5341. _catch: createKeyword("catch"),
  5342. _continue: createKeyword("continue"),
  5343. _debugger: createKeyword("debugger"),
  5344. _default: createKeyword("default", {
  5345. beforeExpr
  5346. }),
  5347. _else: createKeyword("else", {
  5348. beforeExpr
  5349. }),
  5350. _finally: createKeyword("finally"),
  5351. _function: createKeyword("function", {
  5352. startsExpr
  5353. }),
  5354. _if: createKeyword("if"),
  5355. _return: createKeyword("return", {
  5356. beforeExpr
  5357. }),
  5358. _switch: createKeyword("switch"),
  5359. _throw: createKeyword("throw", {
  5360. beforeExpr,
  5361. prefix,
  5362. startsExpr
  5363. }),
  5364. _try: createKeyword("try"),
  5365. _var: createKeyword("var"),
  5366. _const: createKeyword("const"),
  5367. _with: createKeyword("with"),
  5368. _new: createKeyword("new", {
  5369. beforeExpr,
  5370. startsExpr
  5371. }),
  5372. _this: createKeyword("this", {
  5373. startsExpr
  5374. }),
  5375. _super: createKeyword("super", {
  5376. startsExpr
  5377. }),
  5378. _class: createKeyword("class", {
  5379. startsExpr
  5380. }),
  5381. _extends: createKeyword("extends", {
  5382. beforeExpr
  5383. }),
  5384. _export: createKeyword("export"),
  5385. _import: createKeyword("import", {
  5386. startsExpr
  5387. }),
  5388. _null: createKeyword("null", {
  5389. startsExpr
  5390. }),
  5391. _true: createKeyword("true", {
  5392. startsExpr
  5393. }),
  5394. _false: createKeyword("false", {
  5395. startsExpr
  5396. }),
  5397. _typeof: createKeyword("typeof", {
  5398. beforeExpr,
  5399. prefix,
  5400. startsExpr
  5401. }),
  5402. _void: createKeyword("void", {
  5403. beforeExpr,
  5404. prefix,
  5405. startsExpr
  5406. }),
  5407. _delete: createKeyword("delete", {
  5408. beforeExpr,
  5409. prefix,
  5410. startsExpr
  5411. }),
  5412. _do: createKeyword("do", {
  5413. isLoop,
  5414. beforeExpr
  5415. }),
  5416. _for: createKeyword("for", {
  5417. isLoop
  5418. }),
  5419. _while: createKeyword("while", {
  5420. isLoop
  5421. }),
  5422. _as: createKeywordLike("as", {
  5423. startsExpr
  5424. }),
  5425. _assert: createKeywordLike("assert", {
  5426. startsExpr
  5427. }),
  5428. _async: createKeywordLike("async", {
  5429. startsExpr
  5430. }),
  5431. _await: createKeywordLike("await", {
  5432. startsExpr
  5433. }),
  5434. _defer: createKeywordLike("defer", {
  5435. startsExpr
  5436. }),
  5437. _from: createKeywordLike("from", {
  5438. startsExpr
  5439. }),
  5440. _get: createKeywordLike("get", {
  5441. startsExpr
  5442. }),
  5443. _let: createKeywordLike("let", {
  5444. startsExpr
  5445. }),
  5446. _meta: createKeywordLike("meta", {
  5447. startsExpr
  5448. }),
  5449. _of: createKeywordLike("of", {
  5450. startsExpr
  5451. }),
  5452. _sent: createKeywordLike("sent", {
  5453. startsExpr
  5454. }),
  5455. _set: createKeywordLike("set", {
  5456. startsExpr
  5457. }),
  5458. _source: createKeywordLike("source", {
  5459. startsExpr
  5460. }),
  5461. _static: createKeywordLike("static", {
  5462. startsExpr
  5463. }),
  5464. _using: createKeywordLike("using", {
  5465. startsExpr
  5466. }),
  5467. _yield: createKeywordLike("yield", {
  5468. startsExpr
  5469. }),
  5470. _asserts: createKeywordLike("asserts", {
  5471. startsExpr
  5472. }),
  5473. _checks: createKeywordLike("checks", {
  5474. startsExpr
  5475. }),
  5476. _exports: createKeywordLike("exports", {
  5477. startsExpr
  5478. }),
  5479. _global: createKeywordLike("global", {
  5480. startsExpr
  5481. }),
  5482. _implements: createKeywordLike("implements", {
  5483. startsExpr
  5484. }),
  5485. _intrinsic: createKeywordLike("intrinsic", {
  5486. startsExpr
  5487. }),
  5488. _infer: createKeywordLike("infer", {
  5489. startsExpr
  5490. }),
  5491. _is: createKeywordLike("is", {
  5492. startsExpr
  5493. }),
  5494. _mixins: createKeywordLike("mixins", {
  5495. startsExpr
  5496. }),
  5497. _proto: createKeywordLike("proto", {
  5498. startsExpr
  5499. }),
  5500. _require: createKeywordLike("require", {
  5501. startsExpr
  5502. }),
  5503. _satisfies: createKeywordLike("satisfies", {
  5504. startsExpr
  5505. }),
  5506. _keyof: createKeywordLike("keyof", {
  5507. startsExpr
  5508. }),
  5509. _readonly: createKeywordLike("readonly", {
  5510. startsExpr
  5511. }),
  5512. _unique: createKeywordLike("unique", {
  5513. startsExpr
  5514. }),
  5515. _abstract: createKeywordLike("abstract", {
  5516. startsExpr
  5517. }),
  5518. _declare: createKeywordLike("declare", {
  5519. startsExpr
  5520. }),
  5521. _enum: createKeywordLike("enum", {
  5522. startsExpr
  5523. }),
  5524. _module: createKeywordLike("module", {
  5525. startsExpr
  5526. }),
  5527. _namespace: createKeywordLike("namespace", {
  5528. startsExpr
  5529. }),
  5530. _interface: createKeywordLike("interface", {
  5531. startsExpr
  5532. }),
  5533. _type: createKeywordLike("type", {
  5534. startsExpr
  5535. }),
  5536. _opaque: createKeywordLike("opaque", {
  5537. startsExpr
  5538. }),
  5539. name: createToken("name", {
  5540. startsExpr
  5541. }),
  5542. placeholder: createToken("%%", {
  5543. startsExpr
  5544. }),
  5545. string: createToken("string", {
  5546. startsExpr
  5547. }),
  5548. num: createToken("num", {
  5549. startsExpr
  5550. }),
  5551. bigint: createToken("bigint", {
  5552. startsExpr
  5553. }),
  5554. decimal: createToken("decimal", {
  5555. startsExpr
  5556. }),
  5557. regexp: createToken("regexp", {
  5558. startsExpr
  5559. }),
  5560. privateName: createToken("#name", {
  5561. startsExpr
  5562. }),
  5563. eof: createToken("eof"),
  5564. jsxName: createToken("jsxName"),
  5565. jsxText: createToken("jsxText", {
  5566. beforeExpr
  5567. }),
  5568. jsxTagStart: createToken("jsxTagStart", {
  5569. startsExpr
  5570. }),
  5571. jsxTagEnd: createToken("jsxTagEnd")
  5572. };
  5573. function tokenIsIdentifier(token) {
  5574. return token >= 93 && token <= 133;
  5575. }
  5576. function tokenKeywordOrIdentifierIsKeyword(token) {
  5577. return token <= 92;
  5578. }
  5579. function tokenIsKeywordOrIdentifier(token) {
  5580. return token >= 58 && token <= 133;
  5581. }
  5582. function tokenIsLiteralPropertyName(token) {
  5583. return token >= 58 && token <= 137;
  5584. }
  5585. function tokenComesBeforeExpression(token) {
  5586. return tokenBeforeExprs[token];
  5587. }
  5588. function tokenCanStartExpression(token) {
  5589. return tokenStartsExprs[token];
  5590. }
  5591. function tokenIsAssignment(token) {
  5592. return token >= 29 && token <= 33;
  5593. }
  5594. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  5595. return token >= 129 && token <= 131;
  5596. }
  5597. function tokenIsLoop(token) {
  5598. return token >= 90 && token <= 92;
  5599. }
  5600. function tokenIsKeyword(token) {
  5601. return token >= 58 && token <= 92;
  5602. }
  5603. function tokenIsOperator(token) {
  5604. return token >= 39 && token <= 59;
  5605. }
  5606. function tokenIsPostfix(token) {
  5607. return token === 34;
  5608. }
  5609. function tokenIsPrefix(token) {
  5610. return tokenPrefixes[token];
  5611. }
  5612. function tokenIsTSTypeOperator(token) {
  5613. return token >= 121 && token <= 123;
  5614. }
  5615. function tokenIsTSDeclarationStart(token) {
  5616. return token >= 124 && token <= 130;
  5617. }
  5618. function tokenLabelName(token) {
  5619. return tokenLabels[token];
  5620. }
  5621. function tokenOperatorPrecedence(token) {
  5622. return tokenBinops[token];
  5623. }
  5624. function tokenIsRightAssociative(token) {
  5625. return token === 57;
  5626. }
  5627. function tokenIsTemplate(token) {
  5628. return token >= 24 && token <= 25;
  5629. }
  5630. function getExportedToken(token) {
  5631. return tokenTypes[token];
  5632. }
  5633. tokenTypes[8].updateContext = context => {
  5634. context.pop();
  5635. };
  5636. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  5637. context.push(types.brace);
  5638. };
  5639. tokenTypes[22].updateContext = context => {
  5640. if (context[context.length - 1] === types.template) {
  5641. context.pop();
  5642. } else {
  5643. context.push(types.template);
  5644. }
  5645. };
  5646. tokenTypes[143].updateContext = context => {
  5647. context.push(types.j_expr, types.j_oTag);
  5648. };
  5649. 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";
  5650. 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";
  5651. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  5652. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  5653. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  5654. 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];
  5655. 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];
  5656. function isInAstralSet(code, set) {
  5657. let pos = 0x10000;
  5658. for (let i = 0, length = set.length; i < length; i += 2) {
  5659. pos += set[i];
  5660. if (pos > code) return false;
  5661. pos += set[i + 1];
  5662. if (pos >= code) return true;
  5663. }
  5664. return false;
  5665. }
  5666. function isIdentifierStart(code) {
  5667. if (code < 65) return code === 36;
  5668. if (code <= 90) return true;
  5669. if (code < 97) return code === 95;
  5670. if (code <= 122) return true;
  5671. if (code <= 0xffff) {
  5672. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  5673. }
  5674. return isInAstralSet(code, astralIdentifierStartCodes);
  5675. }
  5676. function isIdentifierChar(code) {
  5677. if (code < 48) return code === 36;
  5678. if (code < 58) return true;
  5679. if (code < 65) return false;
  5680. if (code <= 90) return true;
  5681. if (code < 97) return code === 95;
  5682. if (code <= 122) return true;
  5683. if (code <= 0xffff) {
  5684. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  5685. }
  5686. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  5687. }
  5688. const reservedWords = {
  5689. 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"],
  5690. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  5691. strictBind: ["eval", "arguments"]
  5692. };
  5693. const keywords = new Set(reservedWords.keyword);
  5694. const reservedWordsStrictSet = new Set(reservedWords.strict);
  5695. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  5696. function isReservedWord(word, inModule) {
  5697. return inModule && word === "await" || word === "enum";
  5698. }
  5699. function isStrictReservedWord(word, inModule) {
  5700. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  5701. }
  5702. function isStrictBindOnlyReservedWord(word) {
  5703. return reservedWordsStrictBindSet.has(word);
  5704. }
  5705. function isStrictBindReservedWord(word, inModule) {
  5706. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  5707. }
  5708. function isKeyword(word) {
  5709. return keywords.has(word);
  5710. }
  5711. function isIteratorStart(current, next, next2) {
  5712. return current === 64 && next === 64 && isIdentifierStart(next2);
  5713. }
  5714. 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"]);
  5715. function canBeReservedWord(word) {
  5716. return reservedWordLikeSet.has(word);
  5717. }
  5718. class Scope {
  5719. constructor(flags) {
  5720. this.flags = 0;
  5721. this.names = new Map();
  5722. this.firstLexicalName = "";
  5723. this.flags = flags;
  5724. }
  5725. }
  5726. class ScopeHandler {
  5727. constructor(parser, inModule) {
  5728. this.parser = void 0;
  5729. this.scopeStack = [];
  5730. this.inModule = void 0;
  5731. this.undefinedExports = new Map();
  5732. this.parser = parser;
  5733. this.inModule = inModule;
  5734. }
  5735. get inTopLevel() {
  5736. return (this.currentScope().flags & 1) > 0;
  5737. }
  5738. get inFunction() {
  5739. return (this.currentVarScopeFlags() & 2) > 0;
  5740. }
  5741. get allowSuper() {
  5742. return (this.currentThisScopeFlags() & 16) > 0;
  5743. }
  5744. get allowDirectSuper() {
  5745. return (this.currentThisScopeFlags() & 32) > 0;
  5746. }
  5747. get allowNewTarget() {
  5748. return (this.currentThisScopeFlags() & 512) > 0;
  5749. }
  5750. get inClass() {
  5751. return (this.currentThisScopeFlags() & 64) > 0;
  5752. }
  5753. get inClassAndNotInNonArrowFunction() {
  5754. const flags = this.currentThisScopeFlags();
  5755. return (flags & 64) > 0 && (flags & 2) === 0;
  5756. }
  5757. get inStaticBlock() {
  5758. for (let i = this.scopeStack.length - 1;; i--) {
  5759. const {
  5760. flags
  5761. } = this.scopeStack[i];
  5762. if (flags & 128) {
  5763. return true;
  5764. }
  5765. if (flags & (1667 | 64)) {
  5766. return false;
  5767. }
  5768. }
  5769. }
  5770. get inNonArrowFunction() {
  5771. return (this.currentThisScopeFlags() & 2) > 0;
  5772. }
  5773. get inBareCaseStatement() {
  5774. return (this.currentScope().flags & 256) > 0;
  5775. }
  5776. get treatFunctionsAsVar() {
  5777. return this.treatFunctionsAsVarInScope(this.currentScope());
  5778. }
  5779. createScope(flags) {
  5780. return new Scope(flags);
  5781. }
  5782. enter(flags) {
  5783. this.scopeStack.push(this.createScope(flags));
  5784. }
  5785. exit() {
  5786. const scope = this.scopeStack.pop();
  5787. return scope.flags;
  5788. }
  5789. treatFunctionsAsVarInScope(scope) {
  5790. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  5791. }
  5792. declareName(name, bindingType, loc) {
  5793. let scope = this.currentScope();
  5794. if (bindingType & 8 || bindingType & 16) {
  5795. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5796. let type = scope.names.get(name) || 0;
  5797. if (bindingType & 16) {
  5798. type = type | 4;
  5799. } else {
  5800. if (!scope.firstLexicalName) {
  5801. scope.firstLexicalName = name;
  5802. }
  5803. type = type | 2;
  5804. }
  5805. scope.names.set(name, type);
  5806. if (bindingType & 8) {
  5807. this.maybeExportDefined(scope, name);
  5808. }
  5809. } else if (bindingType & 4) {
  5810. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  5811. scope = this.scopeStack[i];
  5812. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5813. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  5814. this.maybeExportDefined(scope, name);
  5815. if (scope.flags & 1667) break;
  5816. }
  5817. }
  5818. if (this.parser.inModule && scope.flags & 1) {
  5819. this.undefinedExports.delete(name);
  5820. }
  5821. }
  5822. maybeExportDefined(scope, name) {
  5823. if (this.parser.inModule && scope.flags & 1) {
  5824. this.undefinedExports.delete(name);
  5825. }
  5826. }
  5827. checkRedeclarationInScope(scope, name, bindingType, loc) {
  5828. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  5829. this.parser.raise(Errors.VarRedeclaration, loc, {
  5830. identifierName: name
  5831. });
  5832. }
  5833. }
  5834. isRedeclaredInScope(scope, name, bindingType) {
  5835. if (!(bindingType & 1)) return false;
  5836. if (bindingType & 8) {
  5837. return scope.names.has(name);
  5838. }
  5839. const type = scope.names.get(name) || 0;
  5840. if (bindingType & 16) {
  5841. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  5842. }
  5843. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  5844. }
  5845. checkLocalExport(id) {
  5846. const {
  5847. name
  5848. } = id;
  5849. const topLevelScope = this.scopeStack[0];
  5850. if (!topLevelScope.names.has(name)) {
  5851. this.undefinedExports.set(name, id.loc.start);
  5852. }
  5853. }
  5854. currentScope() {
  5855. return this.scopeStack[this.scopeStack.length - 1];
  5856. }
  5857. currentVarScopeFlags() {
  5858. for (let i = this.scopeStack.length - 1;; i--) {
  5859. const {
  5860. flags
  5861. } = this.scopeStack[i];
  5862. if (flags & 1667) {
  5863. return flags;
  5864. }
  5865. }
  5866. }
  5867. currentThisScopeFlags() {
  5868. for (let i = this.scopeStack.length - 1;; i--) {
  5869. const {
  5870. flags
  5871. } = this.scopeStack[i];
  5872. if (flags & (1667 | 64) && !(flags & 4)) {
  5873. return flags;
  5874. }
  5875. }
  5876. }
  5877. }
  5878. class FlowScope extends Scope {
  5879. constructor(...args) {
  5880. super(...args);
  5881. this.declareFunctions = new Set();
  5882. }
  5883. }
  5884. class FlowScopeHandler extends ScopeHandler {
  5885. createScope(flags) {
  5886. return new FlowScope(flags);
  5887. }
  5888. declareName(name, bindingType, loc) {
  5889. const scope = this.currentScope();
  5890. if (bindingType & 2048) {
  5891. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  5892. this.maybeExportDefined(scope, name);
  5893. scope.declareFunctions.add(name);
  5894. return;
  5895. }
  5896. super.declareName(name, bindingType, loc);
  5897. }
  5898. isRedeclaredInScope(scope, name, bindingType) {
  5899. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  5900. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  5901. const type = scope.names.get(name);
  5902. return (type & 4) > 0 || (type & 2) > 0;
  5903. }
  5904. return false;
  5905. }
  5906. checkLocalExport(id) {
  5907. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  5908. super.checkLocalExport(id);
  5909. }
  5910. }
  5911. }
  5912. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  5913. const FlowErrors = ParseErrorEnum`flow`({
  5914. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  5915. 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.",
  5916. AssignReservedType: ({
  5917. reservedType
  5918. }) => `Cannot overwrite reserved type ${reservedType}.`,
  5919. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  5920. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  5921. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  5922. EnumBooleanMemberNotInitialized: ({
  5923. memberName,
  5924. enumName
  5925. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  5926. EnumDuplicateMemberName: ({
  5927. memberName,
  5928. enumName
  5929. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  5930. EnumInconsistentMemberValues: ({
  5931. enumName
  5932. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  5933. EnumInvalidExplicitType: ({
  5934. invalidEnumType,
  5935. enumName
  5936. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  5937. EnumInvalidExplicitTypeUnknownSupplied: ({
  5938. enumName
  5939. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  5940. EnumInvalidMemberInitializerPrimaryType: ({
  5941. enumName,
  5942. memberName,
  5943. explicitType
  5944. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  5945. EnumInvalidMemberInitializerSymbolType: ({
  5946. enumName,
  5947. memberName
  5948. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  5949. EnumInvalidMemberInitializerUnknownType: ({
  5950. enumName,
  5951. memberName
  5952. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  5953. EnumInvalidMemberName: ({
  5954. enumName,
  5955. memberName,
  5956. suggestion
  5957. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  5958. EnumNumberMemberNotInitialized: ({
  5959. enumName,
  5960. memberName
  5961. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  5962. EnumStringMemberInconsistentlyInitialized: ({
  5963. enumName
  5964. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  5965. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  5966. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  5967. 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.",
  5968. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  5969. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  5970. InexactVariance: "Explicit inexact syntax cannot have variance.",
  5971. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  5972. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  5973. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  5974. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  5975. PatternIsOptional: Object.assign({
  5976. message: "A binding pattern parameter cannot be optional in an implementation signature."
  5977. }, {
  5978. reasonCode: "OptionalBindingPattern"
  5979. }),
  5980. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  5981. SpreadVariance: "Spread properties cannot have variance.",
  5982. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  5983. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  5984. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  5985. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  5986. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  5987. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  5988. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  5989. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  5990. UnexpectedReservedType: ({
  5991. reservedType
  5992. }) => `Unexpected reserved type ${reservedType}.`,
  5993. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  5994. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  5995. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  5996. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  5997. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  5998. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  5999. UnsupportedDeclareExportKind: ({
  6000. unsupportedExportKind,
  6001. suggestion
  6002. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  6003. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  6004. UnterminatedFlowComment: "Unterminated flow-comment."
  6005. });
  6006. function isEsModuleType(bodyElement) {
  6007. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  6008. }
  6009. function hasTypeImportKind(node) {
  6010. return node.importKind === "type" || node.importKind === "typeof";
  6011. }
  6012. const exportSuggestions = {
  6013. const: "declare export var",
  6014. let: "declare export var",
  6015. type: "export type",
  6016. interface: "export interface"
  6017. };
  6018. function partition(list, test) {
  6019. const list1 = [];
  6020. const list2 = [];
  6021. for (let i = 0; i < list.length; i++) {
  6022. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  6023. }
  6024. return [list1, list2];
  6025. }
  6026. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  6027. var flow = superClass => class FlowParserMixin extends superClass {
  6028. constructor(...args) {
  6029. super(...args);
  6030. this.flowPragma = undefined;
  6031. }
  6032. getScopeHandler() {
  6033. return FlowScopeHandler;
  6034. }
  6035. shouldParseTypes() {
  6036. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  6037. }
  6038. finishToken(type, val) {
  6039. if (type !== 134 && type !== 13 && type !== 28) {
  6040. if (this.flowPragma === undefined) {
  6041. this.flowPragma = null;
  6042. }
  6043. }
  6044. super.finishToken(type, val);
  6045. }
  6046. addComment(comment) {
  6047. if (this.flowPragma === undefined) {
  6048. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  6049. if (!matches) ;else if (matches[1] === "flow") {
  6050. this.flowPragma = "flow";
  6051. } else if (matches[1] === "noflow") {
  6052. this.flowPragma = "noflow";
  6053. } else {
  6054. throw new Error("Unexpected flow pragma");
  6055. }
  6056. }
  6057. super.addComment(comment);
  6058. }
  6059. flowParseTypeInitialiser(tok) {
  6060. const oldInType = this.state.inType;
  6061. this.state.inType = true;
  6062. this.expect(tok || 14);
  6063. const type = this.flowParseType();
  6064. this.state.inType = oldInType;
  6065. return type;
  6066. }
  6067. flowParsePredicate() {
  6068. const node = this.startNode();
  6069. const moduloLoc = this.state.startLoc;
  6070. this.next();
  6071. this.expectContextual(110);
  6072. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  6073. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  6074. }
  6075. if (this.eat(10)) {
  6076. node.value = super.parseExpression();
  6077. this.expect(11);
  6078. return this.finishNode(node, "DeclaredPredicate");
  6079. } else {
  6080. return this.finishNode(node, "InferredPredicate");
  6081. }
  6082. }
  6083. flowParseTypeAndPredicateInitialiser() {
  6084. const oldInType = this.state.inType;
  6085. this.state.inType = true;
  6086. this.expect(14);
  6087. let type = null;
  6088. let predicate = null;
  6089. if (this.match(54)) {
  6090. this.state.inType = oldInType;
  6091. predicate = this.flowParsePredicate();
  6092. } else {
  6093. type = this.flowParseType();
  6094. this.state.inType = oldInType;
  6095. if (this.match(54)) {
  6096. predicate = this.flowParsePredicate();
  6097. }
  6098. }
  6099. return [type, predicate];
  6100. }
  6101. flowParseDeclareClass(node) {
  6102. this.next();
  6103. this.flowParseInterfaceish(node, true);
  6104. return this.finishNode(node, "DeclareClass");
  6105. }
  6106. flowParseDeclareFunction(node) {
  6107. this.next();
  6108. const id = node.id = this.parseIdentifier();
  6109. const typeNode = this.startNode();
  6110. const typeContainer = this.startNode();
  6111. if (this.match(47)) {
  6112. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  6113. } else {
  6114. typeNode.typeParameters = null;
  6115. }
  6116. this.expect(10);
  6117. const tmp = this.flowParseFunctionTypeParams();
  6118. typeNode.params = tmp.params;
  6119. typeNode.rest = tmp.rest;
  6120. typeNode.this = tmp._this;
  6121. this.expect(11);
  6122. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6123. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  6124. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  6125. this.resetEndLocation(id);
  6126. this.semicolon();
  6127. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  6128. return this.finishNode(node, "DeclareFunction");
  6129. }
  6130. flowParseDeclare(node, insideModule) {
  6131. if (this.match(80)) {
  6132. return this.flowParseDeclareClass(node);
  6133. } else if (this.match(68)) {
  6134. return this.flowParseDeclareFunction(node);
  6135. } else if (this.match(74)) {
  6136. return this.flowParseDeclareVariable(node);
  6137. } else if (this.eatContextual(127)) {
  6138. if (this.match(16)) {
  6139. return this.flowParseDeclareModuleExports(node);
  6140. } else {
  6141. if (insideModule) {
  6142. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  6143. }
  6144. return this.flowParseDeclareModule(node);
  6145. }
  6146. } else if (this.isContextual(130)) {
  6147. return this.flowParseDeclareTypeAlias(node);
  6148. } else if (this.isContextual(131)) {
  6149. return this.flowParseDeclareOpaqueType(node);
  6150. } else if (this.isContextual(129)) {
  6151. return this.flowParseDeclareInterface(node);
  6152. } else if (this.match(82)) {
  6153. return this.flowParseDeclareExportDeclaration(node, insideModule);
  6154. }
  6155. throw this.unexpected();
  6156. }
  6157. flowParseDeclareVariable(node) {
  6158. this.next();
  6159. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  6160. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  6161. this.semicolon();
  6162. return this.finishNode(node, "DeclareVariable");
  6163. }
  6164. flowParseDeclareModule(node) {
  6165. this.scope.enter(0);
  6166. if (this.match(134)) {
  6167. node.id = super.parseExprAtom();
  6168. } else {
  6169. node.id = this.parseIdentifier();
  6170. }
  6171. const bodyNode = node.body = this.startNode();
  6172. const body = bodyNode.body = [];
  6173. this.expect(5);
  6174. while (!this.match(8)) {
  6175. const bodyNode = this.startNode();
  6176. if (this.match(83)) {
  6177. this.next();
  6178. if (!this.isContextual(130) && !this.match(87)) {
  6179. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  6180. }
  6181. body.push(super.parseImport(bodyNode));
  6182. } else {
  6183. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  6184. body.push(this.flowParseDeclare(bodyNode, true));
  6185. }
  6186. }
  6187. this.scope.exit();
  6188. this.expect(8);
  6189. this.finishNode(bodyNode, "BlockStatement");
  6190. let kind = null;
  6191. let hasModuleExport = false;
  6192. body.forEach(bodyElement => {
  6193. if (isEsModuleType(bodyElement)) {
  6194. if (kind === "CommonJS") {
  6195. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  6196. }
  6197. kind = "ES";
  6198. } else if (bodyElement.type === "DeclareModuleExports") {
  6199. if (hasModuleExport) {
  6200. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  6201. }
  6202. if (kind === "ES") {
  6203. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  6204. }
  6205. kind = "CommonJS";
  6206. hasModuleExport = true;
  6207. }
  6208. });
  6209. node.kind = kind || "CommonJS";
  6210. return this.finishNode(node, "DeclareModule");
  6211. }
  6212. flowParseDeclareExportDeclaration(node, insideModule) {
  6213. this.expect(82);
  6214. if (this.eat(65)) {
  6215. if (this.match(68) || this.match(80)) {
  6216. node.declaration = this.flowParseDeclare(this.startNode());
  6217. } else {
  6218. node.declaration = this.flowParseType();
  6219. this.semicolon();
  6220. }
  6221. node.default = true;
  6222. return this.finishNode(node, "DeclareExportDeclaration");
  6223. } else {
  6224. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  6225. const label = this.state.value;
  6226. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  6227. unsupportedExportKind: label,
  6228. suggestion: exportSuggestions[label]
  6229. });
  6230. }
  6231. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  6232. node.declaration = this.flowParseDeclare(this.startNode());
  6233. node.default = false;
  6234. return this.finishNode(node, "DeclareExportDeclaration");
  6235. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  6236. node = this.parseExport(node, null);
  6237. if (node.type === "ExportNamedDeclaration") {
  6238. node.default = false;
  6239. delete node.exportKind;
  6240. return this.castNodeTo(node, "DeclareExportDeclaration");
  6241. } else {
  6242. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  6243. }
  6244. }
  6245. }
  6246. throw this.unexpected();
  6247. }
  6248. flowParseDeclareModuleExports(node) {
  6249. this.next();
  6250. this.expectContextual(111);
  6251. node.typeAnnotation = this.flowParseTypeAnnotation();
  6252. this.semicolon();
  6253. return this.finishNode(node, "DeclareModuleExports");
  6254. }
  6255. flowParseDeclareTypeAlias(node) {
  6256. this.next();
  6257. const finished = this.flowParseTypeAlias(node);
  6258. this.castNodeTo(finished, "DeclareTypeAlias");
  6259. return finished;
  6260. }
  6261. flowParseDeclareOpaqueType(node) {
  6262. this.next();
  6263. const finished = this.flowParseOpaqueType(node, true);
  6264. this.castNodeTo(finished, "DeclareOpaqueType");
  6265. return finished;
  6266. }
  6267. flowParseDeclareInterface(node) {
  6268. this.next();
  6269. this.flowParseInterfaceish(node, false);
  6270. return this.finishNode(node, "DeclareInterface");
  6271. }
  6272. flowParseInterfaceish(node, isClass) {
  6273. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  6274. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  6275. if (this.match(47)) {
  6276. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6277. } else {
  6278. node.typeParameters = null;
  6279. }
  6280. node.extends = [];
  6281. if (this.eat(81)) {
  6282. do {
  6283. node.extends.push(this.flowParseInterfaceExtends());
  6284. } while (!isClass && this.eat(12));
  6285. }
  6286. if (isClass) {
  6287. node.implements = [];
  6288. node.mixins = [];
  6289. if (this.eatContextual(117)) {
  6290. do {
  6291. node.mixins.push(this.flowParseInterfaceExtends());
  6292. } while (this.eat(12));
  6293. }
  6294. if (this.eatContextual(113)) {
  6295. do {
  6296. node.implements.push(this.flowParseInterfaceExtends());
  6297. } while (this.eat(12));
  6298. }
  6299. }
  6300. node.body = this.flowParseObjectType({
  6301. allowStatic: isClass,
  6302. allowExact: false,
  6303. allowSpread: false,
  6304. allowProto: isClass,
  6305. allowInexact: false
  6306. });
  6307. }
  6308. flowParseInterfaceExtends() {
  6309. const node = this.startNode();
  6310. node.id = this.flowParseQualifiedTypeIdentifier();
  6311. if (this.match(47)) {
  6312. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6313. } else {
  6314. node.typeParameters = null;
  6315. }
  6316. return this.finishNode(node, "InterfaceExtends");
  6317. }
  6318. flowParseInterface(node) {
  6319. this.flowParseInterfaceish(node, false);
  6320. return this.finishNode(node, "InterfaceDeclaration");
  6321. }
  6322. checkNotUnderscore(word) {
  6323. if (word === "_") {
  6324. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  6325. }
  6326. }
  6327. checkReservedType(word, startLoc, declaration) {
  6328. if (!reservedTypes.has(word)) return;
  6329. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  6330. reservedType: word
  6331. });
  6332. }
  6333. flowParseRestrictedIdentifier(liberal, declaration) {
  6334. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  6335. return this.parseIdentifier(liberal);
  6336. }
  6337. flowParseTypeAlias(node) {
  6338. node.id = this.flowParseRestrictedIdentifier(false, true);
  6339. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  6340. if (this.match(47)) {
  6341. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6342. } else {
  6343. node.typeParameters = null;
  6344. }
  6345. node.right = this.flowParseTypeInitialiser(29);
  6346. this.semicolon();
  6347. return this.finishNode(node, "TypeAlias");
  6348. }
  6349. flowParseOpaqueType(node, declare) {
  6350. this.expectContextual(130);
  6351. node.id = this.flowParseRestrictedIdentifier(true, true);
  6352. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  6353. if (this.match(47)) {
  6354. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6355. } else {
  6356. node.typeParameters = null;
  6357. }
  6358. node.supertype = null;
  6359. if (this.match(14)) {
  6360. node.supertype = this.flowParseTypeInitialiser(14);
  6361. }
  6362. node.impltype = null;
  6363. if (!declare) {
  6364. node.impltype = this.flowParseTypeInitialiser(29);
  6365. }
  6366. this.semicolon();
  6367. return this.finishNode(node, "OpaqueType");
  6368. }
  6369. flowParseTypeParameter(requireDefault = false) {
  6370. const nodeStartLoc = this.state.startLoc;
  6371. const node = this.startNode();
  6372. const variance = this.flowParseVariance();
  6373. const ident = this.flowParseTypeAnnotatableIdentifier();
  6374. node.name = ident.name;
  6375. node.variance = variance;
  6376. node.bound = ident.typeAnnotation;
  6377. if (this.match(29)) {
  6378. this.eat(29);
  6379. node.default = this.flowParseType();
  6380. } else {
  6381. if (requireDefault) {
  6382. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  6383. }
  6384. }
  6385. return this.finishNode(node, "TypeParameter");
  6386. }
  6387. flowParseTypeParameterDeclaration() {
  6388. const oldInType = this.state.inType;
  6389. const node = this.startNode();
  6390. node.params = [];
  6391. this.state.inType = true;
  6392. if (this.match(47) || this.match(143)) {
  6393. this.next();
  6394. } else {
  6395. this.unexpected();
  6396. }
  6397. let defaultRequired = false;
  6398. do {
  6399. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  6400. node.params.push(typeParameter);
  6401. if (typeParameter.default) {
  6402. defaultRequired = true;
  6403. }
  6404. if (!this.match(48)) {
  6405. this.expect(12);
  6406. }
  6407. } while (!this.match(48));
  6408. this.expect(48);
  6409. this.state.inType = oldInType;
  6410. return this.finishNode(node, "TypeParameterDeclaration");
  6411. }
  6412. flowInTopLevelContext(cb) {
  6413. if (this.curContext() !== types.brace) {
  6414. const oldContext = this.state.context;
  6415. this.state.context = [oldContext[0]];
  6416. try {
  6417. return cb();
  6418. } finally {
  6419. this.state.context = oldContext;
  6420. }
  6421. } else {
  6422. return cb();
  6423. }
  6424. }
  6425. flowParseTypeParameterInstantiationInExpression() {
  6426. if (this.reScan_lt() !== 47) return;
  6427. return this.flowParseTypeParameterInstantiation();
  6428. }
  6429. flowParseTypeParameterInstantiation() {
  6430. const node = this.startNode();
  6431. const oldInType = this.state.inType;
  6432. this.state.inType = true;
  6433. node.params = [];
  6434. this.flowInTopLevelContext(() => {
  6435. this.expect(47);
  6436. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6437. this.state.noAnonFunctionType = false;
  6438. while (!this.match(48)) {
  6439. node.params.push(this.flowParseType());
  6440. if (!this.match(48)) {
  6441. this.expect(12);
  6442. }
  6443. }
  6444. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6445. });
  6446. this.state.inType = oldInType;
  6447. if (!this.state.inType && this.curContext() === types.brace) {
  6448. this.reScan_lt_gt();
  6449. }
  6450. this.expect(48);
  6451. return this.finishNode(node, "TypeParameterInstantiation");
  6452. }
  6453. flowParseTypeParameterInstantiationCallOrNew() {
  6454. if (this.reScan_lt() !== 47) return null;
  6455. const node = this.startNode();
  6456. const oldInType = this.state.inType;
  6457. node.params = [];
  6458. this.state.inType = true;
  6459. this.expect(47);
  6460. while (!this.match(48)) {
  6461. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  6462. if (!this.match(48)) {
  6463. this.expect(12);
  6464. }
  6465. }
  6466. this.expect(48);
  6467. this.state.inType = oldInType;
  6468. return this.finishNode(node, "TypeParameterInstantiation");
  6469. }
  6470. flowParseInterfaceType() {
  6471. const node = this.startNode();
  6472. this.expectContextual(129);
  6473. node.extends = [];
  6474. if (this.eat(81)) {
  6475. do {
  6476. node.extends.push(this.flowParseInterfaceExtends());
  6477. } while (this.eat(12));
  6478. }
  6479. node.body = this.flowParseObjectType({
  6480. allowStatic: false,
  6481. allowExact: false,
  6482. allowSpread: false,
  6483. allowProto: false,
  6484. allowInexact: false
  6485. });
  6486. return this.finishNode(node, "InterfaceTypeAnnotation");
  6487. }
  6488. flowParseObjectPropertyKey() {
  6489. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  6490. }
  6491. flowParseObjectTypeIndexer(node, isStatic, variance) {
  6492. node.static = isStatic;
  6493. if (this.lookahead().type === 14) {
  6494. node.id = this.flowParseObjectPropertyKey();
  6495. node.key = this.flowParseTypeInitialiser();
  6496. } else {
  6497. node.id = null;
  6498. node.key = this.flowParseType();
  6499. }
  6500. this.expect(3);
  6501. node.value = this.flowParseTypeInitialiser();
  6502. node.variance = variance;
  6503. return this.finishNode(node, "ObjectTypeIndexer");
  6504. }
  6505. flowParseObjectTypeInternalSlot(node, isStatic) {
  6506. node.static = isStatic;
  6507. node.id = this.flowParseObjectPropertyKey();
  6508. this.expect(3);
  6509. this.expect(3);
  6510. if (this.match(47) || this.match(10)) {
  6511. node.method = true;
  6512. node.optional = false;
  6513. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  6514. } else {
  6515. node.method = false;
  6516. if (this.eat(17)) {
  6517. node.optional = true;
  6518. }
  6519. node.value = this.flowParseTypeInitialiser();
  6520. }
  6521. return this.finishNode(node, "ObjectTypeInternalSlot");
  6522. }
  6523. flowParseObjectTypeMethodish(node) {
  6524. node.params = [];
  6525. node.rest = null;
  6526. node.typeParameters = null;
  6527. node.this = null;
  6528. if (this.match(47)) {
  6529. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6530. }
  6531. this.expect(10);
  6532. if (this.match(78)) {
  6533. node.this = this.flowParseFunctionTypeParam(true);
  6534. node.this.name = null;
  6535. if (!this.match(11)) {
  6536. this.expect(12);
  6537. }
  6538. }
  6539. while (!this.match(11) && !this.match(21)) {
  6540. node.params.push(this.flowParseFunctionTypeParam(false));
  6541. if (!this.match(11)) {
  6542. this.expect(12);
  6543. }
  6544. }
  6545. if (this.eat(21)) {
  6546. node.rest = this.flowParseFunctionTypeParam(false);
  6547. }
  6548. this.expect(11);
  6549. node.returnType = this.flowParseTypeInitialiser();
  6550. return this.finishNode(node, "FunctionTypeAnnotation");
  6551. }
  6552. flowParseObjectTypeCallProperty(node, isStatic) {
  6553. const valueNode = this.startNode();
  6554. node.static = isStatic;
  6555. node.value = this.flowParseObjectTypeMethodish(valueNode);
  6556. return this.finishNode(node, "ObjectTypeCallProperty");
  6557. }
  6558. flowParseObjectType({
  6559. allowStatic,
  6560. allowExact,
  6561. allowSpread,
  6562. allowProto,
  6563. allowInexact
  6564. }) {
  6565. const oldInType = this.state.inType;
  6566. this.state.inType = true;
  6567. const nodeStart = this.startNode();
  6568. nodeStart.callProperties = [];
  6569. nodeStart.properties = [];
  6570. nodeStart.indexers = [];
  6571. nodeStart.internalSlots = [];
  6572. let endDelim;
  6573. let exact;
  6574. let inexact = false;
  6575. if (allowExact && this.match(6)) {
  6576. this.expect(6);
  6577. endDelim = 9;
  6578. exact = true;
  6579. } else {
  6580. this.expect(5);
  6581. endDelim = 8;
  6582. exact = false;
  6583. }
  6584. nodeStart.exact = exact;
  6585. while (!this.match(endDelim)) {
  6586. let isStatic = false;
  6587. let protoStartLoc = null;
  6588. let inexactStartLoc = null;
  6589. const node = this.startNode();
  6590. if (allowProto && this.isContextual(118)) {
  6591. const lookahead = this.lookahead();
  6592. if (lookahead.type !== 14 && lookahead.type !== 17) {
  6593. this.next();
  6594. protoStartLoc = this.state.startLoc;
  6595. allowStatic = false;
  6596. }
  6597. }
  6598. if (allowStatic && this.isContextual(106)) {
  6599. const lookahead = this.lookahead();
  6600. if (lookahead.type !== 14 && lookahead.type !== 17) {
  6601. this.next();
  6602. isStatic = true;
  6603. }
  6604. }
  6605. const variance = this.flowParseVariance();
  6606. if (this.eat(0)) {
  6607. if (protoStartLoc != null) {
  6608. this.unexpected(protoStartLoc);
  6609. }
  6610. if (this.eat(0)) {
  6611. if (variance) {
  6612. this.unexpected(variance.loc.start);
  6613. }
  6614. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  6615. } else {
  6616. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  6617. }
  6618. } else if (this.match(10) || this.match(47)) {
  6619. if (protoStartLoc != null) {
  6620. this.unexpected(protoStartLoc);
  6621. }
  6622. if (variance) {
  6623. this.unexpected(variance.loc.start);
  6624. }
  6625. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  6626. } else {
  6627. let kind = "init";
  6628. if (this.isContextual(99) || this.isContextual(104)) {
  6629. const lookahead = this.lookahead();
  6630. if (tokenIsLiteralPropertyName(lookahead.type)) {
  6631. kind = this.state.value;
  6632. this.next();
  6633. }
  6634. }
  6635. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  6636. if (propOrInexact === null) {
  6637. inexact = true;
  6638. inexactStartLoc = this.state.lastTokStartLoc;
  6639. } else {
  6640. nodeStart.properties.push(propOrInexact);
  6641. }
  6642. }
  6643. this.flowObjectTypeSemicolon();
  6644. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  6645. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  6646. }
  6647. }
  6648. this.expect(endDelim);
  6649. if (allowSpread) {
  6650. nodeStart.inexact = inexact;
  6651. }
  6652. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  6653. this.state.inType = oldInType;
  6654. return out;
  6655. }
  6656. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  6657. if (this.eat(21)) {
  6658. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  6659. if (isInexactToken) {
  6660. if (!allowSpread) {
  6661. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  6662. } else if (!allowInexact) {
  6663. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  6664. }
  6665. if (variance) {
  6666. this.raise(FlowErrors.InexactVariance, variance);
  6667. }
  6668. return null;
  6669. }
  6670. if (!allowSpread) {
  6671. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  6672. }
  6673. if (protoStartLoc != null) {
  6674. this.unexpected(protoStartLoc);
  6675. }
  6676. if (variance) {
  6677. this.raise(FlowErrors.SpreadVariance, variance);
  6678. }
  6679. node.argument = this.flowParseType();
  6680. return this.finishNode(node, "ObjectTypeSpreadProperty");
  6681. } else {
  6682. node.key = this.flowParseObjectPropertyKey();
  6683. node.static = isStatic;
  6684. node.proto = protoStartLoc != null;
  6685. node.kind = kind;
  6686. let optional = false;
  6687. if (this.match(47) || this.match(10)) {
  6688. node.method = true;
  6689. if (protoStartLoc != null) {
  6690. this.unexpected(protoStartLoc);
  6691. }
  6692. if (variance) {
  6693. this.unexpected(variance.loc.start);
  6694. }
  6695. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  6696. if (kind === "get" || kind === "set") {
  6697. this.flowCheckGetterSetterParams(node);
  6698. }
  6699. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  6700. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  6701. }
  6702. } else {
  6703. if (kind !== "init") this.unexpected();
  6704. node.method = false;
  6705. if (this.eat(17)) {
  6706. optional = true;
  6707. }
  6708. node.value = this.flowParseTypeInitialiser();
  6709. node.variance = variance;
  6710. }
  6711. node.optional = optional;
  6712. return this.finishNode(node, "ObjectTypeProperty");
  6713. }
  6714. }
  6715. flowCheckGetterSetterParams(property) {
  6716. const paramCount = property.kind === "get" ? 0 : 1;
  6717. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  6718. if (property.value.this) {
  6719. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  6720. }
  6721. if (length !== paramCount) {
  6722. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  6723. }
  6724. if (property.kind === "set" && property.value.rest) {
  6725. this.raise(Errors.BadSetterRestParameter, property);
  6726. }
  6727. }
  6728. flowObjectTypeSemicolon() {
  6729. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  6730. this.unexpected();
  6731. }
  6732. }
  6733. flowParseQualifiedTypeIdentifier(startLoc, id) {
  6734. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  6735. let node = id || this.flowParseRestrictedIdentifier(true);
  6736. while (this.eat(16)) {
  6737. const node2 = this.startNodeAt(startLoc);
  6738. node2.qualification = node;
  6739. node2.id = this.flowParseRestrictedIdentifier(true);
  6740. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  6741. }
  6742. return node;
  6743. }
  6744. flowParseGenericType(startLoc, id) {
  6745. const node = this.startNodeAt(startLoc);
  6746. node.typeParameters = null;
  6747. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  6748. if (this.match(47)) {
  6749. node.typeParameters = this.flowParseTypeParameterInstantiation();
  6750. }
  6751. return this.finishNode(node, "GenericTypeAnnotation");
  6752. }
  6753. flowParseTypeofType() {
  6754. const node = this.startNode();
  6755. this.expect(87);
  6756. node.argument = this.flowParsePrimaryType();
  6757. return this.finishNode(node, "TypeofTypeAnnotation");
  6758. }
  6759. flowParseTupleType() {
  6760. const node = this.startNode();
  6761. node.types = [];
  6762. this.expect(0);
  6763. while (this.state.pos < this.length && !this.match(3)) {
  6764. node.types.push(this.flowParseType());
  6765. if (this.match(3)) break;
  6766. this.expect(12);
  6767. }
  6768. this.expect(3);
  6769. return this.finishNode(node, "TupleTypeAnnotation");
  6770. }
  6771. flowParseFunctionTypeParam(first) {
  6772. let name = null;
  6773. let optional = false;
  6774. let typeAnnotation = null;
  6775. const node = this.startNode();
  6776. const lh = this.lookahead();
  6777. const isThis = this.state.type === 78;
  6778. if (lh.type === 14 || lh.type === 17) {
  6779. if (isThis && !first) {
  6780. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  6781. }
  6782. name = this.parseIdentifier(isThis);
  6783. if (this.eat(17)) {
  6784. optional = true;
  6785. if (isThis) {
  6786. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  6787. }
  6788. }
  6789. typeAnnotation = this.flowParseTypeInitialiser();
  6790. } else {
  6791. typeAnnotation = this.flowParseType();
  6792. }
  6793. node.name = name;
  6794. node.optional = optional;
  6795. node.typeAnnotation = typeAnnotation;
  6796. return this.finishNode(node, "FunctionTypeParam");
  6797. }
  6798. reinterpretTypeAsFunctionTypeParam(type) {
  6799. const node = this.startNodeAt(type.loc.start);
  6800. node.name = null;
  6801. node.optional = false;
  6802. node.typeAnnotation = type;
  6803. return this.finishNode(node, "FunctionTypeParam");
  6804. }
  6805. flowParseFunctionTypeParams(params = []) {
  6806. let rest = null;
  6807. let _this = null;
  6808. if (this.match(78)) {
  6809. _this = this.flowParseFunctionTypeParam(true);
  6810. _this.name = null;
  6811. if (!this.match(11)) {
  6812. this.expect(12);
  6813. }
  6814. }
  6815. while (!this.match(11) && !this.match(21)) {
  6816. params.push(this.flowParseFunctionTypeParam(false));
  6817. if (!this.match(11)) {
  6818. this.expect(12);
  6819. }
  6820. }
  6821. if (this.eat(21)) {
  6822. rest = this.flowParseFunctionTypeParam(false);
  6823. }
  6824. return {
  6825. params,
  6826. rest,
  6827. _this
  6828. };
  6829. }
  6830. flowIdentToTypeAnnotation(startLoc, node, id) {
  6831. switch (id.name) {
  6832. case "any":
  6833. return this.finishNode(node, "AnyTypeAnnotation");
  6834. case "bool":
  6835. case "boolean":
  6836. return this.finishNode(node, "BooleanTypeAnnotation");
  6837. case "mixed":
  6838. return this.finishNode(node, "MixedTypeAnnotation");
  6839. case "empty":
  6840. return this.finishNode(node, "EmptyTypeAnnotation");
  6841. case "number":
  6842. return this.finishNode(node, "NumberTypeAnnotation");
  6843. case "string":
  6844. return this.finishNode(node, "StringTypeAnnotation");
  6845. case "symbol":
  6846. return this.finishNode(node, "SymbolTypeAnnotation");
  6847. default:
  6848. this.checkNotUnderscore(id.name);
  6849. return this.flowParseGenericType(startLoc, id);
  6850. }
  6851. }
  6852. flowParsePrimaryType() {
  6853. const startLoc = this.state.startLoc;
  6854. const node = this.startNode();
  6855. let tmp;
  6856. let type;
  6857. let isGroupedType = false;
  6858. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6859. switch (this.state.type) {
  6860. case 5:
  6861. return this.flowParseObjectType({
  6862. allowStatic: false,
  6863. allowExact: false,
  6864. allowSpread: true,
  6865. allowProto: false,
  6866. allowInexact: true
  6867. });
  6868. case 6:
  6869. return this.flowParseObjectType({
  6870. allowStatic: false,
  6871. allowExact: true,
  6872. allowSpread: true,
  6873. allowProto: false,
  6874. allowInexact: false
  6875. });
  6876. case 0:
  6877. this.state.noAnonFunctionType = false;
  6878. type = this.flowParseTupleType();
  6879. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6880. return type;
  6881. case 47:
  6882. {
  6883. const node = this.startNode();
  6884. node.typeParameters = this.flowParseTypeParameterDeclaration();
  6885. this.expect(10);
  6886. tmp = this.flowParseFunctionTypeParams();
  6887. node.params = tmp.params;
  6888. node.rest = tmp.rest;
  6889. node.this = tmp._this;
  6890. this.expect(11);
  6891. this.expect(19);
  6892. node.returnType = this.flowParseType();
  6893. return this.finishNode(node, "FunctionTypeAnnotation");
  6894. }
  6895. case 10:
  6896. {
  6897. const node = this.startNode();
  6898. this.next();
  6899. if (!this.match(11) && !this.match(21)) {
  6900. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  6901. const token = this.lookahead().type;
  6902. isGroupedType = token !== 17 && token !== 14;
  6903. } else {
  6904. isGroupedType = true;
  6905. }
  6906. }
  6907. if (isGroupedType) {
  6908. this.state.noAnonFunctionType = false;
  6909. type = this.flowParseType();
  6910. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6911. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  6912. this.expect(11);
  6913. return type;
  6914. } else {
  6915. this.eat(12);
  6916. }
  6917. }
  6918. if (type) {
  6919. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  6920. } else {
  6921. tmp = this.flowParseFunctionTypeParams();
  6922. }
  6923. node.params = tmp.params;
  6924. node.rest = tmp.rest;
  6925. node.this = tmp._this;
  6926. this.expect(11);
  6927. this.expect(19);
  6928. node.returnType = this.flowParseType();
  6929. node.typeParameters = null;
  6930. return this.finishNode(node, "FunctionTypeAnnotation");
  6931. }
  6932. case 134:
  6933. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  6934. case 85:
  6935. case 86:
  6936. node.value = this.match(85);
  6937. this.next();
  6938. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  6939. case 53:
  6940. if (this.state.value === "-") {
  6941. this.next();
  6942. if (this.match(135)) {
  6943. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  6944. }
  6945. if (this.match(136)) {
  6946. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  6947. }
  6948. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  6949. }
  6950. throw this.unexpected();
  6951. case 135:
  6952. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  6953. case 136:
  6954. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  6955. case 88:
  6956. this.next();
  6957. return this.finishNode(node, "VoidTypeAnnotation");
  6958. case 84:
  6959. this.next();
  6960. return this.finishNode(node, "NullLiteralTypeAnnotation");
  6961. case 78:
  6962. this.next();
  6963. return this.finishNode(node, "ThisTypeAnnotation");
  6964. case 55:
  6965. this.next();
  6966. return this.finishNode(node, "ExistsTypeAnnotation");
  6967. case 87:
  6968. return this.flowParseTypeofType();
  6969. default:
  6970. if (tokenIsKeyword(this.state.type)) {
  6971. const label = tokenLabelName(this.state.type);
  6972. this.next();
  6973. return super.createIdentifier(node, label);
  6974. } else if (tokenIsIdentifier(this.state.type)) {
  6975. if (this.isContextual(129)) {
  6976. return this.flowParseInterfaceType();
  6977. }
  6978. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  6979. }
  6980. }
  6981. throw this.unexpected();
  6982. }
  6983. flowParsePostfixType() {
  6984. const startLoc = this.state.startLoc;
  6985. let type = this.flowParsePrimaryType();
  6986. let seenOptionalIndexedAccess = false;
  6987. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  6988. const node = this.startNodeAt(startLoc);
  6989. const optional = this.eat(18);
  6990. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  6991. this.expect(0);
  6992. if (!optional && this.match(3)) {
  6993. node.elementType = type;
  6994. this.next();
  6995. type = this.finishNode(node, "ArrayTypeAnnotation");
  6996. } else {
  6997. node.objectType = type;
  6998. node.indexType = this.flowParseType();
  6999. this.expect(3);
  7000. if (seenOptionalIndexedAccess) {
  7001. node.optional = optional;
  7002. type = this.finishNode(node, "OptionalIndexedAccessType");
  7003. } else {
  7004. type = this.finishNode(node, "IndexedAccessType");
  7005. }
  7006. }
  7007. }
  7008. return type;
  7009. }
  7010. flowParsePrefixType() {
  7011. const node = this.startNode();
  7012. if (this.eat(17)) {
  7013. node.typeAnnotation = this.flowParsePrefixType();
  7014. return this.finishNode(node, "NullableTypeAnnotation");
  7015. } else {
  7016. return this.flowParsePostfixType();
  7017. }
  7018. }
  7019. flowParseAnonFunctionWithoutParens() {
  7020. const param = this.flowParsePrefixType();
  7021. if (!this.state.noAnonFunctionType && this.eat(19)) {
  7022. const node = this.startNodeAt(param.loc.start);
  7023. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  7024. node.rest = null;
  7025. node.this = null;
  7026. node.returnType = this.flowParseType();
  7027. node.typeParameters = null;
  7028. return this.finishNode(node, "FunctionTypeAnnotation");
  7029. }
  7030. return param;
  7031. }
  7032. flowParseIntersectionType() {
  7033. const node = this.startNode();
  7034. this.eat(45);
  7035. const type = this.flowParseAnonFunctionWithoutParens();
  7036. node.types = [type];
  7037. while (this.eat(45)) {
  7038. node.types.push(this.flowParseAnonFunctionWithoutParens());
  7039. }
  7040. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  7041. }
  7042. flowParseUnionType() {
  7043. const node = this.startNode();
  7044. this.eat(43);
  7045. const type = this.flowParseIntersectionType();
  7046. node.types = [type];
  7047. while (this.eat(43)) {
  7048. node.types.push(this.flowParseIntersectionType());
  7049. }
  7050. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  7051. }
  7052. flowParseType() {
  7053. const oldInType = this.state.inType;
  7054. this.state.inType = true;
  7055. const type = this.flowParseUnionType();
  7056. this.state.inType = oldInType;
  7057. return type;
  7058. }
  7059. flowParseTypeOrImplicitInstantiation() {
  7060. if (this.state.type === 132 && this.state.value === "_") {
  7061. const startLoc = this.state.startLoc;
  7062. const node = this.parseIdentifier();
  7063. return this.flowParseGenericType(startLoc, node);
  7064. } else {
  7065. return this.flowParseType();
  7066. }
  7067. }
  7068. flowParseTypeAnnotation() {
  7069. const node = this.startNode();
  7070. node.typeAnnotation = this.flowParseTypeInitialiser();
  7071. return this.finishNode(node, "TypeAnnotation");
  7072. }
  7073. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  7074. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  7075. if (this.match(14)) {
  7076. ident.typeAnnotation = this.flowParseTypeAnnotation();
  7077. this.resetEndLocation(ident);
  7078. }
  7079. return ident;
  7080. }
  7081. typeCastToParameter(node) {
  7082. node.expression.typeAnnotation = node.typeAnnotation;
  7083. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  7084. return node.expression;
  7085. }
  7086. flowParseVariance() {
  7087. let variance = null;
  7088. if (this.match(53)) {
  7089. variance = this.startNode();
  7090. if (this.state.value === "+") {
  7091. variance.kind = "plus";
  7092. } else {
  7093. variance.kind = "minus";
  7094. }
  7095. this.next();
  7096. return this.finishNode(variance, "Variance");
  7097. }
  7098. return variance;
  7099. }
  7100. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  7101. if (allowExpressionBody) {
  7102. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  7103. return;
  7104. }
  7105. super.parseFunctionBody(node, false, isMethod);
  7106. }
  7107. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  7108. if (this.match(14)) {
  7109. const typeNode = this.startNode();
  7110. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  7111. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  7112. }
  7113. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  7114. }
  7115. parseStatementLike(flags) {
  7116. if (this.state.strict && this.isContextual(129)) {
  7117. const lookahead = this.lookahead();
  7118. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  7119. const node = this.startNode();
  7120. this.next();
  7121. return this.flowParseInterface(node);
  7122. }
  7123. } else if (this.isContextual(126)) {
  7124. const node = this.startNode();
  7125. this.next();
  7126. return this.flowParseEnumDeclaration(node);
  7127. }
  7128. const stmt = super.parseStatementLike(flags);
  7129. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  7130. this.flowPragma = null;
  7131. }
  7132. return stmt;
  7133. }
  7134. parseExpressionStatement(node, expr, decorators) {
  7135. if (expr.type === "Identifier") {
  7136. if (expr.name === "declare") {
  7137. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  7138. return this.flowParseDeclare(node);
  7139. }
  7140. } else if (tokenIsIdentifier(this.state.type)) {
  7141. if (expr.name === "interface") {
  7142. return this.flowParseInterface(node);
  7143. } else if (expr.name === "type") {
  7144. return this.flowParseTypeAlias(node);
  7145. } else if (expr.name === "opaque") {
  7146. return this.flowParseOpaqueType(node, false);
  7147. }
  7148. }
  7149. }
  7150. return super.parseExpressionStatement(node, expr, decorators);
  7151. }
  7152. shouldParseExportDeclaration() {
  7153. const {
  7154. type
  7155. } = this.state;
  7156. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  7157. return !this.state.containsEsc;
  7158. }
  7159. return super.shouldParseExportDeclaration();
  7160. }
  7161. isExportDefaultSpecifier() {
  7162. const {
  7163. type
  7164. } = this.state;
  7165. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  7166. return this.state.containsEsc;
  7167. }
  7168. return super.isExportDefaultSpecifier();
  7169. }
  7170. parseExportDefaultExpression() {
  7171. if (this.isContextual(126)) {
  7172. const node = this.startNode();
  7173. this.next();
  7174. return this.flowParseEnumDeclaration(node);
  7175. }
  7176. return super.parseExportDefaultExpression();
  7177. }
  7178. parseConditional(expr, startLoc, refExpressionErrors) {
  7179. if (!this.match(17)) return expr;
  7180. if (this.state.maybeInArrowParameters) {
  7181. const nextCh = this.lookaheadCharCode();
  7182. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  7183. this.setOptionalParametersError(refExpressionErrors);
  7184. return expr;
  7185. }
  7186. }
  7187. this.expect(17);
  7188. const state = this.state.clone();
  7189. const originalNoArrowAt = this.state.noArrowAt;
  7190. const node = this.startNodeAt(startLoc);
  7191. let {
  7192. consequent,
  7193. failed
  7194. } = this.tryParseConditionalConsequent();
  7195. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  7196. if (failed || invalid.length > 0) {
  7197. const noArrowAt = [...originalNoArrowAt];
  7198. if (invalid.length > 0) {
  7199. this.state = state;
  7200. this.state.noArrowAt = noArrowAt;
  7201. for (let i = 0; i < invalid.length; i++) {
  7202. noArrowAt.push(invalid[i].start);
  7203. }
  7204. ({
  7205. consequent,
  7206. failed
  7207. } = this.tryParseConditionalConsequent());
  7208. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  7209. }
  7210. if (failed && valid.length > 1) {
  7211. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  7212. }
  7213. if (failed && valid.length === 1) {
  7214. this.state = state;
  7215. noArrowAt.push(valid[0].start);
  7216. this.state.noArrowAt = noArrowAt;
  7217. ({
  7218. consequent,
  7219. failed
  7220. } = this.tryParseConditionalConsequent());
  7221. }
  7222. }
  7223. this.getArrowLikeExpressions(consequent, true);
  7224. this.state.noArrowAt = originalNoArrowAt;
  7225. this.expect(14);
  7226. node.test = expr;
  7227. node.consequent = consequent;
  7228. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  7229. return this.finishNode(node, "ConditionalExpression");
  7230. }
  7231. tryParseConditionalConsequent() {
  7232. this.state.noArrowParamsConversionAt.push(this.state.start);
  7233. const consequent = this.parseMaybeAssignAllowIn();
  7234. const failed = !this.match(14);
  7235. this.state.noArrowParamsConversionAt.pop();
  7236. return {
  7237. consequent,
  7238. failed
  7239. };
  7240. }
  7241. getArrowLikeExpressions(node, disallowInvalid) {
  7242. const stack = [node];
  7243. const arrows = [];
  7244. while (stack.length !== 0) {
  7245. const node = stack.pop();
  7246. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  7247. if (node.typeParameters || !node.returnType) {
  7248. this.finishArrowValidation(node);
  7249. } else {
  7250. arrows.push(node);
  7251. }
  7252. stack.push(node.body);
  7253. } else if (node.type === "ConditionalExpression") {
  7254. stack.push(node.consequent);
  7255. stack.push(node.alternate);
  7256. }
  7257. }
  7258. if (disallowInvalid) {
  7259. arrows.forEach(node => this.finishArrowValidation(node));
  7260. return [arrows, []];
  7261. }
  7262. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  7263. }
  7264. finishArrowValidation(node) {
  7265. var _node$extra;
  7266. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  7267. this.scope.enter(514 | 4);
  7268. super.checkParams(node, false, true);
  7269. this.scope.exit();
  7270. }
  7271. forwardNoArrowParamsConversionAt(node, parse) {
  7272. let result;
  7273. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7274. this.state.noArrowParamsConversionAt.push(this.state.start);
  7275. result = parse();
  7276. this.state.noArrowParamsConversionAt.pop();
  7277. } else {
  7278. result = parse();
  7279. }
  7280. return result;
  7281. }
  7282. parseParenItem(node, startLoc) {
  7283. const newNode = super.parseParenItem(node, startLoc);
  7284. if (this.eat(17)) {
  7285. newNode.optional = true;
  7286. this.resetEndLocation(node);
  7287. }
  7288. if (this.match(14)) {
  7289. const typeCastNode = this.startNodeAt(startLoc);
  7290. typeCastNode.expression = newNode;
  7291. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  7292. return this.finishNode(typeCastNode, "TypeCastExpression");
  7293. }
  7294. return newNode;
  7295. }
  7296. assertModuleNodeAllowed(node) {
  7297. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  7298. return;
  7299. }
  7300. super.assertModuleNodeAllowed(node);
  7301. }
  7302. parseExportDeclaration(node) {
  7303. if (this.isContextual(130)) {
  7304. node.exportKind = "type";
  7305. const declarationNode = this.startNode();
  7306. this.next();
  7307. if (this.match(5)) {
  7308. node.specifiers = this.parseExportSpecifiers(true);
  7309. super.parseExportFrom(node);
  7310. return null;
  7311. } else {
  7312. return this.flowParseTypeAlias(declarationNode);
  7313. }
  7314. } else if (this.isContextual(131)) {
  7315. node.exportKind = "type";
  7316. const declarationNode = this.startNode();
  7317. this.next();
  7318. return this.flowParseOpaqueType(declarationNode, false);
  7319. } else if (this.isContextual(129)) {
  7320. node.exportKind = "type";
  7321. const declarationNode = this.startNode();
  7322. this.next();
  7323. return this.flowParseInterface(declarationNode);
  7324. } else if (this.isContextual(126)) {
  7325. node.exportKind = "value";
  7326. const declarationNode = this.startNode();
  7327. this.next();
  7328. return this.flowParseEnumDeclaration(declarationNode);
  7329. } else {
  7330. return super.parseExportDeclaration(node);
  7331. }
  7332. }
  7333. eatExportStar(node) {
  7334. if (super.eatExportStar(node)) return true;
  7335. if (this.isContextual(130) && this.lookahead().type === 55) {
  7336. node.exportKind = "type";
  7337. this.next();
  7338. this.next();
  7339. return true;
  7340. }
  7341. return false;
  7342. }
  7343. maybeParseExportNamespaceSpecifier(node) {
  7344. const {
  7345. startLoc
  7346. } = this.state;
  7347. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  7348. if (hasNamespace && node.exportKind === "type") {
  7349. this.unexpected(startLoc);
  7350. }
  7351. return hasNamespace;
  7352. }
  7353. parseClassId(node, isStatement, optionalId) {
  7354. super.parseClassId(node, isStatement, optionalId);
  7355. if (this.match(47)) {
  7356. node.typeParameters = this.flowParseTypeParameterDeclaration();
  7357. }
  7358. }
  7359. parseClassMember(classBody, member, state) {
  7360. const {
  7361. startLoc
  7362. } = this.state;
  7363. if (this.isContextual(125)) {
  7364. if (super.parseClassMemberFromModifier(classBody, member)) {
  7365. return;
  7366. }
  7367. member.declare = true;
  7368. }
  7369. super.parseClassMember(classBody, member, state);
  7370. if (member.declare) {
  7371. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  7372. this.raise(FlowErrors.DeclareClassElement, startLoc);
  7373. } else if (member.value) {
  7374. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  7375. }
  7376. }
  7377. }
  7378. isIterator(word) {
  7379. return word === "iterator" || word === "asyncIterator";
  7380. }
  7381. readIterator() {
  7382. const word = super.readWord1();
  7383. const fullWord = "@@" + word;
  7384. if (!this.isIterator(word) || !this.state.inType) {
  7385. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  7386. identifierName: fullWord
  7387. });
  7388. }
  7389. this.finishToken(132, fullWord);
  7390. }
  7391. getTokenFromCode(code) {
  7392. const next = this.input.charCodeAt(this.state.pos + 1);
  7393. if (code === 123 && next === 124) {
  7394. this.finishOp(6, 2);
  7395. } else if (this.state.inType && (code === 62 || code === 60)) {
  7396. this.finishOp(code === 62 ? 48 : 47, 1);
  7397. } else if (this.state.inType && code === 63) {
  7398. if (next === 46) {
  7399. this.finishOp(18, 2);
  7400. } else {
  7401. this.finishOp(17, 1);
  7402. }
  7403. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  7404. this.state.pos += 2;
  7405. this.readIterator();
  7406. } else {
  7407. super.getTokenFromCode(code);
  7408. }
  7409. }
  7410. isAssignable(node, isBinding) {
  7411. if (node.type === "TypeCastExpression") {
  7412. return this.isAssignable(node.expression, isBinding);
  7413. } else {
  7414. return super.isAssignable(node, isBinding);
  7415. }
  7416. }
  7417. toAssignable(node, isLHS = false) {
  7418. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  7419. node.left = this.typeCastToParameter(node.left);
  7420. }
  7421. super.toAssignable(node, isLHS);
  7422. }
  7423. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  7424. for (let i = 0; i < exprList.length; i++) {
  7425. const expr = exprList[i];
  7426. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  7427. exprList[i] = this.typeCastToParameter(expr);
  7428. }
  7429. }
  7430. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  7431. }
  7432. toReferencedList(exprList, isParenthesizedExpr) {
  7433. for (let i = 0; i < exprList.length; i++) {
  7434. var _expr$extra;
  7435. const expr = exprList[i];
  7436. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  7437. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  7438. }
  7439. }
  7440. return exprList;
  7441. }
  7442. parseArrayLike(close, isTuple, refExpressionErrors) {
  7443. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  7444. if (refExpressionErrors != null && !this.state.maybeInArrowParameters) {
  7445. this.toReferencedList(node.elements);
  7446. }
  7447. return node;
  7448. }
  7449. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  7450. return type === "TypeCastExpression" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  7451. }
  7452. parseClassProperty(node) {
  7453. if (this.match(14)) {
  7454. node.typeAnnotation = this.flowParseTypeAnnotation();
  7455. }
  7456. return super.parseClassProperty(node);
  7457. }
  7458. parseClassPrivateProperty(node) {
  7459. if (this.match(14)) {
  7460. node.typeAnnotation = this.flowParseTypeAnnotation();
  7461. }
  7462. return super.parseClassPrivateProperty(node);
  7463. }
  7464. isClassMethod() {
  7465. return this.match(47) || super.isClassMethod();
  7466. }
  7467. isClassProperty() {
  7468. return this.match(14) || super.isClassProperty();
  7469. }
  7470. isNonstaticConstructor(method) {
  7471. return !this.match(14) && super.isNonstaticConstructor(method);
  7472. }
  7473. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  7474. if (method.variance) {
  7475. this.unexpected(method.variance.loc.start);
  7476. }
  7477. delete method.variance;
  7478. if (this.match(47)) {
  7479. method.typeParameters = this.flowParseTypeParameterDeclaration();
  7480. }
  7481. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  7482. if (method.params && isConstructor) {
  7483. const params = method.params;
  7484. if (params.length > 0 && this.isThisParam(params[0])) {
  7485. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  7486. }
  7487. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  7488. const params = method.value.params;
  7489. if (params.length > 0 && this.isThisParam(params[0])) {
  7490. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  7491. }
  7492. }
  7493. }
  7494. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  7495. if (method.variance) {
  7496. this.unexpected(method.variance.loc.start);
  7497. }
  7498. delete method.variance;
  7499. if (this.match(47)) {
  7500. method.typeParameters = this.flowParseTypeParameterDeclaration();
  7501. }
  7502. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  7503. }
  7504. parseClassSuper(node) {
  7505. super.parseClassSuper(node);
  7506. if (node.superClass && (this.match(47) || this.match(51))) {
  7507. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  7508. }
  7509. if (this.isContextual(113)) {
  7510. this.next();
  7511. const implemented = node.implements = [];
  7512. do {
  7513. const node = this.startNode();
  7514. node.id = this.flowParseRestrictedIdentifier(true);
  7515. if (this.match(47)) {
  7516. node.typeParameters = this.flowParseTypeParameterInstantiation();
  7517. } else {
  7518. node.typeParameters = null;
  7519. }
  7520. implemented.push(this.finishNode(node, "ClassImplements"));
  7521. } while (this.eat(12));
  7522. }
  7523. }
  7524. checkGetterSetterParams(method) {
  7525. super.checkGetterSetterParams(method);
  7526. const params = this.getObjectOrClassMethodParams(method);
  7527. if (params.length > 0) {
  7528. const param = params[0];
  7529. if (this.isThisParam(param) && method.kind === "get") {
  7530. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  7531. } else if (this.isThisParam(param)) {
  7532. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  7533. }
  7534. }
  7535. }
  7536. parsePropertyNamePrefixOperator(node) {
  7537. node.variance = this.flowParseVariance();
  7538. }
  7539. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  7540. if (prop.variance) {
  7541. this.unexpected(prop.variance.loc.start);
  7542. }
  7543. delete prop.variance;
  7544. let typeParameters;
  7545. if (this.match(47) && !isAccessor) {
  7546. typeParameters = this.flowParseTypeParameterDeclaration();
  7547. if (!this.match(10)) this.unexpected();
  7548. }
  7549. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  7550. if (typeParameters) {
  7551. (result.value || result).typeParameters = typeParameters;
  7552. }
  7553. return result;
  7554. }
  7555. parseFunctionParamType(param) {
  7556. if (this.eat(17)) {
  7557. if (param.type !== "Identifier") {
  7558. this.raise(FlowErrors.PatternIsOptional, param);
  7559. }
  7560. if (this.isThisParam(param)) {
  7561. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  7562. }
  7563. param.optional = true;
  7564. }
  7565. if (this.match(14)) {
  7566. param.typeAnnotation = this.flowParseTypeAnnotation();
  7567. } else if (this.isThisParam(param)) {
  7568. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  7569. }
  7570. if (this.match(29) && this.isThisParam(param)) {
  7571. this.raise(FlowErrors.ThisParamNoDefault, param);
  7572. }
  7573. this.resetEndLocation(param);
  7574. return param;
  7575. }
  7576. parseMaybeDefault(startLoc, left) {
  7577. const node = super.parseMaybeDefault(startLoc, left);
  7578. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  7579. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  7580. }
  7581. return node;
  7582. }
  7583. checkImportReflection(node) {
  7584. super.checkImportReflection(node);
  7585. if (node.module && node.importKind !== "value") {
  7586. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  7587. }
  7588. }
  7589. parseImportSpecifierLocal(node, specifier, type) {
  7590. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  7591. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  7592. }
  7593. isPotentialImportPhase(isExport) {
  7594. if (super.isPotentialImportPhase(isExport)) return true;
  7595. if (this.isContextual(130)) {
  7596. if (!isExport) return true;
  7597. const ch = this.lookaheadCharCode();
  7598. return ch === 123 || ch === 42;
  7599. }
  7600. return !isExport && this.isContextual(87);
  7601. }
  7602. applyImportPhase(node, isExport, phase, loc) {
  7603. super.applyImportPhase(node, isExport, phase, loc);
  7604. if (isExport) {
  7605. if (!phase && this.match(65)) {
  7606. return;
  7607. }
  7608. node.exportKind = phase === "type" ? phase : "value";
  7609. } else {
  7610. if (phase === "type" && this.match(55)) this.unexpected();
  7611. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  7612. }
  7613. }
  7614. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  7615. const firstIdent = specifier.imported;
  7616. let specifierTypeKind = null;
  7617. if (firstIdent.type === "Identifier") {
  7618. if (firstIdent.name === "type") {
  7619. specifierTypeKind = "type";
  7620. } else if (firstIdent.name === "typeof") {
  7621. specifierTypeKind = "typeof";
  7622. }
  7623. }
  7624. let isBinding = false;
  7625. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  7626. const as_ident = this.parseIdentifier(true);
  7627. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  7628. specifier.imported = as_ident;
  7629. specifier.importKind = specifierTypeKind;
  7630. specifier.local = this.cloneIdentifier(as_ident);
  7631. } else {
  7632. specifier.imported = firstIdent;
  7633. specifier.importKind = null;
  7634. specifier.local = this.parseIdentifier();
  7635. }
  7636. } else {
  7637. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  7638. specifier.imported = this.parseIdentifier(true);
  7639. specifier.importKind = specifierTypeKind;
  7640. } else {
  7641. if (importedIsString) {
  7642. throw this.raise(Errors.ImportBindingIsString, specifier, {
  7643. importName: firstIdent.value
  7644. });
  7645. }
  7646. specifier.imported = firstIdent;
  7647. specifier.importKind = null;
  7648. }
  7649. if (this.eatContextual(93)) {
  7650. specifier.local = this.parseIdentifier();
  7651. } else {
  7652. isBinding = true;
  7653. specifier.local = this.cloneIdentifier(specifier.imported);
  7654. }
  7655. }
  7656. const specifierIsTypeImport = hasTypeImportKind(specifier);
  7657. if (isInTypeOnlyImport && specifierIsTypeImport) {
  7658. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  7659. }
  7660. if (isInTypeOnlyImport || specifierIsTypeImport) {
  7661. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  7662. }
  7663. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  7664. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  7665. }
  7666. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  7667. }
  7668. parseBindingAtom() {
  7669. switch (this.state.type) {
  7670. case 78:
  7671. return this.parseIdentifier(true);
  7672. default:
  7673. return super.parseBindingAtom();
  7674. }
  7675. }
  7676. parseFunctionParams(node, isConstructor) {
  7677. const kind = node.kind;
  7678. if (kind !== "get" && kind !== "set" && this.match(47)) {
  7679. node.typeParameters = this.flowParseTypeParameterDeclaration();
  7680. }
  7681. super.parseFunctionParams(node, isConstructor);
  7682. }
  7683. parseVarId(decl, kind) {
  7684. super.parseVarId(decl, kind);
  7685. if (this.match(14)) {
  7686. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  7687. this.resetEndLocation(decl.id);
  7688. }
  7689. }
  7690. parseAsyncArrowFromCallExpression(node, call) {
  7691. if (this.match(14)) {
  7692. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  7693. this.state.noAnonFunctionType = true;
  7694. node.returnType = this.flowParseTypeAnnotation();
  7695. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  7696. }
  7697. return super.parseAsyncArrowFromCallExpression(node, call);
  7698. }
  7699. shouldParseAsyncArrow() {
  7700. return this.match(14) || super.shouldParseAsyncArrow();
  7701. }
  7702. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  7703. var _jsx;
  7704. let state = null;
  7705. let jsx;
  7706. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  7707. state = this.state.clone();
  7708. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  7709. if (!jsx.error) return jsx.node;
  7710. const {
  7711. context
  7712. } = this.state;
  7713. const currentContext = context[context.length - 1];
  7714. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  7715. context.pop();
  7716. }
  7717. }
  7718. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  7719. var _jsx2, _jsx3;
  7720. state = state || this.state.clone();
  7721. let typeParameters;
  7722. const arrow = this.tryParse(abort => {
  7723. var _arrowExpression$extr;
  7724. typeParameters = this.flowParseTypeParameterDeclaration();
  7725. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  7726. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  7727. this.resetStartLocationFromNode(result, typeParameters);
  7728. return result;
  7729. });
  7730. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  7731. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  7732. if (expr.type !== "ArrowFunctionExpression") abort();
  7733. expr.typeParameters = typeParameters;
  7734. this.resetStartLocationFromNode(expr, typeParameters);
  7735. return arrowExpression;
  7736. }, state);
  7737. let arrowExpression = null;
  7738. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  7739. if (!arrow.error && !arrow.aborted) {
  7740. if (arrow.node.async) {
  7741. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  7742. }
  7743. return arrow.node;
  7744. }
  7745. arrowExpression = arrow.node;
  7746. }
  7747. if ((_jsx2 = jsx) != null && _jsx2.node) {
  7748. this.state = jsx.failState;
  7749. return jsx.node;
  7750. }
  7751. if (arrowExpression) {
  7752. this.state = arrow.failState;
  7753. return arrowExpression;
  7754. }
  7755. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  7756. if (arrow.thrown) throw arrow.error;
  7757. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  7758. }
  7759. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  7760. }
  7761. parseArrow(node) {
  7762. if (this.match(14)) {
  7763. const result = this.tryParse(() => {
  7764. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  7765. this.state.noAnonFunctionType = true;
  7766. const typeNode = this.startNode();
  7767. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  7768. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  7769. if (this.canInsertSemicolon()) this.unexpected();
  7770. if (!this.match(19)) this.unexpected();
  7771. return typeNode;
  7772. });
  7773. if (result.thrown) return null;
  7774. if (result.error) this.state = result.failState;
  7775. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  7776. }
  7777. return super.parseArrow(node);
  7778. }
  7779. shouldParseArrow(params) {
  7780. return this.match(14) || super.shouldParseArrow(params);
  7781. }
  7782. setArrowFunctionParameters(node, params) {
  7783. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7784. node.params = params;
  7785. } else {
  7786. super.setArrowFunctionParameters(node, params);
  7787. }
  7788. }
  7789. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  7790. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  7791. return;
  7792. }
  7793. for (let i = 0; i < node.params.length; i++) {
  7794. if (this.isThisParam(node.params[i]) && i > 0) {
  7795. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  7796. }
  7797. }
  7798. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  7799. }
  7800. parseParenAndDistinguishExpression(canBeArrow) {
  7801. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  7802. }
  7803. parseSubscripts(base, startLoc, noCalls) {
  7804. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  7805. this.next();
  7806. const node = this.startNodeAt(startLoc);
  7807. node.callee = base;
  7808. node.arguments = super.parseCallExpressionArguments();
  7809. base = this.finishNode(node, "CallExpression");
  7810. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  7811. const state = this.state.clone();
  7812. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  7813. if (!arrow.error && !arrow.aborted) return arrow.node;
  7814. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  7815. if (result.node && !result.error) return result.node;
  7816. if (arrow.node) {
  7817. this.state = arrow.failState;
  7818. return arrow.node;
  7819. }
  7820. if (result.node) {
  7821. this.state = result.failState;
  7822. return result.node;
  7823. }
  7824. throw arrow.error || result.error;
  7825. }
  7826. return super.parseSubscripts(base, startLoc, noCalls);
  7827. }
  7828. parseSubscript(base, startLoc, noCalls, subscriptState) {
  7829. if (this.match(18) && this.isLookaheadToken_lt()) {
  7830. subscriptState.optionalChainMember = true;
  7831. if (noCalls) {
  7832. subscriptState.stop = true;
  7833. return base;
  7834. }
  7835. this.next();
  7836. const node = this.startNodeAt(startLoc);
  7837. node.callee = base;
  7838. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  7839. this.expect(10);
  7840. node.arguments = this.parseCallExpressionArguments();
  7841. node.optional = true;
  7842. return this.finishCallExpression(node, true);
  7843. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  7844. const node = this.startNodeAt(startLoc);
  7845. node.callee = base;
  7846. const result = this.tryParse(() => {
  7847. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  7848. this.expect(10);
  7849. node.arguments = super.parseCallExpressionArguments();
  7850. if (subscriptState.optionalChainMember) {
  7851. node.optional = false;
  7852. }
  7853. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  7854. });
  7855. if (result.node) {
  7856. if (result.error) this.state = result.failState;
  7857. return result.node;
  7858. }
  7859. }
  7860. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  7861. }
  7862. parseNewCallee(node) {
  7863. super.parseNewCallee(node);
  7864. let targs = null;
  7865. if (this.shouldParseTypes() && this.match(47)) {
  7866. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  7867. }
  7868. node.typeArguments = targs;
  7869. }
  7870. parseAsyncArrowWithTypeParameters(startLoc) {
  7871. const node = this.startNodeAt(startLoc);
  7872. this.parseFunctionParams(node, false);
  7873. if (!this.parseArrow(node)) return;
  7874. return super.parseArrowExpression(node, undefined, true);
  7875. }
  7876. readToken_mult_modulo(code) {
  7877. const next = this.input.charCodeAt(this.state.pos + 1);
  7878. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  7879. this.state.hasFlowComment = false;
  7880. this.state.pos += 2;
  7881. this.nextToken();
  7882. return;
  7883. }
  7884. super.readToken_mult_modulo(code);
  7885. }
  7886. readToken_pipe_amp(code) {
  7887. const next = this.input.charCodeAt(this.state.pos + 1);
  7888. if (code === 124 && next === 125) {
  7889. this.finishOp(9, 2);
  7890. return;
  7891. }
  7892. super.readToken_pipe_amp(code);
  7893. }
  7894. parseTopLevel(file, program) {
  7895. const fileNode = super.parseTopLevel(file, program);
  7896. if (this.state.hasFlowComment) {
  7897. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  7898. }
  7899. return fileNode;
  7900. }
  7901. skipBlockComment() {
  7902. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  7903. if (this.state.hasFlowComment) {
  7904. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  7905. }
  7906. this.hasFlowCommentCompletion();
  7907. const commentSkip = this.skipFlowComment();
  7908. if (commentSkip) {
  7909. this.state.pos += commentSkip;
  7910. this.state.hasFlowComment = true;
  7911. }
  7912. return;
  7913. }
  7914. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  7915. }
  7916. skipFlowComment() {
  7917. const {
  7918. pos
  7919. } = this.state;
  7920. let shiftToFirstNonWhiteSpace = 2;
  7921. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  7922. shiftToFirstNonWhiteSpace++;
  7923. }
  7924. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  7925. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  7926. if (ch2 === 58 && ch3 === 58) {
  7927. return shiftToFirstNonWhiteSpace + 2;
  7928. }
  7929. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  7930. return shiftToFirstNonWhiteSpace + 12;
  7931. }
  7932. if (ch2 === 58 && ch3 !== 58) {
  7933. return shiftToFirstNonWhiteSpace;
  7934. }
  7935. return false;
  7936. }
  7937. hasFlowCommentCompletion() {
  7938. const end = this.input.indexOf("*/", this.state.pos);
  7939. if (end === -1) {
  7940. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  7941. }
  7942. }
  7943. flowEnumErrorBooleanMemberNotInitialized(loc, {
  7944. enumName,
  7945. memberName
  7946. }) {
  7947. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  7948. memberName,
  7949. enumName
  7950. });
  7951. }
  7952. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  7953. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  7954. }
  7955. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  7956. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  7957. }
  7958. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  7959. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  7960. }
  7961. flowEnumMemberInit() {
  7962. const startLoc = this.state.startLoc;
  7963. const endOfInit = () => this.match(12) || this.match(8);
  7964. switch (this.state.type) {
  7965. case 135:
  7966. {
  7967. const literal = this.parseNumericLiteral(this.state.value);
  7968. if (endOfInit()) {
  7969. return {
  7970. type: "number",
  7971. loc: literal.loc.start,
  7972. value: literal
  7973. };
  7974. }
  7975. return {
  7976. type: "invalid",
  7977. loc: startLoc
  7978. };
  7979. }
  7980. case 134:
  7981. {
  7982. const literal = this.parseStringLiteral(this.state.value);
  7983. if (endOfInit()) {
  7984. return {
  7985. type: "string",
  7986. loc: literal.loc.start,
  7987. value: literal
  7988. };
  7989. }
  7990. return {
  7991. type: "invalid",
  7992. loc: startLoc
  7993. };
  7994. }
  7995. case 85:
  7996. case 86:
  7997. {
  7998. const literal = this.parseBooleanLiteral(this.match(85));
  7999. if (endOfInit()) {
  8000. return {
  8001. type: "boolean",
  8002. loc: literal.loc.start,
  8003. value: literal
  8004. };
  8005. }
  8006. return {
  8007. type: "invalid",
  8008. loc: startLoc
  8009. };
  8010. }
  8011. default:
  8012. return {
  8013. type: "invalid",
  8014. loc: startLoc
  8015. };
  8016. }
  8017. }
  8018. flowEnumMemberRaw() {
  8019. const loc = this.state.startLoc;
  8020. const id = this.parseIdentifier(true);
  8021. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  8022. type: "none",
  8023. loc
  8024. };
  8025. return {
  8026. id,
  8027. init
  8028. };
  8029. }
  8030. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  8031. const {
  8032. explicitType
  8033. } = context;
  8034. if (explicitType === null) {
  8035. return;
  8036. }
  8037. if (explicitType !== expectedType) {
  8038. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  8039. }
  8040. }
  8041. flowEnumMembers({
  8042. enumName,
  8043. explicitType
  8044. }) {
  8045. const seenNames = new Set();
  8046. const members = {
  8047. booleanMembers: [],
  8048. numberMembers: [],
  8049. stringMembers: [],
  8050. defaultedMembers: []
  8051. };
  8052. let hasUnknownMembers = false;
  8053. while (!this.match(8)) {
  8054. if (this.eat(21)) {
  8055. hasUnknownMembers = true;
  8056. break;
  8057. }
  8058. const memberNode = this.startNode();
  8059. const {
  8060. id,
  8061. init
  8062. } = this.flowEnumMemberRaw();
  8063. const memberName = id.name;
  8064. if (memberName === "") {
  8065. continue;
  8066. }
  8067. if (/^[a-z]/.test(memberName)) {
  8068. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  8069. memberName,
  8070. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  8071. enumName
  8072. });
  8073. }
  8074. if (seenNames.has(memberName)) {
  8075. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  8076. memberName,
  8077. enumName
  8078. });
  8079. }
  8080. seenNames.add(memberName);
  8081. const context = {
  8082. enumName,
  8083. explicitType,
  8084. memberName
  8085. };
  8086. memberNode.id = id;
  8087. switch (init.type) {
  8088. case "boolean":
  8089. {
  8090. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  8091. memberNode.init = init.value;
  8092. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  8093. break;
  8094. }
  8095. case "number":
  8096. {
  8097. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  8098. memberNode.init = init.value;
  8099. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  8100. break;
  8101. }
  8102. case "string":
  8103. {
  8104. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  8105. memberNode.init = init.value;
  8106. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  8107. break;
  8108. }
  8109. case "invalid":
  8110. {
  8111. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  8112. }
  8113. case "none":
  8114. {
  8115. switch (explicitType) {
  8116. case "boolean":
  8117. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  8118. break;
  8119. case "number":
  8120. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  8121. break;
  8122. default:
  8123. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  8124. }
  8125. }
  8126. }
  8127. if (!this.match(8)) {
  8128. this.expect(12);
  8129. }
  8130. }
  8131. return {
  8132. members,
  8133. hasUnknownMembers
  8134. };
  8135. }
  8136. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  8137. enumName
  8138. }) {
  8139. if (initializedMembers.length === 0) {
  8140. return defaultedMembers;
  8141. } else if (defaultedMembers.length === 0) {
  8142. return initializedMembers;
  8143. } else if (defaultedMembers.length > initializedMembers.length) {
  8144. for (const member of initializedMembers) {
  8145. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  8146. enumName
  8147. });
  8148. }
  8149. return defaultedMembers;
  8150. } else {
  8151. for (const member of defaultedMembers) {
  8152. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  8153. enumName
  8154. });
  8155. }
  8156. return initializedMembers;
  8157. }
  8158. }
  8159. flowEnumParseExplicitType({
  8160. enumName
  8161. }) {
  8162. if (!this.eatContextual(102)) return null;
  8163. if (!tokenIsIdentifier(this.state.type)) {
  8164. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  8165. enumName
  8166. });
  8167. }
  8168. const {
  8169. value
  8170. } = this.state;
  8171. this.next();
  8172. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  8173. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  8174. enumName,
  8175. invalidEnumType: value
  8176. });
  8177. }
  8178. return value;
  8179. }
  8180. flowEnumBody(node, id) {
  8181. const enumName = id.name;
  8182. const nameLoc = id.loc.start;
  8183. const explicitType = this.flowEnumParseExplicitType({
  8184. enumName
  8185. });
  8186. this.expect(5);
  8187. const {
  8188. members,
  8189. hasUnknownMembers
  8190. } = this.flowEnumMembers({
  8191. enumName,
  8192. explicitType
  8193. });
  8194. node.hasUnknownMembers = hasUnknownMembers;
  8195. switch (explicitType) {
  8196. case "boolean":
  8197. node.explicitType = true;
  8198. node.members = members.booleanMembers;
  8199. this.expect(8);
  8200. return this.finishNode(node, "EnumBooleanBody");
  8201. case "number":
  8202. node.explicitType = true;
  8203. node.members = members.numberMembers;
  8204. this.expect(8);
  8205. return this.finishNode(node, "EnumNumberBody");
  8206. case "string":
  8207. node.explicitType = true;
  8208. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  8209. enumName
  8210. });
  8211. this.expect(8);
  8212. return this.finishNode(node, "EnumStringBody");
  8213. case "symbol":
  8214. node.members = members.defaultedMembers;
  8215. this.expect(8);
  8216. return this.finishNode(node, "EnumSymbolBody");
  8217. default:
  8218. {
  8219. const empty = () => {
  8220. node.members = [];
  8221. this.expect(8);
  8222. return this.finishNode(node, "EnumStringBody");
  8223. };
  8224. node.explicitType = false;
  8225. const boolsLen = members.booleanMembers.length;
  8226. const numsLen = members.numberMembers.length;
  8227. const strsLen = members.stringMembers.length;
  8228. const defaultedLen = members.defaultedMembers.length;
  8229. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  8230. return empty();
  8231. } else if (!boolsLen && !numsLen) {
  8232. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  8233. enumName
  8234. });
  8235. this.expect(8);
  8236. return this.finishNode(node, "EnumStringBody");
  8237. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  8238. for (const member of members.defaultedMembers) {
  8239. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  8240. enumName,
  8241. memberName: member.id.name
  8242. });
  8243. }
  8244. node.members = members.booleanMembers;
  8245. this.expect(8);
  8246. return this.finishNode(node, "EnumBooleanBody");
  8247. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  8248. for (const member of members.defaultedMembers) {
  8249. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  8250. enumName,
  8251. memberName: member.id.name
  8252. });
  8253. }
  8254. node.members = members.numberMembers;
  8255. this.expect(8);
  8256. return this.finishNode(node, "EnumNumberBody");
  8257. } else {
  8258. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  8259. enumName
  8260. });
  8261. return empty();
  8262. }
  8263. }
  8264. }
  8265. }
  8266. flowParseEnumDeclaration(node) {
  8267. const id = this.parseIdentifier();
  8268. node.id = id;
  8269. node.body = this.flowEnumBody(this.startNode(), id);
  8270. return this.finishNode(node, "EnumDeclaration");
  8271. }
  8272. jsxParseOpeningElementAfterName(node) {
  8273. if (this.shouldParseTypes()) {
  8274. if (this.match(47) || this.match(51)) {
  8275. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  8276. }
  8277. }
  8278. return super.jsxParseOpeningElementAfterName(node);
  8279. }
  8280. isLookaheadToken_lt() {
  8281. const next = this.nextTokenStart();
  8282. if (this.input.charCodeAt(next) === 60) {
  8283. const afterNext = this.input.charCodeAt(next + 1);
  8284. return afterNext !== 60 && afterNext !== 61;
  8285. }
  8286. return false;
  8287. }
  8288. reScan_lt_gt() {
  8289. const {
  8290. type
  8291. } = this.state;
  8292. if (type === 47) {
  8293. this.state.pos -= 1;
  8294. this.readToken_lt();
  8295. } else if (type === 48) {
  8296. this.state.pos -= 1;
  8297. this.readToken_gt();
  8298. }
  8299. }
  8300. reScan_lt() {
  8301. const {
  8302. type
  8303. } = this.state;
  8304. if (type === 51) {
  8305. this.state.pos -= 2;
  8306. this.finishOp(47, 1);
  8307. return 47;
  8308. }
  8309. return type;
  8310. }
  8311. maybeUnwrapTypeCastExpression(node) {
  8312. return node.type === "TypeCastExpression" ? node.expression : node;
  8313. }
  8314. };
  8315. const entities = {
  8316. __proto__: null,
  8317. quot: "\u0022",
  8318. amp: "&",
  8319. apos: "\u0027",
  8320. lt: "<",
  8321. gt: ">",
  8322. nbsp: "\u00A0",
  8323. iexcl: "\u00A1",
  8324. cent: "\u00A2",
  8325. pound: "\u00A3",
  8326. curren: "\u00A4",
  8327. yen: "\u00A5",
  8328. brvbar: "\u00A6",
  8329. sect: "\u00A7",
  8330. uml: "\u00A8",
  8331. copy: "\u00A9",
  8332. ordf: "\u00AA",
  8333. laquo: "\u00AB",
  8334. not: "\u00AC",
  8335. shy: "\u00AD",
  8336. reg: "\u00AE",
  8337. macr: "\u00AF",
  8338. deg: "\u00B0",
  8339. plusmn: "\u00B1",
  8340. sup2: "\u00B2",
  8341. sup3: "\u00B3",
  8342. acute: "\u00B4",
  8343. micro: "\u00B5",
  8344. para: "\u00B6",
  8345. middot: "\u00B7",
  8346. cedil: "\u00B8",
  8347. sup1: "\u00B9",
  8348. ordm: "\u00BA",
  8349. raquo: "\u00BB",
  8350. frac14: "\u00BC",
  8351. frac12: "\u00BD",
  8352. frac34: "\u00BE",
  8353. iquest: "\u00BF",
  8354. Agrave: "\u00C0",
  8355. Aacute: "\u00C1",
  8356. Acirc: "\u00C2",
  8357. Atilde: "\u00C3",
  8358. Auml: "\u00C4",
  8359. Aring: "\u00C5",
  8360. AElig: "\u00C6",
  8361. Ccedil: "\u00C7",
  8362. Egrave: "\u00C8",
  8363. Eacute: "\u00C9",
  8364. Ecirc: "\u00CA",
  8365. Euml: "\u00CB",
  8366. Igrave: "\u00CC",
  8367. Iacute: "\u00CD",
  8368. Icirc: "\u00CE",
  8369. Iuml: "\u00CF",
  8370. ETH: "\u00D0",
  8371. Ntilde: "\u00D1",
  8372. Ograve: "\u00D2",
  8373. Oacute: "\u00D3",
  8374. Ocirc: "\u00D4",
  8375. Otilde: "\u00D5",
  8376. Ouml: "\u00D6",
  8377. times: "\u00D7",
  8378. Oslash: "\u00D8",
  8379. Ugrave: "\u00D9",
  8380. Uacute: "\u00DA",
  8381. Ucirc: "\u00DB",
  8382. Uuml: "\u00DC",
  8383. Yacute: "\u00DD",
  8384. THORN: "\u00DE",
  8385. szlig: "\u00DF",
  8386. agrave: "\u00E0",
  8387. aacute: "\u00E1",
  8388. acirc: "\u00E2",
  8389. atilde: "\u00E3",
  8390. auml: "\u00E4",
  8391. aring: "\u00E5",
  8392. aelig: "\u00E6",
  8393. ccedil: "\u00E7",
  8394. egrave: "\u00E8",
  8395. eacute: "\u00E9",
  8396. ecirc: "\u00EA",
  8397. euml: "\u00EB",
  8398. igrave: "\u00EC",
  8399. iacute: "\u00ED",
  8400. icirc: "\u00EE",
  8401. iuml: "\u00EF",
  8402. eth: "\u00F0",
  8403. ntilde: "\u00F1",
  8404. ograve: "\u00F2",
  8405. oacute: "\u00F3",
  8406. ocirc: "\u00F4",
  8407. otilde: "\u00F5",
  8408. ouml: "\u00F6",
  8409. divide: "\u00F7",
  8410. oslash: "\u00F8",
  8411. ugrave: "\u00F9",
  8412. uacute: "\u00FA",
  8413. ucirc: "\u00FB",
  8414. uuml: "\u00FC",
  8415. yacute: "\u00FD",
  8416. thorn: "\u00FE",
  8417. yuml: "\u00FF",
  8418. OElig: "\u0152",
  8419. oelig: "\u0153",
  8420. Scaron: "\u0160",
  8421. scaron: "\u0161",
  8422. Yuml: "\u0178",
  8423. fnof: "\u0192",
  8424. circ: "\u02C6",
  8425. tilde: "\u02DC",
  8426. Alpha: "\u0391",
  8427. Beta: "\u0392",
  8428. Gamma: "\u0393",
  8429. Delta: "\u0394",
  8430. Epsilon: "\u0395",
  8431. Zeta: "\u0396",
  8432. Eta: "\u0397",
  8433. Theta: "\u0398",
  8434. Iota: "\u0399",
  8435. Kappa: "\u039A",
  8436. Lambda: "\u039B",
  8437. Mu: "\u039C",
  8438. Nu: "\u039D",
  8439. Xi: "\u039E",
  8440. Omicron: "\u039F",
  8441. Pi: "\u03A0",
  8442. Rho: "\u03A1",
  8443. Sigma: "\u03A3",
  8444. Tau: "\u03A4",
  8445. Upsilon: "\u03A5",
  8446. Phi: "\u03A6",
  8447. Chi: "\u03A7",
  8448. Psi: "\u03A8",
  8449. Omega: "\u03A9",
  8450. alpha: "\u03B1",
  8451. beta: "\u03B2",
  8452. gamma: "\u03B3",
  8453. delta: "\u03B4",
  8454. epsilon: "\u03B5",
  8455. zeta: "\u03B6",
  8456. eta: "\u03B7",
  8457. theta: "\u03B8",
  8458. iota: "\u03B9",
  8459. kappa: "\u03BA",
  8460. lambda: "\u03BB",
  8461. mu: "\u03BC",
  8462. nu: "\u03BD",
  8463. xi: "\u03BE",
  8464. omicron: "\u03BF",
  8465. pi: "\u03C0",
  8466. rho: "\u03C1",
  8467. sigmaf: "\u03C2",
  8468. sigma: "\u03C3",
  8469. tau: "\u03C4",
  8470. upsilon: "\u03C5",
  8471. phi: "\u03C6",
  8472. chi: "\u03C7",
  8473. psi: "\u03C8",
  8474. omega: "\u03C9",
  8475. thetasym: "\u03D1",
  8476. upsih: "\u03D2",
  8477. piv: "\u03D6",
  8478. ensp: "\u2002",
  8479. emsp: "\u2003",
  8480. thinsp: "\u2009",
  8481. zwnj: "\u200C",
  8482. zwj: "\u200D",
  8483. lrm: "\u200E",
  8484. rlm: "\u200F",
  8485. ndash: "\u2013",
  8486. mdash: "\u2014",
  8487. lsquo: "\u2018",
  8488. rsquo: "\u2019",
  8489. sbquo: "\u201A",
  8490. ldquo: "\u201C",
  8491. rdquo: "\u201D",
  8492. bdquo: "\u201E",
  8493. dagger: "\u2020",
  8494. Dagger: "\u2021",
  8495. bull: "\u2022",
  8496. hellip: "\u2026",
  8497. permil: "\u2030",
  8498. prime: "\u2032",
  8499. Prime: "\u2033",
  8500. lsaquo: "\u2039",
  8501. rsaquo: "\u203A",
  8502. oline: "\u203E",
  8503. frasl: "\u2044",
  8504. euro: "\u20AC",
  8505. image: "\u2111",
  8506. weierp: "\u2118",
  8507. real: "\u211C",
  8508. trade: "\u2122",
  8509. alefsym: "\u2135",
  8510. larr: "\u2190",
  8511. uarr: "\u2191",
  8512. rarr: "\u2192",
  8513. darr: "\u2193",
  8514. harr: "\u2194",
  8515. crarr: "\u21B5",
  8516. lArr: "\u21D0",
  8517. uArr: "\u21D1",
  8518. rArr: "\u21D2",
  8519. dArr: "\u21D3",
  8520. hArr: "\u21D4",
  8521. forall: "\u2200",
  8522. part: "\u2202",
  8523. exist: "\u2203",
  8524. empty: "\u2205",
  8525. nabla: "\u2207",
  8526. isin: "\u2208",
  8527. notin: "\u2209",
  8528. ni: "\u220B",
  8529. prod: "\u220F",
  8530. sum: "\u2211",
  8531. minus: "\u2212",
  8532. lowast: "\u2217",
  8533. radic: "\u221A",
  8534. prop: "\u221D",
  8535. infin: "\u221E",
  8536. ang: "\u2220",
  8537. and: "\u2227",
  8538. or: "\u2228",
  8539. cap: "\u2229",
  8540. cup: "\u222A",
  8541. int: "\u222B",
  8542. there4: "\u2234",
  8543. sim: "\u223C",
  8544. cong: "\u2245",
  8545. asymp: "\u2248",
  8546. ne: "\u2260",
  8547. equiv: "\u2261",
  8548. le: "\u2264",
  8549. ge: "\u2265",
  8550. sub: "\u2282",
  8551. sup: "\u2283",
  8552. nsub: "\u2284",
  8553. sube: "\u2286",
  8554. supe: "\u2287",
  8555. oplus: "\u2295",
  8556. otimes: "\u2297",
  8557. perp: "\u22A5",
  8558. sdot: "\u22C5",
  8559. lceil: "\u2308",
  8560. rceil: "\u2309",
  8561. lfloor: "\u230A",
  8562. rfloor: "\u230B",
  8563. lang: "\u2329",
  8564. rang: "\u232A",
  8565. loz: "\u25CA",
  8566. spades: "\u2660",
  8567. clubs: "\u2663",
  8568. hearts: "\u2665",
  8569. diams: "\u2666"
  8570. };
  8571. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  8572. const lineBreakG = new RegExp(lineBreak.source, "g");
  8573. function isNewLine(code) {
  8574. switch (code) {
  8575. case 10:
  8576. case 13:
  8577. case 8232:
  8578. case 8233:
  8579. return true;
  8580. default:
  8581. return false;
  8582. }
  8583. }
  8584. function hasNewLine(input, start, end) {
  8585. for (let i = start; i < end; i++) {
  8586. if (isNewLine(input.charCodeAt(i))) {
  8587. return true;
  8588. }
  8589. }
  8590. return false;
  8591. }
  8592. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  8593. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  8594. function isWhitespace(code) {
  8595. switch (code) {
  8596. case 0x0009:
  8597. case 0x000b:
  8598. case 0x000c:
  8599. case 32:
  8600. case 160:
  8601. case 5760:
  8602. case 0x2000:
  8603. case 0x2001:
  8604. case 0x2002:
  8605. case 0x2003:
  8606. case 0x2004:
  8607. case 0x2005:
  8608. case 0x2006:
  8609. case 0x2007:
  8610. case 0x2008:
  8611. case 0x2009:
  8612. case 0x200a:
  8613. case 0x202f:
  8614. case 0x205f:
  8615. case 0x3000:
  8616. case 0xfeff:
  8617. return true;
  8618. default:
  8619. return false;
  8620. }
  8621. }
  8622. const JsxErrors = ParseErrorEnum`jsx`({
  8623. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  8624. MissingClosingTagElement: ({
  8625. openingTagName
  8626. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  8627. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  8628. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  8629. UnexpectedToken: ({
  8630. unexpected,
  8631. HTMLEntity
  8632. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  8633. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  8634. UnterminatedJsxContent: "Unterminated JSX contents.",
  8635. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  8636. });
  8637. function isFragment(object) {
  8638. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  8639. }
  8640. function getQualifiedJSXName(object) {
  8641. if (object.type === "JSXIdentifier") {
  8642. return object.name;
  8643. }
  8644. if (object.type === "JSXNamespacedName") {
  8645. return object.namespace.name + ":" + object.name.name;
  8646. }
  8647. if (object.type === "JSXMemberExpression") {
  8648. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  8649. }
  8650. throw new Error("Node had unexpected type: " + object.type);
  8651. }
  8652. var jsx = superClass => class JSXParserMixin extends superClass {
  8653. jsxReadToken() {
  8654. let out = "";
  8655. let chunkStart = this.state.pos;
  8656. for (;;) {
  8657. if (this.state.pos >= this.length) {
  8658. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  8659. }
  8660. const ch = this.input.charCodeAt(this.state.pos);
  8661. switch (ch) {
  8662. case 60:
  8663. case 123:
  8664. if (this.state.pos === this.state.start) {
  8665. if (ch === 60 && this.state.canStartJSXElement) {
  8666. ++this.state.pos;
  8667. this.finishToken(143);
  8668. } else {
  8669. super.getTokenFromCode(ch);
  8670. }
  8671. return;
  8672. }
  8673. out += this.input.slice(chunkStart, this.state.pos);
  8674. this.finishToken(142, out);
  8675. return;
  8676. case 38:
  8677. out += this.input.slice(chunkStart, this.state.pos);
  8678. out += this.jsxReadEntity();
  8679. chunkStart = this.state.pos;
  8680. break;
  8681. case 62:
  8682. case 125:
  8683. default:
  8684. if (isNewLine(ch)) {
  8685. out += this.input.slice(chunkStart, this.state.pos);
  8686. out += this.jsxReadNewLine(true);
  8687. chunkStart = this.state.pos;
  8688. } else {
  8689. ++this.state.pos;
  8690. }
  8691. }
  8692. }
  8693. }
  8694. jsxReadNewLine(normalizeCRLF) {
  8695. const ch = this.input.charCodeAt(this.state.pos);
  8696. let out;
  8697. ++this.state.pos;
  8698. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  8699. ++this.state.pos;
  8700. out = normalizeCRLF ? "\n" : "\r\n";
  8701. } else {
  8702. out = String.fromCharCode(ch);
  8703. }
  8704. ++this.state.curLine;
  8705. this.state.lineStart = this.state.pos;
  8706. return out;
  8707. }
  8708. jsxReadString(quote) {
  8709. let out = "";
  8710. let chunkStart = ++this.state.pos;
  8711. for (;;) {
  8712. if (this.state.pos >= this.length) {
  8713. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  8714. }
  8715. const ch = this.input.charCodeAt(this.state.pos);
  8716. if (ch === quote) break;
  8717. if (ch === 38) {
  8718. out += this.input.slice(chunkStart, this.state.pos);
  8719. out += this.jsxReadEntity();
  8720. chunkStart = this.state.pos;
  8721. } else if (isNewLine(ch)) {
  8722. out += this.input.slice(chunkStart, this.state.pos);
  8723. out += this.jsxReadNewLine(false);
  8724. chunkStart = this.state.pos;
  8725. } else {
  8726. ++this.state.pos;
  8727. }
  8728. }
  8729. out += this.input.slice(chunkStart, this.state.pos++);
  8730. this.finishToken(134, out);
  8731. }
  8732. jsxReadEntity() {
  8733. const startPos = ++this.state.pos;
  8734. if (this.codePointAtPos(this.state.pos) === 35) {
  8735. ++this.state.pos;
  8736. let radix = 10;
  8737. if (this.codePointAtPos(this.state.pos) === 120) {
  8738. radix = 16;
  8739. ++this.state.pos;
  8740. }
  8741. const codePoint = this.readInt(radix, undefined, false, "bail");
  8742. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  8743. ++this.state.pos;
  8744. return String.fromCodePoint(codePoint);
  8745. }
  8746. } else {
  8747. let count = 0;
  8748. let semi = false;
  8749. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  8750. ++this.state.pos;
  8751. }
  8752. if (semi) {
  8753. const desc = this.input.slice(startPos, this.state.pos);
  8754. const entity = entities[desc];
  8755. ++this.state.pos;
  8756. if (entity) {
  8757. return entity;
  8758. }
  8759. }
  8760. }
  8761. this.state.pos = startPos;
  8762. return "&";
  8763. }
  8764. jsxReadWord() {
  8765. let ch;
  8766. const start = this.state.pos;
  8767. do {
  8768. ch = this.input.charCodeAt(++this.state.pos);
  8769. } while (isIdentifierChar(ch) || ch === 45);
  8770. this.finishToken(141, this.input.slice(start, this.state.pos));
  8771. }
  8772. jsxParseIdentifier() {
  8773. const node = this.startNode();
  8774. if (this.match(141)) {
  8775. node.name = this.state.value;
  8776. } else if (tokenIsKeyword(this.state.type)) {
  8777. node.name = tokenLabelName(this.state.type);
  8778. } else {
  8779. this.unexpected();
  8780. }
  8781. this.next();
  8782. return this.finishNode(node, "JSXIdentifier");
  8783. }
  8784. jsxParseNamespacedName() {
  8785. const startLoc = this.state.startLoc;
  8786. const name = this.jsxParseIdentifier();
  8787. if (!this.eat(14)) return name;
  8788. const node = this.startNodeAt(startLoc);
  8789. node.namespace = name;
  8790. node.name = this.jsxParseIdentifier();
  8791. return this.finishNode(node, "JSXNamespacedName");
  8792. }
  8793. jsxParseElementName() {
  8794. const startLoc = this.state.startLoc;
  8795. let node = this.jsxParseNamespacedName();
  8796. if (node.type === "JSXNamespacedName") {
  8797. return node;
  8798. }
  8799. while (this.eat(16)) {
  8800. const newNode = this.startNodeAt(startLoc);
  8801. newNode.object = node;
  8802. newNode.property = this.jsxParseIdentifier();
  8803. node = this.finishNode(newNode, "JSXMemberExpression");
  8804. }
  8805. return node;
  8806. }
  8807. jsxParseAttributeValue() {
  8808. let node;
  8809. switch (this.state.type) {
  8810. case 5:
  8811. node = this.startNode();
  8812. this.setContext(types.brace);
  8813. this.next();
  8814. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  8815. if (node.expression.type === "JSXEmptyExpression") {
  8816. this.raise(JsxErrors.AttributeIsEmpty, node);
  8817. }
  8818. return node;
  8819. case 143:
  8820. case 134:
  8821. return this.parseExprAtom();
  8822. default:
  8823. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  8824. }
  8825. }
  8826. jsxParseEmptyExpression() {
  8827. const node = this.startNodeAt(this.state.lastTokEndLoc);
  8828. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  8829. }
  8830. jsxParseSpreadChild(node) {
  8831. this.next();
  8832. node.expression = this.parseExpression();
  8833. this.setContext(types.j_expr);
  8834. this.state.canStartJSXElement = true;
  8835. this.expect(8);
  8836. return this.finishNode(node, "JSXSpreadChild");
  8837. }
  8838. jsxParseExpressionContainer(node, previousContext) {
  8839. if (this.match(8)) {
  8840. node.expression = this.jsxParseEmptyExpression();
  8841. } else {
  8842. const expression = this.parseExpression();
  8843. node.expression = expression;
  8844. }
  8845. this.setContext(previousContext);
  8846. this.state.canStartJSXElement = true;
  8847. this.expect(8);
  8848. return this.finishNode(node, "JSXExpressionContainer");
  8849. }
  8850. jsxParseAttribute() {
  8851. const node = this.startNode();
  8852. if (this.match(5)) {
  8853. this.setContext(types.brace);
  8854. this.next();
  8855. this.expect(21);
  8856. node.argument = this.parseMaybeAssignAllowIn();
  8857. this.setContext(types.j_oTag);
  8858. this.state.canStartJSXElement = true;
  8859. this.expect(8);
  8860. return this.finishNode(node, "JSXSpreadAttribute");
  8861. }
  8862. node.name = this.jsxParseNamespacedName();
  8863. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  8864. return this.finishNode(node, "JSXAttribute");
  8865. }
  8866. jsxParseOpeningElementAt(startLoc) {
  8867. const node = this.startNodeAt(startLoc);
  8868. if (this.eat(144)) {
  8869. return this.finishNode(node, "JSXOpeningFragment");
  8870. }
  8871. node.name = this.jsxParseElementName();
  8872. return this.jsxParseOpeningElementAfterName(node);
  8873. }
  8874. jsxParseOpeningElementAfterName(node) {
  8875. const attributes = [];
  8876. while (!this.match(56) && !this.match(144)) {
  8877. attributes.push(this.jsxParseAttribute());
  8878. }
  8879. node.attributes = attributes;
  8880. node.selfClosing = this.eat(56);
  8881. this.expect(144);
  8882. return this.finishNode(node, "JSXOpeningElement");
  8883. }
  8884. jsxParseClosingElementAt(startLoc) {
  8885. const node = this.startNodeAt(startLoc);
  8886. if (this.eat(144)) {
  8887. return this.finishNode(node, "JSXClosingFragment");
  8888. }
  8889. node.name = this.jsxParseElementName();
  8890. this.expect(144);
  8891. return this.finishNode(node, "JSXClosingElement");
  8892. }
  8893. jsxParseElementAt(startLoc) {
  8894. const node = this.startNodeAt(startLoc);
  8895. const children = [];
  8896. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  8897. let closingElement = null;
  8898. if (!openingElement.selfClosing) {
  8899. contents: for (;;) {
  8900. switch (this.state.type) {
  8901. case 143:
  8902. startLoc = this.state.startLoc;
  8903. this.next();
  8904. if (this.eat(56)) {
  8905. closingElement = this.jsxParseClosingElementAt(startLoc);
  8906. break contents;
  8907. }
  8908. children.push(this.jsxParseElementAt(startLoc));
  8909. break;
  8910. case 142:
  8911. children.push(this.parseLiteral(this.state.value, "JSXText"));
  8912. break;
  8913. case 5:
  8914. {
  8915. const node = this.startNode();
  8916. this.setContext(types.brace);
  8917. this.next();
  8918. if (this.match(21)) {
  8919. children.push(this.jsxParseSpreadChild(node));
  8920. } else {
  8921. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  8922. }
  8923. break;
  8924. }
  8925. default:
  8926. this.unexpected();
  8927. }
  8928. }
  8929. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  8930. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  8931. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  8932. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  8933. openingTagName: getQualifiedJSXName(openingElement.name)
  8934. });
  8935. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  8936. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  8937. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  8938. openingTagName: getQualifiedJSXName(openingElement.name)
  8939. });
  8940. }
  8941. }
  8942. }
  8943. if (isFragment(openingElement)) {
  8944. node.openingFragment = openingElement;
  8945. node.closingFragment = closingElement;
  8946. } else {
  8947. node.openingElement = openingElement;
  8948. node.closingElement = closingElement;
  8949. }
  8950. node.children = children;
  8951. if (this.match(47)) {
  8952. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  8953. }
  8954. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  8955. }
  8956. jsxParseElement() {
  8957. const startLoc = this.state.startLoc;
  8958. this.next();
  8959. return this.jsxParseElementAt(startLoc);
  8960. }
  8961. setContext(newContext) {
  8962. const {
  8963. context
  8964. } = this.state;
  8965. context[context.length - 1] = newContext;
  8966. }
  8967. parseExprAtom(refExpressionErrors) {
  8968. if (this.match(143)) {
  8969. return this.jsxParseElement();
  8970. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  8971. this.replaceToken(143);
  8972. return this.jsxParseElement();
  8973. } else {
  8974. return super.parseExprAtom(refExpressionErrors);
  8975. }
  8976. }
  8977. skipSpace() {
  8978. const curContext = this.curContext();
  8979. if (!curContext.preserveSpace) super.skipSpace();
  8980. }
  8981. getTokenFromCode(code) {
  8982. const context = this.curContext();
  8983. if (context === types.j_expr) {
  8984. this.jsxReadToken();
  8985. return;
  8986. }
  8987. if (context === types.j_oTag || context === types.j_cTag) {
  8988. if (isIdentifierStart(code)) {
  8989. this.jsxReadWord();
  8990. return;
  8991. }
  8992. if (code === 62) {
  8993. ++this.state.pos;
  8994. this.finishToken(144);
  8995. return;
  8996. }
  8997. if ((code === 34 || code === 39) && context === types.j_oTag) {
  8998. this.jsxReadString(code);
  8999. return;
  9000. }
  9001. }
  9002. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  9003. ++this.state.pos;
  9004. this.finishToken(143);
  9005. return;
  9006. }
  9007. super.getTokenFromCode(code);
  9008. }
  9009. updateContext(prevType) {
  9010. const {
  9011. context,
  9012. type
  9013. } = this.state;
  9014. if (type === 56 && prevType === 143) {
  9015. context.splice(-2, 2, types.j_cTag);
  9016. this.state.canStartJSXElement = false;
  9017. } else if (type === 143) {
  9018. context.push(types.j_oTag);
  9019. } else if (type === 144) {
  9020. const out = context[context.length - 1];
  9021. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  9022. context.pop();
  9023. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  9024. } else {
  9025. this.setContext(types.j_expr);
  9026. this.state.canStartJSXElement = true;
  9027. }
  9028. } else {
  9029. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  9030. }
  9031. }
  9032. };
  9033. class TypeScriptScope extends Scope {
  9034. constructor(...args) {
  9035. super(...args);
  9036. this.tsNames = new Map();
  9037. }
  9038. }
  9039. class TypeScriptScopeHandler extends ScopeHandler {
  9040. constructor(...args) {
  9041. super(...args);
  9042. this.importsStack = [];
  9043. }
  9044. createScope(flags) {
  9045. this.importsStack.push(new Set());
  9046. return new TypeScriptScope(flags);
  9047. }
  9048. enter(flags) {
  9049. if (flags === 1024) {
  9050. this.importsStack.push(new Set());
  9051. }
  9052. super.enter(flags);
  9053. }
  9054. exit() {
  9055. const flags = super.exit();
  9056. if (flags === 1024) {
  9057. this.importsStack.pop();
  9058. }
  9059. return flags;
  9060. }
  9061. hasImport(name, allowShadow) {
  9062. const len = this.importsStack.length;
  9063. if (this.importsStack[len - 1].has(name)) {
  9064. return true;
  9065. }
  9066. if (!allowShadow && len > 1) {
  9067. for (let i = 0; i < len - 1; i++) {
  9068. if (this.importsStack[i].has(name)) return true;
  9069. }
  9070. }
  9071. return false;
  9072. }
  9073. declareName(name, bindingType, loc) {
  9074. if (bindingType & 4096) {
  9075. if (this.hasImport(name, true)) {
  9076. this.parser.raise(Errors.VarRedeclaration, loc, {
  9077. identifierName: name
  9078. });
  9079. }
  9080. this.importsStack[this.importsStack.length - 1].add(name);
  9081. return;
  9082. }
  9083. const scope = this.currentScope();
  9084. let type = scope.tsNames.get(name) || 0;
  9085. if (bindingType & 1024) {
  9086. this.maybeExportDefined(scope, name);
  9087. scope.tsNames.set(name, type | 16);
  9088. return;
  9089. }
  9090. super.declareName(name, bindingType, loc);
  9091. if (bindingType & 2) {
  9092. if (!(bindingType & 1)) {
  9093. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  9094. this.maybeExportDefined(scope, name);
  9095. }
  9096. type = type | 1;
  9097. }
  9098. if (bindingType & 256) {
  9099. type = type | 2;
  9100. }
  9101. if (bindingType & 512) {
  9102. type = type | 4;
  9103. }
  9104. if (bindingType & 128) {
  9105. type = type | 8;
  9106. }
  9107. if (type) scope.tsNames.set(name, type);
  9108. }
  9109. isRedeclaredInScope(scope, name, bindingType) {
  9110. const type = scope.tsNames.get(name);
  9111. if ((type & 2) > 0) {
  9112. if (bindingType & 256) {
  9113. const isConst = !!(bindingType & 512);
  9114. const wasConst = (type & 4) > 0;
  9115. return isConst !== wasConst;
  9116. }
  9117. return true;
  9118. }
  9119. if (bindingType & 128 && (type & 8) > 0) {
  9120. if (scope.names.get(name) & 2) {
  9121. return !!(bindingType & 1);
  9122. } else {
  9123. return false;
  9124. }
  9125. }
  9126. if (bindingType & 2 && (type & 1) > 0) {
  9127. return true;
  9128. }
  9129. return super.isRedeclaredInScope(scope, name, bindingType);
  9130. }
  9131. checkLocalExport(id) {
  9132. const {
  9133. name
  9134. } = id;
  9135. if (this.hasImport(name)) return;
  9136. const len = this.scopeStack.length;
  9137. for (let i = len - 1; i >= 0; i--) {
  9138. const scope = this.scopeStack[i];
  9139. const type = scope.tsNames.get(name);
  9140. if ((type & 1) > 0 || (type & 16) > 0) {
  9141. return;
  9142. }
  9143. }
  9144. super.checkLocalExport(id);
  9145. }
  9146. }
  9147. class ProductionParameterHandler {
  9148. constructor() {
  9149. this.stacks = [];
  9150. }
  9151. enter(flags) {
  9152. this.stacks.push(flags);
  9153. }
  9154. exit() {
  9155. this.stacks.pop();
  9156. }
  9157. currentFlags() {
  9158. return this.stacks[this.stacks.length - 1];
  9159. }
  9160. get hasAwait() {
  9161. return (this.currentFlags() & 2) > 0;
  9162. }
  9163. get hasYield() {
  9164. return (this.currentFlags() & 1) > 0;
  9165. }
  9166. get hasReturn() {
  9167. return (this.currentFlags() & 4) > 0;
  9168. }
  9169. get hasIn() {
  9170. return (this.currentFlags() & 8) > 0;
  9171. }
  9172. }
  9173. function functionFlags(isAsync, isGenerator) {
  9174. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  9175. }
  9176. class BaseParser {
  9177. constructor() {
  9178. this.sawUnambiguousESM = false;
  9179. this.ambiguousScriptDifferentAst = false;
  9180. }
  9181. sourceToOffsetPos(sourcePos) {
  9182. return sourcePos + this.startIndex;
  9183. }
  9184. offsetToSourcePos(offsetPos) {
  9185. return offsetPos - this.startIndex;
  9186. }
  9187. hasPlugin(pluginConfig) {
  9188. if (typeof pluginConfig === "string") {
  9189. return this.plugins.has(pluginConfig);
  9190. } else {
  9191. const [pluginName, pluginOptions] = pluginConfig;
  9192. if (!this.hasPlugin(pluginName)) {
  9193. return false;
  9194. }
  9195. const actualOptions = this.plugins.get(pluginName);
  9196. for (const key of Object.keys(pluginOptions)) {
  9197. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  9198. return false;
  9199. }
  9200. }
  9201. return true;
  9202. }
  9203. }
  9204. getPluginOption(plugin, name) {
  9205. var _this$plugins$get;
  9206. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  9207. }
  9208. }
  9209. function setTrailingComments(node, comments) {
  9210. if (node.trailingComments === undefined) {
  9211. node.trailingComments = comments;
  9212. } else {
  9213. node.trailingComments.unshift(...comments);
  9214. }
  9215. }
  9216. function setLeadingComments(node, comments) {
  9217. if (node.leadingComments === undefined) {
  9218. node.leadingComments = comments;
  9219. } else {
  9220. node.leadingComments.unshift(...comments);
  9221. }
  9222. }
  9223. function setInnerComments(node, comments) {
  9224. if (node.innerComments === undefined) {
  9225. node.innerComments = comments;
  9226. } else {
  9227. node.innerComments.unshift(...comments);
  9228. }
  9229. }
  9230. function adjustInnerComments(node, elements, commentWS) {
  9231. let lastElement = null;
  9232. let i = elements.length;
  9233. while (lastElement === null && i > 0) {
  9234. lastElement = elements[--i];
  9235. }
  9236. if (lastElement === null || lastElement.start > commentWS.start) {
  9237. setInnerComments(node, commentWS.comments);
  9238. } else {
  9239. setTrailingComments(lastElement, commentWS.comments);
  9240. }
  9241. }
  9242. class CommentsParser extends BaseParser {
  9243. addComment(comment) {
  9244. if (this.filename) comment.loc.filename = this.filename;
  9245. const {
  9246. commentsLen
  9247. } = this.state;
  9248. if (this.comments.length !== commentsLen) {
  9249. this.comments.length = commentsLen;
  9250. }
  9251. this.comments.push(comment);
  9252. this.state.commentsLen++;
  9253. }
  9254. processComment(node) {
  9255. const {
  9256. commentStack
  9257. } = this.state;
  9258. const commentStackLength = commentStack.length;
  9259. if (commentStackLength === 0) return;
  9260. let i = commentStackLength - 1;
  9261. const lastCommentWS = commentStack[i];
  9262. if (lastCommentWS.start === node.end) {
  9263. lastCommentWS.leadingNode = node;
  9264. i--;
  9265. }
  9266. const {
  9267. start: nodeStart
  9268. } = node;
  9269. for (; i >= 0; i--) {
  9270. const commentWS = commentStack[i];
  9271. const commentEnd = commentWS.end;
  9272. if (commentEnd > nodeStart) {
  9273. commentWS.containingNode = node;
  9274. this.finalizeComment(commentWS);
  9275. commentStack.splice(i, 1);
  9276. } else {
  9277. if (commentEnd === nodeStart) {
  9278. commentWS.trailingNode = node;
  9279. }
  9280. break;
  9281. }
  9282. }
  9283. }
  9284. finalizeComment(commentWS) {
  9285. var _node$options;
  9286. const {
  9287. comments
  9288. } = commentWS;
  9289. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  9290. if (commentWS.leadingNode !== null) {
  9291. setTrailingComments(commentWS.leadingNode, comments);
  9292. }
  9293. if (commentWS.trailingNode !== null) {
  9294. setLeadingComments(commentWS.trailingNode, comments);
  9295. }
  9296. } else {
  9297. const node = commentWS.containingNode;
  9298. const commentStart = commentWS.start;
  9299. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  9300. switch (node.type) {
  9301. case "ObjectExpression":
  9302. case "ObjectPattern":
  9303. adjustInnerComments(node, node.properties, commentWS);
  9304. break;
  9305. case "CallExpression":
  9306. case "OptionalCallExpression":
  9307. adjustInnerComments(node, node.arguments, commentWS);
  9308. break;
  9309. case "ImportExpression":
  9310. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  9311. break;
  9312. case "FunctionDeclaration":
  9313. case "FunctionExpression":
  9314. case "ArrowFunctionExpression":
  9315. case "ObjectMethod":
  9316. case "ClassMethod":
  9317. case "ClassPrivateMethod":
  9318. adjustInnerComments(node, node.params, commentWS);
  9319. break;
  9320. case "ArrayExpression":
  9321. case "ArrayPattern":
  9322. adjustInnerComments(node, node.elements, commentWS);
  9323. break;
  9324. case "ExportNamedDeclaration":
  9325. case "ImportDeclaration":
  9326. adjustInnerComments(node, node.specifiers, commentWS);
  9327. break;
  9328. case "TSEnumDeclaration":
  9329. adjustInnerComments(node, node.members, commentWS);
  9330. break;
  9331. case "TSEnumBody":
  9332. adjustInnerComments(node, node.members, commentWS);
  9333. break;
  9334. default:
  9335. {
  9336. if (node.type === "RecordExpression") {
  9337. adjustInnerComments(node, node.properties, commentWS);
  9338. break;
  9339. }
  9340. if (node.type === "TupleExpression") {
  9341. adjustInnerComments(node, node.elements, commentWS);
  9342. break;
  9343. }
  9344. setInnerComments(node, comments);
  9345. }
  9346. }
  9347. } else {
  9348. setInnerComments(node, comments);
  9349. }
  9350. }
  9351. }
  9352. finalizeRemainingComments() {
  9353. const {
  9354. commentStack
  9355. } = this.state;
  9356. for (let i = commentStack.length - 1; i >= 0; i--) {
  9357. this.finalizeComment(commentStack[i]);
  9358. }
  9359. this.state.commentStack = [];
  9360. }
  9361. resetPreviousNodeTrailingComments(node) {
  9362. const {
  9363. commentStack
  9364. } = this.state;
  9365. const {
  9366. length
  9367. } = commentStack;
  9368. if (length === 0) return;
  9369. const commentWS = commentStack[length - 1];
  9370. if (commentWS.leadingNode === node) {
  9371. commentWS.leadingNode = null;
  9372. }
  9373. }
  9374. takeSurroundingComments(node, start, end) {
  9375. const {
  9376. commentStack
  9377. } = this.state;
  9378. const commentStackLength = commentStack.length;
  9379. if (commentStackLength === 0) return;
  9380. let i = commentStackLength - 1;
  9381. for (; i >= 0; i--) {
  9382. const commentWS = commentStack[i];
  9383. const commentEnd = commentWS.end;
  9384. const commentStart = commentWS.start;
  9385. if (commentStart === end) {
  9386. commentWS.leadingNode = node;
  9387. } else if (commentEnd === start) {
  9388. commentWS.trailingNode = node;
  9389. } else if (commentEnd < start) {
  9390. break;
  9391. }
  9392. }
  9393. }
  9394. }
  9395. class State {
  9396. constructor() {
  9397. this.flags = 1024;
  9398. this.startIndex = void 0;
  9399. this.curLine = void 0;
  9400. this.lineStart = void 0;
  9401. this.startLoc = void 0;
  9402. this.endLoc = void 0;
  9403. this.errors = [];
  9404. this.potentialArrowAt = -1;
  9405. this.noArrowAt = [];
  9406. this.noArrowParamsConversionAt = [];
  9407. this.topicContext = {
  9408. maxNumOfResolvableTopics: 0,
  9409. maxTopicIndex: null
  9410. };
  9411. this.labels = [];
  9412. this.commentsLen = 0;
  9413. this.commentStack = [];
  9414. this.pos = 0;
  9415. this.type = 140;
  9416. this.value = null;
  9417. this.start = 0;
  9418. this.end = 0;
  9419. this.lastTokEndLoc = null;
  9420. this.lastTokStartLoc = null;
  9421. this.context = [types.brace];
  9422. this.firstInvalidTemplateEscapePos = null;
  9423. this.strictErrors = new Map();
  9424. this.tokensLength = 0;
  9425. }
  9426. get strict() {
  9427. return (this.flags & 1) > 0;
  9428. }
  9429. set strict(v) {
  9430. if (v) this.flags |= 1;else this.flags &= -2;
  9431. }
  9432. init({
  9433. strictMode,
  9434. sourceType,
  9435. startIndex,
  9436. startLine,
  9437. startColumn
  9438. }) {
  9439. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  9440. this.startIndex = startIndex;
  9441. this.curLine = startLine;
  9442. this.lineStart = -startColumn;
  9443. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  9444. }
  9445. get maybeInArrowParameters() {
  9446. return (this.flags & 2) > 0;
  9447. }
  9448. set maybeInArrowParameters(v) {
  9449. if (v) this.flags |= 2;else this.flags &= -3;
  9450. }
  9451. get inType() {
  9452. return (this.flags & 4) > 0;
  9453. }
  9454. set inType(v) {
  9455. if (v) this.flags |= 4;else this.flags &= -5;
  9456. }
  9457. get noAnonFunctionType() {
  9458. return (this.flags & 8) > 0;
  9459. }
  9460. set noAnonFunctionType(v) {
  9461. if (v) this.flags |= 8;else this.flags &= -9;
  9462. }
  9463. get hasFlowComment() {
  9464. return (this.flags & 16) > 0;
  9465. }
  9466. set hasFlowComment(v) {
  9467. if (v) this.flags |= 16;else this.flags &= -17;
  9468. }
  9469. get isAmbientContext() {
  9470. return (this.flags & 32) > 0;
  9471. }
  9472. set isAmbientContext(v) {
  9473. if (v) this.flags |= 32;else this.flags &= -33;
  9474. }
  9475. get inAbstractClass() {
  9476. return (this.flags & 64) > 0;
  9477. }
  9478. set inAbstractClass(v) {
  9479. if (v) this.flags |= 64;else this.flags &= -65;
  9480. }
  9481. get inDisallowConditionalTypesContext() {
  9482. return (this.flags & 128) > 0;
  9483. }
  9484. set inDisallowConditionalTypesContext(v) {
  9485. if (v) this.flags |= 128;else this.flags &= -129;
  9486. }
  9487. get soloAwait() {
  9488. return (this.flags & 256) > 0;
  9489. }
  9490. set soloAwait(v) {
  9491. if (v) this.flags |= 256;else this.flags &= -257;
  9492. }
  9493. get inFSharpPipelineDirectBody() {
  9494. return (this.flags & 512) > 0;
  9495. }
  9496. set inFSharpPipelineDirectBody(v) {
  9497. if (v) this.flags |= 512;else this.flags &= -513;
  9498. }
  9499. get canStartJSXElement() {
  9500. return (this.flags & 1024) > 0;
  9501. }
  9502. set canStartJSXElement(v) {
  9503. if (v) this.flags |= 1024;else this.flags &= -1025;
  9504. }
  9505. get containsEsc() {
  9506. return (this.flags & 2048) > 0;
  9507. }
  9508. set containsEsc(v) {
  9509. if (v) this.flags |= 2048;else this.flags &= -2049;
  9510. }
  9511. get hasTopLevelAwait() {
  9512. return (this.flags & 4096) > 0;
  9513. }
  9514. set hasTopLevelAwait(v) {
  9515. if (v) this.flags |= 4096;else this.flags &= -4097;
  9516. }
  9517. curPosition() {
  9518. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  9519. }
  9520. clone() {
  9521. const state = new State();
  9522. state.flags = this.flags;
  9523. state.startIndex = this.startIndex;
  9524. state.curLine = this.curLine;
  9525. state.lineStart = this.lineStart;
  9526. state.startLoc = this.startLoc;
  9527. state.endLoc = this.endLoc;
  9528. state.errors = this.errors.slice();
  9529. state.potentialArrowAt = this.potentialArrowAt;
  9530. state.noArrowAt = this.noArrowAt.slice();
  9531. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  9532. state.topicContext = this.topicContext;
  9533. state.labels = this.labels.slice();
  9534. state.commentsLen = this.commentsLen;
  9535. state.commentStack = this.commentStack.slice();
  9536. state.pos = this.pos;
  9537. state.type = this.type;
  9538. state.value = this.value;
  9539. state.start = this.start;
  9540. state.end = this.end;
  9541. state.lastTokEndLoc = this.lastTokEndLoc;
  9542. state.lastTokStartLoc = this.lastTokStartLoc;
  9543. state.context = this.context.slice();
  9544. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  9545. state.strictErrors = this.strictErrors;
  9546. state.tokensLength = this.tokensLength;
  9547. return state;
  9548. }
  9549. }
  9550. var _isDigit = function isDigit(code) {
  9551. return code >= 48 && code <= 57;
  9552. };
  9553. const forbiddenNumericSeparatorSiblings = {
  9554. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  9555. hex: new Set([46, 88, 95, 120])
  9556. };
  9557. const isAllowedNumericSeparatorSibling = {
  9558. bin: ch => ch === 48 || ch === 49,
  9559. oct: ch => ch >= 48 && ch <= 55,
  9560. dec: ch => ch >= 48 && ch <= 57,
  9561. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  9562. };
  9563. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  9564. const initialPos = pos;
  9565. const initialLineStart = lineStart;
  9566. const initialCurLine = curLine;
  9567. let out = "";
  9568. let firstInvalidLoc = null;
  9569. let chunkStart = pos;
  9570. const {
  9571. length
  9572. } = input;
  9573. for (;;) {
  9574. if (pos >= length) {
  9575. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  9576. out += input.slice(chunkStart, pos);
  9577. break;
  9578. }
  9579. const ch = input.charCodeAt(pos);
  9580. if (isStringEnd(type, ch, input, pos)) {
  9581. out += input.slice(chunkStart, pos);
  9582. break;
  9583. }
  9584. if (ch === 92) {
  9585. out += input.slice(chunkStart, pos);
  9586. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  9587. if (res.ch === null && !firstInvalidLoc) {
  9588. firstInvalidLoc = {
  9589. pos,
  9590. lineStart,
  9591. curLine
  9592. };
  9593. } else {
  9594. out += res.ch;
  9595. }
  9596. ({
  9597. pos,
  9598. lineStart,
  9599. curLine
  9600. } = res);
  9601. chunkStart = pos;
  9602. } else if (ch === 8232 || ch === 8233) {
  9603. ++pos;
  9604. ++curLine;
  9605. lineStart = pos;
  9606. } else if (ch === 10 || ch === 13) {
  9607. if (type === "template") {
  9608. out += input.slice(chunkStart, pos) + "\n";
  9609. ++pos;
  9610. if (ch === 13 && input.charCodeAt(pos) === 10) {
  9611. ++pos;
  9612. }
  9613. ++curLine;
  9614. chunkStart = lineStart = pos;
  9615. } else {
  9616. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  9617. }
  9618. } else {
  9619. ++pos;
  9620. }
  9621. }
  9622. return {
  9623. pos,
  9624. str: out,
  9625. firstInvalidLoc,
  9626. lineStart,
  9627. curLine,
  9628. containsInvalid: !!firstInvalidLoc
  9629. };
  9630. }
  9631. function isStringEnd(type, ch, input, pos) {
  9632. if (type === "template") {
  9633. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  9634. }
  9635. return ch === (type === "double" ? 34 : 39);
  9636. }
  9637. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  9638. const throwOnInvalid = !inTemplate;
  9639. pos++;
  9640. const res = ch => ({
  9641. pos,
  9642. ch,
  9643. lineStart,
  9644. curLine
  9645. });
  9646. const ch = input.charCodeAt(pos++);
  9647. switch (ch) {
  9648. case 110:
  9649. return res("\n");
  9650. case 114:
  9651. return res("\r");
  9652. case 120:
  9653. {
  9654. let code;
  9655. ({
  9656. code,
  9657. pos
  9658. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  9659. return res(code === null ? null : String.fromCharCode(code));
  9660. }
  9661. case 117:
  9662. {
  9663. let code;
  9664. ({
  9665. code,
  9666. pos
  9667. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  9668. return res(code === null ? null : String.fromCodePoint(code));
  9669. }
  9670. case 116:
  9671. return res("\t");
  9672. case 98:
  9673. return res("\b");
  9674. case 118:
  9675. return res("\u000b");
  9676. case 102:
  9677. return res("\f");
  9678. case 13:
  9679. if (input.charCodeAt(pos) === 10) {
  9680. ++pos;
  9681. }
  9682. case 10:
  9683. lineStart = pos;
  9684. ++curLine;
  9685. case 8232:
  9686. case 8233:
  9687. return res("");
  9688. case 56:
  9689. case 57:
  9690. if (inTemplate) {
  9691. return res(null);
  9692. } else {
  9693. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  9694. }
  9695. default:
  9696. if (ch >= 48 && ch <= 55) {
  9697. const startPos = pos - 1;
  9698. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  9699. let octalStr = match[0];
  9700. let octal = parseInt(octalStr, 8);
  9701. if (octal > 255) {
  9702. octalStr = octalStr.slice(0, -1);
  9703. octal = parseInt(octalStr, 8);
  9704. }
  9705. pos += octalStr.length - 1;
  9706. const next = input.charCodeAt(pos);
  9707. if (octalStr !== "0" || next === 56 || next === 57) {
  9708. if (inTemplate) {
  9709. return res(null);
  9710. } else {
  9711. errors.strictNumericEscape(startPos, lineStart, curLine);
  9712. }
  9713. }
  9714. return res(String.fromCharCode(octal));
  9715. }
  9716. return res(String.fromCharCode(ch));
  9717. }
  9718. }
  9719. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  9720. const initialPos = pos;
  9721. let n;
  9722. ({
  9723. n,
  9724. pos
  9725. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  9726. if (n === null) {
  9727. if (throwOnInvalid) {
  9728. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  9729. } else {
  9730. pos = initialPos - 1;
  9731. }
  9732. }
  9733. return {
  9734. code: n,
  9735. pos
  9736. };
  9737. }
  9738. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  9739. const start = pos;
  9740. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  9741. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  9742. let invalid = false;
  9743. let total = 0;
  9744. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  9745. const code = input.charCodeAt(pos);
  9746. let val;
  9747. if (code === 95 && allowNumSeparator !== "bail") {
  9748. const prev = input.charCodeAt(pos - 1);
  9749. const next = input.charCodeAt(pos + 1);
  9750. if (!allowNumSeparator) {
  9751. if (bailOnError) return {
  9752. n: null,
  9753. pos
  9754. };
  9755. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  9756. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  9757. if (bailOnError) return {
  9758. n: null,
  9759. pos
  9760. };
  9761. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  9762. }
  9763. ++pos;
  9764. continue;
  9765. }
  9766. if (code >= 97) {
  9767. val = code - 97 + 10;
  9768. } else if (code >= 65) {
  9769. val = code - 65 + 10;
  9770. } else if (_isDigit(code)) {
  9771. val = code - 48;
  9772. } else {
  9773. val = Infinity;
  9774. }
  9775. if (val >= radix) {
  9776. if (val <= 9 && bailOnError) {
  9777. return {
  9778. n: null,
  9779. pos
  9780. };
  9781. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  9782. val = 0;
  9783. } else if (forceLen) {
  9784. val = 0;
  9785. invalid = true;
  9786. } else {
  9787. break;
  9788. }
  9789. }
  9790. ++pos;
  9791. total = total * radix + val;
  9792. }
  9793. if (pos === start || len != null && pos - start !== len || invalid) {
  9794. return {
  9795. n: null,
  9796. pos
  9797. };
  9798. }
  9799. return {
  9800. n: total,
  9801. pos
  9802. };
  9803. }
  9804. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  9805. const ch = input.charCodeAt(pos);
  9806. let code;
  9807. if (ch === 123) {
  9808. ++pos;
  9809. ({
  9810. code,
  9811. pos
  9812. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  9813. ++pos;
  9814. if (code !== null && code > 0x10ffff) {
  9815. if (throwOnInvalid) {
  9816. errors.invalidCodePoint(pos, lineStart, curLine);
  9817. } else {
  9818. return {
  9819. code: null,
  9820. pos
  9821. };
  9822. }
  9823. }
  9824. } else {
  9825. ({
  9826. code,
  9827. pos
  9828. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  9829. }
  9830. return {
  9831. code,
  9832. pos
  9833. };
  9834. }
  9835. function buildPosition(pos, lineStart, curLine) {
  9836. return new Position(curLine, pos - lineStart, pos);
  9837. }
  9838. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  9839. class Token {
  9840. constructor(state) {
  9841. const startIndex = state.startIndex || 0;
  9842. this.type = state.type;
  9843. this.value = state.value;
  9844. this.start = startIndex + state.start;
  9845. this.end = startIndex + state.end;
  9846. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  9847. }
  9848. }
  9849. class Tokenizer extends CommentsParser {
  9850. constructor(options, input) {
  9851. super();
  9852. this.isLookahead = void 0;
  9853. this.tokens = [];
  9854. this.errorHandlers_readInt = {
  9855. invalidDigit: (pos, lineStart, curLine, radix) => {
  9856. if (!(this.optionFlags & 2048)) return false;
  9857. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  9858. radix
  9859. });
  9860. return true;
  9861. },
  9862. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  9863. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  9864. };
  9865. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  9866. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  9867. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  9868. });
  9869. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  9870. strictNumericEscape: (pos, lineStart, curLine) => {
  9871. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  9872. },
  9873. unterminated: (pos, lineStart, curLine) => {
  9874. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  9875. }
  9876. });
  9877. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  9878. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  9879. unterminated: (pos, lineStart, curLine) => {
  9880. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  9881. }
  9882. });
  9883. this.state = new State();
  9884. this.state.init(options);
  9885. this.input = input;
  9886. this.length = input.length;
  9887. this.comments = [];
  9888. this.isLookahead = false;
  9889. }
  9890. pushToken(token) {
  9891. this.tokens.length = this.state.tokensLength;
  9892. this.tokens.push(token);
  9893. ++this.state.tokensLength;
  9894. }
  9895. next() {
  9896. this.checkKeywordEscapes();
  9897. if (this.optionFlags & 256) {
  9898. this.pushToken(new Token(this.state));
  9899. }
  9900. this.state.lastTokEndLoc = this.state.endLoc;
  9901. this.state.lastTokStartLoc = this.state.startLoc;
  9902. this.nextToken();
  9903. }
  9904. eat(type) {
  9905. if (this.match(type)) {
  9906. this.next();
  9907. return true;
  9908. } else {
  9909. return false;
  9910. }
  9911. }
  9912. match(type) {
  9913. return this.state.type === type;
  9914. }
  9915. createLookaheadState(state) {
  9916. return {
  9917. pos: state.pos,
  9918. value: null,
  9919. type: state.type,
  9920. start: state.start,
  9921. end: state.end,
  9922. context: [this.curContext()],
  9923. inType: state.inType,
  9924. startLoc: state.startLoc,
  9925. lastTokEndLoc: state.lastTokEndLoc,
  9926. curLine: state.curLine,
  9927. lineStart: state.lineStart,
  9928. curPosition: state.curPosition
  9929. };
  9930. }
  9931. lookahead() {
  9932. const old = this.state;
  9933. this.state = this.createLookaheadState(old);
  9934. this.isLookahead = true;
  9935. this.nextToken();
  9936. this.isLookahead = false;
  9937. const curr = this.state;
  9938. this.state = old;
  9939. return curr;
  9940. }
  9941. nextTokenStart() {
  9942. return this.nextTokenStartSince(this.state.pos);
  9943. }
  9944. nextTokenStartSince(pos) {
  9945. skipWhiteSpace.lastIndex = pos;
  9946. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  9947. }
  9948. lookaheadCharCode() {
  9949. return this.lookaheadCharCodeSince(this.state.pos);
  9950. }
  9951. lookaheadCharCodeSince(pos) {
  9952. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  9953. }
  9954. nextTokenInLineStart() {
  9955. return this.nextTokenInLineStartSince(this.state.pos);
  9956. }
  9957. nextTokenInLineStartSince(pos) {
  9958. skipWhiteSpaceInLine.lastIndex = pos;
  9959. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  9960. }
  9961. lookaheadInLineCharCode() {
  9962. return this.input.charCodeAt(this.nextTokenInLineStart());
  9963. }
  9964. codePointAtPos(pos) {
  9965. let cp = this.input.charCodeAt(pos);
  9966. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  9967. const trail = this.input.charCodeAt(pos);
  9968. if ((trail & 0xfc00) === 0xdc00) {
  9969. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  9970. }
  9971. }
  9972. return cp;
  9973. }
  9974. setStrict(strict) {
  9975. this.state.strict = strict;
  9976. if (strict) {
  9977. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  9978. this.state.strictErrors.clear();
  9979. }
  9980. }
  9981. curContext() {
  9982. return this.state.context[this.state.context.length - 1];
  9983. }
  9984. nextToken() {
  9985. this.skipSpace();
  9986. this.state.start = this.state.pos;
  9987. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  9988. if (this.state.pos >= this.length) {
  9989. this.finishToken(140);
  9990. return;
  9991. }
  9992. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  9993. }
  9994. skipBlockComment(commentEnd) {
  9995. let startLoc;
  9996. if (!this.isLookahead) startLoc = this.state.curPosition();
  9997. const start = this.state.pos;
  9998. const end = this.input.indexOf(commentEnd, start + 2);
  9999. if (end === -1) {
  10000. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  10001. }
  10002. this.state.pos = end + commentEnd.length;
  10003. lineBreakG.lastIndex = start + 2;
  10004. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  10005. ++this.state.curLine;
  10006. this.state.lineStart = lineBreakG.lastIndex;
  10007. }
  10008. if (this.isLookahead) return;
  10009. const comment = {
  10010. type: "CommentBlock",
  10011. value: this.input.slice(start + 2, end),
  10012. start: this.sourceToOffsetPos(start),
  10013. end: this.sourceToOffsetPos(end + commentEnd.length),
  10014. loc: new SourceLocation(startLoc, this.state.curPosition())
  10015. };
  10016. if (this.optionFlags & 256) this.pushToken(comment);
  10017. return comment;
  10018. }
  10019. skipLineComment(startSkip) {
  10020. const start = this.state.pos;
  10021. let startLoc;
  10022. if (!this.isLookahead) startLoc = this.state.curPosition();
  10023. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  10024. if (this.state.pos < this.length) {
  10025. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  10026. ch = this.input.charCodeAt(this.state.pos);
  10027. }
  10028. }
  10029. if (this.isLookahead) return;
  10030. const end = this.state.pos;
  10031. const value = this.input.slice(start + startSkip, end);
  10032. const comment = {
  10033. type: "CommentLine",
  10034. value,
  10035. start: this.sourceToOffsetPos(start),
  10036. end: this.sourceToOffsetPos(end),
  10037. loc: new SourceLocation(startLoc, this.state.curPosition())
  10038. };
  10039. if (this.optionFlags & 256) this.pushToken(comment);
  10040. return comment;
  10041. }
  10042. skipSpace() {
  10043. const spaceStart = this.state.pos;
  10044. const comments = this.optionFlags & 4096 ? [] : null;
  10045. loop: while (this.state.pos < this.length) {
  10046. const ch = this.input.charCodeAt(this.state.pos);
  10047. switch (ch) {
  10048. case 32:
  10049. case 160:
  10050. case 9:
  10051. ++this.state.pos;
  10052. break;
  10053. case 13:
  10054. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  10055. ++this.state.pos;
  10056. }
  10057. case 10:
  10058. case 8232:
  10059. case 8233:
  10060. ++this.state.pos;
  10061. ++this.state.curLine;
  10062. this.state.lineStart = this.state.pos;
  10063. break;
  10064. case 47:
  10065. switch (this.input.charCodeAt(this.state.pos + 1)) {
  10066. case 42:
  10067. {
  10068. const comment = this.skipBlockComment("*/");
  10069. if (comment !== undefined) {
  10070. this.addComment(comment);
  10071. comments == null || comments.push(comment);
  10072. }
  10073. break;
  10074. }
  10075. case 47:
  10076. {
  10077. const comment = this.skipLineComment(2);
  10078. if (comment !== undefined) {
  10079. this.addComment(comment);
  10080. comments == null || comments.push(comment);
  10081. }
  10082. break;
  10083. }
  10084. default:
  10085. break loop;
  10086. }
  10087. break;
  10088. default:
  10089. if (isWhitespace(ch)) {
  10090. ++this.state.pos;
  10091. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  10092. const pos = this.state.pos;
  10093. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  10094. const comment = this.skipLineComment(3);
  10095. if (comment !== undefined) {
  10096. this.addComment(comment);
  10097. comments == null || comments.push(comment);
  10098. }
  10099. } else {
  10100. break loop;
  10101. }
  10102. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  10103. const pos = this.state.pos;
  10104. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  10105. const comment = this.skipLineComment(4);
  10106. if (comment !== undefined) {
  10107. this.addComment(comment);
  10108. comments == null || comments.push(comment);
  10109. }
  10110. } else {
  10111. break loop;
  10112. }
  10113. } else {
  10114. break loop;
  10115. }
  10116. }
  10117. }
  10118. if ((comments == null ? void 0 : comments.length) > 0) {
  10119. const end = this.state.pos;
  10120. const commentWhitespace = {
  10121. start: this.sourceToOffsetPos(spaceStart),
  10122. end: this.sourceToOffsetPos(end),
  10123. comments: comments,
  10124. leadingNode: null,
  10125. trailingNode: null,
  10126. containingNode: null
  10127. };
  10128. this.state.commentStack.push(commentWhitespace);
  10129. }
  10130. }
  10131. finishToken(type, val) {
  10132. this.state.end = this.state.pos;
  10133. this.state.endLoc = this.state.curPosition();
  10134. const prevType = this.state.type;
  10135. this.state.type = type;
  10136. this.state.value = val;
  10137. if (!this.isLookahead) {
  10138. this.updateContext(prevType);
  10139. }
  10140. }
  10141. replaceToken(type) {
  10142. this.state.type = type;
  10143. this.updateContext();
  10144. }
  10145. readToken_numberSign() {
  10146. if (this.state.pos === 0 && this.readToken_interpreter()) {
  10147. return;
  10148. }
  10149. const nextPos = this.state.pos + 1;
  10150. const next = this.codePointAtPos(nextPos);
  10151. if (next >= 48 && next <= 57) {
  10152. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  10153. }
  10154. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  10155. this.expectPlugin("recordAndTuple");
  10156. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  10157. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  10158. }
  10159. this.state.pos += 2;
  10160. if (next === 123) {
  10161. this.finishToken(7);
  10162. } else {
  10163. this.finishToken(1);
  10164. }
  10165. } else if (isIdentifierStart(next)) {
  10166. ++this.state.pos;
  10167. this.finishToken(139, this.readWord1(next));
  10168. } else if (next === 92) {
  10169. ++this.state.pos;
  10170. this.finishToken(139, this.readWord1());
  10171. } else {
  10172. this.finishOp(27, 1);
  10173. }
  10174. }
  10175. readToken_dot() {
  10176. const next = this.input.charCodeAt(this.state.pos + 1);
  10177. if (next >= 48 && next <= 57) {
  10178. this.readNumber(true);
  10179. return;
  10180. }
  10181. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  10182. this.state.pos += 3;
  10183. this.finishToken(21);
  10184. } else {
  10185. ++this.state.pos;
  10186. this.finishToken(16);
  10187. }
  10188. }
  10189. readToken_slash() {
  10190. const next = this.input.charCodeAt(this.state.pos + 1);
  10191. if (next === 61) {
  10192. this.finishOp(31, 2);
  10193. } else {
  10194. this.finishOp(56, 1);
  10195. }
  10196. }
  10197. readToken_interpreter() {
  10198. if (this.state.pos !== 0 || this.length < 2) return false;
  10199. let ch = this.input.charCodeAt(this.state.pos + 1);
  10200. if (ch !== 33) return false;
  10201. const start = this.state.pos;
  10202. this.state.pos += 1;
  10203. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  10204. ch = this.input.charCodeAt(this.state.pos);
  10205. }
  10206. const value = this.input.slice(start + 2, this.state.pos);
  10207. this.finishToken(28, value);
  10208. return true;
  10209. }
  10210. readToken_mult_modulo(code) {
  10211. let type = code === 42 ? 55 : 54;
  10212. let width = 1;
  10213. let next = this.input.charCodeAt(this.state.pos + 1);
  10214. if (code === 42 && next === 42) {
  10215. width++;
  10216. next = this.input.charCodeAt(this.state.pos + 2);
  10217. type = 57;
  10218. }
  10219. if (next === 61 && !this.state.inType) {
  10220. width++;
  10221. type = code === 37 ? 33 : 30;
  10222. }
  10223. this.finishOp(type, width);
  10224. }
  10225. readToken_pipe_amp(code) {
  10226. const next = this.input.charCodeAt(this.state.pos + 1);
  10227. if (next === code) {
  10228. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  10229. this.finishOp(30, 3);
  10230. } else {
  10231. this.finishOp(code === 124 ? 41 : 42, 2);
  10232. }
  10233. return;
  10234. }
  10235. if (code === 124) {
  10236. if (next === 62) {
  10237. this.finishOp(39, 2);
  10238. return;
  10239. }
  10240. if (this.hasPlugin("recordAndTuple") && next === 125) {
  10241. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10242. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  10243. }
  10244. this.state.pos += 2;
  10245. this.finishToken(9);
  10246. return;
  10247. }
  10248. if (this.hasPlugin("recordAndTuple") && next === 93) {
  10249. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10250. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  10251. }
  10252. this.state.pos += 2;
  10253. this.finishToken(4);
  10254. return;
  10255. }
  10256. }
  10257. if (next === 61) {
  10258. this.finishOp(30, 2);
  10259. return;
  10260. }
  10261. this.finishOp(code === 124 ? 43 : 45, 1);
  10262. }
  10263. readToken_caret() {
  10264. const next = this.input.charCodeAt(this.state.pos + 1);
  10265. if (next === 61 && !this.state.inType) {
  10266. this.finishOp(32, 2);
  10267. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  10268. proposal: "hack",
  10269. topicToken: "^^"
  10270. }])) {
  10271. this.finishOp(37, 2);
  10272. const lookaheadCh = this.input.codePointAt(this.state.pos);
  10273. if (lookaheadCh === 94) {
  10274. this.unexpected();
  10275. }
  10276. } else {
  10277. this.finishOp(44, 1);
  10278. }
  10279. }
  10280. readToken_atSign() {
  10281. const next = this.input.charCodeAt(this.state.pos + 1);
  10282. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  10283. proposal: "hack",
  10284. topicToken: "@@"
  10285. }])) {
  10286. this.finishOp(38, 2);
  10287. } else {
  10288. this.finishOp(26, 1);
  10289. }
  10290. }
  10291. readToken_plus_min(code) {
  10292. const next = this.input.charCodeAt(this.state.pos + 1);
  10293. if (next === code) {
  10294. this.finishOp(34, 2);
  10295. return;
  10296. }
  10297. if (next === 61) {
  10298. this.finishOp(30, 2);
  10299. } else {
  10300. this.finishOp(53, 1);
  10301. }
  10302. }
  10303. readToken_lt() {
  10304. const {
  10305. pos
  10306. } = this.state;
  10307. const next = this.input.charCodeAt(pos + 1);
  10308. if (next === 60) {
  10309. if (this.input.charCodeAt(pos + 2) === 61) {
  10310. this.finishOp(30, 3);
  10311. return;
  10312. }
  10313. this.finishOp(51, 2);
  10314. return;
  10315. }
  10316. if (next === 61) {
  10317. this.finishOp(49, 2);
  10318. return;
  10319. }
  10320. this.finishOp(47, 1);
  10321. }
  10322. readToken_gt() {
  10323. const {
  10324. pos
  10325. } = this.state;
  10326. const next = this.input.charCodeAt(pos + 1);
  10327. if (next === 62) {
  10328. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  10329. if (this.input.charCodeAt(pos + size) === 61) {
  10330. this.finishOp(30, size + 1);
  10331. return;
  10332. }
  10333. this.finishOp(52, size);
  10334. return;
  10335. }
  10336. if (next === 61) {
  10337. this.finishOp(49, 2);
  10338. return;
  10339. }
  10340. this.finishOp(48, 1);
  10341. }
  10342. readToken_eq_excl(code) {
  10343. const next = this.input.charCodeAt(this.state.pos + 1);
  10344. if (next === 61) {
  10345. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  10346. return;
  10347. }
  10348. if (code === 61 && next === 62) {
  10349. this.state.pos += 2;
  10350. this.finishToken(19);
  10351. return;
  10352. }
  10353. this.finishOp(code === 61 ? 29 : 35, 1);
  10354. }
  10355. readToken_question() {
  10356. const next = this.input.charCodeAt(this.state.pos + 1);
  10357. const next2 = this.input.charCodeAt(this.state.pos + 2);
  10358. if (next === 63) {
  10359. if (next2 === 61) {
  10360. this.finishOp(30, 3);
  10361. } else {
  10362. this.finishOp(40, 2);
  10363. }
  10364. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  10365. this.state.pos += 2;
  10366. this.finishToken(18);
  10367. } else {
  10368. ++this.state.pos;
  10369. this.finishToken(17);
  10370. }
  10371. }
  10372. getTokenFromCode(code) {
  10373. switch (code) {
  10374. case 46:
  10375. this.readToken_dot();
  10376. return;
  10377. case 40:
  10378. ++this.state.pos;
  10379. this.finishToken(10);
  10380. return;
  10381. case 41:
  10382. ++this.state.pos;
  10383. this.finishToken(11);
  10384. return;
  10385. case 59:
  10386. ++this.state.pos;
  10387. this.finishToken(13);
  10388. return;
  10389. case 44:
  10390. ++this.state.pos;
  10391. this.finishToken(12);
  10392. return;
  10393. case 91:
  10394. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  10395. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10396. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  10397. }
  10398. this.state.pos += 2;
  10399. this.finishToken(2);
  10400. } else {
  10401. ++this.state.pos;
  10402. this.finishToken(0);
  10403. }
  10404. return;
  10405. case 93:
  10406. ++this.state.pos;
  10407. this.finishToken(3);
  10408. return;
  10409. case 123:
  10410. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  10411. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  10412. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  10413. }
  10414. this.state.pos += 2;
  10415. this.finishToken(6);
  10416. } else {
  10417. ++this.state.pos;
  10418. this.finishToken(5);
  10419. }
  10420. return;
  10421. case 125:
  10422. ++this.state.pos;
  10423. this.finishToken(8);
  10424. return;
  10425. case 58:
  10426. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  10427. this.finishOp(15, 2);
  10428. } else {
  10429. ++this.state.pos;
  10430. this.finishToken(14);
  10431. }
  10432. return;
  10433. case 63:
  10434. this.readToken_question();
  10435. return;
  10436. case 96:
  10437. this.readTemplateToken();
  10438. return;
  10439. case 48:
  10440. {
  10441. const next = this.input.charCodeAt(this.state.pos + 1);
  10442. if (next === 120 || next === 88) {
  10443. this.readRadixNumber(16);
  10444. return;
  10445. }
  10446. if (next === 111 || next === 79) {
  10447. this.readRadixNumber(8);
  10448. return;
  10449. }
  10450. if (next === 98 || next === 66) {
  10451. this.readRadixNumber(2);
  10452. return;
  10453. }
  10454. }
  10455. case 49:
  10456. case 50:
  10457. case 51:
  10458. case 52:
  10459. case 53:
  10460. case 54:
  10461. case 55:
  10462. case 56:
  10463. case 57:
  10464. this.readNumber(false);
  10465. return;
  10466. case 34:
  10467. case 39:
  10468. this.readString(code);
  10469. return;
  10470. case 47:
  10471. this.readToken_slash();
  10472. return;
  10473. case 37:
  10474. case 42:
  10475. this.readToken_mult_modulo(code);
  10476. return;
  10477. case 124:
  10478. case 38:
  10479. this.readToken_pipe_amp(code);
  10480. return;
  10481. case 94:
  10482. this.readToken_caret();
  10483. return;
  10484. case 43:
  10485. case 45:
  10486. this.readToken_plus_min(code);
  10487. return;
  10488. case 60:
  10489. this.readToken_lt();
  10490. return;
  10491. case 62:
  10492. this.readToken_gt();
  10493. return;
  10494. case 61:
  10495. case 33:
  10496. this.readToken_eq_excl(code);
  10497. return;
  10498. case 126:
  10499. this.finishOp(36, 1);
  10500. return;
  10501. case 64:
  10502. this.readToken_atSign();
  10503. return;
  10504. case 35:
  10505. this.readToken_numberSign();
  10506. return;
  10507. case 92:
  10508. this.readWord();
  10509. return;
  10510. default:
  10511. if (isIdentifierStart(code)) {
  10512. this.readWord(code);
  10513. return;
  10514. }
  10515. }
  10516. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  10517. unexpected: String.fromCodePoint(code)
  10518. });
  10519. }
  10520. finishOp(type, size) {
  10521. const str = this.input.slice(this.state.pos, this.state.pos + size);
  10522. this.state.pos += size;
  10523. this.finishToken(type, str);
  10524. }
  10525. readRegexp() {
  10526. const startLoc = this.state.startLoc;
  10527. const start = this.state.start + 1;
  10528. let escaped, inClass;
  10529. let {
  10530. pos
  10531. } = this.state;
  10532. for (;; ++pos) {
  10533. if (pos >= this.length) {
  10534. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  10535. }
  10536. const ch = this.input.charCodeAt(pos);
  10537. if (isNewLine(ch)) {
  10538. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  10539. }
  10540. if (escaped) {
  10541. escaped = false;
  10542. } else {
  10543. if (ch === 91) {
  10544. inClass = true;
  10545. } else if (ch === 93 && inClass) {
  10546. inClass = false;
  10547. } else if (ch === 47 && !inClass) {
  10548. break;
  10549. }
  10550. escaped = ch === 92;
  10551. }
  10552. }
  10553. const content = this.input.slice(start, pos);
  10554. ++pos;
  10555. let mods = "";
  10556. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  10557. while (pos < this.length) {
  10558. const cp = this.codePointAtPos(pos);
  10559. const char = String.fromCharCode(cp);
  10560. if (VALID_REGEX_FLAGS.has(cp)) {
  10561. if (cp === 118) {
  10562. if (mods.includes("u")) {
  10563. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  10564. }
  10565. } else if (cp === 117) {
  10566. if (mods.includes("v")) {
  10567. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  10568. }
  10569. }
  10570. if (mods.includes(char)) {
  10571. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  10572. }
  10573. } else if (isIdentifierChar(cp) || cp === 92) {
  10574. this.raise(Errors.MalformedRegExpFlags, nextPos());
  10575. } else {
  10576. break;
  10577. }
  10578. ++pos;
  10579. mods += char;
  10580. }
  10581. this.state.pos = pos;
  10582. this.finishToken(138, {
  10583. pattern: content,
  10584. flags: mods
  10585. });
  10586. }
  10587. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  10588. const {
  10589. n,
  10590. pos
  10591. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  10592. this.state.pos = pos;
  10593. return n;
  10594. }
  10595. readRadixNumber(radix) {
  10596. const start = this.state.pos;
  10597. const startLoc = this.state.curPosition();
  10598. let isBigInt = false;
  10599. this.state.pos += 2;
  10600. const val = this.readInt(radix);
  10601. if (val == null) {
  10602. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  10603. radix
  10604. });
  10605. }
  10606. const next = this.input.charCodeAt(this.state.pos);
  10607. if (next === 110) {
  10608. ++this.state.pos;
  10609. isBigInt = true;
  10610. } else if (next === 109) {
  10611. throw this.raise(Errors.InvalidDecimal, startLoc);
  10612. }
  10613. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  10614. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  10615. }
  10616. if (isBigInt) {
  10617. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  10618. this.finishToken(136, str);
  10619. return;
  10620. }
  10621. this.finishToken(135, val);
  10622. }
  10623. readNumber(startsWithDot) {
  10624. const start = this.state.pos;
  10625. const startLoc = this.state.curPosition();
  10626. let isFloat = false;
  10627. let isBigInt = false;
  10628. let hasExponent = false;
  10629. let isOctal = false;
  10630. if (!startsWithDot && this.readInt(10) === null) {
  10631. this.raise(Errors.InvalidNumber, this.state.curPosition());
  10632. }
  10633. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  10634. if (hasLeadingZero) {
  10635. const integer = this.input.slice(start, this.state.pos);
  10636. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  10637. if (!this.state.strict) {
  10638. const underscorePos = integer.indexOf("_");
  10639. if (underscorePos > 0) {
  10640. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  10641. }
  10642. }
  10643. isOctal = hasLeadingZero && !/[89]/.test(integer);
  10644. }
  10645. let next = this.input.charCodeAt(this.state.pos);
  10646. if (next === 46 && !isOctal) {
  10647. ++this.state.pos;
  10648. this.readInt(10);
  10649. isFloat = true;
  10650. next = this.input.charCodeAt(this.state.pos);
  10651. }
  10652. if ((next === 69 || next === 101) && !isOctal) {
  10653. next = this.input.charCodeAt(++this.state.pos);
  10654. if (next === 43 || next === 45) {
  10655. ++this.state.pos;
  10656. }
  10657. if (this.readInt(10) === null) {
  10658. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  10659. }
  10660. isFloat = true;
  10661. hasExponent = true;
  10662. next = this.input.charCodeAt(this.state.pos);
  10663. }
  10664. if (next === 110) {
  10665. if (isFloat || hasLeadingZero) {
  10666. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  10667. }
  10668. ++this.state.pos;
  10669. isBigInt = true;
  10670. }
  10671. if (next === 109) {
  10672. this.expectPlugin("decimal", this.state.curPosition());
  10673. if (hasExponent || hasLeadingZero) {
  10674. this.raise(Errors.InvalidDecimal, startLoc);
  10675. }
  10676. ++this.state.pos;
  10677. var isDecimal = true;
  10678. }
  10679. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  10680. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  10681. }
  10682. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  10683. if (isBigInt) {
  10684. this.finishToken(136, str);
  10685. return;
  10686. }
  10687. if (isDecimal) {
  10688. this.finishToken(137, str);
  10689. return;
  10690. }
  10691. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  10692. this.finishToken(135, val);
  10693. }
  10694. readCodePoint(throwOnInvalid) {
  10695. const {
  10696. code,
  10697. pos
  10698. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  10699. this.state.pos = pos;
  10700. return code;
  10701. }
  10702. readString(quote) {
  10703. const {
  10704. str,
  10705. pos,
  10706. curLine,
  10707. lineStart
  10708. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  10709. this.state.pos = pos + 1;
  10710. this.state.lineStart = lineStart;
  10711. this.state.curLine = curLine;
  10712. this.finishToken(134, str);
  10713. }
  10714. readTemplateContinuation() {
  10715. if (!this.match(8)) {
  10716. this.unexpected(null, 8);
  10717. }
  10718. this.state.pos--;
  10719. this.readTemplateToken();
  10720. }
  10721. readTemplateToken() {
  10722. const opening = this.input[this.state.pos];
  10723. const {
  10724. str,
  10725. firstInvalidLoc,
  10726. pos,
  10727. curLine,
  10728. lineStart
  10729. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  10730. this.state.pos = pos + 1;
  10731. this.state.lineStart = lineStart;
  10732. this.state.curLine = curLine;
  10733. if (firstInvalidLoc) {
  10734. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  10735. }
  10736. if (this.input.codePointAt(pos) === 96) {
  10737. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  10738. } else {
  10739. this.state.pos++;
  10740. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  10741. }
  10742. }
  10743. recordStrictModeErrors(toParseError, at) {
  10744. const index = at.index;
  10745. if (this.state.strict && !this.state.strictErrors.has(index)) {
  10746. this.raise(toParseError, at);
  10747. } else {
  10748. this.state.strictErrors.set(index, [toParseError, at]);
  10749. }
  10750. }
  10751. readWord1(firstCode) {
  10752. this.state.containsEsc = false;
  10753. let word = "";
  10754. const start = this.state.pos;
  10755. let chunkStart = this.state.pos;
  10756. if (firstCode !== undefined) {
  10757. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  10758. }
  10759. while (this.state.pos < this.length) {
  10760. const ch = this.codePointAtPos(this.state.pos);
  10761. if (isIdentifierChar(ch)) {
  10762. this.state.pos += ch <= 0xffff ? 1 : 2;
  10763. } else if (ch === 92) {
  10764. this.state.containsEsc = true;
  10765. word += this.input.slice(chunkStart, this.state.pos);
  10766. const escStart = this.state.curPosition();
  10767. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  10768. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  10769. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  10770. chunkStart = this.state.pos - 1;
  10771. continue;
  10772. }
  10773. ++this.state.pos;
  10774. const esc = this.readCodePoint(true);
  10775. if (esc !== null) {
  10776. if (!identifierCheck(esc)) {
  10777. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  10778. }
  10779. word += String.fromCodePoint(esc);
  10780. }
  10781. chunkStart = this.state.pos;
  10782. } else {
  10783. break;
  10784. }
  10785. }
  10786. return word + this.input.slice(chunkStart, this.state.pos);
  10787. }
  10788. readWord(firstCode) {
  10789. const word = this.readWord1(firstCode);
  10790. const type = keywords$1.get(word);
  10791. if (type !== undefined) {
  10792. this.finishToken(type, tokenLabelName(type));
  10793. } else {
  10794. this.finishToken(132, word);
  10795. }
  10796. }
  10797. checkKeywordEscapes() {
  10798. const {
  10799. type
  10800. } = this.state;
  10801. if (tokenIsKeyword(type) && this.state.containsEsc) {
  10802. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  10803. reservedWord: tokenLabelName(type)
  10804. });
  10805. }
  10806. }
  10807. raise(toParseError, at, details = {}) {
  10808. const loc = at instanceof Position ? at : at.loc.start;
  10809. const error = toParseError(loc, details);
  10810. if (!(this.optionFlags & 2048)) throw error;
  10811. if (!this.isLookahead) this.state.errors.push(error);
  10812. return error;
  10813. }
  10814. raiseOverwrite(toParseError, at, details = {}) {
  10815. const loc = at instanceof Position ? at : at.loc.start;
  10816. const pos = loc.index;
  10817. const errors = this.state.errors;
  10818. for (let i = errors.length - 1; i >= 0; i--) {
  10819. const error = errors[i];
  10820. if (error.loc.index === pos) {
  10821. return errors[i] = toParseError(loc, details);
  10822. }
  10823. if (error.loc.index < pos) break;
  10824. }
  10825. return this.raise(toParseError, at, details);
  10826. }
  10827. updateContext(prevType) {}
  10828. unexpected(loc, type) {
  10829. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  10830. expected: type ? tokenLabelName(type) : null
  10831. });
  10832. }
  10833. expectPlugin(pluginName, loc) {
  10834. if (this.hasPlugin(pluginName)) {
  10835. return true;
  10836. }
  10837. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  10838. missingPlugin: [pluginName]
  10839. });
  10840. }
  10841. expectOnePlugin(pluginNames) {
  10842. if (!pluginNames.some(name => this.hasPlugin(name))) {
  10843. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  10844. missingPlugin: pluginNames
  10845. });
  10846. }
  10847. }
  10848. errorBuilder(error) {
  10849. return (pos, lineStart, curLine) => {
  10850. this.raise(error, buildPosition(pos, lineStart, curLine));
  10851. };
  10852. }
  10853. }
  10854. class ClassScope {
  10855. constructor() {
  10856. this.privateNames = new Set();
  10857. this.loneAccessors = new Map();
  10858. this.undefinedPrivateNames = new Map();
  10859. }
  10860. }
  10861. class ClassScopeHandler {
  10862. constructor(parser) {
  10863. this.parser = void 0;
  10864. this.stack = [];
  10865. this.undefinedPrivateNames = new Map();
  10866. this.parser = parser;
  10867. }
  10868. current() {
  10869. return this.stack[this.stack.length - 1];
  10870. }
  10871. enter() {
  10872. this.stack.push(new ClassScope());
  10873. }
  10874. exit() {
  10875. const oldClassScope = this.stack.pop();
  10876. const current = this.current();
  10877. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  10878. if (current) {
  10879. if (!current.undefinedPrivateNames.has(name)) {
  10880. current.undefinedPrivateNames.set(name, loc);
  10881. }
  10882. } else {
  10883. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  10884. identifierName: name
  10885. });
  10886. }
  10887. }
  10888. }
  10889. declarePrivateName(name, elementType, loc) {
  10890. const {
  10891. privateNames,
  10892. loneAccessors,
  10893. undefinedPrivateNames
  10894. } = this.current();
  10895. let redefined = privateNames.has(name);
  10896. if (elementType & 3) {
  10897. const accessor = redefined && loneAccessors.get(name);
  10898. if (accessor) {
  10899. const oldStatic = accessor & 4;
  10900. const newStatic = elementType & 4;
  10901. const oldKind = accessor & 3;
  10902. const newKind = elementType & 3;
  10903. redefined = oldKind === newKind || oldStatic !== newStatic;
  10904. if (!redefined) loneAccessors.delete(name);
  10905. } else if (!redefined) {
  10906. loneAccessors.set(name, elementType);
  10907. }
  10908. }
  10909. if (redefined) {
  10910. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  10911. identifierName: name
  10912. });
  10913. }
  10914. privateNames.add(name);
  10915. undefinedPrivateNames.delete(name);
  10916. }
  10917. usePrivateName(name, loc) {
  10918. let classScope;
  10919. for (classScope of this.stack) {
  10920. if (classScope.privateNames.has(name)) return;
  10921. }
  10922. if (classScope) {
  10923. classScope.undefinedPrivateNames.set(name, loc);
  10924. } else {
  10925. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  10926. identifierName: name
  10927. });
  10928. }
  10929. }
  10930. }
  10931. class ExpressionScope {
  10932. constructor(type = 0) {
  10933. this.type = type;
  10934. }
  10935. canBeArrowParameterDeclaration() {
  10936. return this.type === 2 || this.type === 1;
  10937. }
  10938. isCertainlyParameterDeclaration() {
  10939. return this.type === 3;
  10940. }
  10941. }
  10942. class ArrowHeadParsingScope extends ExpressionScope {
  10943. constructor(type) {
  10944. super(type);
  10945. this.declarationErrors = new Map();
  10946. }
  10947. recordDeclarationError(ParsingErrorClass, at) {
  10948. const index = at.index;
  10949. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  10950. }
  10951. clearDeclarationError(index) {
  10952. this.declarationErrors.delete(index);
  10953. }
  10954. iterateErrors(iterator) {
  10955. this.declarationErrors.forEach(iterator);
  10956. }
  10957. }
  10958. class ExpressionScopeHandler {
  10959. constructor(parser) {
  10960. this.parser = void 0;
  10961. this.stack = [new ExpressionScope()];
  10962. this.parser = parser;
  10963. }
  10964. enter(scope) {
  10965. this.stack.push(scope);
  10966. }
  10967. exit() {
  10968. this.stack.pop();
  10969. }
  10970. recordParameterInitializerError(toParseError, node) {
  10971. const origin = node.loc.start;
  10972. const {
  10973. stack
  10974. } = this;
  10975. let i = stack.length - 1;
  10976. let scope = stack[i];
  10977. while (!scope.isCertainlyParameterDeclaration()) {
  10978. if (scope.canBeArrowParameterDeclaration()) {
  10979. scope.recordDeclarationError(toParseError, origin);
  10980. } else {
  10981. return;
  10982. }
  10983. scope = stack[--i];
  10984. }
  10985. this.parser.raise(toParseError, origin);
  10986. }
  10987. recordArrowParameterBindingError(error, node) {
  10988. const {
  10989. stack
  10990. } = this;
  10991. const scope = stack[stack.length - 1];
  10992. const origin = node.loc.start;
  10993. if (scope.isCertainlyParameterDeclaration()) {
  10994. this.parser.raise(error, origin);
  10995. } else if (scope.canBeArrowParameterDeclaration()) {
  10996. scope.recordDeclarationError(error, origin);
  10997. } else {
  10998. return;
  10999. }
  11000. }
  11001. recordAsyncArrowParametersError(at) {
  11002. const {
  11003. stack
  11004. } = this;
  11005. let i = stack.length - 1;
  11006. let scope = stack[i];
  11007. while (scope.canBeArrowParameterDeclaration()) {
  11008. if (scope.type === 2) {
  11009. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  11010. }
  11011. scope = stack[--i];
  11012. }
  11013. }
  11014. validateAsPattern() {
  11015. const {
  11016. stack
  11017. } = this;
  11018. const currentScope = stack[stack.length - 1];
  11019. if (!currentScope.canBeArrowParameterDeclaration()) return;
  11020. currentScope.iterateErrors(([toParseError, loc]) => {
  11021. this.parser.raise(toParseError, loc);
  11022. let i = stack.length - 2;
  11023. let scope = stack[i];
  11024. while (scope.canBeArrowParameterDeclaration()) {
  11025. scope.clearDeclarationError(loc.index);
  11026. scope = stack[--i];
  11027. }
  11028. });
  11029. }
  11030. }
  11031. function newParameterDeclarationScope() {
  11032. return new ExpressionScope(3);
  11033. }
  11034. function newArrowHeadScope() {
  11035. return new ArrowHeadParsingScope(1);
  11036. }
  11037. function newAsyncArrowScope() {
  11038. return new ArrowHeadParsingScope(2);
  11039. }
  11040. function newExpressionScope() {
  11041. return new ExpressionScope();
  11042. }
  11043. class UtilParser extends Tokenizer {
  11044. addExtra(node, key, value, enumerable = true) {
  11045. if (!node) return;
  11046. let {
  11047. extra
  11048. } = node;
  11049. if (extra == null) {
  11050. extra = {};
  11051. node.extra = extra;
  11052. }
  11053. if (enumerable) {
  11054. extra[key] = value;
  11055. } else {
  11056. Object.defineProperty(extra, key, {
  11057. enumerable,
  11058. value
  11059. });
  11060. }
  11061. }
  11062. isContextual(token) {
  11063. return this.state.type === token && !this.state.containsEsc;
  11064. }
  11065. isUnparsedContextual(nameStart, name) {
  11066. if (this.input.startsWith(name, nameStart)) {
  11067. const nextCh = this.input.charCodeAt(nameStart + name.length);
  11068. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  11069. }
  11070. return false;
  11071. }
  11072. isLookaheadContextual(name) {
  11073. const next = this.nextTokenStart();
  11074. return this.isUnparsedContextual(next, name);
  11075. }
  11076. eatContextual(token) {
  11077. if (this.isContextual(token)) {
  11078. this.next();
  11079. return true;
  11080. }
  11081. return false;
  11082. }
  11083. expectContextual(token, toParseError) {
  11084. if (!this.eatContextual(token)) {
  11085. if (toParseError != null) {
  11086. throw this.raise(toParseError, this.state.startLoc);
  11087. }
  11088. this.unexpected(null, token);
  11089. }
  11090. }
  11091. canInsertSemicolon() {
  11092. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  11093. }
  11094. hasPrecedingLineBreak() {
  11095. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  11096. }
  11097. hasFollowingLineBreak() {
  11098. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  11099. }
  11100. isLineTerminator() {
  11101. return this.eat(13) || this.canInsertSemicolon();
  11102. }
  11103. semicolon(allowAsi = true) {
  11104. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  11105. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  11106. }
  11107. expect(type, loc) {
  11108. if (!this.eat(type)) {
  11109. this.unexpected(loc, type);
  11110. }
  11111. }
  11112. tryParse(fn, oldState = this.state.clone()) {
  11113. const abortSignal = {
  11114. node: null
  11115. };
  11116. try {
  11117. const node = fn((node = null) => {
  11118. abortSignal.node = node;
  11119. throw abortSignal;
  11120. });
  11121. if (this.state.errors.length > oldState.errors.length) {
  11122. const failState = this.state;
  11123. this.state = oldState;
  11124. this.state.tokensLength = failState.tokensLength;
  11125. return {
  11126. node,
  11127. error: failState.errors[oldState.errors.length],
  11128. thrown: false,
  11129. aborted: false,
  11130. failState
  11131. };
  11132. }
  11133. return {
  11134. node: node,
  11135. error: null,
  11136. thrown: false,
  11137. aborted: false,
  11138. failState: null
  11139. };
  11140. } catch (error) {
  11141. const failState = this.state;
  11142. this.state = oldState;
  11143. if (error instanceof SyntaxError) {
  11144. return {
  11145. node: null,
  11146. error,
  11147. thrown: true,
  11148. aborted: false,
  11149. failState
  11150. };
  11151. }
  11152. if (error === abortSignal) {
  11153. return {
  11154. node: abortSignal.node,
  11155. error: null,
  11156. thrown: false,
  11157. aborted: true,
  11158. failState
  11159. };
  11160. }
  11161. throw error;
  11162. }
  11163. }
  11164. checkExpressionErrors(refExpressionErrors, andThrow) {
  11165. if (!refExpressionErrors) return false;
  11166. const {
  11167. shorthandAssignLoc,
  11168. doubleProtoLoc,
  11169. privateKeyLoc,
  11170. optionalParametersLoc,
  11171. voidPatternLoc
  11172. } = refExpressionErrors;
  11173. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  11174. if (!andThrow) {
  11175. return hasErrors;
  11176. }
  11177. if (shorthandAssignLoc != null) {
  11178. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  11179. }
  11180. if (doubleProtoLoc != null) {
  11181. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  11182. }
  11183. if (privateKeyLoc != null) {
  11184. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  11185. }
  11186. if (optionalParametersLoc != null) {
  11187. this.unexpected(optionalParametersLoc);
  11188. }
  11189. if (voidPatternLoc != null) {
  11190. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  11191. }
  11192. }
  11193. isLiteralPropertyName() {
  11194. return tokenIsLiteralPropertyName(this.state.type);
  11195. }
  11196. isPrivateName(node) {
  11197. return node.type === "PrivateName";
  11198. }
  11199. getPrivateNameSV(node) {
  11200. return node.id.name;
  11201. }
  11202. hasPropertyAsPrivateName(node) {
  11203. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  11204. }
  11205. isObjectProperty(node) {
  11206. return node.type === "ObjectProperty";
  11207. }
  11208. isObjectMethod(node) {
  11209. return node.type === "ObjectMethod";
  11210. }
  11211. initializeScopes(inModule = this.options.sourceType === "module") {
  11212. const oldLabels = this.state.labels;
  11213. this.state.labels = [];
  11214. const oldExportedIdentifiers = this.exportedIdentifiers;
  11215. this.exportedIdentifiers = new Set();
  11216. const oldInModule = this.inModule;
  11217. this.inModule = inModule;
  11218. const oldScope = this.scope;
  11219. const ScopeHandler = this.getScopeHandler();
  11220. this.scope = new ScopeHandler(this, inModule);
  11221. const oldProdParam = this.prodParam;
  11222. this.prodParam = new ProductionParameterHandler();
  11223. const oldClassScope = this.classScope;
  11224. this.classScope = new ClassScopeHandler(this);
  11225. const oldExpressionScope = this.expressionScope;
  11226. this.expressionScope = new ExpressionScopeHandler(this);
  11227. return () => {
  11228. this.state.labels = oldLabels;
  11229. this.exportedIdentifiers = oldExportedIdentifiers;
  11230. this.inModule = oldInModule;
  11231. this.scope = oldScope;
  11232. this.prodParam = oldProdParam;
  11233. this.classScope = oldClassScope;
  11234. this.expressionScope = oldExpressionScope;
  11235. };
  11236. }
  11237. enterInitialScopes() {
  11238. let paramFlags = 0;
  11239. if (this.inModule || this.optionFlags & 1) {
  11240. paramFlags |= 2;
  11241. }
  11242. if (this.optionFlags & 32) {
  11243. paramFlags |= 1;
  11244. }
  11245. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  11246. if (isCommonJS || this.optionFlags & 2) {
  11247. paramFlags |= 4;
  11248. }
  11249. this.prodParam.enter(paramFlags);
  11250. let scopeFlags = isCommonJS ? 514 : 1;
  11251. if (this.optionFlags & 4) {
  11252. scopeFlags |= 512;
  11253. }
  11254. this.scope.enter(scopeFlags);
  11255. }
  11256. checkDestructuringPrivate(refExpressionErrors) {
  11257. const {
  11258. privateKeyLoc
  11259. } = refExpressionErrors;
  11260. if (privateKeyLoc !== null) {
  11261. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  11262. }
  11263. }
  11264. }
  11265. class ExpressionErrors {
  11266. constructor() {
  11267. this.shorthandAssignLoc = null;
  11268. this.doubleProtoLoc = null;
  11269. this.privateKeyLoc = null;
  11270. this.optionalParametersLoc = null;
  11271. this.voidPatternLoc = null;
  11272. }
  11273. }
  11274. class Node {
  11275. constructor(parser, pos, loc) {
  11276. this.type = "";
  11277. this.start = pos;
  11278. this.end = 0;
  11279. this.loc = new SourceLocation(loc);
  11280. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  11281. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  11282. }
  11283. }
  11284. const NodePrototype = Node.prototype;
  11285. NodePrototype.__clone = function () {
  11286. const newNode = new Node(undefined, this.start, this.loc.start);
  11287. const keys = Object.keys(this);
  11288. for (let i = 0, length = keys.length; i < length; i++) {
  11289. const key = keys[i];
  11290. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  11291. newNode[key] = this[key];
  11292. }
  11293. }
  11294. return newNode;
  11295. };
  11296. class NodeUtils extends UtilParser {
  11297. startNode() {
  11298. const loc = this.state.startLoc;
  11299. return new Node(this, loc.index, loc);
  11300. }
  11301. startNodeAt(loc) {
  11302. return new Node(this, loc.index, loc);
  11303. }
  11304. startNodeAtNode(type) {
  11305. return this.startNodeAt(type.loc.start);
  11306. }
  11307. finishNode(node, type) {
  11308. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  11309. }
  11310. finishNodeAt(node, type, endLoc) {
  11311. node.type = type;
  11312. node.end = endLoc.index;
  11313. node.loc.end = endLoc;
  11314. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  11315. if (this.optionFlags & 4096) {
  11316. this.processComment(node);
  11317. }
  11318. return node;
  11319. }
  11320. resetStartLocation(node, startLoc) {
  11321. node.start = startLoc.index;
  11322. node.loc.start = startLoc;
  11323. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  11324. }
  11325. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  11326. node.end = endLoc.index;
  11327. node.loc.end = endLoc;
  11328. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  11329. }
  11330. resetStartLocationFromNode(node, locationNode) {
  11331. this.resetStartLocation(node, locationNode.loc.start);
  11332. }
  11333. castNodeTo(node, type) {
  11334. node.type = type;
  11335. return node;
  11336. }
  11337. cloneIdentifier(node) {
  11338. const {
  11339. type,
  11340. start,
  11341. end,
  11342. loc,
  11343. range,
  11344. name
  11345. } = node;
  11346. const cloned = Object.create(NodePrototype);
  11347. cloned.type = type;
  11348. cloned.start = start;
  11349. cloned.end = end;
  11350. cloned.loc = loc;
  11351. cloned.range = range;
  11352. cloned.name = name;
  11353. if (node.extra) cloned.extra = node.extra;
  11354. return cloned;
  11355. }
  11356. cloneStringLiteral(node) {
  11357. const {
  11358. type,
  11359. start,
  11360. end,
  11361. loc,
  11362. range,
  11363. extra
  11364. } = node;
  11365. const cloned = Object.create(NodePrototype);
  11366. cloned.type = type;
  11367. cloned.start = start;
  11368. cloned.end = end;
  11369. cloned.loc = loc;
  11370. cloned.range = range;
  11371. cloned.extra = extra;
  11372. cloned.value = node.value;
  11373. return cloned;
  11374. }
  11375. }
  11376. const unwrapParenthesizedExpression = node => {
  11377. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  11378. };
  11379. class LValParser extends NodeUtils {
  11380. toAssignable(node, isLHS = false) {
  11381. var _node$extra, _node$extra3;
  11382. let parenthesized = undefined;
  11383. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  11384. parenthesized = unwrapParenthesizedExpression(node);
  11385. if (isLHS) {
  11386. if (parenthesized.type === "Identifier") {
  11387. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  11388. } else if (parenthesized.type !== "CallExpression" && parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  11389. this.raise(Errors.InvalidParenthesizedAssignment, node);
  11390. }
  11391. } else {
  11392. this.raise(Errors.InvalidParenthesizedAssignment, node);
  11393. }
  11394. }
  11395. switch (node.type) {
  11396. case "Identifier":
  11397. case "ObjectPattern":
  11398. case "ArrayPattern":
  11399. case "AssignmentPattern":
  11400. case "RestElement":
  11401. case "VoidPattern":
  11402. break;
  11403. case "ObjectExpression":
  11404. this.castNodeTo(node, "ObjectPattern");
  11405. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  11406. var _node$extra2;
  11407. const prop = node.properties[i];
  11408. const isLast = i === last;
  11409. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  11410. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  11411. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  11412. }
  11413. }
  11414. break;
  11415. case "ObjectProperty":
  11416. {
  11417. const {
  11418. key,
  11419. value
  11420. } = node;
  11421. if (this.isPrivateName(key)) {
  11422. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  11423. }
  11424. this.toAssignable(value, isLHS);
  11425. break;
  11426. }
  11427. case "SpreadElement":
  11428. {
  11429. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  11430. }
  11431. case "ArrayExpression":
  11432. this.castNodeTo(node, "ArrayPattern");
  11433. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  11434. break;
  11435. case "AssignmentExpression":
  11436. if (node.operator !== "=") {
  11437. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  11438. }
  11439. this.castNodeTo(node, "AssignmentPattern");
  11440. delete node.operator;
  11441. if (node.left.type === "VoidPattern") {
  11442. this.raise(Errors.VoidPatternInitializer, node.left);
  11443. }
  11444. this.toAssignable(node.left, isLHS);
  11445. break;
  11446. case "ParenthesizedExpression":
  11447. this.toAssignable(parenthesized, isLHS);
  11448. break;
  11449. }
  11450. }
  11451. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  11452. if (prop.type === "ObjectMethod") {
  11453. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  11454. } else if (prop.type === "SpreadElement") {
  11455. this.castNodeTo(prop, "RestElement");
  11456. const arg = prop.argument;
  11457. this.checkToRestConversion(arg, false);
  11458. this.toAssignable(arg, isLHS);
  11459. if (!isLast) {
  11460. this.raise(Errors.RestTrailingComma, prop);
  11461. }
  11462. } else {
  11463. this.toAssignable(prop, isLHS);
  11464. }
  11465. }
  11466. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  11467. const end = exprList.length - 1;
  11468. for (let i = 0; i <= end; i++) {
  11469. const elt = exprList[i];
  11470. if (!elt) continue;
  11471. this.toAssignableListItem(exprList, i, isLHS);
  11472. if (elt.type === "RestElement") {
  11473. if (i < end) {
  11474. this.raise(Errors.RestTrailingComma, elt);
  11475. } else if (trailingCommaLoc) {
  11476. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  11477. }
  11478. }
  11479. }
  11480. }
  11481. toAssignableListItem(exprList, index, isLHS) {
  11482. const node = exprList[index];
  11483. if (node.type === "SpreadElement") {
  11484. this.castNodeTo(node, "RestElement");
  11485. const arg = node.argument;
  11486. this.checkToRestConversion(arg, true);
  11487. this.toAssignable(arg, isLHS);
  11488. } else {
  11489. this.toAssignable(node, isLHS);
  11490. }
  11491. }
  11492. isAssignable(node, isBinding) {
  11493. switch (node.type) {
  11494. case "Identifier":
  11495. case "ObjectPattern":
  11496. case "ArrayPattern":
  11497. case "AssignmentPattern":
  11498. case "RestElement":
  11499. case "VoidPattern":
  11500. return true;
  11501. case "ObjectExpression":
  11502. {
  11503. const last = node.properties.length - 1;
  11504. return node.properties.every((prop, i) => {
  11505. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  11506. });
  11507. }
  11508. case "ObjectProperty":
  11509. return this.isAssignable(node.value);
  11510. case "SpreadElement":
  11511. return this.isAssignable(node.argument);
  11512. case "ArrayExpression":
  11513. return node.elements.every(element => element === null || this.isAssignable(element));
  11514. case "AssignmentExpression":
  11515. return node.operator === "=";
  11516. case "ParenthesizedExpression":
  11517. return this.isAssignable(node.expression);
  11518. case "MemberExpression":
  11519. case "OptionalMemberExpression":
  11520. return !isBinding;
  11521. default:
  11522. return false;
  11523. }
  11524. }
  11525. toReferencedList(exprList, isParenthesizedExpr) {
  11526. return exprList;
  11527. }
  11528. toReferencedListDeep(exprList, isParenthesizedExpr) {
  11529. this.toReferencedList(exprList, isParenthesizedExpr);
  11530. for (const expr of exprList) {
  11531. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  11532. this.toReferencedListDeep(expr.elements);
  11533. }
  11534. }
  11535. }
  11536. parseSpread(refExpressionErrors) {
  11537. const node = this.startNode();
  11538. this.next();
  11539. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  11540. return this.finishNode(node, "SpreadElement");
  11541. }
  11542. parseRestBinding() {
  11543. const node = this.startNode();
  11544. this.next();
  11545. const argument = this.parseBindingAtom();
  11546. if (argument.type === "VoidPattern") {
  11547. this.raise(Errors.UnexpectedVoidPattern, argument);
  11548. }
  11549. node.argument = argument;
  11550. return this.finishNode(node, "RestElement");
  11551. }
  11552. parseBindingAtom() {
  11553. switch (this.state.type) {
  11554. case 0:
  11555. {
  11556. const node = this.startNode();
  11557. this.next();
  11558. node.elements = this.parseBindingList(3, 93, 1);
  11559. return this.finishNode(node, "ArrayPattern");
  11560. }
  11561. case 5:
  11562. return this.parseObjectLike(8, true);
  11563. case 88:
  11564. return this.parseVoidPattern(null);
  11565. }
  11566. return this.parseIdentifier();
  11567. }
  11568. parseBindingList(close, closeCharCode, flags) {
  11569. const allowEmpty = flags & 1;
  11570. const elts = [];
  11571. let first = true;
  11572. while (!this.eat(close)) {
  11573. if (first) {
  11574. first = false;
  11575. } else {
  11576. this.expect(12);
  11577. }
  11578. if (allowEmpty && this.match(12)) {
  11579. elts.push(null);
  11580. } else if (this.eat(close)) {
  11581. break;
  11582. } else if (this.match(21)) {
  11583. let rest = this.parseRestBinding();
  11584. if (this.hasPlugin("flow") || flags & 2) {
  11585. rest = this.parseFunctionParamType(rest);
  11586. }
  11587. elts.push(rest);
  11588. if (!this.checkCommaAfterRest(closeCharCode)) {
  11589. this.expect(close);
  11590. break;
  11591. }
  11592. } else {
  11593. const decorators = [];
  11594. if (flags & 2) {
  11595. if (this.match(26) && this.hasPlugin("decorators")) {
  11596. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  11597. }
  11598. while (this.match(26)) {
  11599. decorators.push(this.parseDecorator());
  11600. }
  11601. }
  11602. elts.push(this.parseBindingElement(flags, decorators));
  11603. }
  11604. }
  11605. return elts;
  11606. }
  11607. parseBindingRestProperty(prop) {
  11608. this.next();
  11609. if (this.hasPlugin("discardBinding") && this.match(88)) {
  11610. prop.argument = this.parseVoidPattern(null);
  11611. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  11612. } else {
  11613. prop.argument = this.parseIdentifier();
  11614. }
  11615. this.checkCommaAfterRest(125);
  11616. return this.finishNode(prop, "RestElement");
  11617. }
  11618. parseBindingProperty() {
  11619. const {
  11620. type,
  11621. startLoc
  11622. } = this.state;
  11623. if (type === 21) {
  11624. return this.parseBindingRestProperty(this.startNode());
  11625. }
  11626. const prop = this.startNode();
  11627. if (type === 139) {
  11628. this.expectPlugin("destructuringPrivate", startLoc);
  11629. this.classScope.usePrivateName(this.state.value, startLoc);
  11630. prop.key = this.parsePrivateName();
  11631. } else {
  11632. this.parsePropertyName(prop);
  11633. }
  11634. prop.method = false;
  11635. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  11636. }
  11637. parseBindingElement(flags, decorators) {
  11638. const left = this.parseMaybeDefault();
  11639. if (this.hasPlugin("flow") || flags & 2) {
  11640. this.parseFunctionParamType(left);
  11641. }
  11642. if (decorators.length) {
  11643. left.decorators = decorators;
  11644. this.resetStartLocationFromNode(left, decorators[0]);
  11645. }
  11646. const elt = this.parseMaybeDefault(left.loc.start, left);
  11647. return elt;
  11648. }
  11649. parseFunctionParamType(param) {
  11650. return param;
  11651. }
  11652. parseMaybeDefault(startLoc, left) {
  11653. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  11654. left = left != null ? left : this.parseBindingAtom();
  11655. if (!this.eat(29)) return left;
  11656. const node = this.startNodeAt(startLoc);
  11657. if (left.type === "VoidPattern") {
  11658. this.raise(Errors.VoidPatternInitializer, left);
  11659. }
  11660. node.left = left;
  11661. node.right = this.parseMaybeAssignAllowIn();
  11662. return this.finishNode(node, "AssignmentPattern");
  11663. }
  11664. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  11665. switch (type) {
  11666. case "AssignmentPattern":
  11667. return "left";
  11668. case "RestElement":
  11669. return "argument";
  11670. case "ObjectProperty":
  11671. return "value";
  11672. case "ParenthesizedExpression":
  11673. return "expression";
  11674. case "ArrayPattern":
  11675. return "elements";
  11676. case "ObjectPattern":
  11677. return "properties";
  11678. case "VoidPattern":
  11679. return true;
  11680. case "CallExpression":
  11681. if (!disallowCallExpression && !this.state.strict && this.optionFlags & 8192) {
  11682. return true;
  11683. }
  11684. }
  11685. return false;
  11686. }
  11687. isOptionalMemberExpression(expression) {
  11688. return expression.type === "OptionalMemberExpression";
  11689. }
  11690. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false, disallowCallExpression = false) {
  11691. var _expression$extra;
  11692. const type = expression.type;
  11693. if (this.isObjectMethod(expression)) return;
  11694. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  11695. if (isOptionalMemberExpression || type === "MemberExpression") {
  11696. if (isOptionalMemberExpression) {
  11697. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  11698. if (ancestor.type !== "AssignmentExpression") {
  11699. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  11700. ancestor
  11701. });
  11702. }
  11703. }
  11704. if (binding !== 64) {
  11705. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  11706. }
  11707. return;
  11708. }
  11709. if (type === "Identifier") {
  11710. this.checkIdentifier(expression, binding, strictModeChanged);
  11711. const {
  11712. name
  11713. } = expression;
  11714. if (checkClashes) {
  11715. if (checkClashes.has(name)) {
  11716. this.raise(Errors.ParamDupe, expression);
  11717. } else {
  11718. checkClashes.add(name);
  11719. }
  11720. }
  11721. return;
  11722. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  11723. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  11724. }
  11725. const unwrappedExpression = unwrapParenthesizedExpression(expression);
  11726. disallowCallExpression || (disallowCallExpression = unwrappedExpression.type === "CallExpression" && (unwrappedExpression.callee.type === "Import" || unwrappedExpression.callee.type === "Super"));
  11727. const validity = this.isValidLVal(type, disallowCallExpression, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  11728. if (validity === true) return;
  11729. if (validity === false) {
  11730. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  11731. this.raise(ParseErrorClass, expression, {
  11732. ancestor
  11733. });
  11734. return;
  11735. }
  11736. let key, isParenthesizedExpression;
  11737. if (typeof validity === "string") {
  11738. key = validity;
  11739. isParenthesizedExpression = type === "ParenthesizedExpression";
  11740. } else {
  11741. [key, isParenthesizedExpression] = validity;
  11742. }
  11743. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  11744. type
  11745. } : ancestor;
  11746. const val = expression[key];
  11747. if (Array.isArray(val)) {
  11748. for (const child of val) {
  11749. if (child) {
  11750. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, true);
  11751. }
  11752. }
  11753. } else if (val) {
  11754. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression, disallowCallExpression);
  11755. }
  11756. }
  11757. checkIdentifier(at, bindingType, strictModeChanged = false) {
  11758. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  11759. if (bindingType === 64) {
  11760. this.raise(Errors.StrictEvalArguments, at, {
  11761. referenceName: at.name
  11762. });
  11763. } else {
  11764. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  11765. bindingName: at.name
  11766. });
  11767. }
  11768. }
  11769. if (bindingType & 8192 && at.name === "let") {
  11770. this.raise(Errors.LetInLexicalBinding, at);
  11771. }
  11772. if (!(bindingType & 64)) {
  11773. this.declareNameFromIdentifier(at, bindingType);
  11774. }
  11775. }
  11776. declareNameFromIdentifier(identifier, binding) {
  11777. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  11778. }
  11779. checkToRestConversion(node, allowPattern) {
  11780. switch (node.type) {
  11781. case "ParenthesizedExpression":
  11782. this.checkToRestConversion(node.expression, allowPattern);
  11783. break;
  11784. case "Identifier":
  11785. case "MemberExpression":
  11786. break;
  11787. case "ArrayExpression":
  11788. case "ObjectExpression":
  11789. if (allowPattern) break;
  11790. default:
  11791. this.raise(Errors.InvalidRestAssignmentPattern, node);
  11792. }
  11793. }
  11794. checkCommaAfterRest(close) {
  11795. if (!this.match(12)) {
  11796. return false;
  11797. }
  11798. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  11799. return true;
  11800. }
  11801. }
  11802. const keywordAndTSRelationalOperator = /in(?:stanceof)?|as|satisfies/y;
  11803. function nonNull(x) {
  11804. if (x == null) {
  11805. throw new Error(`Unexpected ${x} value.`);
  11806. }
  11807. return x;
  11808. }
  11809. function assert(x) {
  11810. if (!x) {
  11811. throw new Error("Assert fail");
  11812. }
  11813. }
  11814. const TSErrors = ParseErrorEnum`typescript`({
  11815. AbstractMethodHasImplementation: ({
  11816. methodName
  11817. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  11818. AbstractPropertyHasInitializer: ({
  11819. propertyName
  11820. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  11821. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  11822. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  11823. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  11824. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  11825. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  11826. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  11827. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  11828. DeclareAccessor: ({
  11829. kind
  11830. }) => `'declare' is not allowed in ${kind}ters.`,
  11831. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  11832. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  11833. DuplicateAccessibilityModifier: ({
  11834. modifier
  11835. }) => `Accessibility modifier already seen: '${modifier}'.`,
  11836. DuplicateModifier: ({
  11837. modifier
  11838. }) => `Duplicate modifier: '${modifier}'.`,
  11839. EmptyHeritageClauseType: ({
  11840. token
  11841. }) => `'${token}' list cannot be empty.`,
  11842. EmptyTypeArguments: "Type argument list cannot be empty.",
  11843. EmptyTypeParameters: "Type parameter list cannot be empty.",
  11844. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  11845. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  11846. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  11847. IncompatibleModifiers: ({
  11848. modifiers
  11849. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  11850. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  11851. IndexSignatureHasAccessibility: ({
  11852. modifier
  11853. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  11854. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  11855. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  11856. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  11857. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  11858. InvalidHeritageClauseType: ({
  11859. token
  11860. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  11861. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  11862. InvalidModifierOnTypeMember: ({
  11863. modifier
  11864. }) => `'${modifier}' modifier cannot appear on a type member.`,
  11865. InvalidModifierOnTypeParameter: ({
  11866. modifier
  11867. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  11868. InvalidModifierOnTypeParameterPositions: ({
  11869. modifier
  11870. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  11871. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  11872. InvalidModifiersOrder: ({
  11873. orderedModifiers
  11874. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  11875. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  11876. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  11877. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  11878. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  11879. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  11880. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  11881. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  11882. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  11883. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  11884. PrivateElementHasAccessibility: ({
  11885. modifier
  11886. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  11887. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  11888. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  11889. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  11890. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  11891. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  11892. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  11893. SingleTypeParameterWithoutTrailingComma: ({
  11894. typeParameterName
  11895. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  11896. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  11897. 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?`).",
  11898. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  11899. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  11900. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  11901. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  11902. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  11903. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  11904. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  11905. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  11906. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  11907. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  11908. UnsupportedSignatureParameterKind: ({
  11909. type
  11910. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  11911. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  11912. });
  11913. function keywordTypeFromName(value) {
  11914. switch (value) {
  11915. case "any":
  11916. return "TSAnyKeyword";
  11917. case "boolean":
  11918. return "TSBooleanKeyword";
  11919. case "bigint":
  11920. return "TSBigIntKeyword";
  11921. case "never":
  11922. return "TSNeverKeyword";
  11923. case "number":
  11924. return "TSNumberKeyword";
  11925. case "object":
  11926. return "TSObjectKeyword";
  11927. case "string":
  11928. return "TSStringKeyword";
  11929. case "symbol":
  11930. return "TSSymbolKeyword";
  11931. case "undefined":
  11932. return "TSUndefinedKeyword";
  11933. case "unknown":
  11934. return "TSUnknownKeyword";
  11935. default:
  11936. return undefined;
  11937. }
  11938. }
  11939. function tsIsAccessModifier(modifier) {
  11940. return modifier === "private" || modifier === "public" || modifier === "protected";
  11941. }
  11942. function tsIsVarianceAnnotations(modifier) {
  11943. return modifier === "in" || modifier === "out";
  11944. }
  11945. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  11946. constructor(...args) {
  11947. super(...args);
  11948. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  11949. allowedModifiers: ["in", "out"],
  11950. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  11951. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  11952. });
  11953. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  11954. allowedModifiers: ["const"],
  11955. disallowedModifiers: ["in", "out"],
  11956. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  11957. });
  11958. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  11959. allowedModifiers: ["in", "out", "const"],
  11960. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  11961. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  11962. });
  11963. }
  11964. getScopeHandler() {
  11965. return TypeScriptScopeHandler;
  11966. }
  11967. tsIsIdentifier() {
  11968. return tokenIsIdentifier(this.state.type);
  11969. }
  11970. tsTokenCanFollowModifier() {
  11971. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  11972. }
  11973. tsNextTokenOnSameLineAndCanFollowModifier() {
  11974. this.next();
  11975. if (this.hasPrecedingLineBreak()) {
  11976. return false;
  11977. }
  11978. return this.tsTokenCanFollowModifier();
  11979. }
  11980. tsNextTokenCanFollowModifier() {
  11981. if (this.match(106)) {
  11982. this.next();
  11983. return this.tsTokenCanFollowModifier();
  11984. }
  11985. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  11986. }
  11987. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  11988. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  11989. return undefined;
  11990. }
  11991. const modifier = this.state.value;
  11992. if (allowedModifiers.includes(modifier)) {
  11993. if (hasSeenStaticModifier && this.match(106)) {
  11994. return undefined;
  11995. }
  11996. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  11997. return undefined;
  11998. }
  11999. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  12000. return modifier;
  12001. }
  12002. }
  12003. return undefined;
  12004. }
  12005. tsParseModifiers({
  12006. allowedModifiers,
  12007. disallowedModifiers,
  12008. stopOnStartOfClassStaticBlock,
  12009. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  12010. }, modified) {
  12011. const enforceOrder = (loc, modifier, before, after) => {
  12012. if (modifier === before && modified[after]) {
  12013. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  12014. orderedModifiers: [before, after]
  12015. });
  12016. }
  12017. };
  12018. const incompatible = (loc, modifier, mod1, mod2) => {
  12019. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  12020. this.raise(TSErrors.IncompatibleModifiers, loc, {
  12021. modifiers: [mod1, mod2]
  12022. });
  12023. }
  12024. };
  12025. for (;;) {
  12026. const {
  12027. startLoc
  12028. } = this.state;
  12029. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  12030. if (!modifier) break;
  12031. if (tsIsAccessModifier(modifier)) {
  12032. if (modified.accessibility) {
  12033. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  12034. modifier
  12035. });
  12036. } else {
  12037. enforceOrder(startLoc, modifier, modifier, "override");
  12038. enforceOrder(startLoc, modifier, modifier, "static");
  12039. enforceOrder(startLoc, modifier, modifier, "readonly");
  12040. modified.accessibility = modifier;
  12041. }
  12042. } else if (tsIsVarianceAnnotations(modifier)) {
  12043. if (modified[modifier]) {
  12044. this.raise(TSErrors.DuplicateModifier, startLoc, {
  12045. modifier
  12046. });
  12047. }
  12048. modified[modifier] = true;
  12049. enforceOrder(startLoc, modifier, "in", "out");
  12050. } else {
  12051. if (hasOwnProperty.call(modified, modifier)) {
  12052. this.raise(TSErrors.DuplicateModifier, startLoc, {
  12053. modifier
  12054. });
  12055. } else {
  12056. enforceOrder(startLoc, modifier, "static", "readonly");
  12057. enforceOrder(startLoc, modifier, "static", "override");
  12058. enforceOrder(startLoc, modifier, "override", "readonly");
  12059. enforceOrder(startLoc, modifier, "abstract", "override");
  12060. incompatible(startLoc, modifier, "declare", "override");
  12061. incompatible(startLoc, modifier, "static", "abstract");
  12062. }
  12063. modified[modifier] = true;
  12064. }
  12065. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  12066. this.raise(errorTemplate, startLoc, {
  12067. modifier
  12068. });
  12069. }
  12070. }
  12071. }
  12072. tsIsListTerminator(kind) {
  12073. switch (kind) {
  12074. case "EnumMembers":
  12075. case "TypeMembers":
  12076. return this.match(8);
  12077. case "HeritageClauseElement":
  12078. return this.match(5);
  12079. case "TupleElementTypes":
  12080. return this.match(3);
  12081. case "TypeParametersOrArguments":
  12082. return this.match(48);
  12083. }
  12084. }
  12085. tsParseList(kind, parseElement) {
  12086. const result = [];
  12087. while (!this.tsIsListTerminator(kind)) {
  12088. result.push(parseElement());
  12089. }
  12090. return result;
  12091. }
  12092. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  12093. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  12094. }
  12095. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  12096. const result = [];
  12097. let trailingCommaPos = -1;
  12098. for (;;) {
  12099. if (this.tsIsListTerminator(kind)) {
  12100. break;
  12101. }
  12102. trailingCommaPos = -1;
  12103. const element = parseElement();
  12104. if (element == null) {
  12105. return undefined;
  12106. }
  12107. result.push(element);
  12108. if (this.eat(12)) {
  12109. trailingCommaPos = this.state.lastTokStartLoc.index;
  12110. continue;
  12111. }
  12112. if (this.tsIsListTerminator(kind)) {
  12113. break;
  12114. }
  12115. if (expectSuccess) {
  12116. this.expect(12);
  12117. }
  12118. return undefined;
  12119. }
  12120. if (refTrailingCommaPos) {
  12121. refTrailingCommaPos.value = trailingCommaPos;
  12122. }
  12123. return result;
  12124. }
  12125. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  12126. if (!skipFirstToken) {
  12127. if (bracket) {
  12128. this.expect(0);
  12129. } else {
  12130. this.expect(47);
  12131. }
  12132. }
  12133. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  12134. if (bracket) {
  12135. this.expect(3);
  12136. } else {
  12137. this.expect(48);
  12138. }
  12139. return result;
  12140. }
  12141. tsParseImportType() {
  12142. const node = this.startNode();
  12143. this.expect(83);
  12144. this.expect(10);
  12145. if (!this.match(134)) {
  12146. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  12147. node.argument = super.parseExprAtom();
  12148. } else {
  12149. node.argument = this.parseStringLiteral(this.state.value);
  12150. }
  12151. if (this.eat(12)) {
  12152. node.options = this.tsParseImportTypeOptions();
  12153. } else {
  12154. node.options = null;
  12155. }
  12156. this.expect(11);
  12157. if (this.eat(16)) {
  12158. node.qualifier = this.tsParseEntityName(1 | 2);
  12159. }
  12160. if (this.match(47)) {
  12161. node.typeParameters = this.tsParseTypeArguments();
  12162. }
  12163. return this.finishNode(node, "TSImportType");
  12164. }
  12165. tsParseImportTypeOptions() {
  12166. const node = this.startNode();
  12167. this.expect(5);
  12168. const withProperty = this.startNode();
  12169. if (this.isContextual(76)) {
  12170. withProperty.method = false;
  12171. withProperty.key = this.parseIdentifier(true);
  12172. withProperty.computed = false;
  12173. withProperty.shorthand = false;
  12174. } else {
  12175. this.unexpected(null, 76);
  12176. }
  12177. this.expect(14);
  12178. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  12179. node.properties = [this.finishObjectProperty(withProperty)];
  12180. this.eat(12);
  12181. this.expect(8);
  12182. return this.finishNode(node, "ObjectExpression");
  12183. }
  12184. tsParseImportTypeWithPropertyValue() {
  12185. const node = this.startNode();
  12186. const properties = [];
  12187. this.expect(5);
  12188. while (!this.match(8)) {
  12189. const type = this.state.type;
  12190. if (tokenIsIdentifier(type) || type === 134) {
  12191. properties.push(super.parsePropertyDefinition(null));
  12192. } else {
  12193. this.unexpected();
  12194. }
  12195. this.eat(12);
  12196. }
  12197. node.properties = properties;
  12198. this.next();
  12199. return this.finishNode(node, "ObjectExpression");
  12200. }
  12201. tsParseEntityName(flags) {
  12202. let entity;
  12203. if (flags & 1 && this.match(78)) {
  12204. if (flags & 2) {
  12205. entity = this.parseIdentifier(true);
  12206. } else {
  12207. const node = this.startNode();
  12208. this.next();
  12209. entity = this.finishNode(node, "ThisExpression");
  12210. }
  12211. } else {
  12212. entity = this.parseIdentifier(!!(flags & 1));
  12213. }
  12214. while (this.eat(16)) {
  12215. const node = this.startNodeAtNode(entity);
  12216. node.left = entity;
  12217. node.right = this.parseIdentifier(!!(flags & 1));
  12218. entity = this.finishNode(node, "TSQualifiedName");
  12219. }
  12220. return entity;
  12221. }
  12222. tsParseTypeReference() {
  12223. const node = this.startNode();
  12224. node.typeName = this.tsParseEntityName(1);
  12225. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  12226. node.typeParameters = this.tsParseTypeArguments();
  12227. }
  12228. return this.finishNode(node, "TSTypeReference");
  12229. }
  12230. tsParseThisTypePredicate(lhs) {
  12231. this.next();
  12232. const node = this.startNodeAtNode(lhs);
  12233. node.parameterName = lhs;
  12234. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  12235. node.asserts = false;
  12236. return this.finishNode(node, "TSTypePredicate");
  12237. }
  12238. tsParseThisTypeNode() {
  12239. const node = this.startNode();
  12240. this.next();
  12241. return this.finishNode(node, "TSThisType");
  12242. }
  12243. tsParseTypeQuery() {
  12244. const node = this.startNode();
  12245. this.expect(87);
  12246. if (this.match(83)) {
  12247. node.exprName = this.tsParseImportType();
  12248. } else {
  12249. node.exprName = this.tsParseEntityName(1 | 2);
  12250. }
  12251. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  12252. node.typeParameters = this.tsParseTypeArguments();
  12253. }
  12254. return this.finishNode(node, "TSTypeQuery");
  12255. }
  12256. tsParseTypeParameter(parseModifiers) {
  12257. const node = this.startNode();
  12258. parseModifiers(node);
  12259. node.name = this.tsParseTypeParameterName();
  12260. node.constraint = this.tsEatThenParseType(81);
  12261. node.default = this.tsEatThenParseType(29);
  12262. return this.finishNode(node, "TSTypeParameter");
  12263. }
  12264. tsTryParseTypeParameters(parseModifiers) {
  12265. if (this.match(47)) {
  12266. return this.tsParseTypeParameters(parseModifiers);
  12267. }
  12268. }
  12269. tsParseTypeParameters(parseModifiers) {
  12270. const node = this.startNode();
  12271. if (this.match(47) || this.match(143)) {
  12272. this.next();
  12273. } else {
  12274. this.unexpected();
  12275. }
  12276. const refTrailingCommaPos = {
  12277. value: -1
  12278. };
  12279. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  12280. if (node.params.length === 0) {
  12281. this.raise(TSErrors.EmptyTypeParameters, node);
  12282. }
  12283. if (refTrailingCommaPos.value !== -1) {
  12284. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  12285. }
  12286. return this.finishNode(node, "TSTypeParameterDeclaration");
  12287. }
  12288. tsFillSignature(returnToken, signature) {
  12289. const returnTokenRequired = returnToken === 19;
  12290. const paramsKey = "parameters";
  12291. const returnTypeKey = "typeAnnotation";
  12292. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12293. this.expect(10);
  12294. signature[paramsKey] = this.tsParseBindingListForSignature();
  12295. if (returnTokenRequired) {
  12296. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  12297. } else if (this.match(returnToken)) {
  12298. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  12299. }
  12300. }
  12301. tsParseBindingListForSignature() {
  12302. const list = super.parseBindingList(11, 41, 2);
  12303. for (const pattern of list) {
  12304. const {
  12305. type
  12306. } = pattern;
  12307. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  12308. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  12309. type
  12310. });
  12311. }
  12312. }
  12313. return list;
  12314. }
  12315. tsParseTypeMemberSemicolon() {
  12316. if (!this.eat(12) && !this.isLineTerminator()) {
  12317. this.expect(13);
  12318. }
  12319. }
  12320. tsParseSignatureMember(kind, node) {
  12321. this.tsFillSignature(14, node);
  12322. this.tsParseTypeMemberSemicolon();
  12323. return this.finishNode(node, kind);
  12324. }
  12325. tsIsUnambiguouslyIndexSignature() {
  12326. this.next();
  12327. if (tokenIsIdentifier(this.state.type)) {
  12328. this.next();
  12329. return this.match(14);
  12330. }
  12331. return false;
  12332. }
  12333. tsTryParseIndexSignature(node) {
  12334. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  12335. return;
  12336. }
  12337. this.expect(0);
  12338. const id = this.parseIdentifier();
  12339. id.typeAnnotation = this.tsParseTypeAnnotation();
  12340. this.resetEndLocation(id);
  12341. this.expect(3);
  12342. node.parameters = [id];
  12343. const type = this.tsTryParseTypeAnnotation();
  12344. if (type) node.typeAnnotation = type;
  12345. this.tsParseTypeMemberSemicolon();
  12346. return this.finishNode(node, "TSIndexSignature");
  12347. }
  12348. tsParsePropertyOrMethodSignature(node, readonly) {
  12349. if (this.eat(17)) node.optional = true;
  12350. if (this.match(10) || this.match(47)) {
  12351. if (readonly) {
  12352. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  12353. }
  12354. const method = node;
  12355. if (method.kind && this.match(47)) {
  12356. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  12357. }
  12358. this.tsFillSignature(14, method);
  12359. this.tsParseTypeMemberSemicolon();
  12360. const paramsKey = "parameters";
  12361. const returnTypeKey = "typeAnnotation";
  12362. if (method.kind === "get") {
  12363. if (method[paramsKey].length > 0) {
  12364. this.raise(Errors.BadGetterArity, this.state.curPosition());
  12365. if (this.isThisParam(method[paramsKey][0])) {
  12366. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  12367. }
  12368. }
  12369. } else if (method.kind === "set") {
  12370. if (method[paramsKey].length !== 1) {
  12371. this.raise(Errors.BadSetterArity, this.state.curPosition());
  12372. } else {
  12373. const firstParameter = method[paramsKey][0];
  12374. if (this.isThisParam(firstParameter)) {
  12375. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  12376. }
  12377. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  12378. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  12379. }
  12380. if (firstParameter.type === "RestElement") {
  12381. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  12382. }
  12383. }
  12384. if (method[returnTypeKey]) {
  12385. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  12386. }
  12387. } else {
  12388. method.kind = "method";
  12389. }
  12390. return this.finishNode(method, "TSMethodSignature");
  12391. } else {
  12392. const property = node;
  12393. if (readonly) property.readonly = true;
  12394. const type = this.tsTryParseTypeAnnotation();
  12395. if (type) property.typeAnnotation = type;
  12396. this.tsParseTypeMemberSemicolon();
  12397. return this.finishNode(property, "TSPropertySignature");
  12398. }
  12399. }
  12400. tsParseTypeMember() {
  12401. const node = this.startNode();
  12402. if (this.match(10) || this.match(47)) {
  12403. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  12404. }
  12405. if (this.match(77)) {
  12406. const id = this.startNode();
  12407. this.next();
  12408. if (this.match(10) || this.match(47)) {
  12409. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  12410. } else {
  12411. node.key = this.createIdentifier(id, "new");
  12412. return this.tsParsePropertyOrMethodSignature(node, false);
  12413. }
  12414. }
  12415. this.tsParseModifiers({
  12416. allowedModifiers: ["readonly"],
  12417. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  12418. }, node);
  12419. const idx = this.tsTryParseIndexSignature(node);
  12420. if (idx) {
  12421. return idx;
  12422. }
  12423. super.parsePropertyName(node);
  12424. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  12425. node.kind = node.key.name;
  12426. super.parsePropertyName(node);
  12427. if (!this.match(10) && !this.match(47)) {
  12428. this.unexpected(null, 10);
  12429. }
  12430. }
  12431. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  12432. }
  12433. tsParseTypeLiteral() {
  12434. const node = this.startNode();
  12435. node.members = this.tsParseObjectTypeMembers();
  12436. return this.finishNode(node, "TSTypeLiteral");
  12437. }
  12438. tsParseObjectTypeMembers() {
  12439. this.expect(5);
  12440. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  12441. this.expect(8);
  12442. return members;
  12443. }
  12444. tsIsStartOfMappedType() {
  12445. this.next();
  12446. if (this.eat(53)) {
  12447. return this.isContextual(122);
  12448. }
  12449. if (this.isContextual(122)) {
  12450. this.next();
  12451. }
  12452. if (!this.match(0)) {
  12453. return false;
  12454. }
  12455. this.next();
  12456. if (!this.tsIsIdentifier()) {
  12457. return false;
  12458. }
  12459. this.next();
  12460. return this.match(58);
  12461. }
  12462. tsParseMappedType() {
  12463. const node = this.startNode();
  12464. this.expect(5);
  12465. if (this.match(53)) {
  12466. node.readonly = this.state.value;
  12467. this.next();
  12468. this.expectContextual(122);
  12469. } else if (this.eatContextual(122)) {
  12470. node.readonly = true;
  12471. }
  12472. this.expect(0);
  12473. const typeParameter = this.startNode();
  12474. typeParameter.name = this.tsParseTypeParameterName();
  12475. typeParameter.constraint = this.tsExpectThenParseType(58);
  12476. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  12477. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  12478. this.expect(3);
  12479. if (this.match(53)) {
  12480. node.optional = this.state.value;
  12481. this.next();
  12482. this.expect(17);
  12483. } else if (this.eat(17)) {
  12484. node.optional = true;
  12485. }
  12486. node.typeAnnotation = this.tsTryParseType();
  12487. this.semicolon();
  12488. this.expect(8);
  12489. return this.finishNode(node, "TSMappedType");
  12490. }
  12491. tsParseTupleType() {
  12492. const node = this.startNode();
  12493. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  12494. let seenOptionalElement = false;
  12495. node.elementTypes.forEach(elementNode => {
  12496. const {
  12497. type
  12498. } = elementNode;
  12499. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  12500. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  12501. }
  12502. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  12503. });
  12504. return this.finishNode(node, "TSTupleType");
  12505. }
  12506. tsParseTupleElementType() {
  12507. const restStartLoc = this.state.startLoc;
  12508. const rest = this.eat(21);
  12509. const {
  12510. startLoc
  12511. } = this.state;
  12512. let labeled;
  12513. let label;
  12514. let optional;
  12515. let type;
  12516. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  12517. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  12518. if (chAfterWord === 58) {
  12519. labeled = true;
  12520. optional = false;
  12521. label = this.parseIdentifier(true);
  12522. this.expect(14);
  12523. type = this.tsParseType();
  12524. } else if (chAfterWord === 63) {
  12525. optional = true;
  12526. const wordName = this.state.value;
  12527. const typeOrLabel = this.tsParseNonArrayType();
  12528. if (this.lookaheadCharCode() === 58) {
  12529. labeled = true;
  12530. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  12531. this.expect(17);
  12532. this.expect(14);
  12533. type = this.tsParseType();
  12534. } else {
  12535. labeled = false;
  12536. type = typeOrLabel;
  12537. this.expect(17);
  12538. }
  12539. } else {
  12540. type = this.tsParseType();
  12541. optional = this.eat(17);
  12542. labeled = this.eat(14);
  12543. }
  12544. if (labeled) {
  12545. let labeledNode;
  12546. if (label) {
  12547. labeledNode = this.startNodeAt(startLoc);
  12548. labeledNode.optional = optional;
  12549. labeledNode.label = label;
  12550. labeledNode.elementType = type;
  12551. if (this.eat(17)) {
  12552. labeledNode.optional = true;
  12553. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  12554. }
  12555. } else {
  12556. labeledNode = this.startNodeAt(startLoc);
  12557. labeledNode.optional = optional;
  12558. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  12559. labeledNode.label = type;
  12560. labeledNode.elementType = this.tsParseType();
  12561. }
  12562. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  12563. } else if (optional) {
  12564. const optionalTypeNode = this.startNodeAt(startLoc);
  12565. optionalTypeNode.typeAnnotation = type;
  12566. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  12567. }
  12568. if (rest) {
  12569. const restNode = this.startNodeAt(restStartLoc);
  12570. restNode.typeAnnotation = type;
  12571. type = this.finishNode(restNode, "TSRestType");
  12572. }
  12573. return type;
  12574. }
  12575. tsParseParenthesizedType() {
  12576. const node = this.startNode();
  12577. this.expect(10);
  12578. node.typeAnnotation = this.tsParseType();
  12579. this.expect(11);
  12580. return this.finishNode(node, "TSParenthesizedType");
  12581. }
  12582. tsParseFunctionOrConstructorType(type, abstract) {
  12583. const node = this.startNode();
  12584. if (type === "TSConstructorType") {
  12585. node.abstract = !!abstract;
  12586. if (abstract) this.next();
  12587. this.next();
  12588. }
  12589. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  12590. return this.finishNode(node, type);
  12591. }
  12592. tsParseLiteralTypeNode() {
  12593. const node = this.startNode();
  12594. switch (this.state.type) {
  12595. case 135:
  12596. case 136:
  12597. case 134:
  12598. case 85:
  12599. case 86:
  12600. node.literal = super.parseExprAtom();
  12601. break;
  12602. default:
  12603. this.unexpected();
  12604. }
  12605. return this.finishNode(node, "TSLiteralType");
  12606. }
  12607. tsParseTemplateLiteralType() {
  12608. const node = this.startNode();
  12609. node.literal = super.parseTemplate(false);
  12610. return this.finishNode(node, "TSLiteralType");
  12611. }
  12612. parseTemplateSubstitution() {
  12613. if (this.state.inType) return this.tsParseType();
  12614. return super.parseTemplateSubstitution();
  12615. }
  12616. tsParseThisTypeOrThisTypePredicate() {
  12617. const thisKeyword = this.tsParseThisTypeNode();
  12618. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  12619. return this.tsParseThisTypePredicate(thisKeyword);
  12620. } else {
  12621. return thisKeyword;
  12622. }
  12623. }
  12624. tsParseNonArrayType() {
  12625. switch (this.state.type) {
  12626. case 134:
  12627. case 135:
  12628. case 136:
  12629. case 85:
  12630. case 86:
  12631. return this.tsParseLiteralTypeNode();
  12632. case 53:
  12633. if (this.state.value === "-") {
  12634. const node = this.startNode();
  12635. const nextToken = this.lookahead();
  12636. if (nextToken.type !== 135 && nextToken.type !== 136) {
  12637. this.unexpected();
  12638. }
  12639. node.literal = this.parseMaybeUnary();
  12640. return this.finishNode(node, "TSLiteralType");
  12641. }
  12642. break;
  12643. case 78:
  12644. return this.tsParseThisTypeOrThisTypePredicate();
  12645. case 87:
  12646. return this.tsParseTypeQuery();
  12647. case 83:
  12648. return this.tsParseImportType();
  12649. case 5:
  12650. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  12651. case 0:
  12652. return this.tsParseTupleType();
  12653. case 10:
  12654. return this.tsParseParenthesizedType();
  12655. case 25:
  12656. case 24:
  12657. return this.tsParseTemplateLiteralType();
  12658. default:
  12659. {
  12660. const {
  12661. type
  12662. } = this.state;
  12663. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  12664. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  12665. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  12666. const node = this.startNode();
  12667. this.next();
  12668. return this.finishNode(node, nodeType);
  12669. }
  12670. return this.tsParseTypeReference();
  12671. }
  12672. }
  12673. }
  12674. throw this.unexpected();
  12675. }
  12676. tsParseArrayTypeOrHigher() {
  12677. const {
  12678. startLoc
  12679. } = this.state;
  12680. let type = this.tsParseNonArrayType();
  12681. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  12682. if (this.match(3)) {
  12683. const node = this.startNodeAt(startLoc);
  12684. node.elementType = type;
  12685. this.expect(3);
  12686. type = this.finishNode(node, "TSArrayType");
  12687. } else {
  12688. const node = this.startNodeAt(startLoc);
  12689. node.objectType = type;
  12690. node.indexType = this.tsParseType();
  12691. this.expect(3);
  12692. type = this.finishNode(node, "TSIndexedAccessType");
  12693. }
  12694. }
  12695. return type;
  12696. }
  12697. tsParseTypeOperator() {
  12698. const node = this.startNode();
  12699. const operator = this.state.value;
  12700. this.next();
  12701. node.operator = operator;
  12702. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  12703. if (operator === "readonly") {
  12704. this.tsCheckTypeAnnotationForReadOnly(node);
  12705. }
  12706. return this.finishNode(node, "TSTypeOperator");
  12707. }
  12708. tsCheckTypeAnnotationForReadOnly(node) {
  12709. switch (node.typeAnnotation.type) {
  12710. case "TSTupleType":
  12711. case "TSArrayType":
  12712. return;
  12713. default:
  12714. this.raise(TSErrors.UnexpectedReadonly, node);
  12715. }
  12716. }
  12717. tsParseInferType() {
  12718. const node = this.startNode();
  12719. this.expectContextual(115);
  12720. const typeParameter = this.startNode();
  12721. typeParameter.name = this.tsParseTypeParameterName();
  12722. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  12723. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  12724. return this.finishNode(node, "TSInferType");
  12725. }
  12726. tsParseConstraintForInferType() {
  12727. if (this.eat(81)) {
  12728. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  12729. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  12730. return constraint;
  12731. }
  12732. }
  12733. }
  12734. tsParseTypeOperatorOrHigher() {
  12735. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  12736. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  12737. }
  12738. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  12739. const node = this.startNode();
  12740. const hasLeadingOperator = this.eat(operator);
  12741. const types = [];
  12742. do {
  12743. types.push(parseConstituentType());
  12744. } while (this.eat(operator));
  12745. if (types.length === 1 && !hasLeadingOperator) {
  12746. return types[0];
  12747. }
  12748. node.types = types;
  12749. return this.finishNode(node, kind);
  12750. }
  12751. tsParseIntersectionTypeOrHigher() {
  12752. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  12753. }
  12754. tsParseUnionTypeOrHigher() {
  12755. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  12756. }
  12757. tsIsStartOfFunctionType() {
  12758. if (this.match(47)) {
  12759. return true;
  12760. }
  12761. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  12762. }
  12763. tsSkipParameterStart() {
  12764. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  12765. this.next();
  12766. return true;
  12767. }
  12768. if (this.match(5)) {
  12769. const {
  12770. errors
  12771. } = this.state;
  12772. const previousErrorCount = errors.length;
  12773. try {
  12774. this.parseObjectLike(8, true);
  12775. return errors.length === previousErrorCount;
  12776. } catch (_unused) {
  12777. return false;
  12778. }
  12779. }
  12780. if (this.match(0)) {
  12781. this.next();
  12782. const {
  12783. errors
  12784. } = this.state;
  12785. const previousErrorCount = errors.length;
  12786. try {
  12787. super.parseBindingList(3, 93, 1);
  12788. return errors.length === previousErrorCount;
  12789. } catch (_unused2) {
  12790. return false;
  12791. }
  12792. }
  12793. return false;
  12794. }
  12795. tsIsUnambiguouslyStartOfFunctionType() {
  12796. this.next();
  12797. if (this.match(11) || this.match(21)) {
  12798. return true;
  12799. }
  12800. if (this.tsSkipParameterStart()) {
  12801. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  12802. return true;
  12803. }
  12804. if (this.match(11)) {
  12805. this.next();
  12806. if (this.match(19)) {
  12807. return true;
  12808. }
  12809. }
  12810. }
  12811. return false;
  12812. }
  12813. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  12814. return this.tsInType(() => {
  12815. const t = this.startNode();
  12816. this.expect(returnToken);
  12817. const node = this.startNode();
  12818. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  12819. if (asserts && this.match(78)) {
  12820. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  12821. if (thisTypePredicate.type === "TSThisType") {
  12822. node.parameterName = thisTypePredicate;
  12823. node.asserts = true;
  12824. node.typeAnnotation = null;
  12825. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  12826. } else {
  12827. this.resetStartLocationFromNode(thisTypePredicate, node);
  12828. thisTypePredicate.asserts = true;
  12829. }
  12830. t.typeAnnotation = thisTypePredicate;
  12831. return this.finishNode(t, "TSTypeAnnotation");
  12832. }
  12833. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  12834. if (!typePredicateVariable) {
  12835. if (!asserts) {
  12836. return this.tsParseTypeAnnotation(false, t);
  12837. }
  12838. node.parameterName = this.parseIdentifier();
  12839. node.asserts = asserts;
  12840. node.typeAnnotation = null;
  12841. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  12842. return this.finishNode(t, "TSTypeAnnotation");
  12843. }
  12844. const type = this.tsParseTypeAnnotation(false);
  12845. node.parameterName = typePredicateVariable;
  12846. node.typeAnnotation = type;
  12847. node.asserts = asserts;
  12848. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  12849. return this.finishNode(t, "TSTypeAnnotation");
  12850. });
  12851. }
  12852. tsTryParseTypeOrTypePredicateAnnotation() {
  12853. if (this.match(14)) {
  12854. return this.tsParseTypeOrTypePredicateAnnotation(14);
  12855. }
  12856. }
  12857. tsTryParseTypeAnnotation() {
  12858. if (this.match(14)) {
  12859. return this.tsParseTypeAnnotation();
  12860. }
  12861. }
  12862. tsTryParseType() {
  12863. return this.tsEatThenParseType(14);
  12864. }
  12865. tsParseTypePredicatePrefix() {
  12866. const id = this.parseIdentifier();
  12867. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  12868. this.next();
  12869. return id;
  12870. }
  12871. }
  12872. tsParseTypePredicateAsserts() {
  12873. if (this.state.type !== 109) {
  12874. return false;
  12875. }
  12876. const containsEsc = this.state.containsEsc;
  12877. this.next();
  12878. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  12879. return false;
  12880. }
  12881. if (containsEsc) {
  12882. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  12883. reservedWord: "asserts"
  12884. });
  12885. }
  12886. return true;
  12887. }
  12888. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  12889. this.tsInType(() => {
  12890. if (eatColon) this.expect(14);
  12891. t.typeAnnotation = this.tsParseType();
  12892. });
  12893. return this.finishNode(t, "TSTypeAnnotation");
  12894. }
  12895. tsParseType() {
  12896. assert(this.state.inType);
  12897. const type = this.tsParseNonConditionalType();
  12898. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  12899. return type;
  12900. }
  12901. const node = this.startNodeAtNode(type);
  12902. node.checkType = type;
  12903. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  12904. this.expect(17);
  12905. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  12906. this.expect(14);
  12907. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  12908. return this.finishNode(node, "TSConditionalType");
  12909. }
  12910. isAbstractConstructorSignature() {
  12911. return this.isContextual(124) && this.isLookaheadContextual("new");
  12912. }
  12913. tsParseNonConditionalType() {
  12914. if (this.tsIsStartOfFunctionType()) {
  12915. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  12916. }
  12917. if (this.match(77)) {
  12918. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  12919. } else if (this.isAbstractConstructorSignature()) {
  12920. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  12921. }
  12922. return this.tsParseUnionTypeOrHigher();
  12923. }
  12924. tsParseTypeAssertion() {
  12925. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  12926. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  12927. }
  12928. const node = this.startNode();
  12929. node.typeAnnotation = this.tsInType(() => {
  12930. this.next();
  12931. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  12932. });
  12933. this.expect(48);
  12934. node.expression = this.parseMaybeUnary();
  12935. return this.finishNode(node, "TSTypeAssertion");
  12936. }
  12937. tsParseHeritageClause(token) {
  12938. const originalStartLoc = this.state.startLoc;
  12939. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  12940. const node = this.startNode();
  12941. node.expression = this.tsParseEntityName(1 | 2);
  12942. if (this.match(47)) {
  12943. node.typeParameters = this.tsParseTypeArguments();
  12944. }
  12945. return this.finishNode(node, "TSExpressionWithTypeArguments");
  12946. });
  12947. if (!delimitedList.length) {
  12948. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  12949. token
  12950. });
  12951. }
  12952. return delimitedList;
  12953. }
  12954. tsParseInterfaceDeclaration(node, properties = {}) {
  12955. if (this.hasFollowingLineBreak()) return null;
  12956. this.expectContextual(129);
  12957. if (properties.declare) node.declare = true;
  12958. if (tokenIsIdentifier(this.state.type)) {
  12959. node.id = this.parseIdentifier();
  12960. this.checkIdentifier(node.id, 130);
  12961. } else {
  12962. node.id = null;
  12963. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  12964. }
  12965. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  12966. if (this.eat(81)) {
  12967. node.extends = this.tsParseHeritageClause("extends");
  12968. }
  12969. const body = this.startNode();
  12970. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  12971. node.body = this.finishNode(body, "TSInterfaceBody");
  12972. return this.finishNode(node, "TSInterfaceDeclaration");
  12973. }
  12974. tsParseTypeAliasDeclaration(node) {
  12975. node.id = this.parseIdentifier();
  12976. this.checkIdentifier(node.id, 2);
  12977. node.typeAnnotation = this.tsInType(() => {
  12978. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  12979. this.expect(29);
  12980. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  12981. const node = this.startNode();
  12982. this.next();
  12983. return this.finishNode(node, "TSIntrinsicKeyword");
  12984. }
  12985. return this.tsParseType();
  12986. });
  12987. this.semicolon();
  12988. return this.finishNode(node, "TSTypeAliasDeclaration");
  12989. }
  12990. tsInTopLevelContext(cb) {
  12991. if (this.curContext() !== types.brace) {
  12992. const oldContext = this.state.context;
  12993. this.state.context = [oldContext[0]];
  12994. try {
  12995. return cb();
  12996. } finally {
  12997. this.state.context = oldContext;
  12998. }
  12999. } else {
  13000. return cb();
  13001. }
  13002. }
  13003. tsInType(cb) {
  13004. const oldInType = this.state.inType;
  13005. this.state.inType = true;
  13006. try {
  13007. return cb();
  13008. } finally {
  13009. this.state.inType = oldInType;
  13010. }
  13011. }
  13012. tsInDisallowConditionalTypesContext(cb) {
  13013. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  13014. this.state.inDisallowConditionalTypesContext = true;
  13015. try {
  13016. return cb();
  13017. } finally {
  13018. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  13019. }
  13020. }
  13021. tsInAllowConditionalTypesContext(cb) {
  13022. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  13023. this.state.inDisallowConditionalTypesContext = false;
  13024. try {
  13025. return cb();
  13026. } finally {
  13027. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  13028. }
  13029. }
  13030. tsEatThenParseType(token) {
  13031. if (this.match(token)) {
  13032. return this.tsNextThenParseType();
  13033. }
  13034. }
  13035. tsExpectThenParseType(token) {
  13036. return this.tsInType(() => {
  13037. this.expect(token);
  13038. return this.tsParseType();
  13039. });
  13040. }
  13041. tsNextThenParseType() {
  13042. return this.tsInType(() => {
  13043. this.next();
  13044. return this.tsParseType();
  13045. });
  13046. }
  13047. tsParseEnumMember() {
  13048. const node = this.startNode();
  13049. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  13050. if (this.eat(29)) {
  13051. node.initializer = super.parseMaybeAssignAllowIn();
  13052. }
  13053. return this.finishNode(node, "TSEnumMember");
  13054. }
  13055. tsParseEnumDeclaration(node, properties = {}) {
  13056. if (properties.const) node.const = true;
  13057. if (properties.declare) node.declare = true;
  13058. this.expectContextual(126);
  13059. node.id = this.parseIdentifier();
  13060. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  13061. this.expect(5);
  13062. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  13063. this.expect(8);
  13064. return this.finishNode(node, "TSEnumDeclaration");
  13065. }
  13066. tsParseEnumBody() {
  13067. const node = this.startNode();
  13068. this.expect(5);
  13069. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  13070. this.expect(8);
  13071. return this.finishNode(node, "TSEnumBody");
  13072. }
  13073. tsParseModuleBlock() {
  13074. const node = this.startNode();
  13075. this.scope.enter(0);
  13076. this.expect(5);
  13077. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  13078. this.scope.exit();
  13079. return this.finishNode(node, "TSModuleBlock");
  13080. }
  13081. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  13082. node.id = this.parseIdentifier();
  13083. if (!nested) {
  13084. this.checkIdentifier(node.id, 1024);
  13085. }
  13086. if (this.eat(16)) {
  13087. const inner = this.startNode();
  13088. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  13089. node.body = inner;
  13090. } else {
  13091. this.scope.enter(1024);
  13092. this.prodParam.enter(0);
  13093. node.body = this.tsParseModuleBlock();
  13094. this.prodParam.exit();
  13095. this.scope.exit();
  13096. }
  13097. return this.finishNode(node, "TSModuleDeclaration");
  13098. }
  13099. tsParseAmbientExternalModuleDeclaration(node) {
  13100. if (this.isContextual(112)) {
  13101. node.kind = "global";
  13102. node.global = true;
  13103. node.id = this.parseIdentifier();
  13104. } else if (this.match(134)) {
  13105. node.kind = "module";
  13106. node.id = super.parseStringLiteral(this.state.value);
  13107. } else {
  13108. this.unexpected();
  13109. }
  13110. if (this.match(5)) {
  13111. this.scope.enter(1024);
  13112. this.prodParam.enter(0);
  13113. node.body = this.tsParseModuleBlock();
  13114. this.prodParam.exit();
  13115. this.scope.exit();
  13116. } else {
  13117. this.semicolon();
  13118. }
  13119. return this.finishNode(node, "TSModuleDeclaration");
  13120. }
  13121. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  13122. node.isExport = isExport || false;
  13123. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  13124. this.checkIdentifier(node.id, 4096);
  13125. this.expect(29);
  13126. const moduleReference = this.tsParseModuleReference();
  13127. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  13128. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  13129. }
  13130. node.moduleReference = moduleReference;
  13131. this.semicolon();
  13132. return this.finishNode(node, "TSImportEqualsDeclaration");
  13133. }
  13134. tsIsExternalModuleReference() {
  13135. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  13136. }
  13137. tsParseModuleReference() {
  13138. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  13139. }
  13140. tsParseExternalModuleReference() {
  13141. const node = this.startNode();
  13142. this.expectContextual(119);
  13143. this.expect(10);
  13144. if (!this.match(134)) {
  13145. this.unexpected();
  13146. }
  13147. node.expression = super.parseExprAtom();
  13148. this.expect(11);
  13149. this.sawUnambiguousESM = true;
  13150. return this.finishNode(node, "TSExternalModuleReference");
  13151. }
  13152. tsLookAhead(f) {
  13153. const state = this.state.clone();
  13154. const res = f();
  13155. this.state = state;
  13156. return res;
  13157. }
  13158. tsTryParseAndCatch(f) {
  13159. const result = this.tryParse(abort => f() || abort());
  13160. if (result.aborted || !result.node) return;
  13161. if (result.error) this.state = result.failState;
  13162. return result.node;
  13163. }
  13164. tsTryParse(f) {
  13165. const state = this.state.clone();
  13166. const result = f();
  13167. if (result !== undefined && result !== false) {
  13168. return result;
  13169. }
  13170. this.state = state;
  13171. }
  13172. tsTryParseDeclare(node) {
  13173. if (this.isLineTerminator()) {
  13174. return;
  13175. }
  13176. const startType = this.state.type;
  13177. return this.tsInAmbientContext(() => {
  13178. switch (startType) {
  13179. case 68:
  13180. node.declare = true;
  13181. return super.parseFunctionStatement(node, false, false);
  13182. case 80:
  13183. node.declare = true;
  13184. return this.parseClass(node, true, false);
  13185. case 126:
  13186. return this.tsParseEnumDeclaration(node, {
  13187. declare: true
  13188. });
  13189. case 112:
  13190. return this.tsParseAmbientExternalModuleDeclaration(node);
  13191. case 100:
  13192. if (this.state.containsEsc) {
  13193. return;
  13194. }
  13195. case 75:
  13196. case 74:
  13197. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  13198. node.declare = true;
  13199. return this.parseVarStatement(node, this.state.value, true);
  13200. }
  13201. this.expect(75);
  13202. return this.tsParseEnumDeclaration(node, {
  13203. const: true,
  13204. declare: true
  13205. });
  13206. case 107:
  13207. if (this.isUsing()) {
  13208. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  13209. node.declare = true;
  13210. return this.parseVarStatement(node, "using", true);
  13211. }
  13212. break;
  13213. case 96:
  13214. if (this.isAwaitUsing()) {
  13215. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  13216. node.declare = true;
  13217. this.next();
  13218. return this.parseVarStatement(node, "await using", true);
  13219. }
  13220. break;
  13221. case 129:
  13222. {
  13223. const result = this.tsParseInterfaceDeclaration(node, {
  13224. declare: true
  13225. });
  13226. if (result) return result;
  13227. }
  13228. default:
  13229. if (tokenIsIdentifier(startType)) {
  13230. return this.tsParseDeclaration(node, this.state.type, true, null);
  13231. }
  13232. }
  13233. });
  13234. }
  13235. tsTryParseExportDeclaration() {
  13236. return this.tsParseDeclaration(this.startNode(), this.state.type, true, null);
  13237. }
  13238. tsParseDeclaration(node, type, next, decorators) {
  13239. switch (type) {
  13240. case 124:
  13241. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  13242. return this.tsParseAbstractDeclaration(node, decorators);
  13243. }
  13244. break;
  13245. case 127:
  13246. if (this.tsCheckLineTerminator(next)) {
  13247. if (this.match(134)) {
  13248. return this.tsParseAmbientExternalModuleDeclaration(node);
  13249. } else if (tokenIsIdentifier(this.state.type)) {
  13250. node.kind = "module";
  13251. return this.tsParseModuleOrNamespaceDeclaration(node);
  13252. }
  13253. }
  13254. break;
  13255. case 128:
  13256. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  13257. node.kind = "namespace";
  13258. return this.tsParseModuleOrNamespaceDeclaration(node);
  13259. }
  13260. break;
  13261. case 130:
  13262. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  13263. return this.tsParseTypeAliasDeclaration(node);
  13264. }
  13265. break;
  13266. }
  13267. }
  13268. tsCheckLineTerminator(next) {
  13269. if (next) {
  13270. if (this.hasFollowingLineBreak()) return false;
  13271. this.next();
  13272. return true;
  13273. }
  13274. return !this.isLineTerminator();
  13275. }
  13276. tsTryParseGenericAsyncArrowFunction(startLoc) {
  13277. if (!this.match(47)) return;
  13278. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13279. this.state.maybeInArrowParameters = true;
  13280. const res = this.tsTryParseAndCatch(() => {
  13281. const node = this.startNodeAt(startLoc);
  13282. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  13283. super.parseFunctionParams(node);
  13284. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  13285. this.expect(19);
  13286. return node;
  13287. });
  13288. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13289. if (!res) return;
  13290. return super.parseArrowExpression(res, null, true);
  13291. }
  13292. tsParseTypeArgumentsInExpression() {
  13293. if (this.reScan_lt() !== 47) return;
  13294. return this.tsParseTypeArguments();
  13295. }
  13296. tsParseTypeArguments() {
  13297. const node = this.startNode();
  13298. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  13299. this.expect(47);
  13300. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  13301. }));
  13302. if (node.params.length === 0) {
  13303. this.raise(TSErrors.EmptyTypeArguments, node);
  13304. } else if (!this.state.inType && this.curContext() === types.brace) {
  13305. this.reScan_lt_gt();
  13306. }
  13307. this.expect(48);
  13308. return this.finishNode(node, "TSTypeParameterInstantiation");
  13309. }
  13310. tsIsDeclarationStart() {
  13311. return tokenIsTSDeclarationStart(this.state.type);
  13312. }
  13313. isExportDefaultSpecifier() {
  13314. if (this.tsIsDeclarationStart()) return false;
  13315. return super.isExportDefaultSpecifier();
  13316. }
  13317. parseBindingElement(flags, decorators) {
  13318. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  13319. const modified = {};
  13320. this.tsParseModifiers({
  13321. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  13322. }, modified);
  13323. const accessibility = modified.accessibility;
  13324. const override = modified.override;
  13325. const readonly = modified.readonly;
  13326. if (!(flags & 4) && (accessibility || readonly || override)) {
  13327. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  13328. }
  13329. const left = this.parseMaybeDefault();
  13330. if (flags & 2) {
  13331. this.parseFunctionParamType(left);
  13332. }
  13333. const elt = this.parseMaybeDefault(left.loc.start, left);
  13334. if (accessibility || readonly || override) {
  13335. const pp = this.startNodeAt(startLoc);
  13336. if (decorators.length) {
  13337. pp.decorators = decorators;
  13338. }
  13339. if (accessibility) pp.accessibility = accessibility;
  13340. if (readonly) pp.readonly = readonly;
  13341. if (override) pp.override = override;
  13342. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  13343. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  13344. }
  13345. pp.parameter = elt;
  13346. return this.finishNode(pp, "TSParameterProperty");
  13347. }
  13348. if (decorators.length) {
  13349. left.decorators = decorators;
  13350. }
  13351. return elt;
  13352. }
  13353. isSimpleParameter(node) {
  13354. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  13355. }
  13356. tsDisallowOptionalPattern(node) {
  13357. for (const param of node.params) {
  13358. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  13359. this.raise(TSErrors.PatternIsOptional, param);
  13360. }
  13361. }
  13362. }
  13363. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  13364. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  13365. this.tsDisallowOptionalPattern(node);
  13366. }
  13367. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  13368. if (this.match(14)) {
  13369. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  13370. }
  13371. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  13372. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  13373. return this.finishNode(node, bodilessType);
  13374. }
  13375. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  13376. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  13377. if (node.declare) {
  13378. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  13379. }
  13380. }
  13381. this.tsDisallowOptionalPattern(node);
  13382. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  13383. }
  13384. registerFunctionStatementId(node) {
  13385. if (!node.body && node.id) {
  13386. this.checkIdentifier(node.id, 1024);
  13387. } else {
  13388. super.registerFunctionStatementId(node);
  13389. }
  13390. }
  13391. tsCheckForInvalidTypeCasts(items) {
  13392. items.forEach(node => {
  13393. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  13394. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  13395. }
  13396. });
  13397. }
  13398. toReferencedList(exprList, isInParens) {
  13399. this.tsCheckForInvalidTypeCasts(exprList);
  13400. return exprList;
  13401. }
  13402. parseArrayLike(close, isTuple, refExpressionErrors) {
  13403. const node = super.parseArrayLike(close, isTuple, refExpressionErrors);
  13404. if (node.type === "ArrayExpression") {
  13405. this.tsCheckForInvalidTypeCasts(node.elements);
  13406. }
  13407. return node;
  13408. }
  13409. parseSubscript(base, startLoc, noCalls, state) {
  13410. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  13411. this.state.canStartJSXElement = false;
  13412. this.next();
  13413. const nonNullExpression = this.startNodeAt(startLoc);
  13414. nonNullExpression.expression = base;
  13415. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  13416. }
  13417. let isOptionalCall = false;
  13418. if (this.match(18) && this.lookaheadCharCode() === 60) {
  13419. if (noCalls) {
  13420. state.stop = true;
  13421. return base;
  13422. }
  13423. state.optionalChainMember = isOptionalCall = true;
  13424. this.next();
  13425. }
  13426. if (this.match(47) || this.match(51)) {
  13427. let missingParenErrorLoc;
  13428. const result = this.tsTryParseAndCatch(() => {
  13429. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  13430. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  13431. if (asyncArrowFn) {
  13432. state.stop = true;
  13433. return asyncArrowFn;
  13434. }
  13435. }
  13436. const typeArguments = this.tsParseTypeArgumentsInExpression();
  13437. if (!typeArguments) return;
  13438. if (isOptionalCall && !this.match(10)) {
  13439. missingParenErrorLoc = this.state.curPosition();
  13440. return;
  13441. }
  13442. if (tokenIsTemplate(this.state.type)) {
  13443. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  13444. result.typeParameters = typeArguments;
  13445. return result;
  13446. }
  13447. if (!noCalls && this.eat(10)) {
  13448. const node = this.startNodeAt(startLoc);
  13449. node.callee = base;
  13450. node.arguments = this.parseCallExpressionArguments();
  13451. this.tsCheckForInvalidTypeCasts(node.arguments);
  13452. node.typeParameters = typeArguments;
  13453. if (state.optionalChainMember) {
  13454. node.optional = isOptionalCall;
  13455. }
  13456. return this.finishCallExpression(node, state.optionalChainMember);
  13457. }
  13458. const tokenType = this.state.type;
  13459. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenType !== 93 && tokenType !== 120 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  13460. return;
  13461. }
  13462. const node = this.startNodeAt(startLoc);
  13463. node.expression = base;
  13464. node.typeParameters = typeArguments;
  13465. return this.finishNode(node, "TSInstantiationExpression");
  13466. });
  13467. if (missingParenErrorLoc) {
  13468. this.unexpected(missingParenErrorLoc, 10);
  13469. }
  13470. if (result) {
  13471. if (result.type === "TSInstantiationExpression") {
  13472. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  13473. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  13474. }
  13475. if (!this.match(16) && !this.match(18)) {
  13476. result.expression = super.stopParseSubscript(base, state);
  13477. }
  13478. }
  13479. return result;
  13480. }
  13481. }
  13482. return super.parseSubscript(base, startLoc, noCalls, state);
  13483. }
  13484. parseNewCallee(node) {
  13485. var _callee$extra;
  13486. super.parseNewCallee(node);
  13487. const {
  13488. callee
  13489. } = node;
  13490. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  13491. node.typeParameters = callee.typeParameters;
  13492. node.callee = callee.expression;
  13493. }
  13494. }
  13495. parseExprOp(left, leftStartLoc, minPrec) {
  13496. let isSatisfies;
  13497. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  13498. const node = this.startNodeAt(leftStartLoc);
  13499. node.expression = left;
  13500. node.typeAnnotation = this.tsInType(() => {
  13501. this.next();
  13502. if (this.match(75)) {
  13503. if (isSatisfies) {
  13504. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  13505. keyword: "const"
  13506. });
  13507. }
  13508. return this.tsParseTypeReference();
  13509. }
  13510. return this.tsParseType();
  13511. });
  13512. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  13513. this.reScan_lt_gt();
  13514. return this.parseExprOp(node, leftStartLoc, minPrec);
  13515. }
  13516. return super.parseExprOp(left, leftStartLoc, minPrec);
  13517. }
  13518. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  13519. if (!this.state.isAmbientContext) {
  13520. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  13521. }
  13522. }
  13523. checkImportReflection(node) {
  13524. super.checkImportReflection(node);
  13525. if (node.module && node.importKind !== "value") {
  13526. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  13527. }
  13528. }
  13529. checkDuplicateExports() {}
  13530. isPotentialImportPhase(isExport) {
  13531. if (super.isPotentialImportPhase(isExport)) return true;
  13532. if (this.isContextual(130)) {
  13533. const ch = this.lookaheadCharCode();
  13534. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  13535. }
  13536. return !isExport && this.isContextual(87);
  13537. }
  13538. applyImportPhase(node, isExport, phase, loc) {
  13539. super.applyImportPhase(node, isExport, phase, loc);
  13540. if (isExport) {
  13541. node.exportKind = phase === "type" ? "type" : "value";
  13542. } else {
  13543. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  13544. }
  13545. }
  13546. parseImport(node) {
  13547. if (this.match(134)) {
  13548. node.importKind = "value";
  13549. return super.parseImport(node);
  13550. }
  13551. let importNode;
  13552. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  13553. node.importKind = "value";
  13554. return this.tsParseImportEqualsDeclaration(node);
  13555. } else if (this.isContextual(130)) {
  13556. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  13557. if (this.lookaheadCharCode() === 61) {
  13558. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  13559. } else {
  13560. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  13561. }
  13562. } else {
  13563. importNode = super.parseImport(node);
  13564. }
  13565. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  13566. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  13567. }
  13568. return importNode;
  13569. }
  13570. parseExport(node, decorators) {
  13571. if (this.match(83)) {
  13572. const nodeImportEquals = node;
  13573. this.next();
  13574. let maybeDefaultIdentifier = null;
  13575. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  13576. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  13577. } else {
  13578. nodeImportEquals.importKind = "value";
  13579. }
  13580. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  13581. return declaration;
  13582. } else if (this.eat(29)) {
  13583. const assign = node;
  13584. assign.expression = super.parseExpression();
  13585. this.semicolon();
  13586. this.sawUnambiguousESM = true;
  13587. return this.finishNode(assign, "TSExportAssignment");
  13588. } else if (this.eatContextual(93)) {
  13589. const decl = node;
  13590. this.expectContextual(128);
  13591. decl.id = this.parseIdentifier();
  13592. this.semicolon();
  13593. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  13594. } else {
  13595. return super.parseExport(node, decorators);
  13596. }
  13597. }
  13598. isAbstractClass() {
  13599. return this.isContextual(124) && this.isLookaheadContextual("class");
  13600. }
  13601. parseExportDefaultExpression() {
  13602. if (this.isAbstractClass()) {
  13603. const cls = this.startNode();
  13604. this.next();
  13605. cls.abstract = true;
  13606. return this.parseClass(cls, true, true);
  13607. }
  13608. if (this.match(129)) {
  13609. const result = this.tsParseInterfaceDeclaration(this.startNode());
  13610. if (result) return result;
  13611. }
  13612. return super.parseExportDefaultExpression();
  13613. }
  13614. parseVarStatement(node, kind, allowMissingInitializer = false) {
  13615. const {
  13616. isAmbientContext
  13617. } = this.state;
  13618. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  13619. if (!isAmbientContext) return declaration;
  13620. if (!node.declare && (kind === "using" || kind === "await using")) {
  13621. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  13622. return declaration;
  13623. }
  13624. for (const {
  13625. id,
  13626. init
  13627. } of declaration.declarations) {
  13628. if (!init) continue;
  13629. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  13630. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  13631. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  13632. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  13633. }
  13634. }
  13635. return declaration;
  13636. }
  13637. parseStatementContent(flags, decorators) {
  13638. if (!this.state.containsEsc) {
  13639. switch (this.state.type) {
  13640. case 75:
  13641. {
  13642. if (this.isLookaheadContextual("enum")) {
  13643. const node = this.startNode();
  13644. this.expect(75);
  13645. return this.tsParseEnumDeclaration(node, {
  13646. const: true
  13647. });
  13648. }
  13649. break;
  13650. }
  13651. case 124:
  13652. case 125:
  13653. {
  13654. if (this.nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine()) {
  13655. const token = this.state.type;
  13656. const node = this.startNode();
  13657. this.next();
  13658. const declaration = token === 125 ? this.tsTryParseDeclare(node) : this.tsParseAbstractDeclaration(node, decorators);
  13659. if (declaration) {
  13660. if (token === 125) {
  13661. declaration.declare = true;
  13662. }
  13663. return declaration;
  13664. } else {
  13665. node.expression = this.createIdentifier(this.startNodeAt(node.loc.start), token === 125 ? "declare" : "abstract");
  13666. this.semicolon(false);
  13667. return this.finishNode(node, "ExpressionStatement");
  13668. }
  13669. }
  13670. break;
  13671. }
  13672. case 126:
  13673. return this.tsParseEnumDeclaration(this.startNode());
  13674. case 112:
  13675. {
  13676. const nextCh = this.lookaheadCharCode();
  13677. if (nextCh === 123) {
  13678. const node = this.startNode();
  13679. return this.tsParseAmbientExternalModuleDeclaration(node);
  13680. }
  13681. break;
  13682. }
  13683. case 129:
  13684. {
  13685. const result = this.tsParseInterfaceDeclaration(this.startNode());
  13686. if (result) return result;
  13687. break;
  13688. }
  13689. case 127:
  13690. {
  13691. if (this.nextTokenIsIdentifierOrStringLiteralOnSameLine()) {
  13692. const node = this.startNode();
  13693. this.next();
  13694. return this.tsParseDeclaration(node, 127, false, decorators);
  13695. }
  13696. break;
  13697. }
  13698. case 128:
  13699. {
  13700. if (this.nextTokenIsIdentifierOnSameLine()) {
  13701. const node = this.startNode();
  13702. this.next();
  13703. return this.tsParseDeclaration(node, 128, false, decorators);
  13704. }
  13705. break;
  13706. }
  13707. case 130:
  13708. {
  13709. if (this.nextTokenIsIdentifierOnSameLine()) {
  13710. const node = this.startNode();
  13711. this.next();
  13712. return this.tsParseTypeAliasDeclaration(node);
  13713. }
  13714. break;
  13715. }
  13716. }
  13717. }
  13718. return super.parseStatementContent(flags, decorators);
  13719. }
  13720. parseAccessModifier() {
  13721. return this.tsParseModifier(["public", "protected", "private"]);
  13722. }
  13723. tsHasSomeModifiers(member, modifiers) {
  13724. return modifiers.some(modifier => {
  13725. if (tsIsAccessModifier(modifier)) {
  13726. return member.accessibility === modifier;
  13727. }
  13728. return !!member[modifier];
  13729. });
  13730. }
  13731. tsIsStartOfStaticBlocks() {
  13732. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  13733. }
  13734. parseClassMember(classBody, member, state) {
  13735. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  13736. this.tsParseModifiers({
  13737. allowedModifiers: modifiers,
  13738. disallowedModifiers: ["in", "out"],
  13739. stopOnStartOfClassStaticBlock: true,
  13740. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  13741. }, member);
  13742. const callParseClassMemberWithIsStatic = () => {
  13743. if (this.tsIsStartOfStaticBlocks()) {
  13744. this.next();
  13745. this.next();
  13746. if (this.tsHasSomeModifiers(member, modifiers)) {
  13747. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  13748. }
  13749. super.parseClassStaticBlock(classBody, member);
  13750. } else {
  13751. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  13752. }
  13753. };
  13754. if (member.declare) {
  13755. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  13756. } else {
  13757. callParseClassMemberWithIsStatic();
  13758. }
  13759. }
  13760. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  13761. const idx = this.tsTryParseIndexSignature(member);
  13762. if (idx) {
  13763. classBody.body.push(idx);
  13764. if (member.abstract) {
  13765. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  13766. }
  13767. if (member.accessibility) {
  13768. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  13769. modifier: member.accessibility
  13770. });
  13771. }
  13772. if (member.declare) {
  13773. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  13774. }
  13775. if (member.override) {
  13776. this.raise(TSErrors.IndexSignatureHasOverride, member);
  13777. }
  13778. return;
  13779. }
  13780. if (!this.state.inAbstractClass && member.abstract) {
  13781. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  13782. }
  13783. if (member.override) {
  13784. if (!state.hadSuperClass) {
  13785. this.raise(TSErrors.OverrideNotInSubClass, member);
  13786. }
  13787. }
  13788. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  13789. }
  13790. parsePostMemberNameModifiers(methodOrProp) {
  13791. const optional = this.eat(17);
  13792. if (optional) methodOrProp.optional = true;
  13793. if (methodOrProp.readonly && this.match(10)) {
  13794. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  13795. }
  13796. if (methodOrProp.declare && this.match(10)) {
  13797. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  13798. }
  13799. }
  13800. shouldParseExportDeclaration() {
  13801. if (this.tsIsDeclarationStart()) return true;
  13802. return super.shouldParseExportDeclaration();
  13803. }
  13804. parseConditional(expr, startLoc, refExpressionErrors) {
  13805. if (!this.match(17)) return expr;
  13806. if (this.state.maybeInArrowParameters) {
  13807. const nextCh = this.lookaheadCharCode();
  13808. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  13809. this.setOptionalParametersError(refExpressionErrors);
  13810. return expr;
  13811. }
  13812. }
  13813. return super.parseConditional(expr, startLoc, refExpressionErrors);
  13814. }
  13815. parseParenItem(node, startLoc) {
  13816. const newNode = super.parseParenItem(node, startLoc);
  13817. if (this.eat(17)) {
  13818. newNode.optional = true;
  13819. this.resetEndLocation(node);
  13820. }
  13821. if (this.match(14)) {
  13822. const typeCastNode = this.startNodeAt(startLoc);
  13823. typeCastNode.expression = node;
  13824. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  13825. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  13826. }
  13827. return node;
  13828. }
  13829. parseExportDeclaration(node) {
  13830. if (!this.state.isAmbientContext && this.isContextual(125)) {
  13831. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  13832. }
  13833. const startLoc = this.state.startLoc;
  13834. const isDeclare = this.eatContextual(125);
  13835. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  13836. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  13837. }
  13838. const isIdentifier = tokenIsIdentifier(this.state.type);
  13839. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  13840. if (!declaration) return null;
  13841. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  13842. node.exportKind = "type";
  13843. }
  13844. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  13845. this.resetStartLocation(declaration, startLoc);
  13846. declaration.declare = true;
  13847. }
  13848. return declaration;
  13849. }
  13850. parseClassId(node, isStatement, optionalId, bindingType) {
  13851. if ((!isStatement || optionalId) && this.isContextual(113)) {
  13852. return;
  13853. }
  13854. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  13855. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  13856. if (typeParameters) node.typeParameters = typeParameters;
  13857. }
  13858. parseClassPropertyAnnotation(node) {
  13859. if (!node.optional) {
  13860. if (this.eat(35)) {
  13861. node.definite = true;
  13862. } else if (this.eat(17)) {
  13863. node.optional = true;
  13864. }
  13865. }
  13866. const type = this.tsTryParseTypeAnnotation();
  13867. if (type) node.typeAnnotation = type;
  13868. }
  13869. parseClassProperty(node) {
  13870. this.parseClassPropertyAnnotation(node);
  13871. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  13872. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  13873. }
  13874. if (node.abstract && this.match(29)) {
  13875. const {
  13876. key
  13877. } = node;
  13878. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  13879. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  13880. });
  13881. }
  13882. return super.parseClassProperty(node);
  13883. }
  13884. parseClassPrivateProperty(node) {
  13885. if (node.abstract) {
  13886. this.raise(TSErrors.PrivateElementHasAbstract, node);
  13887. }
  13888. if (node.accessibility) {
  13889. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  13890. modifier: node.accessibility
  13891. });
  13892. }
  13893. this.parseClassPropertyAnnotation(node);
  13894. return super.parseClassPrivateProperty(node);
  13895. }
  13896. parseClassAccessorProperty(node) {
  13897. this.parseClassPropertyAnnotation(node);
  13898. if (node.optional) {
  13899. this.raise(TSErrors.AccessorCannotBeOptional, node);
  13900. }
  13901. return super.parseClassAccessorProperty(node);
  13902. }
  13903. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  13904. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13905. if (typeParameters && isConstructor) {
  13906. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  13907. }
  13908. const {
  13909. declare = false,
  13910. kind
  13911. } = method;
  13912. if (declare && (kind === "get" || kind === "set")) {
  13913. this.raise(TSErrors.DeclareAccessor, method, {
  13914. kind
  13915. });
  13916. }
  13917. if (typeParameters) method.typeParameters = typeParameters;
  13918. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  13919. }
  13920. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  13921. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13922. if (typeParameters) method.typeParameters = typeParameters;
  13923. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  13924. }
  13925. declareClassPrivateMethodInScope(node, kind) {
  13926. if (node.type === "TSDeclareMethod") return;
  13927. if (node.type === "MethodDefinition" && node.value.body == null) {
  13928. return;
  13929. }
  13930. super.declareClassPrivateMethodInScope(node, kind);
  13931. }
  13932. parseClassSuper(node) {
  13933. super.parseClassSuper(node);
  13934. if (node.superClass) {
  13935. if (node.superClass.type === "TSInstantiationExpression") {
  13936. const tsInstantiationExpression = node.superClass;
  13937. const superClass = tsInstantiationExpression.expression;
  13938. this.takeSurroundingComments(superClass, superClass.start, superClass.end);
  13939. const superTypeArguments = tsInstantiationExpression.typeParameters;
  13940. this.takeSurroundingComments(superTypeArguments, superTypeArguments.start, superTypeArguments.end);
  13941. node.superClass = superClass;
  13942. node.superTypeParameters = superTypeArguments;
  13943. } else if (this.match(47) || this.match(51)) {
  13944. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  13945. }
  13946. }
  13947. if (this.eatContextual(113)) {
  13948. node.implements = this.tsParseHeritageClause("implements");
  13949. }
  13950. }
  13951. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  13952. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13953. if (typeParameters) prop.typeParameters = typeParameters;
  13954. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  13955. }
  13956. parseFunctionParams(node, isConstructor) {
  13957. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  13958. if (typeParameters) node.typeParameters = typeParameters;
  13959. super.parseFunctionParams(node, isConstructor);
  13960. }
  13961. parseVarId(decl, kind) {
  13962. super.parseVarId(decl, kind);
  13963. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  13964. decl.definite = true;
  13965. }
  13966. const type = this.tsTryParseTypeAnnotation();
  13967. if (type) {
  13968. decl.id.typeAnnotation = type;
  13969. this.resetEndLocation(decl.id);
  13970. }
  13971. }
  13972. parseAsyncArrowFromCallExpression(node, call) {
  13973. if (this.match(14)) {
  13974. node.returnType = this.tsParseTypeAnnotation();
  13975. }
  13976. return super.parseAsyncArrowFromCallExpression(node, call);
  13977. }
  13978. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  13979. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  13980. let state;
  13981. let jsx;
  13982. let typeCast;
  13983. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  13984. state = this.state.clone();
  13985. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  13986. if (!jsx.error) return jsx.node;
  13987. const {
  13988. context
  13989. } = this.state;
  13990. const currentContext = context[context.length - 1];
  13991. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  13992. context.pop();
  13993. }
  13994. }
  13995. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  13996. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  13997. }
  13998. if (!state || state === this.state) state = this.state.clone();
  13999. let typeParameters;
  14000. const arrow = this.tryParse(abort => {
  14001. var _expr$extra, _typeParameters;
  14002. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  14003. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  14004. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  14005. abort();
  14006. }
  14007. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  14008. this.resetStartLocationFromNode(expr, typeParameters);
  14009. }
  14010. expr.typeParameters = typeParameters;
  14011. return expr;
  14012. }, state);
  14013. if (!arrow.error && !arrow.aborted) {
  14014. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  14015. return arrow.node;
  14016. }
  14017. if (!jsx) {
  14018. assert(!this.hasPlugin("jsx"));
  14019. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  14020. if (!typeCast.error) return typeCast.node;
  14021. }
  14022. if ((_jsx2 = jsx) != null && _jsx2.node) {
  14023. this.state = jsx.failState;
  14024. return jsx.node;
  14025. }
  14026. if (arrow.node) {
  14027. this.state = arrow.failState;
  14028. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  14029. return arrow.node;
  14030. }
  14031. if ((_typeCast = typeCast) != null && _typeCast.node) {
  14032. this.state = typeCast.failState;
  14033. return typeCast.node;
  14034. }
  14035. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  14036. }
  14037. reportReservedArrowTypeParam(node) {
  14038. var _node$extra2;
  14039. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  14040. this.raise(TSErrors.ReservedArrowTypeParam, node);
  14041. }
  14042. }
  14043. parseMaybeUnary(refExpressionErrors, sawUnary) {
  14044. if (!this.hasPlugin("jsx") && this.match(47)) {
  14045. return this.tsParseTypeAssertion();
  14046. }
  14047. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  14048. }
  14049. parseArrow(node) {
  14050. if (this.match(14)) {
  14051. const result = this.tryParse(abort => {
  14052. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  14053. if (this.canInsertSemicolon() || !this.match(19)) abort();
  14054. return returnType;
  14055. });
  14056. if (result.aborted) return;
  14057. if (!result.thrown) {
  14058. if (result.error) this.state = result.failState;
  14059. node.returnType = result.node;
  14060. }
  14061. }
  14062. return super.parseArrow(node);
  14063. }
  14064. parseFunctionParamType(param) {
  14065. if (this.eat(17)) {
  14066. param.optional = true;
  14067. }
  14068. const type = this.tsTryParseTypeAnnotation();
  14069. if (type) param.typeAnnotation = type;
  14070. this.resetEndLocation(param);
  14071. return param;
  14072. }
  14073. isAssignable(node, isBinding) {
  14074. switch (node.type) {
  14075. case "TSTypeCastExpression":
  14076. return this.isAssignable(node.expression, isBinding);
  14077. case "TSParameterProperty":
  14078. return true;
  14079. default:
  14080. return super.isAssignable(node, isBinding);
  14081. }
  14082. }
  14083. toAssignable(node, isLHS = false) {
  14084. switch (node.type) {
  14085. case "ParenthesizedExpression":
  14086. this.toAssignableParenthesizedExpression(node, isLHS);
  14087. break;
  14088. case "TSAsExpression":
  14089. case "TSSatisfiesExpression":
  14090. case "TSNonNullExpression":
  14091. case "TSTypeAssertion":
  14092. if (isLHS) {
  14093. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  14094. } else {
  14095. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  14096. }
  14097. this.toAssignable(node.expression, isLHS);
  14098. break;
  14099. case "AssignmentExpression":
  14100. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  14101. node.left = this.typeCastToParameter(node.left);
  14102. }
  14103. default:
  14104. super.toAssignable(node, isLHS);
  14105. }
  14106. }
  14107. toAssignableParenthesizedExpression(node, isLHS) {
  14108. switch (node.expression.type) {
  14109. case "TSAsExpression":
  14110. case "TSSatisfiesExpression":
  14111. case "TSNonNullExpression":
  14112. case "TSTypeAssertion":
  14113. case "ParenthesizedExpression":
  14114. this.toAssignable(node.expression, isLHS);
  14115. break;
  14116. default:
  14117. super.toAssignable(node, isLHS);
  14118. }
  14119. }
  14120. checkToRestConversion(node, allowPattern) {
  14121. switch (node.type) {
  14122. case "TSAsExpression":
  14123. case "TSSatisfiesExpression":
  14124. case "TSTypeAssertion":
  14125. case "TSNonNullExpression":
  14126. this.checkToRestConversion(node.expression, false);
  14127. break;
  14128. default:
  14129. super.checkToRestConversion(node, allowPattern);
  14130. }
  14131. }
  14132. isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding) {
  14133. switch (type) {
  14134. case "TSTypeCastExpression":
  14135. return true;
  14136. case "TSParameterProperty":
  14137. return "parameter";
  14138. case "TSNonNullExpression":
  14139. return "expression";
  14140. case "TSAsExpression":
  14141. case "TSSatisfiesExpression":
  14142. case "TSTypeAssertion":
  14143. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  14144. default:
  14145. return super.isValidLVal(type, disallowCallExpression, isUnparenthesizedInAssign, binding);
  14146. }
  14147. }
  14148. parseBindingAtom() {
  14149. if (this.state.type === 78) {
  14150. return this.parseIdentifier(true);
  14151. }
  14152. return super.parseBindingAtom();
  14153. }
  14154. parseMaybeDecoratorArguments(expr, startLoc) {
  14155. if (this.match(47) || this.match(51)) {
  14156. const typeArguments = this.tsParseTypeArgumentsInExpression();
  14157. if (this.match(10)) {
  14158. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  14159. call.typeParameters = typeArguments;
  14160. return call;
  14161. }
  14162. this.unexpected(null, 10);
  14163. }
  14164. return super.parseMaybeDecoratorArguments(expr, startLoc);
  14165. }
  14166. checkCommaAfterRest(close) {
  14167. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  14168. this.next();
  14169. return false;
  14170. }
  14171. return super.checkCommaAfterRest(close);
  14172. }
  14173. isClassMethod() {
  14174. return this.match(47) || super.isClassMethod();
  14175. }
  14176. isClassProperty() {
  14177. return this.match(35) || this.match(14) || super.isClassProperty();
  14178. }
  14179. parseMaybeDefault(startLoc, left) {
  14180. const node = super.parseMaybeDefault(startLoc, left);
  14181. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  14182. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  14183. }
  14184. return node;
  14185. }
  14186. getTokenFromCode(code) {
  14187. if (this.state.inType) {
  14188. if (code === 62) {
  14189. this.finishOp(48, 1);
  14190. return;
  14191. }
  14192. if (code === 60) {
  14193. this.finishOp(47, 1);
  14194. return;
  14195. }
  14196. }
  14197. super.getTokenFromCode(code);
  14198. }
  14199. reScan_lt_gt() {
  14200. const {
  14201. type
  14202. } = this.state;
  14203. if (type === 47) {
  14204. this.state.pos -= 1;
  14205. this.readToken_lt();
  14206. } else if (type === 48) {
  14207. this.state.pos -= 1;
  14208. this.readToken_gt();
  14209. }
  14210. }
  14211. reScan_lt() {
  14212. const {
  14213. type
  14214. } = this.state;
  14215. if (type === 51) {
  14216. this.state.pos -= 2;
  14217. this.finishOp(47, 1);
  14218. return 47;
  14219. }
  14220. return type;
  14221. }
  14222. toAssignableListItem(exprList, index, isLHS) {
  14223. const node = exprList[index];
  14224. if (node.type === "TSTypeCastExpression") {
  14225. exprList[index] = this.typeCastToParameter(node);
  14226. }
  14227. super.toAssignableListItem(exprList, index, isLHS);
  14228. }
  14229. typeCastToParameter(node) {
  14230. node.expression.typeAnnotation = node.typeAnnotation;
  14231. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  14232. return node.expression;
  14233. }
  14234. shouldParseArrow(params) {
  14235. if (this.match(14)) {
  14236. return params.every(expr => this.isAssignable(expr, true));
  14237. }
  14238. return super.shouldParseArrow(params);
  14239. }
  14240. shouldParseAsyncArrow() {
  14241. return this.match(14) || super.shouldParseAsyncArrow();
  14242. }
  14243. canHaveLeadingDecorator() {
  14244. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  14245. }
  14246. jsxParseOpeningElementAfterName(node) {
  14247. if (this.match(47) || this.match(51)) {
  14248. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  14249. if (typeArguments) {
  14250. node.typeParameters = typeArguments;
  14251. }
  14252. }
  14253. return super.jsxParseOpeningElementAfterName(node);
  14254. }
  14255. getGetterSetterExpectedParamCount(method) {
  14256. const baseCount = super.getGetterSetterExpectedParamCount(method);
  14257. const params = this.getObjectOrClassMethodParams(method);
  14258. const firstParam = params[0];
  14259. const hasContextParam = firstParam && this.isThisParam(firstParam);
  14260. return hasContextParam ? baseCount + 1 : baseCount;
  14261. }
  14262. parseCatchClauseParam() {
  14263. const param = super.parseCatchClauseParam();
  14264. const type = this.tsTryParseTypeAnnotation();
  14265. if (type) {
  14266. param.typeAnnotation = type;
  14267. this.resetEndLocation(param);
  14268. }
  14269. return param;
  14270. }
  14271. tsInAmbientContext(cb) {
  14272. const {
  14273. isAmbientContext: oldIsAmbientContext,
  14274. strict: oldStrict
  14275. } = this.state;
  14276. this.state.isAmbientContext = true;
  14277. this.state.strict = false;
  14278. try {
  14279. return cb();
  14280. } finally {
  14281. this.state.isAmbientContext = oldIsAmbientContext;
  14282. this.state.strict = oldStrict;
  14283. }
  14284. }
  14285. parseClass(node, isStatement, optionalId) {
  14286. const oldInAbstractClass = this.state.inAbstractClass;
  14287. this.state.inAbstractClass = !!node.abstract;
  14288. try {
  14289. return super.parseClass(node, isStatement, optionalId);
  14290. } finally {
  14291. this.state.inAbstractClass = oldInAbstractClass;
  14292. }
  14293. }
  14294. tsParseAbstractDeclaration(node, decorators) {
  14295. if (this.match(80)) {
  14296. node.abstract = true;
  14297. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  14298. } else if (this.isContextual(129)) {
  14299. if (!this.hasFollowingLineBreak()) {
  14300. node.abstract = true;
  14301. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  14302. return this.tsParseInterfaceDeclaration(node);
  14303. } else {
  14304. return null;
  14305. }
  14306. }
  14307. throw this.unexpected(null, 80);
  14308. }
  14309. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  14310. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  14311. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  14312. const hasEstreePlugin = this.hasPlugin("estree");
  14313. const methodFn = hasEstreePlugin ? method.value : method;
  14314. if (methodFn.body) {
  14315. const {
  14316. key
  14317. } = method;
  14318. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  14319. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  14320. });
  14321. }
  14322. }
  14323. return method;
  14324. }
  14325. tsParseTypeParameterName() {
  14326. const typeName = this.parseIdentifier();
  14327. return typeName.name;
  14328. }
  14329. shouldParseAsAmbientContext() {
  14330. return !!this.getPluginOption("typescript", "dts");
  14331. }
  14332. parse() {
  14333. if (this.shouldParseAsAmbientContext()) {
  14334. this.state.isAmbientContext = true;
  14335. }
  14336. return super.parse();
  14337. }
  14338. getExpression() {
  14339. if (this.shouldParseAsAmbientContext()) {
  14340. this.state.isAmbientContext = true;
  14341. }
  14342. return super.getExpression();
  14343. }
  14344. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  14345. if (!isString && isMaybeTypeOnly) {
  14346. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  14347. return this.finishNode(node, "ExportSpecifier");
  14348. }
  14349. node.exportKind = "value";
  14350. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  14351. }
  14352. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  14353. if (!importedIsString && isMaybeTypeOnly) {
  14354. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  14355. return this.finishNode(specifier, "ImportSpecifier");
  14356. }
  14357. specifier.importKind = "value";
  14358. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  14359. }
  14360. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  14361. const leftOfAsKey = isImport ? "imported" : "local";
  14362. const rightOfAsKey = isImport ? "local" : "exported";
  14363. let leftOfAs = node[leftOfAsKey];
  14364. let rightOfAs;
  14365. let hasTypeSpecifier = false;
  14366. let canParseAsKeyword = true;
  14367. const loc = leftOfAs.loc.start;
  14368. if (this.isContextual(93)) {
  14369. const firstAs = this.parseIdentifier();
  14370. if (this.isContextual(93)) {
  14371. const secondAs = this.parseIdentifier();
  14372. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14373. hasTypeSpecifier = true;
  14374. leftOfAs = firstAs;
  14375. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14376. canParseAsKeyword = false;
  14377. } else {
  14378. rightOfAs = secondAs;
  14379. canParseAsKeyword = false;
  14380. }
  14381. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14382. canParseAsKeyword = false;
  14383. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14384. } else {
  14385. hasTypeSpecifier = true;
  14386. leftOfAs = firstAs;
  14387. }
  14388. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  14389. hasTypeSpecifier = true;
  14390. if (isImport) {
  14391. leftOfAs = this.parseIdentifier(true);
  14392. if (!this.isContextual(93)) {
  14393. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  14394. }
  14395. } else {
  14396. leftOfAs = this.parseModuleExportName();
  14397. }
  14398. }
  14399. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  14400. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  14401. }
  14402. node[leftOfAsKey] = leftOfAs;
  14403. node[rightOfAsKey] = rightOfAs;
  14404. const kindKey = isImport ? "importKind" : "exportKind";
  14405. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  14406. if (canParseAsKeyword && this.eatContextual(93)) {
  14407. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  14408. }
  14409. if (!node[rightOfAsKey]) {
  14410. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  14411. }
  14412. if (isImport) {
  14413. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  14414. }
  14415. }
  14416. fillOptionalPropertiesForTSESLint(node) {
  14417. 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;
  14418. switch (node.type) {
  14419. case "ExpressionStatement":
  14420. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  14421. return;
  14422. case "RestElement":
  14423. node.value = undefined;
  14424. case "Identifier":
  14425. case "ArrayPattern":
  14426. case "AssignmentPattern":
  14427. case "ObjectPattern":
  14428. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  14429. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  14430. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  14431. return;
  14432. case "TSParameterProperty":
  14433. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  14434. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  14435. (_node$override = node.override) != null ? _node$override : node.override = false;
  14436. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  14437. (_node$static = node.static) != null ? _node$static : node.static = false;
  14438. return;
  14439. case "TSEmptyBodyFunctionExpression":
  14440. node.body = null;
  14441. case "TSDeclareFunction":
  14442. case "FunctionDeclaration":
  14443. case "FunctionExpression":
  14444. case "ClassMethod":
  14445. case "ClassPrivateMethod":
  14446. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  14447. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  14448. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  14449. return;
  14450. case "Property":
  14451. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  14452. return;
  14453. case "TSMethodSignature":
  14454. case "TSPropertySignature":
  14455. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  14456. case "TSIndexSignature":
  14457. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  14458. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  14459. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  14460. return;
  14461. case "TSAbstractPropertyDefinition":
  14462. case "PropertyDefinition":
  14463. case "TSAbstractAccessorProperty":
  14464. case "AccessorProperty":
  14465. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  14466. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  14467. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  14468. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  14469. case "TSAbstractMethodDefinition":
  14470. case "MethodDefinition":
  14471. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  14472. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  14473. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  14474. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  14475. return;
  14476. case "ClassExpression":
  14477. (_node$id = node.id) != null ? _node$id : node.id = null;
  14478. case "ClassDeclaration":
  14479. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  14480. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  14481. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  14482. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  14483. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  14484. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  14485. return;
  14486. case "TSTypeAliasDeclaration":
  14487. case "VariableDeclaration":
  14488. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  14489. return;
  14490. case "VariableDeclarator":
  14491. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  14492. return;
  14493. case "TSEnumDeclaration":
  14494. (_node$const = node.const) != null ? _node$const : node.const = false;
  14495. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  14496. return;
  14497. case "TSEnumMember":
  14498. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  14499. return;
  14500. case "TSImportType":
  14501. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  14502. (_node$options = node.options) != null ? _node$options : node.options = null;
  14503. return;
  14504. case "TSInterfaceDeclaration":
  14505. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  14506. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  14507. return;
  14508. case "TSMappedType":
  14509. (_node$optional5 = node.optional) != null ? _node$optional5 : node.optional = false;
  14510. (_node$readonly4 = node.readonly) != null ? _node$readonly4 : node.readonly = undefined;
  14511. return;
  14512. case "TSModuleDeclaration":
  14513. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  14514. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  14515. return;
  14516. case "TSTypeParameter":
  14517. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  14518. (_node$in = node.in) != null ? _node$in : node.in = false;
  14519. (_node$out = node.out) != null ? _node$out : node.out = false;
  14520. return;
  14521. }
  14522. }
  14523. chStartsBindingIdentifierAndNotRelationalOperator(ch, pos) {
  14524. if (isIdentifierStart(ch)) {
  14525. keywordAndTSRelationalOperator.lastIndex = pos;
  14526. if (keywordAndTSRelationalOperator.test(this.input)) {
  14527. const endCh = this.codePointAtPos(keywordAndTSRelationalOperator.lastIndex);
  14528. if (!isIdentifierChar(endCh) && endCh !== 92) {
  14529. return false;
  14530. }
  14531. }
  14532. return true;
  14533. } else if (ch === 92) {
  14534. return true;
  14535. } else {
  14536. return false;
  14537. }
  14538. }
  14539. nextTokenIsIdentifierAndNotTSRelationalOperatorOnSameLine() {
  14540. const next = this.nextTokenInLineStart();
  14541. const nextCh = this.codePointAtPos(next);
  14542. return this.chStartsBindingIdentifierAndNotRelationalOperator(nextCh, next);
  14543. }
  14544. nextTokenIsIdentifierOrStringLiteralOnSameLine() {
  14545. const next = this.nextTokenInLineStart();
  14546. const nextCh = this.codePointAtPos(next);
  14547. return this.chStartsBindingIdentifier(nextCh, next) || nextCh === 34 || nextCh === 39;
  14548. }
  14549. };
  14550. function isPossiblyLiteralEnum(expression) {
  14551. if (expression.type !== "MemberExpression") return false;
  14552. const {
  14553. computed,
  14554. property
  14555. } = expression;
  14556. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  14557. return false;
  14558. }
  14559. return isUncomputedMemberExpressionChain(expression.object);
  14560. }
  14561. function isValidAmbientConstInitializer(expression, estree) {
  14562. var _expression$extra;
  14563. const {
  14564. type
  14565. } = expression;
  14566. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  14567. return false;
  14568. }
  14569. if (estree) {
  14570. if (type === "Literal") {
  14571. const {
  14572. value
  14573. } = expression;
  14574. if (typeof value === "string" || typeof value === "boolean") {
  14575. return true;
  14576. }
  14577. }
  14578. } else {
  14579. if (type === "StringLiteral" || type === "BooleanLiteral") {
  14580. return true;
  14581. }
  14582. }
  14583. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  14584. return true;
  14585. }
  14586. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  14587. return true;
  14588. }
  14589. if (isPossiblyLiteralEnum(expression)) {
  14590. return true;
  14591. }
  14592. return false;
  14593. }
  14594. function isNumber(expression, estree) {
  14595. if (estree) {
  14596. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  14597. }
  14598. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  14599. }
  14600. function isNegativeNumber(expression, estree) {
  14601. if (expression.type === "UnaryExpression") {
  14602. const {
  14603. operator,
  14604. argument
  14605. } = expression;
  14606. if (operator === "-" && isNumber(argument, estree)) {
  14607. return true;
  14608. }
  14609. }
  14610. return false;
  14611. }
  14612. function isUncomputedMemberExpressionChain(expression) {
  14613. if (expression.type === "Identifier") return true;
  14614. if (expression.type !== "MemberExpression" || expression.computed) {
  14615. return false;
  14616. }
  14617. return isUncomputedMemberExpressionChain(expression.object);
  14618. }
  14619. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  14620. ClassNameIsRequired: "A class name is required.",
  14621. UnexpectedSpace: "Unexpected space in placeholder."
  14622. });
  14623. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  14624. parsePlaceholder(expectedNode) {
  14625. if (this.match(133)) {
  14626. const node = this.startNode();
  14627. this.next();
  14628. this.assertNoSpace();
  14629. node.name = super.parseIdentifier(true);
  14630. this.assertNoSpace();
  14631. this.expect(133);
  14632. return this.finishPlaceholder(node, expectedNode);
  14633. }
  14634. }
  14635. finishPlaceholder(node, expectedNode) {
  14636. let placeholder = node;
  14637. if (!placeholder.expectedNode || !placeholder.type) {
  14638. placeholder = this.finishNode(placeholder, "Placeholder");
  14639. }
  14640. placeholder.expectedNode = expectedNode;
  14641. return placeholder;
  14642. }
  14643. getTokenFromCode(code) {
  14644. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  14645. this.finishOp(133, 2);
  14646. } else {
  14647. super.getTokenFromCode(code);
  14648. }
  14649. }
  14650. parseExprAtom(refExpressionErrors) {
  14651. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  14652. }
  14653. parseIdentifier(liberal) {
  14654. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  14655. }
  14656. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  14657. if (word !== undefined) {
  14658. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  14659. }
  14660. }
  14661. cloneIdentifier(node) {
  14662. const cloned = super.cloneIdentifier(node);
  14663. if (cloned.type === "Placeholder") {
  14664. cloned.expectedNode = node.expectedNode;
  14665. }
  14666. return cloned;
  14667. }
  14668. cloneStringLiteral(node) {
  14669. if (node.type === "Placeholder") {
  14670. return this.cloneIdentifier(node);
  14671. }
  14672. return super.cloneStringLiteral(node);
  14673. }
  14674. parseBindingAtom() {
  14675. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  14676. }
  14677. isValidLVal(type, disallowCallExpression, isParenthesized, binding) {
  14678. return type === "Placeholder" || super.isValidLVal(type, disallowCallExpression, isParenthesized, binding);
  14679. }
  14680. toAssignable(node, isLHS) {
  14681. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  14682. node.expectedNode = "Pattern";
  14683. } else {
  14684. super.toAssignable(node, isLHS);
  14685. }
  14686. }
  14687. chStartsBindingIdentifier(ch, pos) {
  14688. if (super.chStartsBindingIdentifier(ch, pos)) {
  14689. return true;
  14690. }
  14691. const next = this.nextTokenStart();
  14692. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  14693. return true;
  14694. }
  14695. return false;
  14696. }
  14697. verifyBreakContinue(node, isBreak) {
  14698. var _node$label;
  14699. if (((_node$label = node.label) == null ? void 0 : _node$label.type) === "Placeholder") return;
  14700. super.verifyBreakContinue(node, isBreak);
  14701. }
  14702. parseExpressionStatement(node, expr) {
  14703. var _expr$extra;
  14704. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  14705. return super.parseExpressionStatement(node, expr);
  14706. }
  14707. if (this.match(14)) {
  14708. const stmt = node;
  14709. stmt.label = this.finishPlaceholder(expr, "Identifier");
  14710. this.next();
  14711. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  14712. return this.finishNode(stmt, "LabeledStatement");
  14713. }
  14714. this.semicolon();
  14715. const stmtPlaceholder = node;
  14716. stmtPlaceholder.name = expr.name;
  14717. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  14718. }
  14719. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  14720. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  14721. }
  14722. parseFunctionId(requireId) {
  14723. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  14724. }
  14725. parseClass(node, isStatement, optionalId) {
  14726. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  14727. this.next();
  14728. const oldStrict = this.state.strict;
  14729. const placeholder = this.parsePlaceholder("Identifier");
  14730. if (placeholder) {
  14731. if (this.match(81) || this.match(133) || this.match(5)) {
  14732. node.id = placeholder;
  14733. } else if (optionalId || !isStatement) {
  14734. node.id = null;
  14735. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  14736. return this.finishNode(node, type);
  14737. } else {
  14738. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  14739. }
  14740. } else {
  14741. this.parseClassId(node, isStatement, optionalId);
  14742. }
  14743. super.parseClassSuper(node);
  14744. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  14745. return this.finishNode(node, type);
  14746. }
  14747. parseExport(node, decorators) {
  14748. const placeholder = this.parsePlaceholder("Identifier");
  14749. if (!placeholder) return super.parseExport(node, decorators);
  14750. const node2 = node;
  14751. if (!this.isContextual(98) && !this.match(12)) {
  14752. node2.specifiers = [];
  14753. node2.source = null;
  14754. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  14755. return this.finishNode(node2, "ExportNamedDeclaration");
  14756. }
  14757. this.expectPlugin("exportDefaultFrom");
  14758. const specifier = this.startNode();
  14759. specifier.exported = placeholder;
  14760. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  14761. return super.parseExport(node2, decorators);
  14762. }
  14763. isExportDefaultSpecifier() {
  14764. if (this.match(65)) {
  14765. const next = this.nextTokenStart();
  14766. if (this.isUnparsedContextual(next, "from")) {
  14767. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  14768. return true;
  14769. }
  14770. }
  14771. }
  14772. return super.isExportDefaultSpecifier();
  14773. }
  14774. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  14775. var _specifiers;
  14776. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  14777. return true;
  14778. }
  14779. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  14780. }
  14781. checkExport(node) {
  14782. const {
  14783. specifiers
  14784. } = node;
  14785. if (specifiers != null && specifiers.length) {
  14786. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  14787. }
  14788. super.checkExport(node);
  14789. node.specifiers = specifiers;
  14790. }
  14791. parseImport(node) {
  14792. const placeholder = this.parsePlaceholder("Identifier");
  14793. if (!placeholder) return super.parseImport(node);
  14794. node.specifiers = [];
  14795. if (!this.isContextual(98) && !this.match(12)) {
  14796. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  14797. this.semicolon();
  14798. return this.finishNode(node, "ImportDeclaration");
  14799. }
  14800. const specifier = this.startNodeAtNode(placeholder);
  14801. specifier.local = placeholder;
  14802. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  14803. if (this.eat(12)) {
  14804. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  14805. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  14806. }
  14807. this.expectContextual(98);
  14808. node.source = this.parseImportSource();
  14809. this.semicolon();
  14810. return this.finishNode(node, "ImportDeclaration");
  14811. }
  14812. parseImportSource() {
  14813. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  14814. }
  14815. assertNoSpace() {
  14816. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  14817. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  14818. }
  14819. }
  14820. };
  14821. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  14822. parseV8Intrinsic() {
  14823. if (this.match(54)) {
  14824. const v8IntrinsicStartLoc = this.state.startLoc;
  14825. const node = this.startNode();
  14826. this.next();
  14827. if (tokenIsIdentifier(this.state.type)) {
  14828. const name = this.parseIdentifierName();
  14829. const identifier = this.createIdentifier(node, name);
  14830. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  14831. if (this.match(10)) {
  14832. return identifier;
  14833. }
  14834. }
  14835. this.unexpected(v8IntrinsicStartLoc);
  14836. }
  14837. }
  14838. parseExprAtom(refExpressionErrors) {
  14839. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  14840. }
  14841. };
  14842. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  14843. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  14844. function validatePlugins(pluginsMap) {
  14845. if (pluginsMap.has("decorators")) {
  14846. if (pluginsMap.has("decorators-legacy")) {
  14847. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  14848. }
  14849. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  14850. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  14851. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  14852. }
  14853. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  14854. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  14855. throw new Error("'allowCallParenthesized' must be a boolean.");
  14856. }
  14857. }
  14858. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  14859. throw new Error("Cannot combine flow and typescript plugins.");
  14860. }
  14861. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  14862. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  14863. }
  14864. if (pluginsMap.has("pipelineOperator")) {
  14865. var _pluginsMap$get2;
  14866. const proposal = pluginsMap.get("pipelineOperator").proposal;
  14867. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  14868. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  14869. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  14870. }
  14871. if (proposal === "hack") {
  14872. var _pluginsMap$get;
  14873. if (pluginsMap.has("placeholders")) {
  14874. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  14875. }
  14876. if (pluginsMap.has("v8intrinsic")) {
  14877. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  14878. }
  14879. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  14880. if (!TOPIC_TOKENS.includes(topicToken)) {
  14881. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  14882. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  14883. }
  14884. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  14885. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  14886. }
  14887. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  14888. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  14889. }
  14890. }
  14891. if (pluginsMap.has("moduleAttributes")) {
  14892. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  14893. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  14894. }
  14895. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  14896. if (moduleAttributesVersionPluginOption !== "may-2020") {
  14897. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  14898. }
  14899. }
  14900. if (pluginsMap.has("importAssertions")) {
  14901. if (pluginsMap.has("deprecatedImportAssert")) {
  14902. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  14903. }
  14904. }
  14905. if (pluginsMap.has("deprecatedImportAssert")) ;else if (pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  14906. pluginsMap.set("deprecatedImportAssert", {});
  14907. }
  14908. if (pluginsMap.has("recordAndTuple")) {
  14909. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  14910. if (syntaxType != null) {
  14911. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  14912. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  14913. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  14914. }
  14915. }
  14916. }
  14917. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  14918. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  14919. error.missingPlugins = "doExpressions";
  14920. throw error;
  14921. }
  14922. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  14923. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  14924. }
  14925. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  14926. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  14927. }
  14928. }
  14929. const mixinPlugins = {
  14930. estree,
  14931. jsx,
  14932. flow,
  14933. typescript,
  14934. v8intrinsic,
  14935. placeholders
  14936. };
  14937. const mixinPluginNames = Object.keys(mixinPlugins);
  14938. class ExpressionParser extends LValParser {
  14939. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  14940. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  14941. return sawProto;
  14942. }
  14943. const key = prop.key;
  14944. const name = key.type === "Identifier" ? key.name : key.value;
  14945. if (name === "__proto__") {
  14946. if (isRecord) {
  14947. this.raise(Errors.RecordNoProto, key);
  14948. return true;
  14949. }
  14950. if (sawProto) {
  14951. if (refExpressionErrors) {
  14952. if (refExpressionErrors.doubleProtoLoc === null) {
  14953. refExpressionErrors.doubleProtoLoc = key.loc.start;
  14954. }
  14955. } else {
  14956. this.raise(Errors.DuplicateProto, key);
  14957. }
  14958. }
  14959. return true;
  14960. }
  14961. return sawProto;
  14962. }
  14963. shouldExitDescending(expr, potentialArrowAt) {
  14964. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  14965. }
  14966. getExpression() {
  14967. this.enterInitialScopes();
  14968. this.nextToken();
  14969. if (this.match(140)) {
  14970. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  14971. }
  14972. const expr = this.parseExpression();
  14973. if (!this.match(140)) {
  14974. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  14975. unexpected: this.input.codePointAt(this.state.start)
  14976. });
  14977. }
  14978. this.finalizeRemainingComments();
  14979. expr.comments = this.comments;
  14980. expr.errors = this.state.errors;
  14981. if (this.optionFlags & 256) {
  14982. expr.tokens = this.tokens;
  14983. }
  14984. return expr;
  14985. }
  14986. parseExpression(disallowIn, refExpressionErrors) {
  14987. if (disallowIn) {
  14988. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  14989. }
  14990. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  14991. }
  14992. parseExpressionBase(refExpressionErrors) {
  14993. const startLoc = this.state.startLoc;
  14994. const expr = this.parseMaybeAssign(refExpressionErrors);
  14995. if (this.match(12)) {
  14996. const node = this.startNodeAt(startLoc);
  14997. node.expressions = [expr];
  14998. while (this.eat(12)) {
  14999. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  15000. }
  15001. this.toReferencedList(node.expressions);
  15002. return this.finishNode(node, "SequenceExpression");
  15003. }
  15004. return expr;
  15005. }
  15006. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  15007. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  15008. }
  15009. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  15010. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  15011. }
  15012. setOptionalParametersError(refExpressionErrors) {
  15013. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  15014. }
  15015. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  15016. const startLoc = this.state.startLoc;
  15017. const isYield = this.isContextual(108);
  15018. if (isYield) {
  15019. if (this.prodParam.hasYield) {
  15020. this.next();
  15021. let left = this.parseYield(startLoc);
  15022. if (afterLeftParse) {
  15023. left = afterLeftParse.call(this, left, startLoc);
  15024. }
  15025. return left;
  15026. }
  15027. }
  15028. let ownExpressionErrors;
  15029. if (refExpressionErrors) {
  15030. ownExpressionErrors = false;
  15031. } else {
  15032. refExpressionErrors = new ExpressionErrors();
  15033. ownExpressionErrors = true;
  15034. }
  15035. const {
  15036. type
  15037. } = this.state;
  15038. if (type === 10 || tokenIsIdentifier(type)) {
  15039. this.state.potentialArrowAt = this.state.start;
  15040. }
  15041. let left = this.parseMaybeConditional(refExpressionErrors);
  15042. if (afterLeftParse) {
  15043. left = afterLeftParse.call(this, left, startLoc);
  15044. }
  15045. if (tokenIsAssignment(this.state.type)) {
  15046. const node = this.startNodeAt(startLoc);
  15047. const operator = this.state.value;
  15048. node.operator = operator;
  15049. if (this.match(29)) {
  15050. this.toAssignable(left, true);
  15051. node.left = left;
  15052. const startIndex = startLoc.index;
  15053. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  15054. refExpressionErrors.doubleProtoLoc = null;
  15055. }
  15056. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  15057. refExpressionErrors.shorthandAssignLoc = null;
  15058. }
  15059. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  15060. this.checkDestructuringPrivate(refExpressionErrors);
  15061. refExpressionErrors.privateKeyLoc = null;
  15062. }
  15063. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  15064. refExpressionErrors.voidPatternLoc = null;
  15065. }
  15066. } else {
  15067. node.left = left;
  15068. }
  15069. this.next();
  15070. node.right = this.parseMaybeAssign();
  15071. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"), undefined, undefined, undefined, undefined, operator === "||=" || operator === "&&=" || operator === "??=");
  15072. return node;
  15073. } else if (ownExpressionErrors) {
  15074. this.checkExpressionErrors(refExpressionErrors, true);
  15075. }
  15076. if (isYield) {
  15077. const {
  15078. type
  15079. } = this.state;
  15080. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  15081. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  15082. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  15083. return this.parseYield(startLoc);
  15084. }
  15085. }
  15086. return left;
  15087. }
  15088. parseMaybeConditional(refExpressionErrors) {
  15089. const startLoc = this.state.startLoc;
  15090. const potentialArrowAt = this.state.potentialArrowAt;
  15091. const expr = this.parseExprOps(refExpressionErrors);
  15092. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15093. return expr;
  15094. }
  15095. return this.parseConditional(expr, startLoc, refExpressionErrors);
  15096. }
  15097. parseConditional(expr, startLoc, refExpressionErrors) {
  15098. if (this.eat(17)) {
  15099. const node = this.startNodeAt(startLoc);
  15100. node.test = expr;
  15101. node.consequent = this.parseMaybeAssignAllowIn();
  15102. this.expect(14);
  15103. node.alternate = this.parseMaybeAssign();
  15104. return this.finishNode(node, "ConditionalExpression");
  15105. }
  15106. return expr;
  15107. }
  15108. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  15109. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  15110. }
  15111. parseExprOps(refExpressionErrors) {
  15112. const startLoc = this.state.startLoc;
  15113. const potentialArrowAt = this.state.potentialArrowAt;
  15114. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  15115. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15116. return expr;
  15117. }
  15118. return this.parseExprOp(expr, startLoc, -1);
  15119. }
  15120. parseExprOp(left, leftStartLoc, minPrec) {
  15121. if (this.isPrivateName(left)) {
  15122. const value = this.getPrivateNameSV(left);
  15123. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  15124. this.raise(Errors.PrivateInExpectedIn, left, {
  15125. identifierName: value
  15126. });
  15127. }
  15128. this.classScope.usePrivateName(value, left.loc.start);
  15129. }
  15130. const op = this.state.type;
  15131. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  15132. let prec = tokenOperatorPrecedence(op);
  15133. if (prec > minPrec) {
  15134. if (op === 39) {
  15135. this.expectPlugin("pipelineOperator");
  15136. if (this.state.inFSharpPipelineDirectBody) {
  15137. return left;
  15138. }
  15139. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  15140. }
  15141. const node = this.startNodeAt(leftStartLoc);
  15142. node.left = left;
  15143. node.operator = this.state.value;
  15144. const logical = op === 41 || op === 42;
  15145. const coalesce = op === 40;
  15146. if (coalesce) {
  15147. prec = tokenOperatorPrecedence(42);
  15148. }
  15149. this.next();
  15150. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  15151. proposal: "minimal"
  15152. }])) {
  15153. if (this.state.type === 96 && this.prodParam.hasAwait) {
  15154. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  15155. }
  15156. }
  15157. node.right = this.parseExprOpRightExpr(op, prec);
  15158. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  15159. const nextOp = this.state.type;
  15160. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  15161. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  15162. }
  15163. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  15164. }
  15165. }
  15166. return left;
  15167. }
  15168. parseExprOpRightExpr(op, prec) {
  15169. const startLoc = this.state.startLoc;
  15170. switch (op) {
  15171. case 39:
  15172. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  15173. case "hack":
  15174. return this.withTopicBindingContext(() => {
  15175. return this.parseHackPipeBody();
  15176. });
  15177. case "fsharp":
  15178. return this.withSoloAwaitPermittingContext(() => {
  15179. return this.parseFSharpPipelineBody(prec);
  15180. });
  15181. }
  15182. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  15183. return this.withTopicBindingContext(() => {
  15184. if (this.prodParam.hasYield && this.isContextual(108)) {
  15185. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  15186. }
  15187. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  15188. });
  15189. }
  15190. default:
  15191. return this.parseExprOpBaseRightExpr(op, prec);
  15192. }
  15193. }
  15194. parseExprOpBaseRightExpr(op, prec) {
  15195. const startLoc = this.state.startLoc;
  15196. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  15197. }
  15198. parseHackPipeBody() {
  15199. var _body$extra;
  15200. const {
  15201. startLoc
  15202. } = this.state;
  15203. const body = this.parseMaybeAssign();
  15204. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  15205. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  15206. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  15207. type: body.type
  15208. });
  15209. }
  15210. if (!this.topicReferenceWasUsedInCurrentContext()) {
  15211. this.raise(Errors.PipeTopicUnused, startLoc);
  15212. }
  15213. return body;
  15214. }
  15215. checkExponentialAfterUnary(node) {
  15216. if (this.match(57)) {
  15217. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  15218. }
  15219. }
  15220. parseMaybeUnary(refExpressionErrors, sawUnary) {
  15221. const startLoc = this.state.startLoc;
  15222. const isAwait = this.isContextual(96);
  15223. if (isAwait && this.recordAwaitIfAllowed()) {
  15224. this.next();
  15225. const expr = this.parseAwait(startLoc);
  15226. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  15227. return expr;
  15228. }
  15229. const update = this.match(34);
  15230. const node = this.startNode();
  15231. if (tokenIsPrefix(this.state.type)) {
  15232. node.operator = this.state.value;
  15233. node.prefix = true;
  15234. if (this.match(72)) {
  15235. this.expectPlugin("throwExpressions");
  15236. }
  15237. const isDelete = this.match(89);
  15238. this.next();
  15239. node.argument = this.parseMaybeUnary(null, true);
  15240. this.checkExpressionErrors(refExpressionErrors, true);
  15241. if (this.state.strict && isDelete) {
  15242. const arg = node.argument;
  15243. if (arg.type === "Identifier") {
  15244. this.raise(Errors.StrictDelete, node);
  15245. } else if (this.hasPropertyAsPrivateName(arg)) {
  15246. this.raise(Errors.DeletePrivateField, node);
  15247. }
  15248. }
  15249. if (!update) {
  15250. if (!sawUnary) {
  15251. this.checkExponentialAfterUnary(node);
  15252. }
  15253. return this.finishNode(node, "UnaryExpression");
  15254. }
  15255. }
  15256. const expr = this.parseUpdate(node, update, refExpressionErrors);
  15257. if (isAwait) {
  15258. const {
  15259. type
  15260. } = this.state;
  15261. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  15262. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  15263. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  15264. return this.parseAwait(startLoc);
  15265. }
  15266. }
  15267. return expr;
  15268. }
  15269. parseUpdate(node, update, refExpressionErrors) {
  15270. if (update) {
  15271. const updateExpressionNode = node;
  15272. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  15273. return node;
  15274. }
  15275. const startLoc = this.state.startLoc;
  15276. let expr = this.parseExprSubscripts(refExpressionErrors);
  15277. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  15278. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  15279. const node = this.startNodeAt(startLoc);
  15280. node.operator = this.state.value;
  15281. node.prefix = false;
  15282. node.argument = expr;
  15283. this.next();
  15284. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  15285. }
  15286. return expr;
  15287. }
  15288. parseExprSubscripts(refExpressionErrors) {
  15289. const startLoc = this.state.startLoc;
  15290. const potentialArrowAt = this.state.potentialArrowAt;
  15291. const expr = this.parseExprAtom(refExpressionErrors);
  15292. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  15293. return expr;
  15294. }
  15295. return this.parseSubscripts(expr, startLoc);
  15296. }
  15297. parseSubscripts(base, startLoc, noCalls) {
  15298. const state = {
  15299. optionalChainMember: false,
  15300. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  15301. stop: false
  15302. };
  15303. do {
  15304. base = this.parseSubscript(base, startLoc, noCalls, state);
  15305. state.maybeAsyncArrow = false;
  15306. } while (!state.stop);
  15307. return base;
  15308. }
  15309. parseSubscript(base, startLoc, noCalls, state) {
  15310. const {
  15311. type
  15312. } = this.state;
  15313. if (!noCalls && type === 15) {
  15314. return this.parseBind(base, startLoc, noCalls, state);
  15315. } else if (tokenIsTemplate(type)) {
  15316. return this.parseTaggedTemplateExpression(base, startLoc, state);
  15317. }
  15318. let optional = false;
  15319. if (type === 18) {
  15320. if (noCalls) {
  15321. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  15322. if (this.lookaheadCharCode() === 40) {
  15323. return this.stopParseSubscript(base, state);
  15324. }
  15325. }
  15326. state.optionalChainMember = optional = true;
  15327. this.next();
  15328. }
  15329. if (!noCalls && this.match(10)) {
  15330. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  15331. } else {
  15332. const computed = this.eat(0);
  15333. if (computed || optional || this.eat(16)) {
  15334. return this.parseMember(base, startLoc, state, computed, optional);
  15335. } else {
  15336. return this.stopParseSubscript(base, state);
  15337. }
  15338. }
  15339. }
  15340. stopParseSubscript(base, state) {
  15341. state.stop = true;
  15342. return base;
  15343. }
  15344. parseMember(base, startLoc, state, computed, optional) {
  15345. const node = this.startNodeAt(startLoc);
  15346. node.object = base;
  15347. node.computed = computed;
  15348. if (computed) {
  15349. node.property = this.parseExpression();
  15350. this.expect(3);
  15351. } else if (this.match(139)) {
  15352. if (base.type === "Super") {
  15353. this.raise(Errors.SuperPrivateField, startLoc);
  15354. }
  15355. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  15356. node.property = this.parsePrivateName();
  15357. } else {
  15358. node.property = this.parseIdentifier(true);
  15359. }
  15360. if (state.optionalChainMember) {
  15361. node.optional = optional;
  15362. return this.finishNode(node, "OptionalMemberExpression");
  15363. } else {
  15364. return this.finishNode(node, "MemberExpression");
  15365. }
  15366. }
  15367. parseBind(base, startLoc, noCalls, state) {
  15368. const node = this.startNodeAt(startLoc);
  15369. node.object = base;
  15370. this.next();
  15371. node.callee = this.parseNoCallExpr();
  15372. state.stop = true;
  15373. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  15374. }
  15375. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  15376. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15377. let refExpressionErrors = null;
  15378. this.state.maybeInArrowParameters = true;
  15379. this.next();
  15380. const node = this.startNodeAt(startLoc);
  15381. node.callee = base;
  15382. const {
  15383. maybeAsyncArrow,
  15384. optionalChainMember
  15385. } = state;
  15386. if (maybeAsyncArrow) {
  15387. this.expressionScope.enter(newAsyncArrowScope());
  15388. refExpressionErrors = new ExpressionErrors();
  15389. }
  15390. if (optionalChainMember) {
  15391. node.optional = optional;
  15392. }
  15393. if (optional) {
  15394. node.arguments = this.parseCallExpressionArguments();
  15395. } else {
  15396. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  15397. }
  15398. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  15399. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  15400. state.stop = true;
  15401. this.checkDestructuringPrivate(refExpressionErrors);
  15402. this.expressionScope.validateAsPattern();
  15403. this.expressionScope.exit();
  15404. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  15405. } else {
  15406. if (maybeAsyncArrow) {
  15407. this.checkExpressionErrors(refExpressionErrors, true);
  15408. this.expressionScope.exit();
  15409. }
  15410. this.toReferencedArguments(finishedNode);
  15411. }
  15412. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15413. return finishedNode;
  15414. }
  15415. toReferencedArguments(node, isParenthesizedExpr) {
  15416. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  15417. }
  15418. parseTaggedTemplateExpression(base, startLoc, state) {
  15419. const node = this.startNodeAt(startLoc);
  15420. node.tag = base;
  15421. node.quasi = this.parseTemplate(true);
  15422. if (state.optionalChainMember) {
  15423. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  15424. }
  15425. return this.finishNode(node, "TaggedTemplateExpression");
  15426. }
  15427. atPossibleAsyncArrow(base) {
  15428. 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;
  15429. }
  15430. finishCallExpression(node, optional) {
  15431. if (node.callee.type === "Import") {
  15432. if (node.arguments.length === 0 || node.arguments.length > 2) {
  15433. this.raise(Errors.ImportCallArity, node);
  15434. } else {
  15435. for (const arg of node.arguments) {
  15436. if (arg.type === "SpreadElement") {
  15437. this.raise(Errors.ImportCallSpreadArgument, arg);
  15438. }
  15439. }
  15440. }
  15441. }
  15442. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  15443. }
  15444. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  15445. const elts = [];
  15446. let first = true;
  15447. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  15448. this.state.inFSharpPipelineDirectBody = false;
  15449. while (!this.eat(11)) {
  15450. if (first) {
  15451. first = false;
  15452. } else {
  15453. this.expect(12);
  15454. if (this.match(11)) {
  15455. if (nodeForExtra) {
  15456. this.addTrailingCommaExtraToNode(nodeForExtra);
  15457. }
  15458. this.next();
  15459. break;
  15460. }
  15461. }
  15462. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  15463. }
  15464. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  15465. return elts;
  15466. }
  15467. shouldParseAsyncArrow() {
  15468. return this.match(19) && !this.canInsertSemicolon();
  15469. }
  15470. parseAsyncArrowFromCallExpression(node, call) {
  15471. var _call$extra;
  15472. this.resetPreviousNodeTrailingComments(call);
  15473. this.expect(19);
  15474. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  15475. if (call.innerComments) {
  15476. setInnerComments(node, call.innerComments);
  15477. }
  15478. if (call.callee.trailingComments) {
  15479. setInnerComments(node, call.callee.trailingComments);
  15480. }
  15481. return node;
  15482. }
  15483. parseNoCallExpr() {
  15484. const startLoc = this.state.startLoc;
  15485. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  15486. }
  15487. parseExprAtom(refExpressionErrors) {
  15488. let node;
  15489. let decorators = null;
  15490. const {
  15491. type
  15492. } = this.state;
  15493. switch (type) {
  15494. case 79:
  15495. return this.parseSuper();
  15496. case 83:
  15497. node = this.startNode();
  15498. this.next();
  15499. if (this.match(16)) {
  15500. return this.parseImportMetaPropertyOrPhaseCall(node);
  15501. }
  15502. if (this.match(10)) {
  15503. if (this.optionFlags & 512) {
  15504. return this.parseImportCall(node);
  15505. } else {
  15506. return this.finishNode(node, "Import");
  15507. }
  15508. } else {
  15509. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  15510. return this.finishNode(node, "Import");
  15511. }
  15512. case 78:
  15513. node = this.startNode();
  15514. this.next();
  15515. return this.finishNode(node, "ThisExpression");
  15516. case 90:
  15517. {
  15518. return this.parseDo(this.startNode(), false);
  15519. }
  15520. case 56:
  15521. case 31:
  15522. {
  15523. this.readRegexp();
  15524. return this.parseRegExpLiteral(this.state.value);
  15525. }
  15526. case 135:
  15527. return this.parseNumericLiteral(this.state.value);
  15528. case 136:
  15529. return this.parseBigIntLiteral(this.state.value);
  15530. case 134:
  15531. return this.parseStringLiteral(this.state.value);
  15532. case 84:
  15533. return this.parseNullLiteral();
  15534. case 85:
  15535. return this.parseBooleanLiteral(true);
  15536. case 86:
  15537. return this.parseBooleanLiteral(false);
  15538. case 10:
  15539. {
  15540. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  15541. return this.parseParenAndDistinguishExpression(canBeArrow);
  15542. }
  15543. case 0:
  15544. {
  15545. return this.parseArrayLike(3, false, refExpressionErrors);
  15546. }
  15547. case 5:
  15548. {
  15549. return this.parseObjectLike(8, false, false, refExpressionErrors);
  15550. }
  15551. case 68:
  15552. return this.parseFunctionOrFunctionSent();
  15553. case 26:
  15554. decorators = this.parseDecorators();
  15555. case 80:
  15556. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  15557. case 77:
  15558. return this.parseNewOrNewTarget();
  15559. case 25:
  15560. case 24:
  15561. return this.parseTemplate(false);
  15562. case 15:
  15563. {
  15564. node = this.startNode();
  15565. this.next();
  15566. node.object = null;
  15567. const callee = node.callee = this.parseNoCallExpr();
  15568. if (callee.type === "MemberExpression") {
  15569. return this.finishNode(node, "BindExpression");
  15570. } else {
  15571. throw this.raise(Errors.UnsupportedBind, callee);
  15572. }
  15573. }
  15574. case 139:
  15575. {
  15576. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  15577. identifierName: this.state.value
  15578. });
  15579. return this.parsePrivateName();
  15580. }
  15581. case 33:
  15582. {
  15583. return this.parseTopicReferenceThenEqualsSign(54, "%");
  15584. }
  15585. case 32:
  15586. {
  15587. return this.parseTopicReferenceThenEqualsSign(44, "^");
  15588. }
  15589. case 37:
  15590. case 38:
  15591. {
  15592. return this.parseTopicReference("hack");
  15593. }
  15594. case 44:
  15595. case 54:
  15596. case 27:
  15597. {
  15598. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  15599. if (pipeProposal) {
  15600. return this.parseTopicReference(pipeProposal);
  15601. }
  15602. throw this.unexpected();
  15603. }
  15604. case 47:
  15605. {
  15606. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  15607. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  15608. throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
  15609. }
  15610. throw this.unexpected();
  15611. }
  15612. default:
  15613. if (type === 137) {
  15614. return this.parseDecimalLiteral(this.state.value);
  15615. } else if (type === 2 || type === 1) {
  15616. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, true);
  15617. } else if (type === 6 || type === 7) {
  15618. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  15619. }
  15620. if (tokenIsIdentifier(type)) {
  15621. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  15622. return this.parseModuleExpression();
  15623. }
  15624. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  15625. const containsEsc = this.state.containsEsc;
  15626. const id = this.parseIdentifier();
  15627. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  15628. const {
  15629. type
  15630. } = this.state;
  15631. if (type === 68) {
  15632. this.resetPreviousNodeTrailingComments(id);
  15633. this.next();
  15634. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  15635. } else if (tokenIsIdentifier(type)) {
  15636. if (canBeArrow && this.lookaheadCharCode() === 61) {
  15637. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  15638. } else {
  15639. return id;
  15640. }
  15641. } else if (type === 90) {
  15642. this.resetPreviousNodeTrailingComments(id);
  15643. return this.parseDo(this.startNodeAtNode(id), true);
  15644. }
  15645. }
  15646. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  15647. this.next();
  15648. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  15649. }
  15650. return id;
  15651. } else {
  15652. throw this.unexpected();
  15653. }
  15654. }
  15655. }
  15656. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  15657. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  15658. if (pipeProposal) {
  15659. this.state.type = topicTokenType;
  15660. this.state.value = topicTokenValue;
  15661. this.state.pos--;
  15662. this.state.end--;
  15663. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  15664. return this.parseTopicReference(pipeProposal);
  15665. }
  15666. throw this.unexpected();
  15667. }
  15668. parseTopicReference(pipeProposal) {
  15669. const node = this.startNode();
  15670. const startLoc = this.state.startLoc;
  15671. const tokenType = this.state.type;
  15672. this.next();
  15673. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  15674. }
  15675. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  15676. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  15677. if (pipeProposal === "hack") {
  15678. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  15679. this.raise(Errors.PipeTopicUnbound, startLoc);
  15680. }
  15681. this.registerTopicReference();
  15682. return this.finishNode(node, "TopicReference");
  15683. } else {
  15684. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  15685. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  15686. }
  15687. this.registerTopicReference();
  15688. return this.finishNode(node, "PipelinePrimaryTopicReference");
  15689. }
  15690. } else {
  15691. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  15692. token: tokenLabelName(tokenType)
  15693. });
  15694. }
  15695. }
  15696. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  15697. switch (pipeProposal) {
  15698. case "hack":
  15699. {
  15700. return this.hasPlugin(["pipelineOperator", {
  15701. topicToken: tokenLabelName(tokenType)
  15702. }]);
  15703. }
  15704. case "smart":
  15705. return tokenType === 27;
  15706. default:
  15707. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  15708. }
  15709. }
  15710. parseAsyncArrowUnaryFunction(node) {
  15711. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  15712. const params = [this.parseIdentifier()];
  15713. this.prodParam.exit();
  15714. if (this.hasPrecedingLineBreak()) {
  15715. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  15716. }
  15717. this.expect(19);
  15718. return this.parseArrowExpression(node, params, true);
  15719. }
  15720. parseDo(node, isAsync) {
  15721. this.expectPlugin("doExpressions");
  15722. if (isAsync) {
  15723. this.expectPlugin("asyncDoExpressions");
  15724. }
  15725. node.async = isAsync;
  15726. this.next();
  15727. const oldLabels = this.state.labels;
  15728. this.state.labels = [];
  15729. if (isAsync) {
  15730. this.prodParam.enter(2);
  15731. node.body = this.parseBlock();
  15732. this.prodParam.exit();
  15733. } else {
  15734. node.body = this.parseBlock();
  15735. }
  15736. this.state.labels = oldLabels;
  15737. return this.finishNode(node, "DoExpression");
  15738. }
  15739. parseSuper() {
  15740. const node = this.startNode();
  15741. this.next();
  15742. if (this.match(10) && !this.scope.allowDirectSuper) {
  15743. if (!(this.optionFlags & 16)) {
  15744. this.raise(Errors.SuperNotAllowed, node);
  15745. }
  15746. } else if (!this.scope.allowSuper) {
  15747. if (!(this.optionFlags & 16)) {
  15748. this.raise(Errors.UnexpectedSuper, node);
  15749. }
  15750. }
  15751. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  15752. this.raise(Errors.UnsupportedSuper, node);
  15753. }
  15754. return this.finishNode(node, "Super");
  15755. }
  15756. parsePrivateName() {
  15757. const node = this.startNode();
  15758. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  15759. const name = this.state.value;
  15760. this.next();
  15761. node.id = this.createIdentifier(id, name);
  15762. return this.finishNode(node, "PrivateName");
  15763. }
  15764. parseFunctionOrFunctionSent() {
  15765. const node = this.startNode();
  15766. this.next();
  15767. if (this.prodParam.hasYield && this.match(16)) {
  15768. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  15769. this.next();
  15770. if (this.match(103)) {
  15771. this.expectPlugin("functionSent");
  15772. } else if (!this.hasPlugin("functionSent")) {
  15773. this.unexpected();
  15774. }
  15775. return this.parseMetaProperty(node, meta, "sent");
  15776. }
  15777. return this.parseFunction(node);
  15778. }
  15779. parseMetaProperty(node, meta, propertyName) {
  15780. node.meta = meta;
  15781. const containsEsc = this.state.containsEsc;
  15782. node.property = this.parseIdentifier(true);
  15783. if (node.property.name !== propertyName || containsEsc) {
  15784. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  15785. target: meta.name,
  15786. onlyValidPropertyName: propertyName
  15787. });
  15788. }
  15789. return this.finishNode(node, "MetaProperty");
  15790. }
  15791. parseImportMetaPropertyOrPhaseCall(node) {
  15792. this.next();
  15793. if (this.isContextual(105) || this.isContextual(97)) {
  15794. const isSource = this.isContextual(105);
  15795. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  15796. this.next();
  15797. node.phase = isSource ? "source" : "defer";
  15798. return this.parseImportCall(node);
  15799. } else {
  15800. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  15801. if (this.isContextual(101)) {
  15802. if (!this.inModule) {
  15803. this.raise(Errors.ImportMetaOutsideModule, id);
  15804. }
  15805. this.sawUnambiguousESM = true;
  15806. }
  15807. return this.parseMetaProperty(node, id, "meta");
  15808. }
  15809. }
  15810. parseLiteralAtNode(value, type, node) {
  15811. this.addExtra(node, "rawValue", value);
  15812. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  15813. node.value = value;
  15814. this.next();
  15815. return this.finishNode(node, type);
  15816. }
  15817. parseLiteral(value, type) {
  15818. const node = this.startNode();
  15819. return this.parseLiteralAtNode(value, type, node);
  15820. }
  15821. parseStringLiteral(value) {
  15822. return this.parseLiteral(value, "StringLiteral");
  15823. }
  15824. parseNumericLiteral(value) {
  15825. return this.parseLiteral(value, "NumericLiteral");
  15826. }
  15827. parseBigIntLiteral(value) {
  15828. return this.parseLiteral(value, "BigIntLiteral");
  15829. }
  15830. parseDecimalLiteral(value) {
  15831. return this.parseLiteral(value, "DecimalLiteral");
  15832. }
  15833. parseRegExpLiteral(value) {
  15834. const node = this.startNode();
  15835. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  15836. node.pattern = value.pattern;
  15837. node.flags = value.flags;
  15838. this.next();
  15839. return this.finishNode(node, "RegExpLiteral");
  15840. }
  15841. parseBooleanLiteral(value) {
  15842. const node = this.startNode();
  15843. node.value = value;
  15844. this.next();
  15845. return this.finishNode(node, "BooleanLiteral");
  15846. }
  15847. parseNullLiteral() {
  15848. const node = this.startNode();
  15849. this.next();
  15850. return this.finishNode(node, "NullLiteral");
  15851. }
  15852. parseParenAndDistinguishExpression(canBeArrow) {
  15853. const startLoc = this.state.startLoc;
  15854. let val;
  15855. this.next();
  15856. this.expressionScope.enter(newArrowHeadScope());
  15857. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15858. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  15859. this.state.maybeInArrowParameters = true;
  15860. this.state.inFSharpPipelineDirectBody = false;
  15861. const innerStartLoc = this.state.startLoc;
  15862. const exprList = [];
  15863. const refExpressionErrors = new ExpressionErrors();
  15864. let first = true;
  15865. let spreadStartLoc;
  15866. let optionalCommaStartLoc;
  15867. while (!this.match(11)) {
  15868. if (first) {
  15869. first = false;
  15870. } else {
  15871. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  15872. if (this.match(11)) {
  15873. optionalCommaStartLoc = this.state.startLoc;
  15874. break;
  15875. }
  15876. }
  15877. if (this.match(21)) {
  15878. const spreadNodeStartLoc = this.state.startLoc;
  15879. spreadStartLoc = this.state.startLoc;
  15880. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  15881. if (!this.checkCommaAfterRest(41)) {
  15882. break;
  15883. }
  15884. } else {
  15885. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  15886. }
  15887. }
  15888. const innerEndLoc = this.state.lastTokEndLoc;
  15889. this.expect(11);
  15890. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15891. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  15892. let arrowNode = this.startNodeAt(startLoc);
  15893. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  15894. this.checkDestructuringPrivate(refExpressionErrors);
  15895. this.expressionScope.validateAsPattern();
  15896. this.expressionScope.exit();
  15897. this.parseArrowExpression(arrowNode, exprList, false);
  15898. return arrowNode;
  15899. }
  15900. this.expressionScope.exit();
  15901. if (!exprList.length) {
  15902. this.unexpected(this.state.lastTokStartLoc);
  15903. }
  15904. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  15905. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  15906. this.checkExpressionErrors(refExpressionErrors, true);
  15907. this.toReferencedListDeep(exprList, true);
  15908. if (exprList.length > 1) {
  15909. val = this.startNodeAt(innerStartLoc);
  15910. val.expressions = exprList;
  15911. this.finishNode(val, "SequenceExpression");
  15912. this.resetEndLocation(val, innerEndLoc);
  15913. } else {
  15914. val = exprList[0];
  15915. }
  15916. return this.wrapParenthesis(startLoc, val);
  15917. }
  15918. wrapParenthesis(startLoc, expression) {
  15919. if (!(this.optionFlags & 1024)) {
  15920. this.addExtra(expression, "parenthesized", true);
  15921. this.addExtra(expression, "parenStart", startLoc.index);
  15922. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  15923. return expression;
  15924. }
  15925. const parenExpression = this.startNodeAt(startLoc);
  15926. parenExpression.expression = expression;
  15927. return this.finishNode(parenExpression, "ParenthesizedExpression");
  15928. }
  15929. shouldParseArrow(params) {
  15930. return !this.canInsertSemicolon();
  15931. }
  15932. parseArrow(node) {
  15933. if (this.eat(19)) {
  15934. return node;
  15935. }
  15936. }
  15937. parseParenItem(node, startLoc) {
  15938. return node;
  15939. }
  15940. parseNewOrNewTarget() {
  15941. const node = this.startNode();
  15942. this.next();
  15943. if (this.match(16)) {
  15944. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  15945. this.next();
  15946. const metaProp = this.parseMetaProperty(node, meta, "target");
  15947. if (!this.scope.allowNewTarget) {
  15948. this.raise(Errors.UnexpectedNewTarget, metaProp);
  15949. }
  15950. return metaProp;
  15951. }
  15952. return this.parseNew(node);
  15953. }
  15954. parseNew(node) {
  15955. this.parseNewCallee(node);
  15956. if (this.eat(10)) {
  15957. const args = this.parseExprList(11);
  15958. this.toReferencedList(args);
  15959. node.arguments = args;
  15960. } else {
  15961. node.arguments = [];
  15962. }
  15963. return this.finishNode(node, "NewExpression");
  15964. }
  15965. parseNewCallee(node) {
  15966. const isImport = this.match(83);
  15967. const callee = this.parseNoCallExpr();
  15968. node.callee = callee;
  15969. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  15970. this.raise(Errors.ImportCallNotNewExpression, callee);
  15971. }
  15972. }
  15973. parseTemplateElement(isTagged) {
  15974. const {
  15975. start,
  15976. startLoc,
  15977. end,
  15978. value
  15979. } = this.state;
  15980. const elemStart = start + 1;
  15981. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  15982. if (value === null) {
  15983. if (!isTagged) {
  15984. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  15985. }
  15986. }
  15987. const isTail = this.match(24);
  15988. const endOffset = isTail ? -1 : -2;
  15989. const elemEnd = end + endOffset;
  15990. elem.value = {
  15991. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  15992. cooked: value === null ? null : value.slice(1, endOffset)
  15993. };
  15994. elem.tail = isTail;
  15995. this.next();
  15996. const finishedNode = this.finishNode(elem, "TemplateElement");
  15997. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  15998. return finishedNode;
  15999. }
  16000. parseTemplate(isTagged) {
  16001. const node = this.startNode();
  16002. let curElt = this.parseTemplateElement(isTagged);
  16003. const quasis = [curElt];
  16004. const substitutions = [];
  16005. while (!curElt.tail) {
  16006. substitutions.push(this.parseTemplateSubstitution());
  16007. this.readTemplateContinuation();
  16008. quasis.push(curElt = this.parseTemplateElement(isTagged));
  16009. }
  16010. node.expressions = substitutions;
  16011. node.quasis = quasis;
  16012. return this.finishNode(node, "TemplateLiteral");
  16013. }
  16014. parseTemplateSubstitution() {
  16015. return this.parseExpression();
  16016. }
  16017. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  16018. if (isRecord) {
  16019. this.expectPlugin("recordAndTuple");
  16020. }
  16021. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16022. this.state.inFSharpPipelineDirectBody = false;
  16023. let sawProto = false;
  16024. let first = true;
  16025. const node = this.startNode();
  16026. node.properties = [];
  16027. this.next();
  16028. while (!this.match(close)) {
  16029. if (first) {
  16030. first = false;
  16031. } else {
  16032. this.expect(12);
  16033. if (this.match(close)) {
  16034. this.addTrailingCommaExtraToNode(node);
  16035. break;
  16036. }
  16037. }
  16038. let prop;
  16039. if (isPattern) {
  16040. prop = this.parseBindingProperty();
  16041. } else {
  16042. prop = this.parsePropertyDefinition(refExpressionErrors);
  16043. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  16044. }
  16045. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  16046. this.raise(Errors.InvalidRecordProperty, prop);
  16047. }
  16048. if (prop.shorthand) {
  16049. this.addExtra(prop, "shorthand", true);
  16050. }
  16051. node.properties.push(prop);
  16052. }
  16053. this.next();
  16054. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16055. let type = "ObjectExpression";
  16056. if (isPattern) {
  16057. type = "ObjectPattern";
  16058. } else if (isRecord) {
  16059. type = "RecordExpression";
  16060. }
  16061. return this.finishNode(node, type);
  16062. }
  16063. addTrailingCommaExtraToNode(node) {
  16064. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  16065. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  16066. }
  16067. maybeAsyncOrAccessorProp(prop) {
  16068. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  16069. }
  16070. parsePropertyDefinition(refExpressionErrors) {
  16071. let decorators = [];
  16072. if (this.match(26)) {
  16073. if (this.hasPlugin("decorators")) {
  16074. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  16075. }
  16076. while (this.match(26)) {
  16077. decorators.push(this.parseDecorator());
  16078. }
  16079. }
  16080. const prop = this.startNode();
  16081. let isAsync = false;
  16082. let isAccessor = false;
  16083. let startLoc;
  16084. if (this.match(21)) {
  16085. if (decorators.length) this.unexpected();
  16086. return this.parseSpread();
  16087. }
  16088. if (decorators.length) {
  16089. prop.decorators = decorators;
  16090. decorators = [];
  16091. }
  16092. prop.method = false;
  16093. if (refExpressionErrors) {
  16094. startLoc = this.state.startLoc;
  16095. }
  16096. let isGenerator = this.eat(55);
  16097. this.parsePropertyNamePrefixOperator(prop);
  16098. const containsEsc = this.state.containsEsc;
  16099. this.parsePropertyName(prop, refExpressionErrors);
  16100. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  16101. const {
  16102. key
  16103. } = prop;
  16104. const keyName = key.name;
  16105. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  16106. isAsync = true;
  16107. this.resetPreviousNodeTrailingComments(key);
  16108. isGenerator = this.eat(55);
  16109. this.parsePropertyName(prop);
  16110. }
  16111. if (keyName === "get" || keyName === "set") {
  16112. isAccessor = true;
  16113. this.resetPreviousNodeTrailingComments(key);
  16114. prop.kind = keyName;
  16115. if (this.match(55)) {
  16116. isGenerator = true;
  16117. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  16118. kind: keyName
  16119. });
  16120. this.next();
  16121. }
  16122. this.parsePropertyName(prop);
  16123. }
  16124. }
  16125. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  16126. }
  16127. getGetterSetterExpectedParamCount(method) {
  16128. return method.kind === "get" ? 0 : 1;
  16129. }
  16130. getObjectOrClassMethodParams(method) {
  16131. return method.params;
  16132. }
  16133. checkGetterSetterParams(method) {
  16134. var _params;
  16135. const paramCount = this.getGetterSetterExpectedParamCount(method);
  16136. const params = this.getObjectOrClassMethodParams(method);
  16137. if (params.length !== paramCount) {
  16138. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  16139. }
  16140. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  16141. this.raise(Errors.BadSetterRestParameter, method);
  16142. }
  16143. }
  16144. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  16145. if (isAccessor) {
  16146. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  16147. this.checkGetterSetterParams(finishedProp);
  16148. return finishedProp;
  16149. }
  16150. if (isAsync || isGenerator || this.match(10)) {
  16151. if (isPattern) this.unexpected();
  16152. prop.kind = "method";
  16153. prop.method = true;
  16154. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  16155. }
  16156. }
  16157. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  16158. prop.shorthand = false;
  16159. if (this.eat(14)) {
  16160. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  16161. return this.finishObjectProperty(prop);
  16162. }
  16163. if (!prop.computed && prop.key.type === "Identifier") {
  16164. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  16165. if (isPattern) {
  16166. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  16167. } else if (this.match(29)) {
  16168. const shorthandAssignLoc = this.state.startLoc;
  16169. if (refExpressionErrors != null) {
  16170. if (refExpressionErrors.shorthandAssignLoc === null) {
  16171. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  16172. }
  16173. } else {
  16174. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  16175. }
  16176. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  16177. } else {
  16178. prop.value = this.cloneIdentifier(prop.key);
  16179. }
  16180. prop.shorthand = true;
  16181. return this.finishObjectProperty(prop);
  16182. }
  16183. }
  16184. finishObjectProperty(node) {
  16185. return this.finishNode(node, "ObjectProperty");
  16186. }
  16187. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  16188. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  16189. if (!node) this.unexpected();
  16190. return node;
  16191. }
  16192. parsePropertyName(prop, refExpressionErrors) {
  16193. if (this.eat(0)) {
  16194. prop.computed = true;
  16195. prop.key = this.parseMaybeAssignAllowIn();
  16196. this.expect(3);
  16197. } else {
  16198. const {
  16199. type,
  16200. value
  16201. } = this.state;
  16202. let key;
  16203. if (tokenIsKeywordOrIdentifier(type)) {
  16204. key = this.parseIdentifier(true);
  16205. } else {
  16206. switch (type) {
  16207. case 135:
  16208. key = this.parseNumericLiteral(value);
  16209. break;
  16210. case 134:
  16211. key = this.parseStringLiteral(value);
  16212. break;
  16213. case 136:
  16214. key = this.parseBigIntLiteral(value);
  16215. break;
  16216. case 139:
  16217. {
  16218. const privateKeyLoc = this.state.startLoc;
  16219. if (refExpressionErrors != null) {
  16220. if (refExpressionErrors.privateKeyLoc === null) {
  16221. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  16222. }
  16223. } else {
  16224. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  16225. }
  16226. key = this.parsePrivateName();
  16227. break;
  16228. }
  16229. default:
  16230. if (type === 137) {
  16231. key = this.parseDecimalLiteral(value);
  16232. break;
  16233. }
  16234. this.unexpected();
  16235. }
  16236. }
  16237. prop.key = key;
  16238. if (type !== 139) {
  16239. prop.computed = false;
  16240. }
  16241. }
  16242. }
  16243. initFunction(node, isAsync) {
  16244. node.id = null;
  16245. node.generator = false;
  16246. node.async = isAsync;
  16247. }
  16248. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  16249. this.initFunction(node, isAsync);
  16250. node.generator = isGenerator;
  16251. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  16252. this.prodParam.enter(functionFlags(isAsync, node.generator));
  16253. this.parseFunctionParams(node, isConstructor);
  16254. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  16255. this.prodParam.exit();
  16256. this.scope.exit();
  16257. return finishedNode;
  16258. }
  16259. parseArrayLike(close, isTuple, refExpressionErrors) {
  16260. if (isTuple) {
  16261. this.expectPlugin("recordAndTuple");
  16262. }
  16263. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16264. this.state.inFSharpPipelineDirectBody = false;
  16265. const node = this.startNode();
  16266. this.next();
  16267. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  16268. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16269. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  16270. }
  16271. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  16272. this.scope.enter(514 | 4);
  16273. let flags = functionFlags(isAsync, false);
  16274. if (!this.match(5) && this.prodParam.hasIn) {
  16275. flags |= 8;
  16276. }
  16277. this.prodParam.enter(flags);
  16278. this.initFunction(node, isAsync);
  16279. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  16280. if (params) {
  16281. this.state.maybeInArrowParameters = true;
  16282. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  16283. }
  16284. this.state.maybeInArrowParameters = false;
  16285. this.parseFunctionBody(node, true);
  16286. this.prodParam.exit();
  16287. this.scope.exit();
  16288. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  16289. return this.finishNode(node, "ArrowFunctionExpression");
  16290. }
  16291. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  16292. this.toAssignableList(params, trailingCommaLoc, false);
  16293. node.params = params;
  16294. }
  16295. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  16296. this.parseFunctionBody(node, false, isMethod);
  16297. return this.finishNode(node, type);
  16298. }
  16299. parseFunctionBody(node, allowExpression, isMethod = false) {
  16300. const isExpression = allowExpression && !this.match(5);
  16301. this.expressionScope.enter(newExpressionScope());
  16302. if (isExpression) {
  16303. node.body = this.parseMaybeAssign();
  16304. this.checkParams(node, false, allowExpression, false);
  16305. } else {
  16306. const oldStrict = this.state.strict;
  16307. const oldLabels = this.state.labels;
  16308. this.state.labels = [];
  16309. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  16310. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  16311. const nonSimple = !this.isSimpleParamList(node.params);
  16312. if (hasStrictModeDirective && nonSimple) {
  16313. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  16314. }
  16315. const strictModeChanged = !oldStrict && this.state.strict;
  16316. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  16317. if (this.state.strict && node.id) {
  16318. this.checkIdentifier(node.id, 65, strictModeChanged);
  16319. }
  16320. });
  16321. this.prodParam.exit();
  16322. this.state.labels = oldLabels;
  16323. }
  16324. this.expressionScope.exit();
  16325. }
  16326. isSimpleParameter(node) {
  16327. return node.type === "Identifier";
  16328. }
  16329. isSimpleParamList(params) {
  16330. for (let i = 0, len = params.length; i < len; i++) {
  16331. if (!this.isSimpleParameter(params[i])) return false;
  16332. }
  16333. return true;
  16334. }
  16335. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  16336. const checkClashes = !allowDuplicates && new Set();
  16337. const formalParameters = {
  16338. type: "FormalParameters"
  16339. };
  16340. for (const param of node.params) {
  16341. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  16342. }
  16343. }
  16344. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  16345. const elts = [];
  16346. let first = true;
  16347. while (!this.eat(close)) {
  16348. if (first) {
  16349. first = false;
  16350. } else {
  16351. this.expect(12);
  16352. if (this.match(close)) {
  16353. if (nodeForExtra) {
  16354. this.addTrailingCommaExtraToNode(nodeForExtra);
  16355. }
  16356. this.next();
  16357. break;
  16358. }
  16359. }
  16360. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  16361. }
  16362. return elts;
  16363. }
  16364. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  16365. let elt;
  16366. if (this.match(12)) {
  16367. if (!allowEmpty) {
  16368. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  16369. unexpected: ","
  16370. });
  16371. }
  16372. elt = null;
  16373. } else if (this.match(21)) {
  16374. const spreadNodeStartLoc = this.state.startLoc;
  16375. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  16376. } else if (this.match(17)) {
  16377. this.expectPlugin("partialApplication");
  16378. if (!allowPlaceholder) {
  16379. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  16380. }
  16381. const node = this.startNode();
  16382. this.next();
  16383. elt = this.finishNode(node, "ArgumentPlaceholder");
  16384. } else {
  16385. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  16386. }
  16387. return elt;
  16388. }
  16389. parseIdentifier(liberal) {
  16390. const node = this.startNode();
  16391. const name = this.parseIdentifierName(liberal);
  16392. return this.createIdentifier(node, name);
  16393. }
  16394. createIdentifier(node, name) {
  16395. node.name = name;
  16396. node.loc.identifierName = name;
  16397. return this.finishNode(node, "Identifier");
  16398. }
  16399. createIdentifierAt(node, name, endLoc) {
  16400. node.name = name;
  16401. node.loc.identifierName = name;
  16402. return this.finishNodeAt(node, "Identifier", endLoc);
  16403. }
  16404. parseIdentifierName(liberal) {
  16405. let name;
  16406. const {
  16407. startLoc,
  16408. type
  16409. } = this.state;
  16410. if (tokenIsKeywordOrIdentifier(type)) {
  16411. name = this.state.value;
  16412. } else {
  16413. this.unexpected();
  16414. }
  16415. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  16416. if (liberal) {
  16417. if (tokenIsKeyword) {
  16418. this.replaceToken(132);
  16419. }
  16420. } else {
  16421. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  16422. }
  16423. this.next();
  16424. return name;
  16425. }
  16426. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  16427. if (word.length > 10) {
  16428. return;
  16429. }
  16430. if (!canBeReservedWord(word)) {
  16431. return;
  16432. }
  16433. if (checkKeywords && isKeyword(word)) {
  16434. this.raise(Errors.UnexpectedKeyword, startLoc, {
  16435. keyword: word
  16436. });
  16437. return;
  16438. }
  16439. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  16440. if (reservedTest(word, this.inModule)) {
  16441. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  16442. reservedWord: word
  16443. });
  16444. return;
  16445. } else if (word === "yield") {
  16446. if (this.prodParam.hasYield) {
  16447. this.raise(Errors.YieldBindingIdentifier, startLoc);
  16448. return;
  16449. }
  16450. } else if (word === "await") {
  16451. if (this.prodParam.hasAwait) {
  16452. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  16453. return;
  16454. }
  16455. if (this.scope.inStaticBlock) {
  16456. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  16457. return;
  16458. }
  16459. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  16460. } else if (word === "arguments") {
  16461. if (this.scope.inClassAndNotInNonArrowFunction) {
  16462. this.raise(Errors.ArgumentsInClass, startLoc);
  16463. return;
  16464. }
  16465. }
  16466. }
  16467. recordAwaitIfAllowed() {
  16468. const isAwaitAllowed = this.prodParam.hasAwait;
  16469. if (isAwaitAllowed && !this.scope.inFunction) {
  16470. this.state.hasTopLevelAwait = true;
  16471. }
  16472. return isAwaitAllowed;
  16473. }
  16474. parseAwait(startLoc) {
  16475. const node = this.startNodeAt(startLoc);
  16476. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  16477. if (this.eat(55)) {
  16478. this.raise(Errors.ObsoleteAwaitStar, node);
  16479. }
  16480. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  16481. if (this.isAmbiguousPrefixOrIdentifier()) {
  16482. this.ambiguousScriptDifferentAst = true;
  16483. } else {
  16484. this.sawUnambiguousESM = true;
  16485. }
  16486. }
  16487. if (!this.state.soloAwait) {
  16488. node.argument = this.parseMaybeUnary(null, true);
  16489. }
  16490. return this.finishNode(node, "AwaitExpression");
  16491. }
  16492. isAmbiguousPrefixOrIdentifier() {
  16493. if (this.hasPrecedingLineBreak()) return true;
  16494. const {
  16495. type
  16496. } = this.state;
  16497. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  16498. }
  16499. parseYield(startLoc) {
  16500. const node = this.startNodeAt(startLoc);
  16501. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  16502. let delegating = false;
  16503. let argument = null;
  16504. if (!this.hasPrecedingLineBreak()) {
  16505. delegating = this.eat(55);
  16506. switch (this.state.type) {
  16507. case 13:
  16508. case 140:
  16509. case 8:
  16510. case 11:
  16511. case 3:
  16512. case 9:
  16513. case 14:
  16514. case 12:
  16515. if (!delegating) break;
  16516. default:
  16517. argument = this.parseMaybeAssign();
  16518. }
  16519. }
  16520. node.delegate = delegating;
  16521. node.argument = argument;
  16522. return this.finishNode(node, "YieldExpression");
  16523. }
  16524. parseImportCall(node) {
  16525. this.next();
  16526. node.source = this.parseMaybeAssignAllowIn();
  16527. node.options = null;
  16528. if (this.eat(12)) {
  16529. if (!this.match(11)) {
  16530. node.options = this.parseMaybeAssignAllowIn();
  16531. if (this.eat(12)) {
  16532. this.addTrailingCommaExtraToNode(node.options);
  16533. if (!this.match(11)) {
  16534. do {
  16535. this.parseMaybeAssignAllowIn();
  16536. } while (this.eat(12) && !this.match(11));
  16537. this.raise(Errors.ImportCallArity, node);
  16538. }
  16539. }
  16540. } else {
  16541. this.addTrailingCommaExtraToNode(node.source);
  16542. }
  16543. }
  16544. this.expect(11);
  16545. return this.finishNode(node, "ImportExpression");
  16546. }
  16547. checkPipelineAtInfixOperator(left, leftStartLoc) {
  16548. if (this.hasPlugin(["pipelineOperator", {
  16549. proposal: "smart"
  16550. }])) {
  16551. if (left.type === "SequenceExpression") {
  16552. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  16553. }
  16554. }
  16555. }
  16556. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  16557. if (this.isSimpleReference(childExpr)) {
  16558. const bodyNode = this.startNodeAt(startLoc);
  16559. bodyNode.callee = childExpr;
  16560. return this.finishNode(bodyNode, "PipelineBareFunction");
  16561. } else {
  16562. const bodyNode = this.startNodeAt(startLoc);
  16563. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  16564. bodyNode.expression = childExpr;
  16565. return this.finishNode(bodyNode, "PipelineTopicExpression");
  16566. }
  16567. }
  16568. isSimpleReference(expression) {
  16569. switch (expression.type) {
  16570. case "MemberExpression":
  16571. return !expression.computed && this.isSimpleReference(expression.object);
  16572. case "Identifier":
  16573. return true;
  16574. default:
  16575. return false;
  16576. }
  16577. }
  16578. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  16579. if (this.match(19)) {
  16580. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  16581. }
  16582. if (!this.topicReferenceWasUsedInCurrentContext()) {
  16583. this.raise(Errors.PipelineTopicUnused, startLoc);
  16584. }
  16585. }
  16586. withTopicBindingContext(callback) {
  16587. const outerContextTopicState = this.state.topicContext;
  16588. this.state.topicContext = {
  16589. maxNumOfResolvableTopics: 1,
  16590. maxTopicIndex: null
  16591. };
  16592. try {
  16593. return callback();
  16594. } finally {
  16595. this.state.topicContext = outerContextTopicState;
  16596. }
  16597. }
  16598. withSmartMixTopicForbiddingContext(callback) {
  16599. if (this.hasPlugin(["pipelineOperator", {
  16600. proposal: "smart"
  16601. }])) {
  16602. const outerContextTopicState = this.state.topicContext;
  16603. this.state.topicContext = {
  16604. maxNumOfResolvableTopics: 0,
  16605. maxTopicIndex: null
  16606. };
  16607. try {
  16608. return callback();
  16609. } finally {
  16610. this.state.topicContext = outerContextTopicState;
  16611. }
  16612. } else {
  16613. return callback();
  16614. }
  16615. }
  16616. withSoloAwaitPermittingContext(callback) {
  16617. const outerContextSoloAwaitState = this.state.soloAwait;
  16618. this.state.soloAwait = true;
  16619. try {
  16620. return callback();
  16621. } finally {
  16622. this.state.soloAwait = outerContextSoloAwaitState;
  16623. }
  16624. }
  16625. allowInAnd(callback) {
  16626. const flags = this.prodParam.currentFlags();
  16627. const prodParamToSet = 8 & ~flags;
  16628. if (prodParamToSet) {
  16629. this.prodParam.enter(flags | 8);
  16630. try {
  16631. return callback();
  16632. } finally {
  16633. this.prodParam.exit();
  16634. }
  16635. }
  16636. return callback();
  16637. }
  16638. disallowInAnd(callback) {
  16639. const flags = this.prodParam.currentFlags();
  16640. const prodParamToClear = 8 & flags;
  16641. if (prodParamToClear) {
  16642. this.prodParam.enter(flags & -9);
  16643. try {
  16644. return callback();
  16645. } finally {
  16646. this.prodParam.exit();
  16647. }
  16648. }
  16649. return callback();
  16650. }
  16651. registerTopicReference() {
  16652. this.state.topicContext.maxTopicIndex = 0;
  16653. }
  16654. topicReferenceIsAllowedInCurrentContext() {
  16655. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  16656. }
  16657. topicReferenceWasUsedInCurrentContext() {
  16658. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  16659. }
  16660. parseFSharpPipelineBody(prec) {
  16661. const startLoc = this.state.startLoc;
  16662. this.state.potentialArrowAt = this.state.start;
  16663. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  16664. this.state.inFSharpPipelineDirectBody = true;
  16665. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  16666. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  16667. return ret;
  16668. }
  16669. parseModuleExpression() {
  16670. this.expectPlugin("moduleBlocks");
  16671. const node = this.startNode();
  16672. this.next();
  16673. if (!this.match(5)) {
  16674. this.unexpected(null, 5);
  16675. }
  16676. const program = this.startNodeAt(this.state.endLoc);
  16677. this.next();
  16678. const revertScopes = this.initializeScopes(true);
  16679. this.enterInitialScopes();
  16680. try {
  16681. node.body = this.parseProgram(program, 8, "module");
  16682. } finally {
  16683. revertScopes();
  16684. }
  16685. return this.finishNode(node, "ModuleExpression");
  16686. }
  16687. parseVoidPattern(refExpressionErrors) {
  16688. this.expectPlugin("discardBinding");
  16689. const node = this.startNode();
  16690. if (refExpressionErrors != null) {
  16691. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  16692. }
  16693. this.next();
  16694. return this.finishNode(node, "VoidPattern");
  16695. }
  16696. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  16697. if (refExpressionErrors != null && this.match(88)) {
  16698. const nextCode = this.lookaheadCharCode();
  16699. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  16700. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  16701. }
  16702. }
  16703. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  16704. }
  16705. parsePropertyNamePrefixOperator(prop) {}
  16706. }
  16707. const loopLabel = {
  16708. kind: 1
  16709. },
  16710. switchLabel = {
  16711. kind: 2
  16712. };
  16713. const loneSurrogate = /[\uD800-\uDFFF]/u;
  16714. const keywordRelationalOperator = /in(?:stanceof)?/y;
  16715. function babel7CompatTokens(tokens, input, startIndex) {
  16716. for (let i = 0; i < tokens.length; i++) {
  16717. const token = tokens[i];
  16718. const {
  16719. type
  16720. } = token;
  16721. if (typeof type === "number") {
  16722. if (type === 139) {
  16723. const {
  16724. loc,
  16725. start,
  16726. value,
  16727. end
  16728. } = token;
  16729. const hashEndPos = start + 1;
  16730. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  16731. tokens.splice(i, 1, new Token({
  16732. type: getExportedToken(27),
  16733. value: "#",
  16734. start: start,
  16735. end: hashEndPos,
  16736. startLoc: loc.start,
  16737. endLoc: hashEndLoc
  16738. }), new Token({
  16739. type: getExportedToken(132),
  16740. value: value,
  16741. start: hashEndPos,
  16742. end: end,
  16743. startLoc: hashEndLoc,
  16744. endLoc: loc.end
  16745. }));
  16746. i++;
  16747. continue;
  16748. }
  16749. if (tokenIsTemplate(type)) {
  16750. const {
  16751. loc,
  16752. start,
  16753. value,
  16754. end
  16755. } = token;
  16756. const backquoteEnd = start + 1;
  16757. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  16758. let startToken;
  16759. if (input.charCodeAt(start - startIndex) === 96) {
  16760. startToken = new Token({
  16761. type: getExportedToken(22),
  16762. value: "`",
  16763. start: start,
  16764. end: backquoteEnd,
  16765. startLoc: loc.start,
  16766. endLoc: backquoteEndLoc
  16767. });
  16768. } else {
  16769. startToken = new Token({
  16770. type: getExportedToken(8),
  16771. value: "}",
  16772. start: start,
  16773. end: backquoteEnd,
  16774. startLoc: loc.start,
  16775. endLoc: backquoteEndLoc
  16776. });
  16777. }
  16778. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  16779. if (type === 24) {
  16780. templateElementEnd = end - 1;
  16781. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  16782. templateValue = value === null ? null : value.slice(1, -1);
  16783. endToken = new Token({
  16784. type: getExportedToken(22),
  16785. value: "`",
  16786. start: templateElementEnd,
  16787. end: end,
  16788. startLoc: templateElementEndLoc,
  16789. endLoc: loc.end
  16790. });
  16791. } else {
  16792. templateElementEnd = end - 2;
  16793. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  16794. templateValue = value === null ? null : value.slice(1, -2);
  16795. endToken = new Token({
  16796. type: getExportedToken(23),
  16797. value: "${",
  16798. start: templateElementEnd,
  16799. end: end,
  16800. startLoc: templateElementEndLoc,
  16801. endLoc: loc.end
  16802. });
  16803. }
  16804. tokens.splice(i, 1, startToken, new Token({
  16805. type: getExportedToken(20),
  16806. value: templateValue,
  16807. start: backquoteEnd,
  16808. end: templateElementEnd,
  16809. startLoc: backquoteEndLoc,
  16810. endLoc: templateElementEndLoc
  16811. }), endToken);
  16812. i += 2;
  16813. continue;
  16814. }
  16815. token.type = getExportedToken(type);
  16816. }
  16817. }
  16818. return tokens;
  16819. }
  16820. class StatementParser extends ExpressionParser {
  16821. parseTopLevel(file, program) {
  16822. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  16823. file.comments = this.comments;
  16824. if (this.optionFlags & 256) {
  16825. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  16826. }
  16827. return this.finishNode(file, "File");
  16828. }
  16829. parseProgram(program, end, sourceType) {
  16830. program.sourceType = sourceType;
  16831. program.interpreter = this.parseInterpreterDirective();
  16832. this.parseBlockBody(program, true, true, end);
  16833. if (this.inModule) {
  16834. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  16835. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  16836. this.raise(Errors.ModuleExportUndefined, at, {
  16837. localName
  16838. });
  16839. }
  16840. }
  16841. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  16842. }
  16843. let finishedProgram;
  16844. if (end === 140) {
  16845. finishedProgram = this.finishNode(program, "Program");
  16846. } else {
  16847. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  16848. }
  16849. return finishedProgram;
  16850. }
  16851. stmtToDirective(stmt) {
  16852. const directive = this.castNodeTo(stmt, "Directive");
  16853. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  16854. const expressionValue = directiveLiteral.value;
  16855. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  16856. const val = directiveLiteral.value = raw.slice(1, -1);
  16857. this.addExtra(directiveLiteral, "raw", raw);
  16858. this.addExtra(directiveLiteral, "rawValue", val);
  16859. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  16860. directive.value = directiveLiteral;
  16861. delete stmt.expression;
  16862. return directive;
  16863. }
  16864. parseInterpreterDirective() {
  16865. if (!this.match(28)) {
  16866. return null;
  16867. }
  16868. const node = this.startNode();
  16869. node.value = this.state.value;
  16870. this.next();
  16871. return this.finishNode(node, "InterpreterDirective");
  16872. }
  16873. isLet() {
  16874. if (!this.isContextual(100)) {
  16875. return false;
  16876. }
  16877. return this.hasFollowingBindingAtom();
  16878. }
  16879. isUsing() {
  16880. if (!this.isContextual(107)) {
  16881. return false;
  16882. }
  16883. return this.nextTokenIsIdentifierOnSameLine();
  16884. }
  16885. isForUsing() {
  16886. if (!this.isContextual(107)) {
  16887. return false;
  16888. }
  16889. const next = this.nextTokenInLineStart();
  16890. const nextCh = this.codePointAtPos(next);
  16891. if (this.isUnparsedContextual(next, "of")) {
  16892. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  16893. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  16894. return false;
  16895. }
  16896. }
  16897. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  16898. return true;
  16899. }
  16900. return false;
  16901. }
  16902. nextTokenIsIdentifierOnSameLine() {
  16903. const next = this.nextTokenInLineStart();
  16904. const nextCh = this.codePointAtPos(next);
  16905. return this.chStartsBindingIdentifier(nextCh, next);
  16906. }
  16907. isAwaitUsing() {
  16908. if (!this.isContextual(96)) {
  16909. return false;
  16910. }
  16911. let next = this.nextTokenInLineStart();
  16912. if (this.isUnparsedContextual(next, "using")) {
  16913. next = this.nextTokenInLineStartSince(next + 5);
  16914. const nextCh = this.codePointAtPos(next);
  16915. if (this.chStartsBindingIdentifier(nextCh, next)) {
  16916. return true;
  16917. }
  16918. }
  16919. return false;
  16920. }
  16921. chStartsBindingIdentifier(ch, pos) {
  16922. if (isIdentifierStart(ch)) {
  16923. keywordRelationalOperator.lastIndex = pos;
  16924. if (keywordRelationalOperator.test(this.input)) {
  16925. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  16926. if (!isIdentifierChar(endCh) && endCh !== 92) {
  16927. return false;
  16928. }
  16929. }
  16930. return true;
  16931. } else if (ch === 92) {
  16932. return true;
  16933. } else {
  16934. return false;
  16935. }
  16936. }
  16937. chStartsBindingPattern(ch) {
  16938. return ch === 91 || ch === 123;
  16939. }
  16940. hasFollowingBindingAtom() {
  16941. const next = this.nextTokenStart();
  16942. const nextCh = this.codePointAtPos(next);
  16943. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  16944. }
  16945. hasInLineFollowingBindingIdentifierOrBrace() {
  16946. const next = this.nextTokenInLineStart();
  16947. const nextCh = this.codePointAtPos(next);
  16948. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  16949. }
  16950. allowsUsing() {
  16951. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  16952. }
  16953. parseModuleItem() {
  16954. return this.parseStatementLike(1 | 2 | 4 | 8);
  16955. }
  16956. parseStatementListItem() {
  16957. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  16958. }
  16959. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  16960. let flags = 0;
  16961. if (this.options.annexB && !this.state.strict) {
  16962. flags |= 4;
  16963. if (allowLabeledFunction) {
  16964. flags |= 8;
  16965. }
  16966. }
  16967. return this.parseStatementLike(flags);
  16968. }
  16969. parseStatement() {
  16970. return this.parseStatementLike(0);
  16971. }
  16972. parseStatementLike(flags) {
  16973. let decorators = null;
  16974. if (this.match(26)) {
  16975. decorators = this.parseDecorators(true);
  16976. }
  16977. return this.parseStatementContent(flags, decorators);
  16978. }
  16979. parseStatementContent(flags, decorators) {
  16980. const startType = this.state.type;
  16981. const node = this.startNode();
  16982. const allowDeclaration = !!(flags & 2);
  16983. const allowFunctionDeclaration = !!(flags & 4);
  16984. const topLevel = flags & 1;
  16985. switch (startType) {
  16986. case 60:
  16987. return this.parseBreakContinueStatement(node, true);
  16988. case 63:
  16989. return this.parseBreakContinueStatement(node, false);
  16990. case 64:
  16991. return this.parseDebuggerStatement(node);
  16992. case 90:
  16993. return this.parseDoWhileStatement(node);
  16994. case 91:
  16995. return this.parseForStatement(node);
  16996. case 68:
  16997. if (this.lookaheadCharCode() === 46) break;
  16998. if (!allowFunctionDeclaration) {
  16999. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  17000. }
  17001. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  17002. case 80:
  17003. if (!allowDeclaration) this.unexpected();
  17004. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  17005. case 69:
  17006. return this.parseIfStatement(node);
  17007. case 70:
  17008. return this.parseReturnStatement(node);
  17009. case 71:
  17010. return this.parseSwitchStatement(node);
  17011. case 72:
  17012. return this.parseThrowStatement(node);
  17013. case 73:
  17014. return this.parseTryStatement(node);
  17015. case 96:
  17016. if (this.isAwaitUsing()) {
  17017. if (!this.allowsUsing()) {
  17018. this.raise(Errors.UnexpectedUsingDeclaration, node);
  17019. } else if (!allowDeclaration) {
  17020. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  17021. } else if (!this.recordAwaitIfAllowed()) {
  17022. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  17023. }
  17024. this.next();
  17025. return this.parseVarStatement(node, "await using");
  17026. }
  17027. break;
  17028. case 107:
  17029. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  17030. break;
  17031. }
  17032. if (!this.allowsUsing()) {
  17033. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  17034. } else if (!allowDeclaration) {
  17035. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  17036. }
  17037. return this.parseVarStatement(node, "using");
  17038. case 100:
  17039. {
  17040. if (this.state.containsEsc) {
  17041. break;
  17042. }
  17043. const next = this.nextTokenStart();
  17044. const nextCh = this.codePointAtPos(next);
  17045. if (nextCh !== 91) {
  17046. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  17047. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  17048. break;
  17049. }
  17050. }
  17051. }
  17052. case 75:
  17053. {
  17054. if (!allowDeclaration) {
  17055. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  17056. }
  17057. }
  17058. case 74:
  17059. {
  17060. const kind = this.state.value;
  17061. return this.parseVarStatement(node, kind);
  17062. }
  17063. case 92:
  17064. return this.parseWhileStatement(node);
  17065. case 76:
  17066. return this.parseWithStatement(node);
  17067. case 5:
  17068. return this.parseBlock();
  17069. case 13:
  17070. return this.parseEmptyStatement(node);
  17071. case 83:
  17072. {
  17073. const nextTokenCharCode = this.lookaheadCharCode();
  17074. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  17075. break;
  17076. }
  17077. }
  17078. case 82:
  17079. {
  17080. if (!(this.optionFlags & 8) && !topLevel) {
  17081. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  17082. }
  17083. this.next();
  17084. let result;
  17085. if (startType === 83) {
  17086. result = this.parseImport(node);
  17087. } else {
  17088. result = this.parseExport(node, decorators);
  17089. }
  17090. this.assertModuleNodeAllowed(result);
  17091. return result;
  17092. }
  17093. default:
  17094. {
  17095. if (this.isAsyncFunction()) {
  17096. if (!allowDeclaration) {
  17097. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  17098. }
  17099. this.next();
  17100. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  17101. }
  17102. }
  17103. }
  17104. const maybeName = this.state.value;
  17105. const expr = this.parseExpression();
  17106. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  17107. return this.parseLabeledStatement(node, maybeName, expr, flags);
  17108. } else {
  17109. return this.parseExpressionStatement(node, expr, decorators);
  17110. }
  17111. }
  17112. assertModuleNodeAllowed(node) {
  17113. if (!(this.optionFlags & 8) && !this.inModule) {
  17114. this.raise(Errors.ImportOutsideModule, node);
  17115. }
  17116. }
  17117. decoratorsEnabledBeforeExport() {
  17118. if (this.hasPlugin("decorators-legacy")) return true;
  17119. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  17120. }
  17121. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  17122. if (maybeDecorators) {
  17123. var _classNode$decorators;
  17124. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  17125. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  17126. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  17127. }
  17128. classNode.decorators.unshift(...maybeDecorators);
  17129. } else {
  17130. classNode.decorators = maybeDecorators;
  17131. }
  17132. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  17133. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  17134. }
  17135. return classNode;
  17136. }
  17137. canHaveLeadingDecorator() {
  17138. return this.match(80);
  17139. }
  17140. parseDecorators(allowExport) {
  17141. const decorators = [];
  17142. do {
  17143. decorators.push(this.parseDecorator());
  17144. } while (this.match(26));
  17145. if (this.match(82)) {
  17146. if (!allowExport) {
  17147. this.unexpected();
  17148. }
  17149. if (!this.decoratorsEnabledBeforeExport()) {
  17150. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  17151. }
  17152. } else if (!this.canHaveLeadingDecorator()) {
  17153. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  17154. }
  17155. return decorators;
  17156. }
  17157. parseDecorator() {
  17158. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  17159. const node = this.startNode();
  17160. this.next();
  17161. if (this.hasPlugin("decorators")) {
  17162. const startLoc = this.state.startLoc;
  17163. let expr;
  17164. if (this.match(10)) {
  17165. const startLoc = this.state.startLoc;
  17166. this.next();
  17167. expr = this.parseExpression();
  17168. this.expect(11);
  17169. expr = this.wrapParenthesis(startLoc, expr);
  17170. const paramsStartLoc = this.state.startLoc;
  17171. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  17172. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  17173. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  17174. }
  17175. } else {
  17176. expr = this.parseIdentifier(false);
  17177. while (this.eat(16)) {
  17178. const node = this.startNodeAt(startLoc);
  17179. node.object = expr;
  17180. if (this.match(139)) {
  17181. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  17182. node.property = this.parsePrivateName();
  17183. } else {
  17184. node.property = this.parseIdentifier(true);
  17185. }
  17186. node.computed = false;
  17187. expr = this.finishNode(node, "MemberExpression");
  17188. }
  17189. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  17190. }
  17191. } else {
  17192. node.expression = this.parseExprSubscripts();
  17193. }
  17194. return this.finishNode(node, "Decorator");
  17195. }
  17196. parseMaybeDecoratorArguments(expr, startLoc) {
  17197. if (this.eat(10)) {
  17198. const node = this.startNodeAt(startLoc);
  17199. node.callee = expr;
  17200. node.arguments = this.parseCallExpressionArguments();
  17201. this.toReferencedList(node.arguments);
  17202. return this.finishNode(node, "CallExpression");
  17203. }
  17204. return expr;
  17205. }
  17206. parseBreakContinueStatement(node, isBreak) {
  17207. this.next();
  17208. if (this.isLineTerminator()) {
  17209. node.label = null;
  17210. } else {
  17211. node.label = this.parseIdentifier();
  17212. this.semicolon();
  17213. }
  17214. this.verifyBreakContinue(node, isBreak);
  17215. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  17216. }
  17217. verifyBreakContinue(node, isBreak) {
  17218. let i;
  17219. for (i = 0; i < this.state.labels.length; ++i) {
  17220. const lab = this.state.labels[i];
  17221. if (node.label == null || lab.name === node.label.name) {
  17222. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  17223. break;
  17224. }
  17225. if (node.label && isBreak) break;
  17226. }
  17227. }
  17228. if (i === this.state.labels.length) {
  17229. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  17230. this.raise(Errors.IllegalBreakContinue, node, {
  17231. type
  17232. });
  17233. }
  17234. }
  17235. parseDebuggerStatement(node) {
  17236. this.next();
  17237. this.semicolon();
  17238. return this.finishNode(node, "DebuggerStatement");
  17239. }
  17240. parseHeaderExpression() {
  17241. this.expect(10);
  17242. const val = this.parseExpression();
  17243. this.expect(11);
  17244. return val;
  17245. }
  17246. parseDoWhileStatement(node) {
  17247. this.next();
  17248. this.state.labels.push(loopLabel);
  17249. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17250. this.state.labels.pop();
  17251. this.expect(92);
  17252. node.test = this.parseHeaderExpression();
  17253. this.eat(13);
  17254. return this.finishNode(node, "DoWhileStatement");
  17255. }
  17256. parseForStatement(node) {
  17257. this.next();
  17258. this.state.labels.push(loopLabel);
  17259. let awaitAt = null;
  17260. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  17261. awaitAt = this.state.startLoc;
  17262. this.next();
  17263. }
  17264. this.scope.enter(0);
  17265. this.expect(10);
  17266. if (this.match(13)) {
  17267. if (awaitAt !== null) {
  17268. this.unexpected(awaitAt);
  17269. }
  17270. return this.parseFor(node, null);
  17271. }
  17272. const startsWithLet = this.isContextual(100);
  17273. {
  17274. const startsWithAwaitUsing = this.isAwaitUsing();
  17275. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  17276. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  17277. if (this.match(74) || this.match(75) || isLetOrUsing) {
  17278. const initNode = this.startNode();
  17279. let kind;
  17280. if (startsWithAwaitUsing) {
  17281. kind = "await using";
  17282. if (!this.recordAwaitIfAllowed()) {
  17283. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  17284. }
  17285. this.next();
  17286. } else {
  17287. kind = this.state.value;
  17288. }
  17289. this.next();
  17290. this.parseVar(initNode, true, kind);
  17291. const init = this.finishNode(initNode, "VariableDeclaration");
  17292. const isForIn = this.match(58);
  17293. if (isForIn && starsWithUsingDeclaration) {
  17294. this.raise(Errors.ForInUsing, init);
  17295. }
  17296. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  17297. return this.parseForIn(node, init, awaitAt);
  17298. }
  17299. if (awaitAt !== null) {
  17300. this.unexpected(awaitAt);
  17301. }
  17302. return this.parseFor(node, init);
  17303. }
  17304. }
  17305. const startsWithAsync = this.isContextual(95);
  17306. const refExpressionErrors = new ExpressionErrors();
  17307. const init = this.parseExpression(true, refExpressionErrors);
  17308. const isForOf = this.isContextual(102);
  17309. if (isForOf) {
  17310. if (startsWithLet) {
  17311. this.raise(Errors.ForOfLet, init);
  17312. }
  17313. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  17314. this.raise(Errors.ForOfAsync, init);
  17315. }
  17316. }
  17317. if (isForOf || this.match(58)) {
  17318. this.checkDestructuringPrivate(refExpressionErrors);
  17319. this.toAssignable(init, true);
  17320. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  17321. this.checkLVal(init, {
  17322. type
  17323. });
  17324. return this.parseForIn(node, init, awaitAt);
  17325. } else {
  17326. this.checkExpressionErrors(refExpressionErrors, true);
  17327. }
  17328. if (awaitAt !== null) {
  17329. this.unexpected(awaitAt);
  17330. }
  17331. return this.parseFor(node, init);
  17332. }
  17333. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  17334. this.next();
  17335. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  17336. }
  17337. parseIfStatement(node) {
  17338. this.next();
  17339. node.test = this.parseHeaderExpression();
  17340. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  17341. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  17342. return this.finishNode(node, "IfStatement");
  17343. }
  17344. parseReturnStatement(node) {
  17345. if (!this.prodParam.hasReturn) {
  17346. this.raise(Errors.IllegalReturn, this.state.startLoc);
  17347. }
  17348. this.next();
  17349. if (this.isLineTerminator()) {
  17350. node.argument = null;
  17351. } else {
  17352. node.argument = this.parseExpression();
  17353. this.semicolon();
  17354. }
  17355. return this.finishNode(node, "ReturnStatement");
  17356. }
  17357. parseSwitchStatement(node) {
  17358. this.next();
  17359. node.discriminant = this.parseHeaderExpression();
  17360. const cases = node.cases = [];
  17361. this.expect(5);
  17362. this.state.labels.push(switchLabel);
  17363. this.scope.enter(256);
  17364. let cur;
  17365. for (let sawDefault; !this.match(8);) {
  17366. if (this.match(61) || this.match(65)) {
  17367. const isCase = this.match(61);
  17368. if (cur) this.finishNode(cur, "SwitchCase");
  17369. cases.push(cur = this.startNode());
  17370. cur.consequent = [];
  17371. this.next();
  17372. if (isCase) {
  17373. cur.test = this.parseExpression();
  17374. } else {
  17375. if (sawDefault) {
  17376. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  17377. }
  17378. sawDefault = true;
  17379. cur.test = null;
  17380. }
  17381. this.expect(14);
  17382. } else {
  17383. if (cur) {
  17384. cur.consequent.push(this.parseStatementListItem());
  17385. } else {
  17386. this.unexpected();
  17387. }
  17388. }
  17389. }
  17390. this.scope.exit();
  17391. if (cur) this.finishNode(cur, "SwitchCase");
  17392. this.next();
  17393. this.state.labels.pop();
  17394. return this.finishNode(node, "SwitchStatement");
  17395. }
  17396. parseThrowStatement(node) {
  17397. this.next();
  17398. if (this.hasPrecedingLineBreak()) {
  17399. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  17400. }
  17401. node.argument = this.parseExpression();
  17402. this.semicolon();
  17403. return this.finishNode(node, "ThrowStatement");
  17404. }
  17405. parseCatchClauseParam() {
  17406. const param = this.parseBindingAtom();
  17407. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  17408. this.checkLVal(param, {
  17409. type: "CatchClause"
  17410. }, 9);
  17411. return param;
  17412. }
  17413. parseTryStatement(node) {
  17414. this.next();
  17415. node.block = this.parseBlock();
  17416. node.handler = null;
  17417. if (this.match(62)) {
  17418. const clause = this.startNode();
  17419. this.next();
  17420. if (this.match(10)) {
  17421. this.expect(10);
  17422. clause.param = this.parseCatchClauseParam();
  17423. this.expect(11);
  17424. } else {
  17425. clause.param = null;
  17426. this.scope.enter(0);
  17427. }
  17428. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  17429. this.scope.exit();
  17430. node.handler = this.finishNode(clause, "CatchClause");
  17431. }
  17432. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  17433. if (!node.handler && !node.finalizer) {
  17434. this.raise(Errors.NoCatchOrFinally, node);
  17435. }
  17436. return this.finishNode(node, "TryStatement");
  17437. }
  17438. parseVarStatement(node, kind, allowMissingInitializer = false) {
  17439. this.next();
  17440. this.parseVar(node, false, kind, allowMissingInitializer);
  17441. this.semicolon();
  17442. return this.finishNode(node, "VariableDeclaration");
  17443. }
  17444. parseWhileStatement(node) {
  17445. this.next();
  17446. node.test = this.parseHeaderExpression();
  17447. this.state.labels.push(loopLabel);
  17448. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17449. this.state.labels.pop();
  17450. return this.finishNode(node, "WhileStatement");
  17451. }
  17452. parseWithStatement(node) {
  17453. if (this.state.strict) {
  17454. this.raise(Errors.StrictWith, this.state.startLoc);
  17455. }
  17456. this.next();
  17457. node.object = this.parseHeaderExpression();
  17458. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17459. return this.finishNode(node, "WithStatement");
  17460. }
  17461. parseEmptyStatement(node) {
  17462. this.next();
  17463. return this.finishNode(node, "EmptyStatement");
  17464. }
  17465. parseLabeledStatement(node, maybeName, expr, flags) {
  17466. for (const label of this.state.labels) {
  17467. if (label.name === maybeName) {
  17468. this.raise(Errors.LabelRedeclaration, expr, {
  17469. labelName: maybeName
  17470. });
  17471. }
  17472. }
  17473. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  17474. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  17475. const label = this.state.labels[i];
  17476. if (label.statementStart === node.start) {
  17477. label.statementStart = this.sourceToOffsetPos(this.state.start);
  17478. label.kind = kind;
  17479. } else {
  17480. break;
  17481. }
  17482. }
  17483. this.state.labels.push({
  17484. name: maybeName,
  17485. kind: kind,
  17486. statementStart: this.sourceToOffsetPos(this.state.start)
  17487. });
  17488. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  17489. this.state.labels.pop();
  17490. node.label = expr;
  17491. return this.finishNode(node, "LabeledStatement");
  17492. }
  17493. parseExpressionStatement(node, expr, decorators) {
  17494. node.expression = expr;
  17495. this.semicolon();
  17496. return this.finishNode(node, "ExpressionStatement");
  17497. }
  17498. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  17499. const node = this.startNode();
  17500. if (allowDirectives) {
  17501. this.state.strictErrors.clear();
  17502. }
  17503. this.expect(5);
  17504. if (createNewLexicalScope) {
  17505. this.scope.enter(0);
  17506. }
  17507. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  17508. if (createNewLexicalScope) {
  17509. this.scope.exit();
  17510. }
  17511. return this.finishNode(node, "BlockStatement");
  17512. }
  17513. isValidDirective(stmt) {
  17514. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  17515. }
  17516. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  17517. const body = node.body = [];
  17518. const directives = node.directives = [];
  17519. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  17520. }
  17521. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  17522. const oldStrict = this.state.strict;
  17523. let hasStrictModeDirective = false;
  17524. let parsedNonDirective = false;
  17525. while (!this.match(end)) {
  17526. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  17527. if (directives && !parsedNonDirective) {
  17528. if (this.isValidDirective(stmt)) {
  17529. const directive = this.stmtToDirective(stmt);
  17530. directives.push(directive);
  17531. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  17532. hasStrictModeDirective = true;
  17533. this.setStrict(true);
  17534. }
  17535. continue;
  17536. }
  17537. parsedNonDirective = true;
  17538. this.state.strictErrors.clear();
  17539. }
  17540. body.push(stmt);
  17541. }
  17542. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  17543. if (!oldStrict) {
  17544. this.setStrict(false);
  17545. }
  17546. this.next();
  17547. }
  17548. parseFor(node, init) {
  17549. node.init = init;
  17550. this.semicolon(false);
  17551. node.test = this.match(13) ? null : this.parseExpression();
  17552. this.semicolon(false);
  17553. node.update = this.match(11) ? null : this.parseExpression();
  17554. this.expect(11);
  17555. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17556. this.scope.exit();
  17557. this.state.labels.pop();
  17558. return this.finishNode(node, "ForStatement");
  17559. }
  17560. parseForIn(node, init, awaitAt) {
  17561. const isForIn = this.match(58);
  17562. this.next();
  17563. if (isForIn) {
  17564. if (awaitAt !== null) this.unexpected(awaitAt);
  17565. } else {
  17566. node.await = awaitAt !== null;
  17567. }
  17568. 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")) {
  17569. this.raise(Errors.ForInOfLoopInitializer, init, {
  17570. type: isForIn ? "ForInStatement" : "ForOfStatement"
  17571. });
  17572. }
  17573. if (init.type === "AssignmentPattern") {
  17574. this.raise(Errors.InvalidLhs, init, {
  17575. ancestor: {
  17576. type: "ForStatement"
  17577. }
  17578. });
  17579. }
  17580. node.left = init;
  17581. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  17582. this.expect(11);
  17583. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  17584. this.scope.exit();
  17585. this.state.labels.pop();
  17586. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  17587. }
  17588. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  17589. const declarations = node.declarations = [];
  17590. node.kind = kind;
  17591. for (;;) {
  17592. const decl = this.startNode();
  17593. this.parseVarId(decl, kind);
  17594. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  17595. if (decl.init === null && !allowMissingInitializer) {
  17596. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  17597. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  17598. kind: "destructuring"
  17599. });
  17600. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  17601. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  17602. kind
  17603. });
  17604. }
  17605. }
  17606. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  17607. if (!this.eat(12)) break;
  17608. }
  17609. return node;
  17610. }
  17611. parseVarId(decl, kind) {
  17612. const id = this.parseBindingAtom();
  17613. if (kind === "using" || kind === "await using") {
  17614. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  17615. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  17616. }
  17617. } else {
  17618. if (id.type === "VoidPattern") {
  17619. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  17620. }
  17621. }
  17622. this.checkLVal(id, {
  17623. type: "VariableDeclarator"
  17624. }, kind === "var" ? 5 : 8201);
  17625. decl.id = id;
  17626. }
  17627. parseAsyncFunctionExpression(node) {
  17628. return this.parseFunction(node, 8);
  17629. }
  17630. parseFunction(node, flags = 0) {
  17631. const hangingDeclaration = flags & 2;
  17632. const isDeclaration = !!(flags & 1);
  17633. const requireId = isDeclaration && !(flags & 4);
  17634. const isAsync = !!(flags & 8);
  17635. this.initFunction(node, isAsync);
  17636. if (this.match(55)) {
  17637. if (hangingDeclaration) {
  17638. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  17639. }
  17640. this.next();
  17641. node.generator = true;
  17642. }
  17643. if (isDeclaration) {
  17644. node.id = this.parseFunctionId(requireId);
  17645. }
  17646. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  17647. this.state.maybeInArrowParameters = false;
  17648. this.scope.enter(514);
  17649. this.prodParam.enter(functionFlags(isAsync, node.generator));
  17650. if (!isDeclaration) {
  17651. node.id = this.parseFunctionId();
  17652. }
  17653. this.parseFunctionParams(node, false);
  17654. this.withSmartMixTopicForbiddingContext(() => {
  17655. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  17656. });
  17657. this.prodParam.exit();
  17658. this.scope.exit();
  17659. if (isDeclaration && !hangingDeclaration) {
  17660. this.registerFunctionStatementId(node);
  17661. }
  17662. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  17663. return node;
  17664. }
  17665. parseFunctionId(requireId) {
  17666. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  17667. }
  17668. parseFunctionParams(node, isConstructor) {
  17669. this.expect(10);
  17670. this.expressionScope.enter(newParameterDeclarationScope());
  17671. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  17672. this.expressionScope.exit();
  17673. }
  17674. registerFunctionStatementId(node) {
  17675. if (!node.id) return;
  17676. 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);
  17677. }
  17678. parseClass(node, isStatement, optionalId) {
  17679. this.next();
  17680. const oldStrict = this.state.strict;
  17681. this.state.strict = true;
  17682. this.parseClassId(node, isStatement, optionalId);
  17683. this.parseClassSuper(node);
  17684. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  17685. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  17686. }
  17687. isClassProperty() {
  17688. return this.match(29) || this.match(13) || this.match(8);
  17689. }
  17690. isClassMethod() {
  17691. return this.match(10);
  17692. }
  17693. nameIsConstructor(key) {
  17694. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  17695. }
  17696. isNonstaticConstructor(method) {
  17697. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  17698. }
  17699. parseClassBody(hadSuperClass, oldStrict) {
  17700. this.classScope.enter();
  17701. const state = {
  17702. hadConstructor: false,
  17703. hadSuperClass
  17704. };
  17705. let decorators = [];
  17706. const classBody = this.startNode();
  17707. classBody.body = [];
  17708. this.expect(5);
  17709. this.withSmartMixTopicForbiddingContext(() => {
  17710. while (!this.match(8)) {
  17711. if (this.eat(13)) {
  17712. if (decorators.length > 0) {
  17713. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  17714. }
  17715. continue;
  17716. }
  17717. if (this.match(26)) {
  17718. decorators.push(this.parseDecorator());
  17719. continue;
  17720. }
  17721. const member = this.startNode();
  17722. if (decorators.length) {
  17723. member.decorators = decorators;
  17724. this.resetStartLocationFromNode(member, decorators[0]);
  17725. decorators = [];
  17726. }
  17727. this.parseClassMember(classBody, member, state);
  17728. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  17729. this.raise(Errors.DecoratorConstructor, member);
  17730. }
  17731. }
  17732. });
  17733. this.state.strict = oldStrict;
  17734. this.next();
  17735. if (decorators.length) {
  17736. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  17737. }
  17738. this.classScope.exit();
  17739. return this.finishNode(classBody, "ClassBody");
  17740. }
  17741. parseClassMemberFromModifier(classBody, member) {
  17742. const key = this.parseIdentifier(true);
  17743. if (this.isClassMethod()) {
  17744. const method = member;
  17745. method.kind = "method";
  17746. method.computed = false;
  17747. method.key = key;
  17748. method.static = false;
  17749. this.pushClassMethod(classBody, method, false, false, false, false);
  17750. return true;
  17751. } else if (this.isClassProperty()) {
  17752. const prop = member;
  17753. prop.computed = false;
  17754. prop.key = key;
  17755. prop.static = false;
  17756. classBody.body.push(this.parseClassProperty(prop));
  17757. return true;
  17758. }
  17759. this.resetPreviousNodeTrailingComments(key);
  17760. return false;
  17761. }
  17762. parseClassMember(classBody, member, state) {
  17763. const isStatic = this.isContextual(106);
  17764. if (isStatic) {
  17765. if (this.parseClassMemberFromModifier(classBody, member)) {
  17766. return;
  17767. }
  17768. if (this.eat(5)) {
  17769. this.parseClassStaticBlock(classBody, member);
  17770. return;
  17771. }
  17772. }
  17773. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  17774. }
  17775. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  17776. const publicMethod = member;
  17777. const privateMethod = member;
  17778. const publicProp = member;
  17779. const privateProp = member;
  17780. const accessorProp = member;
  17781. const method = publicMethod;
  17782. const publicMember = publicMethod;
  17783. member.static = isStatic;
  17784. this.parsePropertyNamePrefixOperator(member);
  17785. if (this.eat(55)) {
  17786. method.kind = "method";
  17787. const isPrivateName = this.match(139);
  17788. this.parseClassElementName(method);
  17789. this.parsePostMemberNameModifiers(method);
  17790. if (isPrivateName) {
  17791. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  17792. return;
  17793. }
  17794. if (this.isNonstaticConstructor(publicMethod)) {
  17795. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  17796. }
  17797. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  17798. return;
  17799. }
  17800. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  17801. const key = this.parseClassElementName(member);
  17802. const maybeContextualKw = isContextual ? key.name : null;
  17803. const isPrivate = this.isPrivateName(key);
  17804. const maybeQuestionTokenStartLoc = this.state.startLoc;
  17805. this.parsePostMemberNameModifiers(publicMember);
  17806. if (this.isClassMethod()) {
  17807. method.kind = "method";
  17808. if (isPrivate) {
  17809. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  17810. return;
  17811. }
  17812. const isConstructor = this.isNonstaticConstructor(publicMethod);
  17813. let allowsDirectSuper = false;
  17814. if (isConstructor) {
  17815. publicMethod.kind = "constructor";
  17816. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  17817. this.raise(Errors.DuplicateConstructor, key);
  17818. }
  17819. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  17820. this.raise(Errors.OverrideOnConstructor, key);
  17821. }
  17822. state.hadConstructor = true;
  17823. allowsDirectSuper = state.hadSuperClass;
  17824. }
  17825. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  17826. } else if (this.isClassProperty()) {
  17827. if (isPrivate) {
  17828. this.pushClassPrivateProperty(classBody, privateProp);
  17829. } else {
  17830. this.pushClassProperty(classBody, publicProp);
  17831. }
  17832. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  17833. this.resetPreviousNodeTrailingComments(key);
  17834. const isGenerator = this.eat(55);
  17835. if (publicMember.optional) {
  17836. this.unexpected(maybeQuestionTokenStartLoc);
  17837. }
  17838. method.kind = "method";
  17839. const isPrivate = this.match(139);
  17840. this.parseClassElementName(method);
  17841. this.parsePostMemberNameModifiers(publicMember);
  17842. if (isPrivate) {
  17843. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  17844. } else {
  17845. if (this.isNonstaticConstructor(publicMethod)) {
  17846. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  17847. }
  17848. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  17849. }
  17850. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  17851. this.resetPreviousNodeTrailingComments(key);
  17852. method.kind = maybeContextualKw;
  17853. const isPrivate = this.match(139);
  17854. this.parseClassElementName(publicMethod);
  17855. if (isPrivate) {
  17856. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  17857. } else {
  17858. if (this.isNonstaticConstructor(publicMethod)) {
  17859. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  17860. }
  17861. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  17862. }
  17863. this.checkGetterSetterParams(publicMethod);
  17864. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  17865. this.expectPlugin("decoratorAutoAccessors");
  17866. this.resetPreviousNodeTrailingComments(key);
  17867. const isPrivate = this.match(139);
  17868. this.parseClassElementName(publicProp);
  17869. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  17870. } else if (this.isLineTerminator()) {
  17871. if (isPrivate) {
  17872. this.pushClassPrivateProperty(classBody, privateProp);
  17873. } else {
  17874. this.pushClassProperty(classBody, publicProp);
  17875. }
  17876. } else {
  17877. this.unexpected();
  17878. }
  17879. }
  17880. parseClassElementName(member) {
  17881. const {
  17882. type,
  17883. value
  17884. } = this.state;
  17885. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  17886. this.raise(Errors.StaticPrototype, this.state.startLoc);
  17887. }
  17888. if (type === 139) {
  17889. if (value === "constructor") {
  17890. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  17891. }
  17892. const key = this.parsePrivateName();
  17893. member.key = key;
  17894. return key;
  17895. }
  17896. this.parsePropertyName(member);
  17897. return member.key;
  17898. }
  17899. parseClassStaticBlock(classBody, member) {
  17900. var _member$decorators;
  17901. this.scope.enter(576 | 128 | 16);
  17902. const oldLabels = this.state.labels;
  17903. this.state.labels = [];
  17904. this.prodParam.enter(0);
  17905. const body = member.body = [];
  17906. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  17907. this.prodParam.exit();
  17908. this.scope.exit();
  17909. this.state.labels = oldLabels;
  17910. classBody.body.push(this.finishNode(member, "StaticBlock"));
  17911. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  17912. this.raise(Errors.DecoratorStaticBlock, member);
  17913. }
  17914. }
  17915. pushClassProperty(classBody, prop) {
  17916. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  17917. this.raise(Errors.ConstructorClassField, prop.key);
  17918. }
  17919. classBody.body.push(this.parseClassProperty(prop));
  17920. }
  17921. pushClassPrivateProperty(classBody, prop) {
  17922. const node = this.parseClassPrivateProperty(prop);
  17923. classBody.body.push(node);
  17924. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  17925. }
  17926. pushClassAccessorProperty(classBody, prop, isPrivate) {
  17927. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  17928. this.raise(Errors.ConstructorClassField, prop.key);
  17929. }
  17930. const node = this.parseClassAccessorProperty(prop);
  17931. classBody.body.push(node);
  17932. if (isPrivate) {
  17933. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  17934. }
  17935. }
  17936. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  17937. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  17938. }
  17939. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  17940. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  17941. classBody.body.push(node);
  17942. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  17943. this.declareClassPrivateMethodInScope(node, kind);
  17944. }
  17945. declareClassPrivateMethodInScope(node, kind) {
  17946. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  17947. }
  17948. parsePostMemberNameModifiers(methodOrProp) {}
  17949. parseClassPrivateProperty(node) {
  17950. this.parseInitializer(node);
  17951. this.semicolon();
  17952. return this.finishNode(node, "ClassPrivateProperty");
  17953. }
  17954. parseClassProperty(node) {
  17955. this.parseInitializer(node);
  17956. this.semicolon();
  17957. return this.finishNode(node, "ClassProperty");
  17958. }
  17959. parseClassAccessorProperty(node) {
  17960. this.parseInitializer(node);
  17961. this.semicolon();
  17962. return this.finishNode(node, "ClassAccessorProperty");
  17963. }
  17964. parseInitializer(node) {
  17965. this.scope.enter(576 | 16);
  17966. this.expressionScope.enter(newExpressionScope());
  17967. this.prodParam.enter(0);
  17968. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  17969. this.expressionScope.exit();
  17970. this.prodParam.exit();
  17971. this.scope.exit();
  17972. }
  17973. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  17974. if (tokenIsIdentifier(this.state.type)) {
  17975. node.id = this.parseIdentifier();
  17976. if (isStatement) {
  17977. this.declareNameFromIdentifier(node.id, bindingType);
  17978. }
  17979. } else {
  17980. if (optionalId || !isStatement) {
  17981. node.id = null;
  17982. } else {
  17983. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  17984. }
  17985. }
  17986. }
  17987. parseClassSuper(node) {
  17988. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  17989. }
  17990. parseExport(node, decorators) {
  17991. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  17992. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  17993. const parseAfterDefault = !hasDefault || this.eat(12);
  17994. const hasStar = parseAfterDefault && this.eatExportStar(node);
  17995. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  17996. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  17997. const isFromRequired = hasDefault || hasStar;
  17998. if (hasStar && !hasNamespace) {
  17999. if (hasDefault) this.unexpected();
  18000. if (decorators) {
  18001. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18002. }
  18003. this.parseExportFrom(node, true);
  18004. this.sawUnambiguousESM = true;
  18005. return this.finishNode(node, "ExportAllDeclaration");
  18006. }
  18007. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  18008. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  18009. this.unexpected(null, 5);
  18010. }
  18011. if (hasNamespace && parseAfterNamespace) {
  18012. this.unexpected(null, 98);
  18013. }
  18014. let hasDeclaration;
  18015. if (isFromRequired || hasSpecifiers) {
  18016. hasDeclaration = false;
  18017. if (decorators) {
  18018. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18019. }
  18020. this.parseExportFrom(node, isFromRequired);
  18021. } else {
  18022. hasDeclaration = this.maybeParseExportDeclaration(node);
  18023. }
  18024. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  18025. var _node2$declaration;
  18026. const node2 = node;
  18027. this.checkExport(node2, true, false, !!node2.source);
  18028. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  18029. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  18030. } else if (decorators) {
  18031. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18032. }
  18033. this.sawUnambiguousESM = true;
  18034. return this.finishNode(node2, "ExportNamedDeclaration");
  18035. }
  18036. if (this.eat(65)) {
  18037. const node2 = node;
  18038. const decl = this.parseExportDefaultExpression();
  18039. node2.declaration = decl;
  18040. if (decl.type === "ClassDeclaration") {
  18041. this.maybeTakeDecorators(decorators, decl, node2);
  18042. } else if (decorators) {
  18043. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  18044. }
  18045. this.checkExport(node2, true, true);
  18046. this.sawUnambiguousESM = true;
  18047. return this.finishNode(node2, "ExportDefaultDeclaration");
  18048. }
  18049. throw this.unexpected(null, 5);
  18050. }
  18051. eatExportStar(node) {
  18052. return this.eat(55);
  18053. }
  18054. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  18055. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  18056. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  18057. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  18058. const specifier = this.startNodeAtNode(id);
  18059. specifier.exported = id;
  18060. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  18061. return true;
  18062. }
  18063. return false;
  18064. }
  18065. maybeParseExportNamespaceSpecifier(node) {
  18066. if (this.isContextual(93)) {
  18067. var _ref, _ref$specifiers;
  18068. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  18069. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  18070. this.next();
  18071. specifier.exported = this.parseModuleExportName();
  18072. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  18073. return true;
  18074. }
  18075. return false;
  18076. }
  18077. maybeParseExportNamedSpecifiers(node) {
  18078. if (this.match(5)) {
  18079. const node2 = node;
  18080. if (!node2.specifiers) node2.specifiers = [];
  18081. const isTypeExport = node2.exportKind === "type";
  18082. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  18083. node2.source = null;
  18084. if (this.hasPlugin("importAssertions")) {
  18085. node2.assertions = [];
  18086. } else {
  18087. node2.attributes = [];
  18088. }
  18089. node2.declaration = null;
  18090. return true;
  18091. }
  18092. return false;
  18093. }
  18094. maybeParseExportDeclaration(node) {
  18095. if (this.shouldParseExportDeclaration()) {
  18096. node.specifiers = [];
  18097. node.source = null;
  18098. if (this.hasPlugin("importAssertions")) {
  18099. node.assertions = [];
  18100. } else {
  18101. node.attributes = [];
  18102. }
  18103. node.declaration = this.parseExportDeclaration(node);
  18104. return true;
  18105. }
  18106. return false;
  18107. }
  18108. isAsyncFunction() {
  18109. if (!this.isContextual(95)) return false;
  18110. const next = this.nextTokenInLineStart();
  18111. return this.isUnparsedContextual(next, "function");
  18112. }
  18113. parseExportDefaultExpression() {
  18114. const expr = this.startNode();
  18115. if (this.match(68)) {
  18116. this.next();
  18117. return this.parseFunction(expr, 1 | 4);
  18118. } else if (this.isAsyncFunction()) {
  18119. this.next();
  18120. this.next();
  18121. return this.parseFunction(expr, 1 | 4 | 8);
  18122. }
  18123. if (this.match(80)) {
  18124. return this.parseClass(expr, true, true);
  18125. }
  18126. if (this.match(26)) {
  18127. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  18128. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  18129. }
  18130. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  18131. }
  18132. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  18133. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  18134. }
  18135. const res = this.parseMaybeAssignAllowIn();
  18136. this.semicolon();
  18137. return res;
  18138. }
  18139. parseExportDeclaration(node) {
  18140. if (this.match(80)) {
  18141. const node = this.parseClass(this.startNode(), true, false);
  18142. return node;
  18143. }
  18144. return this.parseStatementListItem();
  18145. }
  18146. isExportDefaultSpecifier() {
  18147. const {
  18148. type
  18149. } = this.state;
  18150. if (tokenIsIdentifier(type)) {
  18151. if (type === 95 && !this.state.containsEsc || type === 100) {
  18152. return false;
  18153. }
  18154. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  18155. const next = this.nextTokenStart();
  18156. const nextChar = this.input.charCodeAt(next);
  18157. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  18158. this.expectOnePlugin(["flow", "typescript"]);
  18159. return false;
  18160. }
  18161. }
  18162. } else if (!this.match(65)) {
  18163. return false;
  18164. }
  18165. const next = this.nextTokenStart();
  18166. const hasFrom = this.isUnparsedContextual(next, "from");
  18167. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  18168. return true;
  18169. }
  18170. if (this.match(65) && hasFrom) {
  18171. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  18172. return nextAfterFrom === 34 || nextAfterFrom === 39;
  18173. }
  18174. return false;
  18175. }
  18176. parseExportFrom(node, expect) {
  18177. if (this.eatContextual(98)) {
  18178. node.source = this.parseImportSource();
  18179. this.checkExport(node);
  18180. this.maybeParseImportAttributes(node);
  18181. this.checkJSONModuleImport(node);
  18182. } else if (expect) {
  18183. this.unexpected();
  18184. }
  18185. this.semicolon();
  18186. }
  18187. shouldParseExportDeclaration() {
  18188. const {
  18189. type
  18190. } = this.state;
  18191. if (type === 26) {
  18192. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  18193. if (this.hasPlugin("decorators")) {
  18194. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  18195. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  18196. }
  18197. return true;
  18198. }
  18199. }
  18200. if (this.isUsing()) {
  18201. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  18202. return true;
  18203. }
  18204. if (this.isAwaitUsing()) {
  18205. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  18206. return true;
  18207. }
  18208. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  18209. }
  18210. checkExport(node, checkNames, isDefault, isFrom) {
  18211. if (checkNames) {
  18212. var _node$specifiers;
  18213. if (isDefault) {
  18214. this.checkDuplicateExports(node, "default");
  18215. if (this.hasPlugin("exportDefaultFrom")) {
  18216. var _declaration$extra;
  18217. const declaration = node.declaration;
  18218. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  18219. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  18220. }
  18221. }
  18222. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  18223. for (const specifier of node.specifiers) {
  18224. const {
  18225. exported
  18226. } = specifier;
  18227. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  18228. this.checkDuplicateExports(specifier, exportName);
  18229. if (!isFrom && specifier.local) {
  18230. const {
  18231. local
  18232. } = specifier;
  18233. if (local.type !== "Identifier") {
  18234. this.raise(Errors.ExportBindingIsString, specifier, {
  18235. localName: local.value,
  18236. exportName
  18237. });
  18238. } else {
  18239. this.checkReservedWord(local.name, local.loc.start, true, false);
  18240. this.scope.checkLocalExport(local);
  18241. }
  18242. }
  18243. }
  18244. } else if (node.declaration) {
  18245. const decl = node.declaration;
  18246. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  18247. const {
  18248. id
  18249. } = decl;
  18250. if (!id) throw new Error("Assertion failure");
  18251. this.checkDuplicateExports(node, id.name);
  18252. } else if (decl.type === "VariableDeclaration") {
  18253. for (const declaration of decl.declarations) {
  18254. this.checkDeclaration(declaration.id);
  18255. }
  18256. }
  18257. }
  18258. }
  18259. }
  18260. checkDeclaration(node) {
  18261. if (node.type === "Identifier") {
  18262. this.checkDuplicateExports(node, node.name);
  18263. } else if (node.type === "ObjectPattern") {
  18264. for (const prop of node.properties) {
  18265. this.checkDeclaration(prop);
  18266. }
  18267. } else if (node.type === "ArrayPattern") {
  18268. for (const elem of node.elements) {
  18269. if (elem) {
  18270. this.checkDeclaration(elem);
  18271. }
  18272. }
  18273. } else if (node.type === "ObjectProperty") {
  18274. this.checkDeclaration(node.value);
  18275. } else if (node.type === "RestElement") {
  18276. this.checkDeclaration(node.argument);
  18277. } else if (node.type === "AssignmentPattern") {
  18278. this.checkDeclaration(node.left);
  18279. }
  18280. }
  18281. checkDuplicateExports(node, exportName) {
  18282. if (this.exportedIdentifiers.has(exportName)) {
  18283. if (exportName === "default") {
  18284. this.raise(Errors.DuplicateDefaultExport, node);
  18285. } else {
  18286. this.raise(Errors.DuplicateExport, node, {
  18287. exportName
  18288. });
  18289. }
  18290. }
  18291. this.exportedIdentifiers.add(exportName);
  18292. }
  18293. parseExportSpecifiers(isInTypeExport) {
  18294. const nodes = [];
  18295. let first = true;
  18296. this.expect(5);
  18297. while (!this.eat(8)) {
  18298. if (first) {
  18299. first = false;
  18300. } else {
  18301. this.expect(12);
  18302. if (this.eat(8)) break;
  18303. }
  18304. const isMaybeTypeOnly = this.isContextual(130);
  18305. const isString = this.match(134);
  18306. const node = this.startNode();
  18307. node.local = this.parseModuleExportName();
  18308. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  18309. }
  18310. return nodes;
  18311. }
  18312. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  18313. if (this.eatContextual(93)) {
  18314. node.exported = this.parseModuleExportName();
  18315. } else if (isString) {
  18316. node.exported = this.cloneStringLiteral(node.local);
  18317. } else if (!node.exported) {
  18318. node.exported = this.cloneIdentifier(node.local);
  18319. }
  18320. return this.finishNode(node, "ExportSpecifier");
  18321. }
  18322. parseModuleExportName() {
  18323. if (this.match(134)) {
  18324. const result = this.parseStringLiteral(this.state.value);
  18325. const surrogate = loneSurrogate.exec(result.value);
  18326. if (surrogate) {
  18327. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  18328. surrogateCharCode: surrogate[0].charCodeAt(0)
  18329. });
  18330. }
  18331. return result;
  18332. }
  18333. return this.parseIdentifier(true);
  18334. }
  18335. isJSONModuleImport(node) {
  18336. if (node.assertions != null) {
  18337. return node.assertions.some(({
  18338. key,
  18339. value
  18340. }) => {
  18341. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  18342. });
  18343. }
  18344. return false;
  18345. }
  18346. checkImportReflection(node) {
  18347. const {
  18348. specifiers
  18349. } = node;
  18350. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  18351. if (node.phase === "source") {
  18352. if (singleBindingType !== "ImportDefaultSpecifier") {
  18353. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  18354. }
  18355. } else if (node.phase === "defer") {
  18356. if (singleBindingType !== "ImportNamespaceSpecifier") {
  18357. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  18358. }
  18359. } else if (node.module) {
  18360. var _node$assertions;
  18361. if (singleBindingType !== "ImportDefaultSpecifier") {
  18362. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  18363. }
  18364. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  18365. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  18366. }
  18367. }
  18368. }
  18369. checkJSONModuleImport(node) {
  18370. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  18371. const {
  18372. specifiers
  18373. } = node;
  18374. if (specifiers != null) {
  18375. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  18376. let imported;
  18377. if (specifier.type === "ExportSpecifier") {
  18378. imported = specifier.local;
  18379. } else if (specifier.type === "ImportSpecifier") {
  18380. imported = specifier.imported;
  18381. }
  18382. if (imported !== undefined) {
  18383. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  18384. }
  18385. });
  18386. if (nonDefaultNamedSpecifier !== undefined) {
  18387. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  18388. }
  18389. }
  18390. }
  18391. }
  18392. isPotentialImportPhase(isExport) {
  18393. if (isExport) return false;
  18394. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  18395. }
  18396. applyImportPhase(node, isExport, phase, loc) {
  18397. if (isExport) {
  18398. return;
  18399. }
  18400. if (phase === "module") {
  18401. this.expectPlugin("importReflection", loc);
  18402. node.module = true;
  18403. } else if (this.hasPlugin("importReflection")) {
  18404. node.module = false;
  18405. }
  18406. if (phase === "source") {
  18407. this.expectPlugin("sourcePhaseImports", loc);
  18408. node.phase = "source";
  18409. } else if (phase === "defer") {
  18410. this.expectPlugin("deferredImportEvaluation", loc);
  18411. node.phase = "defer";
  18412. } else if (this.hasPlugin("sourcePhaseImports")) {
  18413. node.phase = null;
  18414. }
  18415. }
  18416. parseMaybeImportPhase(node, isExport) {
  18417. if (!this.isPotentialImportPhase(isExport)) {
  18418. this.applyImportPhase(node, isExport, null);
  18419. return null;
  18420. }
  18421. const phaseIdentifier = this.startNode();
  18422. const phaseIdentifierName = this.parseIdentifierName(true);
  18423. const {
  18424. type
  18425. } = this.state;
  18426. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  18427. if (isImportPhase) {
  18428. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  18429. return null;
  18430. } else {
  18431. this.applyImportPhase(node, isExport, null);
  18432. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  18433. }
  18434. }
  18435. isPrecedingIdImportPhase(phase) {
  18436. const {
  18437. type
  18438. } = this.state;
  18439. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  18440. }
  18441. parseImport(node) {
  18442. if (this.match(134)) {
  18443. return this.parseImportSourceAndAttributes(node);
  18444. }
  18445. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  18446. }
  18447. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  18448. node.specifiers = [];
  18449. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  18450. const parseNext = !hasDefault || this.eat(12);
  18451. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  18452. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  18453. this.expectContextual(98);
  18454. return this.parseImportSourceAndAttributes(node);
  18455. }
  18456. parseImportSourceAndAttributes(node) {
  18457. var _node$specifiers2;
  18458. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  18459. node.source = this.parseImportSource();
  18460. this.maybeParseImportAttributes(node);
  18461. this.checkImportReflection(node);
  18462. this.checkJSONModuleImport(node);
  18463. this.semicolon();
  18464. this.sawUnambiguousESM = true;
  18465. return this.finishNode(node, "ImportDeclaration");
  18466. }
  18467. parseImportSource() {
  18468. if (!this.match(134)) this.unexpected();
  18469. return this.parseExprAtom();
  18470. }
  18471. parseImportSpecifierLocal(node, specifier, type) {
  18472. specifier.local = this.parseIdentifier();
  18473. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  18474. }
  18475. finishImportSpecifier(specifier, type, bindingType = 8201) {
  18476. this.checkLVal(specifier.local, {
  18477. type
  18478. }, bindingType);
  18479. return this.finishNode(specifier, type);
  18480. }
  18481. parseImportAttributes() {
  18482. this.expect(5);
  18483. const attrs = [];
  18484. const attrNames = new Set();
  18485. do {
  18486. if (this.match(8)) {
  18487. break;
  18488. }
  18489. const node = this.startNode();
  18490. const keyName = this.state.value;
  18491. if (attrNames.has(keyName)) {
  18492. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  18493. key: keyName
  18494. });
  18495. }
  18496. attrNames.add(keyName);
  18497. if (this.match(134)) {
  18498. node.key = this.parseStringLiteral(keyName);
  18499. } else {
  18500. node.key = this.parseIdentifier(true);
  18501. }
  18502. this.expect(14);
  18503. if (!this.match(134)) {
  18504. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  18505. }
  18506. node.value = this.parseStringLiteral(this.state.value);
  18507. attrs.push(this.finishNode(node, "ImportAttribute"));
  18508. } while (this.eat(12));
  18509. this.expect(8);
  18510. return attrs;
  18511. }
  18512. parseModuleAttributes() {
  18513. const attrs = [];
  18514. const attributes = new Set();
  18515. do {
  18516. const node = this.startNode();
  18517. node.key = this.parseIdentifier(true);
  18518. if (node.key.name !== "type") {
  18519. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  18520. }
  18521. if (attributes.has(node.key.name)) {
  18522. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  18523. key: node.key.name
  18524. });
  18525. }
  18526. attributes.add(node.key.name);
  18527. this.expect(14);
  18528. if (!this.match(134)) {
  18529. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  18530. }
  18531. node.value = this.parseStringLiteral(this.state.value);
  18532. attrs.push(this.finishNode(node, "ImportAttribute"));
  18533. } while (this.eat(12));
  18534. return attrs;
  18535. }
  18536. maybeParseImportAttributes(node) {
  18537. let attributes;
  18538. var useWith = false;
  18539. if (this.match(76)) {
  18540. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  18541. return;
  18542. }
  18543. this.next();
  18544. if (this.hasPlugin("moduleAttributes")) {
  18545. attributes = this.parseModuleAttributes();
  18546. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  18547. } else {
  18548. attributes = this.parseImportAttributes();
  18549. }
  18550. useWith = true;
  18551. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  18552. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  18553. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  18554. }
  18555. if (!this.hasPlugin("importAssertions")) {
  18556. this.addExtra(node, "deprecatedAssertSyntax", true);
  18557. }
  18558. this.next();
  18559. attributes = this.parseImportAttributes();
  18560. } else {
  18561. attributes = [];
  18562. }
  18563. if (!useWith && this.hasPlugin("importAssertions")) {
  18564. node.assertions = attributes;
  18565. } else {
  18566. node.attributes = attributes;
  18567. }
  18568. }
  18569. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  18570. if (maybeDefaultIdentifier) {
  18571. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  18572. specifier.local = maybeDefaultIdentifier;
  18573. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  18574. return true;
  18575. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  18576. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  18577. return true;
  18578. }
  18579. return false;
  18580. }
  18581. maybeParseStarImportSpecifier(node) {
  18582. if (this.match(55)) {
  18583. const specifier = this.startNode();
  18584. this.next();
  18585. this.expectContextual(93);
  18586. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  18587. return true;
  18588. }
  18589. return false;
  18590. }
  18591. parseNamedImportSpecifiers(node) {
  18592. let first = true;
  18593. this.expect(5);
  18594. while (!this.eat(8)) {
  18595. if (first) {
  18596. first = false;
  18597. } else {
  18598. if (this.eat(14)) {
  18599. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  18600. }
  18601. this.expect(12);
  18602. if (this.eat(8)) break;
  18603. }
  18604. const specifier = this.startNode();
  18605. const importedIsString = this.match(134);
  18606. const isMaybeTypeOnly = this.isContextual(130);
  18607. specifier.imported = this.parseModuleExportName();
  18608. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  18609. node.specifiers.push(importSpecifier);
  18610. }
  18611. }
  18612. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  18613. if (this.eatContextual(93)) {
  18614. specifier.local = this.parseIdentifier();
  18615. } else {
  18616. const {
  18617. imported
  18618. } = specifier;
  18619. if (importedIsString) {
  18620. throw this.raise(Errors.ImportBindingIsString, specifier, {
  18621. importName: imported.value
  18622. });
  18623. }
  18624. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  18625. if (!specifier.local) {
  18626. specifier.local = this.cloneIdentifier(imported);
  18627. }
  18628. }
  18629. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  18630. }
  18631. isThisParam(param) {
  18632. return param.type === "Identifier" && param.name === "this";
  18633. }
  18634. }
  18635. class Parser extends StatementParser {
  18636. constructor(options, input, pluginsMap) {
  18637. const normalizedOptions = getOptions(options);
  18638. super(normalizedOptions, input);
  18639. this.options = normalizedOptions;
  18640. this.initializeScopes();
  18641. this.plugins = pluginsMap;
  18642. this.filename = normalizedOptions.sourceFilename;
  18643. this.startIndex = normalizedOptions.startIndex;
  18644. let optionFlags = 0;
  18645. if (normalizedOptions.allowAwaitOutsideFunction) {
  18646. optionFlags |= 1;
  18647. }
  18648. if (normalizedOptions.allowReturnOutsideFunction) {
  18649. optionFlags |= 2;
  18650. }
  18651. if (normalizedOptions.allowImportExportEverywhere) {
  18652. optionFlags |= 8;
  18653. }
  18654. if (normalizedOptions.allowSuperOutsideMethod) {
  18655. optionFlags |= 16;
  18656. }
  18657. if (normalizedOptions.allowUndeclaredExports) {
  18658. optionFlags |= 64;
  18659. }
  18660. if (normalizedOptions.allowNewTargetOutsideFunction) {
  18661. optionFlags |= 4;
  18662. }
  18663. if (normalizedOptions.allowYieldOutsideFunction) {
  18664. optionFlags |= 32;
  18665. }
  18666. if (normalizedOptions.ranges) {
  18667. optionFlags |= 128;
  18668. }
  18669. if (normalizedOptions.tokens) {
  18670. optionFlags |= 256;
  18671. }
  18672. if (normalizedOptions.createImportExpressions) {
  18673. optionFlags |= 512;
  18674. }
  18675. if (normalizedOptions.createParenthesizedExpressions) {
  18676. optionFlags |= 1024;
  18677. }
  18678. if (normalizedOptions.errorRecovery) {
  18679. optionFlags |= 2048;
  18680. }
  18681. if (normalizedOptions.attachComment) {
  18682. optionFlags |= 4096;
  18683. }
  18684. if (normalizedOptions.annexB) {
  18685. optionFlags |= 8192;
  18686. }
  18687. this.optionFlags = optionFlags;
  18688. }
  18689. getScopeHandler() {
  18690. return ScopeHandler;
  18691. }
  18692. parse() {
  18693. this.enterInitialScopes();
  18694. const file = this.startNode();
  18695. const program = this.startNode();
  18696. this.nextToken();
  18697. file.errors = null;
  18698. const result = this.parseTopLevel(file, program);
  18699. result.errors = this.state.errors;
  18700. result.comments.length = this.state.commentsLen;
  18701. return result;
  18702. }
  18703. }
  18704. function parse(input, options) {
  18705. var _options;
  18706. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  18707. options = Object.assign({}, options);
  18708. try {
  18709. options.sourceType = "module";
  18710. const parser = getParser(options, input);
  18711. const ast = parser.parse();
  18712. if (parser.sawUnambiguousESM) {
  18713. return ast;
  18714. }
  18715. if (parser.ambiguousScriptDifferentAst) {
  18716. try {
  18717. options.sourceType = "script";
  18718. return getParser(options, input).parse();
  18719. } catch (_unused) {}
  18720. } else {
  18721. ast.program.sourceType = "script";
  18722. }
  18723. return ast;
  18724. } catch (moduleError) {
  18725. try {
  18726. options.sourceType = "script";
  18727. return getParser(options, input).parse();
  18728. } catch (_unused2) {}
  18729. throw moduleError;
  18730. }
  18731. } else {
  18732. return getParser(options, input).parse();
  18733. }
  18734. }
  18735. function parseExpression(input, options) {
  18736. const parser = getParser(options, input);
  18737. if (parser.options.strictMode) {
  18738. parser.state.strict = true;
  18739. }
  18740. return parser.getExpression();
  18741. }
  18742. function generateExportedTokenTypes(internalTokenTypes) {
  18743. const tokenTypes = {};
  18744. for (const typeName of Object.keys(internalTokenTypes)) {
  18745. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  18746. }
  18747. return tokenTypes;
  18748. }
  18749. const tokTypes = generateExportedTokenTypes(tt);
  18750. function getParser(options, input) {
  18751. let cls = Parser;
  18752. const pluginsMap = new Map();
  18753. if (options != null && options.plugins) {
  18754. for (const plugin of options.plugins) {
  18755. let name, opts;
  18756. if (typeof plugin === "string") {
  18757. name = plugin;
  18758. } else {
  18759. [name, opts] = plugin;
  18760. }
  18761. if (!pluginsMap.has(name)) {
  18762. pluginsMap.set(name, opts || {});
  18763. }
  18764. }
  18765. validatePlugins(pluginsMap);
  18766. cls = getParserClass(pluginsMap);
  18767. }
  18768. return new cls(options, input, pluginsMap);
  18769. }
  18770. const parserClassCache = new Map();
  18771. function getParserClass(pluginsMap) {
  18772. const pluginList = [];
  18773. for (const name of mixinPluginNames) {
  18774. if (pluginsMap.has(name)) {
  18775. pluginList.push(name);
  18776. }
  18777. }
  18778. const key = pluginList.join("|");
  18779. let cls = parserClassCache.get(key);
  18780. if (!cls) {
  18781. cls = Parser;
  18782. for (const plugin of pluginList) {
  18783. cls = mixinPlugins[plugin](cls);
  18784. }
  18785. parserClassCache.set(key, cls);
  18786. }
  18787. return cls;
  18788. }
  18789. lib.parse = parse;
  18790. lib.parseExpression = parseExpression;
  18791. lib.tokTypes = tokTypes;
  18792. return lib;
  18793. }
  18794. var libExports = /*@__PURE__*/ requireLib();
  18795. // @ts-check
  18796. /** @typedef { import('estree').BaseNode} BaseNode */
  18797. /** @typedef {{
  18798. skip: () => void;
  18799. remove: () => void;
  18800. replace: (node: BaseNode) => void;
  18801. }} WalkerContext */
  18802. class WalkerBase {
  18803. constructor() {
  18804. /** @type {boolean} */
  18805. this.should_skip = false;
  18806. /** @type {boolean} */
  18807. this.should_remove = false;
  18808. /** @type {BaseNode | null} */
  18809. this.replacement = null;
  18810. /** @type {WalkerContext} */
  18811. this.context = {
  18812. skip: () => (this.should_skip = true),
  18813. remove: () => (this.should_remove = true),
  18814. replace: (node) => (this.replacement = node)
  18815. };
  18816. }
  18817. /**
  18818. *
  18819. * @param {any} parent
  18820. * @param {string} prop
  18821. * @param {number} index
  18822. * @param {BaseNode} node
  18823. */
  18824. replace(parent, prop, index, node) {
  18825. if (parent) {
  18826. if (index !== null) {
  18827. parent[prop][index] = node;
  18828. } else {
  18829. parent[prop] = node;
  18830. }
  18831. }
  18832. }
  18833. /**
  18834. *
  18835. * @param {any} parent
  18836. * @param {string} prop
  18837. * @param {number} index
  18838. */
  18839. remove(parent, prop, index) {
  18840. if (parent) {
  18841. if (index !== null) {
  18842. parent[prop].splice(index, 1);
  18843. } else {
  18844. delete parent[prop];
  18845. }
  18846. }
  18847. }
  18848. }
  18849. // @ts-check
  18850. /** @typedef { import('estree').BaseNode} BaseNode */
  18851. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  18852. /** @typedef {(
  18853. * this: WalkerContext,
  18854. * node: BaseNode,
  18855. * parent: BaseNode,
  18856. * key: string,
  18857. * index: number
  18858. * ) => void} SyncHandler */
  18859. class SyncWalker extends WalkerBase {
  18860. /**
  18861. *
  18862. * @param {SyncHandler} enter
  18863. * @param {SyncHandler} leave
  18864. */
  18865. constructor(enter, leave) {
  18866. super();
  18867. /** @type {SyncHandler} */
  18868. this.enter = enter;
  18869. /** @type {SyncHandler} */
  18870. this.leave = leave;
  18871. }
  18872. /**
  18873. *
  18874. * @param {BaseNode} node
  18875. * @param {BaseNode} parent
  18876. * @param {string} [prop]
  18877. * @param {number} [index]
  18878. * @returns {BaseNode}
  18879. */
  18880. visit(node, parent, prop, index) {
  18881. if (node) {
  18882. if (this.enter) {
  18883. const _should_skip = this.should_skip;
  18884. const _should_remove = this.should_remove;
  18885. const _replacement = this.replacement;
  18886. this.should_skip = false;
  18887. this.should_remove = false;
  18888. this.replacement = null;
  18889. this.enter.call(this.context, node, parent, prop, index);
  18890. if (this.replacement) {
  18891. node = this.replacement;
  18892. this.replace(parent, prop, index, node);
  18893. }
  18894. if (this.should_remove) {
  18895. this.remove(parent, prop, index);
  18896. }
  18897. const skipped = this.should_skip;
  18898. const removed = this.should_remove;
  18899. this.should_skip = _should_skip;
  18900. this.should_remove = _should_remove;
  18901. this.replacement = _replacement;
  18902. if (skipped) return node;
  18903. if (removed) return null;
  18904. }
  18905. for (const key in node) {
  18906. const value = node[key];
  18907. if (typeof value !== "object") {
  18908. continue;
  18909. } else if (Array.isArray(value)) {
  18910. for (let i = 0; i < value.length; i += 1) {
  18911. if (value[i] !== null && typeof value[i].type === 'string') {
  18912. if (!this.visit(value[i], node, key, i)) {
  18913. // removed
  18914. i--;
  18915. }
  18916. }
  18917. }
  18918. } else if (value !== null && typeof value.type === "string") {
  18919. this.visit(value, node, key, null);
  18920. }
  18921. }
  18922. if (this.leave) {
  18923. const _replacement = this.replacement;
  18924. const _should_remove = this.should_remove;
  18925. this.replacement = null;
  18926. this.should_remove = false;
  18927. this.leave.call(this.context, node, parent, prop, index);
  18928. if (this.replacement) {
  18929. node = this.replacement;
  18930. this.replace(parent, prop, index, node);
  18931. }
  18932. if (this.should_remove) {
  18933. this.remove(parent, prop, index);
  18934. }
  18935. const removed = this.should_remove;
  18936. this.replacement = _replacement;
  18937. this.should_remove = _should_remove;
  18938. if (removed) return null;
  18939. }
  18940. }
  18941. return node;
  18942. }
  18943. }
  18944. // @ts-check
  18945. /** @typedef { import('estree').BaseNode} BaseNode */
  18946. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  18947. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  18948. /**
  18949. *
  18950. * @param {BaseNode} ast
  18951. * @param {{
  18952. * enter?: SyncHandler
  18953. * leave?: SyncHandler
  18954. * }} walker
  18955. * @returns {BaseNode}
  18956. */
  18957. function walk$2(ast, { enter, leave }) {
  18958. const instance = new SyncWalker(enter, leave);
  18959. return instance.visit(ast, null);
  18960. }
  18961. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  18962. const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
  18963. walk$2(root, {
  18964. enter(node, parent) {
  18965. parent && parentStack.push(parent);
  18966. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  18967. return this.skip();
  18968. }
  18969. if (node.type === "Identifier") {
  18970. const isLocal = !!knownIds[node.name];
  18971. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  18972. if (includeAll || isRefed && !isLocal) {
  18973. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  18974. }
  18975. } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
  18976. (parent == null ? void 0 : parent.type) === "ObjectPattern") {
  18977. node.inPattern = true;
  18978. } else if (isFunctionType(node)) {
  18979. if (node.scopeIds) {
  18980. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  18981. } else {
  18982. walkFunctionParams(
  18983. node,
  18984. (id) => markScopeIdentifier(node, id, knownIds)
  18985. );
  18986. }
  18987. } else if (node.type === "BlockStatement") {
  18988. if (node.scopeIds) {
  18989. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  18990. } else {
  18991. walkBlockDeclarations(
  18992. node,
  18993. (id) => markScopeIdentifier(node, id, knownIds)
  18994. );
  18995. }
  18996. } else if (node.type === "SwitchStatement") {
  18997. if (node.scopeIds) {
  18998. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  18999. } else {
  19000. walkSwitchStatement(
  19001. node,
  19002. false,
  19003. (id) => markScopeIdentifier(node, id, knownIds)
  19004. );
  19005. }
  19006. } else if (node.type === "CatchClause" && node.param) {
  19007. if (node.scopeIds) {
  19008. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19009. } else {
  19010. for (const id of extractIdentifiers$1(node.param)) {
  19011. markScopeIdentifier(node, id, knownIds);
  19012. }
  19013. }
  19014. } else if (isForStatement(node)) {
  19015. if (node.scopeIds) {
  19016. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  19017. } else {
  19018. walkForStatement(
  19019. node,
  19020. false,
  19021. (id) => markScopeIdentifier(node, id, knownIds)
  19022. );
  19023. }
  19024. }
  19025. },
  19026. leave(node, parent) {
  19027. parent && parentStack.pop();
  19028. if (node !== rootExp && node.scopeIds) {
  19029. for (const id of node.scopeIds) {
  19030. knownIds[id]--;
  19031. if (knownIds[id] === 0) {
  19032. delete knownIds[id];
  19033. }
  19034. }
  19035. }
  19036. }
  19037. });
  19038. }
  19039. function isReferencedIdentifier(id, parent, parentStack) {
  19040. if (!parent) {
  19041. return true;
  19042. }
  19043. if (id.name === "arguments") {
  19044. return false;
  19045. }
  19046. if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
  19047. return true;
  19048. }
  19049. switch (parent.type) {
  19050. case "AssignmentExpression":
  19051. case "AssignmentPattern":
  19052. return true;
  19053. case "ObjectProperty":
  19054. return parent.key !== id && isInDestructureAssignment(parent, parentStack);
  19055. case "ArrayPattern":
  19056. return isInDestructureAssignment(parent, parentStack);
  19057. }
  19058. return false;
  19059. }
  19060. function isInDestructureAssignment(parent, parentStack) {
  19061. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  19062. let i = parentStack.length;
  19063. while (i--) {
  19064. const p = parentStack[i];
  19065. if (p.type === "AssignmentExpression") {
  19066. return true;
  19067. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  19068. break;
  19069. }
  19070. }
  19071. }
  19072. return false;
  19073. }
  19074. function isInNewExpression(parentStack) {
  19075. let i = parentStack.length;
  19076. while (i--) {
  19077. const p = parentStack[i];
  19078. if (p.type === "NewExpression") {
  19079. return true;
  19080. } else if (p.type !== "MemberExpression") {
  19081. break;
  19082. }
  19083. }
  19084. return false;
  19085. }
  19086. function walkFunctionParams(node, onIdent) {
  19087. for (const p of node.params) {
  19088. for (const id of extractIdentifiers$1(p)) {
  19089. onIdent(id);
  19090. }
  19091. }
  19092. }
  19093. function walkBlockDeclarations(block, onIdent) {
  19094. const body = block.type === "SwitchCase" ? block.consequent : block.body;
  19095. for (const stmt of body) {
  19096. if (stmt.type === "VariableDeclaration") {
  19097. if (stmt.declare) continue;
  19098. for (const decl of stmt.declarations) {
  19099. for (const id of extractIdentifiers$1(decl.id)) {
  19100. onIdent(id);
  19101. }
  19102. }
  19103. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  19104. if (stmt.declare || !stmt.id) continue;
  19105. onIdent(stmt.id);
  19106. } else if (isForStatement(stmt)) {
  19107. walkForStatement(stmt, true, onIdent);
  19108. } else if (stmt.type === "SwitchStatement") {
  19109. walkSwitchStatement(stmt, true, onIdent);
  19110. }
  19111. }
  19112. }
  19113. function isForStatement(stmt) {
  19114. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  19115. }
  19116. function walkForStatement(stmt, isVar, onIdent) {
  19117. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  19118. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  19119. for (const decl of variable.declarations) {
  19120. for (const id of extractIdentifiers$1(decl.id)) {
  19121. onIdent(id);
  19122. }
  19123. }
  19124. }
  19125. }
  19126. function walkSwitchStatement(stmt, isVar, onIdent) {
  19127. for (const cs of stmt.cases) {
  19128. for (const stmt2 of cs.consequent) {
  19129. if (stmt2.type === "VariableDeclaration" && (stmt2.kind === "var" ? isVar : !isVar)) {
  19130. for (const decl of stmt2.declarations) {
  19131. for (const id of extractIdentifiers$1(decl.id)) {
  19132. onIdent(id);
  19133. }
  19134. }
  19135. }
  19136. }
  19137. walkBlockDeclarations(cs, onIdent);
  19138. }
  19139. }
  19140. function extractIdentifiers$1(param, nodes = []) {
  19141. switch (param.type) {
  19142. case "Identifier":
  19143. nodes.push(param);
  19144. break;
  19145. case "MemberExpression":
  19146. let object = param;
  19147. while (object.type === "MemberExpression") {
  19148. object = object.object;
  19149. }
  19150. nodes.push(object);
  19151. break;
  19152. case "ObjectPattern":
  19153. for (const prop of param.properties) {
  19154. if (prop.type === "RestElement") {
  19155. extractIdentifiers$1(prop.argument, nodes);
  19156. } else {
  19157. extractIdentifiers$1(prop.value, nodes);
  19158. }
  19159. }
  19160. break;
  19161. case "ArrayPattern":
  19162. param.elements.forEach((element) => {
  19163. if (element) extractIdentifiers$1(element, nodes);
  19164. });
  19165. break;
  19166. case "RestElement":
  19167. extractIdentifiers$1(param.argument, nodes);
  19168. break;
  19169. case "AssignmentPattern":
  19170. extractIdentifiers$1(param.left, nodes);
  19171. break;
  19172. }
  19173. return nodes;
  19174. }
  19175. function markKnownIds(name, knownIds) {
  19176. if (name in knownIds) {
  19177. knownIds[name]++;
  19178. } else {
  19179. knownIds[name] = 1;
  19180. }
  19181. }
  19182. function markScopeIdentifier(node, child, knownIds) {
  19183. const { name } = child;
  19184. if (node.scopeIds && node.scopeIds.has(name)) {
  19185. return;
  19186. }
  19187. markKnownIds(name, knownIds);
  19188. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  19189. }
  19190. const isFunctionType = (node) => {
  19191. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  19192. };
  19193. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  19194. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  19195. function isReferenced(node, parent, grandparent) {
  19196. switch (parent.type) {
  19197. // yes: PARENT[NODE]
  19198. // yes: NODE.child
  19199. // no: parent.NODE
  19200. case "MemberExpression":
  19201. case "OptionalMemberExpression":
  19202. if (parent.property === node) {
  19203. return !!parent.computed;
  19204. }
  19205. return parent.object === node;
  19206. case "JSXMemberExpression":
  19207. return parent.object === node;
  19208. // no: let NODE = init;
  19209. // yes: let id = NODE;
  19210. case "VariableDeclarator":
  19211. return parent.init === node;
  19212. // yes: () => NODE
  19213. // no: (NODE) => {}
  19214. case "ArrowFunctionExpression":
  19215. return parent.body === node;
  19216. // no: class { #NODE; }
  19217. // no: class { get #NODE() {} }
  19218. // no: class { #NODE() {} }
  19219. // no: class { fn() { return this.#NODE; } }
  19220. case "PrivateName":
  19221. return false;
  19222. // no: class { NODE() {} }
  19223. // yes: class { [NODE]() {} }
  19224. // no: class { foo(NODE) {} }
  19225. case "ClassMethod":
  19226. case "ClassPrivateMethod":
  19227. case "ObjectMethod":
  19228. if (parent.key === node) {
  19229. return !!parent.computed;
  19230. }
  19231. return false;
  19232. // yes: { [NODE]: "" }
  19233. // no: { NODE: "" }
  19234. // depends: { NODE }
  19235. // depends: { key: NODE }
  19236. case "ObjectProperty":
  19237. if (parent.key === node) {
  19238. return !!parent.computed;
  19239. }
  19240. return !grandparent || grandparent.type !== "ObjectPattern";
  19241. // no: class { NODE = value; }
  19242. // yes: class { [NODE] = value; }
  19243. // yes: class { key = NODE; }
  19244. case "ClassProperty":
  19245. if (parent.key === node) {
  19246. return !!parent.computed;
  19247. }
  19248. return true;
  19249. case "ClassPrivateProperty":
  19250. return parent.key !== node;
  19251. // no: class NODE {}
  19252. // yes: class Foo extends NODE {}
  19253. case "ClassDeclaration":
  19254. case "ClassExpression":
  19255. return parent.superClass === node;
  19256. // yes: left = NODE;
  19257. // no: NODE = right;
  19258. case "AssignmentExpression":
  19259. return parent.right === node;
  19260. // no: [NODE = foo] = [];
  19261. // yes: [foo = NODE] = [];
  19262. case "AssignmentPattern":
  19263. return parent.right === node;
  19264. // no: NODE: for (;;) {}
  19265. case "LabeledStatement":
  19266. return false;
  19267. // no: try {} catch (NODE) {}
  19268. case "CatchClause":
  19269. return false;
  19270. // no: function foo(...NODE) {}
  19271. case "RestElement":
  19272. return false;
  19273. case "BreakStatement":
  19274. case "ContinueStatement":
  19275. return false;
  19276. // no: function NODE() {}
  19277. // no: function foo(NODE) {}
  19278. case "FunctionDeclaration":
  19279. case "FunctionExpression":
  19280. return false;
  19281. // no: export NODE from "foo";
  19282. // no: export * as NODE from "foo";
  19283. case "ExportNamespaceSpecifier":
  19284. case "ExportDefaultSpecifier":
  19285. return false;
  19286. // no: export { foo as NODE };
  19287. // yes: export { NODE as foo };
  19288. // no: export { NODE as foo } from "foo";
  19289. case "ExportSpecifier":
  19290. if (grandparent == null ? void 0 : grandparent.source) {
  19291. return false;
  19292. }
  19293. return parent.local === node;
  19294. // no: import NODE from "foo";
  19295. // no: import * as NODE from "foo";
  19296. // no: import { NODE as foo } from "foo";
  19297. // no: import { foo as NODE } from "foo";
  19298. // no: import NODE from "bar";
  19299. case "ImportDefaultSpecifier":
  19300. case "ImportNamespaceSpecifier":
  19301. case "ImportSpecifier":
  19302. return false;
  19303. // no: import "foo" assert { NODE: "json" }
  19304. case "ImportAttribute":
  19305. return false;
  19306. // no: <div NODE="foo" />
  19307. case "JSXAttribute":
  19308. return false;
  19309. // no: [NODE] = [];
  19310. // no: ({ NODE }) = [];
  19311. case "ObjectPattern":
  19312. case "ArrayPattern":
  19313. return false;
  19314. // no: new.NODE
  19315. // no: NODE.target
  19316. case "MetaProperty":
  19317. return false;
  19318. // yes: type X = { someProperty: NODE }
  19319. // no: type X = { NODE: OtherType }
  19320. case "ObjectTypeProperty":
  19321. return parent.key !== node;
  19322. // yes: enum X { Foo = NODE }
  19323. // no: enum X { NODE }
  19324. case "TSEnumMember":
  19325. return parent.id !== node;
  19326. // yes: { [NODE]: value }
  19327. // no: { NODE: value }
  19328. case "TSPropertySignature":
  19329. if (parent.key === node) {
  19330. return !!parent.computed;
  19331. }
  19332. return true;
  19333. }
  19334. return true;
  19335. }
  19336. const TS_NODE_TYPES = [
  19337. "TSAsExpression",
  19338. // foo as number
  19339. "TSTypeAssertion",
  19340. // (<number>foo)
  19341. "TSNonNullExpression",
  19342. // foo!
  19343. "TSInstantiationExpression",
  19344. // foo<string>
  19345. "TSSatisfiesExpression"
  19346. // foo satisfies T
  19347. ];
  19348. function unwrapTSNode(node) {
  19349. if (TS_NODE_TYPES.includes(node.type)) {
  19350. return unwrapTSNode(node.expression);
  19351. } else {
  19352. return node;
  19353. }
  19354. }
  19355. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  19356. function isCoreComponent(tag) {
  19357. switch (tag) {
  19358. case "Teleport":
  19359. case "teleport":
  19360. return TELEPORT;
  19361. case "Suspense":
  19362. case "suspense":
  19363. return SUSPENSE;
  19364. case "KeepAlive":
  19365. case "keep-alive":
  19366. return KEEP_ALIVE;
  19367. case "BaseTransition":
  19368. case "base-transition":
  19369. return BASE_TRANSITION;
  19370. }
  19371. }
  19372. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  19373. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  19374. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  19375. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  19376. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  19377. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  19378. const isMemberExpressionBrowser = (exp) => {
  19379. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  19380. let state = 0 /* inMemberExp */;
  19381. let stateStack = [];
  19382. let currentOpenBracketCount = 0;
  19383. let currentOpenParensCount = 0;
  19384. let currentStringType = null;
  19385. for (let i = 0; i < path.length; i++) {
  19386. const char = path.charAt(i);
  19387. switch (state) {
  19388. case 0 /* inMemberExp */:
  19389. if (char === "[") {
  19390. stateStack.push(state);
  19391. state = 1 /* inBrackets */;
  19392. currentOpenBracketCount++;
  19393. } else if (char === "(") {
  19394. stateStack.push(state);
  19395. state = 2 /* inParens */;
  19396. currentOpenParensCount++;
  19397. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  19398. return false;
  19399. }
  19400. break;
  19401. case 1 /* inBrackets */:
  19402. if (char === `'` || char === `"` || char === "`") {
  19403. stateStack.push(state);
  19404. state = 3 /* inString */;
  19405. currentStringType = char;
  19406. } else if (char === `[`) {
  19407. currentOpenBracketCount++;
  19408. } else if (char === `]`) {
  19409. if (!--currentOpenBracketCount) {
  19410. state = stateStack.pop();
  19411. }
  19412. }
  19413. break;
  19414. case 2 /* inParens */:
  19415. if (char === `'` || char === `"` || char === "`") {
  19416. stateStack.push(state);
  19417. state = 3 /* inString */;
  19418. currentStringType = char;
  19419. } else if (char === `(`) {
  19420. currentOpenParensCount++;
  19421. } else if (char === `)`) {
  19422. if (i === path.length - 1) {
  19423. return false;
  19424. }
  19425. if (!--currentOpenParensCount) {
  19426. state = stateStack.pop();
  19427. }
  19428. }
  19429. break;
  19430. case 3 /* inString */:
  19431. if (char === currentStringType) {
  19432. state = stateStack.pop();
  19433. currentStringType = null;
  19434. }
  19435. break;
  19436. }
  19437. }
  19438. return !currentOpenBracketCount && !currentOpenParensCount;
  19439. };
  19440. const isMemberExpressionNode = (exp, context) => {
  19441. try {
  19442. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  19443. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  19444. });
  19445. ret = unwrapTSNode(ret);
  19446. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
  19447. } catch (e) {
  19448. return false;
  19449. }
  19450. };
  19451. const isMemberExpression = isMemberExpressionNode;
  19452. const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  19453. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  19454. const isFnExpressionNode = (exp, context) => {
  19455. try {
  19456. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  19457. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  19458. });
  19459. if (ret.type === "Program") {
  19460. ret = ret.body[0];
  19461. if (ret.type === "ExpressionStatement") {
  19462. ret = ret.expression;
  19463. }
  19464. }
  19465. ret = unwrapTSNode(ret);
  19466. return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
  19467. } catch (e) {
  19468. return false;
  19469. }
  19470. };
  19471. const isFnExpression = isFnExpressionNode;
  19472. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  19473. return advancePositionWithMutation(
  19474. {
  19475. offset: pos.offset,
  19476. line: pos.line,
  19477. column: pos.column
  19478. },
  19479. source,
  19480. numberOfCharacters
  19481. );
  19482. }
  19483. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  19484. let linesCount = 0;
  19485. let lastNewLinePos = -1;
  19486. for (let i = 0; i < numberOfCharacters; i++) {
  19487. if (source.charCodeAt(i) === 10) {
  19488. linesCount++;
  19489. lastNewLinePos = i;
  19490. }
  19491. }
  19492. pos.offset += numberOfCharacters;
  19493. pos.line += linesCount;
  19494. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  19495. return pos;
  19496. }
  19497. function assert(condition, msg) {
  19498. if (!condition) {
  19499. throw new Error(msg || `unexpected compiler condition`);
  19500. }
  19501. }
  19502. function findDir(node, name, allowEmpty = false) {
  19503. for (let i = 0; i < node.props.length; i++) {
  19504. const p = node.props[i];
  19505. if (p.type === 7 && (allowEmpty || p.exp) && (isString$1(name) ? p.name === name : name.test(p.name))) {
  19506. return p;
  19507. }
  19508. }
  19509. }
  19510. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  19511. for (let i = 0; i < node.props.length; i++) {
  19512. const p = node.props[i];
  19513. if (p.type === 6) {
  19514. if (dynamicOnly) continue;
  19515. if (p.name === name && (p.value || allowEmpty)) {
  19516. return p;
  19517. }
  19518. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  19519. return p;
  19520. }
  19521. }
  19522. }
  19523. function isStaticArgOf(arg, name) {
  19524. return !!(arg && isStaticExp(arg) && arg.content === name);
  19525. }
  19526. function hasDynamicKeyVBind(node) {
  19527. return node.props.some(
  19528. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  19529. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  19530. !p.arg.isStatic)
  19531. // v-bind:[foo]
  19532. );
  19533. }
  19534. function isText$1(node) {
  19535. return node.type === 5 || node.type === 2;
  19536. }
  19537. function isVPre(p) {
  19538. return p.type === 7 && p.name === "pre";
  19539. }
  19540. function isVSlot(p) {
  19541. return p.type === 7 && p.name === "slot";
  19542. }
  19543. function isTemplateNode(node) {
  19544. return node.type === 1 && node.tagType === 3;
  19545. }
  19546. function isSlotOutlet(node) {
  19547. return node.type === 1 && node.tagType === 2;
  19548. }
  19549. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  19550. function getUnnormalizedProps(props, callPath = []) {
  19551. if (props && !isString$1(props) && props.type === 14) {
  19552. const callee = props.callee;
  19553. if (!isString$1(callee) && propsHelperSet.has(callee)) {
  19554. return getUnnormalizedProps(
  19555. props.arguments[0],
  19556. callPath.concat(props)
  19557. );
  19558. }
  19559. }
  19560. return [props, callPath];
  19561. }
  19562. function injectProp(node, prop, context) {
  19563. let propsWithInjection;
  19564. let props = node.type === 13 ? node.props : node.arguments[2];
  19565. let callPath = [];
  19566. let parentCall;
  19567. if (props && !isString$1(props) && props.type === 14) {
  19568. const ret = getUnnormalizedProps(props);
  19569. props = ret[0];
  19570. callPath = ret[1];
  19571. parentCall = callPath[callPath.length - 1];
  19572. }
  19573. if (props == null || isString$1(props)) {
  19574. propsWithInjection = createObjectExpression([prop]);
  19575. } else if (props.type === 14) {
  19576. const first = props.arguments[0];
  19577. if (!isString$1(first) && first.type === 15) {
  19578. if (!hasProp(prop, first)) {
  19579. first.properties.unshift(prop);
  19580. }
  19581. } else {
  19582. if (props.callee === TO_HANDLERS) {
  19583. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  19584. createObjectExpression([prop]),
  19585. props
  19586. ]);
  19587. } else {
  19588. props.arguments.unshift(createObjectExpression([prop]));
  19589. }
  19590. }
  19591. !propsWithInjection && (propsWithInjection = props);
  19592. } else if (props.type === 15) {
  19593. if (!hasProp(prop, props)) {
  19594. props.properties.unshift(prop);
  19595. }
  19596. propsWithInjection = props;
  19597. } else {
  19598. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  19599. createObjectExpression([prop]),
  19600. props
  19601. ]);
  19602. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  19603. parentCall = callPath[callPath.length - 2];
  19604. }
  19605. }
  19606. if (node.type === 13) {
  19607. if (parentCall) {
  19608. parentCall.arguments[0] = propsWithInjection;
  19609. } else {
  19610. node.props = propsWithInjection;
  19611. }
  19612. } else {
  19613. if (parentCall) {
  19614. parentCall.arguments[0] = propsWithInjection;
  19615. } else {
  19616. node.arguments[2] = propsWithInjection;
  19617. }
  19618. }
  19619. }
  19620. function hasProp(prop, props) {
  19621. let result = false;
  19622. if (prop.key.type === 4) {
  19623. const propKeyName = prop.key.content;
  19624. result = props.properties.some(
  19625. (p) => p.key.type === 4 && p.key.content === propKeyName
  19626. );
  19627. }
  19628. return result;
  19629. }
  19630. function toValidAssetId(name, type) {
  19631. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  19632. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  19633. })}`;
  19634. }
  19635. function hasScopeRef(node, ids) {
  19636. if (!node || Object.keys(ids).length === 0) {
  19637. return false;
  19638. }
  19639. switch (node.type) {
  19640. case 1:
  19641. for (let i = 0; i < node.props.length; i++) {
  19642. const p = node.props[i];
  19643. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  19644. return true;
  19645. }
  19646. }
  19647. return node.children.some((c) => hasScopeRef(c, ids));
  19648. case 11:
  19649. if (hasScopeRef(node.source, ids)) {
  19650. return true;
  19651. }
  19652. return node.children.some((c) => hasScopeRef(c, ids));
  19653. case 9:
  19654. return node.branches.some((b) => hasScopeRef(b, ids));
  19655. case 10:
  19656. if (hasScopeRef(node.condition, ids)) {
  19657. return true;
  19658. }
  19659. return node.children.some((c) => hasScopeRef(c, ids));
  19660. case 4:
  19661. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  19662. case 8:
  19663. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  19664. case 5:
  19665. case 12:
  19666. return hasScopeRef(node.content, ids);
  19667. case 2:
  19668. case 3:
  19669. case 20:
  19670. return false;
  19671. default:
  19672. return false;
  19673. }
  19674. }
  19675. function getMemoedVNodeCall(node) {
  19676. if (node.type === 14 && node.callee === WITH_MEMO) {
  19677. return node.arguments[1].returns;
  19678. } else {
  19679. return node;
  19680. }
  19681. }
  19682. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  19683. function isAllWhitespace(str) {
  19684. for (let i = 0; i < str.length; i++) {
  19685. if (!isWhitespace(str.charCodeAt(i))) {
  19686. return false;
  19687. }
  19688. }
  19689. return true;
  19690. }
  19691. function isWhitespaceText(node) {
  19692. return node.type === 2 && isAllWhitespace(node.content) || node.type === 12 && isWhitespaceText(node.content);
  19693. }
  19694. function isCommentOrWhitespace(node) {
  19695. return node.type === 3 || isWhitespaceText(node);
  19696. }
  19697. const defaultParserOptions = {
  19698. parseMode: "base",
  19699. ns: 0,
  19700. delimiters: [`{{`, `}}`],
  19701. getNamespace: () => 0,
  19702. isVoidTag: NO,
  19703. isPreTag: NO,
  19704. isIgnoreNewlineTag: NO,
  19705. isCustomElement: NO,
  19706. onError: defaultOnError,
  19707. onWarn: defaultOnWarn,
  19708. comments: true,
  19709. prefixIdentifiers: false
  19710. };
  19711. let currentOptions = defaultParserOptions;
  19712. let currentRoot = null;
  19713. let currentInput = "";
  19714. let currentOpenTag = null;
  19715. let currentProp = null;
  19716. let currentAttrValue = "";
  19717. let currentAttrStartIndex = -1;
  19718. let currentAttrEndIndex = -1;
  19719. let inPre = 0;
  19720. let inVPre = false;
  19721. let currentVPreBoundary = null;
  19722. const stack = [];
  19723. const tokenizer = new Tokenizer(stack, {
  19724. onerr: emitError,
  19725. ontext(start, end) {
  19726. onText(getSlice(start, end), start, end);
  19727. },
  19728. ontextentity(char, start, end) {
  19729. onText(char, start, end);
  19730. },
  19731. oninterpolation(start, end) {
  19732. if (inVPre) {
  19733. return onText(getSlice(start, end), start, end);
  19734. }
  19735. let innerStart = start + tokenizer.delimiterOpen.length;
  19736. let innerEnd = end - tokenizer.delimiterClose.length;
  19737. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  19738. innerStart++;
  19739. }
  19740. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  19741. innerEnd--;
  19742. }
  19743. let exp = getSlice(innerStart, innerEnd);
  19744. if (exp.includes("&")) {
  19745. {
  19746. exp = decodeHTML(exp);
  19747. }
  19748. }
  19749. addNode({
  19750. type: 5,
  19751. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  19752. loc: getLoc(start, end)
  19753. });
  19754. },
  19755. onopentagname(start, end) {
  19756. const name = getSlice(start, end);
  19757. currentOpenTag = {
  19758. type: 1,
  19759. tag: name,
  19760. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  19761. tagType: 0,
  19762. // will be refined on tag close
  19763. props: [],
  19764. children: [],
  19765. loc: getLoc(start - 1, end),
  19766. codegenNode: void 0
  19767. };
  19768. },
  19769. onopentagend(end) {
  19770. endOpenTag(end);
  19771. },
  19772. onclosetag(start, end) {
  19773. const name = getSlice(start, end);
  19774. if (!currentOptions.isVoidTag(name)) {
  19775. let found = false;
  19776. for (let i = 0; i < stack.length; i++) {
  19777. const e = stack[i];
  19778. if (e.tag.toLowerCase() === name.toLowerCase()) {
  19779. found = true;
  19780. if (i > 0) {
  19781. emitError(24, stack[0].loc.start.offset);
  19782. }
  19783. for (let j = 0; j <= i; j++) {
  19784. const el = stack.shift();
  19785. onCloseTag(el, end, j < i);
  19786. }
  19787. break;
  19788. }
  19789. }
  19790. if (!found) {
  19791. emitError(23, backTrack(start, 60));
  19792. }
  19793. }
  19794. },
  19795. onselfclosingtag(end) {
  19796. const name = currentOpenTag.tag;
  19797. currentOpenTag.isSelfClosing = true;
  19798. endOpenTag(end);
  19799. if (stack[0] && stack[0].tag === name) {
  19800. onCloseTag(stack.shift(), end);
  19801. }
  19802. },
  19803. onattribname(start, end) {
  19804. currentProp = {
  19805. type: 6,
  19806. name: getSlice(start, end),
  19807. nameLoc: getLoc(start, end),
  19808. value: void 0,
  19809. loc: getLoc(start)
  19810. };
  19811. },
  19812. ondirname(start, end) {
  19813. const raw = getSlice(start, end);
  19814. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  19815. if (!inVPre && name === "") {
  19816. emitError(26, start);
  19817. }
  19818. if (inVPre || name === "") {
  19819. currentProp = {
  19820. type: 6,
  19821. name: raw,
  19822. nameLoc: getLoc(start, end),
  19823. value: void 0,
  19824. loc: getLoc(start)
  19825. };
  19826. } else {
  19827. currentProp = {
  19828. type: 7,
  19829. name,
  19830. rawName: raw,
  19831. exp: void 0,
  19832. arg: void 0,
  19833. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  19834. loc: getLoc(start)
  19835. };
  19836. if (name === "pre") {
  19837. inVPre = tokenizer.inVPre = true;
  19838. currentVPreBoundary = currentOpenTag;
  19839. const props = currentOpenTag.props;
  19840. for (let i = 0; i < props.length; i++) {
  19841. if (props[i].type === 7) {
  19842. props[i] = dirToAttr(props[i]);
  19843. }
  19844. }
  19845. }
  19846. }
  19847. },
  19848. ondirarg(start, end) {
  19849. if (start === end) return;
  19850. const arg = getSlice(start, end);
  19851. if (inVPre && !isVPre(currentProp)) {
  19852. currentProp.name += arg;
  19853. setLocEnd(currentProp.nameLoc, end);
  19854. } else {
  19855. const isStatic = arg[0] !== `[`;
  19856. currentProp.arg = createExp(
  19857. isStatic ? arg : arg.slice(1, -1),
  19858. isStatic,
  19859. getLoc(start, end),
  19860. isStatic ? 3 : 0
  19861. );
  19862. }
  19863. },
  19864. ondirmodifier(start, end) {
  19865. const mod = getSlice(start, end);
  19866. if (inVPre && !isVPre(currentProp)) {
  19867. currentProp.name += "." + mod;
  19868. setLocEnd(currentProp.nameLoc, end);
  19869. } else if (currentProp.name === "slot") {
  19870. const arg = currentProp.arg;
  19871. if (arg) {
  19872. arg.content += "." + mod;
  19873. setLocEnd(arg.loc, end);
  19874. }
  19875. } else {
  19876. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  19877. currentProp.modifiers.push(exp);
  19878. }
  19879. },
  19880. onattribdata(start, end) {
  19881. currentAttrValue += getSlice(start, end);
  19882. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  19883. currentAttrEndIndex = end;
  19884. },
  19885. onattribentity(char, start, end) {
  19886. currentAttrValue += char;
  19887. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  19888. currentAttrEndIndex = end;
  19889. },
  19890. onattribnameend(end) {
  19891. const start = currentProp.loc.start.offset;
  19892. const name = getSlice(start, end);
  19893. if (currentProp.type === 7) {
  19894. currentProp.rawName = name;
  19895. }
  19896. if (currentOpenTag.props.some(
  19897. (p) => (p.type === 7 ? p.rawName : p.name) === name
  19898. )) {
  19899. emitError(2, start);
  19900. }
  19901. },
  19902. onattribend(quote, end) {
  19903. if (currentOpenTag && currentProp) {
  19904. setLocEnd(currentProp.loc, end);
  19905. if (quote !== 0) {
  19906. if (currentProp.type === 6) {
  19907. if (currentProp.name === "class") {
  19908. currentAttrValue = condense(currentAttrValue).trim();
  19909. }
  19910. if (quote === 1 && !currentAttrValue) {
  19911. emitError(13, end);
  19912. }
  19913. currentProp.value = {
  19914. type: 2,
  19915. content: currentAttrValue,
  19916. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  19917. };
  19918. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  19919. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  19920. }
  19921. } else {
  19922. let expParseMode = 0 /* Normal */;
  19923. {
  19924. if (currentProp.name === "for") {
  19925. expParseMode = 3 /* Skip */;
  19926. } else if (currentProp.name === "slot") {
  19927. expParseMode = 1 /* Params */;
  19928. } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
  19929. expParseMode = 2 /* Statements */;
  19930. }
  19931. }
  19932. currentProp.exp = createExp(
  19933. currentAttrValue,
  19934. false,
  19935. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  19936. 0,
  19937. expParseMode
  19938. );
  19939. if (currentProp.name === "for") {
  19940. currentProp.forParseResult = parseForExpression(currentProp.exp);
  19941. }
  19942. }
  19943. }
  19944. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  19945. currentOpenTag.props.push(currentProp);
  19946. }
  19947. }
  19948. currentAttrValue = "";
  19949. currentAttrStartIndex = currentAttrEndIndex = -1;
  19950. },
  19951. oncomment(start, end) {
  19952. if (currentOptions.comments) {
  19953. addNode({
  19954. type: 3,
  19955. content: getSlice(start, end),
  19956. loc: getLoc(start - 4, end + 3)
  19957. });
  19958. }
  19959. },
  19960. onend() {
  19961. const end = currentInput.length;
  19962. if (tokenizer.state !== 1) {
  19963. switch (tokenizer.state) {
  19964. case 5:
  19965. case 8:
  19966. emitError(5, end);
  19967. break;
  19968. case 3:
  19969. case 4:
  19970. emitError(
  19971. 25,
  19972. tokenizer.sectionStart
  19973. );
  19974. break;
  19975. case 28:
  19976. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  19977. emitError(6, end);
  19978. } else {
  19979. emitError(7, end);
  19980. }
  19981. break;
  19982. case 6:
  19983. case 7:
  19984. case 9:
  19985. case 11:
  19986. case 12:
  19987. case 13:
  19988. case 14:
  19989. case 15:
  19990. case 16:
  19991. case 17:
  19992. case 18:
  19993. case 19:
  19994. // "
  19995. case 20:
  19996. // '
  19997. case 21:
  19998. emitError(9, end);
  19999. break;
  20000. }
  20001. }
  20002. for (let index = 0; index < stack.length; index++) {
  20003. onCloseTag(stack[index], end - 1);
  20004. emitError(24, stack[index].loc.start.offset);
  20005. }
  20006. },
  20007. oncdata(start, end) {
  20008. if (stack[0].ns !== 0) {
  20009. onText(getSlice(start, end), start, end);
  20010. } else {
  20011. emitError(1, start - 9);
  20012. }
  20013. },
  20014. onprocessinginstruction(start) {
  20015. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  20016. emitError(
  20017. 21,
  20018. start - 1
  20019. );
  20020. }
  20021. }
  20022. });
  20023. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  20024. const stripParensRE = /^\(|\)$/g;
  20025. function parseForExpression(input) {
  20026. const loc = input.loc;
  20027. const exp = input.content;
  20028. const inMatch = exp.match(forAliasRE);
  20029. if (!inMatch) return;
  20030. const [, LHS, RHS] = inMatch;
  20031. const createAliasExpression = (content, offset, asParam = false) => {
  20032. const start = loc.start.offset + offset;
  20033. const end = start + content.length;
  20034. return createExp(
  20035. content,
  20036. false,
  20037. getLoc(start, end),
  20038. 0,
  20039. asParam ? 1 /* Params */ : 0 /* Normal */
  20040. );
  20041. };
  20042. const result = {
  20043. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  20044. value: void 0,
  20045. key: void 0,
  20046. index: void 0,
  20047. finalized: false
  20048. };
  20049. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  20050. const trimmedOffset = LHS.indexOf(valueContent);
  20051. const iteratorMatch = valueContent.match(forIteratorRE);
  20052. if (iteratorMatch) {
  20053. valueContent = valueContent.replace(forIteratorRE, "").trim();
  20054. const keyContent = iteratorMatch[1].trim();
  20055. let keyOffset;
  20056. if (keyContent) {
  20057. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  20058. result.key = createAliasExpression(keyContent, keyOffset, true);
  20059. }
  20060. if (iteratorMatch[2]) {
  20061. const indexContent = iteratorMatch[2].trim();
  20062. if (indexContent) {
  20063. result.index = createAliasExpression(
  20064. indexContent,
  20065. exp.indexOf(
  20066. indexContent,
  20067. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  20068. ),
  20069. true
  20070. );
  20071. }
  20072. }
  20073. }
  20074. if (valueContent) {
  20075. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  20076. }
  20077. return result;
  20078. }
  20079. function getSlice(start, end) {
  20080. return currentInput.slice(start, end);
  20081. }
  20082. function endOpenTag(end) {
  20083. if (tokenizer.inSFCRoot) {
  20084. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  20085. }
  20086. addNode(currentOpenTag);
  20087. const { tag, ns } = currentOpenTag;
  20088. if (ns === 0 && currentOptions.isPreTag(tag)) {
  20089. inPre++;
  20090. }
  20091. if (currentOptions.isVoidTag(tag)) {
  20092. onCloseTag(currentOpenTag, end);
  20093. } else {
  20094. stack.unshift(currentOpenTag);
  20095. if (ns === 1 || ns === 2) {
  20096. tokenizer.inXML = true;
  20097. }
  20098. }
  20099. currentOpenTag = null;
  20100. }
  20101. function onText(content, start, end) {
  20102. const parent = stack[0] || currentRoot;
  20103. const lastNode = parent.children[parent.children.length - 1];
  20104. if (lastNode && lastNode.type === 2) {
  20105. lastNode.content += content;
  20106. setLocEnd(lastNode.loc, end);
  20107. } else {
  20108. parent.children.push({
  20109. type: 2,
  20110. content,
  20111. loc: getLoc(start, end)
  20112. });
  20113. }
  20114. }
  20115. function onCloseTag(el, end, isImplied = false) {
  20116. if (isImplied) {
  20117. setLocEnd(el.loc, backTrack(end, 60));
  20118. } else {
  20119. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  20120. }
  20121. if (tokenizer.inSFCRoot) {
  20122. if (el.children.length) {
  20123. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  20124. } else {
  20125. el.innerLoc.end = extend({}, el.innerLoc.start);
  20126. }
  20127. el.innerLoc.source = getSlice(
  20128. el.innerLoc.start.offset,
  20129. el.innerLoc.end.offset
  20130. );
  20131. }
  20132. const { tag, ns, children } = el;
  20133. if (!inVPre) {
  20134. if (tag === "slot") {
  20135. el.tagType = 2;
  20136. } else if (isFragmentTemplate(el)) {
  20137. el.tagType = 3;
  20138. } else if (isComponent(el)) {
  20139. el.tagType = 1;
  20140. }
  20141. }
  20142. if (!tokenizer.inRCDATA) {
  20143. el.children = condenseWhitespace(children);
  20144. }
  20145. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  20146. const first = children[0];
  20147. if (first && first.type === 2) {
  20148. first.content = first.content.replace(/^\r?\n/, "");
  20149. }
  20150. }
  20151. if (ns === 0 && currentOptions.isPreTag(tag)) {
  20152. inPre--;
  20153. }
  20154. if (currentVPreBoundary === el) {
  20155. inVPre = tokenizer.inVPre = false;
  20156. currentVPreBoundary = null;
  20157. }
  20158. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  20159. tokenizer.inXML = false;
  20160. }
  20161. }
  20162. function lookAhead(index, c) {
  20163. let i = index;
  20164. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  20165. return i;
  20166. }
  20167. function backTrack(index, c) {
  20168. let i = index;
  20169. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  20170. return i;
  20171. }
  20172. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  20173. function isFragmentTemplate({ tag, props }) {
  20174. if (tag === "template") {
  20175. for (let i = 0; i < props.length; i++) {
  20176. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  20177. return true;
  20178. }
  20179. }
  20180. }
  20181. return false;
  20182. }
  20183. function isComponent({ tag, props }) {
  20184. if (currentOptions.isCustomElement(tag)) {
  20185. return false;
  20186. }
  20187. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  20188. return true;
  20189. }
  20190. for (let i = 0; i < props.length; i++) {
  20191. const p = props[i];
  20192. if (p.type === 6) {
  20193. if (p.name === "is" && p.value) {
  20194. if (p.value.content.startsWith("vue:")) {
  20195. return true;
  20196. }
  20197. }
  20198. }
  20199. }
  20200. return false;
  20201. }
  20202. function isUpperCase(c) {
  20203. return c > 64 && c < 91;
  20204. }
  20205. const windowsNewlineRE = /\r\n/g;
  20206. function condenseWhitespace(nodes) {
  20207. const shouldCondense = currentOptions.whitespace !== "preserve";
  20208. let removedWhitespace = false;
  20209. for (let i = 0; i < nodes.length; i++) {
  20210. const node = nodes[i];
  20211. if (node.type === 2) {
  20212. if (!inPre) {
  20213. if (isAllWhitespace(node.content)) {
  20214. const prev = nodes[i - 1] && nodes[i - 1].type;
  20215. const next = nodes[i + 1] && nodes[i + 1].type;
  20216. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  20217. removedWhitespace = true;
  20218. nodes[i] = null;
  20219. } else {
  20220. node.content = " ";
  20221. }
  20222. } else if (shouldCondense) {
  20223. node.content = condense(node.content);
  20224. }
  20225. } else {
  20226. node.content = node.content.replace(windowsNewlineRE, "\n");
  20227. }
  20228. }
  20229. }
  20230. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  20231. }
  20232. function hasNewlineChar(str) {
  20233. for (let i = 0; i < str.length; i++) {
  20234. const c = str.charCodeAt(i);
  20235. if (c === 10 || c === 13) {
  20236. return true;
  20237. }
  20238. }
  20239. return false;
  20240. }
  20241. function condense(str) {
  20242. let ret = "";
  20243. let prevCharIsWhitespace = false;
  20244. for (let i = 0; i < str.length; i++) {
  20245. if (isWhitespace(str.charCodeAt(i))) {
  20246. if (!prevCharIsWhitespace) {
  20247. ret += " ";
  20248. prevCharIsWhitespace = true;
  20249. }
  20250. } else {
  20251. ret += str[i];
  20252. prevCharIsWhitespace = false;
  20253. }
  20254. }
  20255. return ret;
  20256. }
  20257. function addNode(node) {
  20258. (stack[0] || currentRoot).children.push(node);
  20259. }
  20260. function getLoc(start, end) {
  20261. return {
  20262. start: tokenizer.getPos(start),
  20263. // @ts-expect-error allow late attachment
  20264. end: end == null ? end : tokenizer.getPos(end),
  20265. // @ts-expect-error allow late attachment
  20266. source: end == null ? end : getSlice(start, end)
  20267. };
  20268. }
  20269. function cloneLoc(loc) {
  20270. return getLoc(loc.start.offset, loc.end.offset);
  20271. }
  20272. function setLocEnd(loc, end) {
  20273. loc.end = tokenizer.getPos(end);
  20274. loc.source = getSlice(loc.start.offset, end);
  20275. }
  20276. function dirToAttr(dir) {
  20277. const attr = {
  20278. type: 6,
  20279. name: dir.rawName,
  20280. nameLoc: getLoc(
  20281. dir.loc.start.offset,
  20282. dir.loc.start.offset + dir.rawName.length
  20283. ),
  20284. value: void 0,
  20285. loc: dir.loc
  20286. };
  20287. if (dir.exp) {
  20288. const loc = dir.exp.loc;
  20289. if (loc.end.offset < dir.loc.end.offset) {
  20290. loc.start.offset--;
  20291. loc.start.column--;
  20292. loc.end.offset++;
  20293. loc.end.column++;
  20294. }
  20295. attr.value = {
  20296. type: 2,
  20297. content: dir.exp.content,
  20298. loc
  20299. };
  20300. }
  20301. return attr;
  20302. }
  20303. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  20304. const exp = createSimpleExpression(content, isStatic, loc, constType);
  20305. if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
  20306. if (isSimpleIdentifier(content)) {
  20307. exp.ast = null;
  20308. return exp;
  20309. }
  20310. try {
  20311. const plugins = currentOptions.expressionPlugins;
  20312. const options = {
  20313. plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
  20314. };
  20315. if (parseMode === 2 /* Statements */) {
  20316. exp.ast = libExports.parse(` ${content} `, options).program;
  20317. } else if (parseMode === 1 /* Params */) {
  20318. exp.ast = libExports.parseExpression(`(${content})=>{}`, options);
  20319. } else {
  20320. exp.ast = libExports.parseExpression(`(${content})`, options);
  20321. }
  20322. } catch (e) {
  20323. exp.ast = false;
  20324. emitError(46, loc.start.offset, e.message);
  20325. }
  20326. }
  20327. return exp;
  20328. }
  20329. function emitError(code, index, message) {
  20330. currentOptions.onError(
  20331. createCompilerError(code, getLoc(index, index), void 0, message)
  20332. );
  20333. }
  20334. function reset() {
  20335. tokenizer.reset();
  20336. currentOpenTag = null;
  20337. currentProp = null;
  20338. currentAttrValue = "";
  20339. currentAttrStartIndex = -1;
  20340. currentAttrEndIndex = -1;
  20341. stack.length = 0;
  20342. }
  20343. function baseParse(input, options) {
  20344. reset();
  20345. currentInput = input;
  20346. currentOptions = extend({}, defaultParserOptions);
  20347. if (options) {
  20348. let key;
  20349. for (key in options) {
  20350. if (options[key] != null) {
  20351. currentOptions[key] = options[key];
  20352. }
  20353. }
  20354. }
  20355. {
  20356. if (currentOptions.decodeEntities) {
  20357. console.warn(
  20358. `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
  20359. );
  20360. }
  20361. }
  20362. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  20363. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  20364. const delimiters = options && options.delimiters;
  20365. if (delimiters) {
  20366. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  20367. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  20368. }
  20369. const root = currentRoot = createRoot([], input);
  20370. tokenizer.parse(currentInput);
  20371. root.loc = getLoc(0, input.length);
  20372. root.children = condenseWhitespace(root.children);
  20373. currentRoot = null;
  20374. return root;
  20375. }
  20376. function cacheStatic(root, context) {
  20377. walk$1(
  20378. root,
  20379. void 0,
  20380. context,
  20381. // Root node is unfortunately non-hoistable due to potential parent
  20382. // fallthrough attributes.
  20383. !!getSingleElementRoot(root)
  20384. );
  20385. }
  20386. function getSingleElementRoot(root) {
  20387. const children = root.children.filter((x) => x.type !== 3);
  20388. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  20389. }
  20390. function walk$1(node, parent, context, doNotHoistNode = false, inFor = false) {
  20391. const { children } = node;
  20392. const toCache = [];
  20393. for (let i = 0; i < children.length; i++) {
  20394. const child = children[i];
  20395. if (child.type === 1 && child.tagType === 0) {
  20396. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  20397. if (constantType > 0) {
  20398. if (constantType >= 2) {
  20399. child.codegenNode.patchFlag = -1;
  20400. toCache.push(child);
  20401. continue;
  20402. }
  20403. } else {
  20404. const codegenNode = child.codegenNode;
  20405. if (codegenNode.type === 13) {
  20406. const flag = codegenNode.patchFlag;
  20407. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  20408. const props = getNodeProps(child);
  20409. if (props) {
  20410. codegenNode.props = context.hoist(props);
  20411. }
  20412. }
  20413. if (codegenNode.dynamicProps) {
  20414. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  20415. }
  20416. }
  20417. }
  20418. } else if (child.type === 12) {
  20419. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  20420. if (constantType >= 2) {
  20421. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  20422. child.codegenNode.arguments.push(
  20423. -1 + (` /* ${PatchFlagNames[-1]} */` )
  20424. );
  20425. }
  20426. toCache.push(child);
  20427. continue;
  20428. }
  20429. }
  20430. if (child.type === 1) {
  20431. const isComponent = child.tagType === 1;
  20432. if (isComponent) {
  20433. context.scopes.vSlot++;
  20434. }
  20435. walk$1(child, node, context, false, inFor);
  20436. if (isComponent) {
  20437. context.scopes.vSlot--;
  20438. }
  20439. } else if (child.type === 11) {
  20440. walk$1(child, node, context, child.children.length === 1, true);
  20441. } else if (child.type === 9) {
  20442. for (let i2 = 0; i2 < child.branches.length; i2++) {
  20443. walk$1(
  20444. child.branches[i2],
  20445. node,
  20446. context,
  20447. child.branches[i2].children.length === 1,
  20448. inFor
  20449. );
  20450. }
  20451. }
  20452. }
  20453. let cachedAsArray = false;
  20454. if (toCache.length === children.length && node.type === 1) {
  20455. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  20456. node.codegenNode.children = getCacheExpression(
  20457. createArrayExpression(node.codegenNode.children)
  20458. );
  20459. cachedAsArray = true;
  20460. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray$3(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  20461. const slot = getSlotNode(node.codegenNode, "default");
  20462. if (slot) {
  20463. slot.returns = getCacheExpression(
  20464. createArrayExpression(slot.returns)
  20465. );
  20466. cachedAsArray = true;
  20467. }
  20468. } 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) {
  20469. const slotName = findDir(node, "slot", true);
  20470. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  20471. if (slot) {
  20472. slot.returns = getCacheExpression(
  20473. createArrayExpression(slot.returns)
  20474. );
  20475. cachedAsArray = true;
  20476. }
  20477. }
  20478. }
  20479. if (!cachedAsArray) {
  20480. for (const child of toCache) {
  20481. child.codegenNode = context.cache(child.codegenNode);
  20482. }
  20483. }
  20484. function getCacheExpression(value) {
  20485. const exp = context.cache(value);
  20486. exp.needArraySpread = true;
  20487. return exp;
  20488. }
  20489. function getSlotNode(node2, name) {
  20490. if (node2.children && !isArray$3(node2.children) && node2.children.type === 15) {
  20491. const slot = node2.children.properties.find(
  20492. (p) => p.key === name || p.key.content === name
  20493. );
  20494. return slot && slot.value;
  20495. }
  20496. }
  20497. if (toCache.length && context.transformHoist) {
  20498. context.transformHoist(children, context, node);
  20499. }
  20500. }
  20501. function getConstantType(node, context) {
  20502. const { constantCache } = context;
  20503. switch (node.type) {
  20504. case 1:
  20505. if (node.tagType !== 0) {
  20506. return 0;
  20507. }
  20508. const cached = constantCache.get(node);
  20509. if (cached !== void 0) {
  20510. return cached;
  20511. }
  20512. const codegenNode = node.codegenNode;
  20513. if (codegenNode.type !== 13) {
  20514. return 0;
  20515. }
  20516. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  20517. return 0;
  20518. }
  20519. if (codegenNode.patchFlag === void 0) {
  20520. let returnType2 = 3;
  20521. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  20522. if (generatedPropsType === 0) {
  20523. constantCache.set(node, 0);
  20524. return 0;
  20525. }
  20526. if (generatedPropsType < returnType2) {
  20527. returnType2 = generatedPropsType;
  20528. }
  20529. for (let i = 0; i < node.children.length; i++) {
  20530. const childType = getConstantType(node.children[i], context);
  20531. if (childType === 0) {
  20532. constantCache.set(node, 0);
  20533. return 0;
  20534. }
  20535. if (childType < returnType2) {
  20536. returnType2 = childType;
  20537. }
  20538. }
  20539. if (returnType2 > 1) {
  20540. for (let i = 0; i < node.props.length; i++) {
  20541. const p = node.props[i];
  20542. if (p.type === 7 && p.name === "bind" && p.exp) {
  20543. const expType = getConstantType(p.exp, context);
  20544. if (expType === 0) {
  20545. constantCache.set(node, 0);
  20546. return 0;
  20547. }
  20548. if (expType < returnType2) {
  20549. returnType2 = expType;
  20550. }
  20551. }
  20552. }
  20553. }
  20554. if (codegenNode.isBlock) {
  20555. for (let i = 0; i < node.props.length; i++) {
  20556. const p = node.props[i];
  20557. if (p.type === 7) {
  20558. constantCache.set(node, 0);
  20559. return 0;
  20560. }
  20561. }
  20562. context.removeHelper(OPEN_BLOCK);
  20563. context.removeHelper(
  20564. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  20565. );
  20566. codegenNode.isBlock = false;
  20567. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  20568. }
  20569. constantCache.set(node, returnType2);
  20570. return returnType2;
  20571. } else {
  20572. constantCache.set(node, 0);
  20573. return 0;
  20574. }
  20575. case 2:
  20576. case 3:
  20577. return 3;
  20578. case 9:
  20579. case 11:
  20580. case 10:
  20581. return 0;
  20582. case 5:
  20583. case 12:
  20584. return getConstantType(node.content, context);
  20585. case 4:
  20586. return node.constType;
  20587. case 8:
  20588. let returnType = 3;
  20589. for (let i = 0; i < node.children.length; i++) {
  20590. const child = node.children[i];
  20591. if (isString$1(child) || isSymbol$1(child)) {
  20592. continue;
  20593. }
  20594. const childType = getConstantType(child, context);
  20595. if (childType === 0) {
  20596. return 0;
  20597. } else if (childType < returnType) {
  20598. returnType = childType;
  20599. }
  20600. }
  20601. return returnType;
  20602. case 20:
  20603. return 2;
  20604. default:
  20605. return 0;
  20606. }
  20607. }
  20608. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  20609. NORMALIZE_CLASS,
  20610. NORMALIZE_STYLE,
  20611. NORMALIZE_PROPS,
  20612. GUARD_REACTIVE_PROPS
  20613. ]);
  20614. function getConstantTypeOfHelperCall(value, context) {
  20615. if (value.type === 14 && !isString$1(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  20616. const arg = value.arguments[0];
  20617. if (arg.type === 4) {
  20618. return getConstantType(arg, context);
  20619. } else if (arg.type === 14) {
  20620. return getConstantTypeOfHelperCall(arg, context);
  20621. }
  20622. }
  20623. return 0;
  20624. }
  20625. function getGeneratedPropsConstantType(node, context) {
  20626. let returnType = 3;
  20627. const props = getNodeProps(node);
  20628. if (props && props.type === 15) {
  20629. const { properties } = props;
  20630. for (let i = 0; i < properties.length; i++) {
  20631. const { key, value } = properties[i];
  20632. const keyType = getConstantType(key, context);
  20633. if (keyType === 0) {
  20634. return keyType;
  20635. }
  20636. if (keyType < returnType) {
  20637. returnType = keyType;
  20638. }
  20639. let valueType;
  20640. if (value.type === 4) {
  20641. valueType = getConstantType(value, context);
  20642. } else if (value.type === 14) {
  20643. valueType = getConstantTypeOfHelperCall(value, context);
  20644. } else {
  20645. valueType = 0;
  20646. }
  20647. if (valueType === 0) {
  20648. return valueType;
  20649. }
  20650. if (valueType < returnType) {
  20651. returnType = valueType;
  20652. }
  20653. }
  20654. }
  20655. return returnType;
  20656. }
  20657. function getNodeProps(node) {
  20658. const codegenNode = node.codegenNode;
  20659. if (codegenNode.type === 13) {
  20660. return codegenNode.props;
  20661. }
  20662. }
  20663. function createTransformContext(root, {
  20664. filename = "",
  20665. prefixIdentifiers = false,
  20666. hoistStatic = false,
  20667. hmr = false,
  20668. cacheHandlers = false,
  20669. nodeTransforms = [],
  20670. directiveTransforms = {},
  20671. transformHoist = null,
  20672. isBuiltInComponent = NOOP,
  20673. isCustomElement = NOOP,
  20674. expressionPlugins = [],
  20675. scopeId = null,
  20676. slotted = true,
  20677. ssr = false,
  20678. inSSR = false,
  20679. ssrCssVars = ``,
  20680. bindingMetadata = EMPTY_OBJ,
  20681. inline = false,
  20682. isTS = false,
  20683. onError = defaultOnError,
  20684. onWarn = defaultOnWarn,
  20685. compatConfig
  20686. }) {
  20687. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  20688. const context = {
  20689. // options
  20690. filename,
  20691. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  20692. prefixIdentifiers,
  20693. hoistStatic,
  20694. hmr,
  20695. cacheHandlers,
  20696. nodeTransforms,
  20697. directiveTransforms,
  20698. transformHoist,
  20699. isBuiltInComponent,
  20700. isCustomElement,
  20701. expressionPlugins,
  20702. scopeId,
  20703. slotted,
  20704. ssr,
  20705. inSSR,
  20706. ssrCssVars,
  20707. bindingMetadata,
  20708. inline,
  20709. isTS,
  20710. onError,
  20711. onWarn,
  20712. compatConfig,
  20713. // state
  20714. root,
  20715. helpers: /* @__PURE__ */ new Map(),
  20716. components: /* @__PURE__ */ new Set(),
  20717. directives: /* @__PURE__ */ new Set(),
  20718. hoists: [],
  20719. imports: [],
  20720. cached: [],
  20721. constantCache: /* @__PURE__ */ new WeakMap(),
  20722. temps: 0,
  20723. identifiers: /* @__PURE__ */ Object.create(null),
  20724. scopes: {
  20725. vFor: 0,
  20726. vSlot: 0,
  20727. vPre: 0,
  20728. vOnce: 0
  20729. },
  20730. parent: null,
  20731. grandParent: null,
  20732. currentNode: root,
  20733. childIndex: 0,
  20734. inVOnce: false,
  20735. // methods
  20736. helper(name) {
  20737. const count = context.helpers.get(name) || 0;
  20738. context.helpers.set(name, count + 1);
  20739. return name;
  20740. },
  20741. removeHelper(name) {
  20742. const count = context.helpers.get(name);
  20743. if (count) {
  20744. const currentCount = count - 1;
  20745. if (!currentCount) {
  20746. context.helpers.delete(name);
  20747. } else {
  20748. context.helpers.set(name, currentCount);
  20749. }
  20750. }
  20751. },
  20752. helperString(name) {
  20753. return `_${helperNameMap[context.helper(name)]}`;
  20754. },
  20755. replaceNode(node) {
  20756. {
  20757. if (!context.currentNode) {
  20758. throw new Error(`Node being replaced is already removed.`);
  20759. }
  20760. if (!context.parent) {
  20761. throw new Error(`Cannot replace root node.`);
  20762. }
  20763. }
  20764. context.parent.children[context.childIndex] = context.currentNode = node;
  20765. },
  20766. removeNode(node) {
  20767. if (!context.parent) {
  20768. throw new Error(`Cannot remove root node.`);
  20769. }
  20770. const list = context.parent.children;
  20771. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  20772. if (removalIndex < 0) {
  20773. throw new Error(`node being removed is not a child of current parent`);
  20774. }
  20775. if (!node || node === context.currentNode) {
  20776. context.currentNode = null;
  20777. context.onNodeRemoved();
  20778. } else {
  20779. if (context.childIndex > removalIndex) {
  20780. context.childIndex--;
  20781. context.onNodeRemoved();
  20782. }
  20783. }
  20784. context.parent.children.splice(removalIndex, 1);
  20785. },
  20786. onNodeRemoved: NOOP,
  20787. addIdentifiers(exp) {
  20788. {
  20789. if (isString$1(exp)) {
  20790. addId(exp);
  20791. } else if (exp.identifiers) {
  20792. exp.identifiers.forEach(addId);
  20793. } else if (exp.type === 4) {
  20794. addId(exp.content);
  20795. }
  20796. }
  20797. },
  20798. removeIdentifiers(exp) {
  20799. {
  20800. if (isString$1(exp)) {
  20801. removeId(exp);
  20802. } else if (exp.identifiers) {
  20803. exp.identifiers.forEach(removeId);
  20804. } else if (exp.type === 4) {
  20805. removeId(exp.content);
  20806. }
  20807. }
  20808. },
  20809. hoist(exp) {
  20810. if (isString$1(exp)) exp = createSimpleExpression(exp);
  20811. context.hoists.push(exp);
  20812. const identifier = createSimpleExpression(
  20813. `_hoisted_${context.hoists.length}`,
  20814. false,
  20815. exp.loc,
  20816. 2
  20817. );
  20818. identifier.hoisted = exp;
  20819. return identifier;
  20820. },
  20821. cache(exp, isVNode = false, inVOnce = false) {
  20822. const cacheExp = createCacheExpression(
  20823. context.cached.length,
  20824. exp,
  20825. isVNode,
  20826. inVOnce
  20827. );
  20828. context.cached.push(cacheExp);
  20829. return cacheExp;
  20830. }
  20831. };
  20832. function addId(id) {
  20833. const { identifiers } = context;
  20834. if (identifiers[id] === void 0) {
  20835. identifiers[id] = 0;
  20836. }
  20837. identifiers[id]++;
  20838. }
  20839. function removeId(id) {
  20840. context.identifiers[id]--;
  20841. }
  20842. return context;
  20843. }
  20844. function transform(root, options) {
  20845. const context = createTransformContext(root, options);
  20846. traverseNode(root, context);
  20847. if (options.hoistStatic) {
  20848. cacheStatic(root, context);
  20849. }
  20850. if (!options.ssr) {
  20851. createRootCodegen(root, context);
  20852. }
  20853. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  20854. root.components = [...context.components];
  20855. root.directives = [...context.directives];
  20856. root.imports = context.imports;
  20857. root.hoists = context.hoists;
  20858. root.temps = context.temps;
  20859. root.cached = context.cached;
  20860. root.transformed = true;
  20861. }
  20862. function createRootCodegen(root, context) {
  20863. const { helper } = context;
  20864. const { children } = root;
  20865. if (children.length === 1) {
  20866. const singleElementRootChild = getSingleElementRoot(root);
  20867. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  20868. const codegenNode = singleElementRootChild.codegenNode;
  20869. if (codegenNode.type === 13) {
  20870. convertToBlock(codegenNode, context);
  20871. }
  20872. root.codegenNode = codegenNode;
  20873. } else {
  20874. root.codegenNode = children[0];
  20875. }
  20876. } else if (children.length > 1) {
  20877. let patchFlag = 64;
  20878. if (children.filter((c) => c.type !== 3).length === 1) {
  20879. patchFlag |= 2048;
  20880. }
  20881. root.codegenNode = createVNodeCall(
  20882. context,
  20883. helper(FRAGMENT),
  20884. void 0,
  20885. root.children,
  20886. patchFlag,
  20887. void 0,
  20888. void 0,
  20889. true,
  20890. void 0,
  20891. false
  20892. );
  20893. } else ;
  20894. }
  20895. function traverseChildren(parent, context) {
  20896. let i = 0;
  20897. const nodeRemoved = () => {
  20898. i--;
  20899. };
  20900. for (; i < parent.children.length; i++) {
  20901. const child = parent.children[i];
  20902. if (isString$1(child)) continue;
  20903. context.grandParent = context.parent;
  20904. context.parent = parent;
  20905. context.childIndex = i;
  20906. context.onNodeRemoved = nodeRemoved;
  20907. traverseNode(child, context);
  20908. }
  20909. }
  20910. function traverseNode(node, context) {
  20911. context.currentNode = node;
  20912. const { nodeTransforms } = context;
  20913. const exitFns = [];
  20914. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  20915. const onExit = nodeTransforms[i2](node, context);
  20916. if (onExit) {
  20917. if (isArray$3(onExit)) {
  20918. exitFns.push(...onExit);
  20919. } else {
  20920. exitFns.push(onExit);
  20921. }
  20922. }
  20923. if (!context.currentNode) {
  20924. return;
  20925. } else {
  20926. node = context.currentNode;
  20927. }
  20928. }
  20929. switch (node.type) {
  20930. case 3:
  20931. if (!context.ssr) {
  20932. context.helper(CREATE_COMMENT);
  20933. }
  20934. break;
  20935. case 5:
  20936. if (!context.ssr) {
  20937. context.helper(TO_DISPLAY_STRING);
  20938. }
  20939. break;
  20940. // for container types, further traverse downwards
  20941. case 9:
  20942. for (let i2 = 0; i2 < node.branches.length; i2++) {
  20943. traverseNode(node.branches[i2], context);
  20944. }
  20945. break;
  20946. case 10:
  20947. case 11:
  20948. case 1:
  20949. case 0:
  20950. traverseChildren(node, context);
  20951. break;
  20952. }
  20953. context.currentNode = node;
  20954. let i = exitFns.length;
  20955. while (i--) {
  20956. exitFns[i]();
  20957. }
  20958. }
  20959. function createStructuralDirectiveTransform(name, fn) {
  20960. const matches = isString$1(name) ? (n) => n === name : (n) => name.test(n);
  20961. return (node, context) => {
  20962. if (node.type === 1) {
  20963. const { props } = node;
  20964. if (node.tagType === 3 && props.some(isVSlot)) {
  20965. return;
  20966. }
  20967. const exitFns = [];
  20968. for (let i = 0; i < props.length; i++) {
  20969. const prop = props[i];
  20970. if (prop.type === 7 && matches(prop.name)) {
  20971. props.splice(i, 1);
  20972. i--;
  20973. const onExit = fn(node, prop, context);
  20974. if (onExit) exitFns.push(onExit);
  20975. }
  20976. }
  20977. return exitFns;
  20978. }
  20979. };
  20980. }
  20981. var sourceMap$1 = {};
  20982. var sourceMapGenerator$1 = {};
  20983. var base64Vlq$1 = {};
  20984. var base64$1 = {};
  20985. /* -*- Mode: js; js-indent-level: 2; -*- */
  20986. var hasRequiredBase64$1;
  20987. function requireBase64$1 () {
  20988. if (hasRequiredBase64$1) return base64$1;
  20989. hasRequiredBase64$1 = 1;
  20990. /*
  20991. * Copyright 2011 Mozilla Foundation and contributors
  20992. * Licensed under the New BSD license. See LICENSE or:
  20993. * http://opensource.org/licenses/BSD-3-Clause
  20994. */
  20995. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  20996. /**
  20997. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  20998. */
  20999. base64$1.encode = function (number) {
  21000. if (0 <= number && number < intToCharMap.length) {
  21001. return intToCharMap[number];
  21002. }
  21003. throw new TypeError("Must be between 0 and 63: " + number);
  21004. };
  21005. /**
  21006. * Decode a single base 64 character code digit to an integer. Returns -1 on
  21007. * failure.
  21008. */
  21009. base64$1.decode = function (charCode) {
  21010. var bigA = 65; // 'A'
  21011. var bigZ = 90; // 'Z'
  21012. var littleA = 97; // 'a'
  21013. var littleZ = 122; // 'z'
  21014. var zero = 48; // '0'
  21015. var nine = 57; // '9'
  21016. var plus = 43; // '+'
  21017. var slash = 47; // '/'
  21018. var littleOffset = 26;
  21019. var numberOffset = 52;
  21020. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  21021. if (bigA <= charCode && charCode <= bigZ) {
  21022. return (charCode - bigA);
  21023. }
  21024. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  21025. if (littleA <= charCode && charCode <= littleZ) {
  21026. return (charCode - littleA + littleOffset);
  21027. }
  21028. // 52 - 61: 0123456789
  21029. if (zero <= charCode && charCode <= nine) {
  21030. return (charCode - zero + numberOffset);
  21031. }
  21032. // 62: +
  21033. if (charCode == plus) {
  21034. return 62;
  21035. }
  21036. // 63: /
  21037. if (charCode == slash) {
  21038. return 63;
  21039. }
  21040. // Invalid base64 digit.
  21041. return -1;
  21042. };
  21043. return base64$1;
  21044. }
  21045. /* -*- Mode: js; js-indent-level: 2; -*- */
  21046. var hasRequiredBase64Vlq$1;
  21047. function requireBase64Vlq$1 () {
  21048. if (hasRequiredBase64Vlq$1) return base64Vlq$1;
  21049. hasRequiredBase64Vlq$1 = 1;
  21050. /*
  21051. * Copyright 2011 Mozilla Foundation and contributors
  21052. * Licensed under the New BSD license. See LICENSE or:
  21053. * http://opensource.org/licenses/BSD-3-Clause
  21054. *
  21055. * Based on the Base 64 VLQ implementation in Closure Compiler:
  21056. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  21057. *
  21058. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  21059. * Redistribution and use in source and binary forms, with or without
  21060. * modification, are permitted provided that the following conditions are
  21061. * met:
  21062. *
  21063. * * Redistributions of source code must retain the above copyright
  21064. * notice, this list of conditions and the following disclaimer.
  21065. * * Redistributions in binary form must reproduce the above
  21066. * copyright notice, this list of conditions and the following
  21067. * disclaimer in the documentation and/or other materials provided
  21068. * with the distribution.
  21069. * * Neither the name of Google Inc. nor the names of its
  21070. * contributors may be used to endorse or promote products derived
  21071. * from this software without specific prior written permission.
  21072. *
  21073. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21074. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21075. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21076. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21077. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21078. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21079. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21080. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21081. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21082. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  21083. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21084. */
  21085. var base64 = /*@__PURE__*/ requireBase64$1();
  21086. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  21087. // length quantities we use in the source map spec, the first bit is the sign,
  21088. // the next four bits are the actual value, and the 6th bit is the
  21089. // continuation bit. The continuation bit tells us whether there are more
  21090. // digits in this value following this digit.
  21091. //
  21092. // Continuation
  21093. // | Sign
  21094. // | |
  21095. // V V
  21096. // 101011
  21097. var VLQ_BASE_SHIFT = 5;
  21098. // binary: 100000
  21099. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  21100. // binary: 011111
  21101. var VLQ_BASE_MASK = VLQ_BASE - 1;
  21102. // binary: 100000
  21103. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  21104. /**
  21105. * Converts from a two-complement value to a value where the sign bit is
  21106. * placed in the least significant bit. For example, as decimals:
  21107. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  21108. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  21109. */
  21110. function toVLQSigned(aValue) {
  21111. return aValue < 0
  21112. ? ((-aValue) << 1) + 1
  21113. : (aValue << 1) + 0;
  21114. }
  21115. /**
  21116. * Converts to a two-complement value from a value where the sign bit is
  21117. * placed in the least significant bit. For example, as decimals:
  21118. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  21119. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  21120. */
  21121. function fromVLQSigned(aValue) {
  21122. var isNegative = (aValue & 1) === 1;
  21123. var shifted = aValue >> 1;
  21124. return isNegative
  21125. ? -shifted
  21126. : shifted;
  21127. }
  21128. /**
  21129. * Returns the base 64 VLQ encoded value.
  21130. */
  21131. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  21132. var encoded = "";
  21133. var digit;
  21134. var vlq = toVLQSigned(aValue);
  21135. do {
  21136. digit = vlq & VLQ_BASE_MASK;
  21137. vlq >>>= VLQ_BASE_SHIFT;
  21138. if (vlq > 0) {
  21139. // There are still more digits in this value, so we must make sure the
  21140. // continuation bit is marked.
  21141. digit |= VLQ_CONTINUATION_BIT;
  21142. }
  21143. encoded += base64.encode(digit);
  21144. } while (vlq > 0);
  21145. return encoded;
  21146. };
  21147. /**
  21148. * Decodes the next base 64 VLQ value from the given string and returns the
  21149. * value and the rest of the string via the out parameter.
  21150. */
  21151. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  21152. var strLen = aStr.length;
  21153. var result = 0;
  21154. var shift = 0;
  21155. var continuation, digit;
  21156. do {
  21157. if (aIndex >= strLen) {
  21158. throw new Error("Expected more digits in base 64 VLQ value.");
  21159. }
  21160. digit = base64.decode(aStr.charCodeAt(aIndex++));
  21161. if (digit === -1) {
  21162. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  21163. }
  21164. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  21165. digit &= VLQ_BASE_MASK;
  21166. result = result + (digit << shift);
  21167. shift += VLQ_BASE_SHIFT;
  21168. } while (continuation);
  21169. aOutParam.value = fromVLQSigned(result);
  21170. aOutParam.rest = aIndex;
  21171. };
  21172. return base64Vlq$1;
  21173. }
  21174. var util$2 = {};
  21175. /* -*- Mode: js; js-indent-level: 2; -*- */
  21176. var hasRequiredUtil$2;
  21177. function requireUtil$2 () {
  21178. if (hasRequiredUtil$2) return util$2;
  21179. hasRequiredUtil$2 = 1;
  21180. (function (exports$1) {
  21181. /*
  21182. * Copyright 2011 Mozilla Foundation and contributors
  21183. * Licensed under the New BSD license. See LICENSE or:
  21184. * http://opensource.org/licenses/BSD-3-Clause
  21185. */
  21186. /**
  21187. * This is a helper function for getting values from parameter/options
  21188. * objects.
  21189. *
  21190. * @param args The object we are extracting values from
  21191. * @param name The name of the property we are getting.
  21192. * @param defaultValue An optional value to return if the property is missing
  21193. * from the object. If this is not specified and the property is missing, an
  21194. * error will be thrown.
  21195. */
  21196. function getArg(aArgs, aName, aDefaultValue) {
  21197. if (aName in aArgs) {
  21198. return aArgs[aName];
  21199. } else if (arguments.length === 3) {
  21200. return aDefaultValue;
  21201. } else {
  21202. throw new Error('"' + aName + '" is a required argument.');
  21203. }
  21204. }
  21205. exports$1.getArg = getArg;
  21206. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  21207. var dataUrlRegexp = /^data:.+\,.+$/;
  21208. function urlParse(aUrl) {
  21209. var match = aUrl.match(urlRegexp);
  21210. if (!match) {
  21211. return null;
  21212. }
  21213. return {
  21214. scheme: match[1],
  21215. auth: match[2],
  21216. host: match[3],
  21217. port: match[4],
  21218. path: match[5]
  21219. };
  21220. }
  21221. exports$1.urlParse = urlParse;
  21222. function urlGenerate(aParsedUrl) {
  21223. var url = '';
  21224. if (aParsedUrl.scheme) {
  21225. url += aParsedUrl.scheme + ':';
  21226. }
  21227. url += '//';
  21228. if (aParsedUrl.auth) {
  21229. url += aParsedUrl.auth + '@';
  21230. }
  21231. if (aParsedUrl.host) {
  21232. url += aParsedUrl.host;
  21233. }
  21234. if (aParsedUrl.port) {
  21235. url += ":" + aParsedUrl.port;
  21236. }
  21237. if (aParsedUrl.path) {
  21238. url += aParsedUrl.path;
  21239. }
  21240. return url;
  21241. }
  21242. exports$1.urlGenerate = urlGenerate;
  21243. var MAX_CACHED_INPUTS = 32;
  21244. /**
  21245. * Takes some function `f(input) -> result` and returns a memoized version of
  21246. * `f`.
  21247. *
  21248. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  21249. * memoization is a dumb-simple, linear least-recently-used cache.
  21250. */
  21251. function lruMemoize(f) {
  21252. var cache = [];
  21253. return function(input) {
  21254. for (var i = 0; i < cache.length; i++) {
  21255. if (cache[i].input === input) {
  21256. var temp = cache[0];
  21257. cache[0] = cache[i];
  21258. cache[i] = temp;
  21259. return cache[0].result;
  21260. }
  21261. }
  21262. var result = f(input);
  21263. cache.unshift({
  21264. input,
  21265. result,
  21266. });
  21267. if (cache.length > MAX_CACHED_INPUTS) {
  21268. cache.pop();
  21269. }
  21270. return result;
  21271. };
  21272. }
  21273. /**
  21274. * Normalizes a path, or the path portion of a URL:
  21275. *
  21276. * - Replaces consecutive slashes with one slash.
  21277. * - Removes unnecessary '.' parts.
  21278. * - Removes unnecessary '<dir>/..' parts.
  21279. *
  21280. * Based on code in the Node.js 'path' core module.
  21281. *
  21282. * @param aPath The path or url to normalize.
  21283. */
  21284. var normalize = lruMemoize(function normalize(aPath) {
  21285. var path = aPath;
  21286. var url = urlParse(aPath);
  21287. if (url) {
  21288. if (!url.path) {
  21289. return aPath;
  21290. }
  21291. path = url.path;
  21292. }
  21293. var isAbsolute = exports$1.isAbsolute(path);
  21294. // Split the path into parts between `/` characters. This is much faster than
  21295. // using `.split(/\/+/g)`.
  21296. var parts = [];
  21297. var start = 0;
  21298. var i = 0;
  21299. while (true) {
  21300. start = i;
  21301. i = path.indexOf("/", start);
  21302. if (i === -1) {
  21303. parts.push(path.slice(start));
  21304. break;
  21305. } else {
  21306. parts.push(path.slice(start, i));
  21307. while (i < path.length && path[i] === "/") {
  21308. i++;
  21309. }
  21310. }
  21311. }
  21312. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  21313. part = parts[i];
  21314. if (part === '.') {
  21315. parts.splice(i, 1);
  21316. } else if (part === '..') {
  21317. up++;
  21318. } else if (up > 0) {
  21319. if (part === '') {
  21320. // The first part is blank if the path is absolute. Trying to go
  21321. // above the root is a no-op. Therefore we can remove all '..' parts
  21322. // directly after the root.
  21323. parts.splice(i + 1, up);
  21324. up = 0;
  21325. } else {
  21326. parts.splice(i, 2);
  21327. up--;
  21328. }
  21329. }
  21330. }
  21331. path = parts.join('/');
  21332. if (path === '') {
  21333. path = isAbsolute ? '/' : '.';
  21334. }
  21335. if (url) {
  21336. url.path = path;
  21337. return urlGenerate(url);
  21338. }
  21339. return path;
  21340. });
  21341. exports$1.normalize = normalize;
  21342. /**
  21343. * Joins two paths/URLs.
  21344. *
  21345. * @param aRoot The root path or URL.
  21346. * @param aPath The path or URL to be joined with the root.
  21347. *
  21348. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  21349. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  21350. * first.
  21351. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  21352. * is updated with the result and aRoot is returned. Otherwise the result
  21353. * is returned.
  21354. * - If aPath is absolute, the result is aPath.
  21355. * - Otherwise the two paths are joined with a slash.
  21356. * - Joining for example 'http://' and 'www.example.com' is also supported.
  21357. */
  21358. function join(aRoot, aPath) {
  21359. if (aRoot === "") {
  21360. aRoot = ".";
  21361. }
  21362. if (aPath === "") {
  21363. aPath = ".";
  21364. }
  21365. var aPathUrl = urlParse(aPath);
  21366. var aRootUrl = urlParse(aRoot);
  21367. if (aRootUrl) {
  21368. aRoot = aRootUrl.path || '/';
  21369. }
  21370. // `join(foo, '//www.example.org')`
  21371. if (aPathUrl && !aPathUrl.scheme) {
  21372. if (aRootUrl) {
  21373. aPathUrl.scheme = aRootUrl.scheme;
  21374. }
  21375. return urlGenerate(aPathUrl);
  21376. }
  21377. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  21378. return aPath;
  21379. }
  21380. // `join('http://', 'www.example.com')`
  21381. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  21382. aRootUrl.host = aPath;
  21383. return urlGenerate(aRootUrl);
  21384. }
  21385. var joined = aPath.charAt(0) === '/'
  21386. ? aPath
  21387. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  21388. if (aRootUrl) {
  21389. aRootUrl.path = joined;
  21390. return urlGenerate(aRootUrl);
  21391. }
  21392. return joined;
  21393. }
  21394. exports$1.join = join;
  21395. exports$1.isAbsolute = function (aPath) {
  21396. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  21397. };
  21398. /**
  21399. * Make a path relative to a URL or another path.
  21400. *
  21401. * @param aRoot The root path or URL.
  21402. * @param aPath The path or URL to be made relative to aRoot.
  21403. */
  21404. function relative(aRoot, aPath) {
  21405. if (aRoot === "") {
  21406. aRoot = ".";
  21407. }
  21408. aRoot = aRoot.replace(/\/$/, '');
  21409. // It is possible for the path to be above the root. In this case, simply
  21410. // checking whether the root is a prefix of the path won't work. Instead, we
  21411. // need to remove components from the root one by one, until either we find
  21412. // a prefix that fits, or we run out of components to remove.
  21413. var level = 0;
  21414. while (aPath.indexOf(aRoot + '/') !== 0) {
  21415. var index = aRoot.lastIndexOf("/");
  21416. if (index < 0) {
  21417. return aPath;
  21418. }
  21419. // If the only part of the root that is left is the scheme (i.e. http://,
  21420. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  21421. // have exhausted all components, so the path is not relative to the root.
  21422. aRoot = aRoot.slice(0, index);
  21423. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  21424. return aPath;
  21425. }
  21426. ++level;
  21427. }
  21428. // Make sure we add a "../" for each component we removed from the root.
  21429. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  21430. }
  21431. exports$1.relative = relative;
  21432. var supportsNullProto = (function () {
  21433. var obj = Object.create(null);
  21434. return !('__proto__' in obj);
  21435. }());
  21436. function identity (s) {
  21437. return s;
  21438. }
  21439. /**
  21440. * Because behavior goes wacky when you set `__proto__` on objects, we
  21441. * have to prefix all the strings in our set with an arbitrary character.
  21442. *
  21443. * See https://github.com/mozilla/source-map/pull/31 and
  21444. * https://github.com/mozilla/source-map/issues/30
  21445. *
  21446. * @param String aStr
  21447. */
  21448. function toSetString(aStr) {
  21449. if (isProtoString(aStr)) {
  21450. return '$' + aStr;
  21451. }
  21452. return aStr;
  21453. }
  21454. exports$1.toSetString = supportsNullProto ? identity : toSetString;
  21455. function fromSetString(aStr) {
  21456. if (isProtoString(aStr)) {
  21457. return aStr.slice(1);
  21458. }
  21459. return aStr;
  21460. }
  21461. exports$1.fromSetString = supportsNullProto ? identity : fromSetString;
  21462. function isProtoString(s) {
  21463. if (!s) {
  21464. return false;
  21465. }
  21466. var length = s.length;
  21467. if (length < 9 /* "__proto__".length */) {
  21468. return false;
  21469. }
  21470. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  21471. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  21472. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  21473. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  21474. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  21475. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  21476. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  21477. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  21478. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  21479. return false;
  21480. }
  21481. for (var i = length - 10; i >= 0; i--) {
  21482. if (s.charCodeAt(i) !== 36 /* '$' */) {
  21483. return false;
  21484. }
  21485. }
  21486. return true;
  21487. }
  21488. /**
  21489. * Comparator between two mappings where the original positions are compared.
  21490. *
  21491. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  21492. * mappings with the same original source/line/column, but different generated
  21493. * line and column the same. Useful when searching for a mapping with a
  21494. * stubbed out mapping.
  21495. */
  21496. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  21497. var cmp = strcmp(mappingA.source, mappingB.source);
  21498. if (cmp !== 0) {
  21499. return cmp;
  21500. }
  21501. cmp = mappingA.originalLine - mappingB.originalLine;
  21502. if (cmp !== 0) {
  21503. return cmp;
  21504. }
  21505. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21506. if (cmp !== 0 || onlyCompareOriginal) {
  21507. return cmp;
  21508. }
  21509. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21510. if (cmp !== 0) {
  21511. return cmp;
  21512. }
  21513. cmp = mappingA.generatedLine - mappingB.generatedLine;
  21514. if (cmp !== 0) {
  21515. return cmp;
  21516. }
  21517. return strcmp(mappingA.name, mappingB.name);
  21518. }
  21519. exports$1.compareByOriginalPositions = compareByOriginalPositions;
  21520. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  21521. var cmp;
  21522. cmp = mappingA.originalLine - mappingB.originalLine;
  21523. if (cmp !== 0) {
  21524. return cmp;
  21525. }
  21526. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21527. if (cmp !== 0 || onlyCompareOriginal) {
  21528. return cmp;
  21529. }
  21530. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21531. if (cmp !== 0) {
  21532. return cmp;
  21533. }
  21534. cmp = mappingA.generatedLine - mappingB.generatedLine;
  21535. if (cmp !== 0) {
  21536. return cmp;
  21537. }
  21538. return strcmp(mappingA.name, mappingB.name);
  21539. }
  21540. exports$1.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  21541. /**
  21542. * Comparator between two mappings with deflated source and name indices where
  21543. * the generated positions are compared.
  21544. *
  21545. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  21546. * mappings with the same generated line and column, but different
  21547. * source/name/original line and column the same. Useful when searching for a
  21548. * mapping with a stubbed out mapping.
  21549. */
  21550. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  21551. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  21552. if (cmp !== 0) {
  21553. return cmp;
  21554. }
  21555. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21556. if (cmp !== 0 || onlyCompareGenerated) {
  21557. return cmp;
  21558. }
  21559. cmp = strcmp(mappingA.source, mappingB.source);
  21560. if (cmp !== 0) {
  21561. return cmp;
  21562. }
  21563. cmp = mappingA.originalLine - mappingB.originalLine;
  21564. if (cmp !== 0) {
  21565. return cmp;
  21566. }
  21567. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21568. if (cmp !== 0) {
  21569. return cmp;
  21570. }
  21571. return strcmp(mappingA.name, mappingB.name);
  21572. }
  21573. exports$1.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  21574. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  21575. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21576. if (cmp !== 0 || onlyCompareGenerated) {
  21577. return cmp;
  21578. }
  21579. cmp = strcmp(mappingA.source, mappingB.source);
  21580. if (cmp !== 0) {
  21581. return cmp;
  21582. }
  21583. cmp = mappingA.originalLine - mappingB.originalLine;
  21584. if (cmp !== 0) {
  21585. return cmp;
  21586. }
  21587. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21588. if (cmp !== 0) {
  21589. return cmp;
  21590. }
  21591. return strcmp(mappingA.name, mappingB.name);
  21592. }
  21593. exports$1.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  21594. function strcmp(aStr1, aStr2) {
  21595. if (aStr1 === aStr2) {
  21596. return 0;
  21597. }
  21598. if (aStr1 === null) {
  21599. return 1; // aStr2 !== null
  21600. }
  21601. if (aStr2 === null) {
  21602. return -1; // aStr1 !== null
  21603. }
  21604. if (aStr1 > aStr2) {
  21605. return 1;
  21606. }
  21607. return -1;
  21608. }
  21609. /**
  21610. * Comparator between two mappings with inflated source and name strings where
  21611. * the generated positions are compared.
  21612. */
  21613. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  21614. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  21615. if (cmp !== 0) {
  21616. return cmp;
  21617. }
  21618. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  21619. if (cmp !== 0) {
  21620. return cmp;
  21621. }
  21622. cmp = strcmp(mappingA.source, mappingB.source);
  21623. if (cmp !== 0) {
  21624. return cmp;
  21625. }
  21626. cmp = mappingA.originalLine - mappingB.originalLine;
  21627. if (cmp !== 0) {
  21628. return cmp;
  21629. }
  21630. cmp = mappingA.originalColumn - mappingB.originalColumn;
  21631. if (cmp !== 0) {
  21632. return cmp;
  21633. }
  21634. return strcmp(mappingA.name, mappingB.name);
  21635. }
  21636. exports$1.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  21637. /**
  21638. * Strip any JSON XSSI avoidance prefix from the string (as documented
  21639. * in the source maps specification), and then parse the string as
  21640. * JSON.
  21641. */
  21642. function parseSourceMapInput(str) {
  21643. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  21644. }
  21645. exports$1.parseSourceMapInput = parseSourceMapInput;
  21646. /**
  21647. * Compute the URL of a source given the the source root, the source's
  21648. * URL, and the source map's URL.
  21649. */
  21650. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  21651. sourceURL = sourceURL || '';
  21652. if (sourceRoot) {
  21653. // This follows what Chrome does.
  21654. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  21655. sourceRoot += '/';
  21656. }
  21657. // The spec says:
  21658. // Line 4: An optional source root, useful for relocating source
  21659. // files on a server or removing repeated values in the
  21660. // “sources” entry. This value is prepended to the individual
  21661. // entries in the “source” field.
  21662. sourceURL = sourceRoot + sourceURL;
  21663. }
  21664. // Historically, SourceMapConsumer did not take the sourceMapURL as
  21665. // a parameter. This mode is still somewhat supported, which is why
  21666. // this code block is conditional. However, it's preferable to pass
  21667. // the source map URL to SourceMapConsumer, so that this function
  21668. // can implement the source URL resolution algorithm as outlined in
  21669. // the spec. This block is basically the equivalent of:
  21670. // new URL(sourceURL, sourceMapURL).toString()
  21671. // ... except it avoids using URL, which wasn't available in the
  21672. // older releases of node still supported by this library.
  21673. //
  21674. // The spec says:
  21675. // If the sources are not absolute URLs after prepending of the
  21676. // “sourceRoot”, the sources are resolved relative to the
  21677. // SourceMap (like resolving script src in a html document).
  21678. if (sourceMapURL) {
  21679. var parsed = urlParse(sourceMapURL);
  21680. if (!parsed) {
  21681. throw new Error("sourceMapURL could not be parsed");
  21682. }
  21683. if (parsed.path) {
  21684. // Strip the last path component, but keep the "/".
  21685. var index = parsed.path.lastIndexOf('/');
  21686. if (index >= 0) {
  21687. parsed.path = parsed.path.substring(0, index + 1);
  21688. }
  21689. }
  21690. sourceURL = join(urlGenerate(parsed), sourceURL);
  21691. }
  21692. return normalize(sourceURL);
  21693. }
  21694. exports$1.computeSourceURL = computeSourceURL;
  21695. } (util$2));
  21696. return util$2;
  21697. }
  21698. var arraySet$1 = {};
  21699. /* -*- Mode: js; js-indent-level: 2; -*- */
  21700. var hasRequiredArraySet$1;
  21701. function requireArraySet$1 () {
  21702. if (hasRequiredArraySet$1) return arraySet$1;
  21703. hasRequiredArraySet$1 = 1;
  21704. /*
  21705. * Copyright 2011 Mozilla Foundation and contributors
  21706. * Licensed under the New BSD license. See LICENSE or:
  21707. * http://opensource.org/licenses/BSD-3-Clause
  21708. */
  21709. var util = /*@__PURE__*/ requireUtil$2();
  21710. var has = Object.prototype.hasOwnProperty;
  21711. var hasNativeMap = typeof Map !== "undefined";
  21712. /**
  21713. * A data structure which is a combination of an array and a set. Adding a new
  21714. * member is O(1), testing for membership is O(1), and finding the index of an
  21715. * element is O(1). Removing elements from the set is not supported. Only
  21716. * strings are supported for membership.
  21717. */
  21718. function ArraySet() {
  21719. this._array = [];
  21720. this._set = hasNativeMap ? new Map() : Object.create(null);
  21721. }
  21722. /**
  21723. * Static method for creating ArraySet instances from an existing array.
  21724. */
  21725. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  21726. var set = new ArraySet();
  21727. for (var i = 0, len = aArray.length; i < len; i++) {
  21728. set.add(aArray[i], aAllowDuplicates);
  21729. }
  21730. return set;
  21731. };
  21732. /**
  21733. * Return how many unique items are in this ArraySet. If duplicates have been
  21734. * added, than those do not count towards the size.
  21735. *
  21736. * @returns Number
  21737. */
  21738. ArraySet.prototype.size = function ArraySet_size() {
  21739. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  21740. };
  21741. /**
  21742. * Add the given string to this set.
  21743. *
  21744. * @param String aStr
  21745. */
  21746. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  21747. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  21748. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  21749. var idx = this._array.length;
  21750. if (!isDuplicate || aAllowDuplicates) {
  21751. this._array.push(aStr);
  21752. }
  21753. if (!isDuplicate) {
  21754. if (hasNativeMap) {
  21755. this._set.set(aStr, idx);
  21756. } else {
  21757. this._set[sStr] = idx;
  21758. }
  21759. }
  21760. };
  21761. /**
  21762. * Is the given string a member of this set?
  21763. *
  21764. * @param String aStr
  21765. */
  21766. ArraySet.prototype.has = function ArraySet_has(aStr) {
  21767. if (hasNativeMap) {
  21768. return this._set.has(aStr);
  21769. } else {
  21770. var sStr = util.toSetString(aStr);
  21771. return has.call(this._set, sStr);
  21772. }
  21773. };
  21774. /**
  21775. * What is the index of the given string in the array?
  21776. *
  21777. * @param String aStr
  21778. */
  21779. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  21780. if (hasNativeMap) {
  21781. var idx = this._set.get(aStr);
  21782. if (idx >= 0) {
  21783. return idx;
  21784. }
  21785. } else {
  21786. var sStr = util.toSetString(aStr);
  21787. if (has.call(this._set, sStr)) {
  21788. return this._set[sStr];
  21789. }
  21790. }
  21791. throw new Error('"' + aStr + '" is not in the set.');
  21792. };
  21793. /**
  21794. * What is the element at the given index?
  21795. *
  21796. * @param Number aIdx
  21797. */
  21798. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  21799. if (aIdx >= 0 && aIdx < this._array.length) {
  21800. return this._array[aIdx];
  21801. }
  21802. throw new Error('No element indexed by ' + aIdx);
  21803. };
  21804. /**
  21805. * Returns the array representation of this set (which has the proper indices
  21806. * indicated by indexOf). Note that this is a copy of the internal array used
  21807. * for storing the members so that no one can mess with internal state.
  21808. */
  21809. ArraySet.prototype.toArray = function ArraySet_toArray() {
  21810. return this._array.slice();
  21811. };
  21812. arraySet$1.ArraySet = ArraySet;
  21813. return arraySet$1;
  21814. }
  21815. var mappingList$1 = {};
  21816. /* -*- Mode: js; js-indent-level: 2; -*- */
  21817. var hasRequiredMappingList$1;
  21818. function requireMappingList$1 () {
  21819. if (hasRequiredMappingList$1) return mappingList$1;
  21820. hasRequiredMappingList$1 = 1;
  21821. /*
  21822. * Copyright 2014 Mozilla Foundation and contributors
  21823. * Licensed under the New BSD license. See LICENSE or:
  21824. * http://opensource.org/licenses/BSD-3-Clause
  21825. */
  21826. var util = /*@__PURE__*/ requireUtil$2();
  21827. /**
  21828. * Determine whether mappingB is after mappingA with respect to generated
  21829. * position.
  21830. */
  21831. function generatedPositionAfter(mappingA, mappingB) {
  21832. // Optimized for most common case
  21833. var lineA = mappingA.generatedLine;
  21834. var lineB = mappingB.generatedLine;
  21835. var columnA = mappingA.generatedColumn;
  21836. var columnB = mappingB.generatedColumn;
  21837. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  21838. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  21839. }
  21840. /**
  21841. * A data structure to provide a sorted view of accumulated mappings in a
  21842. * performance conscious manner. It trades a neglibable overhead in general
  21843. * case for a large speedup in case of mappings being added in order.
  21844. */
  21845. function MappingList() {
  21846. this._array = [];
  21847. this._sorted = true;
  21848. // Serves as infimum
  21849. this._last = {generatedLine: -1, generatedColumn: 0};
  21850. }
  21851. /**
  21852. * Iterate through internal items. This method takes the same arguments that
  21853. * `Array.prototype.forEach` takes.
  21854. *
  21855. * NOTE: The order of the mappings is NOT guaranteed.
  21856. */
  21857. MappingList.prototype.unsortedForEach =
  21858. function MappingList_forEach(aCallback, aThisArg) {
  21859. this._array.forEach(aCallback, aThisArg);
  21860. };
  21861. /**
  21862. * Add the given source mapping.
  21863. *
  21864. * @param Object aMapping
  21865. */
  21866. MappingList.prototype.add = function MappingList_add(aMapping) {
  21867. if (generatedPositionAfter(this._last, aMapping)) {
  21868. this._last = aMapping;
  21869. this._array.push(aMapping);
  21870. } else {
  21871. this._sorted = false;
  21872. this._array.push(aMapping);
  21873. }
  21874. };
  21875. /**
  21876. * Returns the flat, sorted array of mappings. The mappings are sorted by
  21877. * generated position.
  21878. *
  21879. * WARNING: This method returns internal data without copying, for
  21880. * performance. The return value must NOT be mutated, and should be treated as
  21881. * an immutable borrow. If you want to take ownership, you must make your own
  21882. * copy.
  21883. */
  21884. MappingList.prototype.toArray = function MappingList_toArray() {
  21885. if (!this._sorted) {
  21886. this._array.sort(util.compareByGeneratedPositionsInflated);
  21887. this._sorted = true;
  21888. }
  21889. return this._array;
  21890. };
  21891. mappingList$1.MappingList = MappingList;
  21892. return mappingList$1;
  21893. }
  21894. /* -*- Mode: js; js-indent-level: 2; -*- */
  21895. var hasRequiredSourceMapGenerator$1;
  21896. function requireSourceMapGenerator$1 () {
  21897. if (hasRequiredSourceMapGenerator$1) return sourceMapGenerator$1;
  21898. hasRequiredSourceMapGenerator$1 = 1;
  21899. /*
  21900. * Copyright 2011 Mozilla Foundation and contributors
  21901. * Licensed under the New BSD license. See LICENSE or:
  21902. * http://opensource.org/licenses/BSD-3-Clause
  21903. */
  21904. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  21905. var util = /*@__PURE__*/ requireUtil$2();
  21906. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  21907. var MappingList = /*@__PURE__*/ requireMappingList$1().MappingList;
  21908. /**
  21909. * An instance of the SourceMapGenerator represents a source map which is
  21910. * being built incrementally. You may pass an object with the following
  21911. * properties:
  21912. *
  21913. * - file: The filename of the generated source.
  21914. * - sourceRoot: A root for all relative URLs in this source map.
  21915. */
  21916. function SourceMapGenerator(aArgs) {
  21917. if (!aArgs) {
  21918. aArgs = {};
  21919. }
  21920. this._file = util.getArg(aArgs, 'file', null);
  21921. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  21922. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  21923. this._ignoreInvalidMapping = util.getArg(aArgs, 'ignoreInvalidMapping', false);
  21924. this._sources = new ArraySet();
  21925. this._names = new ArraySet();
  21926. this._mappings = new MappingList();
  21927. this._sourcesContents = null;
  21928. }
  21929. SourceMapGenerator.prototype._version = 3;
  21930. /**
  21931. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  21932. *
  21933. * @param aSourceMapConsumer The SourceMap.
  21934. */
  21935. SourceMapGenerator.fromSourceMap =
  21936. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
  21937. var sourceRoot = aSourceMapConsumer.sourceRoot;
  21938. var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
  21939. file: aSourceMapConsumer.file,
  21940. sourceRoot: sourceRoot
  21941. }));
  21942. aSourceMapConsumer.eachMapping(function (mapping) {
  21943. var newMapping = {
  21944. generated: {
  21945. line: mapping.generatedLine,
  21946. column: mapping.generatedColumn
  21947. }
  21948. };
  21949. if (mapping.source != null) {
  21950. newMapping.source = mapping.source;
  21951. if (sourceRoot != null) {
  21952. newMapping.source = util.relative(sourceRoot, newMapping.source);
  21953. }
  21954. newMapping.original = {
  21955. line: mapping.originalLine,
  21956. column: mapping.originalColumn
  21957. };
  21958. if (mapping.name != null) {
  21959. newMapping.name = mapping.name;
  21960. }
  21961. }
  21962. generator.addMapping(newMapping);
  21963. });
  21964. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  21965. var sourceRelative = sourceFile;
  21966. if (sourceRoot !== null) {
  21967. sourceRelative = util.relative(sourceRoot, sourceFile);
  21968. }
  21969. if (!generator._sources.has(sourceRelative)) {
  21970. generator._sources.add(sourceRelative);
  21971. }
  21972. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  21973. if (content != null) {
  21974. generator.setSourceContent(sourceFile, content);
  21975. }
  21976. });
  21977. return generator;
  21978. };
  21979. /**
  21980. * Add a single mapping from original source line and column to the generated
  21981. * source's line and column for this source map being created. The mapping
  21982. * object should have the following properties:
  21983. *
  21984. * - generated: An object with the generated line and column positions.
  21985. * - original: An object with the original line and column positions.
  21986. * - source: The original source file (relative to the sourceRoot).
  21987. * - name: An optional original token name for this mapping.
  21988. */
  21989. SourceMapGenerator.prototype.addMapping =
  21990. function SourceMapGenerator_addMapping(aArgs) {
  21991. var generated = util.getArg(aArgs, 'generated');
  21992. var original = util.getArg(aArgs, 'original', null);
  21993. var source = util.getArg(aArgs, 'source', null);
  21994. var name = util.getArg(aArgs, 'name', null);
  21995. if (!this._skipValidation) {
  21996. if (this._validateMapping(generated, original, source, name) === false) {
  21997. return;
  21998. }
  21999. }
  22000. if (source != null) {
  22001. source = String(source);
  22002. if (!this._sources.has(source)) {
  22003. this._sources.add(source);
  22004. }
  22005. }
  22006. if (name != null) {
  22007. name = String(name);
  22008. if (!this._names.has(name)) {
  22009. this._names.add(name);
  22010. }
  22011. }
  22012. this._mappings.add({
  22013. generatedLine: generated.line,
  22014. generatedColumn: generated.column,
  22015. originalLine: original != null && original.line,
  22016. originalColumn: original != null && original.column,
  22017. source: source,
  22018. name: name
  22019. });
  22020. };
  22021. /**
  22022. * Set the source content for a source file.
  22023. */
  22024. SourceMapGenerator.prototype.setSourceContent =
  22025. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  22026. var source = aSourceFile;
  22027. if (this._sourceRoot != null) {
  22028. source = util.relative(this._sourceRoot, source);
  22029. }
  22030. if (aSourceContent != null) {
  22031. // Add the source content to the _sourcesContents map.
  22032. // Create a new _sourcesContents map if the property is null.
  22033. if (!this._sourcesContents) {
  22034. this._sourcesContents = Object.create(null);
  22035. }
  22036. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  22037. } else if (this._sourcesContents) {
  22038. // Remove the source file from the _sourcesContents map.
  22039. // If the _sourcesContents map is empty, set the property to null.
  22040. delete this._sourcesContents[util.toSetString(source)];
  22041. if (Object.keys(this._sourcesContents).length === 0) {
  22042. this._sourcesContents = null;
  22043. }
  22044. }
  22045. };
  22046. /**
  22047. * Applies the mappings of a sub-source-map for a specific source file to the
  22048. * source map being generated. Each mapping to the supplied source file is
  22049. * rewritten using the supplied source map. Note: The resolution for the
  22050. * resulting mappings is the minimium of this map and the supplied map.
  22051. *
  22052. * @param aSourceMapConsumer The source map to be applied.
  22053. * @param aSourceFile Optional. The filename of the source file.
  22054. * If omitted, SourceMapConsumer's file property will be used.
  22055. * @param aSourceMapPath Optional. The dirname of the path to the source map
  22056. * to be applied. If relative, it is relative to the SourceMapConsumer.
  22057. * This parameter is needed when the two source maps aren't in the same
  22058. * directory, and the source map to be applied contains relative source
  22059. * paths. If so, those relative source paths need to be rewritten
  22060. * relative to the SourceMapGenerator.
  22061. */
  22062. SourceMapGenerator.prototype.applySourceMap =
  22063. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  22064. var sourceFile = aSourceFile;
  22065. // If aSourceFile is omitted, we will use the file property of the SourceMap
  22066. if (aSourceFile == null) {
  22067. if (aSourceMapConsumer.file == null) {
  22068. throw new Error(
  22069. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  22070. 'or the source map\'s "file" property. Both were omitted.'
  22071. );
  22072. }
  22073. sourceFile = aSourceMapConsumer.file;
  22074. }
  22075. var sourceRoot = this._sourceRoot;
  22076. // Make "sourceFile" relative if an absolute Url is passed.
  22077. if (sourceRoot != null) {
  22078. sourceFile = util.relative(sourceRoot, sourceFile);
  22079. }
  22080. // Applying the SourceMap can add and remove items from the sources and
  22081. // the names array.
  22082. var newSources = new ArraySet();
  22083. var newNames = new ArraySet();
  22084. // Find mappings for the "sourceFile"
  22085. this._mappings.unsortedForEach(function (mapping) {
  22086. if (mapping.source === sourceFile && mapping.originalLine != null) {
  22087. // Check if it can be mapped by the source map, then update the mapping.
  22088. var original = aSourceMapConsumer.originalPositionFor({
  22089. line: mapping.originalLine,
  22090. column: mapping.originalColumn
  22091. });
  22092. if (original.source != null) {
  22093. // Copy mapping
  22094. mapping.source = original.source;
  22095. if (aSourceMapPath != null) {
  22096. mapping.source = util.join(aSourceMapPath, mapping.source);
  22097. }
  22098. if (sourceRoot != null) {
  22099. mapping.source = util.relative(sourceRoot, mapping.source);
  22100. }
  22101. mapping.originalLine = original.line;
  22102. mapping.originalColumn = original.column;
  22103. if (original.name != null) {
  22104. mapping.name = original.name;
  22105. }
  22106. }
  22107. }
  22108. var source = mapping.source;
  22109. if (source != null && !newSources.has(source)) {
  22110. newSources.add(source);
  22111. }
  22112. var name = mapping.name;
  22113. if (name != null && !newNames.has(name)) {
  22114. newNames.add(name);
  22115. }
  22116. }, this);
  22117. this._sources = newSources;
  22118. this._names = newNames;
  22119. // Copy sourcesContents of applied map.
  22120. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  22121. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  22122. if (content != null) {
  22123. if (aSourceMapPath != null) {
  22124. sourceFile = util.join(aSourceMapPath, sourceFile);
  22125. }
  22126. if (sourceRoot != null) {
  22127. sourceFile = util.relative(sourceRoot, sourceFile);
  22128. }
  22129. this.setSourceContent(sourceFile, content);
  22130. }
  22131. }, this);
  22132. };
  22133. /**
  22134. * A mapping can have one of the three levels of data:
  22135. *
  22136. * 1. Just the generated position.
  22137. * 2. The Generated position, original position, and original source.
  22138. * 3. Generated and original position, original source, as well as a name
  22139. * token.
  22140. *
  22141. * To maintain consistency, we validate that any new mapping being added falls
  22142. * in to one of these categories.
  22143. */
  22144. SourceMapGenerator.prototype._validateMapping =
  22145. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  22146. aName) {
  22147. // When aOriginal is truthy but has empty values for .line and .column,
  22148. // it is most likely a programmer error. In this case we throw a very
  22149. // specific error message to try to guide them the right way.
  22150. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  22151. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  22152. var message = 'original.line and original.column are not numbers -- you probably meant to omit ' +
  22153. 'the original mapping entirely and only map the generated position. If so, pass ' +
  22154. 'null for the original mapping instead of an object with empty or null values.';
  22155. if (this._ignoreInvalidMapping) {
  22156. if (typeof console !== 'undefined' && console.warn) {
  22157. console.warn(message);
  22158. }
  22159. return false;
  22160. } else {
  22161. throw new Error(message);
  22162. }
  22163. }
  22164. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  22165. && aGenerated.line > 0 && aGenerated.column >= 0
  22166. && !aOriginal && !aSource && !aName) {
  22167. // Case 1.
  22168. return;
  22169. }
  22170. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  22171. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  22172. && aGenerated.line > 0 && aGenerated.column >= 0
  22173. && aOriginal.line > 0 && aOriginal.column >= 0
  22174. && aSource) {
  22175. // Cases 2 and 3.
  22176. return;
  22177. }
  22178. else {
  22179. var message = 'Invalid mapping: ' + JSON.stringify({
  22180. generated: aGenerated,
  22181. source: aSource,
  22182. original: aOriginal,
  22183. name: aName
  22184. });
  22185. if (this._ignoreInvalidMapping) {
  22186. if (typeof console !== 'undefined' && console.warn) {
  22187. console.warn(message);
  22188. }
  22189. return false;
  22190. } else {
  22191. throw new Error(message)
  22192. }
  22193. }
  22194. };
  22195. /**
  22196. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  22197. * specified by the source map format.
  22198. */
  22199. SourceMapGenerator.prototype._serializeMappings =
  22200. function SourceMapGenerator_serializeMappings() {
  22201. var previousGeneratedColumn = 0;
  22202. var previousGeneratedLine = 1;
  22203. var previousOriginalColumn = 0;
  22204. var previousOriginalLine = 0;
  22205. var previousName = 0;
  22206. var previousSource = 0;
  22207. var result = '';
  22208. var next;
  22209. var mapping;
  22210. var nameIdx;
  22211. var sourceIdx;
  22212. var mappings = this._mappings.toArray();
  22213. for (var i = 0, len = mappings.length; i < len; i++) {
  22214. mapping = mappings[i];
  22215. next = '';
  22216. if (mapping.generatedLine !== previousGeneratedLine) {
  22217. previousGeneratedColumn = 0;
  22218. while (mapping.generatedLine !== previousGeneratedLine) {
  22219. next += ';';
  22220. previousGeneratedLine++;
  22221. }
  22222. }
  22223. else {
  22224. if (i > 0) {
  22225. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  22226. continue;
  22227. }
  22228. next += ',';
  22229. }
  22230. }
  22231. next += base64VLQ.encode(mapping.generatedColumn
  22232. - previousGeneratedColumn);
  22233. previousGeneratedColumn = mapping.generatedColumn;
  22234. if (mapping.source != null) {
  22235. sourceIdx = this._sources.indexOf(mapping.source);
  22236. next += base64VLQ.encode(sourceIdx - previousSource);
  22237. previousSource = sourceIdx;
  22238. // lines are stored 0-based in SourceMap spec version 3
  22239. next += base64VLQ.encode(mapping.originalLine - 1
  22240. - previousOriginalLine);
  22241. previousOriginalLine = mapping.originalLine - 1;
  22242. next += base64VLQ.encode(mapping.originalColumn
  22243. - previousOriginalColumn);
  22244. previousOriginalColumn = mapping.originalColumn;
  22245. if (mapping.name != null) {
  22246. nameIdx = this._names.indexOf(mapping.name);
  22247. next += base64VLQ.encode(nameIdx - previousName);
  22248. previousName = nameIdx;
  22249. }
  22250. }
  22251. result += next;
  22252. }
  22253. return result;
  22254. };
  22255. SourceMapGenerator.prototype._generateSourcesContent =
  22256. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  22257. return aSources.map(function (source) {
  22258. if (!this._sourcesContents) {
  22259. return null;
  22260. }
  22261. if (aSourceRoot != null) {
  22262. source = util.relative(aSourceRoot, source);
  22263. }
  22264. var key = util.toSetString(source);
  22265. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  22266. ? this._sourcesContents[key]
  22267. : null;
  22268. }, this);
  22269. };
  22270. /**
  22271. * Externalize the source map.
  22272. */
  22273. SourceMapGenerator.prototype.toJSON =
  22274. function SourceMapGenerator_toJSON() {
  22275. var map = {
  22276. version: this._version,
  22277. sources: this._sources.toArray(),
  22278. names: this._names.toArray(),
  22279. mappings: this._serializeMappings()
  22280. };
  22281. if (this._file != null) {
  22282. map.file = this._file;
  22283. }
  22284. if (this._sourceRoot != null) {
  22285. map.sourceRoot = this._sourceRoot;
  22286. }
  22287. if (this._sourcesContents) {
  22288. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  22289. }
  22290. return map;
  22291. };
  22292. /**
  22293. * Render the source map being generated to a string.
  22294. */
  22295. SourceMapGenerator.prototype.toString =
  22296. function SourceMapGenerator_toString() {
  22297. return JSON.stringify(this.toJSON());
  22298. };
  22299. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator;
  22300. return sourceMapGenerator$1;
  22301. }
  22302. var sourceMapConsumer$1 = {};
  22303. var binarySearch$1 = {};
  22304. /* -*- Mode: js; js-indent-level: 2; -*- */
  22305. var hasRequiredBinarySearch$1;
  22306. function requireBinarySearch$1 () {
  22307. if (hasRequiredBinarySearch$1) return binarySearch$1;
  22308. hasRequiredBinarySearch$1 = 1;
  22309. (function (exports$1) {
  22310. /*
  22311. * Copyright 2011 Mozilla Foundation and contributors
  22312. * Licensed under the New BSD license. See LICENSE or:
  22313. * http://opensource.org/licenses/BSD-3-Clause
  22314. */
  22315. exports$1.GREATEST_LOWER_BOUND = 1;
  22316. exports$1.LEAST_UPPER_BOUND = 2;
  22317. /**
  22318. * Recursive implementation of binary search.
  22319. *
  22320. * @param aLow Indices here and lower do not contain the needle.
  22321. * @param aHigh Indices here and higher do not contain the needle.
  22322. * @param aNeedle The element being searched for.
  22323. * @param aHaystack The non-empty array being searched.
  22324. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  22325. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  22326. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  22327. * closest element that is smaller than or greater than the one we are
  22328. * searching for, respectively, if the exact element cannot be found.
  22329. */
  22330. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  22331. // This function terminates when one of the following is true:
  22332. //
  22333. // 1. We find the exact element we are looking for.
  22334. //
  22335. // 2. We did not find the exact element, but we can return the index of
  22336. // the next-closest element.
  22337. //
  22338. // 3. We did not find the exact element, and there is no next-closest
  22339. // element than the one we are searching for, so we return -1.
  22340. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  22341. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  22342. if (cmp === 0) {
  22343. // Found the element we are looking for.
  22344. return mid;
  22345. }
  22346. else if (cmp > 0) {
  22347. // Our needle is greater than aHaystack[mid].
  22348. if (aHigh - mid > 1) {
  22349. // The element is in the upper half.
  22350. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  22351. }
  22352. // The exact needle element was not found in this haystack. Determine if
  22353. // we are in termination case (3) or (2) and return the appropriate thing.
  22354. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  22355. return aHigh < aHaystack.length ? aHigh : -1;
  22356. } else {
  22357. return mid;
  22358. }
  22359. }
  22360. else {
  22361. // Our needle is less than aHaystack[mid].
  22362. if (mid - aLow > 1) {
  22363. // The element is in the lower half.
  22364. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  22365. }
  22366. // we are in termination case (3) or (2) and return the appropriate thing.
  22367. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  22368. return mid;
  22369. } else {
  22370. return aLow < 0 ? -1 : aLow;
  22371. }
  22372. }
  22373. }
  22374. /**
  22375. * This is an implementation of binary search which will always try and return
  22376. * the index of the closest element if there is no exact hit. This is because
  22377. * mappings between original and generated line/col pairs are single points,
  22378. * and there is an implicit region between each of them, so a miss just means
  22379. * that you aren't on the very start of a region.
  22380. *
  22381. * @param aNeedle The element you are looking for.
  22382. * @param aHaystack The array that is being searched.
  22383. * @param aCompare A function which takes the needle and an element in the
  22384. * array and returns -1, 0, or 1 depending on whether the needle is less
  22385. * than, equal to, or greater than the element, respectively.
  22386. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  22387. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  22388. * closest element that is smaller than or greater than the one we are
  22389. * searching for, respectively, if the exact element cannot be found.
  22390. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  22391. */
  22392. exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  22393. if (aHaystack.length === 0) {
  22394. return -1;
  22395. }
  22396. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  22397. aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
  22398. if (index < 0) {
  22399. return -1;
  22400. }
  22401. // We have found either the exact element, or the next-closest element than
  22402. // the one we are searching for. However, there may be more than one such
  22403. // element. Make sure we always return the smallest of these.
  22404. while (index - 1 >= 0) {
  22405. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  22406. break;
  22407. }
  22408. --index;
  22409. }
  22410. return index;
  22411. };
  22412. } (binarySearch$1));
  22413. return binarySearch$1;
  22414. }
  22415. var quickSort$1 = {};
  22416. /* -*- Mode: js; js-indent-level: 2; -*- */
  22417. var hasRequiredQuickSort$1;
  22418. function requireQuickSort$1 () {
  22419. if (hasRequiredQuickSort$1) return quickSort$1;
  22420. hasRequiredQuickSort$1 = 1;
  22421. /*
  22422. * Copyright 2011 Mozilla Foundation and contributors
  22423. * Licensed under the New BSD license. See LICENSE or:
  22424. * http://opensource.org/licenses/BSD-3-Clause
  22425. */
  22426. // It turns out that some (most?) JavaScript engines don't self-host
  22427. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  22428. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  22429. // custom comparator function, calling back and forth between the VM's C++ and
  22430. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  22431. // worse generated code for the comparator function than would be optimal. In
  22432. // fact, when sorting with a comparator, these costs outweigh the benefits of
  22433. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  22434. // a ~3500ms mean speed-up in `bench/bench.html`.
  22435. function SortTemplate(comparator) {
  22436. /**
  22437. * Swap the elements indexed by `x` and `y` in the array `ary`.
  22438. *
  22439. * @param {Array} ary
  22440. * The array.
  22441. * @param {Number} x
  22442. * The index of the first item.
  22443. * @param {Number} y
  22444. * The index of the second item.
  22445. */
  22446. function swap(ary, x, y) {
  22447. var temp = ary[x];
  22448. ary[x] = ary[y];
  22449. ary[y] = temp;
  22450. }
  22451. /**
  22452. * Returns a random integer within the range `low .. high` inclusive.
  22453. *
  22454. * @param {Number} low
  22455. * The lower bound on the range.
  22456. * @param {Number} high
  22457. * The upper bound on the range.
  22458. */
  22459. function randomIntInRange(low, high) {
  22460. return Math.round(low + (Math.random() * (high - low)));
  22461. }
  22462. /**
  22463. * The Quick Sort algorithm.
  22464. *
  22465. * @param {Array} ary
  22466. * An array to sort.
  22467. * @param {function} comparator
  22468. * Function to use to compare two items.
  22469. * @param {Number} p
  22470. * Start index of the array
  22471. * @param {Number} r
  22472. * End index of the array
  22473. */
  22474. function doQuickSort(ary, comparator, p, r) {
  22475. // If our lower bound is less than our upper bound, we (1) partition the
  22476. // array into two pieces and (2) recurse on each half. If it is not, this is
  22477. // the empty array and our base case.
  22478. if (p < r) {
  22479. // (1) Partitioning.
  22480. //
  22481. // The partitioning chooses a pivot between `p` and `r` and moves all
  22482. // elements that are less than or equal to the pivot to the before it, and
  22483. // all the elements that are greater than it after it. The effect is that
  22484. // once partition is done, the pivot is in the exact place it will be when
  22485. // the array is put in sorted order, and it will not need to be moved
  22486. // again. This runs in O(n) time.
  22487. // Always choose a random pivot so that an input array which is reverse
  22488. // sorted does not cause O(n^2) running time.
  22489. var pivotIndex = randomIntInRange(p, r);
  22490. var i = p - 1;
  22491. swap(ary, pivotIndex, r);
  22492. var pivot = ary[r];
  22493. // Immediately after `j` is incremented in this loop, the following hold
  22494. // true:
  22495. //
  22496. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  22497. //
  22498. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  22499. for (var j = p; j < r; j++) {
  22500. if (comparator(ary[j], pivot, false) <= 0) {
  22501. i += 1;
  22502. swap(ary, i, j);
  22503. }
  22504. }
  22505. swap(ary, i + 1, j);
  22506. var q = i + 1;
  22507. // (2) Recurse on each half.
  22508. doQuickSort(ary, comparator, p, q - 1);
  22509. doQuickSort(ary, comparator, q + 1, r);
  22510. }
  22511. }
  22512. return doQuickSort;
  22513. }
  22514. function cloneSort(comparator) {
  22515. let template = SortTemplate.toString();
  22516. let templateFn = new Function(`return ${template}`)();
  22517. return templateFn(comparator);
  22518. }
  22519. /**
  22520. * Sort the given array in-place with the given comparator function.
  22521. *
  22522. * @param {Array} ary
  22523. * An array to sort.
  22524. * @param {function} comparator
  22525. * Function to use to compare two items.
  22526. */
  22527. let sortCache = new WeakMap();
  22528. quickSort$1.quickSort = function (ary, comparator, start = 0) {
  22529. let doQuickSort = sortCache.get(comparator);
  22530. if (doQuickSort === void 0) {
  22531. doQuickSort = cloneSort(comparator);
  22532. sortCache.set(comparator, doQuickSort);
  22533. }
  22534. doQuickSort(ary, comparator, start, ary.length - 1);
  22535. };
  22536. return quickSort$1;
  22537. }
  22538. /* -*- Mode: js; js-indent-level: 2; -*- */
  22539. var hasRequiredSourceMapConsumer$1;
  22540. function requireSourceMapConsumer$1 () {
  22541. if (hasRequiredSourceMapConsumer$1) return sourceMapConsumer$1;
  22542. hasRequiredSourceMapConsumer$1 = 1;
  22543. /*
  22544. * Copyright 2011 Mozilla Foundation and contributors
  22545. * Licensed under the New BSD license. See LICENSE or:
  22546. * http://opensource.org/licenses/BSD-3-Clause
  22547. */
  22548. var util = /*@__PURE__*/ requireUtil$2();
  22549. var binarySearch = /*@__PURE__*/ requireBinarySearch$1();
  22550. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  22551. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  22552. var quickSort = /*@__PURE__*/ requireQuickSort$1().quickSort;
  22553. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  22554. var sourceMap = aSourceMap;
  22555. if (typeof aSourceMap === 'string') {
  22556. sourceMap = util.parseSourceMapInput(aSourceMap);
  22557. }
  22558. return sourceMap.sections != null
  22559. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  22560. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  22561. }
  22562. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  22563. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  22564. };
  22565. /**
  22566. * The version of the source mapping spec that we are consuming.
  22567. */
  22568. SourceMapConsumer.prototype._version = 3;
  22569. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  22570. // parsed mapping coordinates from the source map's "mappings" attribute. They
  22571. // are lazily instantiated, accessed via the `_generatedMappings` and
  22572. // `_originalMappings` getters respectively, and we only parse the mappings
  22573. // and create these arrays once queried for a source location. We jump through
  22574. // these hoops because there can be many thousands of mappings, and parsing
  22575. // them is expensive, so we only want to do it if we must.
  22576. //
  22577. // Each object in the arrays is of the form:
  22578. //
  22579. // {
  22580. // generatedLine: The line number in the generated code,
  22581. // generatedColumn: The column number in the generated code,
  22582. // source: The path to the original source file that generated this
  22583. // chunk of code,
  22584. // originalLine: The line number in the original source that
  22585. // corresponds to this chunk of generated code,
  22586. // originalColumn: The column number in the original source that
  22587. // corresponds to this chunk of generated code,
  22588. // name: The name of the original symbol which generated this chunk of
  22589. // code.
  22590. // }
  22591. //
  22592. // All properties except for `generatedLine` and `generatedColumn` can be
  22593. // `null`.
  22594. //
  22595. // `_generatedMappings` is ordered by the generated positions.
  22596. //
  22597. // `_originalMappings` is ordered by the original positions.
  22598. SourceMapConsumer.prototype.__generatedMappings = null;
  22599. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  22600. configurable: true,
  22601. enumerable: true,
  22602. get: function () {
  22603. if (!this.__generatedMappings) {
  22604. this._parseMappings(this._mappings, this.sourceRoot);
  22605. }
  22606. return this.__generatedMappings;
  22607. }
  22608. });
  22609. SourceMapConsumer.prototype.__originalMappings = null;
  22610. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  22611. configurable: true,
  22612. enumerable: true,
  22613. get: function () {
  22614. if (!this.__originalMappings) {
  22615. this._parseMappings(this._mappings, this.sourceRoot);
  22616. }
  22617. return this.__originalMappings;
  22618. }
  22619. });
  22620. SourceMapConsumer.prototype._charIsMappingSeparator =
  22621. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  22622. var c = aStr.charAt(index);
  22623. return c === ";" || c === ",";
  22624. };
  22625. /**
  22626. * Parse the mappings in a string in to a data structure which we can easily
  22627. * query (the ordered arrays in the `this.__generatedMappings` and
  22628. * `this.__originalMappings` properties).
  22629. */
  22630. SourceMapConsumer.prototype._parseMappings =
  22631. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  22632. throw new Error("Subclasses must implement _parseMappings");
  22633. };
  22634. SourceMapConsumer.GENERATED_ORDER = 1;
  22635. SourceMapConsumer.ORIGINAL_ORDER = 2;
  22636. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  22637. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  22638. /**
  22639. * Iterate over each mapping between an original source/line/column and a
  22640. * generated line/column in this source map.
  22641. *
  22642. * @param Function aCallback
  22643. * The function that is called with each mapping.
  22644. * @param Object aContext
  22645. * Optional. If specified, this object will be the value of `this` every
  22646. * time that `aCallback` is called.
  22647. * @param aOrder
  22648. * Either `SourceMapConsumer.GENERATED_ORDER` or
  22649. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  22650. * iterate over the mappings sorted by the generated file's line/column
  22651. * order or the original's source/line/column order, respectively. Defaults to
  22652. * `SourceMapConsumer.GENERATED_ORDER`.
  22653. */
  22654. SourceMapConsumer.prototype.eachMapping =
  22655. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  22656. var context = aContext || null;
  22657. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  22658. var mappings;
  22659. switch (order) {
  22660. case SourceMapConsumer.GENERATED_ORDER:
  22661. mappings = this._generatedMappings;
  22662. break;
  22663. case SourceMapConsumer.ORIGINAL_ORDER:
  22664. mappings = this._originalMappings;
  22665. break;
  22666. default:
  22667. throw new Error("Unknown order of iteration.");
  22668. }
  22669. var sourceRoot = this.sourceRoot;
  22670. var boundCallback = aCallback.bind(context);
  22671. var names = this._names;
  22672. var sources = this._sources;
  22673. var sourceMapURL = this._sourceMapURL;
  22674. for (var i = 0, n = mappings.length; i < n; i++) {
  22675. var mapping = mappings[i];
  22676. var source = mapping.source === null ? null : sources.at(mapping.source);
  22677. if(source !== null) {
  22678. source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
  22679. }
  22680. boundCallback({
  22681. source: source,
  22682. generatedLine: mapping.generatedLine,
  22683. generatedColumn: mapping.generatedColumn,
  22684. originalLine: mapping.originalLine,
  22685. originalColumn: mapping.originalColumn,
  22686. name: mapping.name === null ? null : names.at(mapping.name)
  22687. });
  22688. }
  22689. };
  22690. /**
  22691. * Returns all generated line and column information for the original source,
  22692. * line, and column provided. If no column is provided, returns all mappings
  22693. * corresponding to a either the line we are searching for or the next
  22694. * closest line that has any mappings. Otherwise, returns all mappings
  22695. * corresponding to the given line and either the column we are searching for
  22696. * or the next closest column that has any offsets.
  22697. *
  22698. * The only argument is an object with the following properties:
  22699. *
  22700. * - source: The filename of the original source.
  22701. * - line: The line number in the original source. The line number is 1-based.
  22702. * - column: Optional. the column number in the original source.
  22703. * The column number is 0-based.
  22704. *
  22705. * and an array of objects is returned, each with the following properties:
  22706. *
  22707. * - line: The line number in the generated source, or null. The
  22708. * line number is 1-based.
  22709. * - column: The column number in the generated source, or null.
  22710. * The column number is 0-based.
  22711. */
  22712. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  22713. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  22714. var line = util.getArg(aArgs, 'line');
  22715. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  22716. // returns the index of the closest mapping less than the needle. By
  22717. // setting needle.originalColumn to 0, we thus find the last mapping for
  22718. // the given line, provided such a mapping exists.
  22719. var needle = {
  22720. source: util.getArg(aArgs, 'source'),
  22721. originalLine: line,
  22722. originalColumn: util.getArg(aArgs, 'column', 0)
  22723. };
  22724. needle.source = this._findSourceIndex(needle.source);
  22725. if (needle.source < 0) {
  22726. return [];
  22727. }
  22728. var mappings = [];
  22729. var index = this._findMapping(needle,
  22730. this._originalMappings,
  22731. "originalLine",
  22732. "originalColumn",
  22733. util.compareByOriginalPositions,
  22734. binarySearch.LEAST_UPPER_BOUND);
  22735. if (index >= 0) {
  22736. var mapping = this._originalMappings[index];
  22737. if (aArgs.column === undefined) {
  22738. var originalLine = mapping.originalLine;
  22739. // Iterate until either we run out of mappings, or we run into
  22740. // a mapping for a different line than the one we found. Since
  22741. // mappings are sorted, this is guaranteed to find all mappings for
  22742. // the line we found.
  22743. while (mapping && mapping.originalLine === originalLine) {
  22744. mappings.push({
  22745. line: util.getArg(mapping, 'generatedLine', null),
  22746. column: util.getArg(mapping, 'generatedColumn', null),
  22747. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  22748. });
  22749. mapping = this._originalMappings[++index];
  22750. }
  22751. } else {
  22752. var originalColumn = mapping.originalColumn;
  22753. // Iterate until either we run out of mappings, or we run into
  22754. // a mapping for a different line than the one we were searching for.
  22755. // Since mappings are sorted, this is guaranteed to find all mappings for
  22756. // the line we are searching for.
  22757. while (mapping &&
  22758. mapping.originalLine === line &&
  22759. mapping.originalColumn == originalColumn) {
  22760. mappings.push({
  22761. line: util.getArg(mapping, 'generatedLine', null),
  22762. column: util.getArg(mapping, 'generatedColumn', null),
  22763. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  22764. });
  22765. mapping = this._originalMappings[++index];
  22766. }
  22767. }
  22768. }
  22769. return mappings;
  22770. };
  22771. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer;
  22772. /**
  22773. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  22774. * query for information about the original file positions by giving it a file
  22775. * position in the generated source.
  22776. *
  22777. * The first parameter is the raw source map (either as a JSON string, or
  22778. * already parsed to an object). According to the spec, source maps have the
  22779. * following attributes:
  22780. *
  22781. * - version: Which version of the source map spec this map is following.
  22782. * - sources: An array of URLs to the original source files.
  22783. * - names: An array of identifiers which can be referrenced by individual mappings.
  22784. * - sourceRoot: Optional. The URL root from which all sources are relative.
  22785. * - sourcesContent: Optional. An array of contents of the original source files.
  22786. * - mappings: A string of base64 VLQs which contain the actual mappings.
  22787. * - file: Optional. The generated file this source map is associated with.
  22788. *
  22789. * Here is an example source map, taken from the source map spec[0]:
  22790. *
  22791. * {
  22792. * version : 3,
  22793. * file: "out.js",
  22794. * sourceRoot : "",
  22795. * sources: ["foo.js", "bar.js"],
  22796. * names: ["src", "maps", "are", "fun"],
  22797. * mappings: "AA,AB;;ABCDE;"
  22798. * }
  22799. *
  22800. * The second parameter, if given, is a string whose value is the URL
  22801. * at which the source map was found. This URL is used to compute the
  22802. * sources array.
  22803. *
  22804. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  22805. */
  22806. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  22807. var sourceMap = aSourceMap;
  22808. if (typeof aSourceMap === 'string') {
  22809. sourceMap = util.parseSourceMapInput(aSourceMap);
  22810. }
  22811. var version = util.getArg(sourceMap, 'version');
  22812. var sources = util.getArg(sourceMap, 'sources');
  22813. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  22814. // requires the array) to play nice here.
  22815. var names = util.getArg(sourceMap, 'names', []);
  22816. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  22817. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  22818. var mappings = util.getArg(sourceMap, 'mappings');
  22819. var file = util.getArg(sourceMap, 'file', null);
  22820. // Once again, Sass deviates from the spec and supplies the version as a
  22821. // string rather than a number, so we use loose equality checking here.
  22822. if (version != this._version) {
  22823. throw new Error('Unsupported version: ' + version);
  22824. }
  22825. if (sourceRoot) {
  22826. sourceRoot = util.normalize(sourceRoot);
  22827. }
  22828. sources = sources
  22829. .map(String)
  22830. // Some source maps produce relative source paths like "./foo.js" instead of
  22831. // "foo.js". Normalize these first so that future comparisons will succeed.
  22832. // See bugzil.la/1090768.
  22833. .map(util.normalize)
  22834. // Always ensure that absolute sources are internally stored relative to
  22835. // the source root, if the source root is absolute. Not doing this would
  22836. // be particularly problematic when the source root is a prefix of the
  22837. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  22838. .map(function (source) {
  22839. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  22840. ? util.relative(sourceRoot, source)
  22841. : source;
  22842. });
  22843. // Pass `true` below to allow duplicate names and sources. While source maps
  22844. // are intended to be compressed and deduplicated, the TypeScript compiler
  22845. // sometimes generates source maps with duplicates in them. See Github issue
  22846. // #72 and bugzil.la/889492.
  22847. this._names = ArraySet.fromArray(names.map(String), true);
  22848. this._sources = ArraySet.fromArray(sources, true);
  22849. this._absoluteSources = this._sources.toArray().map(function (s) {
  22850. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  22851. });
  22852. this.sourceRoot = sourceRoot;
  22853. this.sourcesContent = sourcesContent;
  22854. this._mappings = mappings;
  22855. this._sourceMapURL = aSourceMapURL;
  22856. this.file = file;
  22857. }
  22858. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  22859. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  22860. /**
  22861. * Utility function to find the index of a source. Returns -1 if not
  22862. * found.
  22863. */
  22864. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  22865. var relativeSource = aSource;
  22866. if (this.sourceRoot != null) {
  22867. relativeSource = util.relative(this.sourceRoot, relativeSource);
  22868. }
  22869. if (this._sources.has(relativeSource)) {
  22870. return this._sources.indexOf(relativeSource);
  22871. }
  22872. // Maybe aSource is an absolute URL as returned by |sources|. In
  22873. // this case we can't simply undo the transform.
  22874. var i;
  22875. for (i = 0; i < this._absoluteSources.length; ++i) {
  22876. if (this._absoluteSources[i] == aSource) {
  22877. return i;
  22878. }
  22879. }
  22880. return -1;
  22881. };
  22882. /**
  22883. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  22884. *
  22885. * @param SourceMapGenerator aSourceMap
  22886. * The source map that will be consumed.
  22887. * @param String aSourceMapURL
  22888. * The URL at which the source map can be found (optional)
  22889. * @returns BasicSourceMapConsumer
  22890. */
  22891. BasicSourceMapConsumer.fromSourceMap =
  22892. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  22893. var smc = Object.create(BasicSourceMapConsumer.prototype);
  22894. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  22895. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  22896. smc.sourceRoot = aSourceMap._sourceRoot;
  22897. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  22898. smc.sourceRoot);
  22899. smc.file = aSourceMap._file;
  22900. smc._sourceMapURL = aSourceMapURL;
  22901. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  22902. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  22903. });
  22904. // Because we are modifying the entries (by converting string sources and
  22905. // names to indices into the sources and names ArraySets), we have to make
  22906. // a copy of the entry or else bad things happen. Shared mutable state
  22907. // strikes again! See github issue #191.
  22908. var generatedMappings = aSourceMap._mappings.toArray().slice();
  22909. var destGeneratedMappings = smc.__generatedMappings = [];
  22910. var destOriginalMappings = smc.__originalMappings = [];
  22911. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  22912. var srcMapping = generatedMappings[i];
  22913. var destMapping = new Mapping;
  22914. destMapping.generatedLine = srcMapping.generatedLine;
  22915. destMapping.generatedColumn = srcMapping.generatedColumn;
  22916. if (srcMapping.source) {
  22917. destMapping.source = sources.indexOf(srcMapping.source);
  22918. destMapping.originalLine = srcMapping.originalLine;
  22919. destMapping.originalColumn = srcMapping.originalColumn;
  22920. if (srcMapping.name) {
  22921. destMapping.name = names.indexOf(srcMapping.name);
  22922. }
  22923. destOriginalMappings.push(destMapping);
  22924. }
  22925. destGeneratedMappings.push(destMapping);
  22926. }
  22927. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  22928. return smc;
  22929. };
  22930. /**
  22931. * The version of the source mapping spec that we are consuming.
  22932. */
  22933. BasicSourceMapConsumer.prototype._version = 3;
  22934. /**
  22935. * The list of original sources.
  22936. */
  22937. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  22938. get: function () {
  22939. return this._absoluteSources.slice();
  22940. }
  22941. });
  22942. /**
  22943. * Provide the JIT with a nice shape / hidden class.
  22944. */
  22945. function Mapping() {
  22946. this.generatedLine = 0;
  22947. this.generatedColumn = 0;
  22948. this.source = null;
  22949. this.originalLine = null;
  22950. this.originalColumn = null;
  22951. this.name = null;
  22952. }
  22953. /**
  22954. * Parse the mappings in a string in to a data structure which we can easily
  22955. * query (the ordered arrays in the `this.__generatedMappings` and
  22956. * `this.__originalMappings` properties).
  22957. */
  22958. const compareGenerated = util.compareByGeneratedPositionsDeflatedNoLine;
  22959. function sortGenerated(array, start) {
  22960. let l = array.length;
  22961. let n = array.length - start;
  22962. if (n <= 1) {
  22963. return;
  22964. } else if (n == 2) {
  22965. let a = array[start];
  22966. let b = array[start + 1];
  22967. if (compareGenerated(a, b) > 0) {
  22968. array[start] = b;
  22969. array[start + 1] = a;
  22970. }
  22971. } else if (n < 20) {
  22972. for (let i = start; i < l; i++) {
  22973. for (let j = i; j > start; j--) {
  22974. let a = array[j - 1];
  22975. let b = array[j];
  22976. if (compareGenerated(a, b) <= 0) {
  22977. break;
  22978. }
  22979. array[j - 1] = b;
  22980. array[j] = a;
  22981. }
  22982. }
  22983. } else {
  22984. quickSort(array, compareGenerated, start);
  22985. }
  22986. }
  22987. BasicSourceMapConsumer.prototype._parseMappings =
  22988. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  22989. var generatedLine = 1;
  22990. var previousGeneratedColumn = 0;
  22991. var previousOriginalLine = 0;
  22992. var previousOriginalColumn = 0;
  22993. var previousSource = 0;
  22994. var previousName = 0;
  22995. var length = aStr.length;
  22996. var index = 0;
  22997. var temp = {};
  22998. var originalMappings = [];
  22999. var generatedMappings = [];
  23000. var mapping, segment, end, value;
  23001. let subarrayStart = 0;
  23002. while (index < length) {
  23003. if (aStr.charAt(index) === ';') {
  23004. generatedLine++;
  23005. index++;
  23006. previousGeneratedColumn = 0;
  23007. sortGenerated(generatedMappings, subarrayStart);
  23008. subarrayStart = generatedMappings.length;
  23009. }
  23010. else if (aStr.charAt(index) === ',') {
  23011. index++;
  23012. }
  23013. else {
  23014. mapping = new Mapping();
  23015. mapping.generatedLine = generatedLine;
  23016. for (end = index; end < length; end++) {
  23017. if (this._charIsMappingSeparator(aStr, end)) {
  23018. break;
  23019. }
  23020. }
  23021. aStr.slice(index, end);
  23022. segment = [];
  23023. while (index < end) {
  23024. base64VLQ.decode(aStr, index, temp);
  23025. value = temp.value;
  23026. index = temp.rest;
  23027. segment.push(value);
  23028. }
  23029. if (segment.length === 2) {
  23030. throw new Error('Found a source, but no line and column');
  23031. }
  23032. if (segment.length === 3) {
  23033. throw new Error('Found a source and line, but no column');
  23034. }
  23035. // Generated column.
  23036. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  23037. previousGeneratedColumn = mapping.generatedColumn;
  23038. if (segment.length > 1) {
  23039. // Original source.
  23040. mapping.source = previousSource + segment[1];
  23041. previousSource += segment[1];
  23042. // Original line.
  23043. mapping.originalLine = previousOriginalLine + segment[2];
  23044. previousOriginalLine = mapping.originalLine;
  23045. // Lines are stored 0-based
  23046. mapping.originalLine += 1;
  23047. // Original column.
  23048. mapping.originalColumn = previousOriginalColumn + segment[3];
  23049. previousOriginalColumn = mapping.originalColumn;
  23050. if (segment.length > 4) {
  23051. // Original name.
  23052. mapping.name = previousName + segment[4];
  23053. previousName += segment[4];
  23054. }
  23055. }
  23056. generatedMappings.push(mapping);
  23057. if (typeof mapping.originalLine === 'number') {
  23058. let currentSource = mapping.source;
  23059. while (originalMappings.length <= currentSource) {
  23060. originalMappings.push(null);
  23061. }
  23062. if (originalMappings[currentSource] === null) {
  23063. originalMappings[currentSource] = [];
  23064. }
  23065. originalMappings[currentSource].push(mapping);
  23066. }
  23067. }
  23068. }
  23069. sortGenerated(generatedMappings, subarrayStart);
  23070. this.__generatedMappings = generatedMappings;
  23071. for (var i = 0; i < originalMappings.length; i++) {
  23072. if (originalMappings[i] != null) {
  23073. quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource);
  23074. }
  23075. }
  23076. this.__originalMappings = [].concat(...originalMappings);
  23077. };
  23078. /**
  23079. * Find the mapping that best matches the hypothetical "needle" mapping that
  23080. * we are searching for in the given "haystack" of mappings.
  23081. */
  23082. BasicSourceMapConsumer.prototype._findMapping =
  23083. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  23084. aColumnName, aComparator, aBias) {
  23085. // To return the position we are searching for, we must first find the
  23086. // mapping for the given position and then return the opposite position it
  23087. // points to. Because the mappings are sorted, we can use binary search to
  23088. // find the best mapping.
  23089. if (aNeedle[aLineName] <= 0) {
  23090. throw new TypeError('Line must be greater than or equal to 1, got '
  23091. + aNeedle[aLineName]);
  23092. }
  23093. if (aNeedle[aColumnName] < 0) {
  23094. throw new TypeError('Column must be greater than or equal to 0, got '
  23095. + aNeedle[aColumnName]);
  23096. }
  23097. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  23098. };
  23099. /**
  23100. * Compute the last column for each generated mapping. The last column is
  23101. * inclusive.
  23102. */
  23103. BasicSourceMapConsumer.prototype.computeColumnSpans =
  23104. function SourceMapConsumer_computeColumnSpans() {
  23105. for (var index = 0; index < this._generatedMappings.length; ++index) {
  23106. var mapping = this._generatedMappings[index];
  23107. // Mappings do not contain a field for the last generated columnt. We
  23108. // can come up with an optimistic estimate, however, by assuming that
  23109. // mappings are contiguous (i.e. given two consecutive mappings, the
  23110. // first mapping ends where the second one starts).
  23111. if (index + 1 < this._generatedMappings.length) {
  23112. var nextMapping = this._generatedMappings[index + 1];
  23113. if (mapping.generatedLine === nextMapping.generatedLine) {
  23114. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  23115. continue;
  23116. }
  23117. }
  23118. // The last mapping for each line spans the entire line.
  23119. mapping.lastGeneratedColumn = Infinity;
  23120. }
  23121. };
  23122. /**
  23123. * Returns the original source, line, and column information for the generated
  23124. * source's line and column positions provided. The only argument is an object
  23125. * with the following properties:
  23126. *
  23127. * - line: The line number in the generated source. The line number
  23128. * is 1-based.
  23129. * - column: The column number in the generated source. The column
  23130. * number is 0-based.
  23131. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  23132. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  23133. * closest element that is smaller than or greater than the one we are
  23134. * searching for, respectively, if the exact element cannot be found.
  23135. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  23136. *
  23137. * and an object is returned with the following properties:
  23138. *
  23139. * - source: The original source file, or null.
  23140. * - line: The line number in the original source, or null. The
  23141. * line number is 1-based.
  23142. * - column: The column number in the original source, or null. The
  23143. * column number is 0-based.
  23144. * - name: The original identifier, or null.
  23145. */
  23146. BasicSourceMapConsumer.prototype.originalPositionFor =
  23147. function SourceMapConsumer_originalPositionFor(aArgs) {
  23148. var needle = {
  23149. generatedLine: util.getArg(aArgs, 'line'),
  23150. generatedColumn: util.getArg(aArgs, 'column')
  23151. };
  23152. var index = this._findMapping(
  23153. needle,
  23154. this._generatedMappings,
  23155. "generatedLine",
  23156. "generatedColumn",
  23157. util.compareByGeneratedPositionsDeflated,
  23158. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  23159. );
  23160. if (index >= 0) {
  23161. var mapping = this._generatedMappings[index];
  23162. if (mapping.generatedLine === needle.generatedLine) {
  23163. var source = util.getArg(mapping, 'source', null);
  23164. if (source !== null) {
  23165. source = this._sources.at(source);
  23166. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  23167. }
  23168. var name = util.getArg(mapping, 'name', null);
  23169. if (name !== null) {
  23170. name = this._names.at(name);
  23171. }
  23172. return {
  23173. source: source,
  23174. line: util.getArg(mapping, 'originalLine', null),
  23175. column: util.getArg(mapping, 'originalColumn', null),
  23176. name: name
  23177. };
  23178. }
  23179. }
  23180. return {
  23181. source: null,
  23182. line: null,
  23183. column: null,
  23184. name: null
  23185. };
  23186. };
  23187. /**
  23188. * Return true if we have the source content for every source in the source
  23189. * map, false otherwise.
  23190. */
  23191. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  23192. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  23193. if (!this.sourcesContent) {
  23194. return false;
  23195. }
  23196. return this.sourcesContent.length >= this._sources.size() &&
  23197. !this.sourcesContent.some(function (sc) { return sc == null; });
  23198. };
  23199. /**
  23200. * Returns the original source content. The only argument is the url of the
  23201. * original source file. Returns null if no original source content is
  23202. * available.
  23203. */
  23204. BasicSourceMapConsumer.prototype.sourceContentFor =
  23205. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  23206. if (!this.sourcesContent) {
  23207. return null;
  23208. }
  23209. var index = this._findSourceIndex(aSource);
  23210. if (index >= 0) {
  23211. return this.sourcesContent[index];
  23212. }
  23213. var relativeSource = aSource;
  23214. if (this.sourceRoot != null) {
  23215. relativeSource = util.relative(this.sourceRoot, relativeSource);
  23216. }
  23217. var url;
  23218. if (this.sourceRoot != null
  23219. && (url = util.urlParse(this.sourceRoot))) {
  23220. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  23221. // many users. We can help them out when they expect file:// URIs to
  23222. // behave like it would if they were running a local HTTP server. See
  23223. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  23224. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  23225. if (url.scheme == "file"
  23226. && this._sources.has(fileUriAbsPath)) {
  23227. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  23228. }
  23229. if ((!url.path || url.path == "/")
  23230. && this._sources.has("/" + relativeSource)) {
  23231. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  23232. }
  23233. }
  23234. // This function is used recursively from
  23235. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  23236. // don't want to throw if we can't find the source - we just want to
  23237. // return null, so we provide a flag to exit gracefully.
  23238. if (nullOnMissing) {
  23239. return null;
  23240. }
  23241. else {
  23242. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  23243. }
  23244. };
  23245. /**
  23246. * Returns the generated line and column information for the original source,
  23247. * line, and column positions provided. The only argument is an object with
  23248. * the following properties:
  23249. *
  23250. * - source: The filename of the original source.
  23251. * - line: The line number in the original source. The line number
  23252. * is 1-based.
  23253. * - column: The column number in the original source. The column
  23254. * number is 0-based.
  23255. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  23256. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  23257. * closest element that is smaller than or greater than the one we are
  23258. * searching for, respectively, if the exact element cannot be found.
  23259. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  23260. *
  23261. * and an object is returned with the following properties:
  23262. *
  23263. * - line: The line number in the generated source, or null. The
  23264. * line number is 1-based.
  23265. * - column: The column number in the generated source, or null.
  23266. * The column number is 0-based.
  23267. */
  23268. BasicSourceMapConsumer.prototype.generatedPositionFor =
  23269. function SourceMapConsumer_generatedPositionFor(aArgs) {
  23270. var source = util.getArg(aArgs, 'source');
  23271. source = this._findSourceIndex(source);
  23272. if (source < 0) {
  23273. return {
  23274. line: null,
  23275. column: null,
  23276. lastColumn: null
  23277. };
  23278. }
  23279. var needle = {
  23280. source: source,
  23281. originalLine: util.getArg(aArgs, 'line'),
  23282. originalColumn: util.getArg(aArgs, 'column')
  23283. };
  23284. var index = this._findMapping(
  23285. needle,
  23286. this._originalMappings,
  23287. "originalLine",
  23288. "originalColumn",
  23289. util.compareByOriginalPositions,
  23290. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  23291. );
  23292. if (index >= 0) {
  23293. var mapping = this._originalMappings[index];
  23294. if (mapping.source === needle.source) {
  23295. return {
  23296. line: util.getArg(mapping, 'generatedLine', null),
  23297. column: util.getArg(mapping, 'generatedColumn', null),
  23298. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  23299. };
  23300. }
  23301. }
  23302. return {
  23303. line: null,
  23304. column: null,
  23305. lastColumn: null
  23306. };
  23307. };
  23308. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer;
  23309. /**
  23310. * An IndexedSourceMapConsumer instance represents a parsed source map which
  23311. * we can query for information. It differs from BasicSourceMapConsumer in
  23312. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  23313. * input.
  23314. *
  23315. * The first parameter is a raw source map (either as a JSON string, or already
  23316. * parsed to an object). According to the spec for indexed source maps, they
  23317. * have the following attributes:
  23318. *
  23319. * - version: Which version of the source map spec this map is following.
  23320. * - file: Optional. The generated file this source map is associated with.
  23321. * - sections: A list of section definitions.
  23322. *
  23323. * Each value under the "sections" field has two fields:
  23324. * - offset: The offset into the original specified at which this section
  23325. * begins to apply, defined as an object with a "line" and "column"
  23326. * field.
  23327. * - map: A source map definition. This source map could also be indexed,
  23328. * but doesn't have to be.
  23329. *
  23330. * Instead of the "map" field, it's also possible to have a "url" field
  23331. * specifying a URL to retrieve a source map from, but that's currently
  23332. * unsupported.
  23333. *
  23334. * Here's an example source map, taken from the source map spec[0], but
  23335. * modified to omit a section which uses the "url" field.
  23336. *
  23337. * {
  23338. * version : 3,
  23339. * file: "app.js",
  23340. * sections: [{
  23341. * offset: {line:100, column:10},
  23342. * map: {
  23343. * version : 3,
  23344. * file: "section.js",
  23345. * sources: ["foo.js", "bar.js"],
  23346. * names: ["src", "maps", "are", "fun"],
  23347. * mappings: "AAAA,E;;ABCDE;"
  23348. * }
  23349. * }],
  23350. * }
  23351. *
  23352. * The second parameter, if given, is a string whose value is the URL
  23353. * at which the source map was found. This URL is used to compute the
  23354. * sources array.
  23355. *
  23356. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  23357. */
  23358. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  23359. var sourceMap = aSourceMap;
  23360. if (typeof aSourceMap === 'string') {
  23361. sourceMap = util.parseSourceMapInput(aSourceMap);
  23362. }
  23363. var version = util.getArg(sourceMap, 'version');
  23364. var sections = util.getArg(sourceMap, 'sections');
  23365. if (version != this._version) {
  23366. throw new Error('Unsupported version: ' + version);
  23367. }
  23368. this._sources = new ArraySet();
  23369. this._names = new ArraySet();
  23370. var lastOffset = {
  23371. line: -1,
  23372. column: 0
  23373. };
  23374. this._sections = sections.map(function (s) {
  23375. if (s.url) {
  23376. // The url field will require support for asynchronicity.
  23377. // See https://github.com/mozilla/source-map/issues/16
  23378. throw new Error('Support for url field in sections not implemented.');
  23379. }
  23380. var offset = util.getArg(s, 'offset');
  23381. var offsetLine = util.getArg(offset, 'line');
  23382. var offsetColumn = util.getArg(offset, 'column');
  23383. if (offsetLine < lastOffset.line ||
  23384. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  23385. throw new Error('Section offsets must be ordered and non-overlapping.');
  23386. }
  23387. lastOffset = offset;
  23388. return {
  23389. generatedOffset: {
  23390. // The offset fields are 0-based, but we use 1-based indices when
  23391. // encoding/decoding from VLQ.
  23392. generatedLine: offsetLine + 1,
  23393. generatedColumn: offsetColumn + 1
  23394. },
  23395. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  23396. }
  23397. });
  23398. }
  23399. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  23400. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  23401. /**
  23402. * The version of the source mapping spec that we are consuming.
  23403. */
  23404. IndexedSourceMapConsumer.prototype._version = 3;
  23405. /**
  23406. * The list of original sources.
  23407. */
  23408. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  23409. get: function () {
  23410. var sources = [];
  23411. for (var i = 0; i < this._sections.length; i++) {
  23412. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  23413. sources.push(this._sections[i].consumer.sources[j]);
  23414. }
  23415. }
  23416. return sources;
  23417. }
  23418. });
  23419. /**
  23420. * Returns the original source, line, and column information for the generated
  23421. * source's line and column positions provided. The only argument is an object
  23422. * with the following properties:
  23423. *
  23424. * - line: The line number in the generated source. The line number
  23425. * is 1-based.
  23426. * - column: The column number in the generated source. The column
  23427. * number is 0-based.
  23428. *
  23429. * and an object is returned with the following properties:
  23430. *
  23431. * - source: The original source file, or null.
  23432. * - line: The line number in the original source, or null. The
  23433. * line number is 1-based.
  23434. * - column: The column number in the original source, or null. The
  23435. * column number is 0-based.
  23436. * - name: The original identifier, or null.
  23437. */
  23438. IndexedSourceMapConsumer.prototype.originalPositionFor =
  23439. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  23440. var needle = {
  23441. generatedLine: util.getArg(aArgs, 'line'),
  23442. generatedColumn: util.getArg(aArgs, 'column')
  23443. };
  23444. // Find the section containing the generated position we're trying to map
  23445. // to an original position.
  23446. var sectionIndex = binarySearch.search(needle, this._sections,
  23447. function(needle, section) {
  23448. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  23449. if (cmp) {
  23450. return cmp;
  23451. }
  23452. return (needle.generatedColumn -
  23453. section.generatedOffset.generatedColumn);
  23454. });
  23455. var section = this._sections[sectionIndex];
  23456. if (!section) {
  23457. return {
  23458. source: null,
  23459. line: null,
  23460. column: null,
  23461. name: null
  23462. };
  23463. }
  23464. return section.consumer.originalPositionFor({
  23465. line: needle.generatedLine -
  23466. (section.generatedOffset.generatedLine - 1),
  23467. column: needle.generatedColumn -
  23468. (section.generatedOffset.generatedLine === needle.generatedLine
  23469. ? section.generatedOffset.generatedColumn - 1
  23470. : 0),
  23471. bias: aArgs.bias
  23472. });
  23473. };
  23474. /**
  23475. * Return true if we have the source content for every source in the source
  23476. * map, false otherwise.
  23477. */
  23478. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  23479. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  23480. return this._sections.every(function (s) {
  23481. return s.consumer.hasContentsOfAllSources();
  23482. });
  23483. };
  23484. /**
  23485. * Returns the original source content. The only argument is the url of the
  23486. * original source file. Returns null if no original source content is
  23487. * available.
  23488. */
  23489. IndexedSourceMapConsumer.prototype.sourceContentFor =
  23490. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  23491. for (var i = 0; i < this._sections.length; i++) {
  23492. var section = this._sections[i];
  23493. var content = section.consumer.sourceContentFor(aSource, true);
  23494. if (content || content === '') {
  23495. return content;
  23496. }
  23497. }
  23498. if (nullOnMissing) {
  23499. return null;
  23500. }
  23501. else {
  23502. throw new Error('"' + aSource + '" is not in the SourceMap.');
  23503. }
  23504. };
  23505. /**
  23506. * Returns the generated line and column information for the original source,
  23507. * line, and column positions provided. The only argument is an object with
  23508. * the following properties:
  23509. *
  23510. * - source: The filename of the original source.
  23511. * - line: The line number in the original source. The line number
  23512. * is 1-based.
  23513. * - column: The column number in the original source. The column
  23514. * number is 0-based.
  23515. *
  23516. * and an object is returned with the following properties:
  23517. *
  23518. * - line: The line number in the generated source, or null. The
  23519. * line number is 1-based.
  23520. * - column: The column number in the generated source, or null.
  23521. * The column number is 0-based.
  23522. */
  23523. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  23524. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  23525. for (var i = 0; i < this._sections.length; i++) {
  23526. var section = this._sections[i];
  23527. // Only consider this section if the requested source is in the list of
  23528. // sources of the consumer.
  23529. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  23530. continue;
  23531. }
  23532. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  23533. if (generatedPosition) {
  23534. var ret = {
  23535. line: generatedPosition.line +
  23536. (section.generatedOffset.generatedLine - 1),
  23537. column: generatedPosition.column +
  23538. (section.generatedOffset.generatedLine === generatedPosition.line
  23539. ? section.generatedOffset.generatedColumn - 1
  23540. : 0)
  23541. };
  23542. return ret;
  23543. }
  23544. }
  23545. return {
  23546. line: null,
  23547. column: null
  23548. };
  23549. };
  23550. /**
  23551. * Parse the mappings in a string in to a data structure which we can easily
  23552. * query (the ordered arrays in the `this.__generatedMappings` and
  23553. * `this.__originalMappings` properties).
  23554. */
  23555. IndexedSourceMapConsumer.prototype._parseMappings =
  23556. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  23557. this.__generatedMappings = [];
  23558. this.__originalMappings = [];
  23559. for (var i = 0; i < this._sections.length; i++) {
  23560. var section = this._sections[i];
  23561. var sectionMappings = section.consumer._generatedMappings;
  23562. for (var j = 0; j < sectionMappings.length; j++) {
  23563. var mapping = sectionMappings[j];
  23564. var source = section.consumer._sources.at(mapping.source);
  23565. if(source !== null) {
  23566. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  23567. }
  23568. this._sources.add(source);
  23569. source = this._sources.indexOf(source);
  23570. var name = null;
  23571. if (mapping.name) {
  23572. name = section.consumer._names.at(mapping.name);
  23573. this._names.add(name);
  23574. name = this._names.indexOf(name);
  23575. }
  23576. // The mappings coming from the consumer for the section have
  23577. // generated positions relative to the start of the section, so we
  23578. // need to offset them to be relative to the start of the concatenated
  23579. // generated file.
  23580. var adjustedMapping = {
  23581. source: source,
  23582. generatedLine: mapping.generatedLine +
  23583. (section.generatedOffset.generatedLine - 1),
  23584. generatedColumn: mapping.generatedColumn +
  23585. (section.generatedOffset.generatedLine === mapping.generatedLine
  23586. ? section.generatedOffset.generatedColumn - 1
  23587. : 0),
  23588. originalLine: mapping.originalLine,
  23589. originalColumn: mapping.originalColumn,
  23590. name: name
  23591. };
  23592. this.__generatedMappings.push(adjustedMapping);
  23593. if (typeof adjustedMapping.originalLine === 'number') {
  23594. this.__originalMappings.push(adjustedMapping);
  23595. }
  23596. }
  23597. }
  23598. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  23599. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  23600. };
  23601. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  23602. return sourceMapConsumer$1;
  23603. }
  23604. var sourceNode$1 = {};
  23605. /* -*- Mode: js; js-indent-level: 2; -*- */
  23606. var hasRequiredSourceNode$1;
  23607. function requireSourceNode$1 () {
  23608. if (hasRequiredSourceNode$1) return sourceNode$1;
  23609. hasRequiredSourceNode$1 = 1;
  23610. /*
  23611. * Copyright 2011 Mozilla Foundation and contributors
  23612. * Licensed under the New BSD license. See LICENSE or:
  23613. * http://opensource.org/licenses/BSD-3-Clause
  23614. */
  23615. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  23616. var util = /*@__PURE__*/ requireUtil$2();
  23617. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  23618. // operating systems these days (capturing the result).
  23619. var REGEX_NEWLINE = /(\r?\n)/;
  23620. // Newline character code for charCodeAt() comparisons
  23621. var NEWLINE_CODE = 10;
  23622. // Private symbol for identifying `SourceNode`s when multiple versions of
  23623. // the source-map library are loaded. This MUST NOT CHANGE across
  23624. // versions!
  23625. var isSourceNode = "$$$isSourceNode$$$";
  23626. /**
  23627. * SourceNodes provide a way to abstract over interpolating/concatenating
  23628. * snippets of generated JavaScript source code while maintaining the line and
  23629. * column information associated with the original source code.
  23630. *
  23631. * @param aLine The original line number.
  23632. * @param aColumn The original column number.
  23633. * @param aSource The original source's filename.
  23634. * @param aChunks Optional. An array of strings which are snippets of
  23635. * generated JS, or other SourceNodes.
  23636. * @param aName The original identifier.
  23637. */
  23638. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  23639. this.children = [];
  23640. this.sourceContents = {};
  23641. this.line = aLine == null ? null : aLine;
  23642. this.column = aColumn == null ? null : aColumn;
  23643. this.source = aSource == null ? null : aSource;
  23644. this.name = aName == null ? null : aName;
  23645. this[isSourceNode] = true;
  23646. if (aChunks != null) this.add(aChunks);
  23647. }
  23648. /**
  23649. * Creates a SourceNode from generated code and a SourceMapConsumer.
  23650. *
  23651. * @param aGeneratedCode The generated code
  23652. * @param aSourceMapConsumer The SourceMap for the generated code
  23653. * @param aRelativePath Optional. The path that relative sources in the
  23654. * SourceMapConsumer should be relative to.
  23655. */
  23656. SourceNode.fromStringWithSourceMap =
  23657. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  23658. // The SourceNode we want to fill with the generated code
  23659. // and the SourceMap
  23660. var node = new SourceNode();
  23661. // All even indices of this array are one line of the generated code,
  23662. // while all odd indices are the newlines between two adjacent lines
  23663. // (since `REGEX_NEWLINE` captures its match).
  23664. // Processed fragments are accessed by calling `shiftNextLine`.
  23665. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  23666. var remainingLinesIndex = 0;
  23667. var shiftNextLine = function() {
  23668. var lineContents = getNextLine();
  23669. // The last line of a file might not have a newline.
  23670. var newLine = getNextLine() || "";
  23671. return lineContents + newLine;
  23672. function getNextLine() {
  23673. return remainingLinesIndex < remainingLines.length ?
  23674. remainingLines[remainingLinesIndex++] : undefined;
  23675. }
  23676. };
  23677. // We need to remember the position of "remainingLines"
  23678. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  23679. // The generate SourceNodes we need a code range.
  23680. // To extract it current and last mapping is used.
  23681. // Here we store the last mapping.
  23682. var lastMapping = null;
  23683. aSourceMapConsumer.eachMapping(function (mapping) {
  23684. if (lastMapping !== null) {
  23685. // We add the code from "lastMapping" to "mapping":
  23686. // First check if there is a new line in between.
  23687. if (lastGeneratedLine < mapping.generatedLine) {
  23688. // Associate first line with "lastMapping"
  23689. addMappingWithCode(lastMapping, shiftNextLine());
  23690. lastGeneratedLine++;
  23691. lastGeneratedColumn = 0;
  23692. // The remaining code is added without mapping
  23693. } else {
  23694. // There is no new line in between.
  23695. // Associate the code between "lastGeneratedColumn" and
  23696. // "mapping.generatedColumn" with "lastMapping"
  23697. var nextLine = remainingLines[remainingLinesIndex] || '';
  23698. var code = nextLine.substr(0, mapping.generatedColumn -
  23699. lastGeneratedColumn);
  23700. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  23701. lastGeneratedColumn);
  23702. lastGeneratedColumn = mapping.generatedColumn;
  23703. addMappingWithCode(lastMapping, code);
  23704. // No more remaining code, continue
  23705. lastMapping = mapping;
  23706. return;
  23707. }
  23708. }
  23709. // We add the generated code until the first mapping
  23710. // to the SourceNode without any mapping.
  23711. // Each line is added as separate string.
  23712. while (lastGeneratedLine < mapping.generatedLine) {
  23713. node.add(shiftNextLine());
  23714. lastGeneratedLine++;
  23715. }
  23716. if (lastGeneratedColumn < mapping.generatedColumn) {
  23717. var nextLine = remainingLines[remainingLinesIndex] || '';
  23718. node.add(nextLine.substr(0, mapping.generatedColumn));
  23719. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  23720. lastGeneratedColumn = mapping.generatedColumn;
  23721. }
  23722. lastMapping = mapping;
  23723. }, this);
  23724. // We have processed all mappings.
  23725. if (remainingLinesIndex < remainingLines.length) {
  23726. if (lastMapping) {
  23727. // Associate the remaining code in the current line with "lastMapping"
  23728. addMappingWithCode(lastMapping, shiftNextLine());
  23729. }
  23730. // and add the remaining lines without any mapping
  23731. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  23732. }
  23733. // Copy sourcesContent into SourceNode
  23734. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  23735. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  23736. if (content != null) {
  23737. if (aRelativePath != null) {
  23738. sourceFile = util.join(aRelativePath, sourceFile);
  23739. }
  23740. node.setSourceContent(sourceFile, content);
  23741. }
  23742. });
  23743. return node;
  23744. function addMappingWithCode(mapping, code) {
  23745. if (mapping === null || mapping.source === undefined) {
  23746. node.add(code);
  23747. } else {
  23748. var source = aRelativePath
  23749. ? util.join(aRelativePath, mapping.source)
  23750. : mapping.source;
  23751. node.add(new SourceNode(mapping.originalLine,
  23752. mapping.originalColumn,
  23753. source,
  23754. code,
  23755. mapping.name));
  23756. }
  23757. }
  23758. };
  23759. /**
  23760. * Add a chunk of generated JS to this source node.
  23761. *
  23762. * @param aChunk A string snippet of generated JS code, another instance of
  23763. * SourceNode, or an array where each member is one of those things.
  23764. */
  23765. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  23766. if (Array.isArray(aChunk)) {
  23767. aChunk.forEach(function (chunk) {
  23768. this.add(chunk);
  23769. }, this);
  23770. }
  23771. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  23772. if (aChunk) {
  23773. this.children.push(aChunk);
  23774. }
  23775. }
  23776. else {
  23777. throw new TypeError(
  23778. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  23779. );
  23780. }
  23781. return this;
  23782. };
  23783. /**
  23784. * Add a chunk of generated JS to the beginning of this source node.
  23785. *
  23786. * @param aChunk A string snippet of generated JS code, another instance of
  23787. * SourceNode, or an array where each member is one of those things.
  23788. */
  23789. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  23790. if (Array.isArray(aChunk)) {
  23791. for (var i = aChunk.length-1; i >= 0; i--) {
  23792. this.prepend(aChunk[i]);
  23793. }
  23794. }
  23795. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  23796. this.children.unshift(aChunk);
  23797. }
  23798. else {
  23799. throw new TypeError(
  23800. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  23801. );
  23802. }
  23803. return this;
  23804. };
  23805. /**
  23806. * Walk over the tree of JS snippets in this node and its children. The
  23807. * walking function is called once for each snippet of JS and is passed that
  23808. * snippet and the its original associated source's line/column location.
  23809. *
  23810. * @param aFn The traversal function.
  23811. */
  23812. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  23813. var chunk;
  23814. for (var i = 0, len = this.children.length; i < len; i++) {
  23815. chunk = this.children[i];
  23816. if (chunk[isSourceNode]) {
  23817. chunk.walk(aFn);
  23818. }
  23819. else {
  23820. if (chunk !== '') {
  23821. aFn(chunk, { source: this.source,
  23822. line: this.line,
  23823. column: this.column,
  23824. name: this.name });
  23825. }
  23826. }
  23827. }
  23828. };
  23829. /**
  23830. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  23831. * each of `this.children`.
  23832. *
  23833. * @param aSep The separator.
  23834. */
  23835. SourceNode.prototype.join = function SourceNode_join(aSep) {
  23836. var newChildren;
  23837. var i;
  23838. var len = this.children.length;
  23839. if (len > 0) {
  23840. newChildren = [];
  23841. for (i = 0; i < len-1; i++) {
  23842. newChildren.push(this.children[i]);
  23843. newChildren.push(aSep);
  23844. }
  23845. newChildren.push(this.children[i]);
  23846. this.children = newChildren;
  23847. }
  23848. return this;
  23849. };
  23850. /**
  23851. * Call String.prototype.replace on the very right-most source snippet. Useful
  23852. * for trimming whitespace from the end of a source node, etc.
  23853. *
  23854. * @param aPattern The pattern to replace.
  23855. * @param aReplacement The thing to replace the pattern with.
  23856. */
  23857. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  23858. var lastChild = this.children[this.children.length - 1];
  23859. if (lastChild[isSourceNode]) {
  23860. lastChild.replaceRight(aPattern, aReplacement);
  23861. }
  23862. else if (typeof lastChild === 'string') {
  23863. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  23864. }
  23865. else {
  23866. this.children.push(''.replace(aPattern, aReplacement));
  23867. }
  23868. return this;
  23869. };
  23870. /**
  23871. * Set the source content for a source file. This will be added to the SourceMapGenerator
  23872. * in the sourcesContent field.
  23873. *
  23874. * @param aSourceFile The filename of the source file
  23875. * @param aSourceContent The content of the source file
  23876. */
  23877. SourceNode.prototype.setSourceContent =
  23878. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  23879. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  23880. };
  23881. /**
  23882. * Walk over the tree of SourceNodes. The walking function is called for each
  23883. * source file content and is passed the filename and source content.
  23884. *
  23885. * @param aFn The traversal function.
  23886. */
  23887. SourceNode.prototype.walkSourceContents =
  23888. function SourceNode_walkSourceContents(aFn) {
  23889. for (var i = 0, len = this.children.length; i < len; i++) {
  23890. if (this.children[i][isSourceNode]) {
  23891. this.children[i].walkSourceContents(aFn);
  23892. }
  23893. }
  23894. var sources = Object.keys(this.sourceContents);
  23895. for (var i = 0, len = sources.length; i < len; i++) {
  23896. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  23897. }
  23898. };
  23899. /**
  23900. * Return the string representation of this source node. Walks over the tree
  23901. * and concatenates all the various snippets together to one string.
  23902. */
  23903. SourceNode.prototype.toString = function SourceNode_toString() {
  23904. var str = "";
  23905. this.walk(function (chunk) {
  23906. str += chunk;
  23907. });
  23908. return str;
  23909. };
  23910. /**
  23911. * Returns the string representation of this source node along with a source
  23912. * map.
  23913. */
  23914. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  23915. var generated = {
  23916. code: "",
  23917. line: 1,
  23918. column: 0
  23919. };
  23920. var map = new SourceMapGenerator(aArgs);
  23921. var sourceMappingActive = false;
  23922. var lastOriginalSource = null;
  23923. var lastOriginalLine = null;
  23924. var lastOriginalColumn = null;
  23925. var lastOriginalName = null;
  23926. this.walk(function (chunk, original) {
  23927. generated.code += chunk;
  23928. if (original.source !== null
  23929. && original.line !== null
  23930. && original.column !== null) {
  23931. if(lastOriginalSource !== original.source
  23932. || lastOriginalLine !== original.line
  23933. || lastOriginalColumn !== original.column
  23934. || lastOriginalName !== original.name) {
  23935. map.addMapping({
  23936. source: original.source,
  23937. original: {
  23938. line: original.line,
  23939. column: original.column
  23940. },
  23941. generated: {
  23942. line: generated.line,
  23943. column: generated.column
  23944. },
  23945. name: original.name
  23946. });
  23947. }
  23948. lastOriginalSource = original.source;
  23949. lastOriginalLine = original.line;
  23950. lastOriginalColumn = original.column;
  23951. lastOriginalName = original.name;
  23952. sourceMappingActive = true;
  23953. } else if (sourceMappingActive) {
  23954. map.addMapping({
  23955. generated: {
  23956. line: generated.line,
  23957. column: generated.column
  23958. }
  23959. });
  23960. lastOriginalSource = null;
  23961. sourceMappingActive = false;
  23962. }
  23963. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  23964. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  23965. generated.line++;
  23966. generated.column = 0;
  23967. // Mappings end at eol
  23968. if (idx + 1 === length) {
  23969. lastOriginalSource = null;
  23970. sourceMappingActive = false;
  23971. } else if (sourceMappingActive) {
  23972. map.addMapping({
  23973. source: original.source,
  23974. original: {
  23975. line: original.line,
  23976. column: original.column
  23977. },
  23978. generated: {
  23979. line: generated.line,
  23980. column: generated.column
  23981. },
  23982. name: original.name
  23983. });
  23984. }
  23985. } else {
  23986. generated.column++;
  23987. }
  23988. }
  23989. });
  23990. this.walkSourceContents(function (sourceFile, sourceContent) {
  23991. map.setSourceContent(sourceFile, sourceContent);
  23992. });
  23993. return { code: generated.code, map: map };
  23994. };
  23995. sourceNode$1.SourceNode = SourceNode;
  23996. return sourceNode$1;
  23997. }
  23998. /*
  23999. * Copyright 2009-2011 Mozilla Foundation and contributors
  24000. * Licensed under the New BSD license. See LICENSE.txt or:
  24001. * http://opensource.org/licenses/BSD-3-Clause
  24002. */
  24003. var hasRequiredSourceMap$1;
  24004. function requireSourceMap$1 () {
  24005. if (hasRequiredSourceMap$1) return sourceMap$1;
  24006. hasRequiredSourceMap$1 = 1;
  24007. sourceMap$1.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  24008. sourceMap$1.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer$1().SourceMapConsumer;
  24009. sourceMap$1.SourceNode = /*@__PURE__*/ requireSourceNode$1().SourceNode;
  24010. return sourceMap$1;
  24011. }
  24012. var sourceMapExports = /*@__PURE__*/ requireSourceMap$1();
  24013. const PURE_ANNOTATION = `/*@__PURE__*/`;
  24014. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  24015. function createCodegenContext(ast, {
  24016. mode = "function",
  24017. prefixIdentifiers = mode === "module",
  24018. sourceMap = false,
  24019. filename = `template.vue.html`,
  24020. scopeId = null,
  24021. optimizeImports = false,
  24022. runtimeGlobalName = `Vue`,
  24023. runtimeModuleName = `vue`,
  24024. ssrRuntimeModuleName = "vue/server-renderer",
  24025. ssr = false,
  24026. isTS = false,
  24027. inSSR = false
  24028. }) {
  24029. const context = {
  24030. mode,
  24031. prefixIdentifiers,
  24032. sourceMap,
  24033. filename,
  24034. scopeId,
  24035. optimizeImports,
  24036. runtimeGlobalName,
  24037. runtimeModuleName,
  24038. ssrRuntimeModuleName,
  24039. ssr,
  24040. isTS,
  24041. inSSR,
  24042. source: ast.source,
  24043. code: ``,
  24044. column: 1,
  24045. line: 1,
  24046. offset: 0,
  24047. indentLevel: 0,
  24048. pure: false,
  24049. map: void 0,
  24050. helper(key) {
  24051. return `_${helperNameMap[key]}`;
  24052. },
  24053. push(code, newlineIndex = -2 /* None */, node) {
  24054. context.code += code;
  24055. if (context.map) {
  24056. if (node) {
  24057. let name;
  24058. if (node.type === 4 && !node.isStatic) {
  24059. const content = node.content.replace(/^_ctx\./, "");
  24060. if (content !== node.content && isSimpleIdentifier(content)) {
  24061. name = content;
  24062. }
  24063. }
  24064. if (node.loc.source) {
  24065. addMapping(node.loc.start, name);
  24066. }
  24067. }
  24068. if (newlineIndex === -3 /* Unknown */) {
  24069. advancePositionWithMutation(context, code);
  24070. } else {
  24071. context.offset += code.length;
  24072. if (newlineIndex === -2 /* None */) {
  24073. context.column += code.length;
  24074. } else {
  24075. if (newlineIndex === -1 /* End */) {
  24076. newlineIndex = code.length - 1;
  24077. }
  24078. context.line++;
  24079. context.column = code.length - newlineIndex;
  24080. }
  24081. }
  24082. if (node && node.loc !== locStub && node.loc.source) {
  24083. addMapping(node.loc.end);
  24084. }
  24085. }
  24086. },
  24087. indent() {
  24088. newline(++context.indentLevel);
  24089. },
  24090. deindent(withoutNewLine = false) {
  24091. if (withoutNewLine) {
  24092. --context.indentLevel;
  24093. } else {
  24094. newline(--context.indentLevel);
  24095. }
  24096. },
  24097. newline() {
  24098. newline(context.indentLevel);
  24099. }
  24100. };
  24101. function newline(n) {
  24102. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  24103. }
  24104. function addMapping(loc, name = null) {
  24105. const { _names, _mappings } = context.map;
  24106. if (name !== null && !_names.has(name)) _names.add(name);
  24107. _mappings.add({
  24108. originalLine: loc.line,
  24109. originalColumn: loc.column - 1,
  24110. // source-map column is 0 based
  24111. generatedLine: context.line,
  24112. generatedColumn: context.column - 1,
  24113. source: filename,
  24114. name
  24115. });
  24116. }
  24117. if (sourceMap) {
  24118. context.map = new sourceMapExports.SourceMapGenerator();
  24119. context.map.setSourceContent(filename, context.source);
  24120. context.map._sources.add(filename);
  24121. }
  24122. return context;
  24123. }
  24124. function generate(ast, options = {}) {
  24125. const context = createCodegenContext(ast, options);
  24126. if (options.onContextCreated) options.onContextCreated(context);
  24127. const {
  24128. mode,
  24129. push,
  24130. prefixIdentifiers,
  24131. indent,
  24132. deindent,
  24133. newline,
  24134. scopeId,
  24135. ssr
  24136. } = context;
  24137. const helpers = Array.from(ast.helpers);
  24138. const hasHelpers = helpers.length > 0;
  24139. const useWithBlock = !prefixIdentifiers && mode !== "module";
  24140. const genScopeId = scopeId != null && mode === "module";
  24141. const isSetupInlined = !!options.inline;
  24142. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  24143. if (mode === "module") {
  24144. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  24145. } else {
  24146. genFunctionPreamble(ast, preambleContext);
  24147. }
  24148. const functionName = ssr ? `ssrRender` : `render`;
  24149. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  24150. if (options.bindingMetadata && !options.inline) {
  24151. args.push("$props", "$setup", "$data", "$options");
  24152. }
  24153. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  24154. if (isSetupInlined) {
  24155. push(`(${signature}) => {`);
  24156. } else {
  24157. push(`function ${functionName}(${signature}) {`);
  24158. }
  24159. indent();
  24160. if (useWithBlock) {
  24161. push(`with (_ctx) {`);
  24162. indent();
  24163. if (hasHelpers) {
  24164. push(
  24165. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  24166. `,
  24167. -1 /* End */
  24168. );
  24169. newline();
  24170. }
  24171. }
  24172. if (ast.components.length) {
  24173. genAssets(ast.components, "component", context);
  24174. if (ast.directives.length || ast.temps > 0) {
  24175. newline();
  24176. }
  24177. }
  24178. if (ast.directives.length) {
  24179. genAssets(ast.directives, "directive", context);
  24180. if (ast.temps > 0) {
  24181. newline();
  24182. }
  24183. }
  24184. if (ast.temps > 0) {
  24185. push(`let `);
  24186. for (let i = 0; i < ast.temps; i++) {
  24187. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  24188. }
  24189. }
  24190. if (ast.components.length || ast.directives.length || ast.temps) {
  24191. push(`
  24192. `, 0 /* Start */);
  24193. newline();
  24194. }
  24195. if (!ssr) {
  24196. push(`return `);
  24197. }
  24198. if (ast.codegenNode) {
  24199. genNode(ast.codegenNode, context);
  24200. } else {
  24201. push(`null`);
  24202. }
  24203. if (useWithBlock) {
  24204. deindent();
  24205. push(`}`);
  24206. }
  24207. deindent();
  24208. push(`}`);
  24209. return {
  24210. ast,
  24211. code: context.code,
  24212. preamble: isSetupInlined ? preambleContext.code : ``,
  24213. map: context.map ? context.map.toJSON() : void 0
  24214. };
  24215. }
  24216. function genFunctionPreamble(ast, context) {
  24217. const {
  24218. ssr,
  24219. prefixIdentifiers,
  24220. push,
  24221. newline,
  24222. runtimeModuleName,
  24223. runtimeGlobalName,
  24224. ssrRuntimeModuleName
  24225. } = context;
  24226. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  24227. const helpers = Array.from(ast.helpers);
  24228. if (helpers.length > 0) {
  24229. if (prefixIdentifiers) {
  24230. push(
  24231. `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  24232. `,
  24233. -1 /* End */
  24234. );
  24235. } else {
  24236. push(`const _Vue = ${VueBinding}
  24237. `, -1 /* End */);
  24238. if (ast.hoists.length) {
  24239. const staticHelpers = [
  24240. CREATE_VNODE,
  24241. CREATE_ELEMENT_VNODE,
  24242. CREATE_COMMENT,
  24243. CREATE_TEXT,
  24244. CREATE_STATIC
  24245. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  24246. push(`const { ${staticHelpers} } = _Vue
  24247. `, -1 /* End */);
  24248. }
  24249. }
  24250. }
  24251. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  24252. push(
  24253. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  24254. `,
  24255. -1 /* End */
  24256. );
  24257. }
  24258. genHoists(ast.hoists, context);
  24259. newline();
  24260. push(`return `);
  24261. }
  24262. function genModulePreamble(ast, context, genScopeId, inline) {
  24263. const {
  24264. push,
  24265. newline,
  24266. optimizeImports,
  24267. runtimeModuleName,
  24268. ssrRuntimeModuleName
  24269. } = context;
  24270. if (ast.helpers.size) {
  24271. const helpers = Array.from(ast.helpers);
  24272. if (optimizeImports) {
  24273. push(
  24274. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  24275. `,
  24276. -1 /* End */
  24277. );
  24278. push(
  24279. `
  24280. // Binding optimization for webpack code-split
  24281. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  24282. `,
  24283. -1 /* End */
  24284. );
  24285. } else {
  24286. push(
  24287. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  24288. `,
  24289. -1 /* End */
  24290. );
  24291. }
  24292. }
  24293. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  24294. push(
  24295. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  24296. `,
  24297. -1 /* End */
  24298. );
  24299. }
  24300. if (ast.imports.length) {
  24301. genImports(ast.imports, context);
  24302. newline();
  24303. }
  24304. genHoists(ast.hoists, context);
  24305. newline();
  24306. if (!inline) {
  24307. push(`export `);
  24308. }
  24309. }
  24310. function genAssets(assets, type, { helper, push, newline, isTS }) {
  24311. const resolver = helper(
  24312. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  24313. );
  24314. for (let i = 0; i < assets.length; i++) {
  24315. let id = assets[i];
  24316. const maybeSelfReference = id.endsWith("__self");
  24317. if (maybeSelfReference) {
  24318. id = id.slice(0, -6);
  24319. }
  24320. push(
  24321. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  24322. );
  24323. if (i < assets.length - 1) {
  24324. newline();
  24325. }
  24326. }
  24327. }
  24328. function genHoists(hoists, context) {
  24329. if (!hoists.length) {
  24330. return;
  24331. }
  24332. context.pure = true;
  24333. const { push, newline } = context;
  24334. newline();
  24335. for (let i = 0; i < hoists.length; i++) {
  24336. const exp = hoists[i];
  24337. if (exp) {
  24338. push(`const _hoisted_${i + 1} = `);
  24339. genNode(exp, context);
  24340. newline();
  24341. }
  24342. }
  24343. context.pure = false;
  24344. }
  24345. function genImports(importsOptions, context) {
  24346. if (!importsOptions.length) {
  24347. return;
  24348. }
  24349. importsOptions.forEach((imports) => {
  24350. context.push(`import `);
  24351. genNode(imports.exp, context);
  24352. context.push(` from '${imports.path}'`);
  24353. context.newline();
  24354. });
  24355. }
  24356. function isText(n) {
  24357. return isString$1(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  24358. }
  24359. function genNodeListAsArray(nodes, context) {
  24360. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  24361. context.push(`[`);
  24362. multilines && context.indent();
  24363. genNodeList(nodes, context, multilines);
  24364. multilines && context.deindent();
  24365. context.push(`]`);
  24366. }
  24367. function genNodeList(nodes, context, multilines = false, comma = true) {
  24368. const { push, newline } = context;
  24369. for (let i = 0; i < nodes.length; i++) {
  24370. const node = nodes[i];
  24371. if (isString$1(node)) {
  24372. push(node, -3 /* Unknown */);
  24373. } else if (isArray$3(node)) {
  24374. genNodeListAsArray(node, context);
  24375. } else {
  24376. genNode(node, context);
  24377. }
  24378. if (i < nodes.length - 1) {
  24379. if (multilines) {
  24380. comma && push(",");
  24381. newline();
  24382. } else {
  24383. comma && push(", ");
  24384. }
  24385. }
  24386. }
  24387. }
  24388. function genNode(node, context) {
  24389. if (isString$1(node)) {
  24390. context.push(node, -3 /* Unknown */);
  24391. return;
  24392. }
  24393. if (isSymbol$1(node)) {
  24394. context.push(context.helper(node));
  24395. return;
  24396. }
  24397. switch (node.type) {
  24398. case 1:
  24399. case 9:
  24400. case 11:
  24401. assert(
  24402. node.codegenNode != null,
  24403. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  24404. );
  24405. genNode(node.codegenNode, context);
  24406. break;
  24407. case 2:
  24408. genText(node, context);
  24409. break;
  24410. case 4:
  24411. genExpression(node, context);
  24412. break;
  24413. case 5:
  24414. genInterpolation(node, context);
  24415. break;
  24416. case 12:
  24417. genNode(node.codegenNode, context);
  24418. break;
  24419. case 8:
  24420. genCompoundExpression(node, context);
  24421. break;
  24422. case 3:
  24423. genComment(node, context);
  24424. break;
  24425. case 13:
  24426. genVNodeCall(node, context);
  24427. break;
  24428. case 14:
  24429. genCallExpression(node, context);
  24430. break;
  24431. case 15:
  24432. genObjectExpression(node, context);
  24433. break;
  24434. case 17:
  24435. genArrayExpression(node, context);
  24436. break;
  24437. case 18:
  24438. genFunctionExpression(node, context);
  24439. break;
  24440. case 19:
  24441. genConditionalExpression(node, context);
  24442. break;
  24443. case 20:
  24444. genCacheExpression(node, context);
  24445. break;
  24446. case 21:
  24447. genNodeList(node.body, context, true, false);
  24448. break;
  24449. // SSR only types
  24450. case 22:
  24451. genTemplateLiteral(node, context);
  24452. break;
  24453. case 23:
  24454. genIfStatement(node, context);
  24455. break;
  24456. case 24:
  24457. genAssignmentExpression(node, context);
  24458. break;
  24459. case 25:
  24460. genSequenceExpression(node, context);
  24461. break;
  24462. case 26:
  24463. genReturnStatement(node, context);
  24464. break;
  24465. /* v8 ignore start */
  24466. case 10:
  24467. break;
  24468. default:
  24469. {
  24470. assert(false, `unhandled codegen node type: ${node.type}`);
  24471. const exhaustiveCheck = node;
  24472. return exhaustiveCheck;
  24473. }
  24474. }
  24475. }
  24476. function genText(node, context) {
  24477. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  24478. }
  24479. function genExpression(node, context) {
  24480. const { content, isStatic } = node;
  24481. context.push(
  24482. isStatic ? JSON.stringify(content) : content,
  24483. -3 /* Unknown */,
  24484. node
  24485. );
  24486. }
  24487. function genInterpolation(node, context) {
  24488. const { push, helper, pure } = context;
  24489. if (pure) push(PURE_ANNOTATION);
  24490. push(`${helper(TO_DISPLAY_STRING)}(`);
  24491. genNode(node.content, context);
  24492. push(`)`);
  24493. }
  24494. function genCompoundExpression(node, context) {
  24495. for (let i = 0; i < node.children.length; i++) {
  24496. const child = node.children[i];
  24497. if (isString$1(child)) {
  24498. context.push(child, -3 /* Unknown */);
  24499. } else {
  24500. genNode(child, context);
  24501. }
  24502. }
  24503. }
  24504. function genExpressionAsPropertyKey(node, context) {
  24505. const { push } = context;
  24506. if (node.type === 8) {
  24507. push(`[`);
  24508. genCompoundExpression(node, context);
  24509. push(`]`);
  24510. } else if (node.isStatic) {
  24511. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  24512. push(text, -2 /* None */, node);
  24513. } else {
  24514. push(`[${node.content}]`, -3 /* Unknown */, node);
  24515. }
  24516. }
  24517. function genComment(node, context) {
  24518. const { push, helper, pure } = context;
  24519. if (pure) {
  24520. push(PURE_ANNOTATION);
  24521. }
  24522. push(
  24523. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  24524. -3 /* Unknown */,
  24525. node
  24526. );
  24527. }
  24528. function genVNodeCall(node, context) {
  24529. const { push, helper, pure } = context;
  24530. const {
  24531. tag,
  24532. props,
  24533. children,
  24534. patchFlag,
  24535. dynamicProps,
  24536. directives,
  24537. isBlock,
  24538. disableTracking,
  24539. isComponent
  24540. } = node;
  24541. let patchFlagString;
  24542. if (patchFlag) {
  24543. {
  24544. if (patchFlag < 0) {
  24545. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  24546. } else {
  24547. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  24548. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  24549. }
  24550. }
  24551. }
  24552. if (directives) {
  24553. push(helper(WITH_DIRECTIVES) + `(`);
  24554. }
  24555. if (isBlock) {
  24556. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  24557. }
  24558. if (pure) {
  24559. push(PURE_ANNOTATION);
  24560. }
  24561. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  24562. push(helper(callHelper) + `(`, -2 /* None */, node);
  24563. genNodeList(
  24564. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  24565. context
  24566. );
  24567. push(`)`);
  24568. if (isBlock) {
  24569. push(`)`);
  24570. }
  24571. if (directives) {
  24572. push(`, `);
  24573. genNode(directives, context);
  24574. push(`)`);
  24575. }
  24576. }
  24577. function genNullableArgs(args) {
  24578. let i = args.length;
  24579. while (i--) {
  24580. if (args[i] != null) break;
  24581. }
  24582. return args.slice(0, i + 1).map((arg) => arg || `null`);
  24583. }
  24584. function genCallExpression(node, context) {
  24585. const { push, helper, pure } = context;
  24586. const callee = isString$1(node.callee) ? node.callee : helper(node.callee);
  24587. if (pure) {
  24588. push(PURE_ANNOTATION);
  24589. }
  24590. push(callee + `(`, -2 /* None */, node);
  24591. genNodeList(node.arguments, context);
  24592. push(`)`);
  24593. }
  24594. function genObjectExpression(node, context) {
  24595. const { push, indent, deindent, newline } = context;
  24596. const { properties } = node;
  24597. if (!properties.length) {
  24598. push(`{}`, -2 /* None */, node);
  24599. return;
  24600. }
  24601. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  24602. push(multilines ? `{` : `{ `);
  24603. multilines && indent();
  24604. for (let i = 0; i < properties.length; i++) {
  24605. const { key, value } = properties[i];
  24606. genExpressionAsPropertyKey(key, context);
  24607. push(`: `);
  24608. genNode(value, context);
  24609. if (i < properties.length - 1) {
  24610. push(`,`);
  24611. newline();
  24612. }
  24613. }
  24614. multilines && deindent();
  24615. push(multilines ? `}` : ` }`);
  24616. }
  24617. function genArrayExpression(node, context) {
  24618. genNodeListAsArray(node.elements, context);
  24619. }
  24620. function genFunctionExpression(node, context) {
  24621. const { push, indent, deindent } = context;
  24622. const { params, returns, body, newline, isSlot } = node;
  24623. if (isSlot) {
  24624. push(`_${helperNameMap[WITH_CTX]}(`);
  24625. }
  24626. push(`(`, -2 /* None */, node);
  24627. if (isArray$3(params)) {
  24628. genNodeList(params, context);
  24629. } else if (params) {
  24630. genNode(params, context);
  24631. }
  24632. push(`) => `);
  24633. if (newline || body) {
  24634. push(`{`);
  24635. indent();
  24636. }
  24637. if (returns) {
  24638. if (newline) {
  24639. push(`return `);
  24640. }
  24641. if (isArray$3(returns)) {
  24642. genNodeListAsArray(returns, context);
  24643. } else {
  24644. genNode(returns, context);
  24645. }
  24646. } else if (body) {
  24647. genNode(body, context);
  24648. }
  24649. if (newline || body) {
  24650. deindent();
  24651. push(`}`);
  24652. }
  24653. if (isSlot) {
  24654. push(`)`);
  24655. }
  24656. }
  24657. function genConditionalExpression(node, context) {
  24658. const { test, consequent, alternate, newline: needNewline } = node;
  24659. const { push, indent, deindent, newline } = context;
  24660. if (test.type === 4) {
  24661. const needsParens = !isSimpleIdentifier(test.content);
  24662. needsParens && push(`(`);
  24663. genExpression(test, context);
  24664. needsParens && push(`)`);
  24665. } else {
  24666. push(`(`);
  24667. genNode(test, context);
  24668. push(`)`);
  24669. }
  24670. needNewline && indent();
  24671. context.indentLevel++;
  24672. needNewline || push(` `);
  24673. push(`? `);
  24674. genNode(consequent, context);
  24675. context.indentLevel--;
  24676. needNewline && newline();
  24677. needNewline || push(` `);
  24678. push(`: `);
  24679. const isNested = alternate.type === 19;
  24680. if (!isNested) {
  24681. context.indentLevel++;
  24682. }
  24683. genNode(alternate, context);
  24684. if (!isNested) {
  24685. context.indentLevel--;
  24686. }
  24687. needNewline && deindent(
  24688. true
  24689. /* without newline */
  24690. );
  24691. }
  24692. function genCacheExpression(node, context) {
  24693. const { push, helper, indent, deindent, newline } = context;
  24694. const { needPauseTracking, needArraySpread } = node;
  24695. if (needArraySpread) {
  24696. push(`[...(`);
  24697. }
  24698. push(`_cache[${node.index}] || (`);
  24699. if (needPauseTracking) {
  24700. indent();
  24701. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  24702. if (node.inVOnce) push(`, true`);
  24703. push(`),`);
  24704. newline();
  24705. push(`(`);
  24706. }
  24707. push(`_cache[${node.index}] = `);
  24708. genNode(node.value, context);
  24709. if (needPauseTracking) {
  24710. push(`).cacheIndex = ${node.index},`);
  24711. newline();
  24712. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  24713. newline();
  24714. push(`_cache[${node.index}]`);
  24715. deindent();
  24716. }
  24717. push(`)`);
  24718. if (needArraySpread) {
  24719. push(`)]`);
  24720. }
  24721. }
  24722. function genTemplateLiteral(node, context) {
  24723. const { push, indent, deindent } = context;
  24724. push("`");
  24725. const l = node.elements.length;
  24726. const multilines = l > 3;
  24727. for (let i = 0; i < l; i++) {
  24728. const e = node.elements[i];
  24729. if (isString$1(e)) {
  24730. push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
  24731. } else {
  24732. push("${");
  24733. if (multilines) indent();
  24734. genNode(e, context);
  24735. if (multilines) deindent();
  24736. push("}");
  24737. }
  24738. }
  24739. push("`");
  24740. }
  24741. function genIfStatement(node, context) {
  24742. const { push, indent, deindent } = context;
  24743. const { test, consequent, alternate } = node;
  24744. push(`if (`);
  24745. genNode(test, context);
  24746. push(`) {`);
  24747. indent();
  24748. genNode(consequent, context);
  24749. deindent();
  24750. push(`}`);
  24751. if (alternate) {
  24752. push(` else `);
  24753. if (alternate.type === 23) {
  24754. genIfStatement(alternate, context);
  24755. } else {
  24756. push(`{`);
  24757. indent();
  24758. genNode(alternate, context);
  24759. deindent();
  24760. push(`}`);
  24761. }
  24762. }
  24763. }
  24764. function genAssignmentExpression(node, context) {
  24765. genNode(node.left, context);
  24766. context.push(` = `);
  24767. genNode(node.right, context);
  24768. }
  24769. function genSequenceExpression(node, context) {
  24770. context.push(`(`);
  24771. genNodeList(node.expressions, context);
  24772. context.push(`)`);
  24773. }
  24774. function genReturnStatement({ returns }, context) {
  24775. context.push(`return `);
  24776. if (isArray$3(returns)) {
  24777. genNodeListAsArray(returns, context);
  24778. } else {
  24779. genNode(returns, context);
  24780. }
  24781. }
  24782. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  24783. const transformExpression = (node, context) => {
  24784. if (node.type === 5) {
  24785. node.content = processExpression(
  24786. node.content,
  24787. context
  24788. );
  24789. } else if (node.type === 1) {
  24790. const memo = findDir(node, "memo");
  24791. for (let i = 0; i < node.props.length; i++) {
  24792. const dir = node.props[i];
  24793. if (dir.type === 7 && dir.name !== "for") {
  24794. const exp = dir.exp;
  24795. const arg = dir.arg;
  24796. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  24797. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  24798. dir.exp = processExpression(
  24799. exp,
  24800. context,
  24801. // slot args must be processed as function params
  24802. dir.name === "slot"
  24803. );
  24804. }
  24805. if (arg && arg.type === 4 && !arg.isStatic) {
  24806. dir.arg = processExpression(arg, context);
  24807. }
  24808. }
  24809. }
  24810. }
  24811. };
  24812. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  24813. if (!context.prefixIdentifiers || !node.content.trim()) {
  24814. return node;
  24815. }
  24816. const { inline, bindingMetadata } = context;
  24817. const rewriteIdentifier = (raw, parent, id) => {
  24818. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  24819. if (inline) {
  24820. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  24821. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  24822. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  24823. const isNewExpression = parent && isInNewExpression(parentStack);
  24824. const wrapWithUnref = (raw2) => {
  24825. const wrapped = `${context.helperString(UNREF)}(${raw2})`;
  24826. return isNewExpression ? `(${wrapped})` : wrapped;
  24827. };
  24828. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  24829. return raw;
  24830. } else if (type === "setup-ref") {
  24831. return `${raw}.value`;
  24832. } else if (type === "setup-maybe-ref") {
  24833. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
  24834. } else if (type === "setup-let") {
  24835. if (isAssignmentLVal) {
  24836. const { right: rVal, operator } = parent;
  24837. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  24838. const rExpString = stringifyExpression(
  24839. processExpression(
  24840. createSimpleExpression(rExp, false),
  24841. context,
  24842. false,
  24843. false,
  24844. knownIds
  24845. )
  24846. );
  24847. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  24848. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  24849. } else if (isUpdateArg) {
  24850. id.start = parent.start;
  24851. id.end = parent.end;
  24852. const { prefix: isPrefix, operator } = parent;
  24853. const prefix = isPrefix ? operator : ``;
  24854. const postfix = isPrefix ? `` : operator;
  24855. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  24856. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  24857. } else if (isDestructureAssignment) {
  24858. return raw;
  24859. } else {
  24860. return wrapWithUnref(raw);
  24861. }
  24862. } else if (type === "props") {
  24863. return genPropsAccessExp(raw);
  24864. } else if (type === "props-aliased") {
  24865. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  24866. }
  24867. } else {
  24868. if (type && type.startsWith("setup") || type === "literal-const") {
  24869. return `$setup.${raw}`;
  24870. } else if (type === "props-aliased") {
  24871. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  24872. } else if (type) {
  24873. return `$${type}.${raw}`;
  24874. }
  24875. }
  24876. return `_ctx.${raw}`;
  24877. };
  24878. const rawExp = node.content;
  24879. let ast = node.ast;
  24880. if (ast === false) {
  24881. return node;
  24882. }
  24883. if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
  24884. const isScopeVarReference = context.identifiers[rawExp];
  24885. const isAllowedGlobal = isGloballyAllowed(rawExp);
  24886. const isLiteral = isLiteralWhitelisted(rawExp);
  24887. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  24888. if (isConst(bindingMetadata[rawExp])) {
  24889. node.constType = 1;
  24890. }
  24891. node.content = rewriteIdentifier(rawExp);
  24892. } else if (!isScopeVarReference) {
  24893. if (isLiteral) {
  24894. node.constType = 3;
  24895. } else {
  24896. node.constType = 2;
  24897. }
  24898. }
  24899. return node;
  24900. }
  24901. if (!ast) {
  24902. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  24903. try {
  24904. ast = libExports.parseExpression(source, {
  24905. sourceType: "module",
  24906. plugins: context.expressionPlugins
  24907. });
  24908. } catch (e) {
  24909. context.onError(
  24910. createCompilerError(
  24911. 46,
  24912. node.loc,
  24913. void 0,
  24914. e.message
  24915. )
  24916. );
  24917. return node;
  24918. }
  24919. }
  24920. const ids = [];
  24921. const parentStack = [];
  24922. const knownIds = Object.create(context.identifiers);
  24923. walkIdentifiers(
  24924. ast,
  24925. (node2, parent, _, isReferenced, isLocal) => {
  24926. if (isStaticPropertyKey(node2, parent)) {
  24927. return;
  24928. }
  24929. const needPrefix = isReferenced && canPrefix(node2);
  24930. if (needPrefix && !isLocal) {
  24931. if (isStaticProperty(parent) && parent.shorthand) {
  24932. node2.prefix = `${node2.name}: `;
  24933. }
  24934. node2.name = rewriteIdentifier(node2.name, parent, node2);
  24935. ids.push(node2);
  24936. } else {
  24937. if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
  24938. node2.isConstant = true;
  24939. }
  24940. ids.push(node2);
  24941. }
  24942. },
  24943. true,
  24944. // invoke on ALL identifiers
  24945. parentStack,
  24946. knownIds
  24947. );
  24948. const children = [];
  24949. ids.sort((a, b) => a.start - b.start);
  24950. ids.forEach((id, i) => {
  24951. const start = id.start - 1;
  24952. const end = id.end - 1;
  24953. const last = ids[i - 1];
  24954. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  24955. if (leadingText.length || id.prefix) {
  24956. children.push(leadingText + (id.prefix || ``));
  24957. }
  24958. const source = rawExp.slice(start, end);
  24959. children.push(
  24960. createSimpleExpression(
  24961. id.name,
  24962. false,
  24963. {
  24964. start: advancePositionWithClone(node.loc.start, source, start),
  24965. end: advancePositionWithClone(node.loc.start, source, end),
  24966. source
  24967. },
  24968. id.isConstant ? 3 : 0
  24969. )
  24970. );
  24971. if (i === ids.length - 1 && end < rawExp.length) {
  24972. children.push(rawExp.slice(end));
  24973. }
  24974. });
  24975. let ret;
  24976. if (children.length) {
  24977. ret = createCompoundExpression(children, node.loc);
  24978. ret.ast = ast;
  24979. } else {
  24980. ret = node;
  24981. ret.constType = 3;
  24982. }
  24983. ret.identifiers = Object.keys(knownIds);
  24984. return ret;
  24985. }
  24986. function canPrefix(id) {
  24987. if (isGloballyAllowed(id.name)) {
  24988. return false;
  24989. }
  24990. if (id.name === "require") {
  24991. return false;
  24992. }
  24993. return true;
  24994. }
  24995. function stringifyExpression(exp) {
  24996. if (isString$1(exp)) {
  24997. return exp;
  24998. } else if (exp.type === 4) {
  24999. return exp.content;
  25000. } else {
  25001. return exp.children.map(stringifyExpression).join("");
  25002. }
  25003. }
  25004. function isConst(type) {
  25005. return type === "setup-const" || type === "literal-const";
  25006. }
  25007. const transformIf = createStructuralDirectiveTransform(
  25008. /^(?:if|else|else-if)$/,
  25009. (node, dir, context) => {
  25010. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  25011. const siblings = context.parent.children;
  25012. let i = siblings.indexOf(ifNode);
  25013. let key = 0;
  25014. while (i-- >= 0) {
  25015. const sibling = siblings[i];
  25016. if (sibling && sibling.type === 9) {
  25017. key += sibling.branches.length;
  25018. }
  25019. }
  25020. return () => {
  25021. if (isRoot) {
  25022. ifNode.codegenNode = createCodegenNodeForBranch(
  25023. branch,
  25024. key,
  25025. context
  25026. );
  25027. } else {
  25028. const parentCondition = getParentCondition(ifNode.codegenNode);
  25029. parentCondition.alternate = createCodegenNodeForBranch(
  25030. branch,
  25031. key + ifNode.branches.length - 1,
  25032. context
  25033. );
  25034. }
  25035. };
  25036. });
  25037. }
  25038. );
  25039. function processIf(node, dir, context, processCodegen) {
  25040. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  25041. const loc = dir.exp ? dir.exp.loc : node.loc;
  25042. context.onError(
  25043. createCompilerError(28, dir.loc)
  25044. );
  25045. dir.exp = createSimpleExpression(`true`, false, loc);
  25046. }
  25047. if (context.prefixIdentifiers && dir.exp) {
  25048. dir.exp = processExpression(dir.exp, context);
  25049. }
  25050. if (dir.name === "if") {
  25051. const branch = createIfBranch(node, dir);
  25052. const ifNode = {
  25053. type: 9,
  25054. loc: cloneLoc(node.loc),
  25055. branches: [branch]
  25056. };
  25057. context.replaceNode(ifNode);
  25058. if (processCodegen) {
  25059. return processCodegen(ifNode, branch, true);
  25060. }
  25061. } else {
  25062. const siblings = context.parent.children;
  25063. const comments = [];
  25064. let i = siblings.indexOf(node);
  25065. while (i-- >= -1) {
  25066. const sibling = siblings[i];
  25067. if (sibling && isCommentOrWhitespace(sibling)) {
  25068. context.removeNode(sibling);
  25069. if (sibling.type === 3) {
  25070. comments.unshift(sibling);
  25071. }
  25072. continue;
  25073. }
  25074. if (sibling && sibling.type === 9) {
  25075. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  25076. context.onError(
  25077. createCompilerError(30, node.loc)
  25078. );
  25079. }
  25080. context.removeNode();
  25081. const branch = createIfBranch(node, dir);
  25082. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  25083. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  25084. branch.children = [...comments, ...branch.children];
  25085. }
  25086. {
  25087. const key = branch.userKey;
  25088. if (key) {
  25089. sibling.branches.forEach(({ userKey }) => {
  25090. if (isSameKey(userKey, key)) {
  25091. context.onError(
  25092. createCompilerError(
  25093. 29,
  25094. branch.userKey.loc
  25095. )
  25096. );
  25097. }
  25098. });
  25099. }
  25100. }
  25101. sibling.branches.push(branch);
  25102. const onExit = processCodegen && processCodegen(sibling, branch, false);
  25103. traverseNode(branch, context);
  25104. if (onExit) onExit();
  25105. context.currentNode = null;
  25106. } else {
  25107. context.onError(
  25108. createCompilerError(30, node.loc)
  25109. );
  25110. }
  25111. break;
  25112. }
  25113. }
  25114. }
  25115. function createIfBranch(node, dir) {
  25116. const isTemplateIf = node.tagType === 3;
  25117. return {
  25118. type: 10,
  25119. loc: node.loc,
  25120. condition: dir.name === "else" ? void 0 : dir.exp,
  25121. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  25122. userKey: findProp(node, `key`),
  25123. isTemplateIf
  25124. };
  25125. }
  25126. function createCodegenNodeForBranch(branch, keyIndex, context) {
  25127. if (branch.condition) {
  25128. return createConditionalExpression(
  25129. branch.condition,
  25130. createChildrenCodegenNode(branch, keyIndex, context),
  25131. // make sure to pass in asBlock: true so that the comment node call
  25132. // closes the current block.
  25133. createCallExpression(context.helper(CREATE_COMMENT), [
  25134. '"v-if"' ,
  25135. "true"
  25136. ])
  25137. );
  25138. } else {
  25139. return createChildrenCodegenNode(branch, keyIndex, context);
  25140. }
  25141. }
  25142. function createChildrenCodegenNode(branch, keyIndex, context) {
  25143. const { helper } = context;
  25144. const keyProperty = createObjectProperty(
  25145. `key`,
  25146. createSimpleExpression(
  25147. `${keyIndex}`,
  25148. false,
  25149. locStub,
  25150. 2
  25151. )
  25152. );
  25153. const { children } = branch;
  25154. const firstChild = children[0];
  25155. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  25156. if (needFragmentWrapper) {
  25157. if (children.length === 1 && firstChild.type === 11) {
  25158. const vnodeCall = firstChild.codegenNode;
  25159. injectProp(vnodeCall, keyProperty, context);
  25160. return vnodeCall;
  25161. } else {
  25162. let patchFlag = 64;
  25163. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  25164. patchFlag |= 2048;
  25165. }
  25166. return createVNodeCall(
  25167. context,
  25168. helper(FRAGMENT),
  25169. createObjectExpression([keyProperty]),
  25170. children,
  25171. patchFlag,
  25172. void 0,
  25173. void 0,
  25174. true,
  25175. false,
  25176. false,
  25177. branch.loc
  25178. );
  25179. }
  25180. } else {
  25181. const ret = firstChild.codegenNode;
  25182. const vnodeCall = getMemoedVNodeCall(ret);
  25183. if (vnodeCall.type === 13) {
  25184. convertToBlock(vnodeCall, context);
  25185. }
  25186. injectProp(vnodeCall, keyProperty, context);
  25187. return ret;
  25188. }
  25189. }
  25190. function isSameKey(a, b) {
  25191. if (!a || a.type !== b.type) {
  25192. return false;
  25193. }
  25194. if (a.type === 6) {
  25195. if (a.value.content !== b.value.content) {
  25196. return false;
  25197. }
  25198. } else {
  25199. const exp = a.exp;
  25200. const branchExp = b.exp;
  25201. if (exp.type !== branchExp.type) {
  25202. return false;
  25203. }
  25204. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  25205. return false;
  25206. }
  25207. }
  25208. return true;
  25209. }
  25210. function getParentCondition(node) {
  25211. while (true) {
  25212. if (node.type === 19) {
  25213. if (node.alternate.type === 19) {
  25214. node = node.alternate;
  25215. } else {
  25216. return node;
  25217. }
  25218. } else if (node.type === 20) {
  25219. node = node.value;
  25220. }
  25221. }
  25222. }
  25223. const transformFor = createStructuralDirectiveTransform(
  25224. "for",
  25225. (node, dir, context) => {
  25226. const { helper, removeHelper } = context;
  25227. return processFor(node, dir, context, (forNode) => {
  25228. const renderExp = createCallExpression(helper(RENDER_LIST), [
  25229. forNode.source
  25230. ]);
  25231. const isTemplate = isTemplateNode(node);
  25232. const memo = findDir(node, "memo");
  25233. const keyProp = findProp(node, `key`, false, true);
  25234. const isDirKey = keyProp && keyProp.type === 7;
  25235. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  25236. if (memo && keyExp && isDirKey) {
  25237. {
  25238. keyProp.exp = keyExp = processExpression(
  25239. keyExp,
  25240. context
  25241. );
  25242. }
  25243. }
  25244. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  25245. if (isTemplate) {
  25246. if (memo) {
  25247. memo.exp = processExpression(
  25248. memo.exp,
  25249. context
  25250. );
  25251. }
  25252. if (keyProperty && keyProp.type !== 6) {
  25253. keyProperty.value = processExpression(
  25254. keyProperty.value,
  25255. context
  25256. );
  25257. }
  25258. }
  25259. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  25260. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  25261. forNode.codegenNode = createVNodeCall(
  25262. context,
  25263. helper(FRAGMENT),
  25264. void 0,
  25265. renderExp,
  25266. fragmentFlag,
  25267. void 0,
  25268. void 0,
  25269. true,
  25270. !isStableFragment,
  25271. false,
  25272. node.loc
  25273. );
  25274. return () => {
  25275. let childBlock;
  25276. const { children } = forNode;
  25277. if (isTemplate) {
  25278. node.children.some((c) => {
  25279. if (c.type === 1) {
  25280. const key = findProp(c, "key");
  25281. if (key) {
  25282. context.onError(
  25283. createCompilerError(
  25284. 33,
  25285. key.loc
  25286. )
  25287. );
  25288. return true;
  25289. }
  25290. }
  25291. });
  25292. }
  25293. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  25294. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  25295. if (slotOutlet) {
  25296. childBlock = slotOutlet.codegenNode;
  25297. if (isTemplate && keyProperty) {
  25298. injectProp(childBlock, keyProperty, context);
  25299. }
  25300. } else if (needFragmentWrapper) {
  25301. childBlock = createVNodeCall(
  25302. context,
  25303. helper(FRAGMENT),
  25304. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  25305. node.children,
  25306. 64,
  25307. void 0,
  25308. void 0,
  25309. true,
  25310. void 0,
  25311. false
  25312. );
  25313. } else {
  25314. childBlock = children[0].codegenNode;
  25315. if (isTemplate && keyProperty) {
  25316. injectProp(childBlock, keyProperty, context);
  25317. }
  25318. if (childBlock.isBlock !== !isStableFragment) {
  25319. if (childBlock.isBlock) {
  25320. removeHelper(OPEN_BLOCK);
  25321. removeHelper(
  25322. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  25323. );
  25324. } else {
  25325. removeHelper(
  25326. getVNodeHelper(context.inSSR, childBlock.isComponent)
  25327. );
  25328. }
  25329. }
  25330. childBlock.isBlock = !isStableFragment;
  25331. if (childBlock.isBlock) {
  25332. helper(OPEN_BLOCK);
  25333. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  25334. } else {
  25335. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  25336. }
  25337. }
  25338. if (memo) {
  25339. const loop = createFunctionExpression(
  25340. createForLoopParams(forNode.parseResult, [
  25341. createSimpleExpression(`_cached`)
  25342. ])
  25343. );
  25344. loop.body = createBlockStatement([
  25345. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  25346. createCompoundExpression([
  25347. `if (_cached && _cached.el`,
  25348. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  25349. ` && ${context.helperString(
  25350. IS_MEMO_SAME
  25351. )}(_cached, _memo)) return _cached`
  25352. ]),
  25353. createCompoundExpression([`const _item = `, childBlock]),
  25354. createSimpleExpression(`_item.memo = _memo`),
  25355. createSimpleExpression(`return _item`)
  25356. ]);
  25357. renderExp.arguments.push(
  25358. loop,
  25359. createSimpleExpression(`_cache`),
  25360. createSimpleExpression(String(context.cached.length))
  25361. );
  25362. context.cached.push(null);
  25363. } else {
  25364. renderExp.arguments.push(
  25365. createFunctionExpression(
  25366. createForLoopParams(forNode.parseResult),
  25367. childBlock,
  25368. true
  25369. )
  25370. );
  25371. }
  25372. };
  25373. });
  25374. }
  25375. );
  25376. function processFor(node, dir, context, processCodegen) {
  25377. if (!dir.exp) {
  25378. context.onError(
  25379. createCompilerError(31, dir.loc)
  25380. );
  25381. return;
  25382. }
  25383. const parseResult = dir.forParseResult;
  25384. if (!parseResult) {
  25385. context.onError(
  25386. createCompilerError(32, dir.loc)
  25387. );
  25388. return;
  25389. }
  25390. finalizeForParseResult(parseResult, context);
  25391. const { addIdentifiers, removeIdentifiers, scopes } = context;
  25392. const { source, value, key, index } = parseResult;
  25393. const forNode = {
  25394. type: 11,
  25395. loc: dir.loc,
  25396. source,
  25397. valueAlias: value,
  25398. keyAlias: key,
  25399. objectIndexAlias: index,
  25400. parseResult,
  25401. children: isTemplateNode(node) ? node.children : [node]
  25402. };
  25403. context.replaceNode(forNode);
  25404. scopes.vFor++;
  25405. if (context.prefixIdentifiers) {
  25406. value && addIdentifiers(value);
  25407. key && addIdentifiers(key);
  25408. index && addIdentifiers(index);
  25409. }
  25410. const onExit = processCodegen && processCodegen(forNode);
  25411. return () => {
  25412. scopes.vFor--;
  25413. if (context.prefixIdentifiers) {
  25414. value && removeIdentifiers(value);
  25415. key && removeIdentifiers(key);
  25416. index && removeIdentifiers(index);
  25417. }
  25418. if (onExit) onExit();
  25419. };
  25420. }
  25421. function finalizeForParseResult(result, context) {
  25422. if (result.finalized) return;
  25423. if (context.prefixIdentifiers) {
  25424. result.source = processExpression(
  25425. result.source,
  25426. context
  25427. );
  25428. if (result.key) {
  25429. result.key = processExpression(
  25430. result.key,
  25431. context,
  25432. true
  25433. );
  25434. }
  25435. if (result.index) {
  25436. result.index = processExpression(
  25437. result.index,
  25438. context,
  25439. true
  25440. );
  25441. }
  25442. if (result.value) {
  25443. result.value = processExpression(
  25444. result.value,
  25445. context,
  25446. true
  25447. );
  25448. }
  25449. }
  25450. result.finalized = true;
  25451. }
  25452. function createForLoopParams({ value, key, index }, memoArgs = []) {
  25453. return createParamsList([value, key, index, ...memoArgs]);
  25454. }
  25455. function createParamsList(args) {
  25456. let i = args.length;
  25457. while (i--) {
  25458. if (args[i]) break;
  25459. }
  25460. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  25461. }
  25462. const defaultFallback = createSimpleExpression(`undefined`, false);
  25463. const trackSlotScopes = (node, context) => {
  25464. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  25465. const vSlot = findDir(node, "slot");
  25466. if (vSlot) {
  25467. const slotProps = vSlot.exp;
  25468. if (context.prefixIdentifiers) {
  25469. slotProps && context.addIdentifiers(slotProps);
  25470. }
  25471. context.scopes.vSlot++;
  25472. return () => {
  25473. if (context.prefixIdentifiers) {
  25474. slotProps && context.removeIdentifiers(slotProps);
  25475. }
  25476. context.scopes.vSlot--;
  25477. };
  25478. }
  25479. }
  25480. };
  25481. const trackVForSlotScopes = (node, context) => {
  25482. let vFor;
  25483. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  25484. const result = vFor.forParseResult;
  25485. if (result) {
  25486. finalizeForParseResult(result, context);
  25487. const { value, key, index } = result;
  25488. const { addIdentifiers, removeIdentifiers } = context;
  25489. value && addIdentifiers(value);
  25490. key && addIdentifiers(key);
  25491. index && addIdentifiers(index);
  25492. return () => {
  25493. value && removeIdentifiers(value);
  25494. key && removeIdentifiers(key);
  25495. index && removeIdentifiers(index);
  25496. };
  25497. }
  25498. }
  25499. };
  25500. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  25501. props,
  25502. children,
  25503. false,
  25504. true,
  25505. children.length ? children[0].loc : loc
  25506. );
  25507. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  25508. context.helper(WITH_CTX);
  25509. const { children, loc } = node;
  25510. const slotsProperties = [];
  25511. const dynamicSlots = [];
  25512. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  25513. if (!context.ssr && context.prefixIdentifiers) {
  25514. hasDynamicSlots = node.props.some(
  25515. (prop) => isVSlot(prop) && (hasScopeRef(prop.arg, context.identifiers) || hasScopeRef(prop.exp, context.identifiers))
  25516. ) || children.some((child) => hasScopeRef(child, context.identifiers));
  25517. }
  25518. const onComponentSlot = findDir(node, "slot", true);
  25519. if (onComponentSlot) {
  25520. const { arg, exp } = onComponentSlot;
  25521. if (arg && !isStaticExp(arg)) {
  25522. hasDynamicSlots = true;
  25523. }
  25524. slotsProperties.push(
  25525. createObjectProperty(
  25526. arg || createSimpleExpression("default", true),
  25527. buildSlotFn(exp, void 0, children, loc)
  25528. )
  25529. );
  25530. }
  25531. let hasTemplateSlots = false;
  25532. let hasNamedDefaultSlot = false;
  25533. const implicitDefaultChildren = [];
  25534. const seenSlotNames = /* @__PURE__ */ new Set();
  25535. let conditionalBranchIndex = 0;
  25536. for (let i = 0; i < children.length; i++) {
  25537. const slotElement = children[i];
  25538. let slotDir;
  25539. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  25540. if (slotElement.type !== 3) {
  25541. implicitDefaultChildren.push(slotElement);
  25542. }
  25543. continue;
  25544. }
  25545. if (onComponentSlot) {
  25546. context.onError(
  25547. createCompilerError(37, slotDir.loc)
  25548. );
  25549. break;
  25550. }
  25551. hasTemplateSlots = true;
  25552. const { children: slotChildren, loc: slotLoc } = slotElement;
  25553. const {
  25554. arg: slotName = createSimpleExpression(`default`, true),
  25555. exp: slotProps,
  25556. loc: dirLoc
  25557. } = slotDir;
  25558. let staticSlotName;
  25559. if (isStaticExp(slotName)) {
  25560. staticSlotName = slotName ? slotName.content : `default`;
  25561. } else {
  25562. hasDynamicSlots = true;
  25563. }
  25564. const vFor = findDir(slotElement, "for");
  25565. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  25566. let vIf;
  25567. let vElse;
  25568. if (vIf = findDir(slotElement, "if")) {
  25569. hasDynamicSlots = true;
  25570. dynamicSlots.push(
  25571. createConditionalExpression(
  25572. vIf.exp,
  25573. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  25574. defaultFallback
  25575. )
  25576. );
  25577. } else if (vElse = findDir(
  25578. slotElement,
  25579. /^else(?:-if)?$/,
  25580. true
  25581. /* allowEmpty */
  25582. )) {
  25583. let j = i;
  25584. let prev;
  25585. while (j--) {
  25586. prev = children[j];
  25587. if (!isCommentOrWhitespace(prev)) {
  25588. break;
  25589. }
  25590. }
  25591. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  25592. let conditional = dynamicSlots[dynamicSlots.length - 1];
  25593. while (conditional.alternate.type === 19) {
  25594. conditional = conditional.alternate;
  25595. }
  25596. conditional.alternate = vElse.exp ? createConditionalExpression(
  25597. vElse.exp,
  25598. buildDynamicSlot(
  25599. slotName,
  25600. slotFunction,
  25601. conditionalBranchIndex++
  25602. ),
  25603. defaultFallback
  25604. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  25605. } else {
  25606. context.onError(
  25607. createCompilerError(30, vElse.loc)
  25608. );
  25609. }
  25610. } else if (vFor) {
  25611. hasDynamicSlots = true;
  25612. const parseResult = vFor.forParseResult;
  25613. if (parseResult) {
  25614. finalizeForParseResult(parseResult, context);
  25615. dynamicSlots.push(
  25616. createCallExpression(context.helper(RENDER_LIST), [
  25617. parseResult.source,
  25618. createFunctionExpression(
  25619. createForLoopParams(parseResult),
  25620. buildDynamicSlot(slotName, slotFunction),
  25621. true
  25622. )
  25623. ])
  25624. );
  25625. } else {
  25626. context.onError(
  25627. createCompilerError(
  25628. 32,
  25629. vFor.loc
  25630. )
  25631. );
  25632. }
  25633. } else {
  25634. if (staticSlotName) {
  25635. if (seenSlotNames.has(staticSlotName)) {
  25636. context.onError(
  25637. createCompilerError(
  25638. 38,
  25639. dirLoc
  25640. )
  25641. );
  25642. continue;
  25643. }
  25644. seenSlotNames.add(staticSlotName);
  25645. if (staticSlotName === "default") {
  25646. hasNamedDefaultSlot = true;
  25647. }
  25648. }
  25649. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  25650. }
  25651. }
  25652. if (!onComponentSlot) {
  25653. const buildDefaultSlotProperty = (props, children2) => {
  25654. const fn = buildSlotFn(props, void 0, children2, loc);
  25655. return createObjectProperty(`default`, fn);
  25656. };
  25657. if (!hasTemplateSlots) {
  25658. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  25659. } else if (implicitDefaultChildren.length && // #3766
  25660. // with whitespace: 'preserve', whitespaces between slots will end up in
  25661. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  25662. !implicitDefaultChildren.every(isWhitespaceText)) {
  25663. if (hasNamedDefaultSlot) {
  25664. context.onError(
  25665. createCompilerError(
  25666. 39,
  25667. implicitDefaultChildren[0].loc
  25668. )
  25669. );
  25670. } else {
  25671. slotsProperties.push(
  25672. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  25673. );
  25674. }
  25675. }
  25676. }
  25677. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  25678. let slots = createObjectExpression(
  25679. slotsProperties.concat(
  25680. createObjectProperty(
  25681. `_`,
  25682. // 2 = compiled but dynamic = can skip normalization, but must run diff
  25683. // 1 = compiled and static = can skip normalization AND diff as optimized
  25684. createSimpleExpression(
  25685. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  25686. false
  25687. )
  25688. )
  25689. ),
  25690. loc
  25691. );
  25692. if (dynamicSlots.length) {
  25693. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  25694. slots,
  25695. createArrayExpression(dynamicSlots)
  25696. ]);
  25697. }
  25698. return {
  25699. slots,
  25700. hasDynamicSlots
  25701. };
  25702. }
  25703. function buildDynamicSlot(name, fn, index) {
  25704. const props = [
  25705. createObjectProperty(`name`, name),
  25706. createObjectProperty(`fn`, fn)
  25707. ];
  25708. if (index != null) {
  25709. props.push(
  25710. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  25711. );
  25712. }
  25713. return createObjectExpression(props);
  25714. }
  25715. function hasForwardedSlots(children) {
  25716. for (let i = 0; i < children.length; i++) {
  25717. const child = children[i];
  25718. switch (child.type) {
  25719. case 1:
  25720. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  25721. return true;
  25722. }
  25723. break;
  25724. case 9:
  25725. if (hasForwardedSlots(child.branches)) return true;
  25726. break;
  25727. case 10:
  25728. case 11:
  25729. if (hasForwardedSlots(child.children)) return true;
  25730. break;
  25731. }
  25732. }
  25733. return false;
  25734. }
  25735. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  25736. const transformElement = (node, context) => {
  25737. return function postTransformElement() {
  25738. node = context.currentNode;
  25739. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  25740. return;
  25741. }
  25742. const { tag, props } = node;
  25743. const isComponent = node.tagType === 1;
  25744. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  25745. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  25746. let vnodeProps;
  25747. let vnodeChildren;
  25748. let patchFlag = 0;
  25749. let vnodeDynamicProps;
  25750. let dynamicPropNames;
  25751. let vnodeDirectives;
  25752. let shouldUseBlock = (
  25753. // dynamic component may resolve to plain elements
  25754. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  25755. // updates inside get proper isSVG flag at runtime. (#639, #643)
  25756. // This is technically web-specific, but splitting the logic out of core
  25757. // leads to too much unnecessary complexity.
  25758. (tag === "svg" || tag === "foreignObject" || tag === "math")
  25759. );
  25760. if (props.length > 0) {
  25761. const propsBuildResult = buildProps(
  25762. node,
  25763. context,
  25764. void 0,
  25765. isComponent,
  25766. isDynamicComponent
  25767. );
  25768. vnodeProps = propsBuildResult.props;
  25769. patchFlag = propsBuildResult.patchFlag;
  25770. dynamicPropNames = propsBuildResult.dynamicPropNames;
  25771. const directives = propsBuildResult.directives;
  25772. vnodeDirectives = directives && directives.length ? createArrayExpression(
  25773. directives.map((dir) => buildDirectiveArgs(dir, context))
  25774. ) : void 0;
  25775. if (propsBuildResult.shouldUseBlock) {
  25776. shouldUseBlock = true;
  25777. }
  25778. }
  25779. if (node.children.length > 0) {
  25780. if (vnodeTag === KEEP_ALIVE) {
  25781. shouldUseBlock = true;
  25782. patchFlag |= 1024;
  25783. if (node.children.length > 1) {
  25784. context.onError(
  25785. createCompilerError(47, {
  25786. start: node.children[0].loc.start,
  25787. end: node.children[node.children.length - 1].loc.end,
  25788. source: ""
  25789. })
  25790. );
  25791. }
  25792. }
  25793. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  25794. vnodeTag !== TELEPORT && // explained above.
  25795. vnodeTag !== KEEP_ALIVE;
  25796. if (shouldBuildAsSlots) {
  25797. const { slots, hasDynamicSlots } = buildSlots(node, context);
  25798. vnodeChildren = slots;
  25799. if (hasDynamicSlots) {
  25800. patchFlag |= 1024;
  25801. }
  25802. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  25803. const child = node.children[0];
  25804. const type = child.type;
  25805. const hasDynamicTextChild = type === 5 || type === 8;
  25806. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  25807. patchFlag |= 1;
  25808. }
  25809. if (hasDynamicTextChild || type === 2) {
  25810. vnodeChildren = child;
  25811. } else {
  25812. vnodeChildren = node.children;
  25813. }
  25814. } else {
  25815. vnodeChildren = node.children;
  25816. }
  25817. }
  25818. if (dynamicPropNames && dynamicPropNames.length) {
  25819. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  25820. }
  25821. node.codegenNode = createVNodeCall(
  25822. context,
  25823. vnodeTag,
  25824. vnodeProps,
  25825. vnodeChildren,
  25826. patchFlag === 0 ? void 0 : patchFlag,
  25827. vnodeDynamicProps,
  25828. vnodeDirectives,
  25829. !!shouldUseBlock,
  25830. false,
  25831. isComponent,
  25832. node.loc
  25833. );
  25834. };
  25835. };
  25836. function resolveComponentType(node, context, ssr = false) {
  25837. let { tag } = node;
  25838. const isExplicitDynamic = isComponentTag(tag);
  25839. const isProp = findProp(
  25840. node,
  25841. "is",
  25842. false,
  25843. true
  25844. /* allow empty */
  25845. );
  25846. if (isProp) {
  25847. if (isExplicitDynamic || false) {
  25848. let exp;
  25849. if (isProp.type === 6) {
  25850. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  25851. } else {
  25852. exp = isProp.exp;
  25853. if (!exp) {
  25854. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  25855. {
  25856. exp = isProp.exp = processExpression(exp, context);
  25857. }
  25858. }
  25859. }
  25860. if (exp) {
  25861. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  25862. exp
  25863. ]);
  25864. }
  25865. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  25866. tag = isProp.value.content.slice(4);
  25867. }
  25868. }
  25869. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  25870. if (builtIn) {
  25871. if (!ssr) context.helper(builtIn);
  25872. return builtIn;
  25873. }
  25874. {
  25875. const fromSetup = resolveSetupReference(tag, context);
  25876. if (fromSetup) {
  25877. return fromSetup;
  25878. }
  25879. const dotIndex = tag.indexOf(".");
  25880. if (dotIndex > 0) {
  25881. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  25882. if (ns) {
  25883. return ns + tag.slice(dotIndex);
  25884. }
  25885. }
  25886. }
  25887. if (context.selfName && capitalize(camelize(tag)) === context.selfName) {
  25888. context.helper(RESOLVE_COMPONENT);
  25889. context.components.add(tag + `__self`);
  25890. return toValidAssetId(tag, `component`);
  25891. }
  25892. context.helper(RESOLVE_COMPONENT);
  25893. context.components.add(tag);
  25894. return toValidAssetId(tag, `component`);
  25895. }
  25896. function resolveSetupReference(name, context) {
  25897. const bindings = context.bindingMetadata;
  25898. if (!bindings || bindings.__isScriptSetup === false) {
  25899. return;
  25900. }
  25901. const camelName = camelize(name);
  25902. const PascalName = capitalize(camelName);
  25903. const checkType = (type) => {
  25904. if (bindings[name] === type) {
  25905. return name;
  25906. }
  25907. if (bindings[camelName] === type) {
  25908. return camelName;
  25909. }
  25910. if (bindings[PascalName] === type) {
  25911. return PascalName;
  25912. }
  25913. };
  25914. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  25915. if (fromConst) {
  25916. return context.inline ? (
  25917. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  25918. fromConst
  25919. ) : `$setup[${JSON.stringify(fromConst)}]`;
  25920. }
  25921. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  25922. if (fromMaybeRef) {
  25923. return context.inline ? (
  25924. // setup scope bindings that may be refs need to be unrefed
  25925. `${context.helperString(UNREF)}(${fromMaybeRef})`
  25926. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  25927. }
  25928. const fromProps = checkType("props");
  25929. if (fromProps) {
  25930. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  25931. }
  25932. }
  25933. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  25934. const { tag, loc: elementLoc, children } = node;
  25935. let properties = [];
  25936. const mergeArgs = [];
  25937. const runtimeDirectives = [];
  25938. const hasChildren = children.length > 0;
  25939. let shouldUseBlock = false;
  25940. let patchFlag = 0;
  25941. let hasRef = false;
  25942. let hasClassBinding = false;
  25943. let hasStyleBinding = false;
  25944. let hasHydrationEventBinding = false;
  25945. let hasDynamicKeys = false;
  25946. let hasVnodeHook = false;
  25947. const dynamicPropNames = [];
  25948. const pushMergeArg = (arg) => {
  25949. if (properties.length) {
  25950. mergeArgs.push(
  25951. createObjectExpression(dedupeProperties(properties), elementLoc)
  25952. );
  25953. properties = [];
  25954. }
  25955. if (arg) mergeArgs.push(arg);
  25956. };
  25957. const pushRefVForMarker = () => {
  25958. if (context.scopes.vFor > 0) {
  25959. properties.push(
  25960. createObjectProperty(
  25961. createSimpleExpression("ref_for", true),
  25962. createSimpleExpression("true")
  25963. )
  25964. );
  25965. }
  25966. };
  25967. const analyzePatchFlag = ({ key, value }) => {
  25968. if (isStaticExp(key)) {
  25969. const name = key.content;
  25970. const isEventHandler = isOn(name);
  25971. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  25972. // dedicated fast path.
  25973. name.toLowerCase() !== "onclick" && // omit v-model handlers
  25974. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  25975. !isReservedProp(name)) {
  25976. hasHydrationEventBinding = true;
  25977. }
  25978. if (isEventHandler && isReservedProp(name)) {
  25979. hasVnodeHook = true;
  25980. }
  25981. if (isEventHandler && value.type === 14) {
  25982. value = value.arguments[0];
  25983. }
  25984. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  25985. return;
  25986. }
  25987. if (name === "ref") {
  25988. hasRef = true;
  25989. } else if (name === "class") {
  25990. hasClassBinding = true;
  25991. } else if (name === "style") {
  25992. hasStyleBinding = true;
  25993. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  25994. dynamicPropNames.push(name);
  25995. }
  25996. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  25997. dynamicPropNames.push(name);
  25998. }
  25999. } else {
  26000. hasDynamicKeys = true;
  26001. }
  26002. };
  26003. for (let i = 0; i < props.length; i++) {
  26004. const prop = props[i];
  26005. if (prop.type === 6) {
  26006. const { loc, name, nameLoc, value } = prop;
  26007. let isStatic = true;
  26008. if (name === "ref") {
  26009. hasRef = true;
  26010. pushRefVForMarker();
  26011. if (value && context.inline) {
  26012. const binding = context.bindingMetadata[value.content];
  26013. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  26014. isStatic = false;
  26015. properties.push(
  26016. createObjectProperty(
  26017. createSimpleExpression("ref_key", true),
  26018. createSimpleExpression(value.content, true, value.loc)
  26019. )
  26020. );
  26021. }
  26022. }
  26023. }
  26024. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  26025. continue;
  26026. }
  26027. properties.push(
  26028. createObjectProperty(
  26029. createSimpleExpression(name, true, nameLoc),
  26030. createSimpleExpression(
  26031. value ? value.content : "",
  26032. isStatic,
  26033. value ? value.loc : loc
  26034. )
  26035. )
  26036. );
  26037. } else {
  26038. const { name, arg, exp, loc, modifiers } = prop;
  26039. const isVBind = name === "bind";
  26040. const isVOn = name === "on";
  26041. if (name === "slot") {
  26042. if (!isComponent) {
  26043. context.onError(
  26044. createCompilerError(40, loc)
  26045. );
  26046. }
  26047. continue;
  26048. }
  26049. if (name === "once" || name === "memo") {
  26050. continue;
  26051. }
  26052. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  26053. continue;
  26054. }
  26055. if (isVOn && ssr) {
  26056. continue;
  26057. }
  26058. if (
  26059. // #938: elements with dynamic keys should be forced into blocks
  26060. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  26061. // before children
  26062. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  26063. ) {
  26064. shouldUseBlock = true;
  26065. }
  26066. if (isVBind && isStaticArgOf(arg, "ref")) {
  26067. pushRefVForMarker();
  26068. }
  26069. if (!arg && (isVBind || isVOn)) {
  26070. hasDynamicKeys = true;
  26071. if (exp) {
  26072. if (isVBind) {
  26073. pushRefVForMarker();
  26074. pushMergeArg();
  26075. mergeArgs.push(exp);
  26076. } else {
  26077. pushMergeArg({
  26078. type: 14,
  26079. loc,
  26080. callee: context.helper(TO_HANDLERS),
  26081. arguments: isComponent ? [exp] : [exp, `true`]
  26082. });
  26083. }
  26084. } else {
  26085. context.onError(
  26086. createCompilerError(
  26087. isVBind ? 34 : 35,
  26088. loc
  26089. )
  26090. );
  26091. }
  26092. continue;
  26093. }
  26094. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  26095. patchFlag |= 32;
  26096. }
  26097. const directiveTransform = context.directiveTransforms[name];
  26098. if (directiveTransform) {
  26099. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  26100. !ssr && props2.forEach(analyzePatchFlag);
  26101. if (isVOn && arg && !isStaticExp(arg)) {
  26102. pushMergeArg(createObjectExpression(props2, elementLoc));
  26103. } else {
  26104. properties.push(...props2);
  26105. }
  26106. if (needRuntime) {
  26107. runtimeDirectives.push(prop);
  26108. if (isSymbol$1(needRuntime)) {
  26109. directiveImportMap.set(prop, needRuntime);
  26110. }
  26111. }
  26112. } else if (!isBuiltInDirective(name)) {
  26113. runtimeDirectives.push(prop);
  26114. if (hasChildren) {
  26115. shouldUseBlock = true;
  26116. }
  26117. }
  26118. }
  26119. }
  26120. let propsExpression = void 0;
  26121. if (mergeArgs.length) {
  26122. pushMergeArg();
  26123. if (mergeArgs.length > 1) {
  26124. propsExpression = createCallExpression(
  26125. context.helper(MERGE_PROPS),
  26126. mergeArgs,
  26127. elementLoc
  26128. );
  26129. } else {
  26130. propsExpression = mergeArgs[0];
  26131. }
  26132. } else if (properties.length) {
  26133. propsExpression = createObjectExpression(
  26134. dedupeProperties(properties),
  26135. elementLoc
  26136. );
  26137. }
  26138. if (hasDynamicKeys) {
  26139. patchFlag |= 16;
  26140. } else {
  26141. if (hasClassBinding && !isComponent) {
  26142. patchFlag |= 2;
  26143. }
  26144. if (hasStyleBinding && !isComponent) {
  26145. patchFlag |= 4;
  26146. }
  26147. if (dynamicPropNames.length) {
  26148. patchFlag |= 8;
  26149. }
  26150. if (hasHydrationEventBinding) {
  26151. patchFlag |= 32;
  26152. }
  26153. }
  26154. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  26155. patchFlag |= 512;
  26156. }
  26157. if (!context.inSSR && propsExpression) {
  26158. switch (propsExpression.type) {
  26159. case 15:
  26160. let classKeyIndex = -1;
  26161. let styleKeyIndex = -1;
  26162. let hasDynamicKey = false;
  26163. for (let i = 0; i < propsExpression.properties.length; i++) {
  26164. const key = propsExpression.properties[i].key;
  26165. if (isStaticExp(key)) {
  26166. if (key.content === "class") {
  26167. classKeyIndex = i;
  26168. } else if (key.content === "style") {
  26169. styleKeyIndex = i;
  26170. }
  26171. } else if (!key.isHandlerKey) {
  26172. hasDynamicKey = true;
  26173. }
  26174. }
  26175. const classProp = propsExpression.properties[classKeyIndex];
  26176. const styleProp = propsExpression.properties[styleKeyIndex];
  26177. if (!hasDynamicKey) {
  26178. if (classProp && !isStaticExp(classProp.value)) {
  26179. classProp.value = createCallExpression(
  26180. context.helper(NORMALIZE_CLASS),
  26181. [classProp.value]
  26182. );
  26183. }
  26184. if (styleProp && // the static style is compiled into an object,
  26185. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  26186. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  26187. // v-bind:style with static literal object
  26188. styleProp.value.type === 17)) {
  26189. styleProp.value = createCallExpression(
  26190. context.helper(NORMALIZE_STYLE),
  26191. [styleProp.value]
  26192. );
  26193. }
  26194. } else {
  26195. propsExpression = createCallExpression(
  26196. context.helper(NORMALIZE_PROPS),
  26197. [propsExpression]
  26198. );
  26199. }
  26200. break;
  26201. case 14:
  26202. break;
  26203. default:
  26204. propsExpression = createCallExpression(
  26205. context.helper(NORMALIZE_PROPS),
  26206. [
  26207. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  26208. propsExpression
  26209. ])
  26210. ]
  26211. );
  26212. break;
  26213. }
  26214. }
  26215. return {
  26216. props: propsExpression,
  26217. directives: runtimeDirectives,
  26218. patchFlag,
  26219. dynamicPropNames,
  26220. shouldUseBlock
  26221. };
  26222. }
  26223. function dedupeProperties(properties) {
  26224. const knownProps = /* @__PURE__ */ new Map();
  26225. const deduped = [];
  26226. for (let i = 0; i < properties.length; i++) {
  26227. const prop = properties[i];
  26228. if (prop.key.type === 8 || !prop.key.isStatic) {
  26229. deduped.push(prop);
  26230. continue;
  26231. }
  26232. const name = prop.key.content;
  26233. const existing = knownProps.get(name);
  26234. if (existing) {
  26235. if (name === "style" || name === "class" || isOn(name)) {
  26236. mergeAsArray(existing, prop);
  26237. }
  26238. } else {
  26239. knownProps.set(name, prop);
  26240. deduped.push(prop);
  26241. }
  26242. }
  26243. return deduped;
  26244. }
  26245. function mergeAsArray(existing, incoming) {
  26246. if (existing.value.type === 17) {
  26247. existing.value.elements.push(incoming.value);
  26248. } else {
  26249. existing.value = createArrayExpression(
  26250. [existing.value, incoming.value],
  26251. existing.loc
  26252. );
  26253. }
  26254. }
  26255. function buildDirectiveArgs(dir, context) {
  26256. const dirArgs = [];
  26257. const runtime = directiveImportMap.get(dir);
  26258. if (runtime) {
  26259. dirArgs.push(context.helperString(runtime));
  26260. } else {
  26261. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  26262. if (fromSetup) {
  26263. dirArgs.push(fromSetup);
  26264. } else {
  26265. context.helper(RESOLVE_DIRECTIVE);
  26266. context.directives.add(dir.name);
  26267. dirArgs.push(toValidAssetId(dir.name, `directive`));
  26268. }
  26269. }
  26270. const { loc } = dir;
  26271. if (dir.exp) dirArgs.push(dir.exp);
  26272. if (dir.arg) {
  26273. if (!dir.exp) {
  26274. dirArgs.push(`void 0`);
  26275. }
  26276. dirArgs.push(dir.arg);
  26277. }
  26278. if (Object.keys(dir.modifiers).length) {
  26279. if (!dir.arg) {
  26280. if (!dir.exp) {
  26281. dirArgs.push(`void 0`);
  26282. }
  26283. dirArgs.push(`void 0`);
  26284. }
  26285. const trueExpression = createSimpleExpression(`true`, false, loc);
  26286. dirArgs.push(
  26287. createObjectExpression(
  26288. dir.modifiers.map(
  26289. (modifier) => createObjectProperty(modifier, trueExpression)
  26290. ),
  26291. loc
  26292. )
  26293. );
  26294. }
  26295. return createArrayExpression(dirArgs, dir.loc);
  26296. }
  26297. function stringifyDynamicPropNames(props) {
  26298. let propsNamesString = `[`;
  26299. for (let i = 0, l = props.length; i < l; i++) {
  26300. propsNamesString += JSON.stringify(props[i]);
  26301. if (i < l - 1) propsNamesString += ", ";
  26302. }
  26303. return propsNamesString + `]`;
  26304. }
  26305. function isComponentTag(tag) {
  26306. return tag === "component" || tag === "Component";
  26307. }
  26308. const transformSlotOutlet = (node, context) => {
  26309. if (isSlotOutlet(node)) {
  26310. const { children, loc } = node;
  26311. const { slotName, slotProps } = processSlotOutlet(node, context);
  26312. const slotArgs = [
  26313. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  26314. slotName,
  26315. "{}",
  26316. "undefined",
  26317. "true"
  26318. ];
  26319. let expectedLen = 2;
  26320. if (slotProps) {
  26321. slotArgs[2] = slotProps;
  26322. expectedLen = 3;
  26323. }
  26324. if (children.length) {
  26325. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  26326. expectedLen = 4;
  26327. }
  26328. if (context.scopeId && !context.slotted) {
  26329. expectedLen = 5;
  26330. }
  26331. slotArgs.splice(expectedLen);
  26332. node.codegenNode = createCallExpression(
  26333. context.helper(RENDER_SLOT),
  26334. slotArgs,
  26335. loc
  26336. );
  26337. }
  26338. };
  26339. function processSlotOutlet(node, context) {
  26340. let slotName = `"default"`;
  26341. let slotProps = void 0;
  26342. const nonNameProps = [];
  26343. for (let i = 0; i < node.props.length; i++) {
  26344. const p = node.props[i];
  26345. if (p.type === 6) {
  26346. if (p.value) {
  26347. if (p.name === "name") {
  26348. slotName = JSON.stringify(p.value.content);
  26349. } else {
  26350. p.name = camelize(p.name);
  26351. nonNameProps.push(p);
  26352. }
  26353. }
  26354. } else {
  26355. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  26356. if (p.exp) {
  26357. slotName = p.exp;
  26358. } else if (p.arg && p.arg.type === 4) {
  26359. const name = camelize(p.arg.content);
  26360. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  26361. {
  26362. slotName = p.exp = processExpression(p.exp, context);
  26363. }
  26364. }
  26365. } else {
  26366. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  26367. p.arg.content = camelize(p.arg.content);
  26368. }
  26369. nonNameProps.push(p);
  26370. }
  26371. }
  26372. }
  26373. if (nonNameProps.length > 0) {
  26374. const { props, directives } = buildProps(
  26375. node,
  26376. context,
  26377. nonNameProps,
  26378. false,
  26379. false
  26380. );
  26381. slotProps = props;
  26382. if (directives.length) {
  26383. context.onError(
  26384. createCompilerError(
  26385. 36,
  26386. directives[0].loc
  26387. )
  26388. );
  26389. }
  26390. }
  26391. return {
  26392. slotName,
  26393. slotProps
  26394. };
  26395. }
  26396. const transformOn$1 = (dir, node, context, augmentor) => {
  26397. const { loc, modifiers, arg } = dir;
  26398. if (!dir.exp && !modifiers.length) {
  26399. context.onError(createCompilerError(35, loc));
  26400. }
  26401. let eventName;
  26402. if (arg.type === 4) {
  26403. if (arg.isStatic) {
  26404. let rawName = arg.content;
  26405. if (rawName.startsWith("vnode")) {
  26406. context.onError(createCompilerError(52, arg.loc));
  26407. }
  26408. if (rawName.startsWith("vue:")) {
  26409. rawName = `vnode-${rawName.slice(4)}`;
  26410. }
  26411. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  26412. // for non-element and vnode lifecycle event listeners, auto convert
  26413. // it to camelCase. See issue #2249
  26414. toHandlerKey(camelize(rawName))
  26415. ) : (
  26416. // preserve case for plain element listeners that have uppercase
  26417. // letters, as these may be custom elements' custom events
  26418. `on:${rawName}`
  26419. );
  26420. eventName = createSimpleExpression(eventString, true, arg.loc);
  26421. } else {
  26422. eventName = createCompoundExpression([
  26423. `${context.helperString(TO_HANDLER_KEY)}(`,
  26424. arg,
  26425. `)`
  26426. ]);
  26427. }
  26428. } else {
  26429. eventName = arg;
  26430. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  26431. eventName.children.push(`)`);
  26432. }
  26433. let exp = dir.exp;
  26434. if (exp && !exp.content.trim()) {
  26435. exp = void 0;
  26436. }
  26437. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  26438. if (exp) {
  26439. const isMemberExp = isMemberExpression(exp, context);
  26440. const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
  26441. const hasMultipleStatements = exp.content.includes(`;`);
  26442. if (context.prefixIdentifiers) {
  26443. isInlineStatement && context.addIdentifiers(`$event`);
  26444. exp = dir.exp = processExpression(
  26445. exp,
  26446. context,
  26447. false,
  26448. hasMultipleStatements
  26449. );
  26450. isInlineStatement && context.removeIdentifiers(`$event`);
  26451. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  26452. !context.inVOnce && // runtime constants don't need to be cached
  26453. // (this is analyzed by compileScript in SFC <script setup>)
  26454. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  26455. // we need to use the original function to preserve arity,
  26456. // e.g. <transition> relies on checking cb.length to determine
  26457. // transition end handling. Inline function is ok since its arity
  26458. // is preserved even when cached.
  26459. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  26460. // it must be passed fresh to avoid stale values.
  26461. !hasScopeRef(exp, context.identifiers);
  26462. if (shouldCache && isMemberExp) {
  26463. if (exp.type === 4) {
  26464. exp.content = `${exp.content} && ${exp.content}(...args)`;
  26465. } else {
  26466. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  26467. }
  26468. }
  26469. }
  26470. if (isInlineStatement || shouldCache && isMemberExp) {
  26471. exp = createCompoundExpression([
  26472. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  26473. //@ts-ignore
  26474. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  26475. exp,
  26476. hasMultipleStatements ? `}` : `)`
  26477. ]);
  26478. }
  26479. }
  26480. let ret = {
  26481. props: [
  26482. createObjectProperty(
  26483. eventName,
  26484. exp || createSimpleExpression(`() => {}`, false, loc)
  26485. )
  26486. ]
  26487. };
  26488. if (augmentor) {
  26489. ret = augmentor(ret);
  26490. }
  26491. if (shouldCache) {
  26492. ret.props[0].value = context.cache(ret.props[0].value);
  26493. }
  26494. ret.props.forEach((p) => p.key.isHandlerKey = true);
  26495. return ret;
  26496. };
  26497. const transformBind = (dir, _node, context) => {
  26498. const { modifiers, loc } = dir;
  26499. const arg = dir.arg;
  26500. let { exp } = dir;
  26501. if (exp && exp.type === 4 && !exp.content.trim()) {
  26502. {
  26503. context.onError(
  26504. createCompilerError(34, loc)
  26505. );
  26506. return {
  26507. props: [
  26508. createObjectProperty(arg, createSimpleExpression("", true, loc))
  26509. ]
  26510. };
  26511. }
  26512. }
  26513. if (arg.type !== 4) {
  26514. arg.children.unshift(`(`);
  26515. arg.children.push(`) || ""`);
  26516. } else if (!arg.isStatic) {
  26517. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  26518. }
  26519. if (modifiers.some((mod) => mod.content === "camel")) {
  26520. if (arg.type === 4) {
  26521. if (arg.isStatic) {
  26522. arg.content = camelize(arg.content);
  26523. } else {
  26524. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  26525. }
  26526. } else {
  26527. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  26528. arg.children.push(`)`);
  26529. }
  26530. }
  26531. if (!context.inSSR) {
  26532. if (modifiers.some((mod) => mod.content === "prop")) {
  26533. injectPrefix(arg, ".");
  26534. }
  26535. if (modifiers.some((mod) => mod.content === "attr")) {
  26536. injectPrefix(arg, "^");
  26537. }
  26538. }
  26539. return {
  26540. props: [createObjectProperty(arg, exp)]
  26541. };
  26542. };
  26543. const injectPrefix = (arg, prefix) => {
  26544. if (arg.type === 4) {
  26545. if (arg.isStatic) {
  26546. arg.content = prefix + arg.content;
  26547. } else {
  26548. arg.content = `\`${prefix}\${${arg.content}}\``;
  26549. }
  26550. } else {
  26551. arg.children.unshift(`'${prefix}' + (`);
  26552. arg.children.push(`)`);
  26553. }
  26554. };
  26555. const transformText = (node, context) => {
  26556. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  26557. return () => {
  26558. const children = node.children;
  26559. let currentContainer = void 0;
  26560. let hasText = false;
  26561. for (let i = 0; i < children.length; i++) {
  26562. const child = children[i];
  26563. if (isText$1(child)) {
  26564. hasText = true;
  26565. for (let j = i + 1; j < children.length; j++) {
  26566. const next = children[j];
  26567. if (isText$1(next)) {
  26568. if (!currentContainer) {
  26569. currentContainer = children[i] = createCompoundExpression(
  26570. [child],
  26571. child.loc
  26572. );
  26573. }
  26574. currentContainer.children.push(` + `, next);
  26575. children.splice(j, 1);
  26576. j--;
  26577. } else {
  26578. currentContainer = void 0;
  26579. break;
  26580. }
  26581. }
  26582. }
  26583. }
  26584. if (!hasText || // if this is a plain element with a single text child, leave it
  26585. // as-is since the runtime has dedicated fast path for this by directly
  26586. // setting textContent of the element.
  26587. // for component root it's always normalized anyway.
  26588. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  26589. // custom directives can potentially add DOM elements arbitrarily,
  26590. // we need to avoid setting textContent of the element at runtime
  26591. // to avoid accidentally overwriting the DOM elements added
  26592. // by the user through custom directives.
  26593. !node.props.find(
  26594. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  26595. ) && // in compat mode, <template> tags with no special directives
  26596. // will be rendered as a fragment so its children must be
  26597. // converted into vnodes.
  26598. true)) {
  26599. return;
  26600. }
  26601. for (let i = 0; i < children.length; i++) {
  26602. const child = children[i];
  26603. if (isText$1(child) || child.type === 8) {
  26604. const callArgs = [];
  26605. if (child.type !== 2 || child.content !== " ") {
  26606. callArgs.push(child);
  26607. }
  26608. if (!context.ssr && getConstantType(child, context) === 0) {
  26609. callArgs.push(
  26610. 1 + (` /* ${PatchFlagNames[1]} */` )
  26611. );
  26612. }
  26613. children[i] = {
  26614. type: 12,
  26615. content: child,
  26616. loc: child.loc,
  26617. codegenNode: createCallExpression(
  26618. context.helper(CREATE_TEXT),
  26619. callArgs
  26620. )
  26621. };
  26622. }
  26623. }
  26624. };
  26625. }
  26626. };
  26627. const seen$1 = /* @__PURE__ */ new WeakSet();
  26628. const transformOnce = (node, context) => {
  26629. if (node.type === 1 && findDir(node, "once", true)) {
  26630. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  26631. return;
  26632. }
  26633. seen$1.add(node);
  26634. context.inVOnce = true;
  26635. context.helper(SET_BLOCK_TRACKING);
  26636. return () => {
  26637. context.inVOnce = false;
  26638. const cur = context.currentNode;
  26639. if (cur.codegenNode) {
  26640. cur.codegenNode = context.cache(
  26641. cur.codegenNode,
  26642. true,
  26643. true
  26644. );
  26645. }
  26646. };
  26647. }
  26648. };
  26649. const transformModel$1 = (dir, node, context) => {
  26650. const { exp, arg } = dir;
  26651. if (!exp) {
  26652. context.onError(
  26653. createCompilerError(41, dir.loc)
  26654. );
  26655. return createTransformProps();
  26656. }
  26657. const rawExp = exp.loc.source.trim();
  26658. const expString = exp.type === 4 ? exp.content : rawExp;
  26659. const bindingType = context.bindingMetadata[rawExp];
  26660. if (bindingType === "props" || bindingType === "props-aliased") {
  26661. context.onError(createCompilerError(44, exp.loc));
  26662. return createTransformProps();
  26663. }
  26664. if (bindingType === "literal-const" || bindingType === "setup-const") {
  26665. context.onError(createCompilerError(45, exp.loc));
  26666. return createTransformProps();
  26667. }
  26668. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  26669. if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
  26670. context.onError(
  26671. createCompilerError(42, exp.loc)
  26672. );
  26673. return createTransformProps();
  26674. }
  26675. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  26676. context.onError(
  26677. createCompilerError(43, exp.loc)
  26678. );
  26679. return createTransformProps();
  26680. }
  26681. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  26682. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  26683. let assignmentExp;
  26684. const eventArg = context.isTS ? `($event: any)` : `$event`;
  26685. if (maybeRef) {
  26686. if (bindingType === "setup-ref") {
  26687. assignmentExp = createCompoundExpression([
  26688. `${eventArg} => ((`,
  26689. createSimpleExpression(rawExp, false, exp.loc),
  26690. `).value = $event)`
  26691. ]);
  26692. } else {
  26693. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  26694. assignmentExp = createCompoundExpression([
  26695. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  26696. createSimpleExpression(rawExp, false, exp.loc),
  26697. `).value = $event : ${altAssignment})`
  26698. ]);
  26699. }
  26700. } else {
  26701. assignmentExp = createCompoundExpression([
  26702. `${eventArg} => ((`,
  26703. exp,
  26704. `) = $event)`
  26705. ]);
  26706. }
  26707. const props = [
  26708. // modelValue: foo
  26709. createObjectProperty(propName, dir.exp),
  26710. // "onUpdate:modelValue": $event => (foo = $event)
  26711. createObjectProperty(eventName, assignmentExp)
  26712. ];
  26713. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  26714. props[1].value = context.cache(props[1].value);
  26715. }
  26716. if (dir.modifiers.length && node.tagType === 1) {
  26717. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  26718. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  26719. props.push(
  26720. createObjectProperty(
  26721. modifiersKey,
  26722. createSimpleExpression(
  26723. `{ ${modifiers} }`,
  26724. false,
  26725. dir.loc,
  26726. 2
  26727. )
  26728. )
  26729. );
  26730. }
  26731. return createTransformProps(props);
  26732. };
  26733. function createTransformProps(props = []) {
  26734. return { props };
  26735. }
  26736. const seen = /* @__PURE__ */ new WeakSet();
  26737. const transformMemo = (node, context) => {
  26738. if (node.type === 1) {
  26739. const dir = findDir(node, "memo");
  26740. if (!dir || seen.has(node) || context.inSSR) {
  26741. return;
  26742. }
  26743. seen.add(node);
  26744. return () => {
  26745. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  26746. if (codegenNode && codegenNode.type === 13) {
  26747. if (node.tagType !== 1) {
  26748. convertToBlock(codegenNode, context);
  26749. }
  26750. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  26751. dir.exp,
  26752. createFunctionExpression(void 0, codegenNode),
  26753. `_cache`,
  26754. String(context.cached.length)
  26755. ]);
  26756. context.cached.push(null);
  26757. }
  26758. };
  26759. }
  26760. };
  26761. const transformVBindShorthand = (node, context) => {
  26762. if (node.type === 1) {
  26763. for (const prop of node.props) {
  26764. if (prop.type === 7 && prop.name === "bind" && (!prop.exp || // #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
  26765. false) && prop.arg) {
  26766. const arg = prop.arg;
  26767. if (arg.type !== 4 || !arg.isStatic) {
  26768. context.onError(
  26769. createCompilerError(
  26770. 53,
  26771. arg.loc
  26772. )
  26773. );
  26774. prop.exp = createSimpleExpression("", true, arg.loc);
  26775. } else {
  26776. const propName = camelize(arg.content);
  26777. if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
  26778. propName[0] === "-") {
  26779. prop.exp = createSimpleExpression(propName, false, arg.loc);
  26780. }
  26781. }
  26782. }
  26783. }
  26784. }
  26785. };
  26786. function getBaseTransformPreset(prefixIdentifiers) {
  26787. return [
  26788. [
  26789. transformVBindShorthand,
  26790. transformOnce,
  26791. transformIf,
  26792. transformMemo,
  26793. transformFor,
  26794. ...[],
  26795. ...prefixIdentifiers ? [
  26796. // order is important
  26797. trackVForSlotScopes,
  26798. transformExpression
  26799. ] : [],
  26800. transformSlotOutlet,
  26801. transformElement,
  26802. trackSlotScopes,
  26803. transformText
  26804. ],
  26805. {
  26806. on: transformOn$1,
  26807. bind: transformBind,
  26808. model: transformModel$1
  26809. }
  26810. ];
  26811. }
  26812. function baseCompile(source, options = {}) {
  26813. const onError = options.onError || defaultOnError;
  26814. const isModuleMode = options.mode === "module";
  26815. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  26816. if (!prefixIdentifiers && options.cacheHandlers) {
  26817. onError(createCompilerError(50));
  26818. }
  26819. if (options.scopeId && !isModuleMode) {
  26820. onError(createCompilerError(51));
  26821. }
  26822. const resolvedOptions = extend({}, options, {
  26823. prefixIdentifiers
  26824. });
  26825. const ast = isString$1(source) ? baseParse(source, resolvedOptions) : source;
  26826. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  26827. if (options.isTS) {
  26828. const { expressionPlugins } = options;
  26829. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  26830. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  26831. }
  26832. }
  26833. transform(
  26834. ast,
  26835. extend({}, resolvedOptions, {
  26836. nodeTransforms: [
  26837. ...nodeTransforms,
  26838. ...options.nodeTransforms || []
  26839. // user transforms
  26840. ],
  26841. directiveTransforms: extend(
  26842. {},
  26843. directiveTransforms,
  26844. options.directiveTransforms || {}
  26845. // user transforms
  26846. )
  26847. })
  26848. );
  26849. return generate(ast, resolvedOptions);
  26850. }
  26851. const BindingTypes = {
  26852. "DATA": "data",
  26853. "PROPS": "props",
  26854. "PROPS_ALIASED": "props-aliased",
  26855. "SETUP_LET": "setup-let",
  26856. "SETUP_CONST": "setup-const",
  26857. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  26858. "SETUP_MAYBE_REF": "setup-maybe-ref",
  26859. "SETUP_REF": "setup-ref",
  26860. "OPTIONS": "options",
  26861. "LITERAL_CONST": "literal-const"
  26862. };
  26863. const noopDirectiveTransform = () => ({ props: [] });
  26864. const V_MODEL_RADIO = /* @__PURE__ */ Symbol(`vModelRadio` );
  26865. const V_MODEL_CHECKBOX = /* @__PURE__ */ Symbol(
  26866. `vModelCheckbox`
  26867. );
  26868. const V_MODEL_TEXT = /* @__PURE__ */ Symbol(`vModelText` );
  26869. const V_MODEL_SELECT = /* @__PURE__ */ Symbol(
  26870. `vModelSelect`
  26871. );
  26872. const V_MODEL_DYNAMIC = /* @__PURE__ */ Symbol(
  26873. `vModelDynamic`
  26874. );
  26875. const V_ON_WITH_MODIFIERS = /* @__PURE__ */ Symbol(
  26876. `vOnModifiersGuard`
  26877. );
  26878. const V_ON_WITH_KEYS = /* @__PURE__ */ Symbol(
  26879. `vOnKeysGuard`
  26880. );
  26881. const V_SHOW = /* @__PURE__ */ Symbol(`vShow` );
  26882. const TRANSITION = /* @__PURE__ */ Symbol(`Transition` );
  26883. const TRANSITION_GROUP = /* @__PURE__ */ Symbol(
  26884. `TransitionGroup`
  26885. );
  26886. registerRuntimeHelpers({
  26887. [V_MODEL_RADIO]: `vModelRadio`,
  26888. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  26889. [V_MODEL_TEXT]: `vModelText`,
  26890. [V_MODEL_SELECT]: `vModelSelect`,
  26891. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  26892. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  26893. [V_ON_WITH_KEYS]: `withKeys`,
  26894. [V_SHOW]: `vShow`,
  26895. [TRANSITION]: `Transition`,
  26896. [TRANSITION_GROUP]: `TransitionGroup`
  26897. });
  26898. const parserOptions = {
  26899. parseMode: "html",
  26900. isVoidTag,
  26901. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  26902. isPreTag: (tag) => tag === "pre",
  26903. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  26904. decodeEntities: void 0,
  26905. isBuiltInComponent: (tag) => {
  26906. if (tag === "Transition" || tag === "transition") {
  26907. return TRANSITION;
  26908. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  26909. return TRANSITION_GROUP;
  26910. }
  26911. },
  26912. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  26913. getNamespace(tag, parent, rootNamespace) {
  26914. let ns = parent ? parent.ns : rootNamespace;
  26915. if (parent && ns === 2) {
  26916. if (parent.tag === "annotation-xml") {
  26917. if (tag === "svg") {
  26918. return 1;
  26919. }
  26920. if (parent.props.some(
  26921. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  26922. )) {
  26923. ns = 0;
  26924. }
  26925. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  26926. ns = 0;
  26927. }
  26928. } else if (parent && ns === 1) {
  26929. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  26930. ns = 0;
  26931. }
  26932. }
  26933. if (ns === 0) {
  26934. if (tag === "svg") {
  26935. return 1;
  26936. }
  26937. if (tag === "math") {
  26938. return 2;
  26939. }
  26940. }
  26941. return ns;
  26942. }
  26943. };
  26944. const transformStyle = (node) => {
  26945. if (node.type === 1) {
  26946. node.props.forEach((p, i) => {
  26947. if (p.type === 6 && p.name === "style" && p.value) {
  26948. node.props[i] = {
  26949. type: 7,
  26950. name: `bind`,
  26951. arg: createSimpleExpression(`style`, true, p.loc),
  26952. exp: parseInlineCSS(p.value.content, p.loc),
  26953. modifiers: [],
  26954. loc: p.loc
  26955. };
  26956. }
  26957. });
  26958. }
  26959. };
  26960. const parseInlineCSS = (cssText, loc) => {
  26961. const normalized = parseStringStyle(cssText);
  26962. return createSimpleExpression(
  26963. JSON.stringify(normalized),
  26964. false,
  26965. loc,
  26966. 3
  26967. );
  26968. };
  26969. function createDOMCompilerError(code, loc) {
  26970. return createCompilerError(
  26971. code,
  26972. loc,
  26973. DOMErrorMessages
  26974. );
  26975. }
  26976. const DOMErrorCodes = {
  26977. "X_V_HTML_NO_EXPRESSION": 54,
  26978. "54": "X_V_HTML_NO_EXPRESSION",
  26979. "X_V_HTML_WITH_CHILDREN": 55,
  26980. "55": "X_V_HTML_WITH_CHILDREN",
  26981. "X_V_TEXT_NO_EXPRESSION": 56,
  26982. "56": "X_V_TEXT_NO_EXPRESSION",
  26983. "X_V_TEXT_WITH_CHILDREN": 57,
  26984. "57": "X_V_TEXT_WITH_CHILDREN",
  26985. "X_V_MODEL_ON_INVALID_ELEMENT": 58,
  26986. "58": "X_V_MODEL_ON_INVALID_ELEMENT",
  26987. "X_V_MODEL_ARG_ON_ELEMENT": 59,
  26988. "59": "X_V_MODEL_ARG_ON_ELEMENT",
  26989. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 60,
  26990. "60": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  26991. "X_V_MODEL_UNNECESSARY_VALUE": 61,
  26992. "61": "X_V_MODEL_UNNECESSARY_VALUE",
  26993. "X_V_SHOW_NO_EXPRESSION": 62,
  26994. "62": "X_V_SHOW_NO_EXPRESSION",
  26995. "X_TRANSITION_INVALID_CHILDREN": 63,
  26996. "63": "X_TRANSITION_INVALID_CHILDREN",
  26997. "X_IGNORED_SIDE_EFFECT_TAG": 64,
  26998. "64": "X_IGNORED_SIDE_EFFECT_TAG",
  26999. "__EXTEND_POINT__": 65,
  27000. "65": "__EXTEND_POINT__"
  27001. };
  27002. const DOMErrorMessages = {
  27003. [54]: `v-html is missing expression.`,
  27004. [55]: `v-html will override element children.`,
  27005. [56]: `v-text is missing expression.`,
  27006. [57]: `v-text will override element children.`,
  27007. [58]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  27008. [59]: `v-model argument is not supported on plain elements.`,
  27009. [60]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  27010. [61]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  27011. [62]: `v-show is missing expression.`,
  27012. [63]: `<Transition> expects exactly one child element or component.`,
  27013. [64]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  27014. };
  27015. const transformVHtml = (dir, node, context) => {
  27016. const { exp, loc } = dir;
  27017. if (!exp) {
  27018. context.onError(
  27019. createDOMCompilerError(54, loc)
  27020. );
  27021. }
  27022. if (node.children.length) {
  27023. context.onError(
  27024. createDOMCompilerError(55, loc)
  27025. );
  27026. node.children.length = 0;
  27027. }
  27028. return {
  27029. props: [
  27030. createObjectProperty(
  27031. createSimpleExpression(`innerHTML`, true, loc),
  27032. exp || createSimpleExpression("", true)
  27033. )
  27034. ]
  27035. };
  27036. };
  27037. const transformVText = (dir, node, context) => {
  27038. const { exp, loc } = dir;
  27039. if (!exp) {
  27040. context.onError(
  27041. createDOMCompilerError(56, loc)
  27042. );
  27043. }
  27044. if (node.children.length) {
  27045. context.onError(
  27046. createDOMCompilerError(57, loc)
  27047. );
  27048. node.children.length = 0;
  27049. }
  27050. return {
  27051. props: [
  27052. createObjectProperty(
  27053. createSimpleExpression(`textContent`, true),
  27054. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  27055. context.helperString(TO_DISPLAY_STRING),
  27056. [exp],
  27057. loc
  27058. ) : createSimpleExpression("", true)
  27059. )
  27060. ]
  27061. };
  27062. };
  27063. const transformModel = (dir, node, context) => {
  27064. const baseResult = transformModel$1(dir, node, context);
  27065. if (!baseResult.props.length || node.tagType === 1) {
  27066. return baseResult;
  27067. }
  27068. if (dir.arg) {
  27069. context.onError(
  27070. createDOMCompilerError(
  27071. 59,
  27072. dir.arg.loc
  27073. )
  27074. );
  27075. }
  27076. function checkDuplicatedValue() {
  27077. const value = findDir(node, "bind");
  27078. if (value && isStaticArgOf(value.arg, "value")) {
  27079. context.onError(
  27080. createDOMCompilerError(
  27081. 61,
  27082. value.loc
  27083. )
  27084. );
  27085. }
  27086. }
  27087. const { tag } = node;
  27088. const isCustomElement = context.isCustomElement(tag);
  27089. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  27090. let directiveToUse = V_MODEL_TEXT;
  27091. let isInvalidType = false;
  27092. if (tag === "input" || isCustomElement) {
  27093. const type = findProp(node, `type`);
  27094. if (type) {
  27095. if (type.type === 7) {
  27096. directiveToUse = V_MODEL_DYNAMIC;
  27097. } else if (type.value) {
  27098. switch (type.value.content) {
  27099. case "radio":
  27100. directiveToUse = V_MODEL_RADIO;
  27101. break;
  27102. case "checkbox":
  27103. directiveToUse = V_MODEL_CHECKBOX;
  27104. break;
  27105. case "file":
  27106. isInvalidType = true;
  27107. context.onError(
  27108. createDOMCompilerError(
  27109. 60,
  27110. dir.loc
  27111. )
  27112. );
  27113. break;
  27114. default:
  27115. checkDuplicatedValue();
  27116. break;
  27117. }
  27118. }
  27119. } else if (hasDynamicKeyVBind(node)) {
  27120. directiveToUse = V_MODEL_DYNAMIC;
  27121. } else {
  27122. checkDuplicatedValue();
  27123. }
  27124. } else if (tag === "select") {
  27125. directiveToUse = V_MODEL_SELECT;
  27126. } else {
  27127. checkDuplicatedValue();
  27128. }
  27129. if (!isInvalidType) {
  27130. baseResult.needRuntime = context.helper(directiveToUse);
  27131. }
  27132. } else {
  27133. context.onError(
  27134. createDOMCompilerError(
  27135. 58,
  27136. dir.loc
  27137. )
  27138. );
  27139. }
  27140. baseResult.props = baseResult.props.filter(
  27141. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  27142. );
  27143. return baseResult;
  27144. };
  27145. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  27146. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  27147. // event propagation management
  27148. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  27149. );
  27150. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  27151. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  27152. const resolveModifiers = (key, modifiers, context, loc) => {
  27153. const keyModifiers = [];
  27154. const nonKeyModifiers = [];
  27155. const eventOptionModifiers = [];
  27156. for (let i = 0; i < modifiers.length; i++) {
  27157. const modifier = modifiers[i].content;
  27158. if (isEventOptionModifier(modifier)) {
  27159. eventOptionModifiers.push(modifier);
  27160. } else {
  27161. if (maybeKeyModifier(modifier)) {
  27162. if (isStaticExp(key)) {
  27163. if (isKeyboardEvent(key.content.toLowerCase())) {
  27164. keyModifiers.push(modifier);
  27165. } else {
  27166. nonKeyModifiers.push(modifier);
  27167. }
  27168. } else {
  27169. keyModifiers.push(modifier);
  27170. nonKeyModifiers.push(modifier);
  27171. }
  27172. } else {
  27173. if (isNonKeyModifier(modifier)) {
  27174. nonKeyModifiers.push(modifier);
  27175. } else {
  27176. keyModifiers.push(modifier);
  27177. }
  27178. }
  27179. }
  27180. }
  27181. return {
  27182. keyModifiers,
  27183. nonKeyModifiers,
  27184. eventOptionModifiers
  27185. };
  27186. };
  27187. const transformClick = (key, event) => {
  27188. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  27189. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  27190. `(`,
  27191. key,
  27192. `) === "onClick" ? "${event}" : (`,
  27193. key,
  27194. `)`
  27195. ]) : key;
  27196. };
  27197. const transformOn = (dir, node, context) => {
  27198. return transformOn$1(dir, node, context, (baseResult) => {
  27199. const { modifiers } = dir;
  27200. if (!modifiers.length) return baseResult;
  27201. let { key, value: handlerExp } = baseResult.props[0];
  27202. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  27203. if (nonKeyModifiers.includes("right")) {
  27204. key = transformClick(key, `onContextmenu`);
  27205. }
  27206. if (nonKeyModifiers.includes("middle")) {
  27207. key = transformClick(key, `onMouseup`);
  27208. }
  27209. if (nonKeyModifiers.length) {
  27210. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  27211. handlerExp,
  27212. JSON.stringify(nonKeyModifiers)
  27213. ]);
  27214. }
  27215. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  27216. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  27217. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  27218. handlerExp,
  27219. JSON.stringify(keyModifiers)
  27220. ]);
  27221. }
  27222. if (eventOptionModifiers.length) {
  27223. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  27224. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  27225. }
  27226. return {
  27227. props: [createObjectProperty(key, handlerExp)]
  27228. };
  27229. });
  27230. };
  27231. const transformShow = (dir, node, context) => {
  27232. const { exp, loc } = dir;
  27233. if (!exp) {
  27234. context.onError(
  27235. createDOMCompilerError(62, loc)
  27236. );
  27237. }
  27238. return {
  27239. props: [],
  27240. needRuntime: context.helper(V_SHOW)
  27241. };
  27242. };
  27243. const transformTransition = (node, context) => {
  27244. if (node.type === 1 && node.tagType === 1) {
  27245. const component = context.isBuiltInComponent(node.tag);
  27246. if (component === TRANSITION) {
  27247. return () => {
  27248. if (!node.children.length) {
  27249. return;
  27250. }
  27251. if (hasMultipleChildren(node)) {
  27252. context.onError(
  27253. createDOMCompilerError(
  27254. 63,
  27255. {
  27256. start: node.children[0].loc.start,
  27257. end: node.children[node.children.length - 1].loc.end,
  27258. source: ""
  27259. }
  27260. )
  27261. );
  27262. }
  27263. const child = node.children[0];
  27264. if (child.type === 1) {
  27265. for (const p of child.props) {
  27266. if (p.type === 7 && p.name === "show") {
  27267. node.props.push({
  27268. type: 6,
  27269. name: "persisted",
  27270. nameLoc: node.loc,
  27271. value: void 0,
  27272. loc: node.loc
  27273. });
  27274. }
  27275. }
  27276. }
  27277. };
  27278. }
  27279. }
  27280. };
  27281. function hasMultipleChildren(node) {
  27282. const children = node.children = node.children.filter(
  27283. (c) => !isCommentOrWhitespace(c)
  27284. );
  27285. const child = children[0];
  27286. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  27287. }
  27288. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  27289. const stringifyStatic = (children, context, parent) => {
  27290. if (context.scopes.vSlot > 0) {
  27291. return;
  27292. }
  27293. const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray$3(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
  27294. let nc = 0;
  27295. let ec = 0;
  27296. const currentChunk = [];
  27297. const stringifyCurrentChunk = (currentIndex) => {
  27298. if (nc >= 20 || ec >= 5) {
  27299. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  27300. JSON.stringify(
  27301. currentChunk.map((node) => stringifyNode(node, context)).join("")
  27302. ).replace(expReplaceRE, `" + $1 + "`),
  27303. // the 2nd argument indicates the number of DOM nodes this static vnode
  27304. // will insert / hydrate
  27305. String(currentChunk.length)
  27306. ]);
  27307. const deleteCount = currentChunk.length - 1;
  27308. if (isParentCached) {
  27309. children.splice(
  27310. currentIndex - currentChunk.length,
  27311. currentChunk.length,
  27312. // @ts-expect-error
  27313. staticCall
  27314. );
  27315. } else {
  27316. currentChunk[0].codegenNode.value = staticCall;
  27317. if (currentChunk.length > 1) {
  27318. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  27319. const cacheIndex = context.cached.indexOf(
  27320. currentChunk[currentChunk.length - 1].codegenNode
  27321. );
  27322. if (cacheIndex > -1) {
  27323. for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
  27324. const c = context.cached[i2];
  27325. if (c) c.index -= deleteCount;
  27326. }
  27327. context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
  27328. }
  27329. }
  27330. }
  27331. return deleteCount;
  27332. }
  27333. return 0;
  27334. };
  27335. let i = 0;
  27336. for (; i < children.length; i++) {
  27337. const child = children[i];
  27338. const isCached = isParentCached || getCachedNode(child);
  27339. if (isCached) {
  27340. const result = analyzeNode(child);
  27341. if (result) {
  27342. nc += result[0];
  27343. ec += result[1];
  27344. currentChunk.push(child);
  27345. continue;
  27346. }
  27347. }
  27348. i -= stringifyCurrentChunk(i);
  27349. nc = 0;
  27350. ec = 0;
  27351. currentChunk.length = 0;
  27352. }
  27353. stringifyCurrentChunk(i);
  27354. };
  27355. const getCachedNode = (node) => {
  27356. if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
  27357. return node.codegenNode;
  27358. }
  27359. };
  27360. const dataAriaRE = /^(?:data|aria)-/;
  27361. const isStringifiableAttr = (name, ns) => {
  27362. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : ns === 2 ? isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
  27363. };
  27364. const isNonStringifiable = /* @__PURE__ */ makeMap(
  27365. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  27366. );
  27367. function analyzeNode(node) {
  27368. if (node.type === 1 && isNonStringifiable(node.tag)) {
  27369. return false;
  27370. }
  27371. if (node.type === 1 && findDir(node, "once", true)) {
  27372. return false;
  27373. }
  27374. if (node.type === 12) {
  27375. return [1, 0];
  27376. }
  27377. let nc = 1;
  27378. let ec = node.props.length > 0 ? 1 : 0;
  27379. let bailed = false;
  27380. const bail = () => {
  27381. bailed = true;
  27382. return false;
  27383. };
  27384. function walk(node2) {
  27385. const isOptionTag = node2.tag === "option" && node2.ns === 0;
  27386. for (let i = 0; i < node2.props.length; i++) {
  27387. const p = node2.props[i];
  27388. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  27389. return bail();
  27390. }
  27391. if (p.type === 7 && p.name === "bind") {
  27392. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  27393. return bail();
  27394. }
  27395. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  27396. return bail();
  27397. }
  27398. if (isOptionTag && isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
  27399. return bail();
  27400. }
  27401. }
  27402. }
  27403. for (let i = 0; i < node2.children.length; i++) {
  27404. nc++;
  27405. const child = node2.children[i];
  27406. if (child.type === 1) {
  27407. if (child.props.length > 0) {
  27408. ec++;
  27409. }
  27410. walk(child);
  27411. if (bailed) {
  27412. return false;
  27413. }
  27414. }
  27415. }
  27416. return true;
  27417. }
  27418. return walk(node) ? [nc, ec] : false;
  27419. }
  27420. function stringifyNode(node, context) {
  27421. if (isString$1(node)) {
  27422. return node;
  27423. }
  27424. if (isSymbol$1(node)) {
  27425. return ``;
  27426. }
  27427. switch (node.type) {
  27428. case 1:
  27429. return stringifyElement(node, context);
  27430. case 2:
  27431. return escapeHtml(node.content);
  27432. case 3:
  27433. return `<!--${escapeHtml(node.content)}-->`;
  27434. case 5:
  27435. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  27436. case 8:
  27437. return escapeHtml(evaluateConstant(node));
  27438. case 12:
  27439. return stringifyNode(node.content, context);
  27440. default:
  27441. return "";
  27442. }
  27443. }
  27444. function stringifyElement(node, context) {
  27445. let res = `<${node.tag}`;
  27446. let innerHTML = "";
  27447. for (let i = 0; i < node.props.length; i++) {
  27448. const p = node.props[i];
  27449. if (p.type === 6) {
  27450. res += ` ${p.name}`;
  27451. if (p.value) {
  27452. res += `="${escapeHtml(p.value.content)}"`;
  27453. }
  27454. } else if (p.type === 7) {
  27455. if (p.name === "bind") {
  27456. const exp = p.exp;
  27457. if (exp.content[0] === "_") {
  27458. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  27459. continue;
  27460. }
  27461. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  27462. continue;
  27463. }
  27464. let evaluated = evaluateConstant(exp);
  27465. if (evaluated != null) {
  27466. const arg = p.arg && p.arg.content;
  27467. if (arg === "class") {
  27468. evaluated = normalizeClass(evaluated);
  27469. } else if (arg === "style") {
  27470. evaluated = stringifyStyle(normalizeStyle(evaluated));
  27471. }
  27472. res += ` ${p.arg.content}="${escapeHtml(
  27473. evaluated
  27474. )}"`;
  27475. }
  27476. } else if (p.name === "html") {
  27477. innerHTML = evaluateConstant(p.exp);
  27478. } else if (p.name === "text") {
  27479. innerHTML = escapeHtml(
  27480. toDisplayString(evaluateConstant(p.exp))
  27481. );
  27482. }
  27483. }
  27484. }
  27485. if (context.scopeId) {
  27486. res += ` ${context.scopeId}`;
  27487. }
  27488. res += `>`;
  27489. if (innerHTML) {
  27490. res += innerHTML;
  27491. } else {
  27492. for (let i = 0; i < node.children.length; i++) {
  27493. res += stringifyNode(node.children[i], context);
  27494. }
  27495. }
  27496. if (!isVoidTag(node.tag)) {
  27497. res += `</${node.tag}>`;
  27498. }
  27499. return res;
  27500. }
  27501. function evaluateConstant(exp) {
  27502. if (exp.type === 4) {
  27503. return new Function(`return (${exp.content})`)();
  27504. } else {
  27505. let res = ``;
  27506. exp.children.forEach((c) => {
  27507. if (isString$1(c) || isSymbol$1(c)) {
  27508. return;
  27509. }
  27510. if (c.type === 2) {
  27511. res += c.content;
  27512. } else if (c.type === 5) {
  27513. res += toDisplayString(evaluateConstant(c.content));
  27514. } else {
  27515. res += evaluateConstant(c);
  27516. }
  27517. });
  27518. return res;
  27519. }
  27520. }
  27521. const ignoreSideEffectTags = (node, context) => {
  27522. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  27523. context.onError(
  27524. createDOMCompilerError(
  27525. 64,
  27526. node.loc
  27527. )
  27528. );
  27529. context.removeNode();
  27530. }
  27531. };
  27532. function isValidHTMLNesting(parent, child) {
  27533. if (parent === "template") {
  27534. return true;
  27535. }
  27536. if (parent in onlyValidChildren) {
  27537. return onlyValidChildren[parent].has(child);
  27538. }
  27539. if (child in onlyValidParents) {
  27540. return onlyValidParents[child].has(parent);
  27541. }
  27542. if (parent in knownInvalidChildren) {
  27543. if (knownInvalidChildren[parent].has(child)) return false;
  27544. }
  27545. if (child in knownInvalidParents) {
  27546. if (knownInvalidParents[child].has(parent)) return false;
  27547. }
  27548. return true;
  27549. }
  27550. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  27551. const emptySet = /* @__PURE__ */ new Set([]);
  27552. const onlyValidChildren = {
  27553. head: /* @__PURE__ */ new Set([
  27554. "base",
  27555. "basefront",
  27556. "bgsound",
  27557. "link",
  27558. "meta",
  27559. "title",
  27560. "noscript",
  27561. "noframes",
  27562. "style",
  27563. "script",
  27564. "template"
  27565. ]),
  27566. optgroup: /* @__PURE__ */ new Set(["option"]),
  27567. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  27568. // table
  27569. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  27570. tr: /* @__PURE__ */ new Set(["td", "th"]),
  27571. colgroup: /* @__PURE__ */ new Set(["col"]),
  27572. tbody: /* @__PURE__ */ new Set(["tr"]),
  27573. thead: /* @__PURE__ */ new Set(["tr"]),
  27574. tfoot: /* @__PURE__ */ new Set(["tr"]),
  27575. // these elements can not have any children elements
  27576. script: emptySet,
  27577. iframe: emptySet,
  27578. option: emptySet,
  27579. textarea: emptySet,
  27580. style: emptySet,
  27581. title: emptySet
  27582. };
  27583. const onlyValidParents = {
  27584. // sections
  27585. html: emptySet,
  27586. body: /* @__PURE__ */ new Set(["html"]),
  27587. head: /* @__PURE__ */ new Set(["html"]),
  27588. // table
  27589. td: /* @__PURE__ */ new Set(["tr"]),
  27590. colgroup: /* @__PURE__ */ new Set(["table"]),
  27591. caption: /* @__PURE__ */ new Set(["table"]),
  27592. tbody: /* @__PURE__ */ new Set(["table"]),
  27593. tfoot: /* @__PURE__ */ new Set(["table"]),
  27594. col: /* @__PURE__ */ new Set(["colgroup"]),
  27595. th: /* @__PURE__ */ new Set(["tr"]),
  27596. thead: /* @__PURE__ */ new Set(["table"]),
  27597. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  27598. // data list
  27599. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  27600. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  27601. // other
  27602. figcaption: /* @__PURE__ */ new Set(["figure"]),
  27603. // li: new Set(["ul", "ol"]),
  27604. summary: /* @__PURE__ */ new Set(["details"]),
  27605. area: /* @__PURE__ */ new Set(["map"])
  27606. };
  27607. const knownInvalidChildren = {
  27608. p: /* @__PURE__ */ new Set([
  27609. "address",
  27610. "article",
  27611. "aside",
  27612. "blockquote",
  27613. "center",
  27614. "details",
  27615. "dialog",
  27616. "dir",
  27617. "div",
  27618. "dl",
  27619. "fieldset",
  27620. "figure",
  27621. "footer",
  27622. "form",
  27623. "h1",
  27624. "h2",
  27625. "h3",
  27626. "h4",
  27627. "h5",
  27628. "h6",
  27629. "header",
  27630. "hgroup",
  27631. "hr",
  27632. "li",
  27633. "main",
  27634. "nav",
  27635. "menu",
  27636. "ol",
  27637. "p",
  27638. "pre",
  27639. "section",
  27640. "table",
  27641. "ul"
  27642. ]),
  27643. svg: /* @__PURE__ */ new Set([
  27644. "b",
  27645. "blockquote",
  27646. "br",
  27647. "code",
  27648. "dd",
  27649. "div",
  27650. "dl",
  27651. "dt",
  27652. "em",
  27653. "embed",
  27654. "h1",
  27655. "h2",
  27656. "h3",
  27657. "h4",
  27658. "h5",
  27659. "h6",
  27660. "hr",
  27661. "i",
  27662. "img",
  27663. "li",
  27664. "menu",
  27665. "meta",
  27666. "ol",
  27667. "p",
  27668. "pre",
  27669. "ruby",
  27670. "s",
  27671. "small",
  27672. "span",
  27673. "strong",
  27674. "sub",
  27675. "sup",
  27676. "table",
  27677. "u",
  27678. "ul",
  27679. "var"
  27680. ])
  27681. };
  27682. const knownInvalidParents = {
  27683. a: /* @__PURE__ */ new Set(["a"]),
  27684. button: /* @__PURE__ */ new Set(["button"]),
  27685. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  27686. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  27687. form: /* @__PURE__ */ new Set(["form"]),
  27688. li: /* @__PURE__ */ new Set(["li"]),
  27689. h1: headings,
  27690. h2: headings,
  27691. h3: headings,
  27692. h4: headings,
  27693. h5: headings,
  27694. h6: headings
  27695. };
  27696. const validateHtmlNesting = (node, context) => {
  27697. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  27698. const error = new SyntaxError(
  27699. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  27700. );
  27701. error.loc = node.loc;
  27702. context.onWarn(error);
  27703. }
  27704. };
  27705. const DOMNodeTransforms = [
  27706. transformStyle,
  27707. ...[transformTransition, validateHtmlNesting]
  27708. ];
  27709. const DOMDirectiveTransforms = {
  27710. cloak: noopDirectiveTransform,
  27711. html: transformVHtml,
  27712. text: transformVText,
  27713. model: transformModel,
  27714. // override compiler-core
  27715. on: transformOn,
  27716. // override compiler-core
  27717. show: transformShow
  27718. };
  27719. function compile$1(src, options = {}) {
  27720. return baseCompile(
  27721. src,
  27722. extend({}, parserOptions, options, {
  27723. nodeTransforms: [
  27724. // ignore <script> and <tag>
  27725. // this is not put inside DOMNodeTransforms because that list is used
  27726. // by compiler-ssr to generate vnode fallback branches
  27727. ignoreSideEffectTags,
  27728. ...DOMNodeTransforms,
  27729. ...options.nodeTransforms || []
  27730. ],
  27731. directiveTransforms: extend(
  27732. {},
  27733. DOMDirectiveTransforms,
  27734. options.directiveTransforms || {}
  27735. ),
  27736. transformHoist: stringifyStatic
  27737. })
  27738. );
  27739. }
  27740. function parse$3(template, options = {}) {
  27741. return baseParse(template, extend({}, parserOptions, options));
  27742. }
  27743. var CompilerDOM = /*#__PURE__*/Object.freeze({
  27744. __proto__: null,
  27745. BASE_TRANSITION: BASE_TRANSITION,
  27746. BindingTypes: BindingTypes,
  27747. CAMELIZE: CAMELIZE,
  27748. CAPITALIZE: CAPITALIZE,
  27749. CREATE_BLOCK: CREATE_BLOCK,
  27750. CREATE_COMMENT: CREATE_COMMENT,
  27751. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  27752. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  27753. CREATE_SLOTS: CREATE_SLOTS,
  27754. CREATE_STATIC: CREATE_STATIC,
  27755. CREATE_TEXT: CREATE_TEXT,
  27756. CREATE_VNODE: CREATE_VNODE,
  27757. CompilerDeprecationTypes: CompilerDeprecationTypes,
  27758. ConstantTypes: ConstantTypes,
  27759. DOMDirectiveTransforms: DOMDirectiveTransforms,
  27760. DOMErrorCodes: DOMErrorCodes,
  27761. DOMErrorMessages: DOMErrorMessages,
  27762. DOMNodeTransforms: DOMNodeTransforms,
  27763. ElementTypes: ElementTypes,
  27764. ErrorCodes: ErrorCodes,
  27765. FRAGMENT: FRAGMENT,
  27766. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  27767. IS_MEMO_SAME: IS_MEMO_SAME,
  27768. IS_REF: IS_REF,
  27769. KEEP_ALIVE: KEEP_ALIVE,
  27770. MERGE_PROPS: MERGE_PROPS,
  27771. NORMALIZE_CLASS: NORMALIZE_CLASS,
  27772. NORMALIZE_PROPS: NORMALIZE_PROPS,
  27773. NORMALIZE_STYLE: NORMALIZE_STYLE,
  27774. Namespaces: Namespaces,
  27775. NodeTypes: NodeTypes,
  27776. OPEN_BLOCK: OPEN_BLOCK,
  27777. POP_SCOPE_ID: POP_SCOPE_ID,
  27778. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  27779. RENDER_LIST: RENDER_LIST,
  27780. RENDER_SLOT: RENDER_SLOT,
  27781. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  27782. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  27783. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  27784. RESOLVE_FILTER: RESOLVE_FILTER,
  27785. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  27786. SUSPENSE: SUSPENSE,
  27787. TELEPORT: TELEPORT,
  27788. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  27789. TO_HANDLERS: TO_HANDLERS,
  27790. TO_HANDLER_KEY: TO_HANDLER_KEY,
  27791. TRANSITION: TRANSITION,
  27792. TRANSITION_GROUP: TRANSITION_GROUP,
  27793. TS_NODE_TYPES: TS_NODE_TYPES,
  27794. UNREF: UNREF,
  27795. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  27796. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  27797. V_MODEL_RADIO: V_MODEL_RADIO,
  27798. V_MODEL_SELECT: V_MODEL_SELECT,
  27799. V_MODEL_TEXT: V_MODEL_TEXT,
  27800. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  27801. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  27802. V_SHOW: V_SHOW,
  27803. WITH_CTX: WITH_CTX,
  27804. WITH_DIRECTIVES: WITH_DIRECTIVES,
  27805. WITH_MEMO: WITH_MEMO,
  27806. advancePositionWithClone: advancePositionWithClone,
  27807. advancePositionWithMutation: advancePositionWithMutation,
  27808. assert: assert,
  27809. baseCompile: baseCompile,
  27810. baseParse: baseParse,
  27811. buildDirectiveArgs: buildDirectiveArgs,
  27812. buildProps: buildProps,
  27813. buildSlots: buildSlots,
  27814. checkCompatEnabled: checkCompatEnabled,
  27815. compile: compile$1,
  27816. convertToBlock: convertToBlock,
  27817. createArrayExpression: createArrayExpression,
  27818. createAssignmentExpression: createAssignmentExpression,
  27819. createBlockStatement: createBlockStatement,
  27820. createCacheExpression: createCacheExpression,
  27821. createCallExpression: createCallExpression,
  27822. createCompilerError: createCompilerError,
  27823. createCompoundExpression: createCompoundExpression,
  27824. createConditionalExpression: createConditionalExpression,
  27825. createDOMCompilerError: createDOMCompilerError,
  27826. createForLoopParams: createForLoopParams,
  27827. createFunctionExpression: createFunctionExpression,
  27828. createIfStatement: createIfStatement,
  27829. createInterpolation: createInterpolation,
  27830. createObjectExpression: createObjectExpression,
  27831. createObjectProperty: createObjectProperty,
  27832. createReturnStatement: createReturnStatement,
  27833. createRoot: createRoot,
  27834. createSequenceExpression: createSequenceExpression,
  27835. createSimpleExpression: createSimpleExpression,
  27836. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  27837. createTemplateLiteral: createTemplateLiteral,
  27838. createTransformContext: createTransformContext,
  27839. createVNodeCall: createVNodeCall,
  27840. errorMessages: errorMessages$1,
  27841. extractIdentifiers: extractIdentifiers$1,
  27842. findDir: findDir,
  27843. findProp: findProp,
  27844. forAliasRE: forAliasRE,
  27845. generate: generate,
  27846. generateCodeFrame: generateCodeFrame,
  27847. getBaseTransformPreset: getBaseTransformPreset,
  27848. getConstantType: getConstantType,
  27849. getMemoedVNodeCall: getMemoedVNodeCall,
  27850. getVNodeBlockHelper: getVNodeBlockHelper,
  27851. getVNodeHelper: getVNodeHelper,
  27852. hasDynamicKeyVBind: hasDynamicKeyVBind,
  27853. hasScopeRef: hasScopeRef,
  27854. helperNameMap: helperNameMap,
  27855. injectProp: injectProp,
  27856. isAllWhitespace: isAllWhitespace,
  27857. isCommentOrWhitespace: isCommentOrWhitespace,
  27858. isCoreComponent: isCoreComponent,
  27859. isFnExpression: isFnExpression,
  27860. isFnExpressionBrowser: isFnExpressionBrowser,
  27861. isFnExpressionNode: isFnExpressionNode,
  27862. isFunctionType: isFunctionType,
  27863. isInDestructureAssignment: isInDestructureAssignment,
  27864. isInNewExpression: isInNewExpression,
  27865. isMemberExpression: isMemberExpression,
  27866. isMemberExpressionBrowser: isMemberExpressionBrowser,
  27867. isMemberExpressionNode: isMemberExpressionNode,
  27868. isReferencedIdentifier: isReferencedIdentifier,
  27869. isSimpleIdentifier: isSimpleIdentifier,
  27870. isSlotOutlet: isSlotOutlet,
  27871. isStaticArgOf: isStaticArgOf,
  27872. isStaticExp: isStaticExp,
  27873. isStaticProperty: isStaticProperty,
  27874. isStaticPropertyKey: isStaticPropertyKey,
  27875. isTemplateNode: isTemplateNode,
  27876. isText: isText$1,
  27877. isVPre: isVPre,
  27878. isVSlot: isVSlot,
  27879. isWhitespaceText: isWhitespaceText,
  27880. locStub: locStub,
  27881. noopDirectiveTransform: noopDirectiveTransform,
  27882. parse: parse$3,
  27883. parserOptions: parserOptions,
  27884. processExpression: processExpression,
  27885. processFor: processFor,
  27886. processIf: processIf,
  27887. processSlotOutlet: processSlotOutlet,
  27888. registerRuntimeHelpers: registerRuntimeHelpers,
  27889. resolveComponentType: resolveComponentType,
  27890. stringifyExpression: stringifyExpression,
  27891. toValidAssetId: toValidAssetId,
  27892. trackSlotScopes: trackSlotScopes,
  27893. trackVForSlotScopes: trackVForSlotScopes,
  27894. transform: transform,
  27895. transformBind: transformBind,
  27896. transformElement: transformElement,
  27897. transformExpression: transformExpression,
  27898. transformModel: transformModel$1,
  27899. transformOn: transformOn$1,
  27900. transformStyle: transformStyle,
  27901. transformVBindShorthand: transformVBindShorthand,
  27902. traverseNode: traverseNode,
  27903. unwrapTSNode: unwrapTSNode,
  27904. validFirstIdentCharRE: validFirstIdentCharRE,
  27905. walkBlockDeclarations: walkBlockDeclarations,
  27906. walkFunctionParams: walkFunctionParams,
  27907. walkIdentifiers: walkIdentifiers,
  27908. warnDeprecation: warnDeprecation
  27909. });
  27910. var hashSum;
  27911. var hasRequiredHashSum;
  27912. function requireHashSum () {
  27913. if (hasRequiredHashSum) return hashSum;
  27914. hasRequiredHashSum = 1;
  27915. function pad (hash, len) {
  27916. while (hash.length < len) {
  27917. hash = '0' + hash;
  27918. }
  27919. return hash;
  27920. }
  27921. function fold (hash, text) {
  27922. var i;
  27923. var chr;
  27924. var len;
  27925. if (text.length === 0) {
  27926. return hash;
  27927. }
  27928. for (i = 0, len = text.length; i < len; i++) {
  27929. chr = text.charCodeAt(i);
  27930. hash = ((hash << 5) - hash) + chr;
  27931. hash |= 0;
  27932. }
  27933. return hash < 0 ? hash * -2 : hash;
  27934. }
  27935. function foldObject (hash, o, seen) {
  27936. return Object.keys(o).sort().reduce(foldKey, hash);
  27937. function foldKey (hash, key) {
  27938. return foldValue(hash, o[key], key, seen);
  27939. }
  27940. }
  27941. function foldValue (input, value, key, seen) {
  27942. var hash = fold(fold(fold(input, key), toString(value)), typeof value);
  27943. if (value === null) {
  27944. return fold(hash, 'null');
  27945. }
  27946. if (value === undefined) {
  27947. return fold(hash, 'undefined');
  27948. }
  27949. if (typeof value === 'object' || typeof value === 'function') {
  27950. if (seen.indexOf(value) !== -1) {
  27951. return fold(hash, '[Circular]' + key);
  27952. }
  27953. seen.push(value);
  27954. var objHash = foldObject(hash, value, seen);
  27955. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  27956. return objHash;
  27957. }
  27958. try {
  27959. return fold(objHash, String(value.valueOf()))
  27960. } catch (err) {
  27961. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  27962. }
  27963. }
  27964. return fold(hash, value.toString());
  27965. }
  27966. function toString (o) {
  27967. return Object.prototype.toString.call(o);
  27968. }
  27969. function sum (o) {
  27970. return pad(foldValue(0, o, '', []).toString(16), 8);
  27971. }
  27972. hashSum = sum;
  27973. return hashSum;
  27974. }
  27975. var hashSumExports = /*@__PURE__*/ requireHashSum();
  27976. var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
  27977. const CSS_VARS_HELPER = `useCssVars`;
  27978. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  27979. return `{
  27980. ${vars.map(
  27981. (key) => (
  27982. // The `:` prefix here is used in `ssrRenderStyle` to distinguish whether
  27983. // a custom property comes from `ssrCssVars`. If it does, we need to reset
  27984. // its value to `initial` on the component instance to avoid unintentionally
  27985. // inheriting the same property value from a different instance of the same
  27986. // component in the outer scope.
  27987. `"${isSSR ? `:--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`
  27988. )
  27989. ).join(",\n ")}
  27990. }`;
  27991. }
  27992. function genVarName(id, raw, isProd, isSSR = false) {
  27993. if (isProd) {
  27994. return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
  27995. } else {
  27996. return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
  27997. }
  27998. }
  27999. function normalizeExpression(exp) {
  28000. exp = exp.trim();
  28001. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  28002. return exp.slice(1, -1);
  28003. }
  28004. return exp;
  28005. }
  28006. const vBindRE = /v-bind\s*\(/g;
  28007. function parseCssVars(sfc) {
  28008. const vars = [];
  28009. sfc.styles.forEach((style) => {
  28010. let match;
  28011. const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
  28012. while (match = vBindRE.exec(content)) {
  28013. const start = match.index + match[0].length;
  28014. const end = lexBinding(content, start);
  28015. if (end !== null) {
  28016. const variable = normalizeExpression(content.slice(start, end));
  28017. if (!vars.includes(variable)) {
  28018. vars.push(variable);
  28019. }
  28020. }
  28021. }
  28022. });
  28023. return vars;
  28024. }
  28025. function lexBinding(content, start) {
  28026. let state = 0 /* inParens */;
  28027. let parenDepth = 0;
  28028. for (let i = start; i < content.length; i++) {
  28029. const char = content.charAt(i);
  28030. switch (state) {
  28031. case 0 /* inParens */:
  28032. if (char === `'`) {
  28033. state = 1 /* inSingleQuoteString */;
  28034. } else if (char === `"`) {
  28035. state = 2 /* inDoubleQuoteString */;
  28036. } else if (char === `(`) {
  28037. parenDepth++;
  28038. } else if (char === `)`) {
  28039. if (parenDepth > 0) {
  28040. parenDepth--;
  28041. } else {
  28042. return i;
  28043. }
  28044. }
  28045. break;
  28046. case 1 /* inSingleQuoteString */:
  28047. if (char === `'`) {
  28048. state = 0 /* inParens */;
  28049. }
  28050. break;
  28051. case 2 /* inDoubleQuoteString */:
  28052. if (char === `"`) {
  28053. state = 0 /* inParens */;
  28054. }
  28055. break;
  28056. }
  28057. }
  28058. return null;
  28059. }
  28060. const cssVarsPlugin = (opts) => {
  28061. const { id, isProd } = opts;
  28062. return {
  28063. postcssPlugin: "vue-sfc-vars",
  28064. Declaration(decl) {
  28065. const value = decl.value;
  28066. if (vBindRE.test(value)) {
  28067. vBindRE.lastIndex = 0;
  28068. let transformed = "";
  28069. let lastIndex = 0;
  28070. let match;
  28071. while (match = vBindRE.exec(value)) {
  28072. const start = match.index + match[0].length;
  28073. const end = lexBinding(value, start);
  28074. if (end !== null) {
  28075. const variable = normalizeExpression(value.slice(start, end));
  28076. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  28077. lastIndex = end + 1;
  28078. }
  28079. }
  28080. decl.value = transformed + value.slice(lastIndex);
  28081. }
  28082. }
  28083. };
  28084. };
  28085. cssVarsPlugin.postcss = true;
  28086. function genCssVarsCode(vars, bindings, id, isProd) {
  28087. const varsExp = genCssVarsFromList(vars, id, isProd);
  28088. const exp = createSimpleExpression(varsExp, false);
  28089. const context = createTransformContext(createRoot([]), {
  28090. prefixIdentifiers: true,
  28091. inline: true,
  28092. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  28093. });
  28094. const transformed = processExpression(exp, context);
  28095. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  28096. return typeof c === "string" ? c : c.content;
  28097. }).join("");
  28098. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  28099. }
  28100. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  28101. return `
  28102. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  28103. const __injectCSSVars__ = () => {
  28104. ${genCssVarsCode(
  28105. cssVars,
  28106. bindings,
  28107. id,
  28108. isProd
  28109. )}}
  28110. const __setup__ = ${defaultVar}.setup
  28111. ${defaultVar}.setup = __setup__
  28112. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  28113. : __injectCSSVars__
  28114. `;
  28115. }
  28116. // shim for using process in browser
  28117. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  28118. function defaultSetTimout() {
  28119. throw new Error('setTimeout has not been defined');
  28120. }
  28121. function defaultClearTimeout () {
  28122. throw new Error('clearTimeout has not been defined');
  28123. }
  28124. var cachedSetTimeout = defaultSetTimout;
  28125. var cachedClearTimeout = defaultClearTimeout;
  28126. if (typeof global$1.setTimeout === 'function') {
  28127. cachedSetTimeout = setTimeout;
  28128. }
  28129. if (typeof global$1.clearTimeout === 'function') {
  28130. cachedClearTimeout = clearTimeout;
  28131. }
  28132. function runTimeout(fun) {
  28133. if (cachedSetTimeout === setTimeout) {
  28134. //normal enviroments in sane situations
  28135. return setTimeout(fun, 0);
  28136. }
  28137. // if setTimeout wasn't available but was latter defined
  28138. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  28139. cachedSetTimeout = setTimeout;
  28140. return setTimeout(fun, 0);
  28141. }
  28142. try {
  28143. // when when somebody has screwed with setTimeout but no I.E. maddness
  28144. return cachedSetTimeout(fun, 0);
  28145. } catch(e){
  28146. try {
  28147. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28148. return cachedSetTimeout.call(null, fun, 0);
  28149. } catch(e){
  28150. // 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
  28151. return cachedSetTimeout.call(this, fun, 0);
  28152. }
  28153. }
  28154. }
  28155. function runClearTimeout(marker) {
  28156. if (cachedClearTimeout === clearTimeout) {
  28157. //normal enviroments in sane situations
  28158. return clearTimeout(marker);
  28159. }
  28160. // if clearTimeout wasn't available but was latter defined
  28161. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  28162. cachedClearTimeout = clearTimeout;
  28163. return clearTimeout(marker);
  28164. }
  28165. try {
  28166. // when when somebody has screwed with setTimeout but no I.E. maddness
  28167. return cachedClearTimeout(marker);
  28168. } catch (e){
  28169. try {
  28170. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  28171. return cachedClearTimeout.call(null, marker);
  28172. } catch (e){
  28173. // 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.
  28174. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  28175. return cachedClearTimeout.call(this, marker);
  28176. }
  28177. }
  28178. }
  28179. var queue = [];
  28180. var draining = false;
  28181. var currentQueue;
  28182. var queueIndex = -1;
  28183. function cleanUpNextTick() {
  28184. if (!draining || !currentQueue) {
  28185. return;
  28186. }
  28187. draining = false;
  28188. if (currentQueue.length) {
  28189. queue = currentQueue.concat(queue);
  28190. } else {
  28191. queueIndex = -1;
  28192. }
  28193. if (queue.length) {
  28194. drainQueue();
  28195. }
  28196. }
  28197. function drainQueue() {
  28198. if (draining) {
  28199. return;
  28200. }
  28201. var timeout = runTimeout(cleanUpNextTick);
  28202. draining = true;
  28203. var len = queue.length;
  28204. while(len) {
  28205. currentQueue = queue;
  28206. queue = [];
  28207. while (++queueIndex < len) {
  28208. if (currentQueue) {
  28209. currentQueue[queueIndex].run();
  28210. }
  28211. }
  28212. queueIndex = -1;
  28213. len = queue.length;
  28214. }
  28215. currentQueue = null;
  28216. draining = false;
  28217. runClearTimeout(timeout);
  28218. }
  28219. function nextTick(fun) {
  28220. var args = new Array(arguments.length - 1);
  28221. if (arguments.length > 1) {
  28222. for (var i = 1; i < arguments.length; i++) {
  28223. args[i - 1] = arguments[i];
  28224. }
  28225. }
  28226. queue.push(new Item(fun, args));
  28227. if (queue.length === 1 && !draining) {
  28228. runTimeout(drainQueue);
  28229. }
  28230. }
  28231. // v8 likes predictible objects
  28232. function Item(fun, array) {
  28233. this.fun = fun;
  28234. this.array = array;
  28235. }
  28236. Item.prototype.run = function () {
  28237. this.fun.apply(null, this.array);
  28238. };
  28239. var title = 'browser';
  28240. var platform = 'browser';
  28241. var browser = true;
  28242. var env = {};
  28243. var argv = [];
  28244. var version$1 = ''; // empty string to avoid regexp issues
  28245. var versions = {};
  28246. var release = {};
  28247. var config = {};
  28248. function noop() {}
  28249. var on = noop;
  28250. var addListener = noop;
  28251. var once = noop;
  28252. var off = noop;
  28253. var removeListener = noop;
  28254. var removeAllListeners = noop;
  28255. var emit = noop;
  28256. function binding(name) {
  28257. throw new Error('process.binding is not supported');
  28258. }
  28259. function cwd () { return '/' }
  28260. function chdir (dir) {
  28261. throw new Error('process.chdir is not supported');
  28262. }function umask() { return 0; }
  28263. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  28264. var performance = global$1.performance || {};
  28265. var performanceNow =
  28266. performance.now ||
  28267. performance.mozNow ||
  28268. performance.msNow ||
  28269. performance.oNow ||
  28270. performance.webkitNow ||
  28271. function(){ return (new Date()).getTime() };
  28272. // generate timestamp or delta
  28273. // see http://nodejs.org/api/process.html#process_process_hrtime
  28274. function hrtime(previousTimestamp){
  28275. var clocktime = performanceNow.call(performance)*1e-3;
  28276. var seconds = Math.floor(clocktime);
  28277. var nanoseconds = Math.floor((clocktime%1)*1e9);
  28278. if (previousTimestamp) {
  28279. seconds = seconds - previousTimestamp[0];
  28280. nanoseconds = nanoseconds - previousTimestamp[1];
  28281. if (nanoseconds<0) {
  28282. seconds--;
  28283. nanoseconds += 1e9;
  28284. }
  28285. }
  28286. return [seconds,nanoseconds]
  28287. }
  28288. var startTime = new Date();
  28289. function uptime() {
  28290. var currentTime = new Date();
  28291. var dif = currentTime - startTime;
  28292. return dif / 1000;
  28293. }
  28294. var browser$1 = {
  28295. nextTick: nextTick,
  28296. title: title,
  28297. browser: browser,
  28298. env: env,
  28299. argv: argv,
  28300. version: version$1,
  28301. versions: versions,
  28302. on: on,
  28303. addListener: addListener,
  28304. once: once,
  28305. off: off,
  28306. removeListener: removeListener,
  28307. removeAllListeners: removeAllListeners,
  28308. emit: emit,
  28309. binding: binding,
  28310. cwd: cwd,
  28311. chdir: chdir,
  28312. umask: umask,
  28313. hrtime: hrtime,
  28314. platform: platform,
  28315. release: release,
  28316. config: config,
  28317. uptime: uptime
  28318. };
  28319. function createCache(max = 500) {
  28320. {
  28321. return /* @__PURE__ */ new Map();
  28322. }
  28323. }
  28324. function isImportUsed(local, sfc) {
  28325. return resolveTemplateUsedIdentifiers(sfc).has(local);
  28326. }
  28327. const templateAnalysisCache = createCache();
  28328. function resolveTemplateVModelIdentifiers(sfc) {
  28329. return resolveTemplateAnalysisResult(sfc, false).vModelIds;
  28330. }
  28331. function resolveTemplateUsedIdentifiers(sfc) {
  28332. return resolveTemplateAnalysisResult(sfc).usedIds;
  28333. }
  28334. function resolveTemplateAnalysisResult(sfc, collectUsedIds = true) {
  28335. const { content, ast } = sfc.template;
  28336. const cached = templateAnalysisCache.get(content);
  28337. if (cached && (!collectUsedIds || cached.usedIds)) {
  28338. return cached;
  28339. }
  28340. const ids = collectUsedIds ? /* @__PURE__ */ new Set() : void 0;
  28341. const vModelIds = /* @__PURE__ */ new Set();
  28342. ast.children.forEach(walk);
  28343. function walk(node) {
  28344. var _a;
  28345. switch (node.type) {
  28346. case 1:
  28347. let tag = node.tag;
  28348. if (tag.includes(".")) tag = tag.split(".")[0].trim();
  28349. if (!parserOptions.isNativeTag(tag) && !parserOptions.isBuiltInComponent(tag)) {
  28350. if (ids) {
  28351. ids.add(camelize(tag));
  28352. ids.add(capitalize(camelize(tag)));
  28353. }
  28354. }
  28355. for (let i = 0; i < node.props.length; i++) {
  28356. const prop = node.props[i];
  28357. if (prop.type === 7) {
  28358. if (ids) {
  28359. if (!isBuiltInDirective(prop.name)) {
  28360. ids.add(`v${capitalize(camelize(prop.name))}`);
  28361. }
  28362. }
  28363. if (prop.name === "model") {
  28364. const exp = prop.exp;
  28365. if (exp && exp.type === 4) {
  28366. const expString = exp.content.trim();
  28367. if (isSimpleIdentifier(expString) && expString !== "undefined") {
  28368. vModelIds.add(expString);
  28369. }
  28370. }
  28371. }
  28372. if (ids && prop.arg && !prop.arg.isStatic) {
  28373. extractIdentifiers(ids, prop.arg);
  28374. }
  28375. if (ids) {
  28376. if (prop.name === "for") {
  28377. extractIdentifiers(ids, prop.forParseResult.source);
  28378. } else if (prop.exp) {
  28379. extractIdentifiers(ids, prop.exp);
  28380. } else if (prop.name === "bind" && !prop.exp) {
  28381. ids.add(camelize(prop.arg.content));
  28382. }
  28383. }
  28384. }
  28385. if (ids && prop.type === 6 && prop.name === "ref" && ((_a = prop.value) == null ? void 0 : _a.content)) {
  28386. ids.add(prop.value.content);
  28387. }
  28388. }
  28389. node.children.forEach(walk);
  28390. break;
  28391. case 5:
  28392. if (ids) extractIdentifiers(ids, node.content);
  28393. break;
  28394. }
  28395. }
  28396. const result = { usedIds: ids, vModelIds };
  28397. templateAnalysisCache.set(content, result);
  28398. return result;
  28399. }
  28400. function extractIdentifiers(ids, node) {
  28401. if (node.ast) {
  28402. walkIdentifiers(node.ast, (n) => ids.add(n.name));
  28403. } else if (node.ast === null) {
  28404. ids.add(node.content);
  28405. }
  28406. }
  28407. var __defProp$a = Object.defineProperty;
  28408. var __defProps$9 = Object.defineProperties;
  28409. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  28410. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  28411. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  28412. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  28413. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  28414. var __spreadValues$a = (a, b) => {
  28415. for (var prop in b || (b = {}))
  28416. if (__hasOwnProp$a.call(b, prop))
  28417. __defNormalProp$a(a, prop, b[prop]);
  28418. if (__getOwnPropSymbols$a)
  28419. for (var prop of __getOwnPropSymbols$a(b)) {
  28420. if (__propIsEnum$a.call(b, prop))
  28421. __defNormalProp$a(a, prop, b[prop]);
  28422. }
  28423. return a;
  28424. };
  28425. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  28426. const DEFAULT_FILENAME = "anonymous.vue";
  28427. const parseCache$1 = createCache();
  28428. function parse$2(source, options = {}) {
  28429. var _a;
  28430. const sourceKey = genCacheKey(source, __spreadProps$9(__spreadValues$a({}, options), {
  28431. compiler: { parse: (_a = options.compiler) == null ? void 0 : _a.parse }
  28432. }));
  28433. const cache = parseCache$1.get(sourceKey);
  28434. if (cache) {
  28435. return cache;
  28436. }
  28437. const {
  28438. sourceMap = true,
  28439. filename = DEFAULT_FILENAME,
  28440. sourceRoot = "",
  28441. pad = false,
  28442. ignoreEmpty = true,
  28443. compiler = CompilerDOM,
  28444. templateParseOptions = {}
  28445. } = options;
  28446. const descriptor = {
  28447. filename,
  28448. source,
  28449. template: null,
  28450. script: null,
  28451. scriptSetup: null,
  28452. styles: [],
  28453. customBlocks: [],
  28454. cssVars: [],
  28455. slotted: false,
  28456. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  28457. };
  28458. const errors = [];
  28459. const ast = compiler.parse(source, __spreadProps$9(__spreadValues$a({
  28460. parseMode: "sfc",
  28461. prefixIdentifiers: true
  28462. }, templateParseOptions), {
  28463. onError: (e) => {
  28464. errors.push(e);
  28465. }
  28466. }));
  28467. ast.children.forEach((node) => {
  28468. if (node.type !== 1) {
  28469. return;
  28470. }
  28471. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  28472. return;
  28473. }
  28474. switch (node.tag) {
  28475. case "template":
  28476. if (!descriptor.template) {
  28477. const templateBlock = descriptor.template = createBlock(
  28478. node,
  28479. source,
  28480. false
  28481. );
  28482. if (!templateBlock.attrs.src) {
  28483. templateBlock.ast = createRoot(node.children, source);
  28484. }
  28485. if (templateBlock.attrs.functional) {
  28486. const err = new SyntaxError(
  28487. `<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.`
  28488. );
  28489. err.loc = node.props.find(
  28490. (p) => p.type === 6 && p.name === "functional"
  28491. ).loc;
  28492. errors.push(err);
  28493. }
  28494. } else {
  28495. errors.push(createDuplicateBlockError(node));
  28496. }
  28497. break;
  28498. case "script":
  28499. const scriptBlock = createBlock(node, source, pad);
  28500. const isSetup = !!scriptBlock.attrs.setup;
  28501. if (isSetup && !descriptor.scriptSetup) {
  28502. descriptor.scriptSetup = scriptBlock;
  28503. break;
  28504. }
  28505. if (!isSetup && !descriptor.script) {
  28506. descriptor.script = scriptBlock;
  28507. break;
  28508. }
  28509. errors.push(createDuplicateBlockError(node, isSetup));
  28510. break;
  28511. case "style":
  28512. const styleBlock = createBlock(node, source, pad);
  28513. if (styleBlock.attrs.vars) {
  28514. errors.push(
  28515. new SyntaxError(
  28516. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  28517. )
  28518. );
  28519. }
  28520. descriptor.styles.push(styleBlock);
  28521. break;
  28522. default:
  28523. descriptor.customBlocks.push(createBlock(node, source, pad));
  28524. break;
  28525. }
  28526. });
  28527. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  28528. errors.push(
  28529. new SyntaxError(
  28530. `At least one <template> or <script> is required in a single file component. ${descriptor.filename}`
  28531. )
  28532. );
  28533. }
  28534. if (descriptor.scriptSetup) {
  28535. if (descriptor.scriptSetup.src) {
  28536. errors.push(
  28537. new SyntaxError(
  28538. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  28539. )
  28540. );
  28541. descriptor.scriptSetup = null;
  28542. }
  28543. if (descriptor.script && descriptor.script.src) {
  28544. errors.push(
  28545. new SyntaxError(
  28546. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  28547. )
  28548. );
  28549. descriptor.script = null;
  28550. }
  28551. }
  28552. let templateColumnOffset = 0;
  28553. if (descriptor.template && (descriptor.template.lang === "pug" || descriptor.template.lang === "jade")) {
  28554. [descriptor.template.content, templateColumnOffset] = dedent(
  28555. descriptor.template.content
  28556. );
  28557. }
  28558. if (sourceMap) {
  28559. const genMap = (block, columnOffset = 0) => {
  28560. if (block && !block.src) {
  28561. block.map = generateSourceMap(
  28562. filename,
  28563. source,
  28564. block.content,
  28565. sourceRoot,
  28566. !pad || block.type === "template" ? block.loc.start.line - 1 : 0,
  28567. columnOffset
  28568. );
  28569. }
  28570. };
  28571. genMap(descriptor.template, templateColumnOffset);
  28572. genMap(descriptor.script);
  28573. descriptor.styles.forEach((s) => genMap(s));
  28574. descriptor.customBlocks.forEach((s) => genMap(s));
  28575. }
  28576. descriptor.cssVars = parseCssVars(descriptor);
  28577. const slottedRE = /(?:::v-|:)slotted\(/;
  28578. descriptor.slotted = descriptor.styles.some(
  28579. (s) => s.scoped && slottedRE.test(s.content)
  28580. );
  28581. const result = {
  28582. descriptor,
  28583. errors
  28584. };
  28585. parseCache$1.set(sourceKey, result);
  28586. return result;
  28587. }
  28588. function createDuplicateBlockError(node, isScriptSetup = false) {
  28589. const err = new SyntaxError(
  28590. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  28591. );
  28592. err.loc = node.loc;
  28593. return err;
  28594. }
  28595. function createBlock(node, source, pad) {
  28596. const type = node.tag;
  28597. const loc = node.innerLoc;
  28598. const attrs = {};
  28599. const block = {
  28600. type,
  28601. content: source.slice(loc.start.offset, loc.end.offset),
  28602. loc,
  28603. attrs
  28604. };
  28605. if (pad) {
  28606. block.content = padContent(source, block, pad) + block.content;
  28607. }
  28608. node.props.forEach((p) => {
  28609. if (p.type === 6) {
  28610. const name = p.name;
  28611. attrs[name] = p.value ? p.value.content || true : true;
  28612. if (name === "lang") {
  28613. block.lang = p.value && p.value.content;
  28614. } else if (name === "src") {
  28615. block.src = p.value && p.value.content;
  28616. } else if (type === "style") {
  28617. if (name === "scoped") {
  28618. block.scoped = true;
  28619. } else if (name === "module") {
  28620. block.module = attrs[name];
  28621. }
  28622. } else if (type === "script" && name === "setup") {
  28623. block.setup = attrs.setup;
  28624. }
  28625. }
  28626. });
  28627. return block;
  28628. }
  28629. const splitRE = /\r?\n/g;
  28630. const emptyRE = /^(?:\/\/)?\s*$/;
  28631. const replaceRE = /./g;
  28632. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset, columnOffset) {
  28633. const map = new sourceMapExports.SourceMapGenerator({
  28634. file: filename.replace(/\\/g, "/"),
  28635. sourceRoot: sourceRoot.replace(/\\/g, "/")
  28636. });
  28637. map.setSourceContent(filename, source);
  28638. map._sources.add(filename);
  28639. generated.split(splitRE).forEach((line, index) => {
  28640. if (!emptyRE.test(line)) {
  28641. const originalLine = index + 1 + lineOffset;
  28642. const generatedLine = index + 1;
  28643. for (let i = 0; i < line.length; i++) {
  28644. if (!/\s/.test(line[i])) {
  28645. map._mappings.add({
  28646. originalLine,
  28647. originalColumn: i + columnOffset,
  28648. generatedLine,
  28649. generatedColumn: i,
  28650. source: filename,
  28651. name: null
  28652. });
  28653. }
  28654. }
  28655. }
  28656. });
  28657. return map.toJSON();
  28658. }
  28659. function padContent(content, block, pad) {
  28660. content = content.slice(0, block.loc.start.offset);
  28661. if (pad === "space") {
  28662. return content.replace(replaceRE, " ");
  28663. } else {
  28664. const offset = content.split(splitRE).length;
  28665. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  28666. return Array(offset).join(padChar);
  28667. }
  28668. }
  28669. function hasSrc(node) {
  28670. return node.props.some((p) => {
  28671. if (p.type !== 6) {
  28672. return false;
  28673. }
  28674. return p.name === "src";
  28675. });
  28676. }
  28677. function isEmpty(node) {
  28678. for (let i = 0; i < node.children.length; i++) {
  28679. const child = node.children[i];
  28680. if (child.type !== 2 || child.content.trim() !== "") {
  28681. return false;
  28682. }
  28683. }
  28684. return true;
  28685. }
  28686. function hmrShouldReload(prevImports, next) {
  28687. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  28688. return false;
  28689. }
  28690. for (const key in prevImports) {
  28691. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  28692. return true;
  28693. }
  28694. }
  28695. return false;
  28696. }
  28697. function dedent(s) {
  28698. const lines = s.split("\n");
  28699. const minIndent = lines.reduce(function(minIndent2, line) {
  28700. var _a, _b;
  28701. if (line.trim() === "") {
  28702. return minIndent2;
  28703. }
  28704. const indent = ((_b = (_a = line.match(/^\s*/)) == null ? void 0 : _a[0]) == null ? void 0 : _b.length) || 0;
  28705. return Math.min(indent, minIndent2);
  28706. }, Infinity);
  28707. if (minIndent === 0) {
  28708. return [s, minIndent];
  28709. }
  28710. return [
  28711. lines.map(function(line) {
  28712. return line.slice(minIndent);
  28713. }).join("\n"),
  28714. minIndent
  28715. ];
  28716. }
  28717. // Copyright Joyent, Inc. and other Node contributors.
  28718. //
  28719. // Permission is hereby granted, free of charge, to any person obtaining a
  28720. // copy of this software and associated documentation files (the
  28721. // "Software"), to deal in the Software without restriction, including
  28722. // without limitation the rights to use, copy, modify, merge, publish,
  28723. // distribute, sublicense, and/or sell copies of the Software, and to permit
  28724. // persons to whom the Software is furnished to do so, subject to the
  28725. // following conditions:
  28726. //
  28727. // The above copyright notice and this permission notice shall be included
  28728. // in all copies or substantial portions of the Software.
  28729. //
  28730. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  28731. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28732. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  28733. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  28734. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  28735. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  28736. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  28737. // resolves . and .. elements in a path array with directory names there
  28738. // must be no slashes, empty elements, or device names (c:\) in the array
  28739. // (so also no leading and trailing slashes - it does not distinguish
  28740. // relative and absolute paths)
  28741. function normalizeArray(parts, allowAboveRoot) {
  28742. // if the path tries to go above the root, `up` ends up > 0
  28743. var up = 0;
  28744. for (var i = parts.length - 1; i >= 0; i--) {
  28745. var last = parts[i];
  28746. if (last === '.') {
  28747. parts.splice(i, 1);
  28748. } else if (last === '..') {
  28749. parts.splice(i, 1);
  28750. up++;
  28751. } else if (up) {
  28752. parts.splice(i, 1);
  28753. up--;
  28754. }
  28755. }
  28756. // if the path is allowed to go above the root, restore leading ..s
  28757. if (allowAboveRoot) {
  28758. for (; up--; up) {
  28759. parts.unshift('..');
  28760. }
  28761. }
  28762. return parts;
  28763. }
  28764. // Split a filename into [root, dir, basename, ext], unix version
  28765. // 'root' is just a slash, or nothing.
  28766. var splitPathRe =
  28767. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  28768. var splitPath = function(filename) {
  28769. return splitPathRe.exec(filename).slice(1);
  28770. };
  28771. // path.resolve([from ...], to)
  28772. // posix version
  28773. function resolve() {
  28774. var resolvedPath = '',
  28775. resolvedAbsolute = false;
  28776. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  28777. var path = (i >= 0) ? arguments[i] : '/';
  28778. // Skip empty and invalid entries
  28779. if (typeof path !== 'string') {
  28780. throw new TypeError('Arguments to path.resolve must be strings');
  28781. } else if (!path) {
  28782. continue;
  28783. }
  28784. resolvedPath = path + '/' + resolvedPath;
  28785. resolvedAbsolute = path.charAt(0) === '/';
  28786. }
  28787. // At this point the path should be resolved to a full absolute path, but
  28788. // handle relative paths to be safe (might happen when process.cwd() fails)
  28789. // Normalize the path
  28790. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  28791. return !!p;
  28792. }), !resolvedAbsolute).join('/');
  28793. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  28794. }
  28795. // path.normalize(path)
  28796. // posix version
  28797. function normalize$1(path) {
  28798. var isPathAbsolute = isAbsolute(path),
  28799. trailingSlash = substr(path, -1) === '/';
  28800. // Normalize the path
  28801. path = normalizeArray(filter(path.split('/'), function(p) {
  28802. return !!p;
  28803. }), !isPathAbsolute).join('/');
  28804. if (!path && !isPathAbsolute) {
  28805. path = '.';
  28806. }
  28807. if (path && trailingSlash) {
  28808. path += '/';
  28809. }
  28810. return (isPathAbsolute ? '/' : '') + path;
  28811. }
  28812. // posix version
  28813. function isAbsolute(path) {
  28814. return path.charAt(0) === '/';
  28815. }
  28816. // posix version
  28817. function join() {
  28818. var paths = Array.prototype.slice.call(arguments, 0);
  28819. return normalize$1(filter(paths, function(p, index) {
  28820. if (typeof p !== 'string') {
  28821. throw new TypeError('Arguments to path.join must be strings');
  28822. }
  28823. return p;
  28824. }).join('/'));
  28825. }
  28826. // path.relative(from, to)
  28827. // posix version
  28828. function relative(from, to) {
  28829. from = resolve(from).substr(1);
  28830. to = resolve(to).substr(1);
  28831. function trim(arr) {
  28832. var start = 0;
  28833. for (; start < arr.length; start++) {
  28834. if (arr[start] !== '') break;
  28835. }
  28836. var end = arr.length - 1;
  28837. for (; end >= 0; end--) {
  28838. if (arr[end] !== '') break;
  28839. }
  28840. if (start > end) return [];
  28841. return arr.slice(start, end - start + 1);
  28842. }
  28843. var fromParts = trim(from.split('/'));
  28844. var toParts = trim(to.split('/'));
  28845. var length = Math.min(fromParts.length, toParts.length);
  28846. var samePartsLength = length;
  28847. for (var i = 0; i < length; i++) {
  28848. if (fromParts[i] !== toParts[i]) {
  28849. samePartsLength = i;
  28850. break;
  28851. }
  28852. }
  28853. var outputParts = [];
  28854. for (var i = samePartsLength; i < fromParts.length; i++) {
  28855. outputParts.push('..');
  28856. }
  28857. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  28858. return outputParts.join('/');
  28859. }
  28860. var sep = '/';
  28861. var delimiter$1 = ':';
  28862. function dirname(path) {
  28863. var result = splitPath(path),
  28864. root = result[0],
  28865. dir = result[1];
  28866. if (!root && !dir) {
  28867. // No dirname whatsoever
  28868. return '.';
  28869. }
  28870. if (dir) {
  28871. // It has a dirname, strip trailing slash
  28872. dir = dir.substr(0, dir.length - 1);
  28873. }
  28874. return root + dir;
  28875. }
  28876. function basename(path, ext) {
  28877. var f = splitPath(path)[2];
  28878. // TODO: make this comparison case-insensitive on windows?
  28879. if (ext && f.substr(-1 * ext.length) === ext) {
  28880. f = f.substr(0, f.length - ext.length);
  28881. }
  28882. return f;
  28883. }
  28884. function extname(path) {
  28885. return splitPath(path)[3];
  28886. }
  28887. var path = {
  28888. extname: extname,
  28889. basename: basename,
  28890. dirname: dirname,
  28891. sep: sep,
  28892. delimiter: delimiter$1,
  28893. relative: relative,
  28894. join: join,
  28895. isAbsolute: isAbsolute,
  28896. normalize: normalize$1,
  28897. resolve: resolve
  28898. };
  28899. function filter (xs, f) {
  28900. if (xs.filter) return xs.filter(f);
  28901. var res = [];
  28902. for (var i = 0; i < xs.length; i++) {
  28903. if (f(xs[i], i, xs)) res.push(xs[i]);
  28904. }
  28905. return res;
  28906. }
  28907. // String.prototype.substr - negative index don't work in IE8
  28908. var substr = 'ab'.substr(-1) === 'b' ?
  28909. function (str, start, len) { return str.substr(start, len) } :
  28910. function (str, start, len) {
  28911. if (start < 0) start = str.length + start;
  28912. return str.substr(start, len);
  28913. }
  28914. ;
  28915. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  28916. __proto__: null,
  28917. basename: basename,
  28918. default: path,
  28919. delimiter: delimiter$1,
  28920. dirname: dirname,
  28921. extname: extname,
  28922. isAbsolute: isAbsolute,
  28923. join: join,
  28924. normalize: normalize$1,
  28925. relative: relative,
  28926. resolve: resolve,
  28927. sep: sep
  28928. });
  28929. /*! https://mths.be/punycode v1.4.1 by @mathias */
  28930. /** Highest positive signed 32-bit float value */
  28931. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  28932. /** Bootstring parameters */
  28933. var base = 36;
  28934. var tMin = 1;
  28935. var tMax = 26;
  28936. var skew = 38;
  28937. var damp = 700;
  28938. var initialBias = 72;
  28939. var initialN = 128; // 0x80
  28940. var delimiter = '-'; // '\x2D'
  28941. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  28942. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  28943. /** Error messages */
  28944. var errors = {
  28945. 'overflow': 'Overflow: input needs wider integers to process',
  28946. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  28947. 'invalid-input': 'Invalid input'
  28948. };
  28949. /** Convenience shortcuts */
  28950. var baseMinusTMin = base - tMin;
  28951. var floor = Math.floor;
  28952. var stringFromCharCode = String.fromCharCode;
  28953. /*--------------------------------------------------------------------------*/
  28954. /**
  28955. * A generic error utility function.
  28956. * @private
  28957. * @param {String} type The error type.
  28958. * @returns {Error} Throws a `RangeError` with the applicable error message.
  28959. */
  28960. function error(type) {
  28961. throw new RangeError(errors[type]);
  28962. }
  28963. /**
  28964. * A generic `Array#map` utility function.
  28965. * @private
  28966. * @param {Array} array The array to iterate over.
  28967. * @param {Function} callback The function that gets called for every array
  28968. * item.
  28969. * @returns {Array} A new array of values returned by the callback function.
  28970. */
  28971. function map$1(array, fn) {
  28972. var length = array.length;
  28973. var result = [];
  28974. while (length--) {
  28975. result[length] = fn(array[length]);
  28976. }
  28977. return result;
  28978. }
  28979. /**
  28980. * A simple `Array#map`-like wrapper to work with domain name strings or email
  28981. * addresses.
  28982. * @private
  28983. * @param {String} domain The domain name or email address.
  28984. * @param {Function} callback The function that gets called for every
  28985. * character.
  28986. * @returns {Array} A new string of characters returned by the callback
  28987. * function.
  28988. */
  28989. function mapDomain(string, fn) {
  28990. var parts = string.split('@');
  28991. var result = '';
  28992. if (parts.length > 1) {
  28993. // In email addresses, only the domain name should be punycoded. Leave
  28994. // the local part (i.e. everything up to `@`) intact.
  28995. result = parts[0] + '@';
  28996. string = parts[1];
  28997. }
  28998. // Avoid `split(regex)` for IE8 compatibility. See #17.
  28999. string = string.replace(regexSeparators, '\x2E');
  29000. var labels = string.split('.');
  29001. var encoded = map$1(labels, fn).join('.');
  29002. return result + encoded;
  29003. }
  29004. /**
  29005. * Creates an array containing the numeric code points of each Unicode
  29006. * character in the string. While JavaScript uses UCS-2 internally,
  29007. * this function will convert a pair of surrogate halves (each of which
  29008. * UCS-2 exposes as separate characters) into a single code point,
  29009. * matching UTF-16.
  29010. * @see `punycode.ucs2.encode`
  29011. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  29012. * @memberOf punycode.ucs2
  29013. * @name decode
  29014. * @param {String} string The Unicode input string (UCS-2).
  29015. * @returns {Array} The new array of code points.
  29016. */
  29017. function ucs2decode(string) {
  29018. var output = [],
  29019. counter = 0,
  29020. length = string.length,
  29021. value,
  29022. extra;
  29023. while (counter < length) {
  29024. value = string.charCodeAt(counter++);
  29025. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  29026. // high surrogate, and there is a next character
  29027. extra = string.charCodeAt(counter++);
  29028. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  29029. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  29030. } else {
  29031. // unmatched surrogate; only append this code unit, in case the next
  29032. // code unit is the high surrogate of a surrogate pair
  29033. output.push(value);
  29034. counter--;
  29035. }
  29036. } else {
  29037. output.push(value);
  29038. }
  29039. }
  29040. return output;
  29041. }
  29042. /**
  29043. * Converts a digit/integer into a basic code point.
  29044. * @see `basicToDigit()`
  29045. * @private
  29046. * @param {Number} digit The numeric value of a basic code point.
  29047. * @returns {Number} The basic code point whose value (when used for
  29048. * representing integers) is `digit`, which needs to be in the range
  29049. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  29050. * used; else, the lowercase form is used. The behavior is undefined
  29051. * if `flag` is non-zero and `digit` has no uppercase form.
  29052. */
  29053. function digitToBasic(digit, flag) {
  29054. // 0..25 map to ASCII a..z or A..Z
  29055. // 26..35 map to ASCII 0..9
  29056. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  29057. }
  29058. /**
  29059. * Bias adaptation function as per section 3.4 of RFC 3492.
  29060. * https://tools.ietf.org/html/rfc3492#section-3.4
  29061. * @private
  29062. */
  29063. function adapt(delta, numPoints, firstTime) {
  29064. var k = 0;
  29065. delta = firstTime ? floor(delta / damp) : delta >> 1;
  29066. delta += floor(delta / numPoints);
  29067. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  29068. delta = floor(delta / baseMinusTMin);
  29069. }
  29070. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  29071. }
  29072. /**
  29073. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  29074. * Punycode string of ASCII-only symbols.
  29075. * @memberOf punycode
  29076. * @param {String} input The string of Unicode symbols.
  29077. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  29078. */
  29079. function encode$1(input) {
  29080. var n,
  29081. delta,
  29082. handledCPCount,
  29083. basicLength,
  29084. bias,
  29085. j,
  29086. m,
  29087. q,
  29088. k,
  29089. t,
  29090. currentValue,
  29091. output = [],
  29092. /** `inputLength` will hold the number of code points in `input`. */
  29093. inputLength,
  29094. /** Cached calculation results */
  29095. handledCPCountPlusOne,
  29096. baseMinusT,
  29097. qMinusT;
  29098. // Convert the input in UCS-2 to Unicode
  29099. input = ucs2decode(input);
  29100. // Cache the length
  29101. inputLength = input.length;
  29102. // Initialize the state
  29103. n = initialN;
  29104. delta = 0;
  29105. bias = initialBias;
  29106. // Handle the basic code points
  29107. for (j = 0; j < inputLength; ++j) {
  29108. currentValue = input[j];
  29109. if (currentValue < 0x80) {
  29110. output.push(stringFromCharCode(currentValue));
  29111. }
  29112. }
  29113. handledCPCount = basicLength = output.length;
  29114. // `handledCPCount` is the number of code points that have been handled;
  29115. // `basicLength` is the number of basic code points.
  29116. // Finish the basic string - if it is not empty - with a delimiter
  29117. if (basicLength) {
  29118. output.push(delimiter);
  29119. }
  29120. // Main encoding loop:
  29121. while (handledCPCount < inputLength) {
  29122. // All non-basic code points < n have been handled already. Find the next
  29123. // larger one:
  29124. for (m = maxInt, j = 0; j < inputLength; ++j) {
  29125. currentValue = input[j];
  29126. if (currentValue >= n && currentValue < m) {
  29127. m = currentValue;
  29128. }
  29129. }
  29130. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  29131. // but guard against overflow
  29132. handledCPCountPlusOne = handledCPCount + 1;
  29133. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  29134. error('overflow');
  29135. }
  29136. delta += (m - n) * handledCPCountPlusOne;
  29137. n = m;
  29138. for (j = 0; j < inputLength; ++j) {
  29139. currentValue = input[j];
  29140. if (currentValue < n && ++delta > maxInt) {
  29141. error('overflow');
  29142. }
  29143. if (currentValue == n) {
  29144. // Represent delta as a generalized variable-length integer
  29145. for (q = delta, k = base; /* no condition */ ; k += base) {
  29146. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  29147. if (q < t) {
  29148. break;
  29149. }
  29150. qMinusT = q - t;
  29151. baseMinusT = base - t;
  29152. output.push(
  29153. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  29154. );
  29155. q = floor(qMinusT / baseMinusT);
  29156. }
  29157. output.push(stringFromCharCode(digitToBasic(q, 0)));
  29158. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  29159. delta = 0;
  29160. ++handledCPCount;
  29161. }
  29162. }
  29163. ++delta;
  29164. ++n;
  29165. }
  29166. return output.join('');
  29167. }
  29168. /**
  29169. * Converts a Unicode string representing a domain name or an email address to
  29170. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  29171. * i.e. it doesn't matter if you call it with a domain that's already in
  29172. * ASCII.
  29173. * @memberOf punycode
  29174. * @param {String} input The domain name or email address to convert, as a
  29175. * Unicode string.
  29176. * @returns {String} The Punycode representation of the given domain name or
  29177. * email address.
  29178. */
  29179. function toASCII(input) {
  29180. return mapDomain(input, function(string) {
  29181. return regexNonASCII.test(string) ?
  29182. 'xn--' + encode$1(string) :
  29183. string;
  29184. });
  29185. }
  29186. var inherits;
  29187. if (typeof Object.create === 'function'){
  29188. inherits = function inherits(ctor, superCtor) {
  29189. // implementation from standard node.js 'util' module
  29190. ctor.super_ = superCtor;
  29191. ctor.prototype = Object.create(superCtor.prototype, {
  29192. constructor: {
  29193. value: ctor,
  29194. enumerable: false,
  29195. writable: true,
  29196. configurable: true
  29197. }
  29198. });
  29199. };
  29200. } else {
  29201. inherits = function inherits(ctor, superCtor) {
  29202. ctor.super_ = superCtor;
  29203. var TempCtor = function () {};
  29204. TempCtor.prototype = superCtor.prototype;
  29205. ctor.prototype = new TempCtor();
  29206. ctor.prototype.constructor = ctor;
  29207. };
  29208. }
  29209. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  29210. function getOwnPropertyDescriptors(obj) {
  29211. var keys = Object.keys(obj);
  29212. var descriptors = {};
  29213. for (var i = 0; i < keys.length; i++) {
  29214. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  29215. }
  29216. return descriptors;
  29217. };
  29218. var formatRegExp = /%[sdj%]/g;
  29219. function format$1(f) {
  29220. if (!isString(f)) {
  29221. var objects = [];
  29222. for (var i = 0; i < arguments.length; i++) {
  29223. objects.push(inspect(arguments[i]));
  29224. }
  29225. return objects.join(' ');
  29226. }
  29227. var i = 1;
  29228. var args = arguments;
  29229. var len = args.length;
  29230. var str = String(f).replace(formatRegExp, function(x) {
  29231. if (x === '%%') return '%';
  29232. if (i >= len) return x;
  29233. switch (x) {
  29234. case '%s': return String(args[i++]);
  29235. case '%d': return Number(args[i++]);
  29236. case '%j':
  29237. try {
  29238. return JSON.stringify(args[i++]);
  29239. } catch (_) {
  29240. return '[Circular]';
  29241. }
  29242. default:
  29243. return x;
  29244. }
  29245. });
  29246. for (var x = args[i]; i < len; x = args[++i]) {
  29247. if (isNull(x) || !isObject$1(x)) {
  29248. str += ' ' + x;
  29249. } else {
  29250. str += ' ' + inspect(x);
  29251. }
  29252. }
  29253. return str;
  29254. }
  29255. // Mark that a method should not be used.
  29256. // Returns a modified function which warns once by default.
  29257. // If --no-deprecation is set, then it is a no-op.
  29258. function deprecate(fn, msg) {
  29259. // Allow for deprecating things in the process of starting up.
  29260. if (isUndefined(global$1.process)) {
  29261. return function() {
  29262. return deprecate(fn, msg).apply(this, arguments);
  29263. };
  29264. }
  29265. if (browser$1.noDeprecation === true) {
  29266. return fn;
  29267. }
  29268. var warned = false;
  29269. function deprecated() {
  29270. if (!warned) {
  29271. if (browser$1.throwDeprecation) {
  29272. throw new Error(msg);
  29273. } else if (browser$1.traceDeprecation) {
  29274. console.trace(msg);
  29275. } else {
  29276. console.error(msg);
  29277. }
  29278. warned = true;
  29279. }
  29280. return fn.apply(this, arguments);
  29281. }
  29282. return deprecated;
  29283. }
  29284. var debugs = {};
  29285. var debugEnviron;
  29286. function debuglog(set) {
  29287. if (isUndefined(debugEnviron))
  29288. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29289. set = set.toUpperCase();
  29290. if (!debugs[set]) {
  29291. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29292. var pid = 0;
  29293. debugs[set] = function() {
  29294. var msg = format$1.apply(null, arguments);
  29295. console.error('%s %d: %s', set, pid, msg);
  29296. };
  29297. } else {
  29298. debugs[set] = function() {};
  29299. }
  29300. }
  29301. return debugs[set];
  29302. }
  29303. /**
  29304. * Echos the value of a value. Trys to print the value out
  29305. * in the best way possible given the different types.
  29306. *
  29307. * @param {Object} obj The object to print out.
  29308. * @param {Object} opts Optional options object that alters the output.
  29309. */
  29310. /* legacy: obj, showHidden, depth, colors*/
  29311. function inspect(obj, opts) {
  29312. // default options
  29313. var ctx = {
  29314. seen: [],
  29315. stylize: stylizeNoColor
  29316. };
  29317. // legacy...
  29318. if (arguments.length >= 3) ctx.depth = arguments[2];
  29319. if (arguments.length >= 4) ctx.colors = arguments[3];
  29320. if (isBoolean(opts)) {
  29321. // legacy...
  29322. ctx.showHidden = opts;
  29323. } else if (opts) {
  29324. // got an "options" object
  29325. _extend(ctx, opts);
  29326. }
  29327. // set default options
  29328. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29329. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29330. if (isUndefined(ctx.colors)) ctx.colors = false;
  29331. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29332. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29333. return formatValue(ctx, obj, ctx.depth);
  29334. }
  29335. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29336. inspect.colors = {
  29337. 'bold' : [1, 22],
  29338. 'italic' : [3, 23],
  29339. 'underline' : [4, 24],
  29340. 'inverse' : [7, 27],
  29341. 'white' : [37, 39],
  29342. 'grey' : [90, 39],
  29343. 'black' : [30, 39],
  29344. 'blue' : [34, 39],
  29345. 'cyan' : [36, 39],
  29346. 'green' : [32, 39],
  29347. 'magenta' : [35, 39],
  29348. 'red' : [31, 39],
  29349. 'yellow' : [33, 39]
  29350. };
  29351. // Don't use 'blue' not visible on cmd.exe
  29352. inspect.styles = {
  29353. 'special': 'cyan',
  29354. 'number': 'yellow',
  29355. 'boolean': 'yellow',
  29356. 'undefined': 'grey',
  29357. 'null': 'bold',
  29358. 'string': 'green',
  29359. 'date': 'magenta',
  29360. // "name": intentionally not styling
  29361. 'regexp': 'red'
  29362. };
  29363. function stylizeWithColor(str, styleType) {
  29364. var style = inspect.styles[styleType];
  29365. if (style) {
  29366. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29367. '\u001b[' + inspect.colors[style][1] + 'm';
  29368. } else {
  29369. return str;
  29370. }
  29371. }
  29372. function stylizeNoColor(str, styleType) {
  29373. return str;
  29374. }
  29375. function arrayToHash(array) {
  29376. var hash = {};
  29377. array.forEach(function(val, idx) {
  29378. hash[val] = true;
  29379. });
  29380. return hash;
  29381. }
  29382. function formatValue(ctx, value, recurseTimes) {
  29383. // Provide a hook for user-specified inspect functions.
  29384. // Check that value is an object with an inspect function on it
  29385. if (ctx.customInspect &&
  29386. value &&
  29387. isFunction(value.inspect) &&
  29388. // Filter out the util module, it's inspect function is special
  29389. value.inspect !== inspect &&
  29390. // Also filter out any prototype objects using the circular check.
  29391. !(value.constructor && value.constructor.prototype === value)) {
  29392. var ret = value.inspect(recurseTimes, ctx);
  29393. if (!isString(ret)) {
  29394. ret = formatValue(ctx, ret, recurseTimes);
  29395. }
  29396. return ret;
  29397. }
  29398. // Primitive types cannot have properties
  29399. var primitive = formatPrimitive(ctx, value);
  29400. if (primitive) {
  29401. return primitive;
  29402. }
  29403. // Look up the keys of the object.
  29404. var keys = Object.keys(value);
  29405. var visibleKeys = arrayToHash(keys);
  29406. if (ctx.showHidden) {
  29407. keys = Object.getOwnPropertyNames(value);
  29408. }
  29409. // IE doesn't make error fields non-enumerable
  29410. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29411. if (isError(value)
  29412. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29413. return formatError(value);
  29414. }
  29415. // Some type of object without properties can be shortcutted.
  29416. if (keys.length === 0) {
  29417. if (isFunction(value)) {
  29418. var name = value.name ? ': ' + value.name : '';
  29419. return ctx.stylize('[Function' + name + ']', 'special');
  29420. }
  29421. if (isRegExp(value)) {
  29422. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29423. }
  29424. if (isDate(value)) {
  29425. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29426. }
  29427. if (isError(value)) {
  29428. return formatError(value);
  29429. }
  29430. }
  29431. var base = '', array = false, braces = ['{', '}'];
  29432. // Make Array say that they are Array
  29433. if (isArray$1(value)) {
  29434. array = true;
  29435. braces = ['[', ']'];
  29436. }
  29437. // Make functions say that they are functions
  29438. if (isFunction(value)) {
  29439. var n = value.name ? ': ' + value.name : '';
  29440. base = ' [Function' + n + ']';
  29441. }
  29442. // Make RegExps say that they are RegExps
  29443. if (isRegExp(value)) {
  29444. base = ' ' + RegExp.prototype.toString.call(value);
  29445. }
  29446. // Make dates with properties first say the date
  29447. if (isDate(value)) {
  29448. base = ' ' + Date.prototype.toUTCString.call(value);
  29449. }
  29450. // Make error with message first say the error
  29451. if (isError(value)) {
  29452. base = ' ' + formatError(value);
  29453. }
  29454. if (keys.length === 0 && (!array || value.length == 0)) {
  29455. return braces[0] + base + braces[1];
  29456. }
  29457. if (recurseTimes < 0) {
  29458. if (isRegExp(value)) {
  29459. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29460. } else {
  29461. return ctx.stylize('[Object]', 'special');
  29462. }
  29463. }
  29464. ctx.seen.push(value);
  29465. var output;
  29466. if (array) {
  29467. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29468. } else {
  29469. output = keys.map(function(key) {
  29470. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29471. });
  29472. }
  29473. ctx.seen.pop();
  29474. return reduceToSingleString(output, base, braces);
  29475. }
  29476. function formatPrimitive(ctx, value) {
  29477. if (isUndefined(value))
  29478. return ctx.stylize('undefined', 'undefined');
  29479. if (isString(value)) {
  29480. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29481. .replace(/'/g, "\\'")
  29482. .replace(/\\"/g, '"') + '\'';
  29483. return ctx.stylize(simple, 'string');
  29484. }
  29485. if (isNumber(value))
  29486. return ctx.stylize('' + value, 'number');
  29487. if (isBoolean(value))
  29488. return ctx.stylize('' + value, 'boolean');
  29489. // For some reason typeof null is "object", so special case here.
  29490. if (isNull(value))
  29491. return ctx.stylize('null', 'null');
  29492. }
  29493. function formatError(value) {
  29494. return '[' + Error.prototype.toString.call(value) + ']';
  29495. }
  29496. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29497. var output = [];
  29498. for (var i = 0, l = value.length; i < l; ++i) {
  29499. if (hasOwnProperty$2(value, String(i))) {
  29500. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29501. String(i), true));
  29502. } else {
  29503. output.push('');
  29504. }
  29505. }
  29506. keys.forEach(function(key) {
  29507. if (!key.match(/^\d+$/)) {
  29508. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29509. key, true));
  29510. }
  29511. });
  29512. return output;
  29513. }
  29514. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29515. var name, str, desc;
  29516. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29517. if (desc.get) {
  29518. if (desc.set) {
  29519. str = ctx.stylize('[Getter/Setter]', 'special');
  29520. } else {
  29521. str = ctx.stylize('[Getter]', 'special');
  29522. }
  29523. } else {
  29524. if (desc.set) {
  29525. str = ctx.stylize('[Setter]', 'special');
  29526. }
  29527. }
  29528. if (!hasOwnProperty$2(visibleKeys, key)) {
  29529. name = '[' + key + ']';
  29530. }
  29531. if (!str) {
  29532. if (ctx.seen.indexOf(desc.value) < 0) {
  29533. if (isNull(recurseTimes)) {
  29534. str = formatValue(ctx, desc.value, null);
  29535. } else {
  29536. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29537. }
  29538. if (str.indexOf('\n') > -1) {
  29539. if (array) {
  29540. str = str.split('\n').map(function(line) {
  29541. return ' ' + line;
  29542. }).join('\n').substr(2);
  29543. } else {
  29544. str = '\n' + str.split('\n').map(function(line) {
  29545. return ' ' + line;
  29546. }).join('\n');
  29547. }
  29548. }
  29549. } else {
  29550. str = ctx.stylize('[Circular]', 'special');
  29551. }
  29552. }
  29553. if (isUndefined(name)) {
  29554. if (array && key.match(/^\d+$/)) {
  29555. return str;
  29556. }
  29557. name = JSON.stringify('' + key);
  29558. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29559. name = name.substr(1, name.length - 2);
  29560. name = ctx.stylize(name, 'name');
  29561. } else {
  29562. name = name.replace(/'/g, "\\'")
  29563. .replace(/\\"/g, '"')
  29564. .replace(/(^"|"$)/g, "'");
  29565. name = ctx.stylize(name, 'string');
  29566. }
  29567. }
  29568. return name + ': ' + str;
  29569. }
  29570. function reduceToSingleString(output, base, braces) {
  29571. var length = output.reduce(function(prev, cur) {
  29572. if (cur.indexOf('\n') >= 0) ;
  29573. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29574. }, 0);
  29575. if (length > 60) {
  29576. return braces[0] +
  29577. (base === '' ? '' : base + '\n ') +
  29578. ' ' +
  29579. output.join(',\n ') +
  29580. ' ' +
  29581. braces[1];
  29582. }
  29583. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29584. }
  29585. // NOTE: These type checking functions intentionally don't use `instanceof`
  29586. // because it is fragile and can be easily faked with `Object.create()`.
  29587. function isArray$1(ar) {
  29588. return Array.isArray(ar);
  29589. }
  29590. function isBoolean(arg) {
  29591. return typeof arg === 'boolean';
  29592. }
  29593. function isNull(arg) {
  29594. return arg === null;
  29595. }
  29596. function isNullOrUndefined(arg) {
  29597. return arg == null;
  29598. }
  29599. function isNumber(arg) {
  29600. return typeof arg === 'number';
  29601. }
  29602. function isString(arg) {
  29603. return typeof arg === 'string';
  29604. }
  29605. function isSymbol(arg) {
  29606. return typeof arg === 'symbol';
  29607. }
  29608. function isUndefined(arg) {
  29609. return arg === void 0;
  29610. }
  29611. function isRegExp(re) {
  29612. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29613. }
  29614. function isObject$1(arg) {
  29615. return typeof arg === 'object' && arg !== null;
  29616. }
  29617. function isDate(d) {
  29618. return isObject$1(d) && objectToString(d) === '[object Date]';
  29619. }
  29620. function isError(e) {
  29621. return isObject$1(e) &&
  29622. (objectToString(e) === '[object Error]' || e instanceof Error);
  29623. }
  29624. function isFunction(arg) {
  29625. return typeof arg === 'function';
  29626. }
  29627. function isPrimitive(arg) {
  29628. return arg === null ||
  29629. typeof arg === 'boolean' ||
  29630. typeof arg === 'number' ||
  29631. typeof arg === 'string' ||
  29632. typeof arg === 'symbol' || // ES6 symbol
  29633. typeof arg === 'undefined';
  29634. }
  29635. function isBuffer(maybeBuf) {
  29636. return Buffer$1.isBuffer(maybeBuf);
  29637. }
  29638. function objectToString(o) {
  29639. return Object.prototype.toString.call(o);
  29640. }
  29641. function pad(n) {
  29642. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29643. }
  29644. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29645. 'Oct', 'Nov', 'Dec'];
  29646. // 26 Feb 16:19:34
  29647. function timestamp() {
  29648. var d = new Date();
  29649. var time = [pad(d.getHours()),
  29650. pad(d.getMinutes()),
  29651. pad(d.getSeconds())].join(':');
  29652. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29653. }
  29654. // log is just a thin wrapper to console.log that prepends a timestamp
  29655. function log() {
  29656. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29657. }
  29658. function _extend(origin, add) {
  29659. // Don't do anything if add isn't an object
  29660. if (!add || !isObject$1(add)) return origin;
  29661. var keys = Object.keys(add);
  29662. var i = keys.length;
  29663. while (i--) {
  29664. origin[keys[i]] = add[keys[i]];
  29665. }
  29666. return origin;
  29667. }
  29668. function hasOwnProperty$2(obj, prop) {
  29669. return Object.prototype.hasOwnProperty.call(obj, prop);
  29670. }
  29671. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29672. function promisify(original) {
  29673. if (typeof original !== 'function')
  29674. throw new TypeError('The "original" argument must be of type Function');
  29675. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29676. var fn = original[kCustomPromisifiedSymbol];
  29677. if (typeof fn !== 'function') {
  29678. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29679. }
  29680. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29681. value: fn, enumerable: false, writable: false, configurable: true
  29682. });
  29683. return fn;
  29684. }
  29685. function fn() {
  29686. var promiseResolve, promiseReject;
  29687. var promise = new Promise(function (resolve, reject) {
  29688. promiseResolve = resolve;
  29689. promiseReject = reject;
  29690. });
  29691. var args = [];
  29692. for (var i = 0; i < arguments.length; i++) {
  29693. args.push(arguments[i]);
  29694. }
  29695. args.push(function (err, value) {
  29696. if (err) {
  29697. promiseReject(err);
  29698. } else {
  29699. promiseResolve(value);
  29700. }
  29701. });
  29702. try {
  29703. original.apply(this, args);
  29704. } catch (err) {
  29705. promiseReject(err);
  29706. }
  29707. return promise;
  29708. }
  29709. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29710. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29711. value: fn, enumerable: false, writable: false, configurable: true
  29712. });
  29713. return Object.defineProperties(
  29714. fn,
  29715. getOwnPropertyDescriptors(original)
  29716. );
  29717. }
  29718. promisify.custom = kCustomPromisifiedSymbol;
  29719. function callbackifyOnRejected(reason, cb) {
  29720. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29721. // Because `null` is a special error value in callbacks which means "no error
  29722. // occurred", we error-wrap so the callback consumer can distinguish between
  29723. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29724. if (!reason) {
  29725. var newReason = new Error('Promise was rejected with a falsy value');
  29726. newReason.reason = reason;
  29727. reason = newReason;
  29728. }
  29729. return cb(reason);
  29730. }
  29731. function callbackify(original) {
  29732. if (typeof original !== 'function') {
  29733. throw new TypeError('The "original" argument must be of type Function');
  29734. }
  29735. // We DO NOT return the promise as it gives the user a false sense that
  29736. // the promise is actually somehow related to the callback's execution
  29737. // and that the callback throwing will reject the promise.
  29738. function callbackified() {
  29739. var args = [];
  29740. for (var i = 0; i < arguments.length; i++) {
  29741. args.push(arguments[i]);
  29742. }
  29743. var maybeCb = args.pop();
  29744. if (typeof maybeCb !== 'function') {
  29745. throw new TypeError('The last argument must be of type Function');
  29746. }
  29747. var self = this;
  29748. var cb = function() {
  29749. return maybeCb.apply(self, arguments);
  29750. };
  29751. // In true node style we process the callback on `nextTick` with all the
  29752. // implications (stack, `uncaughtException`, `async_hooks`)
  29753. original.apply(this, args)
  29754. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29755. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29756. }
  29757. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29758. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29759. return callbackified;
  29760. }
  29761. var _polyfillNode_util = {
  29762. inherits: inherits,
  29763. _extend: _extend,
  29764. log: log,
  29765. isBuffer: isBuffer,
  29766. isPrimitive: isPrimitive,
  29767. isFunction: isFunction,
  29768. isError: isError,
  29769. isDate: isDate,
  29770. isObject: isObject$1,
  29771. isRegExp: isRegExp,
  29772. isUndefined: isUndefined,
  29773. isSymbol: isSymbol,
  29774. isString: isString,
  29775. isNumber: isNumber,
  29776. isNullOrUndefined: isNullOrUndefined,
  29777. isNull: isNull,
  29778. isBoolean: isBoolean,
  29779. isArray: isArray$1,
  29780. inspect: inspect,
  29781. deprecate: deprecate,
  29782. format: format$1,
  29783. debuglog: debuglog,
  29784. promisify: promisify,
  29785. callbackify: callbackify,
  29786. };
  29787. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29788. __proto__: null,
  29789. _extend: _extend,
  29790. callbackify: callbackify,
  29791. debuglog: debuglog,
  29792. default: _polyfillNode_util,
  29793. deprecate: deprecate,
  29794. format: format$1,
  29795. inherits: inherits,
  29796. inspect: inspect,
  29797. isArray: isArray$1,
  29798. isBoolean: isBoolean,
  29799. isBuffer: isBuffer,
  29800. isDate: isDate,
  29801. isError: isError,
  29802. isFunction: isFunction,
  29803. isNull: isNull,
  29804. isNullOrUndefined: isNullOrUndefined,
  29805. isNumber: isNumber,
  29806. isObject: isObject$1,
  29807. isPrimitive: isPrimitive,
  29808. isRegExp: isRegExp,
  29809. isString: isString,
  29810. isSymbol: isSymbol,
  29811. isUndefined: isUndefined,
  29812. log: log,
  29813. promisify: promisify
  29814. });
  29815. // Copyright Joyent, Inc. and other Node contributors.
  29816. //
  29817. // Permission is hereby granted, free of charge, to any person obtaining a
  29818. // copy of this software and associated documentation files (the
  29819. // "Software"), to deal in the Software without restriction, including
  29820. // without limitation the rights to use, copy, modify, merge, publish,
  29821. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29822. // persons to whom the Software is furnished to do so, subject to the
  29823. // following conditions:
  29824. //
  29825. // The above copyright notice and this permission notice shall be included
  29826. // in all copies or substantial portions of the Software.
  29827. //
  29828. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29829. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29830. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29831. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29832. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29833. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29834. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29835. // If obj.hasOwnProperty has been overridden, then calling
  29836. // obj.hasOwnProperty(prop) will break.
  29837. // See: https://github.com/joyent/node/issues/1707
  29838. function hasOwnProperty$1(obj, prop) {
  29839. return Object.prototype.hasOwnProperty.call(obj, prop);
  29840. }
  29841. var isArray = Array.isArray || function (xs) {
  29842. return Object.prototype.toString.call(xs) === '[object Array]';
  29843. };
  29844. function stringifyPrimitive(v) {
  29845. switch (typeof v) {
  29846. case 'string':
  29847. return v;
  29848. case 'boolean':
  29849. return v ? 'true' : 'false';
  29850. case 'number':
  29851. return isFinite(v) ? v : '';
  29852. default:
  29853. return '';
  29854. }
  29855. }
  29856. function stringify (obj, sep, eq, name) {
  29857. sep = sep || '&';
  29858. eq = eq || '=';
  29859. if (obj === null) {
  29860. obj = undefined;
  29861. }
  29862. if (typeof obj === 'object') {
  29863. return map(objectKeys(obj), function(k) {
  29864. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29865. if (isArray(obj[k])) {
  29866. return map(obj[k], function(v) {
  29867. return ks + encodeURIComponent(stringifyPrimitive(v));
  29868. }).join(sep);
  29869. } else {
  29870. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29871. }
  29872. }).join(sep);
  29873. }
  29874. if (!name) return '';
  29875. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29876. encodeURIComponent(stringifyPrimitive(obj));
  29877. }
  29878. function map (xs, f) {
  29879. if (xs.map) return xs.map(f);
  29880. var res = [];
  29881. for (var i = 0; i < xs.length; i++) {
  29882. res.push(f(xs[i], i));
  29883. }
  29884. return res;
  29885. }
  29886. var objectKeys = Object.keys || function (obj) {
  29887. var res = [];
  29888. for (var key in obj) {
  29889. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29890. }
  29891. return res;
  29892. };
  29893. function parse$1(qs, sep, eq, options) {
  29894. sep = sep || '&';
  29895. eq = eq || '=';
  29896. var obj = {};
  29897. if (typeof qs !== 'string' || qs.length === 0) {
  29898. return obj;
  29899. }
  29900. var regexp = /\+/g;
  29901. qs = qs.split(sep);
  29902. var maxKeys = 1000;
  29903. if (options && typeof options.maxKeys === 'number') {
  29904. maxKeys = options.maxKeys;
  29905. }
  29906. var len = qs.length;
  29907. // maxKeys <= 0 means that we should not limit keys count
  29908. if (maxKeys > 0 && len > maxKeys) {
  29909. len = maxKeys;
  29910. }
  29911. for (var i = 0; i < len; ++i) {
  29912. var x = qs[i].replace(regexp, '%20'),
  29913. idx = x.indexOf(eq),
  29914. kstr, vstr, k, v;
  29915. if (idx >= 0) {
  29916. kstr = x.substr(0, idx);
  29917. vstr = x.substr(idx + 1);
  29918. } else {
  29919. kstr = x;
  29920. vstr = '';
  29921. }
  29922. k = decodeURIComponent(kstr);
  29923. v = decodeURIComponent(vstr);
  29924. if (!hasOwnProperty$1(obj, k)) {
  29925. obj[k] = v;
  29926. } else if (isArray(obj[k])) {
  29927. obj[k].push(v);
  29928. } else {
  29929. obj[k] = [obj[k], v];
  29930. }
  29931. }
  29932. return obj;
  29933. }
  29934. // WHATWG API
  29935. const URL$1 = global$1.URL;
  29936. const URLSearchParams = global$1.URLSearchParams;
  29937. var _polyfillNode_url = {
  29938. parse: urlParse,
  29939. resolve: urlResolve,
  29940. resolveObject: urlResolveObject,
  29941. fileURLToPath: urlFileURLToPath,
  29942. format: urlFormat,
  29943. Url: Url,
  29944. // WHATWG API
  29945. URL: URL$1,
  29946. URLSearchParams,
  29947. };
  29948. function Url() {
  29949. this.protocol = null;
  29950. this.slashes = null;
  29951. this.auth = null;
  29952. this.host = null;
  29953. this.port = null;
  29954. this.hostname = null;
  29955. this.hash = null;
  29956. this.search = null;
  29957. this.query = null;
  29958. this.pathname = null;
  29959. this.path = null;
  29960. this.href = null;
  29961. }
  29962. // Reference: RFC 3986, RFC 1808, RFC 2396
  29963. // define these here so at least they only have to be
  29964. // compiled once on the first module load.
  29965. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  29966. portPattern = /:[0-9]*$/,
  29967. // Special case for a simple path URL
  29968. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  29969. // RFC 2396: characters reserved for delimiting URLs.
  29970. // We actually just auto-escape these.
  29971. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  29972. // RFC 2396: characters not allowed for various reasons.
  29973. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  29974. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  29975. autoEscape = ['\''].concat(unwise),
  29976. // Characters that are never ever allowed in a hostname.
  29977. // Note that any invalid chars are also handled, but these
  29978. // are the ones that are *expected* to be seen, so we fast-path
  29979. // them.
  29980. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  29981. hostEndingChars = ['/', '?', '#'],
  29982. hostnameMaxLen = 255,
  29983. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  29984. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  29985. // protocols that can allow "unsafe" and "unwise" chars.
  29986. unsafeProtocol = {
  29987. 'javascript': true,
  29988. 'javascript:': true
  29989. },
  29990. // protocols that never have a hostname.
  29991. hostlessProtocol = {
  29992. 'javascript': true,
  29993. 'javascript:': true
  29994. },
  29995. // protocols that always contain a // bit.
  29996. slashedProtocol = {
  29997. 'http': true,
  29998. 'https': true,
  29999. 'ftp': true,
  30000. 'gopher': true,
  30001. 'file': true,
  30002. 'http:': true,
  30003. 'https:': true,
  30004. 'ftp:': true,
  30005. 'gopher:': true,
  30006. 'file:': true
  30007. };
  30008. function urlParse(url, parseQueryString, slashesDenoteHost) {
  30009. if (url && isObject$1(url) && url instanceof Url) return url;
  30010. var u = new Url;
  30011. u.parse(url, parseQueryString, slashesDenoteHost);
  30012. return u;
  30013. }
  30014. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  30015. return parse(this, url, parseQueryString, slashesDenoteHost);
  30016. };
  30017. function parse(self, url, parseQueryString, slashesDenoteHost) {
  30018. if (!isString(url)) {
  30019. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  30020. }
  30021. // Copy chrome, IE, opera backslash-handling behavior.
  30022. // Back slashes before the query string get converted to forward slashes
  30023. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  30024. var queryIndex = url.indexOf('?'),
  30025. splitter =
  30026. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  30027. uSplit = url.split(splitter),
  30028. slashRegex = /\\/g;
  30029. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  30030. url = uSplit.join(splitter);
  30031. var rest = url;
  30032. // trim before proceeding.
  30033. // This is to support parse stuff like " http://foo.com \n"
  30034. rest = rest.trim();
  30035. if (!slashesDenoteHost && url.split('#').length === 1) {
  30036. // Try fast path regexp
  30037. var simplePath = simplePathPattern.exec(rest);
  30038. if (simplePath) {
  30039. self.path = rest;
  30040. self.href = rest;
  30041. self.pathname = simplePath[1];
  30042. if (simplePath[2]) {
  30043. self.search = simplePath[2];
  30044. if (parseQueryString) {
  30045. self.query = parse$1(self.search.substr(1));
  30046. } else {
  30047. self.query = self.search.substr(1);
  30048. }
  30049. } else if (parseQueryString) {
  30050. self.search = '';
  30051. self.query = {};
  30052. }
  30053. return self;
  30054. }
  30055. }
  30056. var proto = protocolPattern.exec(rest);
  30057. if (proto) {
  30058. proto = proto[0];
  30059. var lowerProto = proto.toLowerCase();
  30060. self.protocol = lowerProto;
  30061. rest = rest.substr(proto.length);
  30062. }
  30063. // figure out if it's got a host
  30064. // user@server is *always* interpreted as a hostname, and url
  30065. // resolution will treat //foo/bar as host=foo,path=bar because that's
  30066. // how the browser resolves relative URLs.
  30067. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  30068. var slashes = rest.substr(0, 2) === '//';
  30069. if (slashes && !(proto && hostlessProtocol[proto])) {
  30070. rest = rest.substr(2);
  30071. self.slashes = true;
  30072. }
  30073. }
  30074. var i, hec, l, p;
  30075. if (!hostlessProtocol[proto] &&
  30076. (slashes || (proto && !slashedProtocol[proto]))) {
  30077. // there's a hostname.
  30078. // the first instance of /, ?, ;, or # ends the host.
  30079. //
  30080. // If there is an @ in the hostname, then non-host chars *are* allowed
  30081. // to the left of the last @ sign, unless some host-ending character
  30082. // comes *before* the @-sign.
  30083. // URLs are obnoxious.
  30084. //
  30085. // ex:
  30086. // http://a@b@c/ => user:a@b host:c
  30087. // http://a@b?@c => user:a host:c path:/?@c
  30088. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  30089. // Review our test case against browsers more comprehensively.
  30090. // find the first instance of any hostEndingChars
  30091. var hostEnd = -1;
  30092. for (i = 0; i < hostEndingChars.length; i++) {
  30093. hec = rest.indexOf(hostEndingChars[i]);
  30094. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30095. hostEnd = hec;
  30096. }
  30097. // at this point, either we have an explicit point where the
  30098. // auth portion cannot go past, or the last @ char is the decider.
  30099. var auth, atSign;
  30100. if (hostEnd === -1) {
  30101. // atSign can be anywhere.
  30102. atSign = rest.lastIndexOf('@');
  30103. } else {
  30104. // atSign must be in auth portion.
  30105. // http://a@b/c@d => host:b auth:a path:/c@d
  30106. atSign = rest.lastIndexOf('@', hostEnd);
  30107. }
  30108. // Now we have a portion which is definitely the auth.
  30109. // Pull that off.
  30110. if (atSign !== -1) {
  30111. auth = rest.slice(0, atSign);
  30112. rest = rest.slice(atSign + 1);
  30113. self.auth = decodeURIComponent(auth);
  30114. }
  30115. // the host is the remaining to the left of the first non-host char
  30116. hostEnd = -1;
  30117. for (i = 0; i < nonHostChars.length; i++) {
  30118. hec = rest.indexOf(nonHostChars[i]);
  30119. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  30120. hostEnd = hec;
  30121. }
  30122. // if we still have not hit it, then the entire thing is a host.
  30123. if (hostEnd === -1)
  30124. hostEnd = rest.length;
  30125. self.host = rest.slice(0, hostEnd);
  30126. rest = rest.slice(hostEnd);
  30127. // pull out port.
  30128. parseHost(self);
  30129. // we've indicated that there is a hostname,
  30130. // so even if it's empty, it has to be present.
  30131. self.hostname = self.hostname || '';
  30132. // if hostname begins with [ and ends with ]
  30133. // assume that it's an IPv6 address.
  30134. var ipv6Hostname = self.hostname[0] === '[' &&
  30135. self.hostname[self.hostname.length - 1] === ']';
  30136. // validate a little.
  30137. if (!ipv6Hostname) {
  30138. var hostparts = self.hostname.split(/\./);
  30139. for (i = 0, l = hostparts.length; i < l; i++) {
  30140. var part = hostparts[i];
  30141. if (!part) continue;
  30142. if (!part.match(hostnamePartPattern)) {
  30143. var newpart = '';
  30144. for (var j = 0, k = part.length; j < k; j++) {
  30145. if (part.charCodeAt(j) > 127) {
  30146. // we replace non-ASCII char with a temporary placeholder
  30147. // we need this to make sure size of hostname is not
  30148. // broken by replacing non-ASCII by nothing
  30149. newpart += 'x';
  30150. } else {
  30151. newpart += part[j];
  30152. }
  30153. }
  30154. // we test again with ASCII char only
  30155. if (!newpart.match(hostnamePartPattern)) {
  30156. var validParts = hostparts.slice(0, i);
  30157. var notHost = hostparts.slice(i + 1);
  30158. var bit = part.match(hostnamePartStart);
  30159. if (bit) {
  30160. validParts.push(bit[1]);
  30161. notHost.unshift(bit[2]);
  30162. }
  30163. if (notHost.length) {
  30164. rest = '/' + notHost.join('.') + rest;
  30165. }
  30166. self.hostname = validParts.join('.');
  30167. break;
  30168. }
  30169. }
  30170. }
  30171. }
  30172. if (self.hostname.length > hostnameMaxLen) {
  30173. self.hostname = '';
  30174. } else {
  30175. // hostnames are always lower case.
  30176. self.hostname = self.hostname.toLowerCase();
  30177. }
  30178. if (!ipv6Hostname) {
  30179. // IDNA Support: Returns a punycoded representation of "domain".
  30180. // It only converts parts of the domain name that
  30181. // have non-ASCII characters, i.e. it doesn't matter if
  30182. // you call it with a domain that already is ASCII-only.
  30183. self.hostname = toASCII(self.hostname);
  30184. }
  30185. p = self.port ? ':' + self.port : '';
  30186. var h = self.hostname || '';
  30187. self.host = h + p;
  30188. self.href += self.host;
  30189. // strip [ and ] from the hostname
  30190. // the host field still retains them, though
  30191. if (ipv6Hostname) {
  30192. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  30193. if (rest[0] !== '/') {
  30194. rest = '/' + rest;
  30195. }
  30196. }
  30197. }
  30198. // now rest is set to the post-host stuff.
  30199. // chop off any delim chars.
  30200. if (!unsafeProtocol[lowerProto]) {
  30201. // First, make 100% sure that any "autoEscape" chars get
  30202. // escaped, even if encodeURIComponent doesn't think they
  30203. // need to be.
  30204. for (i = 0, l = autoEscape.length; i < l; i++) {
  30205. var ae = autoEscape[i];
  30206. if (rest.indexOf(ae) === -1)
  30207. continue;
  30208. var esc = encodeURIComponent(ae);
  30209. if (esc === ae) {
  30210. esc = escape(ae);
  30211. }
  30212. rest = rest.split(ae).join(esc);
  30213. }
  30214. }
  30215. // chop off from the tail first.
  30216. var hash = rest.indexOf('#');
  30217. if (hash !== -1) {
  30218. // got a fragment string.
  30219. self.hash = rest.substr(hash);
  30220. rest = rest.slice(0, hash);
  30221. }
  30222. var qm = rest.indexOf('?');
  30223. if (qm !== -1) {
  30224. self.search = rest.substr(qm);
  30225. self.query = rest.substr(qm + 1);
  30226. if (parseQueryString) {
  30227. self.query = parse$1(self.query);
  30228. }
  30229. rest = rest.slice(0, qm);
  30230. } else if (parseQueryString) {
  30231. // no query string, but parseQueryString still requested
  30232. self.search = '';
  30233. self.query = {};
  30234. }
  30235. if (rest) self.pathname = rest;
  30236. if (slashedProtocol[lowerProto] &&
  30237. self.hostname && !self.pathname) {
  30238. self.pathname = '/';
  30239. }
  30240. //to support http.request
  30241. if (self.pathname || self.search) {
  30242. p = self.pathname || '';
  30243. var s = self.search || '';
  30244. self.path = p + s;
  30245. }
  30246. // finally, reconstruct the href based on what has been validated.
  30247. self.href = format(self);
  30248. return self;
  30249. }
  30250. function urlFileURLToPath(path) {
  30251. if (typeof path === 'string')
  30252. path = new Url().parse(path);
  30253. else if (!(path instanceof Url))
  30254. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  30255. if (path.protocol !== 'file:')
  30256. throw new TypeError('The URL must be of scheme file');
  30257. return getPathFromURLPosix(path);
  30258. }
  30259. function getPathFromURLPosix(url) {
  30260. const pathname = url.pathname;
  30261. for (let n = 0; n < pathname.length; n++) {
  30262. if (pathname[n] === '%') {
  30263. const third = pathname.codePointAt(n + 2) | 0x20;
  30264. if (pathname[n + 1] === '2' && third === 102) {
  30265. throw new TypeError(
  30266. 'must not include encoded / characters'
  30267. );
  30268. }
  30269. }
  30270. }
  30271. return decodeURIComponent(pathname);
  30272. }
  30273. // format a parsed object into a url string
  30274. function urlFormat(obj) {
  30275. // ensure it's an object, and not a string url.
  30276. // If it's an obj, this is a no-op.
  30277. // this way, you can call url_format() on strings
  30278. // to clean up potentially wonky urls.
  30279. if (isString(obj)) obj = parse({}, obj);
  30280. return format(obj);
  30281. }
  30282. function format(self) {
  30283. var auth = self.auth || '';
  30284. if (auth) {
  30285. auth = encodeURIComponent(auth);
  30286. auth = auth.replace(/%3A/i, ':');
  30287. auth += '@';
  30288. }
  30289. var protocol = self.protocol || '',
  30290. pathname = self.pathname || '',
  30291. hash = self.hash || '',
  30292. host = false,
  30293. query = '';
  30294. if (self.host) {
  30295. host = auth + self.host;
  30296. } else if (self.hostname) {
  30297. host = auth + (self.hostname.indexOf(':') === -1 ?
  30298. self.hostname :
  30299. '[' + this.hostname + ']');
  30300. if (self.port) {
  30301. host += ':' + self.port;
  30302. }
  30303. }
  30304. if (self.query &&
  30305. isObject$1(self.query) &&
  30306. Object.keys(self.query).length) {
  30307. query = stringify(self.query);
  30308. }
  30309. var search = self.search || (query && ('?' + query)) || '';
  30310. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30311. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30312. // unless they had them to begin with.
  30313. if (self.slashes ||
  30314. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30315. host = '//' + (host || '');
  30316. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30317. } else if (!host) {
  30318. host = '';
  30319. }
  30320. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30321. if (search && search.charAt(0) !== '?') search = '?' + search;
  30322. pathname = pathname.replace(/[?#]/g, function(match) {
  30323. return encodeURIComponent(match);
  30324. });
  30325. search = search.replace('#', '%23');
  30326. return protocol + host + pathname + search + hash;
  30327. }
  30328. Url.prototype.format = function() {
  30329. return format(this);
  30330. };
  30331. function urlResolve(source, relative) {
  30332. return urlParse(source, false, true).resolve(relative);
  30333. }
  30334. Url.prototype.resolve = function(relative) {
  30335. return this.resolveObject(urlParse(relative, false, true)).format();
  30336. };
  30337. function urlResolveObject(source, relative) {
  30338. if (!source) return relative;
  30339. return urlParse(source, false, true).resolveObject(relative);
  30340. }
  30341. Url.prototype.resolveObject = function(relative) {
  30342. if (isString(relative)) {
  30343. var rel = new Url();
  30344. rel.parse(relative, false, true);
  30345. relative = rel;
  30346. }
  30347. var result = new Url();
  30348. var tkeys = Object.keys(this);
  30349. for (var tk = 0; tk < tkeys.length; tk++) {
  30350. var tkey = tkeys[tk];
  30351. result[tkey] = this[tkey];
  30352. }
  30353. // hash is always overridden, no matter what.
  30354. // even href="" will remove it.
  30355. result.hash = relative.hash;
  30356. // if the relative url is empty, then there's nothing left to do here.
  30357. if (relative.href === '') {
  30358. result.href = result.format();
  30359. return result;
  30360. }
  30361. // hrefs like //foo/bar always cut to the protocol.
  30362. if (relative.slashes && !relative.protocol) {
  30363. // take everything except the protocol from relative
  30364. var rkeys = Object.keys(relative);
  30365. for (var rk = 0; rk < rkeys.length; rk++) {
  30366. var rkey = rkeys[rk];
  30367. if (rkey !== 'protocol')
  30368. result[rkey] = relative[rkey];
  30369. }
  30370. //urlParse appends trailing / to urls like http://www.example.com
  30371. if (slashedProtocol[result.protocol] &&
  30372. result.hostname && !result.pathname) {
  30373. result.path = result.pathname = '/';
  30374. }
  30375. result.href = result.format();
  30376. return result;
  30377. }
  30378. var relPath;
  30379. if (relative.protocol && relative.protocol !== result.protocol) {
  30380. // if it's a known url protocol, then changing
  30381. // the protocol does weird things
  30382. // first, if it's not file:, then we MUST have a host,
  30383. // and if there was a path
  30384. // to begin with, then we MUST have a path.
  30385. // if it is file:, then the host is dropped,
  30386. // because that's known to be hostless.
  30387. // anything else is assumed to be absolute.
  30388. if (!slashedProtocol[relative.protocol]) {
  30389. var keys = Object.keys(relative);
  30390. for (var v = 0; v < keys.length; v++) {
  30391. var k = keys[v];
  30392. result[k] = relative[k];
  30393. }
  30394. result.href = result.format();
  30395. return result;
  30396. }
  30397. result.protocol = relative.protocol;
  30398. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30399. relPath = (relative.pathname || '').split('/');
  30400. while (relPath.length && !(relative.host = relPath.shift()));
  30401. if (!relative.host) relative.host = '';
  30402. if (!relative.hostname) relative.hostname = '';
  30403. if (relPath[0] !== '') relPath.unshift('');
  30404. if (relPath.length < 2) relPath.unshift('');
  30405. result.pathname = relPath.join('/');
  30406. } else {
  30407. result.pathname = relative.pathname;
  30408. }
  30409. result.search = relative.search;
  30410. result.query = relative.query;
  30411. result.host = relative.host || '';
  30412. result.auth = relative.auth;
  30413. result.hostname = relative.hostname || relative.host;
  30414. result.port = relative.port;
  30415. // to support http.request
  30416. if (result.pathname || result.search) {
  30417. var p = result.pathname || '';
  30418. var s = result.search || '';
  30419. result.path = p + s;
  30420. }
  30421. result.slashes = result.slashes || relative.slashes;
  30422. result.href = result.format();
  30423. return result;
  30424. }
  30425. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30426. isRelAbs = (
  30427. relative.host ||
  30428. relative.pathname && relative.pathname.charAt(0) === '/'
  30429. ),
  30430. mustEndAbs = (isRelAbs || isSourceAbs ||
  30431. (result.host && relative.pathname)),
  30432. removeAllDots = mustEndAbs,
  30433. srcPath = result.pathname && result.pathname.split('/') || [],
  30434. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30435. relPath = relative.pathname && relative.pathname.split('/') || [];
  30436. // if the url is a non-slashed url, then relative
  30437. // links like ../.. should be able
  30438. // to crawl up to the hostname, as well. This is strange.
  30439. // result.protocol has already been set by now.
  30440. // Later on, put the first path part into the host field.
  30441. if (psychotic) {
  30442. result.hostname = '';
  30443. result.port = null;
  30444. if (result.host) {
  30445. if (srcPath[0] === '') srcPath[0] = result.host;
  30446. else srcPath.unshift(result.host);
  30447. }
  30448. result.host = '';
  30449. if (relative.protocol) {
  30450. relative.hostname = null;
  30451. relative.port = null;
  30452. if (relative.host) {
  30453. if (relPath[0] === '') relPath[0] = relative.host;
  30454. else relPath.unshift(relative.host);
  30455. }
  30456. relative.host = null;
  30457. }
  30458. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30459. }
  30460. var authInHost;
  30461. if (isRelAbs) {
  30462. // it's absolute.
  30463. result.host = (relative.host || relative.host === '') ?
  30464. relative.host : result.host;
  30465. result.hostname = (relative.hostname || relative.hostname === '') ?
  30466. relative.hostname : result.hostname;
  30467. result.search = relative.search;
  30468. result.query = relative.query;
  30469. srcPath = relPath;
  30470. // fall through to the dot-handling below.
  30471. } else if (relPath.length) {
  30472. // it's relative
  30473. // throw away the existing file, and take the new path instead.
  30474. if (!srcPath) srcPath = [];
  30475. srcPath.pop();
  30476. srcPath = srcPath.concat(relPath);
  30477. result.search = relative.search;
  30478. result.query = relative.query;
  30479. } else if (!isNullOrUndefined(relative.search)) {
  30480. // just pull out the search.
  30481. // like href='?foo'.
  30482. // Put this after the other two cases because it simplifies the booleans
  30483. if (psychotic) {
  30484. result.hostname = result.host = srcPath.shift();
  30485. //occationaly the auth can get stuck only in host
  30486. //this especially happens in cases like
  30487. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30488. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30489. result.host.split('@') : false;
  30490. if (authInHost) {
  30491. result.auth = authInHost.shift();
  30492. result.host = result.hostname = authInHost.shift();
  30493. }
  30494. }
  30495. result.search = relative.search;
  30496. result.query = relative.query;
  30497. //to support http.request
  30498. if (!isNull(result.pathname) || !isNull(result.search)) {
  30499. result.path = (result.pathname ? result.pathname : '') +
  30500. (result.search ? result.search : '');
  30501. }
  30502. result.href = result.format();
  30503. return result;
  30504. }
  30505. if (!srcPath.length) {
  30506. // no path at all. easy.
  30507. // we've already handled the other stuff above.
  30508. result.pathname = null;
  30509. //to support http.request
  30510. if (result.search) {
  30511. result.path = '/' + result.search;
  30512. } else {
  30513. result.path = null;
  30514. }
  30515. result.href = result.format();
  30516. return result;
  30517. }
  30518. // if a url ENDs in . or .., then it must get a trailing slash.
  30519. // however, if it ends in anything else non-slashy,
  30520. // then it must NOT get a trailing slash.
  30521. var last = srcPath.slice(-1)[0];
  30522. var hasTrailingSlash = (
  30523. (result.host || relative.host || srcPath.length > 1) &&
  30524. (last === '.' || last === '..') || last === '');
  30525. // strip single dots, resolve double dots to parent dir
  30526. // if the path tries to go above the root, `up` ends up > 0
  30527. var up = 0;
  30528. for (var i = srcPath.length; i >= 0; i--) {
  30529. last = srcPath[i];
  30530. if (last === '.') {
  30531. srcPath.splice(i, 1);
  30532. } else if (last === '..') {
  30533. srcPath.splice(i, 1);
  30534. up++;
  30535. } else if (up) {
  30536. srcPath.splice(i, 1);
  30537. up--;
  30538. }
  30539. }
  30540. // if the path is allowed to go above the root, restore leading ..s
  30541. if (!mustEndAbs && !removeAllDots) {
  30542. for (; up--; up) {
  30543. srcPath.unshift('..');
  30544. }
  30545. }
  30546. if (mustEndAbs && srcPath[0] !== '' &&
  30547. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30548. srcPath.unshift('');
  30549. }
  30550. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30551. srcPath.push('');
  30552. }
  30553. var isAbsolute = srcPath[0] === '' ||
  30554. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30555. // put the host back
  30556. if (psychotic) {
  30557. result.hostname = result.host = isAbsolute ? '' :
  30558. srcPath.length ? srcPath.shift() : '';
  30559. //occationaly the auth can get stuck only in host
  30560. //this especially happens in cases like
  30561. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30562. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30563. result.host.split('@') : false;
  30564. if (authInHost) {
  30565. result.auth = authInHost.shift();
  30566. result.host = result.hostname = authInHost.shift();
  30567. }
  30568. }
  30569. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30570. if (mustEndAbs && !isAbsolute) {
  30571. srcPath.unshift('');
  30572. }
  30573. if (!srcPath.length) {
  30574. result.pathname = null;
  30575. result.path = null;
  30576. } else {
  30577. result.pathname = srcPath.join('/');
  30578. }
  30579. //to support request.http
  30580. if (!isNull(result.pathname) || !isNull(result.search)) {
  30581. result.path = (result.pathname ? result.pathname : '') +
  30582. (result.search ? result.search : '');
  30583. }
  30584. result.auth = relative.auth || result.auth;
  30585. result.slashes = result.slashes || relative.slashes;
  30586. result.href = result.format();
  30587. return result;
  30588. };
  30589. Url.prototype.parseHost = function() {
  30590. return parseHost(this);
  30591. };
  30592. function parseHost(self) {
  30593. var host = self.host;
  30594. var port = portPattern.exec(host);
  30595. if (port) {
  30596. port = port[0];
  30597. if (port !== ':') {
  30598. self.port = port.substr(1);
  30599. }
  30600. host = host.substr(0, host.length - port.length);
  30601. }
  30602. if (host) self.hostname = host;
  30603. }
  30604. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30605. __proto__: null,
  30606. URL: URL$1,
  30607. URLSearchParams: URLSearchParams,
  30608. Url: Url,
  30609. default: _polyfillNode_url,
  30610. fileURLToPath: urlFileURLToPath,
  30611. format: urlFormat,
  30612. parse: urlParse,
  30613. resolve: urlResolve,
  30614. resolveObject: urlResolveObject
  30615. });
  30616. function isRelativeUrl(url) {
  30617. const firstChar = url.charAt(0);
  30618. return firstChar === "." || firstChar === "~" || firstChar === "@" || firstChar === "#";
  30619. }
  30620. const externalRE = /^(?:https?:)?\/\//;
  30621. function isExternalUrl(url) {
  30622. return externalRE.test(url);
  30623. }
  30624. const dataUrlRE = /^\s*data:/i;
  30625. function isDataUrl(url) {
  30626. return dataUrlRE.test(url);
  30627. }
  30628. function normalizeDecodedImportPath(source) {
  30629. try {
  30630. return decodeURIComponent(source);
  30631. } catch (e) {
  30632. return source;
  30633. }
  30634. }
  30635. function parseUrl(url) {
  30636. const firstChar = url.charAt(0);
  30637. if (firstChar === "~") {
  30638. const secondChar = url.charAt(1);
  30639. url = url.slice(secondChar === "/" ? 2 : 1);
  30640. }
  30641. return parseUriParts(url);
  30642. }
  30643. function parseUriParts(urlString) {
  30644. return urlParse(isString$1(urlString) ? urlString : "", false, true);
  30645. }
  30646. var __defProp$9 = Object.defineProperty;
  30647. var __defProps$8 = Object.defineProperties;
  30648. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  30649. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30650. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30651. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30652. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30653. var __spreadValues$9 = (a, b) => {
  30654. for (var prop in b || (b = {}))
  30655. if (__hasOwnProp$9.call(b, prop))
  30656. __defNormalProp$9(a, prop, b[prop]);
  30657. if (__getOwnPropSymbols$9)
  30658. for (var prop of __getOwnPropSymbols$9(b)) {
  30659. if (__propIsEnum$9.call(b, prop))
  30660. __defNormalProp$9(a, prop, b[prop]);
  30661. }
  30662. return a;
  30663. };
  30664. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  30665. const resourceUrlTagConfig = {
  30666. video: ["src", "poster"],
  30667. source: ["src"],
  30668. img: ["src"],
  30669. image: ["xlink:href", "href"]
  30670. };
  30671. const defaultAssetUrlOptions = {
  30672. base: null,
  30673. includeAbsolute: false,
  30674. tags: __spreadProps$8(__spreadValues$9({}, resourceUrlTagConfig), {
  30675. use: ["xlink:href", "href"]
  30676. })
  30677. };
  30678. const normalizeOptions = (options) => {
  30679. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30680. return __spreadProps$8(__spreadValues$9({}, defaultAssetUrlOptions), {
  30681. tags: options
  30682. });
  30683. }
  30684. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30685. };
  30686. const createAssetUrlTransformWithOptions = (options) => {
  30687. return (node, context) => transformAssetUrl(node, context, options);
  30688. };
  30689. function canTransformHashImport(tag, attrName) {
  30690. var _a;
  30691. return !!((_a = resourceUrlTagConfig[tag]) == null ? void 0 : _a.includes(attrName));
  30692. }
  30693. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30694. if (node.type === 1) {
  30695. if (!node.props.length) {
  30696. return;
  30697. }
  30698. const tags = options.tags || defaultAssetUrlOptions.tags;
  30699. const attrs = tags[node.tag];
  30700. const wildCardAttrs = tags["*"];
  30701. if (!attrs && !wildCardAttrs) {
  30702. return;
  30703. }
  30704. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30705. node.props.forEach((attr, index) => {
  30706. if (attr.type !== 6 || !assetAttrs.includes(attr.name) || !attr.value) {
  30707. return;
  30708. }
  30709. const urlValue = attr.value.content;
  30710. const isHashOnlyValue = urlValue[0] === "#";
  30711. if (isExternalUrl(urlValue) || isDataUrl(urlValue) || isHashOnlyValue && !canTransformHashImport(node.tag, attr.name) || !options.includeAbsolute && !isRelativeUrl(urlValue)) {
  30712. return;
  30713. }
  30714. const url = parseUrl(urlValue);
  30715. if (options.base && urlValue[0] === ".") {
  30716. const base = parseUrl(options.base);
  30717. const protocol = base.protocol || "";
  30718. const host = base.host ? protocol + "//" + base.host : "";
  30719. const basePath = base.path || "/";
  30720. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30721. return;
  30722. }
  30723. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30724. node.props[index] = {
  30725. type: 7,
  30726. name: "bind",
  30727. arg: createSimpleExpression(attr.name, true, attr.loc),
  30728. exp,
  30729. modifiers: [],
  30730. loc: attr.loc
  30731. };
  30732. });
  30733. }
  30734. };
  30735. function resolveOrRegisterImport(source, loc, context) {
  30736. const normalizedSource = normalizeDecodedImportPath(source);
  30737. const existingIndex = context.imports.findIndex(
  30738. (i) => i.path === normalizedSource
  30739. );
  30740. if (existingIndex > -1) {
  30741. return {
  30742. name: `_imports_${existingIndex}`,
  30743. exp: context.imports[existingIndex].exp
  30744. };
  30745. }
  30746. const name = `_imports_${context.imports.length}`;
  30747. const exp = createSimpleExpression(
  30748. name,
  30749. false,
  30750. loc,
  30751. 3
  30752. );
  30753. context.imports.push({
  30754. exp,
  30755. path: normalizedSource
  30756. });
  30757. return { name, exp };
  30758. }
  30759. function getImportsExpressionExp(path2, hash, loc, context) {
  30760. if (!path2 && !hash) {
  30761. return createSimpleExpression(`''`, false, loc, 3);
  30762. }
  30763. if (!path2 && hash) {
  30764. const { exp } = resolveOrRegisterImport(hash, loc, context);
  30765. return exp;
  30766. }
  30767. if (path2 && !hash) {
  30768. const { exp } = resolveOrRegisterImport(path2, loc, context);
  30769. return exp;
  30770. }
  30771. const { name } = resolveOrRegisterImport(path2, loc, context);
  30772. const hashExp = `${name} + '${hash}'`;
  30773. const finalExp = createSimpleExpression(
  30774. hashExp,
  30775. false,
  30776. loc,
  30777. 3
  30778. );
  30779. if (!context.hoistStatic) {
  30780. return finalExp;
  30781. }
  30782. const existingHoistIndex = context.hoists.findIndex((h) => {
  30783. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30784. });
  30785. if (existingHoistIndex > -1) {
  30786. return createSimpleExpression(
  30787. `_hoisted_${existingHoistIndex + 1}`,
  30788. false,
  30789. loc,
  30790. 3
  30791. );
  30792. }
  30793. return context.hoist(finalExp);
  30794. }
  30795. const srcsetTags = ["img", "source"];
  30796. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30797. const createSrcsetTransformWithOptions = (options) => {
  30798. return (node, context) => transformSrcset(node, context, options);
  30799. };
  30800. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30801. if (node.type === 1) {
  30802. if (srcsetTags.includes(node.tag) && node.props.length) {
  30803. node.props.forEach((attr, index) => {
  30804. if (attr.name === "srcset" && attr.type === 6) {
  30805. if (!attr.value) return;
  30806. const value = attr.value.content;
  30807. if (!value) return;
  30808. const imageCandidates = value.split(",").map((s) => {
  30809. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30810. return { url, descriptor };
  30811. });
  30812. for (let i = 0; i < imageCandidates.length; i++) {
  30813. const { url } = imageCandidates[i];
  30814. if (isDataUrl(url)) {
  30815. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30816. imageCandidates.splice(i, 1);
  30817. }
  30818. }
  30819. const shouldProcessUrl = (url) => {
  30820. return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30821. };
  30822. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30823. return;
  30824. }
  30825. if (options.base) {
  30826. const base = options.base;
  30827. const set = [];
  30828. let needImportTransform = false;
  30829. imageCandidates.forEach((candidate) => {
  30830. let { url, descriptor } = candidate;
  30831. descriptor = descriptor ? ` ${descriptor}` : ``;
  30832. if (url[0] === ".") {
  30833. candidate.url = (path.posix || path).join(base, url);
  30834. set.push(candidate.url + descriptor);
  30835. } else if (shouldProcessUrl(url)) {
  30836. needImportTransform = true;
  30837. } else {
  30838. set.push(url + descriptor);
  30839. }
  30840. });
  30841. if (!needImportTransform) {
  30842. attr.value.content = set.join(", ");
  30843. return;
  30844. }
  30845. }
  30846. const compoundExpression = createCompoundExpression([], attr.loc);
  30847. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30848. if (shouldProcessUrl(url)) {
  30849. const { path: path2, hash } = parseUrl(url);
  30850. const source = path2 ? path2 : hash;
  30851. if (source) {
  30852. const normalizedSource = normalizeDecodedImportPath(source);
  30853. const existingImportsIndex = context.imports.findIndex(
  30854. (i) => i.path === normalizedSource
  30855. );
  30856. let exp2;
  30857. if (existingImportsIndex > -1) {
  30858. exp2 = createSimpleExpression(
  30859. `_imports_${existingImportsIndex}`,
  30860. false,
  30861. attr.loc,
  30862. 3
  30863. );
  30864. } else {
  30865. exp2 = createSimpleExpression(
  30866. `_imports_${context.imports.length}`,
  30867. false,
  30868. attr.loc,
  30869. 3
  30870. );
  30871. context.imports.push({ exp: exp2, path: normalizedSource });
  30872. }
  30873. if (path2 && hash) {
  30874. exp2 = createSimpleExpression(
  30875. `${exp2.content} + '${hash}'`,
  30876. false,
  30877. attr.loc,
  30878. 3
  30879. );
  30880. }
  30881. compoundExpression.children.push(exp2);
  30882. }
  30883. } else {
  30884. const exp2 = createSimpleExpression(
  30885. `"${url}"`,
  30886. false,
  30887. attr.loc,
  30888. 3
  30889. );
  30890. compoundExpression.children.push(exp2);
  30891. }
  30892. const isNotLast = imageCandidates.length - 1 > index2;
  30893. if (descriptor && isNotLast) {
  30894. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30895. } else if (descriptor) {
  30896. compoundExpression.children.push(` + ' ${descriptor}'`);
  30897. } else if (isNotLast) {
  30898. compoundExpression.children.push(` + ', ' + `);
  30899. }
  30900. });
  30901. let exp = compoundExpression;
  30902. if (context.hoistStatic) {
  30903. exp = context.hoist(compoundExpression);
  30904. exp.constType = 3;
  30905. }
  30906. node.props[index] = {
  30907. type: 7,
  30908. name: "bind",
  30909. arg: createSimpleExpression("srcset", true, attr.loc),
  30910. exp,
  30911. modifiers: [],
  30912. loc: attr.loc
  30913. };
  30914. }
  30915. });
  30916. }
  30917. }
  30918. };
  30919. const SSR_INTERPOLATE = /* @__PURE__ */ Symbol(`ssrInterpolate`);
  30920. const SSR_RENDER_VNODE = /* @__PURE__ */ Symbol(`ssrRenderVNode`);
  30921. const SSR_RENDER_COMPONENT = /* @__PURE__ */ Symbol(`ssrRenderComponent`);
  30922. const SSR_RENDER_SLOT = /* @__PURE__ */ Symbol(`ssrRenderSlot`);
  30923. const SSR_RENDER_SLOT_INNER = /* @__PURE__ */ Symbol(`ssrRenderSlotInner`);
  30924. const SSR_RENDER_CLASS = /* @__PURE__ */ Symbol(`ssrRenderClass`);
  30925. const SSR_RENDER_STYLE = /* @__PURE__ */ Symbol(`ssrRenderStyle`);
  30926. const SSR_RENDER_ATTRS = /* @__PURE__ */ Symbol(`ssrRenderAttrs`);
  30927. const SSR_RENDER_ATTR = /* @__PURE__ */ Symbol(`ssrRenderAttr`);
  30928. const SSR_RENDER_DYNAMIC_ATTR = /* @__PURE__ */ Symbol(`ssrRenderDynamicAttr`);
  30929. const SSR_RENDER_LIST = /* @__PURE__ */ Symbol(`ssrRenderList`);
  30930. const SSR_INCLUDE_BOOLEAN_ATTR = /* @__PURE__ */ Symbol(
  30931. `ssrIncludeBooleanAttr`
  30932. );
  30933. const SSR_LOOSE_EQUAL = /* @__PURE__ */ Symbol(`ssrLooseEqual`);
  30934. const SSR_LOOSE_CONTAIN = /* @__PURE__ */ Symbol(`ssrLooseContain`);
  30935. const SSR_RENDER_DYNAMIC_MODEL = /* @__PURE__ */ Symbol(
  30936. `ssrRenderDynamicModel`
  30937. );
  30938. const SSR_GET_DYNAMIC_MODEL_PROPS = /* @__PURE__ */ Symbol(
  30939. `ssrGetDynamicModelProps`
  30940. );
  30941. const SSR_RENDER_TELEPORT = /* @__PURE__ */ Symbol(`ssrRenderTeleport`);
  30942. const SSR_RENDER_SUSPENSE = /* @__PURE__ */ Symbol(`ssrRenderSuspense`);
  30943. const SSR_GET_DIRECTIVE_PROPS = /* @__PURE__ */ Symbol(`ssrGetDirectiveProps`);
  30944. const ssrHelpers = {
  30945. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30946. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30947. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30948. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30949. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30950. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30951. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30952. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30953. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30954. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30955. [SSR_RENDER_LIST]: `ssrRenderList`,
  30956. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30957. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  30958. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  30959. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  30960. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  30961. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  30962. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  30963. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  30964. };
  30965. registerRuntimeHelpers(ssrHelpers);
  30966. const ssrTransformIf = createStructuralDirectiveTransform(
  30967. /^(?:if|else|else-if)$/,
  30968. processIf
  30969. );
  30970. function ssrProcessIf(node, context, disableNestedFragments = false, disableComment = false) {
  30971. const [rootBranch] = node.branches;
  30972. const ifStatement = createIfStatement(
  30973. rootBranch.condition,
  30974. processIfBranch(rootBranch, context, disableNestedFragments)
  30975. );
  30976. context.pushStatement(ifStatement);
  30977. let currentIf = ifStatement;
  30978. for (let i = 1; i < node.branches.length; i++) {
  30979. const branch = node.branches[i];
  30980. const branchBlockStatement = processIfBranch(
  30981. branch,
  30982. context,
  30983. disableNestedFragments
  30984. );
  30985. if (branch.condition) {
  30986. currentIf = currentIf.alternate = createIfStatement(
  30987. branch.condition,
  30988. branchBlockStatement
  30989. );
  30990. } else {
  30991. currentIf.alternate = branchBlockStatement;
  30992. }
  30993. }
  30994. if (!currentIf.alternate && !disableComment) {
  30995. currentIf.alternate = createBlockStatement([
  30996. createCallExpression(`_push`, ["`<!---->`"])
  30997. ]);
  30998. }
  30999. }
  31000. function processIfBranch(branch, context, disableNestedFragments = false) {
  31001. const { children } = branch;
  31002. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  31003. !(children.length === 1 && children[0].type === 11);
  31004. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  31005. }
  31006. const ssrTransformFor = createStructuralDirectiveTransform("for", processFor);
  31007. function ssrProcessFor(node, context, disableNestedFragments = false) {
  31008. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  31009. const renderLoop = createFunctionExpression(
  31010. createForLoopParams(node.parseResult)
  31011. );
  31012. renderLoop.body = processChildrenAsStatement(
  31013. node,
  31014. context,
  31015. needFragmentWrapper
  31016. );
  31017. if (!disableNestedFragments) {
  31018. context.pushStringPart(`<!--[-->`);
  31019. }
  31020. context.pushStatement(
  31021. createCallExpression(context.helper(SSR_RENDER_LIST), [
  31022. node.source,
  31023. renderLoop
  31024. ])
  31025. );
  31026. if (!disableNestedFragments) {
  31027. context.pushStringPart(`<!--]-->`);
  31028. }
  31029. }
  31030. const ssrTransformSlotOutlet = (node, context) => {
  31031. if (isSlotOutlet(node)) {
  31032. const { slotName, slotProps } = processSlotOutlet(node, context);
  31033. const args = [
  31034. `_ctx.$slots`,
  31035. slotName,
  31036. slotProps || `{}`,
  31037. // fallback content placeholder. will be replaced in the process phase
  31038. `null`,
  31039. `_push`,
  31040. `_parent`
  31041. ];
  31042. if (context.scopeId && context.slotted !== false) {
  31043. args.push(`"${context.scopeId}-s"`);
  31044. }
  31045. let method = SSR_RENDER_SLOT;
  31046. let parent = context.parent;
  31047. if (parent) {
  31048. const children = parent.children;
  31049. if (parent.type === 10) {
  31050. parent = context.grandParent;
  31051. }
  31052. let componentType;
  31053. if (parent.type === 1 && parent.tagType === 1 && ((componentType = resolveComponentType(parent, context, true)) === TRANSITION || componentType === TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) {
  31054. method = SSR_RENDER_SLOT_INNER;
  31055. if (!(context.scopeId && context.slotted !== false)) {
  31056. args.push("null");
  31057. }
  31058. args.push("true");
  31059. }
  31060. }
  31061. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  31062. }
  31063. };
  31064. function ssrProcessSlotOutlet(node, context) {
  31065. const renderCall = node.ssrCodegenNode;
  31066. if (node.children.length) {
  31067. const fallbackRenderFn = createFunctionExpression([]);
  31068. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  31069. renderCall.arguments[3] = fallbackRenderFn;
  31070. }
  31071. if (context.withSlotScopeId) {
  31072. const slotScopeId = renderCall.arguments[6];
  31073. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  31074. }
  31075. context.pushStatement(node.ssrCodegenNode);
  31076. }
  31077. function createSSRCompilerError(code, loc) {
  31078. return createCompilerError(code, loc, SSRErrorMessages);
  31079. }
  31080. const SSRErrorMessages = {
  31081. [65]: `Unsafe attribute name for SSR.`,
  31082. [66]: `Missing the 'to' prop on teleport element.`,
  31083. [67]: `Invalid AST node during SSR transform.`
  31084. };
  31085. function ssrProcessTeleport(node, context) {
  31086. const targetProp = findProp(node, "to");
  31087. if (!targetProp) {
  31088. context.onError(
  31089. createSSRCompilerError(66, node.loc)
  31090. );
  31091. return;
  31092. }
  31093. let target;
  31094. if (targetProp.type === 6) {
  31095. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  31096. } else {
  31097. target = targetProp.exp;
  31098. }
  31099. if (!target) {
  31100. context.onError(
  31101. createSSRCompilerError(
  31102. 66,
  31103. targetProp.loc
  31104. )
  31105. );
  31106. return;
  31107. }
  31108. const disabledProp = findProp(
  31109. node,
  31110. "disabled",
  31111. false,
  31112. true
  31113. /* allow empty */
  31114. );
  31115. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  31116. const contentRenderFn = createFunctionExpression(
  31117. [`_push`],
  31118. void 0,
  31119. // Body is added later
  31120. true,
  31121. // newline
  31122. false,
  31123. // isSlot
  31124. node.loc
  31125. );
  31126. contentRenderFn.body = processChildrenAsStatement(node, context);
  31127. context.pushStatement(
  31128. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  31129. `_push`,
  31130. contentRenderFn,
  31131. target,
  31132. disabled,
  31133. `_parent`
  31134. ])
  31135. );
  31136. }
  31137. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  31138. function ssrTransformSuspense(node, context) {
  31139. return () => {
  31140. if (node.children.length) {
  31141. const wipEntry = {
  31142. slotsExp: null,
  31143. // to be immediately set
  31144. wipSlots: []
  31145. };
  31146. wipMap$3.set(node, wipEntry);
  31147. wipEntry.slotsExp = buildSlots(
  31148. node,
  31149. context,
  31150. (_props, _vForExp, children, loc) => {
  31151. const fn = createFunctionExpression(
  31152. [],
  31153. void 0,
  31154. // no return, assign body later
  31155. true,
  31156. // newline
  31157. false,
  31158. // suspense slots are not treated as normal slots
  31159. loc
  31160. );
  31161. wipEntry.wipSlots.push({
  31162. fn,
  31163. children
  31164. });
  31165. return fn;
  31166. }
  31167. ).slots;
  31168. }
  31169. };
  31170. }
  31171. function ssrProcessSuspense(node, context) {
  31172. const wipEntry = wipMap$3.get(node);
  31173. if (!wipEntry) {
  31174. return;
  31175. }
  31176. const { slotsExp, wipSlots } = wipEntry;
  31177. for (let i = 0; i < wipSlots.length; i++) {
  31178. const slot = wipSlots[i];
  31179. slot.fn.body = processChildrenAsStatement(slot, context);
  31180. }
  31181. context.pushStatement(
  31182. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  31183. `_push`,
  31184. slotsExp
  31185. ])
  31186. );
  31187. }
  31188. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  31189. const ssrTransformElement = (node, context) => {
  31190. if (node.type !== 1 || node.tagType !== 0) {
  31191. return;
  31192. }
  31193. return function ssrPostTransformElement() {
  31194. const openTag = [`<${node.tag}`];
  31195. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  31196. const hasDynamicVBind = hasDynamicKeyVBind(node);
  31197. const hasCustomDir = node.props.some(
  31198. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  31199. );
  31200. const vShowPropIndex = node.props.findIndex(
  31201. (i) => i.type === 7 && i.name === "show"
  31202. );
  31203. if (vShowPropIndex !== -1) {
  31204. const vShowProp = node.props[vShowPropIndex];
  31205. node.props.splice(vShowPropIndex, 1);
  31206. node.props.push(vShowProp);
  31207. }
  31208. const needMergeProps = hasDynamicVBind || hasCustomDir;
  31209. if (needMergeProps) {
  31210. const { props, directives } = buildProps(
  31211. node,
  31212. context,
  31213. node.props,
  31214. false,
  31215. false,
  31216. true
  31217. );
  31218. if (props || directives.length) {
  31219. const mergedProps = buildSSRProps(props, directives, context);
  31220. const propsExp = createCallExpression(
  31221. context.helper(SSR_RENDER_ATTRS),
  31222. [mergedProps]
  31223. );
  31224. if (node.tag === "textarea") {
  31225. const existingText = node.children[0];
  31226. if (!hasContentOverrideDirective(node) && (!existingText || existingText.type !== 5)) {
  31227. const tempId = `_temp${context.temps++}`;
  31228. propsExp.arguments = [
  31229. createAssignmentExpression(
  31230. createSimpleExpression(tempId, false),
  31231. mergedProps
  31232. )
  31233. ];
  31234. rawChildrenMap.set(
  31235. node,
  31236. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31237. createConditionalExpression(
  31238. createSimpleExpression(`"value" in ${tempId}`, false),
  31239. createSimpleExpression(`${tempId}.value`, false),
  31240. createSimpleExpression(
  31241. existingText ? existingText.content : ``,
  31242. true
  31243. ),
  31244. false
  31245. )
  31246. ])
  31247. );
  31248. }
  31249. } else if (node.tag === "input") {
  31250. const vModel = findVModel(node);
  31251. if (vModel) {
  31252. const tempId = `_temp${context.temps++}`;
  31253. const tempExp = createSimpleExpression(tempId, false);
  31254. propsExp.arguments = [
  31255. createSequenceExpression([
  31256. createAssignmentExpression(tempExp, mergedProps),
  31257. createCallExpression(context.helper(MERGE_PROPS), [
  31258. tempExp,
  31259. createCallExpression(
  31260. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  31261. [
  31262. tempExp,
  31263. // existing props
  31264. vModel.exp
  31265. // model
  31266. ]
  31267. )
  31268. ])
  31269. ])
  31270. ];
  31271. }
  31272. } else if (directives.length && !node.children.length) {
  31273. if (!hasContentOverrideDirective(node)) {
  31274. const tempId = `_temp${context.temps++}`;
  31275. propsExp.arguments = [
  31276. createAssignmentExpression(
  31277. createSimpleExpression(tempId, false),
  31278. mergedProps
  31279. )
  31280. ];
  31281. rawChildrenMap.set(
  31282. node,
  31283. createConditionalExpression(
  31284. createSimpleExpression(`"textContent" in ${tempId}`, false),
  31285. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31286. createSimpleExpression(`${tempId}.textContent`, false)
  31287. ]),
  31288. createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
  31289. false
  31290. )
  31291. );
  31292. }
  31293. }
  31294. if (needTagForRuntime) {
  31295. propsExp.arguments.push(`"${node.tag}"`);
  31296. }
  31297. openTag.push(propsExp);
  31298. }
  31299. }
  31300. let dynamicClassBinding = void 0;
  31301. let staticClassBinding = void 0;
  31302. let dynamicStyleBinding = void 0;
  31303. for (let i = 0; i < node.props.length; i++) {
  31304. const prop = node.props[i];
  31305. if (node.tag === "input" && isTrueFalseValue(prop)) {
  31306. continue;
  31307. }
  31308. if (prop.type === 7) {
  31309. if (prop.name === "html" && prop.exp) {
  31310. rawChildrenMap.set(
  31311. node,
  31312. createCompoundExpression([`(`, prop.exp, `) ?? ''`])
  31313. );
  31314. } else if (prop.name === "text" && prop.exp) {
  31315. node.children = [createInterpolation(prop.exp, prop.loc)];
  31316. } else if (prop.name === "slot") {
  31317. context.onError(
  31318. createCompilerError(40, prop.loc)
  31319. );
  31320. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  31321. if (!needMergeProps) {
  31322. node.children = [createInterpolation(prop.exp, prop.loc)];
  31323. }
  31324. } else if (!needMergeProps && prop.name !== "on") {
  31325. const directiveTransform = context.directiveTransforms[prop.name];
  31326. if (directiveTransform) {
  31327. const { props, ssrTagParts } = directiveTransform(
  31328. prop,
  31329. node,
  31330. context
  31331. );
  31332. if (ssrTagParts) {
  31333. openTag.push(...ssrTagParts);
  31334. }
  31335. for (let j = 0; j < props.length; j++) {
  31336. const { key, value } = props[j];
  31337. if (isStaticExp(key)) {
  31338. let attrName = key.content;
  31339. if (attrName === "key" || attrName === "ref") {
  31340. continue;
  31341. }
  31342. if (attrName === "class") {
  31343. openTag.push(
  31344. ` class="`,
  31345. dynamicClassBinding = createCallExpression(
  31346. context.helper(SSR_RENDER_CLASS),
  31347. [value]
  31348. ),
  31349. `"`
  31350. );
  31351. } else if (attrName === "style") {
  31352. if (dynamicStyleBinding) {
  31353. mergeCall(dynamicStyleBinding, value);
  31354. } else {
  31355. openTag.push(
  31356. ` style="`,
  31357. dynamicStyleBinding = createCallExpression(
  31358. context.helper(SSR_RENDER_STYLE),
  31359. [value]
  31360. ),
  31361. `"`
  31362. );
  31363. }
  31364. } else {
  31365. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31366. if (isBooleanAttr(attrName)) {
  31367. openTag.push(
  31368. createConditionalExpression(
  31369. createCallExpression(
  31370. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31371. [value]
  31372. ),
  31373. createSimpleExpression(" " + attrName, true),
  31374. createSimpleExpression("", true),
  31375. false
  31376. )
  31377. );
  31378. } else if (isSSRSafeAttrName(attrName)) {
  31379. openTag.push(
  31380. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31381. key,
  31382. value
  31383. ])
  31384. );
  31385. } else {
  31386. context.onError(
  31387. createSSRCompilerError(
  31388. 65,
  31389. key.loc
  31390. )
  31391. );
  31392. }
  31393. }
  31394. } else {
  31395. const args = [key, value];
  31396. if (needTagForRuntime) {
  31397. args.push(`"${node.tag}"`);
  31398. }
  31399. openTag.push(
  31400. createCallExpression(
  31401. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31402. args
  31403. )
  31404. );
  31405. }
  31406. }
  31407. }
  31408. }
  31409. } else {
  31410. const name = prop.name;
  31411. if (node.tag === "textarea" && name === "value" && prop.value) {
  31412. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31413. } else if (!needMergeProps) {
  31414. if (name === "key" || name === "ref") {
  31415. continue;
  31416. }
  31417. if (name === "class" && prop.value) {
  31418. staticClassBinding = JSON.stringify(prop.value.content);
  31419. }
  31420. openTag.push(
  31421. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31422. );
  31423. }
  31424. }
  31425. }
  31426. if (dynamicClassBinding && staticClassBinding) {
  31427. mergeCall(dynamicClassBinding, staticClassBinding);
  31428. removeStaticBinding(openTag, "class");
  31429. }
  31430. if (context.scopeId) {
  31431. openTag.push(` ${context.scopeId}`);
  31432. }
  31433. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31434. };
  31435. };
  31436. function buildSSRProps(props, directives, context) {
  31437. let mergePropsArgs = [];
  31438. if (props) {
  31439. if (props.type === 14) {
  31440. mergePropsArgs = props.arguments;
  31441. } else {
  31442. mergePropsArgs.push(props);
  31443. }
  31444. }
  31445. if (directives.length) {
  31446. for (const dir of directives) {
  31447. mergePropsArgs.push(
  31448. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31449. `_ctx`,
  31450. ...buildDirectiveArgs(dir, context).elements
  31451. ])
  31452. );
  31453. }
  31454. }
  31455. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31456. }
  31457. function isTrueFalseValue(prop) {
  31458. if (prop.type === 7) {
  31459. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31460. } else {
  31461. return prop.name === "true-value" || prop.name === "false-value";
  31462. }
  31463. }
  31464. function isTextareaWithValue(node, prop) {
  31465. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31466. }
  31467. function mergeCall(call, arg) {
  31468. const existing = call.arguments[0];
  31469. if (existing.type === 17) {
  31470. existing.elements.push(arg);
  31471. } else {
  31472. call.arguments[0] = createArrayExpression([existing, arg]);
  31473. }
  31474. }
  31475. function removeStaticBinding(tag, binding) {
  31476. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31477. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31478. if (i > -1) {
  31479. tag.splice(i, 1);
  31480. }
  31481. }
  31482. function findVModel(node) {
  31483. return node.props.find(
  31484. (p) => p.type === 7 && p.name === "model" && p.exp
  31485. );
  31486. }
  31487. function hasContentOverrideDirective(node) {
  31488. return !!findDir(node, "text") || !!findDir(node, "html");
  31489. }
  31490. function ssrProcessElement(node, context) {
  31491. const isVoidTag = context.options.isVoidTag || NO;
  31492. const elementsToAdd = node.ssrCodegenNode.elements;
  31493. for (let j = 0; j < elementsToAdd.length; j++) {
  31494. context.pushStringPart(elementsToAdd[j]);
  31495. }
  31496. if (context.withSlotScopeId) {
  31497. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31498. }
  31499. context.pushStringPart(`>`);
  31500. const rawChildren = rawChildrenMap.get(node);
  31501. if (rawChildren) {
  31502. context.pushStringPart(rawChildren);
  31503. } else if (node.children.length) {
  31504. processChildren(node, context);
  31505. }
  31506. if (!isVoidTag(node.tag)) {
  31507. context.pushStringPart(`</${node.tag}>`);
  31508. }
  31509. }
  31510. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  31511. function ssrTransformTransitionGroup(node, context) {
  31512. return () => {
  31513. const tag = findProp(node, "tag");
  31514. if (tag) {
  31515. const otherProps = node.props.filter((p) => p !== tag);
  31516. const { props, directives } = buildProps(
  31517. node,
  31518. context,
  31519. otherProps,
  31520. true,
  31521. false,
  31522. true
  31523. );
  31524. let propsExp = null;
  31525. if (props || directives.length) {
  31526. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31527. buildSSRProps(props, directives, context)
  31528. ]);
  31529. }
  31530. wipMap$2.set(node, {
  31531. tag,
  31532. propsExp,
  31533. scopeId: context.scopeId || null
  31534. });
  31535. }
  31536. };
  31537. }
  31538. function ssrProcessTransitionGroup(node, context) {
  31539. const entry = wipMap$2.get(node);
  31540. if (entry) {
  31541. const { tag, propsExp, scopeId } = entry;
  31542. if (tag.type === 7) {
  31543. context.pushStringPart(`<`);
  31544. context.pushStringPart(tag.exp);
  31545. if (propsExp) {
  31546. context.pushStringPart(propsExp);
  31547. }
  31548. if (scopeId) {
  31549. context.pushStringPart(` ${scopeId}`);
  31550. }
  31551. context.pushStringPart(`>`);
  31552. processChildren(
  31553. node,
  31554. context,
  31555. false,
  31556. /**
  31557. * TransitionGroup has the special runtime behavior of flattening and
  31558. * concatenating all children into a single fragment (in order for them to
  31559. * be patched using the same key map) so we need to account for that here
  31560. * by disabling nested fragment wrappers from being generated.
  31561. */
  31562. true,
  31563. /**
  31564. * TransitionGroup filters out comment children at runtime and thus
  31565. * doesn't expect comments to be present during hydration. We need to
  31566. * account for that by disabling the empty comment that is otherwise
  31567. * rendered for a falsy v-if that has no v-else specified. (#6715)
  31568. */
  31569. true
  31570. );
  31571. context.pushStringPart(`</`);
  31572. context.pushStringPart(tag.exp);
  31573. context.pushStringPart(`>`);
  31574. } else {
  31575. context.pushStringPart(`<${tag.value.content}`);
  31576. if (propsExp) {
  31577. context.pushStringPart(propsExp);
  31578. }
  31579. if (scopeId) {
  31580. context.pushStringPart(` ${scopeId}`);
  31581. }
  31582. context.pushStringPart(`>`);
  31583. processChildren(node, context, false, true, true);
  31584. context.pushStringPart(`</${tag.value.content}>`);
  31585. }
  31586. } else {
  31587. processChildren(node, context, true, true, true);
  31588. }
  31589. }
  31590. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31591. function ssrTransformTransition(node, context) {
  31592. return () => {
  31593. const appear = findProp(node, "appear", false, true);
  31594. wipMap$1.set(node, !!appear);
  31595. };
  31596. }
  31597. function ssrProcessTransition(node, context) {
  31598. node.children = node.children.filter((c) => c.type !== 3);
  31599. const appear = wipMap$1.get(node);
  31600. if (appear) {
  31601. context.pushStringPart(`<template>`);
  31602. processChildren(node, context, false, true);
  31603. context.pushStringPart(`</template>`);
  31604. } else {
  31605. processChildren(node, context, false, true);
  31606. }
  31607. }
  31608. var __defProp$8 = Object.defineProperty;
  31609. var __defProps$7 = Object.defineProperties;
  31610. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  31611. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31612. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31613. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31614. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31615. var __spreadValues$8 = (a, b) => {
  31616. for (var prop in b || (b = {}))
  31617. if (__hasOwnProp$8.call(b, prop))
  31618. __defNormalProp$8(a, prop, b[prop]);
  31619. if (__getOwnPropSymbols$8)
  31620. for (var prop of __getOwnPropSymbols$8(b)) {
  31621. if (__propIsEnum$8.call(b, prop))
  31622. __defNormalProp$8(a, prop, b[prop]);
  31623. }
  31624. return a;
  31625. };
  31626. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  31627. const wipMap = /* @__PURE__ */ new WeakMap();
  31628. const WIP_SLOT = /* @__PURE__ */ Symbol();
  31629. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31630. const ssrTransformComponent = (node, context) => {
  31631. if (node.type !== 1 || node.tagType !== 1) {
  31632. return;
  31633. }
  31634. const component = resolveComponentType(
  31635. node,
  31636. context,
  31637. true
  31638. /* ssr */
  31639. );
  31640. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31641. componentTypeMap.set(node, component);
  31642. if (isSymbol$1(component)) {
  31643. if (component === SUSPENSE) {
  31644. return ssrTransformSuspense(node, context);
  31645. } else if (component === TRANSITION_GROUP) {
  31646. return ssrTransformTransitionGroup(node, context);
  31647. } else if (component === TRANSITION) {
  31648. return ssrTransformTransition(node);
  31649. }
  31650. return;
  31651. }
  31652. const vnodeBranches = [];
  31653. const clonedNode = clone(node);
  31654. return function ssrPostTransformComponent() {
  31655. if (clonedNode.children.length) {
  31656. buildSlots(clonedNode, context, (props, vFor, children) => {
  31657. vnodeBranches.push(
  31658. createVNodeSlotBranch(props, vFor, children, context)
  31659. );
  31660. return createFunctionExpression(void 0);
  31661. });
  31662. }
  31663. let propsExp = `null`;
  31664. if (node.props.length) {
  31665. const { props, directives } = buildProps(
  31666. node,
  31667. context,
  31668. void 0,
  31669. true,
  31670. isDynamicComponent
  31671. );
  31672. if (props || directives.length) {
  31673. propsExp = buildSSRProps(props, directives, context);
  31674. }
  31675. }
  31676. const wipEntries = [];
  31677. wipMap.set(node, wipEntries);
  31678. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  31679. const param0 = props && stringifyExpression(props) || `_`;
  31680. const fn = createFunctionExpression(
  31681. [param0, `_push`, `_parent`, `_scopeId`],
  31682. void 0,
  31683. // no return, assign body later
  31684. true,
  31685. // newline
  31686. true,
  31687. // isSlot
  31688. loc
  31689. );
  31690. wipEntries.push({
  31691. type: WIP_SLOT,
  31692. fn,
  31693. children,
  31694. // also collect the corresponding vnode branch built earlier
  31695. vnodeBranch: vnodeBranches[wipEntries.length]
  31696. });
  31697. return fn;
  31698. };
  31699. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31700. if (typeof component !== "string") {
  31701. node.ssrCodegenNode = createCallExpression(
  31702. context.helper(SSR_RENDER_VNODE),
  31703. [
  31704. `_push`,
  31705. createCallExpression(context.helper(CREATE_VNODE), [
  31706. component,
  31707. propsExp,
  31708. slots
  31709. ]),
  31710. `_parent`
  31711. ]
  31712. );
  31713. } else {
  31714. node.ssrCodegenNode = createCallExpression(
  31715. context.helper(SSR_RENDER_COMPONENT),
  31716. [component, propsExp, slots, `_parent`]
  31717. );
  31718. }
  31719. };
  31720. };
  31721. function ssrProcessComponent(node, context, parent) {
  31722. const component = componentTypeMap.get(node);
  31723. if (!node.ssrCodegenNode) {
  31724. if (component === TELEPORT) {
  31725. return ssrProcessTeleport(node, context);
  31726. } else if (component === SUSPENSE) {
  31727. return ssrProcessSuspense(node, context);
  31728. } else if (component === TRANSITION_GROUP) {
  31729. return ssrProcessTransitionGroup(node, context);
  31730. } else {
  31731. if (parent.type === WIP_SLOT) {
  31732. context.pushStringPart(``);
  31733. }
  31734. if (component === TRANSITION) {
  31735. return ssrProcessTransition(node, context);
  31736. }
  31737. processChildren(node, context);
  31738. }
  31739. } else {
  31740. const wipEntries = wipMap.get(node) || [];
  31741. for (let i = 0; i < wipEntries.length; i++) {
  31742. const { fn, vnodeBranch } = wipEntries[i];
  31743. fn.body = createIfStatement(
  31744. createSimpleExpression(`_push`, false),
  31745. processChildrenAsStatement(
  31746. wipEntries[i],
  31747. context,
  31748. false,
  31749. true
  31750. ),
  31751. vnodeBranch
  31752. );
  31753. }
  31754. if (context.withSlotScopeId) {
  31755. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31756. }
  31757. if (typeof component === "string") {
  31758. context.pushStatement(
  31759. createCallExpression(`_push`, [node.ssrCodegenNode])
  31760. );
  31761. } else {
  31762. context.pushStatement(node.ssrCodegenNode);
  31763. }
  31764. }
  31765. }
  31766. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31767. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31768. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31769. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31770. function createVNodeSlotBranch(slotProps, vFor, children, parentContext) {
  31771. const rawOptions = rawOptionsMap.get(parentContext.root);
  31772. const subOptions = __spreadProps$7(__spreadValues$8({}, rawOptions), {
  31773. // overwrite with vnode-based transforms
  31774. nodeTransforms: [
  31775. ...vnodeNodeTransforms,
  31776. ...rawOptions.nodeTransforms || []
  31777. ],
  31778. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31779. });
  31780. const wrapperProps = [];
  31781. if (slotProps) {
  31782. wrapperProps.push({
  31783. type: 7,
  31784. name: "slot",
  31785. exp: slotProps,
  31786. arg: void 0,
  31787. modifiers: [],
  31788. loc: locStub
  31789. });
  31790. }
  31791. if (vFor) {
  31792. wrapperProps.push(extend({}, vFor));
  31793. }
  31794. const wrapperNode = {
  31795. type: 1,
  31796. ns: 0,
  31797. tag: "template",
  31798. tagType: 3,
  31799. props: wrapperProps,
  31800. children,
  31801. loc: locStub,
  31802. codegenNode: void 0
  31803. };
  31804. subTransform(wrapperNode, subOptions, parentContext);
  31805. return createReturnStatement(children);
  31806. }
  31807. function subTransform(node, options, parentContext) {
  31808. const childRoot = createRoot([node]);
  31809. const childContext = createTransformContext(childRoot, options);
  31810. childContext.ssr = false;
  31811. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31812. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31813. childContext.imports = parentContext.imports;
  31814. traverseNode(childRoot, childContext);
  31815. ["helpers", "components", "directives"].forEach((key) => {
  31816. childContext[key].forEach((value, helperKey) => {
  31817. if (key === "helpers") {
  31818. const parentCount = parentContext.helpers.get(helperKey);
  31819. if (parentCount === void 0) {
  31820. parentContext.helpers.set(helperKey, value);
  31821. } else {
  31822. parentContext.helpers.set(helperKey, value + parentCount);
  31823. }
  31824. } else {
  31825. parentContext[key].add(value);
  31826. }
  31827. });
  31828. });
  31829. }
  31830. function clone(v) {
  31831. if (isArray$3(v)) {
  31832. return v.map(clone);
  31833. } else if (isPlainObject(v)) {
  31834. const res = {};
  31835. for (const key in v) {
  31836. res[key] = clone(v[key]);
  31837. }
  31838. return res;
  31839. } else {
  31840. return v;
  31841. }
  31842. }
  31843. function ssrCodegenTransform(ast, options) {
  31844. const context = createSSRTransformContext(ast, options);
  31845. if (options.ssrCssVars) {
  31846. const cssContext = createTransformContext(createRoot([]), options);
  31847. const varsExp = processExpression(
  31848. createSimpleExpression(options.ssrCssVars, false),
  31849. cssContext
  31850. );
  31851. context.body.push(
  31852. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31853. );
  31854. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31855. ast.helpers.add(helper);
  31856. });
  31857. }
  31858. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31859. processChildren(ast, context, isFragment);
  31860. ast.codegenNode = createBlockStatement(context.body);
  31861. ast.ssrHelpers = Array.from(
  31862. /* @__PURE__ */ new Set([
  31863. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31864. ...context.helpers
  31865. ])
  31866. );
  31867. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31868. }
  31869. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31870. const body = [];
  31871. let currentString = null;
  31872. return {
  31873. root,
  31874. options,
  31875. body,
  31876. helpers,
  31877. withSlotScopeId,
  31878. onError: options.onError || ((e) => {
  31879. throw e;
  31880. }),
  31881. helper(name) {
  31882. helpers.add(name);
  31883. return name;
  31884. },
  31885. pushStringPart(part) {
  31886. if (!currentString) {
  31887. const currentCall = createCallExpression(`_push`);
  31888. body.push(currentCall);
  31889. currentString = createTemplateLiteral([]);
  31890. currentCall.arguments.push(currentString);
  31891. }
  31892. const bufferedElements = currentString.elements;
  31893. const lastItem = bufferedElements[bufferedElements.length - 1];
  31894. if (isString$1(part) && isString$1(lastItem)) {
  31895. bufferedElements[bufferedElements.length - 1] += part;
  31896. } else {
  31897. bufferedElements.push(part);
  31898. }
  31899. },
  31900. pushStatement(statement) {
  31901. currentString = null;
  31902. body.push(statement);
  31903. }
  31904. };
  31905. }
  31906. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31907. return createSSRTransformContext(
  31908. parent.root,
  31909. parent.options,
  31910. parent.helpers,
  31911. withSlotScopeId
  31912. );
  31913. }
  31914. function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableComment = false) {
  31915. if (asFragment) {
  31916. context.pushStringPart(`<!--[-->`);
  31917. }
  31918. const { children } = parent;
  31919. for (let i = 0; i < children.length; i++) {
  31920. const child = children[i];
  31921. switch (child.type) {
  31922. case 1:
  31923. switch (child.tagType) {
  31924. case 0:
  31925. ssrProcessElement(child, context);
  31926. break;
  31927. case 1:
  31928. ssrProcessComponent(child, context, parent);
  31929. break;
  31930. case 2:
  31931. ssrProcessSlotOutlet(child, context);
  31932. break;
  31933. case 3:
  31934. break;
  31935. default:
  31936. context.onError(
  31937. createSSRCompilerError(
  31938. 67,
  31939. child.loc
  31940. )
  31941. );
  31942. const exhaustiveCheck2 = child;
  31943. return exhaustiveCheck2;
  31944. }
  31945. break;
  31946. case 2:
  31947. context.pushStringPart(escapeHtml(child.content));
  31948. break;
  31949. case 3:
  31950. if (!disableComment) {
  31951. context.pushStringPart(`<!--${child.content}-->`);
  31952. }
  31953. break;
  31954. case 5:
  31955. context.pushStringPart(
  31956. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31957. child.content
  31958. ])
  31959. );
  31960. break;
  31961. case 9:
  31962. ssrProcessIf(child, context, disableNestedFragments, disableComment);
  31963. break;
  31964. case 11:
  31965. ssrProcessFor(child, context, disableNestedFragments);
  31966. break;
  31967. case 10:
  31968. break;
  31969. case 12:
  31970. case 8:
  31971. break;
  31972. default:
  31973. context.onError(
  31974. createSSRCompilerError(
  31975. 67,
  31976. child.loc
  31977. )
  31978. );
  31979. const exhaustiveCheck = child;
  31980. return exhaustiveCheck;
  31981. }
  31982. }
  31983. if (asFragment) {
  31984. context.pushStringPart(`<!--]-->`);
  31985. }
  31986. }
  31987. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  31988. const childContext = createChildContext(parentContext, withSlotScopeId);
  31989. processChildren(parent, childContext, asFragment);
  31990. return createBlockStatement(childContext.body);
  31991. }
  31992. const ssrTransformModel = (dir, node, context) => {
  31993. const model = dir.exp;
  31994. function checkDuplicatedValue() {
  31995. const value = findProp(node, "value");
  31996. if (value) {
  31997. context.onError(
  31998. createDOMCompilerError(
  31999. 61,
  32000. value.loc
  32001. )
  32002. );
  32003. }
  32004. }
  32005. const processSelectChildren = (children) => {
  32006. children.forEach((child) => {
  32007. if (child.type === 1) {
  32008. processOption(child);
  32009. } else if (child.type === 11) {
  32010. processSelectChildren(child.children);
  32011. } else if (child.type === 9) {
  32012. child.branches.forEach((b) => processSelectChildren(b.children));
  32013. }
  32014. });
  32015. };
  32016. function processOption(plainNode) {
  32017. if (plainNode.tag === "option") {
  32018. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  32019. const value = findValueBinding(plainNode);
  32020. plainNode.ssrCodegenNode.elements.push(
  32021. createConditionalExpression(
  32022. createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  32023. createConditionalExpression(
  32024. createCallExpression(`Array.isArray`, [model]),
  32025. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  32026. model,
  32027. value
  32028. ]),
  32029. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32030. model,
  32031. value
  32032. ])
  32033. )
  32034. ]),
  32035. createSimpleExpression(" selected", true),
  32036. createSimpleExpression("", true),
  32037. false
  32038. )
  32039. );
  32040. }
  32041. } else if (plainNode.tag === "optgroup") {
  32042. processSelectChildren(plainNode.children);
  32043. }
  32044. }
  32045. if (node.tagType === 0) {
  32046. const res = { props: [] };
  32047. if (node.tag === "input") {
  32048. const defaultProps = [
  32049. // default value binding for text type inputs
  32050. createObjectProperty(`value`, model)
  32051. ];
  32052. const type = findProp(node, "type");
  32053. if (type) {
  32054. const value = findValueBinding(node);
  32055. if (type.type === 7) {
  32056. res.ssrTagParts = [
  32057. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  32058. type.exp,
  32059. model,
  32060. value
  32061. ])
  32062. ];
  32063. } else if (type.value) {
  32064. switch (type.value.content) {
  32065. case "radio":
  32066. res.props = [
  32067. createObjectProperty(
  32068. `checked`,
  32069. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32070. model,
  32071. value
  32072. ])
  32073. )
  32074. ];
  32075. break;
  32076. case "checkbox":
  32077. const trueValueBinding = findProp(node, "true-value");
  32078. if (trueValueBinding) {
  32079. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  32080. res.props = [
  32081. createObjectProperty(
  32082. `checked`,
  32083. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  32084. model,
  32085. trueValue
  32086. ])
  32087. )
  32088. ];
  32089. } else {
  32090. res.props = [
  32091. createObjectProperty(
  32092. `checked`,
  32093. createConditionalExpression(
  32094. createCallExpression(`Array.isArray`, [model]),
  32095. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  32096. model,
  32097. value
  32098. ]),
  32099. model
  32100. )
  32101. )
  32102. ];
  32103. }
  32104. break;
  32105. case "file":
  32106. context.onError(
  32107. createDOMCompilerError(
  32108. 60,
  32109. dir.loc
  32110. )
  32111. );
  32112. break;
  32113. default:
  32114. checkDuplicatedValue();
  32115. res.props = defaultProps;
  32116. break;
  32117. }
  32118. }
  32119. } else if (hasDynamicKeyVBind(node)) ; else {
  32120. checkDuplicatedValue();
  32121. res.props = defaultProps;
  32122. }
  32123. } else if (node.tag === "textarea") {
  32124. checkDuplicatedValue();
  32125. node.children = [createInterpolation(model, model.loc)];
  32126. } else if (node.tag === "select") {
  32127. processSelectChildren(node.children);
  32128. } else {
  32129. context.onError(
  32130. createDOMCompilerError(
  32131. 58,
  32132. dir.loc
  32133. )
  32134. );
  32135. }
  32136. return res;
  32137. } else {
  32138. return transformModel$1(dir, node, context);
  32139. }
  32140. };
  32141. function findValueBinding(node) {
  32142. const valueBinding = findProp(node, "value");
  32143. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  32144. }
  32145. const ssrTransformShow = (dir, node, context) => {
  32146. if (!dir.exp) {
  32147. context.onError(
  32148. createDOMCompilerError(62)
  32149. );
  32150. }
  32151. return {
  32152. props: [
  32153. createObjectProperty(
  32154. `style`,
  32155. createConditionalExpression(
  32156. dir.exp,
  32157. createSimpleExpression(`null`, false),
  32158. createObjectExpression([
  32159. createObjectProperty(
  32160. `display`,
  32161. createSimpleExpression(`none`, true)
  32162. )
  32163. ]),
  32164. false
  32165. )
  32166. )
  32167. ]
  32168. };
  32169. };
  32170. const filterChild = (node) => node.children.filter((n) => !isCommentOrWhitespace(n));
  32171. const hasSingleChild = (node) => filterChild(node).length === 1;
  32172. const ssrInjectFallthroughAttrs = (node, context) => {
  32173. if (node.type === 0) {
  32174. context.identifiers._attrs = 1;
  32175. }
  32176. if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) {
  32177. const rootChildren = filterChild(context.root);
  32178. if (rootChildren.length === 1 && rootChildren[0] === node) {
  32179. if (hasSingleChild(node)) {
  32180. injectFallthroughAttrs(node.children[0]);
  32181. }
  32182. return;
  32183. }
  32184. }
  32185. const parent = context.parent;
  32186. if (!parent || parent.type !== 0) {
  32187. return;
  32188. }
  32189. if (node.type === 10 && hasSingleChild(node)) {
  32190. let hasEncounteredIf = false;
  32191. for (const c of filterChild(parent)) {
  32192. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  32193. if (hasEncounteredIf) return;
  32194. hasEncounteredIf = true;
  32195. } else if (
  32196. // node before v-if
  32197. !hasEncounteredIf || // non else nodes
  32198. !(c.type === 1 && findDir(c, /else/, true))
  32199. ) {
  32200. return;
  32201. }
  32202. }
  32203. injectFallthroughAttrs(node.children[0]);
  32204. } else if (hasSingleChild(parent)) {
  32205. injectFallthroughAttrs(node);
  32206. }
  32207. };
  32208. function injectFallthroughAttrs(node) {
  32209. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32210. node.props.push({
  32211. type: 7,
  32212. name: "bind",
  32213. arg: void 0,
  32214. exp: createSimpleExpression(`_attrs`, false),
  32215. modifiers: [],
  32216. loc: locStub
  32217. });
  32218. }
  32219. }
  32220. const ssrInjectCssVars = (node, context) => {
  32221. if (!context.ssrCssVars) {
  32222. return;
  32223. }
  32224. if (node.type === 0) {
  32225. context.identifiers._cssVars = 1;
  32226. }
  32227. const parent = context.parent;
  32228. if (!parent || parent.type !== 0) {
  32229. return;
  32230. }
  32231. if (node.type === 10) {
  32232. for (const child of node.children) {
  32233. injectCssVars(child);
  32234. }
  32235. } else {
  32236. injectCssVars(node);
  32237. }
  32238. };
  32239. function injectCssVars(node) {
  32240. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32241. if (node.tag === "suspense" || node.tag === "Suspense") {
  32242. for (const child of node.children) {
  32243. if (child.type === 1 && child.tagType === 3) {
  32244. child.children.forEach(injectCssVars);
  32245. } else {
  32246. injectCssVars(child);
  32247. }
  32248. }
  32249. } else {
  32250. node.props.push({
  32251. type: 7,
  32252. name: "bind",
  32253. arg: void 0,
  32254. exp: createSimpleExpression(`_cssVars`, false),
  32255. modifiers: [],
  32256. loc: locStub
  32257. });
  32258. }
  32259. }
  32260. }
  32261. var __defProp$7 = Object.defineProperty;
  32262. var __defProps$6 = Object.defineProperties;
  32263. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  32264. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  32265. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  32266. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  32267. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32268. var __spreadValues$7 = (a, b) => {
  32269. for (var prop in b || (b = {}))
  32270. if (__hasOwnProp$7.call(b, prop))
  32271. __defNormalProp$7(a, prop, b[prop]);
  32272. if (__getOwnPropSymbols$7)
  32273. for (var prop of __getOwnPropSymbols$7(b)) {
  32274. if (__propIsEnum$7.call(b, prop))
  32275. __defNormalProp$7(a, prop, b[prop]);
  32276. }
  32277. return a;
  32278. };
  32279. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  32280. function compile(source, options = {}) {
  32281. options = __spreadProps$6(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  32282. ssr: true,
  32283. inSSR: true,
  32284. scopeId: options.mode === "function" ? null : options.scopeId,
  32285. // always prefix since compiler-ssr doesn't have size concern
  32286. prefixIdentifiers: true,
  32287. // disable optimizations that are unnecessary for ssr
  32288. cacheHandlers: false,
  32289. hoistStatic: false
  32290. });
  32291. const ast = typeof source === "string" ? baseParse(source, options) : source;
  32292. rawOptionsMap.set(ast, options);
  32293. transform(ast, __spreadProps$6(__spreadValues$7({}, options), {
  32294. hoistStatic: false,
  32295. nodeTransforms: [
  32296. transformVBindShorthand,
  32297. ssrTransformIf,
  32298. ssrTransformFor,
  32299. trackVForSlotScopes,
  32300. transformExpression,
  32301. ssrTransformSlotOutlet,
  32302. ssrInjectFallthroughAttrs,
  32303. ssrInjectCssVars,
  32304. ssrTransformElement,
  32305. ssrTransformComponent,
  32306. trackSlotScopes,
  32307. transformStyle,
  32308. ...options.nodeTransforms || []
  32309. // user transforms
  32310. ],
  32311. directiveTransforms: __spreadValues$7({
  32312. // reusing core v-bind
  32313. bind: transformBind,
  32314. on: transformOn$1,
  32315. // model and show have dedicated SSR handling
  32316. model: ssrTransformModel,
  32317. show: ssrTransformShow,
  32318. // the following are ignored during SSR
  32319. // on: noopDirectiveTransform,
  32320. cloak: noopDirectiveTransform,
  32321. once: noopDirectiveTransform,
  32322. memo: noopDirectiveTransform
  32323. }, options.directiveTransforms || {})
  32324. }));
  32325. ssrCodegenTransform(ast, options);
  32326. return generate(ast, options);
  32327. }
  32328. var CompilerSSR = /*#__PURE__*/Object.freeze({
  32329. __proto__: null,
  32330. compile: compile
  32331. });
  32332. var _polyfillNode_fs = {};
  32333. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  32334. __proto__: null,
  32335. default: _polyfillNode_fs
  32336. });
  32337. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  32338. var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  32339. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  32340. const hasWarned = {};
  32341. function warnOnce$1(msg) {
  32342. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  32343. if (!isNodeProd && true && !hasWarned[msg]) {
  32344. hasWarned[msg] = true;
  32345. warn(msg);
  32346. }
  32347. }
  32348. function warn(msg) {
  32349. console.warn(
  32350. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  32351. `
  32352. );
  32353. }
  32354. var __defProp$6 = Object.defineProperty;
  32355. var __defProps$5 = Object.defineProperties;
  32356. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  32357. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  32358. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  32359. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  32360. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32361. var __spreadValues$6 = (a, b) => {
  32362. for (var prop in b || (b = {}))
  32363. if (__hasOwnProp$6.call(b, prop))
  32364. __defNormalProp$6(a, prop, b[prop]);
  32365. if (__getOwnPropSymbols$6)
  32366. for (var prop of __getOwnPropSymbols$6(b)) {
  32367. if (__propIsEnum$6.call(b, prop))
  32368. __defNormalProp$6(a, prop, b[prop]);
  32369. }
  32370. return a;
  32371. };
  32372. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  32373. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  32374. let res = "";
  32375. let err = null;
  32376. preprocessor.render(
  32377. source,
  32378. __spreadValues$6({ filename }, preprocessOptions),
  32379. (_err, _res) => {
  32380. if (_err) err = _err;
  32381. res = _res;
  32382. }
  32383. );
  32384. if (err) throw err;
  32385. return res;
  32386. }
  32387. function compileTemplate(options) {
  32388. const { preprocessLang, preprocessCustomRequire } = options;
  32389. if (preprocessLang && !preprocessCustomRequire) {
  32390. throw new Error(
  32391. `[@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 }.`
  32392. );
  32393. }
  32394. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  32395. if (preprocessor) {
  32396. try {
  32397. return doCompileTemplate(__spreadProps$5(__spreadValues$6({}, options), {
  32398. source: preprocess$1(options, preprocessor),
  32399. ast: void 0
  32400. // invalidate AST if template goes through preprocessor
  32401. }));
  32402. } catch (e) {
  32403. return {
  32404. code: `export default function render() {}`,
  32405. source: options.source,
  32406. tips: [],
  32407. errors: [e]
  32408. };
  32409. }
  32410. } else if (preprocessLang) {
  32411. return {
  32412. code: `export default function render() {}`,
  32413. source: options.source,
  32414. tips: [
  32415. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  32416. ],
  32417. errors: [
  32418. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  32419. ]
  32420. };
  32421. } else {
  32422. return doCompileTemplate(options);
  32423. }
  32424. }
  32425. function doCompileTemplate({
  32426. filename,
  32427. id,
  32428. scoped,
  32429. slotted,
  32430. inMap,
  32431. source,
  32432. ast: inAST,
  32433. ssr = false,
  32434. ssrCssVars,
  32435. isProd = false,
  32436. compiler,
  32437. compilerOptions = {},
  32438. transformAssetUrls
  32439. }) {
  32440. const errors = [];
  32441. const warnings = [];
  32442. let nodeTransforms = [];
  32443. if (isObject$2(transformAssetUrls)) {
  32444. const assetOptions = normalizeOptions(transformAssetUrls);
  32445. nodeTransforms = [
  32446. createAssetUrlTransformWithOptions(assetOptions),
  32447. createSrcsetTransformWithOptions(assetOptions)
  32448. ];
  32449. } else if (transformAssetUrls !== false) {
  32450. nodeTransforms = [transformAssetUrl, transformSrcset];
  32451. }
  32452. if (ssr && !ssrCssVars) {
  32453. warnOnce$1(
  32454. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.`
  32455. );
  32456. }
  32457. if (!id) {
  32458. warnOnce$1(`compileTemplate now requires the \`id\` option.`);
  32459. id = "";
  32460. }
  32461. const shortId = id.replace(/^data-v-/, "");
  32462. const longId = `data-v-${shortId}`;
  32463. const defaultCompiler = ssr ? CompilerSSR : CompilerDOM;
  32464. compiler = compiler || defaultCompiler;
  32465. if (compiler !== defaultCompiler) {
  32466. inAST = void 0;
  32467. }
  32468. if (inAST == null ? void 0 : inAST.transformed) {
  32469. const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, __spreadProps$5(__spreadValues$6({
  32470. prefixIdentifiers: true
  32471. }, compilerOptions), {
  32472. parseMode: "sfc",
  32473. onError: (e) => errors.push(e)
  32474. }));
  32475. const template = newAST.children.find(
  32476. (node) => node.type === 1 && node.tag === "template"
  32477. );
  32478. inAST = createRoot(template.children, inAST.source);
  32479. }
  32480. let { code, ast, preamble, map } = compiler.compile(inAST || source, __spreadProps$5(__spreadValues$6({
  32481. mode: "module",
  32482. prefixIdentifiers: true,
  32483. hoistStatic: true,
  32484. cacheHandlers: true,
  32485. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32486. scopeId: scoped ? longId : void 0,
  32487. slotted,
  32488. sourceMap: true
  32489. }, compilerOptions), {
  32490. hmr: !isProd,
  32491. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32492. filename,
  32493. onError: (e) => errors.push(e),
  32494. onWarn: (w) => warnings.push(w)
  32495. }));
  32496. if (inMap && !inAST) {
  32497. if (map) {
  32498. map = mapLines(inMap, map);
  32499. }
  32500. if (errors.length) {
  32501. patchErrors(errors, source, inMap);
  32502. }
  32503. }
  32504. const tips = warnings.map((w) => {
  32505. let msg = w.message;
  32506. if (w.loc) {
  32507. msg += `
  32508. ${generateCodeFrame(
  32509. (inAST == null ? void 0 : inAST.source) || source,
  32510. w.loc.start.offset,
  32511. w.loc.end.offset
  32512. )}`;
  32513. }
  32514. return msg;
  32515. });
  32516. return { code, ast, preamble, source, errors, tips, map };
  32517. }
  32518. function mapLines(oldMap, newMap) {
  32519. if (!oldMap) return newMap;
  32520. if (!newMap) return oldMap;
  32521. const oldMapConsumer = new sourceMapExports.SourceMapConsumer(oldMap);
  32522. const newMapConsumer = new sourceMapExports.SourceMapConsumer(newMap);
  32523. const mergedMapGenerator = new sourceMapExports.SourceMapGenerator();
  32524. newMapConsumer.eachMapping((m) => {
  32525. if (m.originalLine == null) {
  32526. return;
  32527. }
  32528. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32529. line: m.originalLine,
  32530. column: m.originalColumn
  32531. });
  32532. if (origPosInOldMap.source == null) {
  32533. return;
  32534. }
  32535. mergedMapGenerator.addMapping({
  32536. generated: {
  32537. line: m.generatedLine,
  32538. column: m.generatedColumn
  32539. },
  32540. original: {
  32541. line: origPosInOldMap.line,
  32542. // map line
  32543. // use current column, since the oldMap produced by @vue/compiler-sfc
  32544. // does not
  32545. column: m.originalColumn
  32546. },
  32547. source: origPosInOldMap.source,
  32548. name: origPosInOldMap.name
  32549. });
  32550. });
  32551. const generator = mergedMapGenerator;
  32552. oldMapConsumer.sources.forEach((sourceFile) => {
  32553. generator._sources.add(sourceFile);
  32554. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32555. if (sourceContent != null) {
  32556. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32557. }
  32558. });
  32559. generator._sourceRoot = oldMap.sourceRoot;
  32560. generator._file = oldMap.file;
  32561. return generator.toJSON();
  32562. }
  32563. function patchErrors(errors, source, inMap) {
  32564. const originalSource = inMap.sourcesContent[0];
  32565. const offset = originalSource.indexOf(source);
  32566. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32567. errors.forEach((err) => {
  32568. if (err.loc) {
  32569. err.loc.start.line += lineOffset;
  32570. err.loc.start.offset += offset;
  32571. if (err.loc.end !== err.loc.start) {
  32572. err.loc.end.line += lineOffset;
  32573. err.loc.end.offset += offset;
  32574. }
  32575. }
  32576. });
  32577. }
  32578. var picocolors = {exports: {}};
  32579. var hasRequiredPicocolors;
  32580. function requirePicocolors () {
  32581. if (hasRequiredPicocolors) return picocolors.exports;
  32582. hasRequiredPicocolors = 1;
  32583. let p = browser$1 || {}, argv = p.argv || [], env = p.env || {};
  32584. let isColorSupported =
  32585. !(!!env.NO_COLOR || argv.includes("--no-color")) &&
  32586. (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
  32587. let formatter = (open, close, replace = open) =>
  32588. input => {
  32589. let string = "" + input, index = string.indexOf(close, open.length);
  32590. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
  32591. };
  32592. let replaceClose = (string, close, replace, index) => {
  32593. let result = "", cursor = 0;
  32594. do {
  32595. result += string.substring(cursor, index) + replace;
  32596. cursor = index + close.length;
  32597. index = string.indexOf(close, cursor);
  32598. } while (~index)
  32599. return result + string.substring(cursor)
  32600. };
  32601. let createColors = (enabled = isColorSupported) => {
  32602. let f = enabled ? formatter : () => String;
  32603. return {
  32604. isColorSupported: enabled,
  32605. reset: f("\x1b[0m", "\x1b[0m"),
  32606. bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
  32607. dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
  32608. italic: f("\x1b[3m", "\x1b[23m"),
  32609. underline: f("\x1b[4m", "\x1b[24m"),
  32610. inverse: f("\x1b[7m", "\x1b[27m"),
  32611. hidden: f("\x1b[8m", "\x1b[28m"),
  32612. strikethrough: f("\x1b[9m", "\x1b[29m"),
  32613. black: f("\x1b[30m", "\x1b[39m"),
  32614. red: f("\x1b[31m", "\x1b[39m"),
  32615. green: f("\x1b[32m", "\x1b[39m"),
  32616. yellow: f("\x1b[33m", "\x1b[39m"),
  32617. blue: f("\x1b[34m", "\x1b[39m"),
  32618. magenta: f("\x1b[35m", "\x1b[39m"),
  32619. cyan: f("\x1b[36m", "\x1b[39m"),
  32620. white: f("\x1b[37m", "\x1b[39m"),
  32621. gray: f("\x1b[90m", "\x1b[39m"),
  32622. bgBlack: f("\x1b[40m", "\x1b[49m"),
  32623. bgRed: f("\x1b[41m", "\x1b[49m"),
  32624. bgGreen: f("\x1b[42m", "\x1b[49m"),
  32625. bgYellow: f("\x1b[43m", "\x1b[49m"),
  32626. bgBlue: f("\x1b[44m", "\x1b[49m"),
  32627. bgMagenta: f("\x1b[45m", "\x1b[49m"),
  32628. bgCyan: f("\x1b[46m", "\x1b[49m"),
  32629. bgWhite: f("\x1b[47m", "\x1b[49m"),
  32630. blackBright: f("\x1b[90m", "\x1b[39m"),
  32631. redBright: f("\x1b[91m", "\x1b[39m"),
  32632. greenBright: f("\x1b[92m", "\x1b[39m"),
  32633. yellowBright: f("\x1b[93m", "\x1b[39m"),
  32634. blueBright: f("\x1b[94m", "\x1b[39m"),
  32635. magentaBright: f("\x1b[95m", "\x1b[39m"),
  32636. cyanBright: f("\x1b[96m", "\x1b[39m"),
  32637. whiteBright: f("\x1b[97m", "\x1b[39m"),
  32638. bgBlackBright: f("\x1b[100m", "\x1b[49m"),
  32639. bgRedBright: f("\x1b[101m", "\x1b[49m"),
  32640. bgGreenBright: f("\x1b[102m", "\x1b[49m"),
  32641. bgYellowBright: f("\x1b[103m", "\x1b[49m"),
  32642. bgBlueBright: f("\x1b[104m", "\x1b[49m"),
  32643. bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
  32644. bgCyanBright: f("\x1b[106m", "\x1b[49m"),
  32645. bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
  32646. }
  32647. };
  32648. picocolors.exports = createColors();
  32649. picocolors.exports.createColors = createColors;
  32650. return picocolors.exports;
  32651. }
  32652. var tokenize$1;
  32653. var hasRequiredTokenize$1;
  32654. function requireTokenize$1 () {
  32655. if (hasRequiredTokenize$1) return tokenize$1;
  32656. hasRequiredTokenize$1 = 1;
  32657. const SINGLE_QUOTE = "'".charCodeAt(0);
  32658. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32659. const BACKSLASH = '\\'.charCodeAt(0);
  32660. const SLASH = '/'.charCodeAt(0);
  32661. const NEWLINE = '\n'.charCodeAt(0);
  32662. const SPACE = ' '.charCodeAt(0);
  32663. const FEED = '\f'.charCodeAt(0);
  32664. const TAB = '\t'.charCodeAt(0);
  32665. const CR = '\r'.charCodeAt(0);
  32666. const OPEN_SQUARE = '['.charCodeAt(0);
  32667. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32668. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32669. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32670. const OPEN_CURLY = '{'.charCodeAt(0);
  32671. const CLOSE_CURLY = '}'.charCodeAt(0);
  32672. const SEMICOLON = ';'.charCodeAt(0);
  32673. const ASTERISK = '*'.charCodeAt(0);
  32674. const COLON = ':'.charCodeAt(0);
  32675. const AT = '@'.charCodeAt(0);
  32676. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32677. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32678. const RE_BAD_BRACKET = /.[\r\n"'(/\\]/;
  32679. const RE_HEX_ESCAPE = /[\da-f]/i;
  32680. tokenize$1 = function tokenizer(input, options = {}) {
  32681. let css = input.css.valueOf();
  32682. let ignore = options.ignoreErrors;
  32683. let code, content, escape, next, quote;
  32684. let currentToken, escaped, escapePos, n, prev;
  32685. let length = css.length;
  32686. let pos = 0;
  32687. let buffer = [];
  32688. let returned = [];
  32689. function position() {
  32690. return pos
  32691. }
  32692. function unclosed(what) {
  32693. throw input.error('Unclosed ' + what, pos)
  32694. }
  32695. function endOfFile() {
  32696. return returned.length === 0 && pos >= length
  32697. }
  32698. function nextToken(opts) {
  32699. if (returned.length) return returned.pop()
  32700. if (pos >= length) return
  32701. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32702. code = css.charCodeAt(pos);
  32703. switch (code) {
  32704. case NEWLINE:
  32705. case SPACE:
  32706. case TAB:
  32707. case CR:
  32708. case FEED: {
  32709. next = pos;
  32710. do {
  32711. next += 1;
  32712. code = css.charCodeAt(next);
  32713. } while (
  32714. code === SPACE ||
  32715. code === NEWLINE ||
  32716. code === TAB ||
  32717. code === CR ||
  32718. code === FEED
  32719. )
  32720. currentToken = ['space', css.slice(pos, next)];
  32721. pos = next - 1;
  32722. break
  32723. }
  32724. case OPEN_SQUARE:
  32725. case CLOSE_SQUARE:
  32726. case OPEN_CURLY:
  32727. case CLOSE_CURLY:
  32728. case COLON:
  32729. case SEMICOLON:
  32730. case CLOSE_PARENTHESES: {
  32731. let controlChar = String.fromCharCode(code);
  32732. currentToken = [controlChar, controlChar, pos];
  32733. break
  32734. }
  32735. case OPEN_PARENTHESES: {
  32736. prev = buffer.length ? buffer.pop()[1] : '';
  32737. n = css.charCodeAt(pos + 1);
  32738. if (
  32739. prev === 'url' &&
  32740. n !== SINGLE_QUOTE &&
  32741. n !== DOUBLE_QUOTE &&
  32742. n !== SPACE &&
  32743. n !== NEWLINE &&
  32744. n !== TAB &&
  32745. n !== FEED &&
  32746. n !== CR
  32747. ) {
  32748. next = pos;
  32749. do {
  32750. escaped = false;
  32751. next = css.indexOf(')', next + 1);
  32752. if (next === -1) {
  32753. if (ignore || ignoreUnclosed) {
  32754. next = pos;
  32755. break
  32756. } else {
  32757. unclosed('bracket');
  32758. }
  32759. }
  32760. escapePos = next;
  32761. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32762. escapePos -= 1;
  32763. escaped = !escaped;
  32764. }
  32765. } while (escaped)
  32766. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32767. pos = next;
  32768. } else {
  32769. next = css.indexOf(')', pos + 1);
  32770. content = css.slice(pos, next + 1);
  32771. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32772. currentToken = ['(', '(', pos];
  32773. } else {
  32774. currentToken = ['brackets', content, pos, next];
  32775. pos = next;
  32776. }
  32777. }
  32778. break
  32779. }
  32780. case SINGLE_QUOTE:
  32781. case DOUBLE_QUOTE: {
  32782. quote = code === SINGLE_QUOTE ? "'" : '"';
  32783. next = pos;
  32784. do {
  32785. escaped = false;
  32786. next = css.indexOf(quote, next + 1);
  32787. if (next === -1) {
  32788. if (ignore || ignoreUnclosed) {
  32789. next = pos + 1;
  32790. break
  32791. } else {
  32792. unclosed('string');
  32793. }
  32794. }
  32795. escapePos = next;
  32796. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32797. escapePos -= 1;
  32798. escaped = !escaped;
  32799. }
  32800. } while (escaped)
  32801. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32802. pos = next;
  32803. break
  32804. }
  32805. case AT: {
  32806. RE_AT_END.lastIndex = pos + 1;
  32807. RE_AT_END.test(css);
  32808. if (RE_AT_END.lastIndex === 0) {
  32809. next = css.length - 1;
  32810. } else {
  32811. next = RE_AT_END.lastIndex - 2;
  32812. }
  32813. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32814. pos = next;
  32815. break
  32816. }
  32817. case BACKSLASH: {
  32818. next = pos;
  32819. escape = true;
  32820. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32821. next += 1;
  32822. escape = !escape;
  32823. }
  32824. code = css.charCodeAt(next + 1);
  32825. if (
  32826. escape &&
  32827. code !== SLASH &&
  32828. code !== SPACE &&
  32829. code !== NEWLINE &&
  32830. code !== TAB &&
  32831. code !== CR &&
  32832. code !== FEED
  32833. ) {
  32834. next += 1;
  32835. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32836. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32837. next += 1;
  32838. }
  32839. if (css.charCodeAt(next + 1) === SPACE) {
  32840. next += 1;
  32841. }
  32842. }
  32843. }
  32844. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32845. pos = next;
  32846. break
  32847. }
  32848. default: {
  32849. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32850. next = css.indexOf('*/', pos + 2) + 1;
  32851. if (next === 0) {
  32852. if (ignore || ignoreUnclosed) {
  32853. next = css.length;
  32854. } else {
  32855. unclosed('comment');
  32856. }
  32857. }
  32858. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32859. pos = next;
  32860. } else {
  32861. RE_WORD_END.lastIndex = pos + 1;
  32862. RE_WORD_END.test(css);
  32863. if (RE_WORD_END.lastIndex === 0) {
  32864. next = css.length - 1;
  32865. } else {
  32866. next = RE_WORD_END.lastIndex - 2;
  32867. }
  32868. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32869. buffer.push(currentToken);
  32870. pos = next;
  32871. }
  32872. break
  32873. }
  32874. }
  32875. pos++;
  32876. return currentToken
  32877. }
  32878. function back(token) {
  32879. returned.push(token);
  32880. }
  32881. return {
  32882. back,
  32883. endOfFile,
  32884. nextToken,
  32885. position
  32886. }
  32887. };
  32888. return tokenize$1;
  32889. }
  32890. var terminalHighlight_1;
  32891. var hasRequiredTerminalHighlight;
  32892. function requireTerminalHighlight () {
  32893. if (hasRequiredTerminalHighlight) return terminalHighlight_1;
  32894. hasRequiredTerminalHighlight = 1;
  32895. let pico = /*@__PURE__*/ requirePicocolors();
  32896. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  32897. let Input;
  32898. function registerInput(dependant) {
  32899. Input = dependant;
  32900. }
  32901. const HIGHLIGHT_THEME = {
  32902. ';': pico.yellow,
  32903. ':': pico.yellow,
  32904. '(': pico.cyan,
  32905. ')': pico.cyan,
  32906. '[': pico.yellow,
  32907. ']': pico.yellow,
  32908. '{': pico.yellow,
  32909. '}': pico.yellow,
  32910. 'at-word': pico.cyan,
  32911. 'brackets': pico.cyan,
  32912. 'call': pico.cyan,
  32913. 'class': pico.yellow,
  32914. 'comment': pico.gray,
  32915. 'hash': pico.magenta,
  32916. 'string': pico.green
  32917. };
  32918. function getTokenType([type, value], processor) {
  32919. if (type === 'word') {
  32920. if (value[0] === '.') {
  32921. return 'class'
  32922. }
  32923. if (value[0] === '#') {
  32924. return 'hash'
  32925. }
  32926. }
  32927. if (!processor.endOfFile()) {
  32928. let next = processor.nextToken();
  32929. processor.back(next);
  32930. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32931. }
  32932. return type
  32933. }
  32934. function terminalHighlight(css) {
  32935. let processor = tokenizer(new Input(css), { ignoreErrors: true });
  32936. let result = '';
  32937. while (!processor.endOfFile()) {
  32938. let token = processor.nextToken();
  32939. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32940. if (color) {
  32941. result += token[1]
  32942. .split(/\r?\n/)
  32943. .map(i => color(i))
  32944. .join('\n');
  32945. } else {
  32946. result += token[1];
  32947. }
  32948. }
  32949. return result
  32950. }
  32951. terminalHighlight.registerInput = registerInput;
  32952. terminalHighlight_1 = terminalHighlight;
  32953. return terminalHighlight_1;
  32954. }
  32955. var cssSyntaxError;
  32956. var hasRequiredCssSyntaxError;
  32957. function requireCssSyntaxError () {
  32958. if (hasRequiredCssSyntaxError) return cssSyntaxError;
  32959. hasRequiredCssSyntaxError = 1;
  32960. let pico = /*@__PURE__*/ requirePicocolors();
  32961. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  32962. class CssSyntaxError extends Error {
  32963. constructor(message, line, column, source, file, plugin) {
  32964. super(message);
  32965. this.name = 'CssSyntaxError';
  32966. this.reason = message;
  32967. if (file) {
  32968. this.file = file;
  32969. }
  32970. if (source) {
  32971. this.source = source;
  32972. }
  32973. if (plugin) {
  32974. this.plugin = plugin;
  32975. }
  32976. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  32977. if (typeof line === 'number') {
  32978. this.line = line;
  32979. this.column = column;
  32980. } else {
  32981. this.line = line.line;
  32982. this.column = line.column;
  32983. this.endLine = column.line;
  32984. this.endColumn = column.column;
  32985. }
  32986. }
  32987. this.setMessage();
  32988. if (Error.captureStackTrace) {
  32989. Error.captureStackTrace(this, CssSyntaxError);
  32990. }
  32991. }
  32992. setMessage() {
  32993. this.message = this.plugin ? this.plugin + ': ' : '';
  32994. this.message += this.file ? this.file : '<css input>';
  32995. if (typeof this.line !== 'undefined') {
  32996. this.message += ':' + this.line + ':' + this.column;
  32997. }
  32998. this.message += ': ' + this.reason;
  32999. }
  33000. showSourceCode(color) {
  33001. if (!this.source) return ''
  33002. let css = this.source;
  33003. if (color == null) color = pico.isColorSupported;
  33004. let aside = text => text;
  33005. let mark = text => text;
  33006. let highlight = text => text;
  33007. if (color) {
  33008. let { bold, gray, red } = pico.createColors(true);
  33009. mark = text => bold(red(text));
  33010. aside = text => gray(text);
  33011. if (terminalHighlight) {
  33012. highlight = text => terminalHighlight(text);
  33013. }
  33014. }
  33015. let lines = css.split(/\r?\n/);
  33016. let start = Math.max(this.line - 3, 0);
  33017. let end = Math.min(this.line + 2, lines.length);
  33018. let maxWidth = String(end).length;
  33019. return lines
  33020. .slice(start, end)
  33021. .map((line, index) => {
  33022. let number = start + 1 + index;
  33023. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  33024. if (number === this.line) {
  33025. if (line.length > 160) {
  33026. let padding = 20;
  33027. let subLineStart = Math.max(0, this.column - padding);
  33028. let subLineEnd = Math.max(
  33029. this.column + padding,
  33030. this.endColumn + padding
  33031. );
  33032. let subLine = line.slice(subLineStart, subLineEnd);
  33033. let spacing =
  33034. aside(gutter.replace(/\d/g, ' ')) +
  33035. line
  33036. .slice(0, Math.min(this.column - 1, padding - 1))
  33037. .replace(/[^\t]/g, ' ');
  33038. return (
  33039. mark('>') +
  33040. aside(gutter) +
  33041. highlight(subLine) +
  33042. '\n ' +
  33043. spacing +
  33044. mark('^')
  33045. )
  33046. }
  33047. let spacing =
  33048. aside(gutter.replace(/\d/g, ' ')) +
  33049. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  33050. return (
  33051. mark('>') +
  33052. aside(gutter) +
  33053. highlight(line) +
  33054. '\n ' +
  33055. spacing +
  33056. mark('^')
  33057. )
  33058. }
  33059. return ' ' + aside(gutter) + highlight(line)
  33060. })
  33061. .join('\n')
  33062. }
  33063. toString() {
  33064. let code = this.showSourceCode();
  33065. if (code) {
  33066. code = '\n\n' + code + '\n';
  33067. }
  33068. return this.name + ': ' + this.message + code
  33069. }
  33070. }
  33071. cssSyntaxError = CssSyntaxError;
  33072. CssSyntaxError.default = CssSyntaxError;
  33073. return cssSyntaxError;
  33074. }
  33075. var stringifier;
  33076. var hasRequiredStringifier;
  33077. function requireStringifier () {
  33078. if (hasRequiredStringifier) return stringifier;
  33079. hasRequiredStringifier = 1;
  33080. const DEFAULT_RAW = {
  33081. after: '\n',
  33082. beforeClose: '\n',
  33083. beforeComment: '\n',
  33084. beforeDecl: '\n',
  33085. beforeOpen: ' ',
  33086. beforeRule: '\n',
  33087. colon: ': ',
  33088. commentLeft: ' ',
  33089. commentRight: ' ',
  33090. emptyBody: '',
  33091. indent: ' ',
  33092. semicolon: false
  33093. };
  33094. function capitalize(str) {
  33095. return str[0].toUpperCase() + str.slice(1)
  33096. }
  33097. class Stringifier {
  33098. constructor(builder) {
  33099. this.builder = builder;
  33100. }
  33101. atrule(node, semicolon) {
  33102. let name = '@' + node.name;
  33103. let params = node.params ? this.rawValue(node, 'params') : '';
  33104. if (typeof node.raws.afterName !== 'undefined') {
  33105. name += node.raws.afterName;
  33106. } else if (params) {
  33107. name += ' ';
  33108. }
  33109. if (node.nodes) {
  33110. this.block(node, name + params);
  33111. } else {
  33112. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  33113. this.builder(name + params + end, node);
  33114. }
  33115. }
  33116. beforeAfter(node, detect) {
  33117. let value;
  33118. if (node.type === 'decl') {
  33119. value = this.raw(node, null, 'beforeDecl');
  33120. } else if (node.type === 'comment') {
  33121. value = this.raw(node, null, 'beforeComment');
  33122. } else if (detect === 'before') {
  33123. value = this.raw(node, null, 'beforeRule');
  33124. } else {
  33125. value = this.raw(node, null, 'beforeClose');
  33126. }
  33127. let buf = node.parent;
  33128. let depth = 0;
  33129. while (buf && buf.type !== 'root') {
  33130. depth += 1;
  33131. buf = buf.parent;
  33132. }
  33133. if (value.includes('\n')) {
  33134. let indent = this.raw(node, null, 'indent');
  33135. if (indent.length) {
  33136. for (let step = 0; step < depth; step++) value += indent;
  33137. }
  33138. }
  33139. return value
  33140. }
  33141. block(node, start) {
  33142. let between = this.raw(node, 'between', 'beforeOpen');
  33143. this.builder(start + between + '{', node, 'start');
  33144. let after;
  33145. if (node.nodes && node.nodes.length) {
  33146. this.body(node);
  33147. after = this.raw(node, 'after');
  33148. } else {
  33149. after = this.raw(node, 'after', 'emptyBody');
  33150. }
  33151. if (after) this.builder(after);
  33152. this.builder('}', node, 'end');
  33153. }
  33154. body(node) {
  33155. let last = node.nodes.length - 1;
  33156. while (last > 0) {
  33157. if (node.nodes[last].type !== 'comment') break
  33158. last -= 1;
  33159. }
  33160. let semicolon = this.raw(node, 'semicolon');
  33161. for (let i = 0; i < node.nodes.length; i++) {
  33162. let child = node.nodes[i];
  33163. let before = this.raw(child, 'before');
  33164. if (before) this.builder(before);
  33165. this.stringify(child, last !== i || semicolon);
  33166. }
  33167. }
  33168. comment(node) {
  33169. let left = this.raw(node, 'left', 'commentLeft');
  33170. let right = this.raw(node, 'right', 'commentRight');
  33171. this.builder('/*' + left + node.text + right + '*/', node);
  33172. }
  33173. decl(node, semicolon) {
  33174. let between = this.raw(node, 'between', 'colon');
  33175. let string = node.prop + between + this.rawValue(node, 'value');
  33176. if (node.important) {
  33177. string += node.raws.important || ' !important';
  33178. }
  33179. if (semicolon) string += ';';
  33180. this.builder(string, node);
  33181. }
  33182. document(node) {
  33183. this.body(node);
  33184. }
  33185. raw(node, own, detect) {
  33186. let value;
  33187. if (!detect) detect = own;
  33188. // Already had
  33189. if (own) {
  33190. value = node.raws[own];
  33191. if (typeof value !== 'undefined') return value
  33192. }
  33193. let parent = node.parent;
  33194. if (detect === 'before') {
  33195. // Hack for first rule in CSS
  33196. if (!parent || (parent.type === 'root' && parent.first === node)) {
  33197. return ''
  33198. }
  33199. // `root` nodes in `document` should use only their own raws
  33200. if (parent && parent.type === 'document') {
  33201. return ''
  33202. }
  33203. }
  33204. // Floating child without parent
  33205. if (!parent) return DEFAULT_RAW[detect]
  33206. // Detect style by other nodes
  33207. let root = node.root();
  33208. if (!root.rawCache) root.rawCache = {};
  33209. if (typeof root.rawCache[detect] !== 'undefined') {
  33210. return root.rawCache[detect]
  33211. }
  33212. if (detect === 'before' || detect === 'after') {
  33213. return this.beforeAfter(node, detect)
  33214. } else {
  33215. let method = 'raw' + capitalize(detect);
  33216. if (this[method]) {
  33217. value = this[method](root, node);
  33218. } else {
  33219. root.walk(i => {
  33220. value = i.raws[own];
  33221. if (typeof value !== 'undefined') return false
  33222. });
  33223. }
  33224. }
  33225. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33226. root.rawCache[detect] = value;
  33227. return value
  33228. }
  33229. rawBeforeClose(root) {
  33230. let value;
  33231. root.walk(i => {
  33232. if (i.nodes && i.nodes.length > 0) {
  33233. if (typeof i.raws.after !== 'undefined') {
  33234. value = i.raws.after;
  33235. if (value.includes('\n')) {
  33236. value = value.replace(/[^\n]+$/, '');
  33237. }
  33238. return false
  33239. }
  33240. }
  33241. });
  33242. if (value) value = value.replace(/\S/g, '');
  33243. return value
  33244. }
  33245. rawBeforeComment(root, node) {
  33246. let value;
  33247. root.walkComments(i => {
  33248. if (typeof i.raws.before !== 'undefined') {
  33249. value = i.raws.before;
  33250. if (value.includes('\n')) {
  33251. value = value.replace(/[^\n]+$/, '');
  33252. }
  33253. return false
  33254. }
  33255. });
  33256. if (typeof value === 'undefined') {
  33257. value = this.raw(node, null, 'beforeDecl');
  33258. } else if (value) {
  33259. value = value.replace(/\S/g, '');
  33260. }
  33261. return value
  33262. }
  33263. rawBeforeDecl(root, node) {
  33264. let value;
  33265. root.walkDecls(i => {
  33266. if (typeof i.raws.before !== 'undefined') {
  33267. value = i.raws.before;
  33268. if (value.includes('\n')) {
  33269. value = value.replace(/[^\n]+$/, '');
  33270. }
  33271. return false
  33272. }
  33273. });
  33274. if (typeof value === 'undefined') {
  33275. value = this.raw(node, null, 'beforeRule');
  33276. } else if (value) {
  33277. value = value.replace(/\S/g, '');
  33278. }
  33279. return value
  33280. }
  33281. rawBeforeOpen(root) {
  33282. let value;
  33283. root.walk(i => {
  33284. if (i.type !== 'decl') {
  33285. value = i.raws.between;
  33286. if (typeof value !== 'undefined') return false
  33287. }
  33288. });
  33289. return value
  33290. }
  33291. rawBeforeRule(root) {
  33292. let value;
  33293. root.walk(i => {
  33294. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33295. if (typeof i.raws.before !== 'undefined') {
  33296. value = i.raws.before;
  33297. if (value.includes('\n')) {
  33298. value = value.replace(/[^\n]+$/, '');
  33299. }
  33300. return false
  33301. }
  33302. }
  33303. });
  33304. if (value) value = value.replace(/\S/g, '');
  33305. return value
  33306. }
  33307. rawColon(root) {
  33308. let value;
  33309. root.walkDecls(i => {
  33310. if (typeof i.raws.between !== 'undefined') {
  33311. value = i.raws.between.replace(/[^\s:]/g, '');
  33312. return false
  33313. }
  33314. });
  33315. return value
  33316. }
  33317. rawEmptyBody(root) {
  33318. let value;
  33319. root.walk(i => {
  33320. if (i.nodes && i.nodes.length === 0) {
  33321. value = i.raws.after;
  33322. if (typeof value !== 'undefined') return false
  33323. }
  33324. });
  33325. return value
  33326. }
  33327. rawIndent(root) {
  33328. if (root.raws.indent) return root.raws.indent
  33329. let value;
  33330. root.walk(i => {
  33331. let p = i.parent;
  33332. if (p && p !== root && p.parent && p.parent === root) {
  33333. if (typeof i.raws.before !== 'undefined') {
  33334. let parts = i.raws.before.split('\n');
  33335. value = parts[parts.length - 1];
  33336. value = value.replace(/\S/g, '');
  33337. return false
  33338. }
  33339. }
  33340. });
  33341. return value
  33342. }
  33343. rawSemicolon(root) {
  33344. let value;
  33345. root.walk(i => {
  33346. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33347. value = i.raws.semicolon;
  33348. if (typeof value !== 'undefined') return false
  33349. }
  33350. });
  33351. return value
  33352. }
  33353. rawValue(node, prop) {
  33354. let value = node[prop];
  33355. let raw = node.raws[prop];
  33356. if (raw && raw.value === value) {
  33357. return raw.raw
  33358. }
  33359. return value
  33360. }
  33361. root(node) {
  33362. this.body(node);
  33363. if (node.raws.after) this.builder(node.raws.after);
  33364. }
  33365. rule(node) {
  33366. this.block(node, this.rawValue(node, 'selector'));
  33367. if (node.raws.ownSemicolon) {
  33368. this.builder(node.raws.ownSemicolon, node, 'end');
  33369. }
  33370. }
  33371. stringify(node, semicolon) {
  33372. /* c8 ignore start */
  33373. if (!this[node.type]) {
  33374. throw new Error(
  33375. 'Unknown AST node type ' +
  33376. node.type +
  33377. '. ' +
  33378. 'Maybe you need to change PostCSS stringifier.'
  33379. )
  33380. }
  33381. /* c8 ignore stop */
  33382. this[node.type](node, semicolon);
  33383. }
  33384. }
  33385. stringifier = Stringifier;
  33386. Stringifier.default = Stringifier;
  33387. return stringifier;
  33388. }
  33389. var stringify_1;
  33390. var hasRequiredStringify;
  33391. function requireStringify () {
  33392. if (hasRequiredStringify) return stringify_1;
  33393. hasRequiredStringify = 1;
  33394. let Stringifier = /*@__PURE__*/ requireStringifier();
  33395. function stringify(node, builder) {
  33396. let str = new Stringifier(builder);
  33397. str.stringify(node);
  33398. }
  33399. stringify_1 = stringify;
  33400. stringify.default = stringify;
  33401. return stringify_1;
  33402. }
  33403. var symbols = {};
  33404. var hasRequiredSymbols;
  33405. function requireSymbols () {
  33406. if (hasRequiredSymbols) return symbols;
  33407. hasRequiredSymbols = 1;
  33408. symbols.isClean = Symbol('isClean');
  33409. symbols.my = Symbol('my');
  33410. return symbols;
  33411. }
  33412. var node$2;
  33413. var hasRequiredNode$2;
  33414. function requireNode$2 () {
  33415. if (hasRequiredNode$2) return node$2;
  33416. hasRequiredNode$2 = 1;
  33417. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  33418. let Stringifier = /*@__PURE__*/ requireStringifier();
  33419. let stringify = /*@__PURE__*/ requireStringify();
  33420. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33421. function cloneNode(obj, parent) {
  33422. let cloned = new obj.constructor();
  33423. for (let i in obj) {
  33424. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33425. /* c8 ignore next 2 */
  33426. continue
  33427. }
  33428. if (i === 'proxyCache') continue
  33429. let value = obj[i];
  33430. let type = typeof value;
  33431. if (i === 'parent' && type === 'object') {
  33432. if (parent) cloned[i] = parent;
  33433. } else if (i === 'source') {
  33434. cloned[i] = value;
  33435. } else if (Array.isArray(value)) {
  33436. cloned[i] = value.map(j => cloneNode(j, cloned));
  33437. } else {
  33438. if (type === 'object' && value !== null) value = cloneNode(value);
  33439. cloned[i] = value;
  33440. }
  33441. }
  33442. return cloned
  33443. }
  33444. function sourceOffset(inputCSS, position) {
  33445. // Not all custom syntaxes support `offset` in `source.start` and `source.end`
  33446. if (position && typeof position.offset !== 'undefined') {
  33447. return position.offset
  33448. }
  33449. let column = 1;
  33450. let line = 1;
  33451. let offset = 0;
  33452. for (let i = 0; i < inputCSS.length; i++) {
  33453. if (line === position.line && column === position.column) {
  33454. offset = i;
  33455. break
  33456. }
  33457. if (inputCSS[i] === '\n') {
  33458. column = 1;
  33459. line += 1;
  33460. } else {
  33461. column += 1;
  33462. }
  33463. }
  33464. return offset
  33465. }
  33466. class Node {
  33467. get proxyOf() {
  33468. return this
  33469. }
  33470. constructor(defaults = {}) {
  33471. this.raws = {};
  33472. this[isClean] = false;
  33473. this[my] = true;
  33474. for (let name in defaults) {
  33475. if (name === 'nodes') {
  33476. this.nodes = [];
  33477. for (let node of defaults[name]) {
  33478. if (typeof node.clone === 'function') {
  33479. this.append(node.clone());
  33480. } else {
  33481. this.append(node);
  33482. }
  33483. }
  33484. } else {
  33485. this[name] = defaults[name];
  33486. }
  33487. }
  33488. }
  33489. addToError(error) {
  33490. error.postcssNode = this;
  33491. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33492. let s = this.source;
  33493. error.stack = error.stack.replace(
  33494. /\n\s{4}at /,
  33495. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33496. );
  33497. }
  33498. return error
  33499. }
  33500. after(add) {
  33501. this.parent.insertAfter(this, add);
  33502. return this
  33503. }
  33504. assign(overrides = {}) {
  33505. for (let name in overrides) {
  33506. this[name] = overrides[name];
  33507. }
  33508. return this
  33509. }
  33510. before(add) {
  33511. this.parent.insertBefore(this, add);
  33512. return this
  33513. }
  33514. cleanRaws(keepBetween) {
  33515. delete this.raws.before;
  33516. delete this.raws.after;
  33517. if (!keepBetween) delete this.raws.between;
  33518. }
  33519. clone(overrides = {}) {
  33520. let cloned = cloneNode(this);
  33521. for (let name in overrides) {
  33522. cloned[name] = overrides[name];
  33523. }
  33524. return cloned
  33525. }
  33526. cloneAfter(overrides = {}) {
  33527. let cloned = this.clone(overrides);
  33528. this.parent.insertAfter(this, cloned);
  33529. return cloned
  33530. }
  33531. cloneBefore(overrides = {}) {
  33532. let cloned = this.clone(overrides);
  33533. this.parent.insertBefore(this, cloned);
  33534. return cloned
  33535. }
  33536. error(message, opts = {}) {
  33537. if (this.source) {
  33538. let { end, start } = this.rangeBy(opts);
  33539. return this.source.input.error(
  33540. message,
  33541. { column: start.column, line: start.line },
  33542. { column: end.column, line: end.line },
  33543. opts
  33544. )
  33545. }
  33546. return new CssSyntaxError(message)
  33547. }
  33548. getProxyProcessor() {
  33549. return {
  33550. get(node, prop) {
  33551. if (prop === 'proxyOf') {
  33552. return node
  33553. } else if (prop === 'root') {
  33554. return () => node.root().toProxy()
  33555. } else {
  33556. return node[prop]
  33557. }
  33558. },
  33559. set(node, prop, value) {
  33560. if (node[prop] === value) return true
  33561. node[prop] = value;
  33562. if (
  33563. prop === 'prop' ||
  33564. prop === 'value' ||
  33565. prop === 'name' ||
  33566. prop === 'params' ||
  33567. prop === 'important' ||
  33568. /* c8 ignore next */
  33569. prop === 'text'
  33570. ) {
  33571. node.markDirty();
  33572. }
  33573. return true
  33574. }
  33575. }
  33576. }
  33577. /* c8 ignore next 3 */
  33578. markClean() {
  33579. this[isClean] = true;
  33580. }
  33581. markDirty() {
  33582. if (this[isClean]) {
  33583. this[isClean] = false;
  33584. let next = this;
  33585. while ((next = next.parent)) {
  33586. next[isClean] = false;
  33587. }
  33588. }
  33589. }
  33590. next() {
  33591. if (!this.parent) return undefined
  33592. let index = this.parent.index(this);
  33593. return this.parent.nodes[index + 1]
  33594. }
  33595. positionBy(opts = {}) {
  33596. let pos = this.source.start;
  33597. if (opts.index) {
  33598. pos = this.positionInside(opts.index);
  33599. } else if (opts.word) {
  33600. let inputString =
  33601. 'document' in this.source.input
  33602. ? this.source.input.document
  33603. : this.source.input.css;
  33604. let stringRepresentation = inputString.slice(
  33605. sourceOffset(inputString, this.source.start),
  33606. sourceOffset(inputString, this.source.end)
  33607. );
  33608. let index = stringRepresentation.indexOf(opts.word);
  33609. if (index !== -1) pos = this.positionInside(index);
  33610. }
  33611. return pos
  33612. }
  33613. positionInside(index) {
  33614. let column = this.source.start.column;
  33615. let line = this.source.start.line;
  33616. let inputString =
  33617. 'document' in this.source.input
  33618. ? this.source.input.document
  33619. : this.source.input.css;
  33620. let offset = sourceOffset(inputString, this.source.start);
  33621. let end = offset + index;
  33622. for (let i = offset; i < end; i++) {
  33623. if (inputString[i] === '\n') {
  33624. column = 1;
  33625. line += 1;
  33626. } else {
  33627. column += 1;
  33628. }
  33629. }
  33630. return { column, line, offset: end }
  33631. }
  33632. prev() {
  33633. if (!this.parent) return undefined
  33634. let index = this.parent.index(this);
  33635. return this.parent.nodes[index - 1]
  33636. }
  33637. rangeBy(opts = {}) {
  33638. let inputString =
  33639. 'document' in this.source.input
  33640. ? this.source.input.document
  33641. : this.source.input.css;
  33642. let start = {
  33643. column: this.source.start.column,
  33644. line: this.source.start.line,
  33645. offset: sourceOffset(inputString, this.source.start)
  33646. };
  33647. let end = this.source.end
  33648. ? {
  33649. column: this.source.end.column + 1,
  33650. line: this.source.end.line,
  33651. offset:
  33652. typeof this.source.end.offset === 'number'
  33653. ? // `source.end.offset` is exclusive, so we don't need to add 1
  33654. this.source.end.offset
  33655. : // Since line/column in this.source.end is inclusive,
  33656. // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
  33657. // So, we add 1 to convert it to exclusive.
  33658. sourceOffset(inputString, this.source.end) + 1
  33659. }
  33660. : {
  33661. column: start.column + 1,
  33662. line: start.line,
  33663. offset: start.offset + 1
  33664. };
  33665. if (opts.word) {
  33666. let stringRepresentation = inputString.slice(
  33667. sourceOffset(inputString, this.source.start),
  33668. sourceOffset(inputString, this.source.end)
  33669. );
  33670. let index = stringRepresentation.indexOf(opts.word);
  33671. if (index !== -1) {
  33672. start = this.positionInside(index);
  33673. end = this.positionInside(index + opts.word.length);
  33674. }
  33675. } else {
  33676. if (opts.start) {
  33677. start = {
  33678. column: opts.start.column,
  33679. line: opts.start.line,
  33680. offset: sourceOffset(inputString, opts.start)
  33681. };
  33682. } else if (opts.index) {
  33683. start = this.positionInside(opts.index);
  33684. }
  33685. if (opts.end) {
  33686. end = {
  33687. column: opts.end.column,
  33688. line: opts.end.line,
  33689. offset: sourceOffset(inputString, opts.end)
  33690. };
  33691. } else if (typeof opts.endIndex === 'number') {
  33692. end = this.positionInside(opts.endIndex);
  33693. } else if (opts.index) {
  33694. end = this.positionInside(opts.index + 1);
  33695. }
  33696. }
  33697. if (
  33698. end.line < start.line ||
  33699. (end.line === start.line && end.column <= start.column)
  33700. ) {
  33701. end = {
  33702. column: start.column + 1,
  33703. line: start.line,
  33704. offset: start.offset + 1
  33705. };
  33706. }
  33707. return { end, start }
  33708. }
  33709. raw(prop, defaultType) {
  33710. let str = new Stringifier();
  33711. return str.raw(this, prop, defaultType)
  33712. }
  33713. remove() {
  33714. if (this.parent) {
  33715. this.parent.removeChild(this);
  33716. }
  33717. this.parent = undefined;
  33718. return this
  33719. }
  33720. replaceWith(...nodes) {
  33721. if (this.parent) {
  33722. let bookmark = this;
  33723. let foundSelf = false;
  33724. for (let node of nodes) {
  33725. if (node === this) {
  33726. foundSelf = true;
  33727. } else if (foundSelf) {
  33728. this.parent.insertAfter(bookmark, node);
  33729. bookmark = node;
  33730. } else {
  33731. this.parent.insertBefore(bookmark, node);
  33732. }
  33733. }
  33734. if (!foundSelf) {
  33735. this.remove();
  33736. }
  33737. }
  33738. return this
  33739. }
  33740. root() {
  33741. let result = this;
  33742. while (result.parent && result.parent.type !== 'document') {
  33743. result = result.parent;
  33744. }
  33745. return result
  33746. }
  33747. toJSON(_, inputs) {
  33748. let fixed = {};
  33749. let emitInputs = inputs == null;
  33750. inputs = inputs || new Map();
  33751. let inputsNextIndex = 0;
  33752. for (let name in this) {
  33753. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33754. /* c8 ignore next 2 */
  33755. continue
  33756. }
  33757. if (name === 'parent' || name === 'proxyCache') continue
  33758. let value = this[name];
  33759. if (Array.isArray(value)) {
  33760. fixed[name] = value.map(i => {
  33761. if (typeof i === 'object' && i.toJSON) {
  33762. return i.toJSON(null, inputs)
  33763. } else {
  33764. return i
  33765. }
  33766. });
  33767. } else if (typeof value === 'object' && value.toJSON) {
  33768. fixed[name] = value.toJSON(null, inputs);
  33769. } else if (name === 'source') {
  33770. if (value == null) continue
  33771. let inputId = inputs.get(value.input);
  33772. if (inputId == null) {
  33773. inputId = inputsNextIndex;
  33774. inputs.set(value.input, inputsNextIndex);
  33775. inputsNextIndex++;
  33776. }
  33777. fixed[name] = {
  33778. end: value.end,
  33779. inputId,
  33780. start: value.start
  33781. };
  33782. } else {
  33783. fixed[name] = value;
  33784. }
  33785. }
  33786. if (emitInputs) {
  33787. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33788. }
  33789. return fixed
  33790. }
  33791. toProxy() {
  33792. if (!this.proxyCache) {
  33793. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33794. }
  33795. return this.proxyCache
  33796. }
  33797. toString(stringifier = stringify) {
  33798. if (stringifier.stringify) stringifier = stringifier.stringify;
  33799. let result = '';
  33800. stringifier(this, i => {
  33801. result += i;
  33802. });
  33803. return result
  33804. }
  33805. warn(result, text, opts = {}) {
  33806. let data = { node: this };
  33807. for (let i in opts) data[i] = opts[i];
  33808. return result.warn(text, data)
  33809. }
  33810. }
  33811. node$2 = Node;
  33812. Node.default = Node;
  33813. return node$2;
  33814. }
  33815. var comment$1;
  33816. var hasRequiredComment$1;
  33817. function requireComment$1 () {
  33818. if (hasRequiredComment$1) return comment$1;
  33819. hasRequiredComment$1 = 1;
  33820. let Node = /*@__PURE__*/ requireNode$2();
  33821. class Comment extends Node {
  33822. constructor(defaults) {
  33823. super(defaults);
  33824. this.type = 'comment';
  33825. }
  33826. }
  33827. comment$1 = Comment;
  33828. Comment.default = Comment;
  33829. return comment$1;
  33830. }
  33831. var declaration;
  33832. var hasRequiredDeclaration;
  33833. function requireDeclaration () {
  33834. if (hasRequiredDeclaration) return declaration;
  33835. hasRequiredDeclaration = 1;
  33836. let Node = /*@__PURE__*/ requireNode$2();
  33837. class Declaration extends Node {
  33838. get variable() {
  33839. return this.prop.startsWith('--') || this.prop[0] === '$'
  33840. }
  33841. constructor(defaults) {
  33842. if (
  33843. defaults &&
  33844. typeof defaults.value !== 'undefined' &&
  33845. typeof defaults.value !== 'string'
  33846. ) {
  33847. defaults = { ...defaults, value: String(defaults.value) };
  33848. }
  33849. super(defaults);
  33850. this.type = 'decl';
  33851. }
  33852. }
  33853. declaration = Declaration;
  33854. Declaration.default = Declaration;
  33855. return declaration;
  33856. }
  33857. var container$1;
  33858. var hasRequiredContainer$1;
  33859. function requireContainer$1 () {
  33860. if (hasRequiredContainer$1) return container$1;
  33861. hasRequiredContainer$1 = 1;
  33862. let Comment = /*@__PURE__*/ requireComment$1();
  33863. let Declaration = /*@__PURE__*/ requireDeclaration();
  33864. let Node = /*@__PURE__*/ requireNode$2();
  33865. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33866. let AtRule, parse, Root, Rule;
  33867. function cleanSource(nodes) {
  33868. return nodes.map(i => {
  33869. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33870. delete i.source;
  33871. return i
  33872. })
  33873. }
  33874. function markTreeDirty(node) {
  33875. node[isClean] = false;
  33876. if (node.proxyOf.nodes) {
  33877. for (let i of node.proxyOf.nodes) {
  33878. markTreeDirty(i);
  33879. }
  33880. }
  33881. }
  33882. class Container extends Node {
  33883. get first() {
  33884. if (!this.proxyOf.nodes) return undefined
  33885. return this.proxyOf.nodes[0]
  33886. }
  33887. get last() {
  33888. if (!this.proxyOf.nodes) return undefined
  33889. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  33890. }
  33891. append(...children) {
  33892. for (let child of children) {
  33893. let nodes = this.normalize(child, this.last);
  33894. for (let node of nodes) this.proxyOf.nodes.push(node);
  33895. }
  33896. this.markDirty();
  33897. return this
  33898. }
  33899. cleanRaws(keepBetween) {
  33900. super.cleanRaws(keepBetween);
  33901. if (this.nodes) {
  33902. for (let node of this.nodes) node.cleanRaws(keepBetween);
  33903. }
  33904. }
  33905. each(callback) {
  33906. if (!this.proxyOf.nodes) return undefined
  33907. let iterator = this.getIterator();
  33908. let index, result;
  33909. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  33910. index = this.indexes[iterator];
  33911. result = callback(this.proxyOf.nodes[index], index);
  33912. if (result === false) break
  33913. this.indexes[iterator] += 1;
  33914. }
  33915. delete this.indexes[iterator];
  33916. return result
  33917. }
  33918. every(condition) {
  33919. return this.nodes.every(condition)
  33920. }
  33921. getIterator() {
  33922. if (!this.lastEach) this.lastEach = 0;
  33923. if (!this.indexes) this.indexes = {};
  33924. this.lastEach += 1;
  33925. let iterator = this.lastEach;
  33926. this.indexes[iterator] = 0;
  33927. return iterator
  33928. }
  33929. getProxyProcessor() {
  33930. return {
  33931. get(node, prop) {
  33932. if (prop === 'proxyOf') {
  33933. return node
  33934. } else if (!node[prop]) {
  33935. return node[prop]
  33936. } else if (
  33937. prop === 'each' ||
  33938. (typeof prop === 'string' && prop.startsWith('walk'))
  33939. ) {
  33940. return (...args) => {
  33941. return node[prop](
  33942. ...args.map(i => {
  33943. if (typeof i === 'function') {
  33944. return (child, index) => i(child.toProxy(), index)
  33945. } else {
  33946. return i
  33947. }
  33948. })
  33949. )
  33950. }
  33951. } else if (prop === 'every' || prop === 'some') {
  33952. return cb => {
  33953. return node[prop]((child, ...other) =>
  33954. cb(child.toProxy(), ...other)
  33955. )
  33956. }
  33957. } else if (prop === 'root') {
  33958. return () => node.root().toProxy()
  33959. } else if (prop === 'nodes') {
  33960. return node.nodes.map(i => i.toProxy())
  33961. } else if (prop === 'first' || prop === 'last') {
  33962. return node[prop].toProxy()
  33963. } else {
  33964. return node[prop]
  33965. }
  33966. },
  33967. set(node, prop, value) {
  33968. if (node[prop] === value) return true
  33969. node[prop] = value;
  33970. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  33971. node.markDirty();
  33972. }
  33973. return true
  33974. }
  33975. }
  33976. }
  33977. index(child) {
  33978. if (typeof child === 'number') return child
  33979. if (child.proxyOf) child = child.proxyOf;
  33980. return this.proxyOf.nodes.indexOf(child)
  33981. }
  33982. insertAfter(exist, add) {
  33983. let existIndex = this.index(exist);
  33984. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  33985. existIndex = this.index(exist);
  33986. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  33987. let index;
  33988. for (let id in this.indexes) {
  33989. index = this.indexes[id];
  33990. if (existIndex < index) {
  33991. this.indexes[id] = index + nodes.length;
  33992. }
  33993. }
  33994. this.markDirty();
  33995. return this
  33996. }
  33997. insertBefore(exist, add) {
  33998. let existIndex = this.index(exist);
  33999. let type = existIndex === 0 ? 'prepend' : false;
  34000. let nodes = this.normalize(
  34001. add,
  34002. this.proxyOf.nodes[existIndex],
  34003. type
  34004. ).reverse();
  34005. existIndex = this.index(exist);
  34006. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  34007. let index;
  34008. for (let id in this.indexes) {
  34009. index = this.indexes[id];
  34010. if (existIndex <= index) {
  34011. this.indexes[id] = index + nodes.length;
  34012. }
  34013. }
  34014. this.markDirty();
  34015. return this
  34016. }
  34017. normalize(nodes, sample) {
  34018. if (typeof nodes === 'string') {
  34019. nodes = cleanSource(parse(nodes).nodes);
  34020. } else if (typeof nodes === 'undefined') {
  34021. nodes = [];
  34022. } else if (Array.isArray(nodes)) {
  34023. nodes = nodes.slice(0);
  34024. for (let i of nodes) {
  34025. if (i.parent) i.parent.removeChild(i, 'ignore');
  34026. }
  34027. } else if (nodes.type === 'root' && this.type !== 'document') {
  34028. nodes = nodes.nodes.slice(0);
  34029. for (let i of nodes) {
  34030. if (i.parent) i.parent.removeChild(i, 'ignore');
  34031. }
  34032. } else if (nodes.type) {
  34033. nodes = [nodes];
  34034. } else if (nodes.prop) {
  34035. if (typeof nodes.value === 'undefined') {
  34036. throw new Error('Value field is missed in node creation')
  34037. } else if (typeof nodes.value !== 'string') {
  34038. nodes.value = String(nodes.value);
  34039. }
  34040. nodes = [new Declaration(nodes)];
  34041. } else if (nodes.selector || nodes.selectors) {
  34042. nodes = [new Rule(nodes)];
  34043. } else if (nodes.name) {
  34044. nodes = [new AtRule(nodes)];
  34045. } else if (nodes.text) {
  34046. nodes = [new Comment(nodes)];
  34047. } else {
  34048. throw new Error('Unknown node type in node creation')
  34049. }
  34050. let processed = nodes.map(i => {
  34051. /* c8 ignore next */
  34052. if (!i[my]) Container.rebuild(i);
  34053. i = i.proxyOf;
  34054. if (i.parent) i.parent.removeChild(i);
  34055. if (i[isClean]) markTreeDirty(i);
  34056. if (!i.raws) i.raws = {};
  34057. if (typeof i.raws.before === 'undefined') {
  34058. if (sample && typeof sample.raws.before !== 'undefined') {
  34059. i.raws.before = sample.raws.before.replace(/\S/g, '');
  34060. }
  34061. }
  34062. i.parent = this.proxyOf;
  34063. return i
  34064. });
  34065. return processed
  34066. }
  34067. prepend(...children) {
  34068. children = children.reverse();
  34069. for (let child of children) {
  34070. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  34071. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  34072. for (let id in this.indexes) {
  34073. this.indexes[id] = this.indexes[id] + nodes.length;
  34074. }
  34075. }
  34076. this.markDirty();
  34077. return this
  34078. }
  34079. push(child) {
  34080. child.parent = this;
  34081. this.proxyOf.nodes.push(child);
  34082. return this
  34083. }
  34084. removeAll() {
  34085. for (let node of this.proxyOf.nodes) node.parent = undefined;
  34086. this.proxyOf.nodes = [];
  34087. this.markDirty();
  34088. return this
  34089. }
  34090. removeChild(child) {
  34091. child = this.index(child);
  34092. this.proxyOf.nodes[child].parent = undefined;
  34093. this.proxyOf.nodes.splice(child, 1);
  34094. let index;
  34095. for (let id in this.indexes) {
  34096. index = this.indexes[id];
  34097. if (index >= child) {
  34098. this.indexes[id] = index - 1;
  34099. }
  34100. }
  34101. this.markDirty();
  34102. return this
  34103. }
  34104. replaceValues(pattern, opts, callback) {
  34105. if (!callback) {
  34106. callback = opts;
  34107. opts = {};
  34108. }
  34109. this.walkDecls(decl => {
  34110. if (opts.props && !opts.props.includes(decl.prop)) return
  34111. if (opts.fast && !decl.value.includes(opts.fast)) return
  34112. decl.value = decl.value.replace(pattern, callback);
  34113. });
  34114. this.markDirty();
  34115. return this
  34116. }
  34117. some(condition) {
  34118. return this.nodes.some(condition)
  34119. }
  34120. walk(callback) {
  34121. return this.each((child, i) => {
  34122. let result;
  34123. try {
  34124. result = callback(child, i);
  34125. } catch (e) {
  34126. throw child.addToError(e)
  34127. }
  34128. if (result !== false && child.walk) {
  34129. result = child.walk(callback);
  34130. }
  34131. return result
  34132. })
  34133. }
  34134. walkAtRules(name, callback) {
  34135. if (!callback) {
  34136. callback = name;
  34137. return this.walk((child, i) => {
  34138. if (child.type === 'atrule') {
  34139. return callback(child, i)
  34140. }
  34141. })
  34142. }
  34143. if (name instanceof RegExp) {
  34144. return this.walk((child, i) => {
  34145. if (child.type === 'atrule' && name.test(child.name)) {
  34146. return callback(child, i)
  34147. }
  34148. })
  34149. }
  34150. return this.walk((child, i) => {
  34151. if (child.type === 'atrule' && child.name === name) {
  34152. return callback(child, i)
  34153. }
  34154. })
  34155. }
  34156. walkComments(callback) {
  34157. return this.walk((child, i) => {
  34158. if (child.type === 'comment') {
  34159. return callback(child, i)
  34160. }
  34161. })
  34162. }
  34163. walkDecls(prop, callback) {
  34164. if (!callback) {
  34165. callback = prop;
  34166. return this.walk((child, i) => {
  34167. if (child.type === 'decl') {
  34168. return callback(child, i)
  34169. }
  34170. })
  34171. }
  34172. if (prop instanceof RegExp) {
  34173. return this.walk((child, i) => {
  34174. if (child.type === 'decl' && prop.test(child.prop)) {
  34175. return callback(child, i)
  34176. }
  34177. })
  34178. }
  34179. return this.walk((child, i) => {
  34180. if (child.type === 'decl' && child.prop === prop) {
  34181. return callback(child, i)
  34182. }
  34183. })
  34184. }
  34185. walkRules(selector, callback) {
  34186. if (!callback) {
  34187. callback = selector;
  34188. return this.walk((child, i) => {
  34189. if (child.type === 'rule') {
  34190. return callback(child, i)
  34191. }
  34192. })
  34193. }
  34194. if (selector instanceof RegExp) {
  34195. return this.walk((child, i) => {
  34196. if (child.type === 'rule' && selector.test(child.selector)) {
  34197. return callback(child, i)
  34198. }
  34199. })
  34200. }
  34201. return this.walk((child, i) => {
  34202. if (child.type === 'rule' && child.selector === selector) {
  34203. return callback(child, i)
  34204. }
  34205. })
  34206. }
  34207. }
  34208. Container.registerParse = dependant => {
  34209. parse = dependant;
  34210. };
  34211. Container.registerRule = dependant => {
  34212. Rule = dependant;
  34213. };
  34214. Container.registerAtRule = dependant => {
  34215. AtRule = dependant;
  34216. };
  34217. Container.registerRoot = dependant => {
  34218. Root = dependant;
  34219. };
  34220. container$1 = Container;
  34221. Container.default = Container;
  34222. /* c8 ignore start */
  34223. Container.rebuild = node => {
  34224. if (node.type === 'atrule') {
  34225. Object.setPrototypeOf(node, AtRule.prototype);
  34226. } else if (node.type === 'rule') {
  34227. Object.setPrototypeOf(node, Rule.prototype);
  34228. } else if (node.type === 'decl') {
  34229. Object.setPrototypeOf(node, Declaration.prototype);
  34230. } else if (node.type === 'comment') {
  34231. Object.setPrototypeOf(node, Comment.prototype);
  34232. } else if (node.type === 'root') {
  34233. Object.setPrototypeOf(node, Root.prototype);
  34234. }
  34235. node[my] = true;
  34236. if (node.nodes) {
  34237. node.nodes.forEach(child => {
  34238. Container.rebuild(child);
  34239. });
  34240. }
  34241. };
  34242. /* c8 ignore stop */
  34243. return container$1;
  34244. }
  34245. var atRule;
  34246. var hasRequiredAtRule;
  34247. function requireAtRule () {
  34248. if (hasRequiredAtRule) return atRule;
  34249. hasRequiredAtRule = 1;
  34250. let Container = /*@__PURE__*/ requireContainer$1();
  34251. class AtRule extends Container {
  34252. constructor(defaults) {
  34253. super(defaults);
  34254. this.type = 'atrule';
  34255. }
  34256. append(...children) {
  34257. if (!this.proxyOf.nodes) this.nodes = [];
  34258. return super.append(...children)
  34259. }
  34260. prepend(...children) {
  34261. if (!this.proxyOf.nodes) this.nodes = [];
  34262. return super.prepend(...children)
  34263. }
  34264. }
  34265. atRule = AtRule;
  34266. AtRule.default = AtRule;
  34267. Container.registerAtRule(AtRule);
  34268. return atRule;
  34269. }
  34270. var document;
  34271. var hasRequiredDocument;
  34272. function requireDocument () {
  34273. if (hasRequiredDocument) return document;
  34274. hasRequiredDocument = 1;
  34275. let Container = /*@__PURE__*/ requireContainer$1();
  34276. let LazyResult, Processor;
  34277. class Document extends Container {
  34278. constructor(defaults) {
  34279. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34280. super({ type: 'document', ...defaults });
  34281. if (!this.nodes) {
  34282. this.nodes = [];
  34283. }
  34284. }
  34285. toResult(opts = {}) {
  34286. let lazy = new LazyResult(new Processor(), this, opts);
  34287. return lazy.stringify()
  34288. }
  34289. }
  34290. Document.registerLazyResult = dependant => {
  34291. LazyResult = dependant;
  34292. };
  34293. Document.registerProcessor = dependant => {
  34294. Processor = dependant;
  34295. };
  34296. document = Document;
  34297. Document.default = Document;
  34298. return document;
  34299. }
  34300. var nonSecure;
  34301. var hasRequiredNonSecure;
  34302. function requireNonSecure () {
  34303. if (hasRequiredNonSecure) return nonSecure;
  34304. hasRequiredNonSecure = 1;
  34305. // This alphabet uses `A-Za-z0-9_-` symbols.
  34306. // The order of characters is optimized for better gzip and brotli compression.
  34307. // References to the same file (works both for gzip and brotli):
  34308. // `'use`, `andom`, and `rict'`
  34309. // References to the brotli default dictionary:
  34310. // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
  34311. let urlAlphabet =
  34312. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  34313. let customAlphabet = (alphabet, defaultSize = 21) => {
  34314. return (size = defaultSize) => {
  34315. let id = '';
  34316. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34317. let i = size | 0;
  34318. while (i--) {
  34319. // `| 0` is more compact and faster than `Math.floor()`.
  34320. id += alphabet[(Math.random() * alphabet.length) | 0];
  34321. }
  34322. return id
  34323. }
  34324. };
  34325. let nanoid = (size = 21) => {
  34326. let id = '';
  34327. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34328. let i = size | 0;
  34329. while (i--) {
  34330. // `| 0` is more compact and faster than `Math.floor()`.
  34331. id += urlAlphabet[(Math.random() * 64) | 0];
  34332. }
  34333. return id
  34334. };
  34335. nonSecure = { nanoid, customAlphabet };
  34336. return nonSecure;
  34337. }
  34338. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  34339. var previousMap;
  34340. var hasRequiredPreviousMap;
  34341. function requirePreviousMap () {
  34342. if (hasRequiredPreviousMap) return previousMap;
  34343. hasRequiredPreviousMap = 1;
  34344. let { existsSync, readFileSync } = require$$0$1;
  34345. let { dirname, join } = require$$1;
  34346. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34347. function fromBase64(str) {
  34348. if (Buffer$1) {
  34349. return Buffer$1.from(str, 'base64').toString()
  34350. } else {
  34351. /* c8 ignore next 2 */
  34352. return window.atob(str)
  34353. }
  34354. }
  34355. class PreviousMap {
  34356. constructor(css, opts) {
  34357. if (opts.map === false) return
  34358. this.loadAnnotation(css);
  34359. this.inline = this.startWith(this.annotation, 'data:');
  34360. let prev = opts.map ? opts.map.prev : undefined;
  34361. let text = this.loadMap(opts.from, prev);
  34362. if (!this.mapFile && opts.from) {
  34363. this.mapFile = opts.from;
  34364. }
  34365. if (this.mapFile) this.root = dirname(this.mapFile);
  34366. if (text) this.text = text;
  34367. }
  34368. consumer() {
  34369. if (!this.consumerCache) {
  34370. this.consumerCache = new SourceMapConsumer(this.text);
  34371. }
  34372. return this.consumerCache
  34373. }
  34374. decodeInline(text) {
  34375. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  34376. let baseUri = /^data:application\/json;base64,/;
  34377. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  34378. let uri = /^data:application\/json,/;
  34379. let uriMatch = text.match(charsetUri) || text.match(uri);
  34380. if (uriMatch) {
  34381. return decodeURIComponent(text.substr(uriMatch[0].length))
  34382. }
  34383. let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
  34384. if (baseUriMatch) {
  34385. return fromBase64(text.substr(baseUriMatch[0].length))
  34386. }
  34387. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  34388. throw new Error('Unsupported source map encoding ' + encoding)
  34389. }
  34390. getAnnotationURL(sourceMapString) {
  34391. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  34392. }
  34393. isMap(map) {
  34394. if (typeof map !== 'object') return false
  34395. return (
  34396. typeof map.mappings === 'string' ||
  34397. typeof map._mappings === 'string' ||
  34398. Array.isArray(map.sections)
  34399. )
  34400. }
  34401. loadAnnotation(css) {
  34402. let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
  34403. if (!comments) return
  34404. // sourceMappingURLs from comments, strings, etc.
  34405. let start = css.lastIndexOf(comments.pop());
  34406. let end = css.indexOf('*/', start);
  34407. if (start > -1 && end > -1) {
  34408. // Locate the last sourceMappingURL to avoid pickin
  34409. this.annotation = this.getAnnotationURL(css.substring(start, end));
  34410. }
  34411. }
  34412. loadFile(path) {
  34413. this.root = dirname(path);
  34414. if (existsSync(path)) {
  34415. this.mapFile = path;
  34416. return readFileSync(path, 'utf-8').toString().trim()
  34417. }
  34418. }
  34419. loadMap(file, prev) {
  34420. if (prev === false) return false
  34421. if (prev) {
  34422. if (typeof prev === 'string') {
  34423. return prev
  34424. } else if (typeof prev === 'function') {
  34425. let prevPath = prev(file);
  34426. if (prevPath) {
  34427. let map = this.loadFile(prevPath);
  34428. if (!map) {
  34429. throw new Error(
  34430. 'Unable to load previous source map: ' + prevPath.toString()
  34431. )
  34432. }
  34433. return map
  34434. }
  34435. } else if (prev instanceof SourceMapConsumer) {
  34436. return SourceMapGenerator.fromSourceMap(prev).toString()
  34437. } else if (prev instanceof SourceMapGenerator) {
  34438. return prev.toString()
  34439. } else if (this.isMap(prev)) {
  34440. return JSON.stringify(prev)
  34441. } else {
  34442. throw new Error(
  34443. 'Unsupported previous source map format: ' + prev.toString()
  34444. )
  34445. }
  34446. } else if (this.inline) {
  34447. return this.decodeInline(this.annotation)
  34448. } else if (this.annotation) {
  34449. let map = this.annotation;
  34450. if (file) map = join(dirname(file), map);
  34451. return this.loadFile(map)
  34452. }
  34453. }
  34454. startWith(string, start) {
  34455. if (!string) return false
  34456. return string.substr(0, start.length) === start
  34457. }
  34458. withContent() {
  34459. return !!(
  34460. this.consumer().sourcesContent &&
  34461. this.consumer().sourcesContent.length > 0
  34462. )
  34463. }
  34464. }
  34465. previousMap = PreviousMap;
  34466. PreviousMap.default = PreviousMap;
  34467. return previousMap;
  34468. }
  34469. var input;
  34470. var hasRequiredInput;
  34471. function requireInput () {
  34472. if (hasRequiredInput) return input;
  34473. hasRequiredInput = 1;
  34474. let { nanoid } = /*@__PURE__*/ requireNonSecure();
  34475. let { isAbsolute, resolve } = require$$1;
  34476. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34477. let { fileURLToPath, pathToFileURL } = require$$2;
  34478. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  34479. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34480. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  34481. let lineToIndexCache = Symbol('lineToIndexCache');
  34482. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34483. let pathAvailable = Boolean(resolve && isAbsolute);
  34484. function getLineToIndex(input) {
  34485. if (input[lineToIndexCache]) return input[lineToIndexCache]
  34486. let lines = input.css.split('\n');
  34487. let lineToIndex = new Array(lines.length);
  34488. let prevIndex = 0;
  34489. for (let i = 0, l = lines.length; i < l; i++) {
  34490. lineToIndex[i] = prevIndex;
  34491. prevIndex += lines[i].length + 1;
  34492. }
  34493. input[lineToIndexCache] = lineToIndex;
  34494. return lineToIndex
  34495. }
  34496. class Input {
  34497. get from() {
  34498. return this.file || this.id
  34499. }
  34500. constructor(css, opts = {}) {
  34501. if (
  34502. css === null ||
  34503. typeof css === 'undefined' ||
  34504. (typeof css === 'object' && !css.toString)
  34505. ) {
  34506. throw new Error(`PostCSS received ${css} instead of CSS string`)
  34507. }
  34508. this.css = css.toString();
  34509. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  34510. this.hasBOM = true;
  34511. this.css = this.css.slice(1);
  34512. } else {
  34513. this.hasBOM = false;
  34514. }
  34515. this.document = this.css;
  34516. if (opts.document) this.document = opts.document.toString();
  34517. if (opts.from) {
  34518. if (
  34519. !pathAvailable ||
  34520. /^\w+:\/\//.test(opts.from) ||
  34521. isAbsolute(opts.from)
  34522. ) {
  34523. this.file = opts.from;
  34524. } else {
  34525. this.file = resolve(opts.from);
  34526. }
  34527. }
  34528. if (pathAvailable && sourceMapAvailable) {
  34529. let map = new PreviousMap(this.css, opts);
  34530. if (map.text) {
  34531. this.map = map;
  34532. let file = map.consumer().file;
  34533. if (!this.file && file) this.file = this.mapResolve(file);
  34534. }
  34535. }
  34536. if (!this.file) {
  34537. this.id = '<input css ' + nanoid(6) + '>';
  34538. }
  34539. if (this.map) this.map.file = this.from;
  34540. }
  34541. error(message, line, column, opts = {}) {
  34542. let endColumn, endLine, endOffset, offset, result;
  34543. if (line && typeof line === 'object') {
  34544. let start = line;
  34545. let end = column;
  34546. if (typeof start.offset === 'number') {
  34547. offset = start.offset;
  34548. let pos = this.fromOffset(offset);
  34549. line = pos.line;
  34550. column = pos.col;
  34551. } else {
  34552. line = start.line;
  34553. column = start.column;
  34554. offset = this.fromLineAndColumn(line, column);
  34555. }
  34556. if (typeof end.offset === 'number') {
  34557. endOffset = end.offset;
  34558. let pos = this.fromOffset(endOffset);
  34559. endLine = pos.line;
  34560. endColumn = pos.col;
  34561. } else {
  34562. endLine = end.line;
  34563. endColumn = end.column;
  34564. endOffset = this.fromLineAndColumn(end.line, end.column);
  34565. }
  34566. } else if (!column) {
  34567. offset = line;
  34568. let pos = this.fromOffset(offset);
  34569. line = pos.line;
  34570. column = pos.col;
  34571. } else {
  34572. offset = this.fromLineAndColumn(line, column);
  34573. }
  34574. let origin = this.origin(line, column, endLine, endColumn);
  34575. if (origin) {
  34576. result = new CssSyntaxError(
  34577. message,
  34578. origin.endLine === undefined
  34579. ? origin.line
  34580. : { column: origin.column, line: origin.line },
  34581. origin.endLine === undefined
  34582. ? origin.column
  34583. : { column: origin.endColumn, line: origin.endLine },
  34584. origin.source,
  34585. origin.file,
  34586. opts.plugin
  34587. );
  34588. } else {
  34589. result = new CssSyntaxError(
  34590. message,
  34591. endLine === undefined ? line : { column, line },
  34592. endLine === undefined ? column : { column: endColumn, line: endLine },
  34593. this.css,
  34594. this.file,
  34595. opts.plugin
  34596. );
  34597. }
  34598. result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
  34599. if (this.file) {
  34600. if (pathToFileURL) {
  34601. result.input.url = pathToFileURL(this.file).toString();
  34602. }
  34603. result.input.file = this.file;
  34604. }
  34605. return result
  34606. }
  34607. fromLineAndColumn(line, column) {
  34608. let lineToIndex = getLineToIndex(this);
  34609. let index = lineToIndex[line - 1];
  34610. return index + column - 1
  34611. }
  34612. fromOffset(offset) {
  34613. let lineToIndex = getLineToIndex(this);
  34614. let lastLine = lineToIndex[lineToIndex.length - 1];
  34615. let min = 0;
  34616. if (offset >= lastLine) {
  34617. min = lineToIndex.length - 1;
  34618. } else {
  34619. let max = lineToIndex.length - 2;
  34620. let mid;
  34621. while (min < max) {
  34622. mid = min + ((max - min) >> 1);
  34623. if (offset < lineToIndex[mid]) {
  34624. max = mid - 1;
  34625. } else if (offset >= lineToIndex[mid + 1]) {
  34626. min = mid + 1;
  34627. } else {
  34628. min = mid;
  34629. break
  34630. }
  34631. }
  34632. }
  34633. return {
  34634. col: offset - lineToIndex[min] + 1,
  34635. line: min + 1
  34636. }
  34637. }
  34638. mapResolve(file) {
  34639. if (/^\w+:\/\//.test(file)) {
  34640. return file
  34641. }
  34642. return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
  34643. }
  34644. origin(line, column, endLine, endColumn) {
  34645. if (!this.map) return false
  34646. let consumer = this.map.consumer();
  34647. let from = consumer.originalPositionFor({ column, line });
  34648. if (!from.source) return false
  34649. let to;
  34650. if (typeof endLine === 'number') {
  34651. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  34652. }
  34653. let fromUrl;
  34654. if (isAbsolute(from.source)) {
  34655. fromUrl = pathToFileURL(from.source);
  34656. } else {
  34657. fromUrl = new URL(
  34658. from.source,
  34659. this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
  34660. );
  34661. }
  34662. let result = {
  34663. column: from.column,
  34664. endColumn: to && to.column,
  34665. endLine: to && to.line,
  34666. line: from.line,
  34667. url: fromUrl.toString()
  34668. };
  34669. if (fromUrl.protocol === 'file:') {
  34670. if (fileURLToPath) {
  34671. result.file = fileURLToPath(fromUrl);
  34672. } else {
  34673. /* c8 ignore next 2 */
  34674. throw new Error(`file: protocol is not available in this PostCSS build`)
  34675. }
  34676. }
  34677. let source = consumer.sourceContentFor(from.source);
  34678. if (source) result.source = source;
  34679. return result
  34680. }
  34681. toJSON() {
  34682. let json = {};
  34683. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  34684. if (this[name] != null) {
  34685. json[name] = this[name];
  34686. }
  34687. }
  34688. if (this.map) {
  34689. json.map = { ...this.map };
  34690. if (json.map.consumerCache) {
  34691. json.map.consumerCache = undefined;
  34692. }
  34693. }
  34694. return json
  34695. }
  34696. }
  34697. input = Input;
  34698. Input.default = Input;
  34699. if (terminalHighlight && terminalHighlight.registerInput) {
  34700. terminalHighlight.registerInput(Input);
  34701. }
  34702. return input;
  34703. }
  34704. var root$1;
  34705. var hasRequiredRoot$1;
  34706. function requireRoot$1 () {
  34707. if (hasRequiredRoot$1) return root$1;
  34708. hasRequiredRoot$1 = 1;
  34709. let Container = /*@__PURE__*/ requireContainer$1();
  34710. let LazyResult, Processor;
  34711. class Root extends Container {
  34712. constructor(defaults) {
  34713. super(defaults);
  34714. this.type = 'root';
  34715. if (!this.nodes) this.nodes = [];
  34716. }
  34717. normalize(child, sample, type) {
  34718. let nodes = super.normalize(child);
  34719. if (sample) {
  34720. if (type === 'prepend') {
  34721. if (this.nodes.length > 1) {
  34722. sample.raws.before = this.nodes[1].raws.before;
  34723. } else {
  34724. delete sample.raws.before;
  34725. }
  34726. } else if (this.first !== sample) {
  34727. for (let node of nodes) {
  34728. node.raws.before = sample.raws.before;
  34729. }
  34730. }
  34731. }
  34732. return nodes
  34733. }
  34734. removeChild(child, ignore) {
  34735. let index = this.index(child);
  34736. if (!ignore && index === 0 && this.nodes.length > 1) {
  34737. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34738. }
  34739. return super.removeChild(child)
  34740. }
  34741. toResult(opts = {}) {
  34742. let lazy = new LazyResult(new Processor(), this, opts);
  34743. return lazy.stringify()
  34744. }
  34745. }
  34746. Root.registerLazyResult = dependant => {
  34747. LazyResult = dependant;
  34748. };
  34749. Root.registerProcessor = dependant => {
  34750. Processor = dependant;
  34751. };
  34752. root$1 = Root;
  34753. Root.default = Root;
  34754. Container.registerRoot(Root);
  34755. return root$1;
  34756. }
  34757. var list_1;
  34758. var hasRequiredList;
  34759. function requireList () {
  34760. if (hasRequiredList) return list_1;
  34761. hasRequiredList = 1;
  34762. let list = {
  34763. comma(string) {
  34764. return list.split(string, [','], true)
  34765. },
  34766. space(string) {
  34767. let spaces = [' ', '\n', '\t'];
  34768. return list.split(string, spaces)
  34769. },
  34770. split(string, separators, last) {
  34771. let array = [];
  34772. let current = '';
  34773. let split = false;
  34774. let func = 0;
  34775. let inQuote = false;
  34776. let prevQuote = '';
  34777. let escape = false;
  34778. for (let letter of string) {
  34779. if (escape) {
  34780. escape = false;
  34781. } else if (letter === '\\') {
  34782. escape = true;
  34783. } else if (inQuote) {
  34784. if (letter === prevQuote) {
  34785. inQuote = false;
  34786. }
  34787. } else if (letter === '"' || letter === "'") {
  34788. inQuote = true;
  34789. prevQuote = letter;
  34790. } else if (letter === '(') {
  34791. func += 1;
  34792. } else if (letter === ')') {
  34793. if (func > 0) func -= 1;
  34794. } else if (func === 0) {
  34795. if (separators.includes(letter)) split = true;
  34796. }
  34797. if (split) {
  34798. if (current !== '') array.push(current.trim());
  34799. current = '';
  34800. split = false;
  34801. } else {
  34802. current += letter;
  34803. }
  34804. }
  34805. if (last || current !== '') array.push(current.trim());
  34806. return array
  34807. }
  34808. };
  34809. list_1 = list;
  34810. list.default = list;
  34811. return list_1;
  34812. }
  34813. var rule;
  34814. var hasRequiredRule;
  34815. function requireRule () {
  34816. if (hasRequiredRule) return rule;
  34817. hasRequiredRule = 1;
  34818. let Container = /*@__PURE__*/ requireContainer$1();
  34819. let list = /*@__PURE__*/ requireList();
  34820. class Rule extends Container {
  34821. get selectors() {
  34822. return list.comma(this.selector)
  34823. }
  34824. set selectors(values) {
  34825. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34826. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34827. this.selector = values.join(sep);
  34828. }
  34829. constructor(defaults) {
  34830. super(defaults);
  34831. this.type = 'rule';
  34832. if (!this.nodes) this.nodes = [];
  34833. }
  34834. }
  34835. rule = Rule;
  34836. Rule.default = Rule;
  34837. Container.registerRule(Rule);
  34838. return rule;
  34839. }
  34840. var fromJSON_1;
  34841. var hasRequiredFromJSON;
  34842. function requireFromJSON () {
  34843. if (hasRequiredFromJSON) return fromJSON_1;
  34844. hasRequiredFromJSON = 1;
  34845. let AtRule = /*@__PURE__*/ requireAtRule();
  34846. let Comment = /*@__PURE__*/ requireComment$1();
  34847. let Declaration = /*@__PURE__*/ requireDeclaration();
  34848. let Input = /*@__PURE__*/ requireInput();
  34849. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34850. let Root = /*@__PURE__*/ requireRoot$1();
  34851. let Rule = /*@__PURE__*/ requireRule();
  34852. function fromJSON(json, inputs) {
  34853. if (Array.isArray(json)) return json.map(n => fromJSON(n))
  34854. let { inputs: ownInputs, ...defaults } = json;
  34855. if (ownInputs) {
  34856. inputs = [];
  34857. for (let input of ownInputs) {
  34858. let inputHydrated = { ...input, __proto__: Input.prototype };
  34859. if (inputHydrated.map) {
  34860. inputHydrated.map = {
  34861. ...inputHydrated.map,
  34862. __proto__: PreviousMap.prototype
  34863. };
  34864. }
  34865. inputs.push(inputHydrated);
  34866. }
  34867. }
  34868. if (defaults.nodes) {
  34869. defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
  34870. }
  34871. if (defaults.source) {
  34872. let { inputId, ...source } = defaults.source;
  34873. defaults.source = source;
  34874. if (inputId != null) {
  34875. defaults.source.input = inputs[inputId];
  34876. }
  34877. }
  34878. if (defaults.type === 'root') {
  34879. return new Root(defaults)
  34880. } else if (defaults.type === 'decl') {
  34881. return new Declaration(defaults)
  34882. } else if (defaults.type === 'rule') {
  34883. return new Rule(defaults)
  34884. } else if (defaults.type === 'comment') {
  34885. return new Comment(defaults)
  34886. } else if (defaults.type === 'atrule') {
  34887. return new AtRule(defaults)
  34888. } else {
  34889. throw new Error('Unknown node type: ' + json.type)
  34890. }
  34891. }
  34892. fromJSON_1 = fromJSON;
  34893. fromJSON.default = fromJSON;
  34894. return fromJSON_1;
  34895. }
  34896. var mapGenerator;
  34897. var hasRequiredMapGenerator;
  34898. function requireMapGenerator () {
  34899. if (hasRequiredMapGenerator) return mapGenerator;
  34900. hasRequiredMapGenerator = 1;
  34901. let { dirname, relative, resolve, sep } = require$$1;
  34902. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34903. let { pathToFileURL } = require$$2;
  34904. let Input = /*@__PURE__*/ requireInput();
  34905. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34906. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  34907. class MapGenerator {
  34908. constructor(stringify, root, opts, cssString) {
  34909. this.stringify = stringify;
  34910. this.mapOpts = opts.map || {};
  34911. this.root = root;
  34912. this.opts = opts;
  34913. this.css = cssString;
  34914. this.originalCSS = cssString;
  34915. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  34916. this.memoizedFileURLs = new Map();
  34917. this.memoizedPaths = new Map();
  34918. this.memoizedURLs = new Map();
  34919. }
  34920. addAnnotation() {
  34921. let content;
  34922. if (this.isInline()) {
  34923. content =
  34924. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  34925. } else if (typeof this.mapOpts.annotation === 'string') {
  34926. content = this.mapOpts.annotation;
  34927. } else if (typeof this.mapOpts.annotation === 'function') {
  34928. content = this.mapOpts.annotation(this.opts.to, this.root);
  34929. } else {
  34930. content = this.outputFile() + '.map';
  34931. }
  34932. let eol = '\n';
  34933. if (this.css.includes('\r\n')) eol = '\r\n';
  34934. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  34935. }
  34936. applyPrevMaps() {
  34937. for (let prev of this.previous()) {
  34938. let from = this.toUrl(this.path(prev.file));
  34939. let root = prev.root || dirname(prev.file);
  34940. let map;
  34941. if (this.mapOpts.sourcesContent === false) {
  34942. map = new SourceMapConsumer(prev.text);
  34943. if (map.sourcesContent) {
  34944. map.sourcesContent = null;
  34945. }
  34946. } else {
  34947. map = prev.consumer();
  34948. }
  34949. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  34950. }
  34951. }
  34952. clearAnnotation() {
  34953. if (this.mapOpts.annotation === false) return
  34954. if (this.root) {
  34955. let node;
  34956. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  34957. node = this.root.nodes[i];
  34958. if (node.type !== 'comment') continue
  34959. if (node.text.startsWith('# sourceMappingURL=')) {
  34960. this.root.removeChild(i);
  34961. }
  34962. }
  34963. } else if (this.css) {
  34964. let startIndex;
  34965. while ((startIndex = this.css.lastIndexOf('/*#')) !== -1) {
  34966. let endIndex = this.css.indexOf('*/', startIndex + 3);
  34967. if (endIndex === -1) break
  34968. while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
  34969. startIndex--;
  34970. }
  34971. this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2);
  34972. }
  34973. }
  34974. }
  34975. generate() {
  34976. this.clearAnnotation();
  34977. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  34978. return this.generateMap()
  34979. } else {
  34980. let result = '';
  34981. this.stringify(this.root, i => {
  34982. result += i;
  34983. });
  34984. return [result]
  34985. }
  34986. }
  34987. generateMap() {
  34988. if (this.root) {
  34989. this.generateString();
  34990. } else if (this.previous().length === 1) {
  34991. let prev = this.previous()[0].consumer();
  34992. prev.file = this.outputFile();
  34993. this.map = SourceMapGenerator.fromSourceMap(prev, {
  34994. ignoreInvalidMapping: true
  34995. });
  34996. } else {
  34997. this.map = new SourceMapGenerator({
  34998. file: this.outputFile(),
  34999. ignoreInvalidMapping: true
  35000. });
  35001. this.map.addMapping({
  35002. generated: { column: 0, line: 1 },
  35003. original: { column: 0, line: 1 },
  35004. source: this.opts.from
  35005. ? this.toUrl(this.path(this.opts.from))
  35006. : '<no source>'
  35007. });
  35008. }
  35009. if (this.isSourcesContent()) this.setSourcesContent();
  35010. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  35011. if (this.isAnnotation()) this.addAnnotation();
  35012. if (this.isInline()) {
  35013. return [this.css]
  35014. } else {
  35015. return [this.css, this.map]
  35016. }
  35017. }
  35018. generateString() {
  35019. this.css = '';
  35020. this.map = new SourceMapGenerator({
  35021. file: this.outputFile(),
  35022. ignoreInvalidMapping: true
  35023. });
  35024. let line = 1;
  35025. let column = 1;
  35026. let noSource = '<no source>';
  35027. let mapping = {
  35028. generated: { column: 0, line: 0 },
  35029. original: { column: 0, line: 0 },
  35030. source: ''
  35031. };
  35032. let last, lines;
  35033. this.stringify(this.root, (str, node, type) => {
  35034. this.css += str;
  35035. if (node && type !== 'end') {
  35036. mapping.generated.line = line;
  35037. mapping.generated.column = column - 1;
  35038. if (node.source && node.source.start) {
  35039. mapping.source = this.sourcePath(node);
  35040. mapping.original.line = node.source.start.line;
  35041. mapping.original.column = node.source.start.column - 1;
  35042. this.map.addMapping(mapping);
  35043. } else {
  35044. mapping.source = noSource;
  35045. mapping.original.line = 1;
  35046. mapping.original.column = 0;
  35047. this.map.addMapping(mapping);
  35048. }
  35049. }
  35050. lines = str.match(/\n/g);
  35051. if (lines) {
  35052. line += lines.length;
  35053. last = str.lastIndexOf('\n');
  35054. column = str.length - last;
  35055. } else {
  35056. column += str.length;
  35057. }
  35058. if (node && type !== 'start') {
  35059. let p = node.parent || { raws: {} };
  35060. let childless =
  35061. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  35062. if (!childless || node !== p.last || p.raws.semicolon) {
  35063. if (node.source && node.source.end) {
  35064. mapping.source = this.sourcePath(node);
  35065. mapping.original.line = node.source.end.line;
  35066. mapping.original.column = node.source.end.column - 1;
  35067. mapping.generated.line = line;
  35068. mapping.generated.column = column - 2;
  35069. this.map.addMapping(mapping);
  35070. } else {
  35071. mapping.source = noSource;
  35072. mapping.original.line = 1;
  35073. mapping.original.column = 0;
  35074. mapping.generated.line = line;
  35075. mapping.generated.column = column - 1;
  35076. this.map.addMapping(mapping);
  35077. }
  35078. }
  35079. }
  35080. });
  35081. }
  35082. isAnnotation() {
  35083. if (this.isInline()) {
  35084. return true
  35085. }
  35086. if (typeof this.mapOpts.annotation !== 'undefined') {
  35087. return this.mapOpts.annotation
  35088. }
  35089. if (this.previous().length) {
  35090. return this.previous().some(i => i.annotation)
  35091. }
  35092. return true
  35093. }
  35094. isInline() {
  35095. if (typeof this.mapOpts.inline !== 'undefined') {
  35096. return this.mapOpts.inline
  35097. }
  35098. let annotation = this.mapOpts.annotation;
  35099. if (typeof annotation !== 'undefined' && annotation !== true) {
  35100. return false
  35101. }
  35102. if (this.previous().length) {
  35103. return this.previous().some(i => i.inline)
  35104. }
  35105. return true
  35106. }
  35107. isMap() {
  35108. if (typeof this.opts.map !== 'undefined') {
  35109. return !!this.opts.map
  35110. }
  35111. return this.previous().length > 0
  35112. }
  35113. isSourcesContent() {
  35114. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  35115. return this.mapOpts.sourcesContent
  35116. }
  35117. if (this.previous().length) {
  35118. return this.previous().some(i => i.withContent())
  35119. }
  35120. return true
  35121. }
  35122. outputFile() {
  35123. if (this.opts.to) {
  35124. return this.path(this.opts.to)
  35125. } else if (this.opts.from) {
  35126. return this.path(this.opts.from)
  35127. } else {
  35128. return 'to.css'
  35129. }
  35130. }
  35131. path(file) {
  35132. if (this.mapOpts.absolute) return file
  35133. if (file.charCodeAt(0) === 60 /* `<` */) return file
  35134. if (/^\w+:\/\//.test(file)) return file
  35135. let cached = this.memoizedPaths.get(file);
  35136. if (cached) return cached
  35137. let from = this.opts.to ? dirname(this.opts.to) : '.';
  35138. if (typeof this.mapOpts.annotation === 'string') {
  35139. from = dirname(resolve(from, this.mapOpts.annotation));
  35140. }
  35141. let path = relative(from, file);
  35142. this.memoizedPaths.set(file, path);
  35143. return path
  35144. }
  35145. previous() {
  35146. if (!this.previousMaps) {
  35147. this.previousMaps = [];
  35148. if (this.root) {
  35149. this.root.walk(node => {
  35150. if (node.source && node.source.input.map) {
  35151. let map = node.source.input.map;
  35152. if (!this.previousMaps.includes(map)) {
  35153. this.previousMaps.push(map);
  35154. }
  35155. }
  35156. });
  35157. } else {
  35158. let input = new Input(this.originalCSS, this.opts);
  35159. if (input.map) this.previousMaps.push(input.map);
  35160. }
  35161. }
  35162. return this.previousMaps
  35163. }
  35164. setSourcesContent() {
  35165. let already = {};
  35166. if (this.root) {
  35167. this.root.walk(node => {
  35168. if (node.source) {
  35169. let from = node.source.input.from;
  35170. if (from && !already[from]) {
  35171. already[from] = true;
  35172. let fromUrl = this.usesFileUrls
  35173. ? this.toFileUrl(from)
  35174. : this.toUrl(this.path(from));
  35175. this.map.setSourceContent(fromUrl, node.source.input.css);
  35176. }
  35177. }
  35178. });
  35179. } else if (this.css) {
  35180. let from = this.opts.from
  35181. ? this.toUrl(this.path(this.opts.from))
  35182. : '<no source>';
  35183. this.map.setSourceContent(from, this.css);
  35184. }
  35185. }
  35186. sourcePath(node) {
  35187. if (this.mapOpts.from) {
  35188. return this.toUrl(this.mapOpts.from)
  35189. } else if (this.usesFileUrls) {
  35190. return this.toFileUrl(node.source.input.from)
  35191. } else {
  35192. return this.toUrl(this.path(node.source.input.from))
  35193. }
  35194. }
  35195. toBase64(str) {
  35196. if (Buffer$1) {
  35197. return Buffer$1.from(str).toString('base64')
  35198. } else {
  35199. return window.btoa(unescape(encodeURIComponent(str)))
  35200. }
  35201. }
  35202. toFileUrl(path) {
  35203. let cached = this.memoizedFileURLs.get(path);
  35204. if (cached) return cached
  35205. if (pathToFileURL) {
  35206. let fileURL = pathToFileURL(path).toString();
  35207. this.memoizedFileURLs.set(path, fileURL);
  35208. return fileURL
  35209. } else {
  35210. throw new Error(
  35211. '`map.absolute` option is not available in this PostCSS build'
  35212. )
  35213. }
  35214. }
  35215. toUrl(path) {
  35216. let cached = this.memoizedURLs.get(path);
  35217. if (cached) return cached
  35218. if (sep === '\\') {
  35219. path = path.replace(/\\/g, '/');
  35220. }
  35221. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  35222. this.memoizedURLs.set(path, url);
  35223. return url
  35224. }
  35225. }
  35226. mapGenerator = MapGenerator;
  35227. return mapGenerator;
  35228. }
  35229. var parser$1;
  35230. var hasRequiredParser$1;
  35231. function requireParser$1 () {
  35232. if (hasRequiredParser$1) return parser$1;
  35233. hasRequiredParser$1 = 1;
  35234. let AtRule = /*@__PURE__*/ requireAtRule();
  35235. let Comment = /*@__PURE__*/ requireComment$1();
  35236. let Declaration = /*@__PURE__*/ requireDeclaration();
  35237. let Root = /*@__PURE__*/ requireRoot$1();
  35238. let Rule = /*@__PURE__*/ requireRule();
  35239. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  35240. const SAFE_COMMENT_NEIGHBOR = {
  35241. empty: true,
  35242. space: true
  35243. };
  35244. function findLastWithPosition(tokens) {
  35245. for (let i = tokens.length - 1; i >= 0; i--) {
  35246. let token = tokens[i];
  35247. let pos = token[3] || token[2];
  35248. if (pos) return pos
  35249. }
  35250. }
  35251. class Parser {
  35252. constructor(input) {
  35253. this.input = input;
  35254. this.root = new Root();
  35255. this.current = this.root;
  35256. this.spaces = '';
  35257. this.semicolon = false;
  35258. this.createTokenizer();
  35259. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  35260. }
  35261. atrule(token) {
  35262. let node = new AtRule();
  35263. node.name = token[1].slice(1);
  35264. if (node.name === '') {
  35265. this.unnamedAtrule(node, token);
  35266. }
  35267. this.init(node, token[2]);
  35268. let type;
  35269. let prev;
  35270. let shift;
  35271. let last = false;
  35272. let open = false;
  35273. let params = [];
  35274. let brackets = [];
  35275. while (!this.tokenizer.endOfFile()) {
  35276. token = this.tokenizer.nextToken();
  35277. type = token[0];
  35278. if (type === '(' || type === '[') {
  35279. brackets.push(type === '(' ? ')' : ']');
  35280. } else if (type === '{' && brackets.length > 0) {
  35281. brackets.push('}');
  35282. } else if (type === brackets[brackets.length - 1]) {
  35283. brackets.pop();
  35284. }
  35285. if (brackets.length === 0) {
  35286. if (type === ';') {
  35287. node.source.end = this.getPosition(token[2]);
  35288. node.source.end.offset++;
  35289. this.semicolon = true;
  35290. break
  35291. } else if (type === '{') {
  35292. open = true;
  35293. break
  35294. } else if (type === '}') {
  35295. if (params.length > 0) {
  35296. shift = params.length - 1;
  35297. prev = params[shift];
  35298. while (prev && prev[0] === 'space') {
  35299. prev = params[--shift];
  35300. }
  35301. if (prev) {
  35302. node.source.end = this.getPosition(prev[3] || prev[2]);
  35303. node.source.end.offset++;
  35304. }
  35305. }
  35306. this.end(token);
  35307. break
  35308. } else {
  35309. params.push(token);
  35310. }
  35311. } else {
  35312. params.push(token);
  35313. }
  35314. if (this.tokenizer.endOfFile()) {
  35315. last = true;
  35316. break
  35317. }
  35318. }
  35319. node.raws.between = this.spacesAndCommentsFromEnd(params);
  35320. if (params.length) {
  35321. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  35322. this.raw(node, 'params', params);
  35323. if (last) {
  35324. token = params[params.length - 1];
  35325. node.source.end = this.getPosition(token[3] || token[2]);
  35326. node.source.end.offset++;
  35327. this.spaces = node.raws.between;
  35328. node.raws.between = '';
  35329. }
  35330. } else {
  35331. node.raws.afterName = '';
  35332. node.params = '';
  35333. }
  35334. if (open) {
  35335. node.nodes = [];
  35336. this.current = node;
  35337. }
  35338. }
  35339. checkMissedSemicolon(tokens) {
  35340. let colon = this.colon(tokens);
  35341. if (colon === false) return
  35342. let founded = 0;
  35343. let token;
  35344. for (let j = colon - 1; j >= 0; j--) {
  35345. token = tokens[j];
  35346. if (token[0] !== 'space') {
  35347. founded += 1;
  35348. if (founded === 2) break
  35349. }
  35350. }
  35351. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35352. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35353. // And because we need it after that one we do +1 to get the next one.
  35354. throw this.input.error(
  35355. 'Missed semicolon',
  35356. token[0] === 'word' ? token[3] + 1 : token[2]
  35357. )
  35358. }
  35359. colon(tokens) {
  35360. let brackets = 0;
  35361. let prev, token, type;
  35362. for (let [i, element] of tokens.entries()) {
  35363. token = element;
  35364. type = token[0];
  35365. if (type === '(') {
  35366. brackets += 1;
  35367. }
  35368. if (type === ')') {
  35369. brackets -= 1;
  35370. }
  35371. if (brackets === 0 && type === ':') {
  35372. if (!prev) {
  35373. this.doubleColon(token);
  35374. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  35375. continue
  35376. } else {
  35377. return i
  35378. }
  35379. }
  35380. prev = token;
  35381. }
  35382. return false
  35383. }
  35384. comment(token) {
  35385. let node = new Comment();
  35386. this.init(node, token[2]);
  35387. node.source.end = this.getPosition(token[3] || token[2]);
  35388. node.source.end.offset++;
  35389. let text = token[1].slice(2, -2);
  35390. if (!text.trim()) {
  35391. node.text = '';
  35392. node.raws.left = text;
  35393. node.raws.right = '';
  35394. } else {
  35395. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  35396. node.text = match[2];
  35397. node.raws.left = match[1];
  35398. node.raws.right = match[3];
  35399. }
  35400. }
  35401. createTokenizer() {
  35402. this.tokenizer = tokenizer(this.input);
  35403. }
  35404. decl(tokens, customProperty) {
  35405. let node = new Declaration();
  35406. this.init(node, tokens[0][2]);
  35407. let last = tokens[tokens.length - 1];
  35408. if (last[0] === ';') {
  35409. this.semicolon = true;
  35410. tokens.pop();
  35411. }
  35412. node.source.end = this.getPosition(
  35413. last[3] || last[2] || findLastWithPosition(tokens)
  35414. );
  35415. node.source.end.offset++;
  35416. while (tokens[0][0] !== 'word') {
  35417. if (tokens.length === 1) this.unknownWord(tokens);
  35418. node.raws.before += tokens.shift()[1];
  35419. }
  35420. node.source.start = this.getPosition(tokens[0][2]);
  35421. node.prop = '';
  35422. while (tokens.length) {
  35423. let type = tokens[0][0];
  35424. if (type === ':' || type === 'space' || type === 'comment') {
  35425. break
  35426. }
  35427. node.prop += tokens.shift()[1];
  35428. }
  35429. node.raws.between = '';
  35430. let token;
  35431. while (tokens.length) {
  35432. token = tokens.shift();
  35433. if (token[0] === ':') {
  35434. node.raws.between += token[1];
  35435. break
  35436. } else {
  35437. if (token[0] === 'word' && /\w/.test(token[1])) {
  35438. this.unknownWord([token]);
  35439. }
  35440. node.raws.between += token[1];
  35441. }
  35442. }
  35443. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35444. node.raws.before += node.prop[0];
  35445. node.prop = node.prop.slice(1);
  35446. }
  35447. let firstSpaces = [];
  35448. let next;
  35449. while (tokens.length) {
  35450. next = tokens[0][0];
  35451. if (next !== 'space' && next !== 'comment') break
  35452. firstSpaces.push(tokens.shift());
  35453. }
  35454. this.precheckMissedSemicolon(tokens);
  35455. for (let i = tokens.length - 1; i >= 0; i--) {
  35456. token = tokens[i];
  35457. if (token[1].toLowerCase() === '!important') {
  35458. node.important = true;
  35459. let string = this.stringFrom(tokens, i);
  35460. string = this.spacesFromEnd(tokens) + string;
  35461. if (string !== ' !important') node.raws.important = string;
  35462. break
  35463. } else if (token[1].toLowerCase() === 'important') {
  35464. let cache = tokens.slice(0);
  35465. let str = '';
  35466. for (let j = i; j > 0; j--) {
  35467. let type = cache[j][0];
  35468. if (str.trim().startsWith('!') && type !== 'space') {
  35469. break
  35470. }
  35471. str = cache.pop()[1] + str;
  35472. }
  35473. if (str.trim().startsWith('!')) {
  35474. node.important = true;
  35475. node.raws.important = str;
  35476. tokens = cache;
  35477. }
  35478. }
  35479. if (token[0] !== 'space' && token[0] !== 'comment') {
  35480. break
  35481. }
  35482. }
  35483. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35484. if (hasWord) {
  35485. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35486. firstSpaces = [];
  35487. }
  35488. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35489. if (node.value.includes(':') && !customProperty) {
  35490. this.checkMissedSemicolon(tokens);
  35491. }
  35492. }
  35493. doubleColon(token) {
  35494. throw this.input.error(
  35495. 'Double colon',
  35496. { offset: token[2] },
  35497. { offset: token[2] + token[1].length }
  35498. )
  35499. }
  35500. emptyRule(token) {
  35501. let node = new Rule();
  35502. this.init(node, token[2]);
  35503. node.selector = '';
  35504. node.raws.between = '';
  35505. this.current = node;
  35506. }
  35507. end(token) {
  35508. if (this.current.nodes && this.current.nodes.length) {
  35509. this.current.raws.semicolon = this.semicolon;
  35510. }
  35511. this.semicolon = false;
  35512. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35513. this.spaces = '';
  35514. if (this.current.parent) {
  35515. this.current.source.end = this.getPosition(token[2]);
  35516. this.current.source.end.offset++;
  35517. this.current = this.current.parent;
  35518. } else {
  35519. this.unexpectedClose(token);
  35520. }
  35521. }
  35522. endFile() {
  35523. if (this.current.parent) this.unclosedBlock();
  35524. if (this.current.nodes && this.current.nodes.length) {
  35525. this.current.raws.semicolon = this.semicolon;
  35526. }
  35527. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35528. this.root.source.end = this.getPosition(this.tokenizer.position());
  35529. }
  35530. freeSemicolon(token) {
  35531. this.spaces += token[1];
  35532. if (this.current.nodes) {
  35533. let prev = this.current.nodes[this.current.nodes.length - 1];
  35534. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35535. prev.raws.ownSemicolon = this.spaces;
  35536. this.spaces = '';
  35537. prev.source.end = this.getPosition(token[2]);
  35538. prev.source.end.offset += prev.raws.ownSemicolon.length;
  35539. }
  35540. }
  35541. }
  35542. // Helpers
  35543. getPosition(offset) {
  35544. let pos = this.input.fromOffset(offset);
  35545. return {
  35546. column: pos.col,
  35547. line: pos.line,
  35548. offset
  35549. }
  35550. }
  35551. init(node, offset) {
  35552. this.current.push(node);
  35553. node.source = {
  35554. input: this.input,
  35555. start: this.getPosition(offset)
  35556. };
  35557. node.raws.before = this.spaces;
  35558. this.spaces = '';
  35559. if (node.type !== 'comment') this.semicolon = false;
  35560. }
  35561. other(start) {
  35562. let end = false;
  35563. let type = null;
  35564. let colon = false;
  35565. let bracket = null;
  35566. let brackets = [];
  35567. let customProperty = start[1].startsWith('--');
  35568. let tokens = [];
  35569. let token = start;
  35570. while (token) {
  35571. type = token[0];
  35572. tokens.push(token);
  35573. if (type === '(' || type === '[') {
  35574. if (!bracket) bracket = token;
  35575. brackets.push(type === '(' ? ')' : ']');
  35576. } else if (customProperty && colon && type === '{') {
  35577. if (!bracket) bracket = token;
  35578. brackets.push('}');
  35579. } else if (brackets.length === 0) {
  35580. if (type === ';') {
  35581. if (colon) {
  35582. this.decl(tokens, customProperty);
  35583. return
  35584. } else {
  35585. break
  35586. }
  35587. } else if (type === '{') {
  35588. this.rule(tokens);
  35589. return
  35590. } else if (type === '}') {
  35591. this.tokenizer.back(tokens.pop());
  35592. end = true;
  35593. break
  35594. } else if (type === ':') {
  35595. colon = true;
  35596. }
  35597. } else if (type === brackets[brackets.length - 1]) {
  35598. brackets.pop();
  35599. if (brackets.length === 0) bracket = null;
  35600. }
  35601. token = this.tokenizer.nextToken();
  35602. }
  35603. if (this.tokenizer.endOfFile()) end = true;
  35604. if (brackets.length > 0) this.unclosedBracket(bracket);
  35605. if (end && colon) {
  35606. if (!customProperty) {
  35607. while (tokens.length) {
  35608. token = tokens[tokens.length - 1][0];
  35609. if (token !== 'space' && token !== 'comment') break
  35610. this.tokenizer.back(tokens.pop());
  35611. }
  35612. }
  35613. this.decl(tokens, customProperty);
  35614. } else {
  35615. this.unknownWord(tokens);
  35616. }
  35617. }
  35618. parse() {
  35619. let token;
  35620. while (!this.tokenizer.endOfFile()) {
  35621. token = this.tokenizer.nextToken();
  35622. switch (token[0]) {
  35623. case 'space':
  35624. this.spaces += token[1];
  35625. break
  35626. case ';':
  35627. this.freeSemicolon(token);
  35628. break
  35629. case '}':
  35630. this.end(token);
  35631. break
  35632. case 'comment':
  35633. this.comment(token);
  35634. break
  35635. case 'at-word':
  35636. this.atrule(token);
  35637. break
  35638. case '{':
  35639. this.emptyRule(token);
  35640. break
  35641. default:
  35642. this.other(token);
  35643. break
  35644. }
  35645. }
  35646. this.endFile();
  35647. }
  35648. precheckMissedSemicolon(/* tokens */) {
  35649. // Hook for Safe Parser
  35650. }
  35651. raw(node, prop, tokens, customProperty) {
  35652. let token, type;
  35653. let length = tokens.length;
  35654. let value = '';
  35655. let clean = true;
  35656. let next, prev;
  35657. for (let i = 0; i < length; i += 1) {
  35658. token = tokens[i];
  35659. type = token[0];
  35660. if (type === 'space' && i === length - 1 && !customProperty) {
  35661. clean = false;
  35662. } else if (type === 'comment') {
  35663. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35664. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35665. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35666. if (value.slice(-1) === ',') {
  35667. clean = false;
  35668. } else {
  35669. value += token[1];
  35670. }
  35671. } else {
  35672. clean = false;
  35673. }
  35674. } else {
  35675. value += token[1];
  35676. }
  35677. }
  35678. if (!clean) {
  35679. let raw = tokens.reduce((all, i) => all + i[1], '');
  35680. node.raws[prop] = { raw, value };
  35681. }
  35682. node[prop] = value;
  35683. }
  35684. rule(tokens) {
  35685. tokens.pop();
  35686. let node = new Rule();
  35687. this.init(node, tokens[0][2]);
  35688. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35689. this.raw(node, 'selector', tokens);
  35690. this.current = node;
  35691. }
  35692. spacesAndCommentsFromEnd(tokens) {
  35693. let lastTokenType;
  35694. let spaces = '';
  35695. while (tokens.length) {
  35696. lastTokenType = tokens[tokens.length - 1][0];
  35697. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35698. spaces = tokens.pop()[1] + spaces;
  35699. }
  35700. return spaces
  35701. }
  35702. // Errors
  35703. spacesAndCommentsFromStart(tokens) {
  35704. let next;
  35705. let spaces = '';
  35706. while (tokens.length) {
  35707. next = tokens[0][0];
  35708. if (next !== 'space' && next !== 'comment') break
  35709. spaces += tokens.shift()[1];
  35710. }
  35711. return spaces
  35712. }
  35713. spacesFromEnd(tokens) {
  35714. let lastTokenType;
  35715. let spaces = '';
  35716. while (tokens.length) {
  35717. lastTokenType = tokens[tokens.length - 1][0];
  35718. if (lastTokenType !== 'space') break
  35719. spaces = tokens.pop()[1] + spaces;
  35720. }
  35721. return spaces
  35722. }
  35723. stringFrom(tokens, from) {
  35724. let result = '';
  35725. for (let i = from; i < tokens.length; i++) {
  35726. result += tokens[i][1];
  35727. }
  35728. tokens.splice(from, tokens.length - from);
  35729. return result
  35730. }
  35731. unclosedBlock() {
  35732. let pos = this.current.source.start;
  35733. throw this.input.error('Unclosed block', pos.line, pos.column)
  35734. }
  35735. unclosedBracket(bracket) {
  35736. throw this.input.error(
  35737. 'Unclosed bracket',
  35738. { offset: bracket[2] },
  35739. { offset: bracket[2] + 1 }
  35740. )
  35741. }
  35742. unexpectedClose(token) {
  35743. throw this.input.error(
  35744. 'Unexpected }',
  35745. { offset: token[2] },
  35746. { offset: token[2] + 1 }
  35747. )
  35748. }
  35749. unknownWord(tokens) {
  35750. throw this.input.error(
  35751. 'Unknown word ' + tokens[0][1],
  35752. { offset: tokens[0][2] },
  35753. { offset: tokens[0][2] + tokens[0][1].length }
  35754. )
  35755. }
  35756. unnamedAtrule(node, token) {
  35757. throw this.input.error(
  35758. 'At-rule without name',
  35759. { offset: token[2] },
  35760. { offset: token[2] + token[1].length }
  35761. )
  35762. }
  35763. }
  35764. parser$1 = Parser;
  35765. return parser$1;
  35766. }
  35767. var parse_1;
  35768. var hasRequiredParse;
  35769. function requireParse () {
  35770. if (hasRequiredParse) return parse_1;
  35771. hasRequiredParse = 1;
  35772. let Container = /*@__PURE__*/ requireContainer$1();
  35773. let Input = /*@__PURE__*/ requireInput();
  35774. let Parser = /*@__PURE__*/ requireParser$1();
  35775. function parse(css, opts) {
  35776. let input = new Input(css, opts);
  35777. let parser = new Parser(input);
  35778. try {
  35779. parser.parse();
  35780. } catch (e) {
  35781. if (browser$1.env.NODE_ENV !== 'production') {
  35782. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35783. if (/\.scss$/i.test(opts.from)) {
  35784. e.message +=
  35785. '\nYou tried to parse SCSS with ' +
  35786. 'the standard CSS parser; ' +
  35787. 'try again with the postcss-scss parser';
  35788. } else if (/\.sass/i.test(opts.from)) {
  35789. e.message +=
  35790. '\nYou tried to parse Sass with ' +
  35791. 'the standard CSS parser; ' +
  35792. 'try again with the postcss-sass parser';
  35793. } else if (/\.less$/i.test(opts.from)) {
  35794. e.message +=
  35795. '\nYou tried to parse Less with ' +
  35796. 'the standard CSS parser; ' +
  35797. 'try again with the postcss-less parser';
  35798. }
  35799. }
  35800. }
  35801. throw e
  35802. }
  35803. return parser.root
  35804. }
  35805. parse_1 = parse;
  35806. parse.default = parse;
  35807. Container.registerParse(parse);
  35808. return parse_1;
  35809. }
  35810. var warning;
  35811. var hasRequiredWarning;
  35812. function requireWarning () {
  35813. if (hasRequiredWarning) return warning;
  35814. hasRequiredWarning = 1;
  35815. class Warning {
  35816. constructor(text, opts = {}) {
  35817. this.type = 'warning';
  35818. this.text = text;
  35819. if (opts.node && opts.node.source) {
  35820. let range = opts.node.rangeBy(opts);
  35821. this.line = range.start.line;
  35822. this.column = range.start.column;
  35823. this.endLine = range.end.line;
  35824. this.endColumn = range.end.column;
  35825. }
  35826. for (let opt in opts) this[opt] = opts[opt];
  35827. }
  35828. toString() {
  35829. if (this.node) {
  35830. return this.node.error(this.text, {
  35831. index: this.index,
  35832. plugin: this.plugin,
  35833. word: this.word
  35834. }).message
  35835. }
  35836. if (this.plugin) {
  35837. return this.plugin + ': ' + this.text
  35838. }
  35839. return this.text
  35840. }
  35841. }
  35842. warning = Warning;
  35843. Warning.default = Warning;
  35844. return warning;
  35845. }
  35846. var result;
  35847. var hasRequiredResult;
  35848. function requireResult () {
  35849. if (hasRequiredResult) return result;
  35850. hasRequiredResult = 1;
  35851. let Warning = /*@__PURE__*/ requireWarning();
  35852. class Result {
  35853. get content() {
  35854. return this.css
  35855. }
  35856. constructor(processor, root, opts) {
  35857. this.processor = processor;
  35858. this.messages = [];
  35859. this.root = root;
  35860. this.opts = opts;
  35861. this.css = '';
  35862. this.map = undefined;
  35863. }
  35864. toString() {
  35865. return this.css
  35866. }
  35867. warn(text, opts = {}) {
  35868. if (!opts.plugin) {
  35869. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  35870. opts.plugin = this.lastPlugin.postcssPlugin;
  35871. }
  35872. }
  35873. let warning = new Warning(text, opts);
  35874. this.messages.push(warning);
  35875. return warning
  35876. }
  35877. warnings() {
  35878. return this.messages.filter(i => i.type === 'warning')
  35879. }
  35880. }
  35881. result = Result;
  35882. Result.default = Result;
  35883. return result;
  35884. }
  35885. /* eslint-disable no-console */
  35886. var warnOnce;
  35887. var hasRequiredWarnOnce;
  35888. function requireWarnOnce () {
  35889. if (hasRequiredWarnOnce) return warnOnce;
  35890. hasRequiredWarnOnce = 1;
  35891. let printed = {};
  35892. warnOnce = function warnOnce(message) {
  35893. if (printed[message]) return
  35894. printed[message] = true;
  35895. if (typeof console !== 'undefined' && console.warn) {
  35896. console.warn(message);
  35897. }
  35898. };
  35899. return warnOnce;
  35900. }
  35901. var lazyResult;
  35902. var hasRequiredLazyResult;
  35903. function requireLazyResult () {
  35904. if (hasRequiredLazyResult) return lazyResult;
  35905. hasRequiredLazyResult = 1;
  35906. let Container = /*@__PURE__*/ requireContainer$1();
  35907. let Document = /*@__PURE__*/ requireDocument();
  35908. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  35909. let parse = /*@__PURE__*/ requireParse();
  35910. let Result = /*@__PURE__*/ requireResult();
  35911. let Root = /*@__PURE__*/ requireRoot$1();
  35912. let stringify = /*@__PURE__*/ requireStringify();
  35913. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  35914. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  35915. const TYPE_TO_CLASS_NAME = {
  35916. atrule: 'AtRule',
  35917. comment: 'Comment',
  35918. decl: 'Declaration',
  35919. document: 'Document',
  35920. root: 'Root',
  35921. rule: 'Rule'
  35922. };
  35923. const PLUGIN_PROPS = {
  35924. AtRule: true,
  35925. AtRuleExit: true,
  35926. Comment: true,
  35927. CommentExit: true,
  35928. Declaration: true,
  35929. DeclarationExit: true,
  35930. Document: true,
  35931. DocumentExit: true,
  35932. Once: true,
  35933. OnceExit: true,
  35934. postcssPlugin: true,
  35935. prepare: true,
  35936. Root: true,
  35937. RootExit: true,
  35938. Rule: true,
  35939. RuleExit: true
  35940. };
  35941. const NOT_VISITORS = {
  35942. Once: true,
  35943. postcssPlugin: true,
  35944. prepare: true
  35945. };
  35946. const CHILDREN = 0;
  35947. function isPromise(obj) {
  35948. return typeof obj === 'object' && typeof obj.then === 'function'
  35949. }
  35950. function getEvents(node) {
  35951. let key = false;
  35952. let type = TYPE_TO_CLASS_NAME[node.type];
  35953. if (node.type === 'decl') {
  35954. key = node.prop.toLowerCase();
  35955. } else if (node.type === 'atrule') {
  35956. key = node.name.toLowerCase();
  35957. }
  35958. if (key && node.append) {
  35959. return [
  35960. type,
  35961. type + '-' + key,
  35962. CHILDREN,
  35963. type + 'Exit',
  35964. type + 'Exit-' + key
  35965. ]
  35966. } else if (key) {
  35967. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35968. } else if (node.append) {
  35969. return [type, CHILDREN, type + 'Exit']
  35970. } else {
  35971. return [type, type + 'Exit']
  35972. }
  35973. }
  35974. function toStack(node) {
  35975. let events;
  35976. if (node.type === 'document') {
  35977. events = ['Document', CHILDREN, 'DocumentExit'];
  35978. } else if (node.type === 'root') {
  35979. events = ['Root', CHILDREN, 'RootExit'];
  35980. } else {
  35981. events = getEvents(node);
  35982. }
  35983. return {
  35984. eventIndex: 0,
  35985. events,
  35986. iterator: 0,
  35987. node,
  35988. visitorIndex: 0,
  35989. visitors: []
  35990. }
  35991. }
  35992. function cleanMarks(node) {
  35993. node[isClean] = false;
  35994. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  35995. return node
  35996. }
  35997. let postcss = {};
  35998. class LazyResult {
  35999. get content() {
  36000. return this.stringify().content
  36001. }
  36002. get css() {
  36003. return this.stringify().css
  36004. }
  36005. get map() {
  36006. return this.stringify().map
  36007. }
  36008. get messages() {
  36009. return this.sync().messages
  36010. }
  36011. get opts() {
  36012. return this.result.opts
  36013. }
  36014. get processor() {
  36015. return this.result.processor
  36016. }
  36017. get root() {
  36018. return this.sync().root
  36019. }
  36020. get [Symbol.toStringTag]() {
  36021. return 'LazyResult'
  36022. }
  36023. constructor(processor, css, opts) {
  36024. this.stringified = false;
  36025. this.processed = false;
  36026. let root;
  36027. if (
  36028. typeof css === 'object' &&
  36029. css !== null &&
  36030. (css.type === 'root' || css.type === 'document')
  36031. ) {
  36032. root = cleanMarks(css);
  36033. } else if (css instanceof LazyResult || css instanceof Result) {
  36034. root = cleanMarks(css.root);
  36035. if (css.map) {
  36036. if (typeof opts.map === 'undefined') opts.map = {};
  36037. if (!opts.map.inline) opts.map.inline = false;
  36038. opts.map.prev = css.map;
  36039. }
  36040. } else {
  36041. let parser = parse;
  36042. if (opts.syntax) parser = opts.syntax.parse;
  36043. if (opts.parser) parser = opts.parser;
  36044. if (parser.parse) parser = parser.parse;
  36045. try {
  36046. root = parser(css, opts);
  36047. } catch (error) {
  36048. this.processed = true;
  36049. this.error = error;
  36050. }
  36051. if (root && !root[my]) {
  36052. /* c8 ignore next 2 */
  36053. Container.rebuild(root);
  36054. }
  36055. }
  36056. this.result = new Result(processor, root, opts);
  36057. this.helpers = { ...postcss, postcss, result: this.result };
  36058. this.plugins = this.processor.plugins.map(plugin => {
  36059. if (typeof plugin === 'object' && plugin.prepare) {
  36060. return { ...plugin, ...plugin.prepare(this.result) }
  36061. } else {
  36062. return plugin
  36063. }
  36064. });
  36065. }
  36066. async() {
  36067. if (this.error) return Promise.reject(this.error)
  36068. if (this.processed) return Promise.resolve(this.result)
  36069. if (!this.processing) {
  36070. this.processing = this.runAsync();
  36071. }
  36072. return this.processing
  36073. }
  36074. catch(onRejected) {
  36075. return this.async().catch(onRejected)
  36076. }
  36077. finally(onFinally) {
  36078. return this.async().then(onFinally, onFinally)
  36079. }
  36080. getAsyncError() {
  36081. throw new Error('Use process(css).then(cb) to work with async plugins')
  36082. }
  36083. handleError(error, node) {
  36084. let plugin = this.result.lastPlugin;
  36085. try {
  36086. if (node) node.addToError(error);
  36087. this.error = error;
  36088. if (error.name === 'CssSyntaxError' && !error.plugin) {
  36089. error.plugin = plugin.postcssPlugin;
  36090. error.setMessage();
  36091. } else if (plugin.postcssVersion) {
  36092. if (browser$1.env.NODE_ENV !== 'production') {
  36093. let pluginName = plugin.postcssPlugin;
  36094. let pluginVer = plugin.postcssVersion;
  36095. let runtimeVer = this.result.processor.version;
  36096. let a = pluginVer.split('.');
  36097. let b = runtimeVer.split('.');
  36098. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  36099. // eslint-disable-next-line no-console
  36100. console.error(
  36101. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  36102. 'version is ' +
  36103. runtimeVer +
  36104. ', but ' +
  36105. pluginName +
  36106. ' uses ' +
  36107. pluginVer +
  36108. '. Perhaps this is the source of the error below.'
  36109. );
  36110. }
  36111. }
  36112. }
  36113. } catch (err) {
  36114. /* c8 ignore next 3 */
  36115. // eslint-disable-next-line no-console
  36116. if (console && console.error) console.error(err);
  36117. }
  36118. return error
  36119. }
  36120. prepareVisitors() {
  36121. this.listeners = {};
  36122. let add = (plugin, type, cb) => {
  36123. if (!this.listeners[type]) this.listeners[type] = [];
  36124. this.listeners[type].push([plugin, cb]);
  36125. };
  36126. for (let plugin of this.plugins) {
  36127. if (typeof plugin === 'object') {
  36128. for (let event in plugin) {
  36129. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  36130. throw new Error(
  36131. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  36132. `Try to update PostCSS (${this.processor.version} now).`
  36133. )
  36134. }
  36135. if (!NOT_VISITORS[event]) {
  36136. if (typeof plugin[event] === 'object') {
  36137. for (let filter in plugin[event]) {
  36138. if (filter === '*') {
  36139. add(plugin, event, plugin[event][filter]);
  36140. } else {
  36141. add(
  36142. plugin,
  36143. event + '-' + filter.toLowerCase(),
  36144. plugin[event][filter]
  36145. );
  36146. }
  36147. }
  36148. } else if (typeof plugin[event] === 'function') {
  36149. add(plugin, event, plugin[event]);
  36150. }
  36151. }
  36152. }
  36153. }
  36154. }
  36155. this.hasListener = Object.keys(this.listeners).length > 0;
  36156. }
  36157. async runAsync() {
  36158. this.plugin = 0;
  36159. for (let i = 0; i < this.plugins.length; i++) {
  36160. let plugin = this.plugins[i];
  36161. let promise = this.runOnRoot(plugin);
  36162. if (isPromise(promise)) {
  36163. try {
  36164. await promise;
  36165. } catch (error) {
  36166. throw this.handleError(error)
  36167. }
  36168. }
  36169. }
  36170. this.prepareVisitors();
  36171. if (this.hasListener) {
  36172. let root = this.result.root;
  36173. while (!root[isClean]) {
  36174. root[isClean] = true;
  36175. let stack = [toStack(root)];
  36176. while (stack.length > 0) {
  36177. let promise = this.visitTick(stack);
  36178. if (isPromise(promise)) {
  36179. try {
  36180. await promise;
  36181. } catch (e) {
  36182. let node = stack[stack.length - 1].node;
  36183. throw this.handleError(e, node)
  36184. }
  36185. }
  36186. }
  36187. }
  36188. if (this.listeners.OnceExit) {
  36189. for (let [plugin, visitor] of this.listeners.OnceExit) {
  36190. this.result.lastPlugin = plugin;
  36191. try {
  36192. if (root.type === 'document') {
  36193. let roots = root.nodes.map(subRoot =>
  36194. visitor(subRoot, this.helpers)
  36195. );
  36196. await Promise.all(roots);
  36197. } else {
  36198. await visitor(root, this.helpers);
  36199. }
  36200. } catch (e) {
  36201. throw this.handleError(e)
  36202. }
  36203. }
  36204. }
  36205. }
  36206. this.processed = true;
  36207. return this.stringify()
  36208. }
  36209. runOnRoot(plugin) {
  36210. this.result.lastPlugin = plugin;
  36211. try {
  36212. if (typeof plugin === 'object' && plugin.Once) {
  36213. if (this.result.root.type === 'document') {
  36214. let roots = this.result.root.nodes.map(root =>
  36215. plugin.Once(root, this.helpers)
  36216. );
  36217. if (isPromise(roots[0])) {
  36218. return Promise.all(roots)
  36219. }
  36220. return roots
  36221. }
  36222. return plugin.Once(this.result.root, this.helpers)
  36223. } else if (typeof plugin === 'function') {
  36224. return plugin(this.result.root, this.result)
  36225. }
  36226. } catch (error) {
  36227. throw this.handleError(error)
  36228. }
  36229. }
  36230. stringify() {
  36231. if (this.error) throw this.error
  36232. if (this.stringified) return this.result
  36233. this.stringified = true;
  36234. this.sync();
  36235. let opts = this.result.opts;
  36236. let str = stringify;
  36237. if (opts.syntax) str = opts.syntax.stringify;
  36238. if (opts.stringifier) str = opts.stringifier;
  36239. if (str.stringify) str = str.stringify;
  36240. let map = new MapGenerator(str, this.result.root, this.result.opts);
  36241. let data = map.generate();
  36242. this.result.css = data[0];
  36243. this.result.map = data[1];
  36244. return this.result
  36245. }
  36246. sync() {
  36247. if (this.error) throw this.error
  36248. if (this.processed) return this.result
  36249. this.processed = true;
  36250. if (this.processing) {
  36251. throw this.getAsyncError()
  36252. }
  36253. for (let plugin of this.plugins) {
  36254. let promise = this.runOnRoot(plugin);
  36255. if (isPromise(promise)) {
  36256. throw this.getAsyncError()
  36257. }
  36258. }
  36259. this.prepareVisitors();
  36260. if (this.hasListener) {
  36261. let root = this.result.root;
  36262. while (!root[isClean]) {
  36263. root[isClean] = true;
  36264. this.walkSync(root);
  36265. }
  36266. if (this.listeners.OnceExit) {
  36267. if (root.type === 'document') {
  36268. for (let subRoot of root.nodes) {
  36269. this.visitSync(this.listeners.OnceExit, subRoot);
  36270. }
  36271. } else {
  36272. this.visitSync(this.listeners.OnceExit, root);
  36273. }
  36274. }
  36275. }
  36276. return this.result
  36277. }
  36278. then(onFulfilled, onRejected) {
  36279. if (browser$1.env.NODE_ENV !== 'production') {
  36280. if (!('from' in this.opts)) {
  36281. warnOnce(
  36282. 'Without `from` option PostCSS could generate wrong source map ' +
  36283. 'and will not find Browserslist config. Set it to CSS file path ' +
  36284. 'or to `undefined` to prevent this warning.'
  36285. );
  36286. }
  36287. }
  36288. return this.async().then(onFulfilled, onRejected)
  36289. }
  36290. toString() {
  36291. return this.css
  36292. }
  36293. visitSync(visitors, node) {
  36294. for (let [plugin, visitor] of visitors) {
  36295. this.result.lastPlugin = plugin;
  36296. let promise;
  36297. try {
  36298. promise = visitor(node, this.helpers);
  36299. } catch (e) {
  36300. throw this.handleError(e, node.proxyOf)
  36301. }
  36302. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36303. return true
  36304. }
  36305. if (isPromise(promise)) {
  36306. throw this.getAsyncError()
  36307. }
  36308. }
  36309. }
  36310. visitTick(stack) {
  36311. let visit = stack[stack.length - 1];
  36312. let { node, visitors } = visit;
  36313. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36314. stack.pop();
  36315. return
  36316. }
  36317. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  36318. let [plugin, visitor] = visitors[visit.visitorIndex];
  36319. visit.visitorIndex += 1;
  36320. if (visit.visitorIndex === visitors.length) {
  36321. visit.visitors = [];
  36322. visit.visitorIndex = 0;
  36323. }
  36324. this.result.lastPlugin = plugin;
  36325. try {
  36326. return visitor(node.toProxy(), this.helpers)
  36327. } catch (e) {
  36328. throw this.handleError(e, node)
  36329. }
  36330. }
  36331. if (visit.iterator !== 0) {
  36332. let iterator = visit.iterator;
  36333. let child;
  36334. while ((child = node.nodes[node.indexes[iterator]])) {
  36335. node.indexes[iterator] += 1;
  36336. if (!child[isClean]) {
  36337. child[isClean] = true;
  36338. stack.push(toStack(child));
  36339. return
  36340. }
  36341. }
  36342. visit.iterator = 0;
  36343. delete node.indexes[iterator];
  36344. }
  36345. let events = visit.events;
  36346. while (visit.eventIndex < events.length) {
  36347. let event = events[visit.eventIndex];
  36348. visit.eventIndex += 1;
  36349. if (event === CHILDREN) {
  36350. if (node.nodes && node.nodes.length) {
  36351. node[isClean] = true;
  36352. visit.iterator = node.getIterator();
  36353. }
  36354. return
  36355. } else if (this.listeners[event]) {
  36356. visit.visitors = this.listeners[event];
  36357. return
  36358. }
  36359. }
  36360. stack.pop();
  36361. }
  36362. walkSync(node) {
  36363. node[isClean] = true;
  36364. let events = getEvents(node);
  36365. for (let event of events) {
  36366. if (event === CHILDREN) {
  36367. if (node.nodes) {
  36368. node.each(child => {
  36369. if (!child[isClean]) this.walkSync(child);
  36370. });
  36371. }
  36372. } else {
  36373. let visitors = this.listeners[event];
  36374. if (visitors) {
  36375. if (this.visitSync(visitors, node.toProxy())) return
  36376. }
  36377. }
  36378. }
  36379. }
  36380. warnings() {
  36381. return this.sync().warnings()
  36382. }
  36383. }
  36384. LazyResult.registerPostcss = dependant => {
  36385. postcss = dependant;
  36386. };
  36387. lazyResult = LazyResult;
  36388. LazyResult.default = LazyResult;
  36389. Root.registerLazyResult(LazyResult);
  36390. Document.registerLazyResult(LazyResult);
  36391. return lazyResult;
  36392. }
  36393. var noWorkResult;
  36394. var hasRequiredNoWorkResult;
  36395. function requireNoWorkResult () {
  36396. if (hasRequiredNoWorkResult) return noWorkResult;
  36397. hasRequiredNoWorkResult = 1;
  36398. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  36399. let parse = /*@__PURE__*/ requireParse();
  36400. const Result = /*@__PURE__*/ requireResult();
  36401. let stringify = /*@__PURE__*/ requireStringify();
  36402. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  36403. class NoWorkResult {
  36404. get content() {
  36405. return this.result.css
  36406. }
  36407. get css() {
  36408. return this.result.css
  36409. }
  36410. get map() {
  36411. return this.result.map
  36412. }
  36413. get messages() {
  36414. return []
  36415. }
  36416. get opts() {
  36417. return this.result.opts
  36418. }
  36419. get processor() {
  36420. return this.result.processor
  36421. }
  36422. get root() {
  36423. if (this._root) {
  36424. return this._root
  36425. }
  36426. let root;
  36427. let parser = parse;
  36428. try {
  36429. root = parser(this._css, this._opts);
  36430. } catch (error) {
  36431. this.error = error;
  36432. }
  36433. if (this.error) {
  36434. throw this.error
  36435. } else {
  36436. this._root = root;
  36437. return root
  36438. }
  36439. }
  36440. get [Symbol.toStringTag]() {
  36441. return 'NoWorkResult'
  36442. }
  36443. constructor(processor, css, opts) {
  36444. css = css.toString();
  36445. this.stringified = false;
  36446. this._processor = processor;
  36447. this._css = css;
  36448. this._opts = opts;
  36449. this._map = undefined;
  36450. let str = stringify;
  36451. this.result = new Result(this._processor, undefined, this._opts);
  36452. this.result.css = css;
  36453. let self = this;
  36454. Object.defineProperty(this.result, 'root', {
  36455. get() {
  36456. return self.root
  36457. }
  36458. });
  36459. let map = new MapGenerator(str, undefined, this._opts, css);
  36460. if (map.isMap()) {
  36461. let [generatedCSS, generatedMap] = map.generate();
  36462. if (generatedCSS) {
  36463. this.result.css = generatedCSS;
  36464. }
  36465. if (generatedMap) {
  36466. this.result.map = generatedMap;
  36467. }
  36468. } else {
  36469. map.clearAnnotation();
  36470. this.result.css = map.css;
  36471. }
  36472. }
  36473. async() {
  36474. if (this.error) return Promise.reject(this.error)
  36475. return Promise.resolve(this.result)
  36476. }
  36477. catch(onRejected) {
  36478. return this.async().catch(onRejected)
  36479. }
  36480. finally(onFinally) {
  36481. return this.async().then(onFinally, onFinally)
  36482. }
  36483. sync() {
  36484. if (this.error) throw this.error
  36485. return this.result
  36486. }
  36487. then(onFulfilled, onRejected) {
  36488. if (browser$1.env.NODE_ENV !== 'production') {
  36489. if (!('from' in this._opts)) {
  36490. warnOnce(
  36491. 'Without `from` option PostCSS could generate wrong source map ' +
  36492. 'and will not find Browserslist config. Set it to CSS file path ' +
  36493. 'or to `undefined` to prevent this warning.'
  36494. );
  36495. }
  36496. }
  36497. return this.async().then(onFulfilled, onRejected)
  36498. }
  36499. toString() {
  36500. return this._css
  36501. }
  36502. warnings() {
  36503. return []
  36504. }
  36505. }
  36506. noWorkResult = NoWorkResult;
  36507. NoWorkResult.default = NoWorkResult;
  36508. return noWorkResult;
  36509. }
  36510. var processor$1;
  36511. var hasRequiredProcessor$1;
  36512. function requireProcessor$1 () {
  36513. if (hasRequiredProcessor$1) return processor$1;
  36514. hasRequiredProcessor$1 = 1;
  36515. let Document = /*@__PURE__*/ requireDocument();
  36516. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36517. let NoWorkResult = /*@__PURE__*/ requireNoWorkResult();
  36518. let Root = /*@__PURE__*/ requireRoot$1();
  36519. class Processor {
  36520. constructor(plugins = []) {
  36521. this.version = '8.5.8';
  36522. this.plugins = this.normalize(plugins);
  36523. }
  36524. normalize(plugins) {
  36525. let normalized = [];
  36526. for (let i of plugins) {
  36527. if (i.postcss === true) {
  36528. i = i();
  36529. } else if (i.postcss) {
  36530. i = i.postcss;
  36531. }
  36532. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  36533. normalized = normalized.concat(i.plugins);
  36534. } else if (typeof i === 'object' && i.postcssPlugin) {
  36535. normalized.push(i);
  36536. } else if (typeof i === 'function') {
  36537. normalized.push(i);
  36538. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36539. if (browser$1.env.NODE_ENV !== 'production') {
  36540. throw new Error(
  36541. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36542. 'one of the syntax/parser/stringifier options as outlined ' +
  36543. 'in your PostCSS runner documentation.'
  36544. )
  36545. }
  36546. } else {
  36547. throw new Error(i + ' is not a PostCSS plugin')
  36548. }
  36549. }
  36550. return normalized
  36551. }
  36552. process(css, opts = {}) {
  36553. if (
  36554. !this.plugins.length &&
  36555. !opts.parser &&
  36556. !opts.stringifier &&
  36557. !opts.syntax
  36558. ) {
  36559. return new NoWorkResult(this, css, opts)
  36560. } else {
  36561. return new LazyResult(this, css, opts)
  36562. }
  36563. }
  36564. use(plugin) {
  36565. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36566. return this
  36567. }
  36568. }
  36569. processor$1 = Processor;
  36570. Processor.default = Processor;
  36571. Root.registerProcessor(Processor);
  36572. Document.registerProcessor(Processor);
  36573. return processor$1;
  36574. }
  36575. var postcss_1;
  36576. var hasRequiredPostcss;
  36577. function requirePostcss () {
  36578. if (hasRequiredPostcss) return postcss_1;
  36579. hasRequiredPostcss = 1;
  36580. let AtRule = /*@__PURE__*/ requireAtRule();
  36581. let Comment = /*@__PURE__*/ requireComment$1();
  36582. let Container = /*@__PURE__*/ requireContainer$1();
  36583. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  36584. let Declaration = /*@__PURE__*/ requireDeclaration();
  36585. let Document = /*@__PURE__*/ requireDocument();
  36586. let fromJSON = /*@__PURE__*/ requireFromJSON();
  36587. let Input = /*@__PURE__*/ requireInput();
  36588. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36589. let list = /*@__PURE__*/ requireList();
  36590. let Node = /*@__PURE__*/ requireNode$2();
  36591. let parse = /*@__PURE__*/ requireParse();
  36592. let Processor = /*@__PURE__*/ requireProcessor$1();
  36593. let Result = /*@__PURE__*/ requireResult();
  36594. let Root = /*@__PURE__*/ requireRoot$1();
  36595. let Rule = /*@__PURE__*/ requireRule();
  36596. let stringify = /*@__PURE__*/ requireStringify();
  36597. let Warning = /*@__PURE__*/ requireWarning();
  36598. function postcss(...plugins) {
  36599. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36600. plugins = plugins[0];
  36601. }
  36602. return new Processor(plugins)
  36603. }
  36604. postcss.plugin = function plugin(name, initializer) {
  36605. let warningPrinted = false;
  36606. function creator(...args) {
  36607. // eslint-disable-next-line no-console
  36608. if (console && console.warn && !warningPrinted) {
  36609. warningPrinted = true;
  36610. // eslint-disable-next-line no-console
  36611. console.warn(
  36612. name +
  36613. ': postcss.plugin was deprecated. Migration guide:\n' +
  36614. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36615. );
  36616. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36617. /* c8 ignore next 7 */
  36618. // eslint-disable-next-line no-console
  36619. console.warn(
  36620. name +
  36621. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36622. 'https://www.w3ctech.com/topic/2226'
  36623. );
  36624. }
  36625. }
  36626. let transformer = initializer(...args);
  36627. transformer.postcssPlugin = name;
  36628. transformer.postcssVersion = new Processor().version;
  36629. return transformer
  36630. }
  36631. let cache;
  36632. Object.defineProperty(creator, 'postcss', {
  36633. get() {
  36634. if (!cache) cache = creator();
  36635. return cache
  36636. }
  36637. });
  36638. creator.process = function (css, processOpts, pluginOpts) {
  36639. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36640. };
  36641. return creator
  36642. };
  36643. postcss.stringify = stringify;
  36644. postcss.parse = parse;
  36645. postcss.fromJSON = fromJSON;
  36646. postcss.list = list;
  36647. postcss.comment = defaults => new Comment(defaults);
  36648. postcss.atRule = defaults => new AtRule(defaults);
  36649. postcss.decl = defaults => new Declaration(defaults);
  36650. postcss.rule = defaults => new Rule(defaults);
  36651. postcss.root = defaults => new Root(defaults);
  36652. postcss.document = defaults => new Document(defaults);
  36653. postcss.CssSyntaxError = CssSyntaxError;
  36654. postcss.Declaration = Declaration;
  36655. postcss.Container = Container;
  36656. postcss.Processor = Processor;
  36657. postcss.Document = Document;
  36658. postcss.Comment = Comment;
  36659. postcss.Warning = Warning;
  36660. postcss.AtRule = AtRule;
  36661. postcss.Result = Result;
  36662. postcss.Input = Input;
  36663. postcss.Rule = Rule;
  36664. postcss.Root = Root;
  36665. postcss.Node = Node;
  36666. LazyResult.registerPostcss(postcss);
  36667. postcss_1 = postcss;
  36668. postcss.default = postcss;
  36669. return postcss_1;
  36670. }
  36671. var postcssExports = /*@__PURE__*/ requirePostcss();
  36672. var postcss = /*@__PURE__*/getDefaultExportFromCjs(postcssExports);
  36673. postcss.stringify;
  36674. postcss.fromJSON;
  36675. postcss.plugin;
  36676. postcss.parse;
  36677. postcss.list;
  36678. postcss.document;
  36679. postcss.comment;
  36680. postcss.atRule;
  36681. postcss.rule;
  36682. postcss.decl;
  36683. postcss.root;
  36684. postcss.CssSyntaxError;
  36685. postcss.Declaration;
  36686. postcss.Container;
  36687. postcss.Processor;
  36688. postcss.Document;
  36689. postcss.Comment;
  36690. postcss.Warning;
  36691. postcss.AtRule;
  36692. postcss.Result;
  36693. postcss.Input;
  36694. const Rule = postcss.Rule;
  36695. postcss.Root;
  36696. postcss.Node;
  36697. const trimPlugin = () => {
  36698. return {
  36699. postcssPlugin: "vue-sfc-trim",
  36700. Once(root) {
  36701. root.walk(({ type, raws }) => {
  36702. if (type === "rule" || type === "atrule") {
  36703. if (raws.before) raws.before = "\n";
  36704. if ("after" in raws && raws.after) raws.after = "\n";
  36705. }
  36706. });
  36707. }
  36708. };
  36709. };
  36710. trimPlugin.postcss = true;
  36711. var dist = {exports: {}};
  36712. var processor = {exports: {}};
  36713. var parser = {exports: {}};
  36714. var root = {exports: {}};
  36715. var container = {exports: {}};
  36716. var node$1 = {exports: {}};
  36717. var util$1 = {};
  36718. var unesc = {exports: {}};
  36719. var hasRequiredUnesc;
  36720. function requireUnesc () {
  36721. if (hasRequiredUnesc) return unesc.exports;
  36722. hasRequiredUnesc = 1;
  36723. (function (module, exports$1) {
  36724. exports$1.__esModule = true;
  36725. exports$1["default"] = unesc;
  36726. // Many thanks for this post which made this migration much easier.
  36727. // https://mathiasbynens.be/notes/css-escapes
  36728. /**
  36729. *
  36730. * @param {string} str
  36731. * @returns {[string, number]|undefined}
  36732. */
  36733. function gobbleHex(str) {
  36734. var lower = str.toLowerCase();
  36735. var hex = '';
  36736. var spaceTerminated = false;
  36737. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36738. var code = lower.charCodeAt(i);
  36739. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36740. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36741. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36742. spaceTerminated = code === 32;
  36743. if (!valid) {
  36744. break;
  36745. }
  36746. hex += lower[i];
  36747. }
  36748. if (hex.length === 0) {
  36749. return undefined;
  36750. }
  36751. var codePoint = parseInt(hex, 16);
  36752. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36753. // Add special case for
  36754. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36755. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36756. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36757. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36758. }
  36759. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36760. }
  36761. var CONTAINS_ESCAPE = /\\/;
  36762. function unesc(str) {
  36763. var needToProcess = CONTAINS_ESCAPE.test(str);
  36764. if (!needToProcess) {
  36765. return str;
  36766. }
  36767. var ret = "";
  36768. for (var i = 0; i < str.length; i++) {
  36769. if (str[i] === "\\") {
  36770. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36771. if (gobbled !== undefined) {
  36772. ret += gobbled[0];
  36773. i += gobbled[1];
  36774. continue;
  36775. }
  36776. // Retain a pair of \\ if double escaped `\\\\`
  36777. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36778. if (str[i + 1] === "\\") {
  36779. ret += "\\";
  36780. i++;
  36781. continue;
  36782. }
  36783. // if \\ is at the end of the string retain it
  36784. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36785. if (str.length === i + 1) {
  36786. ret += str[i];
  36787. }
  36788. continue;
  36789. }
  36790. ret += str[i];
  36791. }
  36792. return ret;
  36793. }
  36794. module.exports = exports$1.default;
  36795. } (unesc, unesc.exports));
  36796. return unesc.exports;
  36797. }
  36798. var getProp = {exports: {}};
  36799. var hasRequiredGetProp;
  36800. function requireGetProp () {
  36801. if (hasRequiredGetProp) return getProp.exports;
  36802. hasRequiredGetProp = 1;
  36803. (function (module, exports$1) {
  36804. exports$1.__esModule = true;
  36805. exports$1["default"] = getProp;
  36806. function getProp(obj) {
  36807. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36808. props[_key - 1] = arguments[_key];
  36809. }
  36810. while (props.length > 0) {
  36811. var prop = props.shift();
  36812. if (!obj[prop]) {
  36813. return undefined;
  36814. }
  36815. obj = obj[prop];
  36816. }
  36817. return obj;
  36818. }
  36819. module.exports = exports$1.default;
  36820. } (getProp, getProp.exports));
  36821. return getProp.exports;
  36822. }
  36823. var ensureObject = {exports: {}};
  36824. var hasRequiredEnsureObject;
  36825. function requireEnsureObject () {
  36826. if (hasRequiredEnsureObject) return ensureObject.exports;
  36827. hasRequiredEnsureObject = 1;
  36828. (function (module, exports$1) {
  36829. exports$1.__esModule = true;
  36830. exports$1["default"] = ensureObject;
  36831. function ensureObject(obj) {
  36832. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36833. props[_key - 1] = arguments[_key];
  36834. }
  36835. while (props.length > 0) {
  36836. var prop = props.shift();
  36837. if (!obj[prop]) {
  36838. obj[prop] = {};
  36839. }
  36840. obj = obj[prop];
  36841. }
  36842. }
  36843. module.exports = exports$1.default;
  36844. } (ensureObject, ensureObject.exports));
  36845. return ensureObject.exports;
  36846. }
  36847. var stripComments = {exports: {}};
  36848. var hasRequiredStripComments;
  36849. function requireStripComments () {
  36850. if (hasRequiredStripComments) return stripComments.exports;
  36851. hasRequiredStripComments = 1;
  36852. (function (module, exports$1) {
  36853. exports$1.__esModule = true;
  36854. exports$1["default"] = stripComments;
  36855. function stripComments(str) {
  36856. var s = "";
  36857. var commentStart = str.indexOf("/*");
  36858. var lastEnd = 0;
  36859. while (commentStart >= 0) {
  36860. s = s + str.slice(lastEnd, commentStart);
  36861. var commentEnd = str.indexOf("*/", commentStart + 2);
  36862. if (commentEnd < 0) {
  36863. return s;
  36864. }
  36865. lastEnd = commentEnd + 2;
  36866. commentStart = str.indexOf("/*", lastEnd);
  36867. }
  36868. s = s + str.slice(lastEnd);
  36869. return s;
  36870. }
  36871. module.exports = exports$1.default;
  36872. } (stripComments, stripComments.exports));
  36873. return stripComments.exports;
  36874. }
  36875. var hasRequiredUtil$1;
  36876. function requireUtil$1 () {
  36877. if (hasRequiredUtil$1) return util$1;
  36878. hasRequiredUtil$1 = 1;
  36879. util$1.__esModule = true;
  36880. util$1.unesc = util$1.stripComments = util$1.getProp = util$1.ensureObject = void 0;
  36881. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  36882. util$1.unesc = _unesc["default"];
  36883. var _getProp = _interopRequireDefault(/*@__PURE__*/ requireGetProp());
  36884. util$1.getProp = _getProp["default"];
  36885. var _ensureObject = _interopRequireDefault(/*@__PURE__*/ requireEnsureObject());
  36886. util$1.ensureObject = _ensureObject["default"];
  36887. var _stripComments = _interopRequireDefault(/*@__PURE__*/ requireStripComments());
  36888. util$1.stripComments = _stripComments["default"];
  36889. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36890. return util$1;
  36891. }
  36892. var hasRequiredNode$1;
  36893. function requireNode$1 () {
  36894. if (hasRequiredNode$1) return node$1.exports;
  36895. hasRequiredNode$1 = 1;
  36896. (function (module, exports$1) {
  36897. exports$1.__esModule = true;
  36898. exports$1["default"] = void 0;
  36899. var _util = /*@__PURE__*/ requireUtil$1();
  36900. 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); } }
  36901. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36902. var cloneNode = function cloneNode(obj, parent) {
  36903. if (typeof obj !== 'object' || obj === null) {
  36904. return obj;
  36905. }
  36906. var cloned = new obj.constructor();
  36907. for (var i in obj) {
  36908. if (!obj.hasOwnProperty(i)) {
  36909. continue;
  36910. }
  36911. var value = obj[i];
  36912. var type = typeof value;
  36913. if (i === 'parent' && type === 'object') {
  36914. if (parent) {
  36915. cloned[i] = parent;
  36916. }
  36917. } else if (value instanceof Array) {
  36918. cloned[i] = value.map(function (j) {
  36919. return cloneNode(j, cloned);
  36920. });
  36921. } else {
  36922. cloned[i] = cloneNode(value, cloned);
  36923. }
  36924. }
  36925. return cloned;
  36926. };
  36927. var Node = /*#__PURE__*/function () {
  36928. function Node(opts) {
  36929. if (opts === void 0) {
  36930. opts = {};
  36931. }
  36932. Object.assign(this, opts);
  36933. this.spaces = this.spaces || {};
  36934. this.spaces.before = this.spaces.before || '';
  36935. this.spaces.after = this.spaces.after || '';
  36936. }
  36937. var _proto = Node.prototype;
  36938. _proto.remove = function remove() {
  36939. if (this.parent) {
  36940. this.parent.removeChild(this);
  36941. }
  36942. this.parent = undefined;
  36943. return this;
  36944. };
  36945. _proto.replaceWith = function replaceWith() {
  36946. if (this.parent) {
  36947. for (var index in arguments) {
  36948. this.parent.insertBefore(this, arguments[index]);
  36949. }
  36950. this.remove();
  36951. }
  36952. return this;
  36953. };
  36954. _proto.next = function next() {
  36955. return this.parent.at(this.parent.index(this) + 1);
  36956. };
  36957. _proto.prev = function prev() {
  36958. return this.parent.at(this.parent.index(this) - 1);
  36959. };
  36960. _proto.clone = function clone(overrides) {
  36961. if (overrides === void 0) {
  36962. overrides = {};
  36963. }
  36964. var cloned = cloneNode(this);
  36965. for (var name in overrides) {
  36966. cloned[name] = overrides[name];
  36967. }
  36968. return cloned;
  36969. }
  36970. /**
  36971. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36972. * This allows non standard syntax to be appended to an existing property
  36973. * by specifying the escaped value. By specifying the escaped value,
  36974. * illegal characters are allowed to be directly inserted into css output.
  36975. * @param {string} name the property to set
  36976. * @param {any} value the unescaped value of the property
  36977. * @param {string} valueEscaped optional. the escaped value of the property.
  36978. */;
  36979. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  36980. if (!this.raws) {
  36981. this.raws = {};
  36982. }
  36983. var originalValue = this[name];
  36984. var originalEscaped = this.raws[name];
  36985. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  36986. if (originalEscaped || valueEscaped !== value) {
  36987. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  36988. } else {
  36989. delete this.raws[name]; // delete any escaped value that was created by the setter.
  36990. }
  36991. }
  36992. /**
  36993. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36994. * This allows the escaped value to be specified directly, allowing illegal
  36995. * characters to be directly inserted into css output.
  36996. * @param {string} name the property to set
  36997. * @param {any} value the unescaped value of the property
  36998. * @param {string} valueEscaped the escaped value of the property.
  36999. */;
  37000. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  37001. if (!this.raws) {
  37002. this.raws = {};
  37003. }
  37004. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37005. this.raws[name] = valueEscaped;
  37006. }
  37007. /**
  37008. * When you want a value to passed through to CSS directly. This method
  37009. * deletes the corresponding raw value causing the stringifier to fallback
  37010. * to the unescaped value.
  37011. * @param {string} name the property to set.
  37012. * @param {any} value The value that is both escaped and unescaped.
  37013. */;
  37014. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  37015. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37016. if (this.raws) {
  37017. delete this.raws[name];
  37018. }
  37019. }
  37020. /**
  37021. *
  37022. * @param {number} line The number (starting with 1)
  37023. * @param {number} column The column number (starting with 1)
  37024. */;
  37025. _proto.isAtPosition = function isAtPosition(line, column) {
  37026. if (this.source && this.source.start && this.source.end) {
  37027. if (this.source.start.line > line) {
  37028. return false;
  37029. }
  37030. if (this.source.end.line < line) {
  37031. return false;
  37032. }
  37033. if (this.source.start.line === line && this.source.start.column > column) {
  37034. return false;
  37035. }
  37036. if (this.source.end.line === line && this.source.end.column < column) {
  37037. return false;
  37038. }
  37039. return true;
  37040. }
  37041. return undefined;
  37042. };
  37043. _proto.stringifyProperty = function stringifyProperty(name) {
  37044. return this.raws && this.raws[name] || this[name];
  37045. };
  37046. _proto.valueToString = function valueToString() {
  37047. return String(this.stringifyProperty("value"));
  37048. };
  37049. _proto.toString = function toString() {
  37050. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  37051. };
  37052. _createClass(Node, [{
  37053. key: "rawSpaceBefore",
  37054. get: function get() {
  37055. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  37056. if (rawSpace === undefined) {
  37057. rawSpace = this.spaces && this.spaces.before;
  37058. }
  37059. return rawSpace || "";
  37060. },
  37061. set: function set(raw) {
  37062. (0, _util.ensureObject)(this, "raws", "spaces");
  37063. this.raws.spaces.before = raw;
  37064. }
  37065. }, {
  37066. key: "rawSpaceAfter",
  37067. get: function get() {
  37068. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  37069. if (rawSpace === undefined) {
  37070. rawSpace = this.spaces.after;
  37071. }
  37072. return rawSpace || "";
  37073. },
  37074. set: function set(raw) {
  37075. (0, _util.ensureObject)(this, "raws", "spaces");
  37076. this.raws.spaces.after = raw;
  37077. }
  37078. }]);
  37079. return Node;
  37080. }();
  37081. exports$1["default"] = Node;
  37082. module.exports = exports$1.default;
  37083. } (node$1, node$1.exports));
  37084. return node$1.exports;
  37085. }
  37086. var types = {};
  37087. var hasRequiredTypes;
  37088. function requireTypes () {
  37089. if (hasRequiredTypes) return types;
  37090. hasRequiredTypes = 1;
  37091. types.__esModule = true;
  37092. 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;
  37093. var TAG = 'tag';
  37094. types.TAG = TAG;
  37095. var STRING = 'string';
  37096. types.STRING = STRING;
  37097. var SELECTOR = 'selector';
  37098. types.SELECTOR = SELECTOR;
  37099. var ROOT = 'root';
  37100. types.ROOT = ROOT;
  37101. var PSEUDO = 'pseudo';
  37102. types.PSEUDO = PSEUDO;
  37103. var NESTING = 'nesting';
  37104. types.NESTING = NESTING;
  37105. var ID = 'id';
  37106. types.ID = ID;
  37107. var COMMENT = 'comment';
  37108. types.COMMENT = COMMENT;
  37109. var COMBINATOR = 'combinator';
  37110. types.COMBINATOR = COMBINATOR;
  37111. var CLASS = 'class';
  37112. types.CLASS = CLASS;
  37113. var ATTRIBUTE = 'attribute';
  37114. types.ATTRIBUTE = ATTRIBUTE;
  37115. var UNIVERSAL = 'universal';
  37116. types.UNIVERSAL = UNIVERSAL;
  37117. return types;
  37118. }
  37119. var hasRequiredContainer;
  37120. function requireContainer () {
  37121. if (hasRequiredContainer) return container.exports;
  37122. hasRequiredContainer = 1;
  37123. (function (module, exports$1) {
  37124. exports$1.__esModule = true;
  37125. exports$1["default"] = void 0;
  37126. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37127. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  37128. 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); }
  37129. 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; }
  37130. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37131. 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."); }
  37132. 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); }
  37133. 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; }
  37134. 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); } }
  37135. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37136. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37137. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37138. var Container = /*#__PURE__*/function (_Node) {
  37139. _inheritsLoose(Container, _Node);
  37140. function Container(opts) {
  37141. var _this;
  37142. _this = _Node.call(this, opts) || this;
  37143. if (!_this.nodes) {
  37144. _this.nodes = [];
  37145. }
  37146. return _this;
  37147. }
  37148. var _proto = Container.prototype;
  37149. _proto.append = function append(selector) {
  37150. selector.parent = this;
  37151. this.nodes.push(selector);
  37152. return this;
  37153. };
  37154. _proto.prepend = function prepend(selector) {
  37155. selector.parent = this;
  37156. this.nodes.unshift(selector);
  37157. for (var id in this.indexes) {
  37158. this.indexes[id]++;
  37159. }
  37160. return this;
  37161. };
  37162. _proto.at = function at(index) {
  37163. return this.nodes[index];
  37164. };
  37165. _proto.index = function index(child) {
  37166. if (typeof child === 'number') {
  37167. return child;
  37168. }
  37169. return this.nodes.indexOf(child);
  37170. };
  37171. _proto.removeChild = function removeChild(child) {
  37172. child = this.index(child);
  37173. this.at(child).parent = undefined;
  37174. this.nodes.splice(child, 1);
  37175. var index;
  37176. for (var id in this.indexes) {
  37177. index = this.indexes[id];
  37178. if (index >= child) {
  37179. this.indexes[id] = index - 1;
  37180. }
  37181. }
  37182. return this;
  37183. };
  37184. _proto.removeAll = function removeAll() {
  37185. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  37186. var node = _step.value;
  37187. node.parent = undefined;
  37188. }
  37189. this.nodes = [];
  37190. return this;
  37191. };
  37192. _proto.empty = function empty() {
  37193. return this.removeAll();
  37194. };
  37195. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  37196. var _this$nodes;
  37197. newNode.parent = this;
  37198. var oldIndex = this.index(oldNode);
  37199. var resetNode = [];
  37200. for (var i = 2; i < arguments.length; i++) {
  37201. resetNode.push(arguments[i]);
  37202. }
  37203. (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
  37204. newNode.parent = this;
  37205. var index;
  37206. for (var id in this.indexes) {
  37207. index = this.indexes[id];
  37208. if (oldIndex < index) {
  37209. this.indexes[id] = index + arguments.length - 1;
  37210. }
  37211. }
  37212. return this;
  37213. };
  37214. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  37215. var _this$nodes2;
  37216. newNode.parent = this;
  37217. var oldIndex = this.index(oldNode);
  37218. var resetNode = [];
  37219. for (var i = 2; i < arguments.length; i++) {
  37220. resetNode.push(arguments[i]);
  37221. }
  37222. (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
  37223. newNode.parent = this;
  37224. var index;
  37225. for (var id in this.indexes) {
  37226. index = this.indexes[id];
  37227. if (index >= oldIndex) {
  37228. this.indexes[id] = index + arguments.length - 1;
  37229. }
  37230. }
  37231. return this;
  37232. };
  37233. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  37234. var found = undefined;
  37235. this.each(function (node) {
  37236. if (node.atPosition) {
  37237. var foundChild = node.atPosition(line, col);
  37238. if (foundChild) {
  37239. found = foundChild;
  37240. return false;
  37241. }
  37242. } else if (node.isAtPosition(line, col)) {
  37243. found = node;
  37244. return false;
  37245. }
  37246. });
  37247. return found;
  37248. }
  37249. /**
  37250. * Return the most specific node at the line and column number given.
  37251. * The source location is based on the original parsed location, locations aren't
  37252. * updated as selector nodes are mutated.
  37253. *
  37254. * Note that this location is relative to the location of the first character
  37255. * of the selector, and not the location of the selector in the overall document
  37256. * when used in conjunction with postcss.
  37257. *
  37258. * If not found, returns undefined.
  37259. * @param {number} line The line number of the node to find. (1-based index)
  37260. * @param {number} col The column number of the node to find. (1-based index)
  37261. */;
  37262. _proto.atPosition = function atPosition(line, col) {
  37263. if (this.isAtPosition(line, col)) {
  37264. return this._findChildAtPosition(line, col) || this;
  37265. } else {
  37266. return undefined;
  37267. }
  37268. };
  37269. _proto._inferEndPosition = function _inferEndPosition() {
  37270. if (this.last && this.last.source && this.last.source.end) {
  37271. this.source = this.source || {};
  37272. this.source.end = this.source.end || {};
  37273. Object.assign(this.source.end, this.last.source.end);
  37274. }
  37275. };
  37276. _proto.each = function each(callback) {
  37277. if (!this.lastEach) {
  37278. this.lastEach = 0;
  37279. }
  37280. if (!this.indexes) {
  37281. this.indexes = {};
  37282. }
  37283. this.lastEach++;
  37284. var id = this.lastEach;
  37285. this.indexes[id] = 0;
  37286. if (!this.length) {
  37287. return undefined;
  37288. }
  37289. var index, result;
  37290. while (this.indexes[id] < this.length) {
  37291. index = this.indexes[id];
  37292. result = callback(this.at(index), index);
  37293. if (result === false) {
  37294. break;
  37295. }
  37296. this.indexes[id] += 1;
  37297. }
  37298. delete this.indexes[id];
  37299. if (result === false) {
  37300. return false;
  37301. }
  37302. };
  37303. _proto.walk = function walk(callback) {
  37304. return this.each(function (node, i) {
  37305. var result = callback(node, i);
  37306. if (result !== false && node.length) {
  37307. result = node.walk(callback);
  37308. }
  37309. if (result === false) {
  37310. return false;
  37311. }
  37312. });
  37313. };
  37314. _proto.walkAttributes = function walkAttributes(callback) {
  37315. var _this2 = this;
  37316. return this.walk(function (selector) {
  37317. if (selector.type === types.ATTRIBUTE) {
  37318. return callback.call(_this2, selector);
  37319. }
  37320. });
  37321. };
  37322. _proto.walkClasses = function walkClasses(callback) {
  37323. var _this3 = this;
  37324. return this.walk(function (selector) {
  37325. if (selector.type === types.CLASS) {
  37326. return callback.call(_this3, selector);
  37327. }
  37328. });
  37329. };
  37330. _proto.walkCombinators = function walkCombinators(callback) {
  37331. var _this4 = this;
  37332. return this.walk(function (selector) {
  37333. if (selector.type === types.COMBINATOR) {
  37334. return callback.call(_this4, selector);
  37335. }
  37336. });
  37337. };
  37338. _proto.walkComments = function walkComments(callback) {
  37339. var _this5 = this;
  37340. return this.walk(function (selector) {
  37341. if (selector.type === types.COMMENT) {
  37342. return callback.call(_this5, selector);
  37343. }
  37344. });
  37345. };
  37346. _proto.walkIds = function walkIds(callback) {
  37347. var _this6 = this;
  37348. return this.walk(function (selector) {
  37349. if (selector.type === types.ID) {
  37350. return callback.call(_this6, selector);
  37351. }
  37352. });
  37353. };
  37354. _proto.walkNesting = function walkNesting(callback) {
  37355. var _this7 = this;
  37356. return this.walk(function (selector) {
  37357. if (selector.type === types.NESTING) {
  37358. return callback.call(_this7, selector);
  37359. }
  37360. });
  37361. };
  37362. _proto.walkPseudos = function walkPseudos(callback) {
  37363. var _this8 = this;
  37364. return this.walk(function (selector) {
  37365. if (selector.type === types.PSEUDO) {
  37366. return callback.call(_this8, selector);
  37367. }
  37368. });
  37369. };
  37370. _proto.walkTags = function walkTags(callback) {
  37371. var _this9 = this;
  37372. return this.walk(function (selector) {
  37373. if (selector.type === types.TAG) {
  37374. return callback.call(_this9, selector);
  37375. }
  37376. });
  37377. };
  37378. _proto.walkUniversals = function walkUniversals(callback) {
  37379. var _this10 = this;
  37380. return this.walk(function (selector) {
  37381. if (selector.type === types.UNIVERSAL) {
  37382. return callback.call(_this10, selector);
  37383. }
  37384. });
  37385. };
  37386. _proto.split = function split(callback) {
  37387. var _this11 = this;
  37388. var current = [];
  37389. return this.reduce(function (memo, node, index) {
  37390. var split = callback.call(_this11, node);
  37391. current.push(node);
  37392. if (split) {
  37393. memo.push(current);
  37394. current = [];
  37395. } else if (index === _this11.length - 1) {
  37396. memo.push(current);
  37397. }
  37398. return memo;
  37399. }, []);
  37400. };
  37401. _proto.map = function map(callback) {
  37402. return this.nodes.map(callback);
  37403. };
  37404. _proto.reduce = function reduce(callback, memo) {
  37405. return this.nodes.reduce(callback, memo);
  37406. };
  37407. _proto.every = function every(callback) {
  37408. return this.nodes.every(callback);
  37409. };
  37410. _proto.some = function some(callback) {
  37411. return this.nodes.some(callback);
  37412. };
  37413. _proto.filter = function filter(callback) {
  37414. return this.nodes.filter(callback);
  37415. };
  37416. _proto.sort = function sort(callback) {
  37417. return this.nodes.sort(callback);
  37418. };
  37419. _proto.toString = function toString() {
  37420. return this.map(String).join('');
  37421. };
  37422. _createClass(Container, [{
  37423. key: "first",
  37424. get: function get() {
  37425. return this.at(0);
  37426. }
  37427. }, {
  37428. key: "last",
  37429. get: function get() {
  37430. return this.at(this.length - 1);
  37431. }
  37432. }, {
  37433. key: "length",
  37434. get: function get() {
  37435. return this.nodes.length;
  37436. }
  37437. }]);
  37438. return Container;
  37439. }(_node["default"]);
  37440. exports$1["default"] = Container;
  37441. module.exports = exports$1.default;
  37442. } (container, container.exports));
  37443. return container.exports;
  37444. }
  37445. var hasRequiredRoot;
  37446. function requireRoot () {
  37447. if (hasRequiredRoot) return root.exports;
  37448. hasRequiredRoot = 1;
  37449. (function (module, exports$1) {
  37450. exports$1.__esModule = true;
  37451. exports$1["default"] = void 0;
  37452. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37453. var _types = /*@__PURE__*/ requireTypes();
  37454. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37455. 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); } }
  37456. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37457. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37458. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37459. var Root = /*#__PURE__*/function (_Container) {
  37460. _inheritsLoose(Root, _Container);
  37461. function Root(opts) {
  37462. var _this;
  37463. _this = _Container.call(this, opts) || this;
  37464. _this.type = _types.ROOT;
  37465. return _this;
  37466. }
  37467. var _proto = Root.prototype;
  37468. _proto.toString = function toString() {
  37469. var str = this.reduce(function (memo, selector) {
  37470. memo.push(String(selector));
  37471. return memo;
  37472. }, []).join(',');
  37473. return this.trailingComma ? str + ',' : str;
  37474. };
  37475. _proto.error = function error(message, options) {
  37476. if (this._error) {
  37477. return this._error(message, options);
  37478. } else {
  37479. return new Error(message);
  37480. }
  37481. };
  37482. _createClass(Root, [{
  37483. key: "errorGenerator",
  37484. set: function set(handler) {
  37485. this._error = handler;
  37486. }
  37487. }]);
  37488. return Root;
  37489. }(_container["default"]);
  37490. exports$1["default"] = Root;
  37491. module.exports = exports$1.default;
  37492. } (root, root.exports));
  37493. return root.exports;
  37494. }
  37495. var selector = {exports: {}};
  37496. var hasRequiredSelector;
  37497. function requireSelector () {
  37498. if (hasRequiredSelector) return selector.exports;
  37499. hasRequiredSelector = 1;
  37500. (function (module, exports$1) {
  37501. exports$1.__esModule = true;
  37502. exports$1["default"] = void 0;
  37503. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37504. var _types = /*@__PURE__*/ requireTypes();
  37505. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37506. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37507. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37508. var Selector = /*#__PURE__*/function (_Container) {
  37509. _inheritsLoose(Selector, _Container);
  37510. function Selector(opts) {
  37511. var _this;
  37512. _this = _Container.call(this, opts) || this;
  37513. _this.type = _types.SELECTOR;
  37514. return _this;
  37515. }
  37516. return Selector;
  37517. }(_container["default"]);
  37518. exports$1["default"] = Selector;
  37519. module.exports = exports$1.default;
  37520. } (selector, selector.exports));
  37521. return selector.exports;
  37522. }
  37523. var className = {exports: {}};
  37524. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  37525. var cssesc_1;
  37526. var hasRequiredCssesc;
  37527. function requireCssesc () {
  37528. if (hasRequiredCssesc) return cssesc_1;
  37529. hasRequiredCssesc = 1;
  37530. var object = {};
  37531. var hasOwnProperty = object.hasOwnProperty;
  37532. var merge = function merge(options, defaults) {
  37533. if (!options) {
  37534. return defaults;
  37535. }
  37536. var result = {};
  37537. for (var key in defaults) {
  37538. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  37539. // only recognized option names are used.
  37540. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  37541. }
  37542. return result;
  37543. };
  37544. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  37545. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  37546. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  37547. // https://mathiasbynens.be/notes/css-escapes#css
  37548. var cssesc = function cssesc(string, options) {
  37549. options = merge(options, cssesc.options);
  37550. if (options.quotes != 'single' && options.quotes != 'double') {
  37551. options.quotes = 'single';
  37552. }
  37553. var quote = options.quotes == 'double' ? '"' : '\'';
  37554. var isIdentifier = options.isIdentifier;
  37555. var firstChar = string.charAt(0);
  37556. var output = '';
  37557. var counter = 0;
  37558. var length = string.length;
  37559. while (counter < length) {
  37560. var character = string.charAt(counter++);
  37561. var codePoint = character.charCodeAt();
  37562. var value = void 0;
  37563. // If it’s not a printable ASCII character…
  37564. if (codePoint < 0x20 || codePoint > 0x7E) {
  37565. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37566. // It’s a high surrogate, and there is a next character.
  37567. var extra = string.charCodeAt(counter++);
  37568. if ((extra & 0xFC00) == 0xDC00) {
  37569. // next character is low surrogate
  37570. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37571. } else {
  37572. // It’s an unmatched surrogate; only append this code unit, in case
  37573. // the next code unit is the high surrogate of a surrogate pair.
  37574. counter--;
  37575. }
  37576. }
  37577. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37578. } else {
  37579. if (options.escapeEverything) {
  37580. if (regexAnySingleEscape.test(character)) {
  37581. value = '\\' + character;
  37582. } else {
  37583. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37584. }
  37585. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37586. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37587. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37588. value = '\\' + character;
  37589. } else {
  37590. value = character;
  37591. }
  37592. }
  37593. output += value;
  37594. }
  37595. if (isIdentifier) {
  37596. if (/^-[-\d]/.test(output)) {
  37597. output = '\\-' + output.slice(1);
  37598. } else if (/\d/.test(firstChar)) {
  37599. output = '\\3' + firstChar + ' ' + output.slice(1);
  37600. }
  37601. }
  37602. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37603. // since they’re redundant. Note that this is only possible if the escape
  37604. // sequence isn’t preceded by an odd number of backslashes.
  37605. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37606. if ($1 && $1.length % 2) {
  37607. // It’s not safe to remove the space, so don’t.
  37608. return $0;
  37609. }
  37610. // Strip the space.
  37611. return ($1 || '') + $2;
  37612. });
  37613. if (!isIdentifier && options.wrap) {
  37614. return quote + output + quote;
  37615. }
  37616. return output;
  37617. };
  37618. // Expose default options (so they can be overridden globally).
  37619. cssesc.options = {
  37620. 'escapeEverything': false,
  37621. 'isIdentifier': false,
  37622. 'quotes': 'single',
  37623. 'wrap': false
  37624. };
  37625. cssesc.version = '3.0.0';
  37626. cssesc_1 = cssesc;
  37627. return cssesc_1;
  37628. }
  37629. var hasRequiredClassName;
  37630. function requireClassName () {
  37631. if (hasRequiredClassName) return className.exports;
  37632. hasRequiredClassName = 1;
  37633. (function (module, exports$1) {
  37634. exports$1.__esModule = true;
  37635. exports$1["default"] = void 0;
  37636. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37637. var _util = /*@__PURE__*/ requireUtil$1();
  37638. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37639. var _types = /*@__PURE__*/ requireTypes();
  37640. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37641. 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); } }
  37642. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37643. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37644. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37645. var ClassName = /*#__PURE__*/function (_Node) {
  37646. _inheritsLoose(ClassName, _Node);
  37647. function ClassName(opts) {
  37648. var _this;
  37649. _this = _Node.call(this, opts) || this;
  37650. _this.type = _types.CLASS;
  37651. _this._constructed = true;
  37652. return _this;
  37653. }
  37654. var _proto = ClassName.prototype;
  37655. _proto.valueToString = function valueToString() {
  37656. return '.' + _Node.prototype.valueToString.call(this);
  37657. };
  37658. _createClass(ClassName, [{
  37659. key: "value",
  37660. get: function get() {
  37661. return this._value;
  37662. },
  37663. set: function set(v) {
  37664. if (this._constructed) {
  37665. var escaped = (0, _cssesc["default"])(v, {
  37666. isIdentifier: true
  37667. });
  37668. if (escaped !== v) {
  37669. (0, _util.ensureObject)(this, "raws");
  37670. this.raws.value = escaped;
  37671. } else if (this.raws) {
  37672. delete this.raws.value;
  37673. }
  37674. }
  37675. this._value = v;
  37676. }
  37677. }]);
  37678. return ClassName;
  37679. }(_node["default"]);
  37680. exports$1["default"] = ClassName;
  37681. module.exports = exports$1.default;
  37682. } (className, className.exports));
  37683. return className.exports;
  37684. }
  37685. var comment = {exports: {}};
  37686. var hasRequiredComment;
  37687. function requireComment () {
  37688. if (hasRequiredComment) return comment.exports;
  37689. hasRequiredComment = 1;
  37690. (function (module, exports$1) {
  37691. exports$1.__esModule = true;
  37692. exports$1["default"] = void 0;
  37693. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37694. var _types = /*@__PURE__*/ requireTypes();
  37695. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37696. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37697. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37698. var Comment = /*#__PURE__*/function (_Node) {
  37699. _inheritsLoose(Comment, _Node);
  37700. function Comment(opts) {
  37701. var _this;
  37702. _this = _Node.call(this, opts) || this;
  37703. _this.type = _types.COMMENT;
  37704. return _this;
  37705. }
  37706. return Comment;
  37707. }(_node["default"]);
  37708. exports$1["default"] = Comment;
  37709. module.exports = exports$1.default;
  37710. } (comment, comment.exports));
  37711. return comment.exports;
  37712. }
  37713. var id = {exports: {}};
  37714. var hasRequiredId;
  37715. function requireId () {
  37716. if (hasRequiredId) return id.exports;
  37717. hasRequiredId = 1;
  37718. (function (module, exports$1) {
  37719. exports$1.__esModule = true;
  37720. exports$1["default"] = void 0;
  37721. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37722. var _types = /*@__PURE__*/ requireTypes();
  37723. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37724. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37725. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37726. var ID = /*#__PURE__*/function (_Node) {
  37727. _inheritsLoose(ID, _Node);
  37728. function ID(opts) {
  37729. var _this;
  37730. _this = _Node.call(this, opts) || this;
  37731. _this.type = _types.ID;
  37732. return _this;
  37733. }
  37734. var _proto = ID.prototype;
  37735. _proto.valueToString = function valueToString() {
  37736. return '#' + _Node.prototype.valueToString.call(this);
  37737. };
  37738. return ID;
  37739. }(_node["default"]);
  37740. exports$1["default"] = ID;
  37741. module.exports = exports$1.default;
  37742. } (id, id.exports));
  37743. return id.exports;
  37744. }
  37745. var tag = {exports: {}};
  37746. var namespace = {exports: {}};
  37747. var hasRequiredNamespace;
  37748. function requireNamespace () {
  37749. if (hasRequiredNamespace) return namespace.exports;
  37750. hasRequiredNamespace = 1;
  37751. (function (module, exports$1) {
  37752. exports$1.__esModule = true;
  37753. exports$1["default"] = void 0;
  37754. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37755. var _util = /*@__PURE__*/ requireUtil$1();
  37756. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37757. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37758. 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); } }
  37759. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37760. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37761. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37762. var Namespace = /*#__PURE__*/function (_Node) {
  37763. _inheritsLoose(Namespace, _Node);
  37764. function Namespace() {
  37765. return _Node.apply(this, arguments) || this;
  37766. }
  37767. var _proto = Namespace.prototype;
  37768. _proto.qualifiedName = function qualifiedName(value) {
  37769. if (this.namespace) {
  37770. return this.namespaceString + "|" + value;
  37771. } else {
  37772. return value;
  37773. }
  37774. };
  37775. _proto.valueToString = function valueToString() {
  37776. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37777. };
  37778. _createClass(Namespace, [{
  37779. key: "namespace",
  37780. get: function get() {
  37781. return this._namespace;
  37782. },
  37783. set: function set(namespace) {
  37784. if (namespace === true || namespace === "*" || namespace === "&") {
  37785. this._namespace = namespace;
  37786. if (this.raws) {
  37787. delete this.raws.namespace;
  37788. }
  37789. return;
  37790. }
  37791. var escaped = (0, _cssesc["default"])(namespace, {
  37792. isIdentifier: true
  37793. });
  37794. this._namespace = namespace;
  37795. if (escaped !== namespace) {
  37796. (0, _util.ensureObject)(this, "raws");
  37797. this.raws.namespace = escaped;
  37798. } else if (this.raws) {
  37799. delete this.raws.namespace;
  37800. }
  37801. }
  37802. }, {
  37803. key: "ns",
  37804. get: function get() {
  37805. return this._namespace;
  37806. },
  37807. set: function set(namespace) {
  37808. this.namespace = namespace;
  37809. }
  37810. }, {
  37811. key: "namespaceString",
  37812. get: function get() {
  37813. if (this.namespace) {
  37814. var ns = this.stringifyProperty("namespace");
  37815. if (ns === true) {
  37816. return '';
  37817. } else {
  37818. return ns;
  37819. }
  37820. } else {
  37821. return '';
  37822. }
  37823. }
  37824. }]);
  37825. return Namespace;
  37826. }(_node["default"]);
  37827. exports$1["default"] = Namespace;
  37828. module.exports = exports$1.default;
  37829. } (namespace, namespace.exports));
  37830. return namespace.exports;
  37831. }
  37832. var hasRequiredTag;
  37833. function requireTag () {
  37834. if (hasRequiredTag) return tag.exports;
  37835. hasRequiredTag = 1;
  37836. (function (module, exports$1) {
  37837. exports$1.__esModule = true;
  37838. exports$1["default"] = void 0;
  37839. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37840. var _types = /*@__PURE__*/ requireTypes();
  37841. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37842. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37843. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37844. var Tag = /*#__PURE__*/function (_Namespace) {
  37845. _inheritsLoose(Tag, _Namespace);
  37846. function Tag(opts) {
  37847. var _this;
  37848. _this = _Namespace.call(this, opts) || this;
  37849. _this.type = _types.TAG;
  37850. return _this;
  37851. }
  37852. return Tag;
  37853. }(_namespace["default"]);
  37854. exports$1["default"] = Tag;
  37855. module.exports = exports$1.default;
  37856. } (tag, tag.exports));
  37857. return tag.exports;
  37858. }
  37859. var string = {exports: {}};
  37860. var hasRequiredString;
  37861. function requireString () {
  37862. if (hasRequiredString) return string.exports;
  37863. hasRequiredString = 1;
  37864. (function (module, exports$1) {
  37865. exports$1.__esModule = true;
  37866. exports$1["default"] = void 0;
  37867. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37868. var _types = /*@__PURE__*/ requireTypes();
  37869. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37870. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37871. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37872. var String = /*#__PURE__*/function (_Node) {
  37873. _inheritsLoose(String, _Node);
  37874. function String(opts) {
  37875. var _this;
  37876. _this = _Node.call(this, opts) || this;
  37877. _this.type = _types.STRING;
  37878. return _this;
  37879. }
  37880. return String;
  37881. }(_node["default"]);
  37882. exports$1["default"] = String;
  37883. module.exports = exports$1.default;
  37884. } (string, string.exports));
  37885. return string.exports;
  37886. }
  37887. var pseudo = {exports: {}};
  37888. var hasRequiredPseudo;
  37889. function requirePseudo () {
  37890. if (hasRequiredPseudo) return pseudo.exports;
  37891. hasRequiredPseudo = 1;
  37892. (function (module, exports$1) {
  37893. exports$1.__esModule = true;
  37894. exports$1["default"] = void 0;
  37895. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37896. var _types = /*@__PURE__*/ requireTypes();
  37897. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37898. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37899. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37900. var Pseudo = /*#__PURE__*/function (_Container) {
  37901. _inheritsLoose(Pseudo, _Container);
  37902. function Pseudo(opts) {
  37903. var _this;
  37904. _this = _Container.call(this, opts) || this;
  37905. _this.type = _types.PSEUDO;
  37906. return _this;
  37907. }
  37908. var _proto = Pseudo.prototype;
  37909. _proto.toString = function toString() {
  37910. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37911. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37912. };
  37913. return Pseudo;
  37914. }(_container["default"]);
  37915. exports$1["default"] = Pseudo;
  37916. module.exports = exports$1.default;
  37917. } (pseudo, pseudo.exports));
  37918. return pseudo.exports;
  37919. }
  37920. var attribute = {};
  37921. var node;
  37922. var hasRequiredNode;
  37923. function requireNode () {
  37924. if (hasRequiredNode) return node;
  37925. hasRequiredNode = 1;
  37926. /**
  37927. * For Node.js, simply re-export the core `util.deprecate` function.
  37928. */
  37929. node = require$$0.deprecate;
  37930. return node;
  37931. }
  37932. var hasRequiredAttribute;
  37933. function requireAttribute () {
  37934. if (hasRequiredAttribute) return attribute;
  37935. hasRequiredAttribute = 1;
  37936. (function (exports$1) {
  37937. exports$1.__esModule = true;
  37938. exports$1["default"] = void 0;
  37939. exports$1.unescapeValue = unescapeValue;
  37940. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37941. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  37942. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37943. var _types = /*@__PURE__*/ requireTypes();
  37944. var _CSSESC_QUOTE_OPTIONS;
  37945. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37946. 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); } }
  37947. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37948. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37949. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37950. var deprecate = /*@__PURE__*/ requireNode();
  37951. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37952. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37953. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37954. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37955. function unescapeValue(value) {
  37956. var deprecatedUsage = false;
  37957. var quoteMark = null;
  37958. var unescaped = value;
  37959. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37960. if (m) {
  37961. quoteMark = m[1];
  37962. unescaped = m[2];
  37963. }
  37964. unescaped = (0, _unesc["default"])(unescaped);
  37965. if (unescaped !== value) {
  37966. deprecatedUsage = true;
  37967. }
  37968. return {
  37969. deprecatedUsage: deprecatedUsage,
  37970. unescaped: unescaped,
  37971. quoteMark: quoteMark
  37972. };
  37973. }
  37974. function handleDeprecatedContructorOpts(opts) {
  37975. if (opts.quoteMark !== undefined) {
  37976. return opts;
  37977. }
  37978. if (opts.value === undefined) {
  37979. return opts;
  37980. }
  37981. warnOfDeprecatedConstructor();
  37982. var _unescapeValue = unescapeValue(opts.value),
  37983. quoteMark = _unescapeValue.quoteMark,
  37984. unescaped = _unescapeValue.unescaped;
  37985. if (!opts.raws) {
  37986. opts.raws = {};
  37987. }
  37988. if (opts.raws.value === undefined) {
  37989. opts.raws.value = opts.value;
  37990. }
  37991. opts.value = unescaped;
  37992. opts.quoteMark = quoteMark;
  37993. return opts;
  37994. }
  37995. var Attribute = /*#__PURE__*/function (_Namespace) {
  37996. _inheritsLoose(Attribute, _Namespace);
  37997. function Attribute(opts) {
  37998. var _this;
  37999. if (opts === void 0) {
  38000. opts = {};
  38001. }
  38002. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  38003. _this.type = _types.ATTRIBUTE;
  38004. _this.raws = _this.raws || {};
  38005. Object.defineProperty(_this.raws, 'unquoted', {
  38006. get: deprecate(function () {
  38007. return _this.value;
  38008. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  38009. set: deprecate(function () {
  38010. return _this.value;
  38011. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  38012. });
  38013. _this._constructed = true;
  38014. return _this;
  38015. }
  38016. /**
  38017. * Returns the Attribute's value quoted such that it would be legal to use
  38018. * in the value of a css file. The original value's quotation setting
  38019. * used for stringification is left unchanged. See `setValue(value, options)`
  38020. * if you want to control the quote settings of a new value for the attribute.
  38021. *
  38022. * You can also change the quotation used for the current value by setting quoteMark.
  38023. *
  38024. * Options:
  38025. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  38026. * option is not set, the original value for quoteMark will be used. If
  38027. * indeterminate, a double quote is used. The legal values are:
  38028. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  38029. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  38030. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  38031. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  38032. * over the quoteMark option value.
  38033. * * smart {boolean} - if true, will select a quote mark based on the value
  38034. * and the other options specified here. See the `smartQuoteMark()`
  38035. * method.
  38036. **/
  38037. var _proto = Attribute.prototype;
  38038. _proto.getQuotedValue = function getQuotedValue(options) {
  38039. if (options === void 0) {
  38040. options = {};
  38041. }
  38042. var quoteMark = this._determineQuoteMark(options);
  38043. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  38044. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  38045. return escaped;
  38046. };
  38047. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  38048. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  38049. }
  38050. /**
  38051. * Set the unescaped value with the specified quotation options. The value
  38052. * provided must not include any wrapping quote marks -- those quotes will
  38053. * be interpreted as part of the value and escaped accordingly.
  38054. */;
  38055. _proto.setValue = function setValue(value, options) {
  38056. if (options === void 0) {
  38057. options = {};
  38058. }
  38059. this._value = value;
  38060. this._quoteMark = this._determineQuoteMark(options);
  38061. this._syncRawValue();
  38062. }
  38063. /**
  38064. * Intelligently select a quoteMark value based on the value's contents. If
  38065. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  38066. * mark will be picked that minimizes the number of escapes.
  38067. *
  38068. * If there's no clear winner, the quote mark from these options is used,
  38069. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  38070. * true). If the quoteMark is unspecified, a double quote is used.
  38071. *
  38072. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  38073. * from the quoteValue method.
  38074. */;
  38075. _proto.smartQuoteMark = function smartQuoteMark(options) {
  38076. var v = this.value;
  38077. var numSingleQuotes = v.replace(/[^']/g, '').length;
  38078. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  38079. if (numSingleQuotes + numDoubleQuotes === 0) {
  38080. var escaped = (0, _cssesc["default"])(v, {
  38081. isIdentifier: true
  38082. });
  38083. if (escaped === v) {
  38084. return Attribute.NO_QUOTE;
  38085. } else {
  38086. var pref = this.preferredQuoteMark(options);
  38087. if (pref === Attribute.NO_QUOTE) {
  38088. // pick a quote mark that isn't none and see if it's smaller
  38089. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  38090. var opts = CSSESC_QUOTE_OPTIONS[quote];
  38091. var quoteValue = (0, _cssesc["default"])(v, opts);
  38092. if (quoteValue.length < escaped.length) {
  38093. return quote;
  38094. }
  38095. }
  38096. return pref;
  38097. }
  38098. } else if (numDoubleQuotes === numSingleQuotes) {
  38099. return this.preferredQuoteMark(options);
  38100. } else if (numDoubleQuotes < numSingleQuotes) {
  38101. return Attribute.DOUBLE_QUOTE;
  38102. } else {
  38103. return Attribute.SINGLE_QUOTE;
  38104. }
  38105. }
  38106. /**
  38107. * Selects the preferred quote mark based on the options and the current quote mark value.
  38108. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  38109. * instead.
  38110. */;
  38111. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  38112. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  38113. if (quoteMark === undefined) {
  38114. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  38115. }
  38116. if (quoteMark === undefined) {
  38117. quoteMark = Attribute.DOUBLE_QUOTE;
  38118. }
  38119. return quoteMark;
  38120. };
  38121. _proto._syncRawValue = function _syncRawValue() {
  38122. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  38123. if (rawValue === this._value) {
  38124. if (this.raws) {
  38125. delete this.raws.value;
  38126. }
  38127. } else {
  38128. this.raws.value = rawValue;
  38129. }
  38130. };
  38131. _proto._handleEscapes = function _handleEscapes(prop, value) {
  38132. if (this._constructed) {
  38133. var escaped = (0, _cssesc["default"])(value, {
  38134. isIdentifier: true
  38135. });
  38136. if (escaped !== value) {
  38137. this.raws[prop] = escaped;
  38138. } else {
  38139. delete this.raws[prop];
  38140. }
  38141. }
  38142. };
  38143. _proto._spacesFor = function _spacesFor(name) {
  38144. var attrSpaces = {
  38145. before: '',
  38146. after: ''
  38147. };
  38148. var spaces = this.spaces[name] || {};
  38149. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  38150. return Object.assign(attrSpaces, spaces, rawSpaces);
  38151. };
  38152. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  38153. if (spaceName === void 0) {
  38154. spaceName = name;
  38155. }
  38156. if (concat === void 0) {
  38157. concat = defaultAttrConcat;
  38158. }
  38159. var attrSpaces = this._spacesFor(spaceName);
  38160. return concat(this.stringifyProperty(name), attrSpaces);
  38161. }
  38162. /**
  38163. * returns the offset of the attribute part specified relative to the
  38164. * start of the node of the output string.
  38165. *
  38166. * * "ns" - alias for "namespace"
  38167. * * "namespace" - the namespace if it exists.
  38168. * * "attribute" - the attribute name
  38169. * * "attributeNS" - the start of the attribute or its namespace
  38170. * * "operator" - the match operator of the attribute
  38171. * * "value" - The value (string or identifier)
  38172. * * "insensitive" - the case insensitivity flag;
  38173. * @param part One of the possible values inside an attribute.
  38174. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  38175. */;
  38176. _proto.offsetOf = function offsetOf(name) {
  38177. var count = 1;
  38178. var attributeSpaces = this._spacesFor("attribute");
  38179. count += attributeSpaces.before.length;
  38180. if (name === "namespace" || name === "ns") {
  38181. return this.namespace ? count : -1;
  38182. }
  38183. if (name === "attributeNS") {
  38184. return count;
  38185. }
  38186. count += this.namespaceString.length;
  38187. if (this.namespace) {
  38188. count += 1;
  38189. }
  38190. if (name === "attribute") {
  38191. return count;
  38192. }
  38193. count += this.stringifyProperty("attribute").length;
  38194. count += attributeSpaces.after.length;
  38195. var operatorSpaces = this._spacesFor("operator");
  38196. count += operatorSpaces.before.length;
  38197. var operator = this.stringifyProperty("operator");
  38198. if (name === "operator") {
  38199. return operator ? count : -1;
  38200. }
  38201. count += operator.length;
  38202. count += operatorSpaces.after.length;
  38203. var valueSpaces = this._spacesFor("value");
  38204. count += valueSpaces.before.length;
  38205. var value = this.stringifyProperty("value");
  38206. if (name === "value") {
  38207. return value ? count : -1;
  38208. }
  38209. count += value.length;
  38210. count += valueSpaces.after.length;
  38211. var insensitiveSpaces = this._spacesFor("insensitive");
  38212. count += insensitiveSpaces.before.length;
  38213. if (name === "insensitive") {
  38214. return this.insensitive ? count : -1;
  38215. }
  38216. return -1;
  38217. };
  38218. _proto.toString = function toString() {
  38219. var _this2 = this;
  38220. var selector = [this.rawSpaceBefore, '['];
  38221. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  38222. if (this.operator && (this.value || this.value === '')) {
  38223. selector.push(this._stringFor('operator'));
  38224. selector.push(this._stringFor('value'));
  38225. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  38226. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  38227. attrSpaces.before = " ";
  38228. }
  38229. return defaultAttrConcat(attrValue, attrSpaces);
  38230. }));
  38231. }
  38232. selector.push(']');
  38233. selector.push(this.rawSpaceAfter);
  38234. return selector.join('');
  38235. };
  38236. _createClass(Attribute, [{
  38237. key: "quoted",
  38238. get: function get() {
  38239. var qm = this.quoteMark;
  38240. return qm === "'" || qm === '"';
  38241. },
  38242. set: function set(value) {
  38243. warnOfDeprecatedQuotedAssignment();
  38244. }
  38245. /**
  38246. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  38247. * returns `null` if the value is not quoted.
  38248. * returns `undefined` if the quotation state is unknown (this can happen when
  38249. * the attribute is constructed without specifying a quote mark.)
  38250. */
  38251. }, {
  38252. key: "quoteMark",
  38253. get: function get() {
  38254. return this._quoteMark;
  38255. }
  38256. /**
  38257. * Set the quote mark to be used by this attribute's value.
  38258. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  38259. * value is updated accordingly.
  38260. *
  38261. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  38262. */,
  38263. set: function set(quoteMark) {
  38264. if (!this._constructed) {
  38265. this._quoteMark = quoteMark;
  38266. return;
  38267. }
  38268. if (this._quoteMark !== quoteMark) {
  38269. this._quoteMark = quoteMark;
  38270. this._syncRawValue();
  38271. }
  38272. }
  38273. }, {
  38274. key: "qualifiedAttribute",
  38275. get: function get() {
  38276. return this.qualifiedName(this.raws.attribute || this.attribute);
  38277. }
  38278. }, {
  38279. key: "insensitiveFlag",
  38280. get: function get() {
  38281. return this.insensitive ? 'i' : '';
  38282. }
  38283. }, {
  38284. key: "value",
  38285. get: function get() {
  38286. return this._value;
  38287. },
  38288. set:
  38289. /**
  38290. * Before 3.0, the value had to be set to an escaped value including any wrapped
  38291. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  38292. * is unescaped during parsing and any quote marks are removed.
  38293. *
  38294. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  38295. * a deprecation warning is raised when the new value contains any characters that would
  38296. * require escaping (including if it contains wrapped quotes).
  38297. *
  38298. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  38299. * how the new value is quoted.
  38300. */
  38301. function set(v) {
  38302. if (this._constructed) {
  38303. var _unescapeValue2 = unescapeValue(v),
  38304. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  38305. unescaped = _unescapeValue2.unescaped,
  38306. quoteMark = _unescapeValue2.quoteMark;
  38307. if (deprecatedUsage) {
  38308. warnOfDeprecatedValueAssignment();
  38309. }
  38310. if (unescaped === this._value && quoteMark === this._quoteMark) {
  38311. return;
  38312. }
  38313. this._value = unescaped;
  38314. this._quoteMark = quoteMark;
  38315. this._syncRawValue();
  38316. } else {
  38317. this._value = v;
  38318. }
  38319. }
  38320. }, {
  38321. key: "insensitive",
  38322. get: function get() {
  38323. return this._insensitive;
  38324. }
  38325. /**
  38326. * Set the case insensitive flag.
  38327. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  38328. * of the attribute is updated accordingly.
  38329. *
  38330. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  38331. */,
  38332. set: function set(insensitive) {
  38333. if (!insensitive) {
  38334. this._insensitive = false;
  38335. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  38336. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  38337. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  38338. this.raws.insensitiveFlag = undefined;
  38339. }
  38340. }
  38341. this._insensitive = insensitive;
  38342. }
  38343. }, {
  38344. key: "attribute",
  38345. get: function get() {
  38346. return this._attribute;
  38347. },
  38348. set: function set(name) {
  38349. this._handleEscapes("attribute", name);
  38350. this._attribute = name;
  38351. }
  38352. }]);
  38353. return Attribute;
  38354. }(_namespace["default"]);
  38355. exports$1["default"] = Attribute;
  38356. Attribute.NO_QUOTE = null;
  38357. Attribute.SINGLE_QUOTE = "'";
  38358. Attribute.DOUBLE_QUOTE = '"';
  38359. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  38360. "'": {
  38361. quotes: 'single',
  38362. wrap: true
  38363. },
  38364. '"': {
  38365. quotes: 'double',
  38366. wrap: true
  38367. }
  38368. }, _CSSESC_QUOTE_OPTIONS[null] = {
  38369. isIdentifier: true
  38370. }, _CSSESC_QUOTE_OPTIONS);
  38371. function defaultAttrConcat(attrValue, attrSpaces) {
  38372. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  38373. }
  38374. } (attribute));
  38375. return attribute;
  38376. }
  38377. var universal = {exports: {}};
  38378. var hasRequiredUniversal;
  38379. function requireUniversal () {
  38380. if (hasRequiredUniversal) return universal.exports;
  38381. hasRequiredUniversal = 1;
  38382. (function (module, exports$1) {
  38383. exports$1.__esModule = true;
  38384. exports$1["default"] = void 0;
  38385. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  38386. var _types = /*@__PURE__*/ requireTypes();
  38387. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38388. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38389. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38390. var Universal = /*#__PURE__*/function (_Namespace) {
  38391. _inheritsLoose(Universal, _Namespace);
  38392. function Universal(opts) {
  38393. var _this;
  38394. _this = _Namespace.call(this, opts) || this;
  38395. _this.type = _types.UNIVERSAL;
  38396. _this.value = '*';
  38397. return _this;
  38398. }
  38399. return Universal;
  38400. }(_namespace["default"]);
  38401. exports$1["default"] = Universal;
  38402. module.exports = exports$1.default;
  38403. } (universal, universal.exports));
  38404. return universal.exports;
  38405. }
  38406. var combinator = {exports: {}};
  38407. var hasRequiredCombinator;
  38408. function requireCombinator () {
  38409. if (hasRequiredCombinator) return combinator.exports;
  38410. hasRequiredCombinator = 1;
  38411. (function (module, exports$1) {
  38412. exports$1.__esModule = true;
  38413. exports$1["default"] = void 0;
  38414. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38415. var _types = /*@__PURE__*/ requireTypes();
  38416. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38417. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38418. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38419. var Combinator = /*#__PURE__*/function (_Node) {
  38420. _inheritsLoose(Combinator, _Node);
  38421. function Combinator(opts) {
  38422. var _this;
  38423. _this = _Node.call(this, opts) || this;
  38424. _this.type = _types.COMBINATOR;
  38425. return _this;
  38426. }
  38427. return Combinator;
  38428. }(_node["default"]);
  38429. exports$1["default"] = Combinator;
  38430. module.exports = exports$1.default;
  38431. } (combinator, combinator.exports));
  38432. return combinator.exports;
  38433. }
  38434. var nesting = {exports: {}};
  38435. var hasRequiredNesting;
  38436. function requireNesting () {
  38437. if (hasRequiredNesting) return nesting.exports;
  38438. hasRequiredNesting = 1;
  38439. (function (module, exports$1) {
  38440. exports$1.__esModule = true;
  38441. exports$1["default"] = void 0;
  38442. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38443. var _types = /*@__PURE__*/ requireTypes();
  38444. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38445. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38446. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38447. var Nesting = /*#__PURE__*/function (_Node) {
  38448. _inheritsLoose(Nesting, _Node);
  38449. function Nesting(opts) {
  38450. var _this;
  38451. _this = _Node.call(this, opts) || this;
  38452. _this.type = _types.NESTING;
  38453. _this.value = '&';
  38454. return _this;
  38455. }
  38456. return Nesting;
  38457. }(_node["default"]);
  38458. exports$1["default"] = Nesting;
  38459. module.exports = exports$1.default;
  38460. } (nesting, nesting.exports));
  38461. return nesting.exports;
  38462. }
  38463. var sortAscending = {exports: {}};
  38464. var hasRequiredSortAscending;
  38465. function requireSortAscending () {
  38466. if (hasRequiredSortAscending) return sortAscending.exports;
  38467. hasRequiredSortAscending = 1;
  38468. (function (module, exports$1) {
  38469. exports$1.__esModule = true;
  38470. exports$1["default"] = sortAscending;
  38471. function sortAscending(list) {
  38472. return list.sort(function (a, b) {
  38473. return a - b;
  38474. });
  38475. }
  38476. module.exports = exports$1.default;
  38477. } (sortAscending, sortAscending.exports));
  38478. return sortAscending.exports;
  38479. }
  38480. var tokenize = {};
  38481. var tokenTypes = {};
  38482. var hasRequiredTokenTypes;
  38483. function requireTokenTypes () {
  38484. if (hasRequiredTokenTypes) return tokenTypes;
  38485. hasRequiredTokenTypes = 1;
  38486. tokenTypes.__esModule = true;
  38487. 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;
  38488. var ampersand = 38; // `&`.charCodeAt(0);
  38489. tokenTypes.ampersand = ampersand;
  38490. var asterisk = 42; // `*`.charCodeAt(0);
  38491. tokenTypes.asterisk = asterisk;
  38492. var at = 64; // `@`.charCodeAt(0);
  38493. tokenTypes.at = at;
  38494. var comma = 44; // `,`.charCodeAt(0);
  38495. tokenTypes.comma = comma;
  38496. var colon = 58; // `:`.charCodeAt(0);
  38497. tokenTypes.colon = colon;
  38498. var semicolon = 59; // `;`.charCodeAt(0);
  38499. tokenTypes.semicolon = semicolon;
  38500. var openParenthesis = 40; // `(`.charCodeAt(0);
  38501. tokenTypes.openParenthesis = openParenthesis;
  38502. var closeParenthesis = 41; // `)`.charCodeAt(0);
  38503. tokenTypes.closeParenthesis = closeParenthesis;
  38504. var openSquare = 91; // `[`.charCodeAt(0);
  38505. tokenTypes.openSquare = openSquare;
  38506. var closeSquare = 93; // `]`.charCodeAt(0);
  38507. tokenTypes.closeSquare = closeSquare;
  38508. var dollar = 36; // `$`.charCodeAt(0);
  38509. tokenTypes.dollar = dollar;
  38510. var tilde = 126; // `~`.charCodeAt(0);
  38511. tokenTypes.tilde = tilde;
  38512. var caret = 94; // `^`.charCodeAt(0);
  38513. tokenTypes.caret = caret;
  38514. var plus = 43; // `+`.charCodeAt(0);
  38515. tokenTypes.plus = plus;
  38516. var equals = 61; // `=`.charCodeAt(0);
  38517. tokenTypes.equals = equals;
  38518. var pipe = 124; // `|`.charCodeAt(0);
  38519. tokenTypes.pipe = pipe;
  38520. var greaterThan = 62; // `>`.charCodeAt(0);
  38521. tokenTypes.greaterThan = greaterThan;
  38522. var space = 32; // ` `.charCodeAt(0);
  38523. tokenTypes.space = space;
  38524. var singleQuote = 39; // `'`.charCodeAt(0);
  38525. tokenTypes.singleQuote = singleQuote;
  38526. var doubleQuote = 34; // `"`.charCodeAt(0);
  38527. tokenTypes.doubleQuote = doubleQuote;
  38528. var slash = 47; // `/`.charCodeAt(0);
  38529. tokenTypes.slash = slash;
  38530. var bang = 33; // `!`.charCodeAt(0);
  38531. tokenTypes.bang = bang;
  38532. var backslash = 92; // '\\'.charCodeAt(0);
  38533. tokenTypes.backslash = backslash;
  38534. var cr = 13; // '\r'.charCodeAt(0);
  38535. tokenTypes.cr = cr;
  38536. var feed = 12; // '\f'.charCodeAt(0);
  38537. tokenTypes.feed = feed;
  38538. var newline = 10; // '\n'.charCodeAt(0);
  38539. tokenTypes.newline = newline;
  38540. var tab = 9; // '\t'.charCodeAt(0);
  38541. // Expose aliases primarily for readability.
  38542. tokenTypes.tab = tab;
  38543. var str = singleQuote;
  38544. // No good single character representation!
  38545. tokenTypes.str = str;
  38546. var comment = -1;
  38547. tokenTypes.comment = comment;
  38548. var word = -2;
  38549. tokenTypes.word = word;
  38550. var combinator = -3;
  38551. tokenTypes.combinator = combinator;
  38552. return tokenTypes;
  38553. }
  38554. var hasRequiredTokenize;
  38555. function requireTokenize () {
  38556. if (hasRequiredTokenize) return tokenize;
  38557. hasRequiredTokenize = 1;
  38558. (function (exports$1) {
  38559. exports$1.__esModule = true;
  38560. exports$1.FIELDS = void 0;
  38561. exports$1["default"] = tokenize;
  38562. var t = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38563. var _unescapable, _wordDelimiters;
  38564. 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); }
  38565. 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; }
  38566. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  38567. 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);
  38568. var hex = {};
  38569. var hexChars = "0123456789abcdefABCDEF";
  38570. for (var i = 0; i < hexChars.length; i++) {
  38571. hex[hexChars.charCodeAt(i)] = true;
  38572. }
  38573. /**
  38574. * Returns the last index of the bar css word
  38575. * @param {string} css The string in which the word begins
  38576. * @param {number} start The index into the string where word's first letter occurs
  38577. */
  38578. function consumeWord(css, start) {
  38579. var next = start;
  38580. var code;
  38581. do {
  38582. code = css.charCodeAt(next);
  38583. if (wordDelimiters[code]) {
  38584. return next - 1;
  38585. } else if (code === t.backslash) {
  38586. next = consumeEscape(css, next) + 1;
  38587. } else {
  38588. // All other characters are part of the word
  38589. next++;
  38590. }
  38591. } while (next < css.length);
  38592. return next - 1;
  38593. }
  38594. /**
  38595. * Returns the last index of the escape sequence
  38596. * @param {string} css The string in which the sequence begins
  38597. * @param {number} start The index into the string where escape character (`\`) occurs.
  38598. */
  38599. function consumeEscape(css, start) {
  38600. var next = start;
  38601. var code = css.charCodeAt(next + 1);
  38602. if (unescapable[code]) ; else if (hex[code]) {
  38603. var hexDigits = 0;
  38604. // consume up to 6 hex chars
  38605. do {
  38606. next++;
  38607. hexDigits++;
  38608. code = css.charCodeAt(next + 1);
  38609. } while (hex[code] && hexDigits < 6);
  38610. // if fewer than 6 hex chars, a trailing space ends the escape
  38611. if (hexDigits < 6 && code === t.space) {
  38612. next++;
  38613. }
  38614. } else {
  38615. // the next char is part of the current word
  38616. next++;
  38617. }
  38618. return next;
  38619. }
  38620. var FIELDS = {
  38621. TYPE: 0,
  38622. START_LINE: 1,
  38623. START_COL: 2,
  38624. END_LINE: 3,
  38625. END_COL: 4,
  38626. START_POS: 5,
  38627. END_POS: 6
  38628. };
  38629. exports$1.FIELDS = FIELDS;
  38630. function tokenize(input) {
  38631. var tokens = [];
  38632. var css = input.css.valueOf();
  38633. var _css = css,
  38634. length = _css.length;
  38635. var offset = -1;
  38636. var line = 1;
  38637. var start = 0;
  38638. var end = 0;
  38639. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  38640. function unclosed(what, fix) {
  38641. if (input.safe) {
  38642. // fyi: this is never set to true.
  38643. css += fix;
  38644. next = css.length - 1;
  38645. } else {
  38646. throw input.error('Unclosed ' + what, line, start - offset, start);
  38647. }
  38648. }
  38649. while (start < length) {
  38650. code = css.charCodeAt(start);
  38651. if (code === t.newline) {
  38652. offset = start;
  38653. line += 1;
  38654. }
  38655. switch (code) {
  38656. case t.space:
  38657. case t.tab:
  38658. case t.newline:
  38659. case t.cr:
  38660. case t.feed:
  38661. next = start;
  38662. do {
  38663. next += 1;
  38664. code = css.charCodeAt(next);
  38665. if (code === t.newline) {
  38666. offset = next;
  38667. line += 1;
  38668. }
  38669. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38670. tokenType = t.space;
  38671. endLine = line;
  38672. endColumn = next - offset - 1;
  38673. end = next;
  38674. break;
  38675. case t.plus:
  38676. case t.greaterThan:
  38677. case t.tilde:
  38678. case t.pipe:
  38679. next = start;
  38680. do {
  38681. next += 1;
  38682. code = css.charCodeAt(next);
  38683. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38684. tokenType = t.combinator;
  38685. endLine = line;
  38686. endColumn = start - offset;
  38687. end = next;
  38688. break;
  38689. // Consume these characters as single tokens.
  38690. case t.asterisk:
  38691. case t.ampersand:
  38692. case t.bang:
  38693. case t.comma:
  38694. case t.equals:
  38695. case t.dollar:
  38696. case t.caret:
  38697. case t.openSquare:
  38698. case t.closeSquare:
  38699. case t.colon:
  38700. case t.semicolon:
  38701. case t.openParenthesis:
  38702. case t.closeParenthesis:
  38703. next = start;
  38704. tokenType = code;
  38705. endLine = line;
  38706. endColumn = start - offset;
  38707. end = next + 1;
  38708. break;
  38709. case t.singleQuote:
  38710. case t.doubleQuote:
  38711. quote = code === t.singleQuote ? "'" : '"';
  38712. next = start;
  38713. do {
  38714. escaped = false;
  38715. next = css.indexOf(quote, next + 1);
  38716. if (next === -1) {
  38717. unclosed('quote', quote);
  38718. }
  38719. escapePos = next;
  38720. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38721. escapePos -= 1;
  38722. escaped = !escaped;
  38723. }
  38724. } while (escaped);
  38725. tokenType = t.str;
  38726. endLine = line;
  38727. endColumn = start - offset;
  38728. end = next + 1;
  38729. break;
  38730. default:
  38731. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38732. next = css.indexOf('*/', start + 2) + 1;
  38733. if (next === 0) {
  38734. unclosed('comment', '*/');
  38735. }
  38736. content = css.slice(start, next + 1);
  38737. lines = content.split('\n');
  38738. last = lines.length - 1;
  38739. if (last > 0) {
  38740. nextLine = line + last;
  38741. nextOffset = next - lines[last].length;
  38742. } else {
  38743. nextLine = line;
  38744. nextOffset = offset;
  38745. }
  38746. tokenType = t.comment;
  38747. line = nextLine;
  38748. endLine = nextLine;
  38749. endColumn = next - nextOffset;
  38750. } else if (code === t.slash) {
  38751. next = start;
  38752. tokenType = code;
  38753. endLine = line;
  38754. endColumn = start - offset;
  38755. end = next + 1;
  38756. } else {
  38757. next = consumeWord(css, start);
  38758. tokenType = t.word;
  38759. endLine = line;
  38760. endColumn = next - offset;
  38761. }
  38762. end = next + 1;
  38763. break;
  38764. }
  38765. // Ensure that the token structure remains consistent
  38766. tokens.push([tokenType,
  38767. // [0] Token type
  38768. line,
  38769. // [1] Starting line
  38770. start - offset,
  38771. // [2] Starting column
  38772. endLine,
  38773. // [3] Ending line
  38774. endColumn,
  38775. // [4] Ending column
  38776. start,
  38777. // [5] Start position / Source index
  38778. end // [6] End position
  38779. ]);
  38780. // Reset offset for the next token
  38781. if (nextOffset) {
  38782. offset = nextOffset;
  38783. nextOffset = null;
  38784. }
  38785. start = end;
  38786. }
  38787. return tokens;
  38788. }
  38789. } (tokenize));
  38790. return tokenize;
  38791. }
  38792. var hasRequiredParser;
  38793. function requireParser () {
  38794. if (hasRequiredParser) return parser.exports;
  38795. hasRequiredParser = 1;
  38796. (function (module, exports$1) {
  38797. exports$1.__esModule = true;
  38798. exports$1["default"] = void 0;
  38799. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  38800. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  38801. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  38802. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  38803. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  38804. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  38805. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  38806. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  38807. var _attribute = _interopRequireWildcard(/*@__PURE__*/ requireAttribute());
  38808. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  38809. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  38810. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  38811. var _sortAscending = _interopRequireDefault(/*@__PURE__*/ requireSortAscending());
  38812. var _tokenize = _interopRequireWildcard(/*@__PURE__*/ requireTokenize());
  38813. var tokens = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38814. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  38815. var _util = /*@__PURE__*/ requireUtil$1();
  38816. var _WHITESPACE_TOKENS, _Object$assign;
  38817. 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); }
  38818. 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; }
  38819. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38820. 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); } }
  38821. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38822. 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);
  38823. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38824. function tokenStart(token) {
  38825. return {
  38826. line: token[_tokenize.FIELDS.START_LINE],
  38827. column: token[_tokenize.FIELDS.START_COL]
  38828. };
  38829. }
  38830. function tokenEnd(token) {
  38831. return {
  38832. line: token[_tokenize.FIELDS.END_LINE],
  38833. column: token[_tokenize.FIELDS.END_COL]
  38834. };
  38835. }
  38836. function getSource(startLine, startColumn, endLine, endColumn) {
  38837. return {
  38838. start: {
  38839. line: startLine,
  38840. column: startColumn
  38841. },
  38842. end: {
  38843. line: endLine,
  38844. column: endColumn
  38845. }
  38846. };
  38847. }
  38848. function getTokenSource(token) {
  38849. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38850. }
  38851. function getTokenSourceSpan(startToken, endToken) {
  38852. if (!startToken) {
  38853. return undefined;
  38854. }
  38855. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38856. }
  38857. function unescapeProp(node, prop) {
  38858. var value = node[prop];
  38859. if (typeof value !== "string") {
  38860. return;
  38861. }
  38862. if (value.indexOf("\\") !== -1) {
  38863. (0, _util.ensureObject)(node, 'raws');
  38864. node[prop] = (0, _util.unesc)(value);
  38865. if (node.raws[prop] === undefined) {
  38866. node.raws[prop] = value;
  38867. }
  38868. }
  38869. return node;
  38870. }
  38871. function indexesOf(array, item) {
  38872. var i = -1;
  38873. var indexes = [];
  38874. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38875. indexes.push(i);
  38876. }
  38877. return indexes;
  38878. }
  38879. function uniqs() {
  38880. var list = Array.prototype.concat.apply([], arguments);
  38881. return list.filter(function (item, i) {
  38882. return i === list.indexOf(item);
  38883. });
  38884. }
  38885. var Parser = /*#__PURE__*/function () {
  38886. function Parser(rule, options) {
  38887. if (options === void 0) {
  38888. options = {};
  38889. }
  38890. this.rule = rule;
  38891. this.options = Object.assign({
  38892. lossy: false,
  38893. safe: false
  38894. }, options);
  38895. this.position = 0;
  38896. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38897. this.tokens = (0, _tokenize["default"])({
  38898. css: this.css,
  38899. error: this._errorGenerator(),
  38900. safe: this.options.safe
  38901. });
  38902. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38903. this.root = new _root["default"]({
  38904. source: rootSource
  38905. });
  38906. this.root.errorGenerator = this._errorGenerator();
  38907. var selector = new _selector["default"]({
  38908. source: {
  38909. start: {
  38910. line: 1,
  38911. column: 1
  38912. }
  38913. },
  38914. sourceIndex: 0
  38915. });
  38916. this.root.append(selector);
  38917. this.current = selector;
  38918. this.loop();
  38919. }
  38920. var _proto = Parser.prototype;
  38921. _proto._errorGenerator = function _errorGenerator() {
  38922. var _this = this;
  38923. return function (message, errorOptions) {
  38924. if (typeof _this.rule === 'string') {
  38925. return new Error(message);
  38926. }
  38927. return _this.rule.error(message, errorOptions);
  38928. };
  38929. };
  38930. _proto.attribute = function attribute() {
  38931. var attr = [];
  38932. var startingToken = this.currToken;
  38933. this.position++;
  38934. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38935. attr.push(this.currToken);
  38936. this.position++;
  38937. }
  38938. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38939. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38940. }
  38941. var len = attr.length;
  38942. var node = {
  38943. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38944. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38945. };
  38946. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38947. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38948. }
  38949. var pos = 0;
  38950. var spaceBefore = '';
  38951. var commentBefore = '';
  38952. var lastAdded = null;
  38953. var spaceAfterMeaningfulToken = false;
  38954. while (pos < len) {
  38955. var token = attr[pos];
  38956. var content = this.content(token);
  38957. var next = attr[pos + 1];
  38958. switch (token[_tokenize.FIELDS.TYPE]) {
  38959. case tokens.space:
  38960. // if (
  38961. // len === 1 ||
  38962. // pos === 0 && this.content(next) === '|'
  38963. // ) {
  38964. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38965. // }
  38966. spaceAfterMeaningfulToken = true;
  38967. if (this.options.lossy) {
  38968. break;
  38969. }
  38970. if (lastAdded) {
  38971. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38972. var prevContent = node.spaces[lastAdded].after || '';
  38973. node.spaces[lastAdded].after = prevContent + content;
  38974. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38975. if (existingComment) {
  38976. node.raws.spaces[lastAdded].after = existingComment + content;
  38977. }
  38978. } else {
  38979. spaceBefore = spaceBefore + content;
  38980. commentBefore = commentBefore + content;
  38981. }
  38982. break;
  38983. case tokens.asterisk:
  38984. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38985. node.operator = content;
  38986. lastAdded = 'operator';
  38987. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  38988. if (spaceBefore) {
  38989. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38990. node.spaces.attribute.before = spaceBefore;
  38991. spaceBefore = '';
  38992. }
  38993. if (commentBefore) {
  38994. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38995. node.raws.spaces.attribute.before = spaceBefore;
  38996. commentBefore = '';
  38997. }
  38998. node.namespace = (node.namespace || "") + content;
  38999. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  39000. if (rawValue) {
  39001. node.raws.namespace += content;
  39002. }
  39003. lastAdded = 'namespace';
  39004. }
  39005. spaceAfterMeaningfulToken = false;
  39006. break;
  39007. case tokens.dollar:
  39008. if (lastAdded === "value") {
  39009. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  39010. node.value += "$";
  39011. if (oldRawValue) {
  39012. node.raws.value = oldRawValue + "$";
  39013. }
  39014. break;
  39015. }
  39016. // Falls through
  39017. case tokens.caret:
  39018. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39019. node.operator = content;
  39020. lastAdded = 'operator';
  39021. }
  39022. spaceAfterMeaningfulToken = false;
  39023. break;
  39024. case tokens.combinator:
  39025. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39026. node.operator = content;
  39027. lastAdded = 'operator';
  39028. }
  39029. if (content !== '|') {
  39030. spaceAfterMeaningfulToken = false;
  39031. break;
  39032. }
  39033. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39034. node.operator = content;
  39035. lastAdded = 'operator';
  39036. } else if (!node.namespace && !node.attribute) {
  39037. node.namespace = true;
  39038. }
  39039. spaceAfterMeaningfulToken = false;
  39040. break;
  39041. case tokens.word:
  39042. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  39043. // this look-ahead probably fails with comment nodes involved.
  39044. !node.operator && !node.namespace) {
  39045. node.namespace = content;
  39046. lastAdded = 'namespace';
  39047. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  39048. if (spaceBefore) {
  39049. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  39050. node.spaces.attribute.before = spaceBefore;
  39051. spaceBefore = '';
  39052. }
  39053. if (commentBefore) {
  39054. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  39055. node.raws.spaces.attribute.before = commentBefore;
  39056. commentBefore = '';
  39057. }
  39058. node.attribute = (node.attribute || "") + content;
  39059. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  39060. if (_rawValue) {
  39061. node.raws.attribute += content;
  39062. }
  39063. lastAdded = 'attribute';
  39064. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  39065. var _unescaped = (0, _util.unesc)(content);
  39066. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  39067. var oldValue = node.value || '';
  39068. node.value = oldValue + _unescaped;
  39069. node.quoteMark = null;
  39070. if (_unescaped !== content || _oldRawValue) {
  39071. (0, _util.ensureObject)(node, 'raws');
  39072. node.raws.value = (_oldRawValue || oldValue) + content;
  39073. }
  39074. lastAdded = 'value';
  39075. } else {
  39076. var insensitive = content === 'i' || content === "I";
  39077. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  39078. node.insensitive = insensitive;
  39079. if (!insensitive || content === "I") {
  39080. (0, _util.ensureObject)(node, 'raws');
  39081. node.raws.insensitiveFlag = content;
  39082. }
  39083. lastAdded = 'insensitive';
  39084. if (spaceBefore) {
  39085. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  39086. node.spaces.insensitive.before = spaceBefore;
  39087. spaceBefore = '';
  39088. }
  39089. if (commentBefore) {
  39090. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  39091. node.raws.spaces.insensitive.before = commentBefore;
  39092. commentBefore = '';
  39093. }
  39094. } else if (node.value || node.value === '') {
  39095. lastAdded = 'value';
  39096. node.value += content;
  39097. if (node.raws.value) {
  39098. node.raws.value += content;
  39099. }
  39100. }
  39101. }
  39102. spaceAfterMeaningfulToken = false;
  39103. break;
  39104. case tokens.str:
  39105. if (!node.attribute || !node.operator) {
  39106. return this.error("Expected an attribute followed by an operator preceding the string.", {
  39107. index: token[_tokenize.FIELDS.START_POS]
  39108. });
  39109. }
  39110. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  39111. unescaped = _unescapeValue.unescaped,
  39112. quoteMark = _unescapeValue.quoteMark;
  39113. node.value = unescaped;
  39114. node.quoteMark = quoteMark;
  39115. lastAdded = 'value';
  39116. (0, _util.ensureObject)(node, 'raws');
  39117. node.raws.value = content;
  39118. spaceAfterMeaningfulToken = false;
  39119. break;
  39120. case tokens.equals:
  39121. if (!node.attribute) {
  39122. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  39123. }
  39124. if (node.value) {
  39125. return this.error('Unexpected "=" found; an operator was already defined.', {
  39126. index: token[_tokenize.FIELDS.START_POS]
  39127. });
  39128. }
  39129. node.operator = node.operator ? node.operator + content : content;
  39130. lastAdded = 'operator';
  39131. spaceAfterMeaningfulToken = false;
  39132. break;
  39133. case tokens.comment:
  39134. if (lastAdded) {
  39135. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  39136. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  39137. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  39138. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  39139. node.raws.spaces[lastAdded].after = rawLastComment + content;
  39140. } else {
  39141. var lastValue = node[lastAdded] || '';
  39142. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  39143. (0, _util.ensureObject)(node, 'raws');
  39144. node.raws[lastAdded] = rawLastValue + content;
  39145. }
  39146. } else {
  39147. commentBefore = commentBefore + content;
  39148. }
  39149. break;
  39150. default:
  39151. return this.error("Unexpected \"" + content + "\" found.", {
  39152. index: token[_tokenize.FIELDS.START_POS]
  39153. });
  39154. }
  39155. pos++;
  39156. }
  39157. unescapeProp(node, "attribute");
  39158. unescapeProp(node, "namespace");
  39159. this.newNode(new _attribute["default"](node));
  39160. this.position++;
  39161. }
  39162. /**
  39163. * return a node containing meaningless garbage up to (but not including) the specified token position.
  39164. * if the token position is negative, all remaining tokens are consumed.
  39165. *
  39166. * This returns an array containing a single string node if all whitespace,
  39167. * otherwise an array of comment nodes with space before and after.
  39168. *
  39169. * These tokens are not added to the current selector, the caller can add them or use them to amend
  39170. * a previous node's space metadata.
  39171. *
  39172. * In lossy mode, this returns only comments.
  39173. */;
  39174. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  39175. if (stopPosition < 0) {
  39176. stopPosition = this.tokens.length;
  39177. }
  39178. var startPosition = this.position;
  39179. var nodes = [];
  39180. var space = "";
  39181. var lastComment = undefined;
  39182. do {
  39183. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  39184. if (!this.options.lossy) {
  39185. space += this.content();
  39186. }
  39187. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  39188. var spaces = {};
  39189. if (space) {
  39190. spaces.before = space;
  39191. space = "";
  39192. }
  39193. lastComment = new _comment["default"]({
  39194. value: this.content(),
  39195. source: getTokenSource(this.currToken),
  39196. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39197. spaces: spaces
  39198. });
  39199. nodes.push(lastComment);
  39200. }
  39201. } while (++this.position < stopPosition);
  39202. if (space) {
  39203. if (lastComment) {
  39204. lastComment.spaces.after = space;
  39205. } else if (!this.options.lossy) {
  39206. var firstToken = this.tokens[startPosition];
  39207. var lastToken = this.tokens[this.position - 1];
  39208. nodes.push(new _string["default"]({
  39209. value: '',
  39210. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  39211. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39212. spaces: {
  39213. before: space,
  39214. after: ''
  39215. }
  39216. }));
  39217. }
  39218. }
  39219. return nodes;
  39220. }
  39221. /**
  39222. *
  39223. * @param {*} nodes
  39224. */;
  39225. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  39226. var _this2 = this;
  39227. if (requiredSpace === void 0) {
  39228. requiredSpace = false;
  39229. }
  39230. var space = "";
  39231. var rawSpace = "";
  39232. nodes.forEach(function (n) {
  39233. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  39234. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  39235. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  39236. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  39237. });
  39238. if (rawSpace === space) {
  39239. rawSpace = undefined;
  39240. }
  39241. var result = {
  39242. space: space,
  39243. rawSpace: rawSpace
  39244. };
  39245. return result;
  39246. };
  39247. _proto.isNamedCombinator = function isNamedCombinator(position) {
  39248. if (position === void 0) {
  39249. position = this.position;
  39250. }
  39251. 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;
  39252. };
  39253. _proto.namedCombinator = function namedCombinator() {
  39254. if (this.isNamedCombinator()) {
  39255. var nameRaw = this.content(this.tokens[this.position + 1]);
  39256. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  39257. var raws = {};
  39258. if (name !== nameRaw) {
  39259. raws.value = "/" + nameRaw + "/";
  39260. }
  39261. var node = new _combinator["default"]({
  39262. value: "/" + name + "/",
  39263. 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]),
  39264. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39265. raws: raws
  39266. });
  39267. this.position = this.position + 3;
  39268. return node;
  39269. } else {
  39270. this.unexpected();
  39271. }
  39272. };
  39273. _proto.combinator = function combinator() {
  39274. var _this3 = this;
  39275. if (this.content() === '|') {
  39276. return this.namespace();
  39277. }
  39278. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  39279. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  39280. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39281. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39282. if (nodes.length > 0) {
  39283. var last = this.current.last;
  39284. if (last) {
  39285. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  39286. space = _this$convertWhitespa.space,
  39287. rawSpace = _this$convertWhitespa.rawSpace;
  39288. if (rawSpace !== undefined) {
  39289. last.rawSpaceAfter += rawSpace;
  39290. }
  39291. last.spaces.after += space;
  39292. } else {
  39293. nodes.forEach(function (n) {
  39294. return _this3.newNode(n);
  39295. });
  39296. }
  39297. }
  39298. return;
  39299. }
  39300. var firstToken = this.currToken;
  39301. var spaceOrDescendantSelectorNodes = undefined;
  39302. if (nextSigTokenPos > this.position) {
  39303. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39304. }
  39305. var node;
  39306. if (this.isNamedCombinator()) {
  39307. node = this.namedCombinator();
  39308. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  39309. node = new _combinator["default"]({
  39310. value: this.content(),
  39311. source: getTokenSource(this.currToken),
  39312. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  39313. });
  39314. this.position++;
  39315. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  39316. this.unexpected();
  39317. }
  39318. if (node) {
  39319. if (spaceOrDescendantSelectorNodes) {
  39320. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  39321. _space = _this$convertWhitespa2.space,
  39322. _rawSpace = _this$convertWhitespa2.rawSpace;
  39323. node.spaces.before = _space;
  39324. node.rawSpaceBefore = _rawSpace;
  39325. }
  39326. } else {
  39327. // descendant combinator
  39328. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  39329. _space2 = _this$convertWhitespa3.space,
  39330. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  39331. if (!_rawSpace2) {
  39332. _rawSpace2 = _space2;
  39333. }
  39334. var spaces = {};
  39335. var raws = {
  39336. spaces: {}
  39337. };
  39338. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  39339. spaces.before = _space2.slice(0, _space2.length - 1);
  39340. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  39341. } else if (_space2[0] === ' ' && _rawSpace2[0] === ' ') {
  39342. spaces.after = _space2.slice(1);
  39343. raws.spaces.after = _rawSpace2.slice(1);
  39344. } else {
  39345. raws.value = _rawSpace2;
  39346. }
  39347. node = new _combinator["default"]({
  39348. value: ' ',
  39349. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  39350. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39351. spaces: spaces,
  39352. raws: raws
  39353. });
  39354. }
  39355. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  39356. node.spaces.after = this.optionalSpace(this.content());
  39357. this.position++;
  39358. }
  39359. return this.newNode(node);
  39360. };
  39361. _proto.comma = function comma() {
  39362. if (this.position === this.tokens.length - 1) {
  39363. this.root.trailingComma = true;
  39364. this.position++;
  39365. return;
  39366. }
  39367. this.current._inferEndPosition();
  39368. var selector = new _selector["default"]({
  39369. source: {
  39370. start: tokenStart(this.tokens[this.position + 1])
  39371. },
  39372. sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
  39373. });
  39374. this.current.parent.append(selector);
  39375. this.current = selector;
  39376. this.position++;
  39377. };
  39378. _proto.comment = function comment() {
  39379. var current = this.currToken;
  39380. this.newNode(new _comment["default"]({
  39381. value: this.content(),
  39382. source: getTokenSource(current),
  39383. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39384. }));
  39385. this.position++;
  39386. };
  39387. _proto.error = function error(message, opts) {
  39388. throw this.root.error(message, opts);
  39389. };
  39390. _proto.missingBackslash = function missingBackslash() {
  39391. return this.error('Expected a backslash preceding the semicolon.', {
  39392. index: this.currToken[_tokenize.FIELDS.START_POS]
  39393. });
  39394. };
  39395. _proto.missingParenthesis = function missingParenthesis() {
  39396. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39397. };
  39398. _proto.missingSquareBracket = function missingSquareBracket() {
  39399. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  39400. };
  39401. _proto.unexpected = function unexpected() {
  39402. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  39403. };
  39404. _proto.unexpectedPipe = function unexpectedPipe() {
  39405. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  39406. };
  39407. _proto.namespace = function namespace() {
  39408. var before = this.prevToken && this.content(this.prevToken) || true;
  39409. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39410. this.position++;
  39411. return this.word(before);
  39412. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  39413. this.position++;
  39414. return this.universal(before);
  39415. }
  39416. this.unexpectedPipe();
  39417. };
  39418. _proto.nesting = function nesting() {
  39419. if (this.nextToken) {
  39420. var nextContent = this.content(this.nextToken);
  39421. if (nextContent === "|") {
  39422. this.position++;
  39423. return;
  39424. }
  39425. }
  39426. var current = this.currToken;
  39427. this.newNode(new _nesting["default"]({
  39428. value: this.content(),
  39429. source: getTokenSource(current),
  39430. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39431. }));
  39432. this.position++;
  39433. };
  39434. _proto.parentheses = function parentheses() {
  39435. var last = this.current.last;
  39436. var unbalanced = 1;
  39437. this.position++;
  39438. if (last && last.type === types.PSEUDO) {
  39439. var selector = new _selector["default"]({
  39440. source: {
  39441. start: tokenStart(this.tokens[this.position])
  39442. },
  39443. sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
  39444. });
  39445. var cache = this.current;
  39446. last.append(selector);
  39447. this.current = selector;
  39448. while (this.position < this.tokens.length && unbalanced) {
  39449. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39450. unbalanced++;
  39451. }
  39452. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39453. unbalanced--;
  39454. }
  39455. if (unbalanced) {
  39456. this.parse();
  39457. } else {
  39458. this.current.source.end = tokenEnd(this.currToken);
  39459. this.current.parent.source.end = tokenEnd(this.currToken);
  39460. this.position++;
  39461. }
  39462. }
  39463. this.current = cache;
  39464. } else {
  39465. // I think this case should be an error. It's used to implement a basic parse of media queries
  39466. // but I don't think it's a good idea.
  39467. var parenStart = this.currToken;
  39468. var parenValue = "(";
  39469. var parenEnd;
  39470. while (this.position < this.tokens.length && unbalanced) {
  39471. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39472. unbalanced++;
  39473. }
  39474. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39475. unbalanced--;
  39476. }
  39477. parenEnd = this.currToken;
  39478. parenValue += this.parseParenthesisToken(this.currToken);
  39479. this.position++;
  39480. }
  39481. if (last) {
  39482. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  39483. } else {
  39484. this.newNode(new _string["default"]({
  39485. value: parenValue,
  39486. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  39487. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  39488. }));
  39489. }
  39490. }
  39491. if (unbalanced) {
  39492. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39493. }
  39494. };
  39495. _proto.pseudo = function pseudo() {
  39496. var _this4 = this;
  39497. var pseudoStr = '';
  39498. var startingToken = this.currToken;
  39499. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  39500. pseudoStr += this.content();
  39501. this.position++;
  39502. }
  39503. if (!this.currToken) {
  39504. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  39505. }
  39506. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39507. this.splitWord(false, function (first, length) {
  39508. pseudoStr += first;
  39509. _this4.newNode(new _pseudo["default"]({
  39510. value: pseudoStr,
  39511. source: getTokenSourceSpan(startingToken, _this4.currToken),
  39512. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  39513. }));
  39514. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39515. _this4.error('Misplaced parenthesis.', {
  39516. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  39517. });
  39518. }
  39519. });
  39520. } else {
  39521. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  39522. }
  39523. };
  39524. _proto.space = function space() {
  39525. var content = this.content();
  39526. // Handle space before and after the selector
  39527. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  39528. return node.type === 'comment';
  39529. })) {
  39530. this.spaces = this.optionalSpace(content);
  39531. this.position++;
  39532. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39533. this.current.last.spaces.after = this.optionalSpace(content);
  39534. this.position++;
  39535. } else {
  39536. this.combinator();
  39537. }
  39538. };
  39539. _proto.string = function string() {
  39540. var current = this.currToken;
  39541. this.newNode(new _string["default"]({
  39542. value: this.content(),
  39543. source: getTokenSource(current),
  39544. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39545. }));
  39546. this.position++;
  39547. };
  39548. _proto.universal = function universal(namespace) {
  39549. var nextToken = this.nextToken;
  39550. if (nextToken && this.content(nextToken) === '|') {
  39551. this.position++;
  39552. return this.namespace();
  39553. }
  39554. var current = this.currToken;
  39555. this.newNode(new _universal["default"]({
  39556. value: this.content(),
  39557. source: getTokenSource(current),
  39558. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39559. }), namespace);
  39560. this.position++;
  39561. };
  39562. _proto.splitWord = function splitWord(namespace, firstCallback) {
  39563. var _this5 = this;
  39564. var nextToken = this.nextToken;
  39565. var word = this.content();
  39566. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  39567. this.position++;
  39568. var current = this.content();
  39569. word += current;
  39570. if (current.lastIndexOf('\\') === current.length - 1) {
  39571. var next = this.nextToken;
  39572. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  39573. word += this.requiredSpace(this.content(next));
  39574. this.position++;
  39575. }
  39576. }
  39577. nextToken = this.nextToken;
  39578. }
  39579. var hasClass = indexesOf(word, '.').filter(function (i) {
  39580. // Allow escaped dot within class name
  39581. var escapedDot = word[i - 1] === '\\';
  39582. // Allow decimal numbers percent in @keyframes
  39583. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  39584. return !escapedDot && !isKeyframesPercent;
  39585. });
  39586. var hasId = indexesOf(word, '#').filter(function (i) {
  39587. return word[i - 1] !== '\\';
  39588. });
  39589. // Eliminate Sass interpolations from the list of id indexes
  39590. var interpolations = indexesOf(word, '#{');
  39591. if (interpolations.length) {
  39592. hasId = hasId.filter(function (hashIndex) {
  39593. return !~interpolations.indexOf(hashIndex);
  39594. });
  39595. }
  39596. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  39597. indices.forEach(function (ind, i) {
  39598. var index = indices[i + 1] || word.length;
  39599. var value = word.slice(ind, index);
  39600. if (i === 0 && firstCallback) {
  39601. return firstCallback.call(_this5, value, indices.length);
  39602. }
  39603. var node;
  39604. var current = _this5.currToken;
  39605. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  39606. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  39607. if (~hasClass.indexOf(ind)) {
  39608. var classNameOpts = {
  39609. value: value.slice(1),
  39610. source: source,
  39611. sourceIndex: sourceIndex
  39612. };
  39613. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  39614. } else if (~hasId.indexOf(ind)) {
  39615. var idOpts = {
  39616. value: value.slice(1),
  39617. source: source,
  39618. sourceIndex: sourceIndex
  39619. };
  39620. node = new _id["default"](unescapeProp(idOpts, "value"));
  39621. } else {
  39622. var tagOpts = {
  39623. value: value,
  39624. source: source,
  39625. sourceIndex: sourceIndex
  39626. };
  39627. unescapeProp(tagOpts, "value");
  39628. node = new _tag["default"](tagOpts);
  39629. }
  39630. _this5.newNode(node, namespace);
  39631. // Ensure that the namespace is used only once
  39632. namespace = null;
  39633. });
  39634. this.position++;
  39635. };
  39636. _proto.word = function word(namespace) {
  39637. var nextToken = this.nextToken;
  39638. if (nextToken && this.content(nextToken) === '|') {
  39639. this.position++;
  39640. return this.namespace();
  39641. }
  39642. return this.splitWord(namespace);
  39643. };
  39644. _proto.loop = function loop() {
  39645. while (this.position < this.tokens.length) {
  39646. this.parse(true);
  39647. }
  39648. this.current._inferEndPosition();
  39649. return this.root;
  39650. };
  39651. _proto.parse = function parse(throwOnParenthesis) {
  39652. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  39653. case tokens.space:
  39654. this.space();
  39655. break;
  39656. case tokens.comment:
  39657. this.comment();
  39658. break;
  39659. case tokens.openParenthesis:
  39660. this.parentheses();
  39661. break;
  39662. case tokens.closeParenthesis:
  39663. if (throwOnParenthesis) {
  39664. this.missingParenthesis();
  39665. }
  39666. break;
  39667. case tokens.openSquare:
  39668. this.attribute();
  39669. break;
  39670. case tokens.dollar:
  39671. case tokens.caret:
  39672. case tokens.equals:
  39673. case tokens.word:
  39674. this.word();
  39675. break;
  39676. case tokens.colon:
  39677. this.pseudo();
  39678. break;
  39679. case tokens.comma:
  39680. this.comma();
  39681. break;
  39682. case tokens.asterisk:
  39683. this.universal();
  39684. break;
  39685. case tokens.ampersand:
  39686. this.nesting();
  39687. break;
  39688. case tokens.slash:
  39689. case tokens.combinator:
  39690. this.combinator();
  39691. break;
  39692. case tokens.str:
  39693. this.string();
  39694. break;
  39695. // These cases throw; no break needed.
  39696. case tokens.closeSquare:
  39697. this.missingSquareBracket();
  39698. case tokens.semicolon:
  39699. this.missingBackslash();
  39700. default:
  39701. this.unexpected();
  39702. }
  39703. }
  39704. /**
  39705. * Helpers
  39706. */;
  39707. _proto.expected = function expected(description, index, found) {
  39708. if (Array.isArray(description)) {
  39709. var last = description.pop();
  39710. description = description.join(', ') + " or " + last;
  39711. }
  39712. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39713. if (!found) {
  39714. return this.error("Expected " + an + " " + description + ".", {
  39715. index: index
  39716. });
  39717. }
  39718. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39719. index: index
  39720. });
  39721. };
  39722. _proto.requiredSpace = function requiredSpace(space) {
  39723. return this.options.lossy ? ' ' : space;
  39724. };
  39725. _proto.optionalSpace = function optionalSpace(space) {
  39726. return this.options.lossy ? '' : space;
  39727. };
  39728. _proto.lossySpace = function lossySpace(space, required) {
  39729. if (this.options.lossy) {
  39730. return required ? ' ' : '';
  39731. } else {
  39732. return space;
  39733. }
  39734. };
  39735. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39736. var content = this.content(token);
  39737. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39738. return this.requiredSpace(content);
  39739. } else {
  39740. return content;
  39741. }
  39742. };
  39743. _proto.newNode = function newNode(node, namespace) {
  39744. if (namespace) {
  39745. if (/^ +$/.test(namespace)) {
  39746. if (!this.options.lossy) {
  39747. this.spaces = (this.spaces || '') + namespace;
  39748. }
  39749. namespace = true;
  39750. }
  39751. node.namespace = namespace;
  39752. unescapeProp(node, "namespace");
  39753. }
  39754. if (this.spaces) {
  39755. node.spaces.before = this.spaces;
  39756. this.spaces = '';
  39757. }
  39758. return this.current.append(node);
  39759. };
  39760. _proto.content = function content(token) {
  39761. if (token === void 0) {
  39762. token = this.currToken;
  39763. }
  39764. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39765. };
  39766. /**
  39767. * returns the index of the next non-whitespace, non-comment token.
  39768. * returns -1 if no meaningful token is found.
  39769. */
  39770. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39771. if (startPosition === void 0) {
  39772. startPosition = this.position + 1;
  39773. }
  39774. var searchPosition = startPosition;
  39775. while (searchPosition < this.tokens.length) {
  39776. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39777. searchPosition++;
  39778. continue;
  39779. } else {
  39780. return searchPosition;
  39781. }
  39782. }
  39783. return -1;
  39784. };
  39785. _createClass(Parser, [{
  39786. key: "currToken",
  39787. get: function get() {
  39788. return this.tokens[this.position];
  39789. }
  39790. }, {
  39791. key: "nextToken",
  39792. get: function get() {
  39793. return this.tokens[this.position + 1];
  39794. }
  39795. }, {
  39796. key: "prevToken",
  39797. get: function get() {
  39798. return this.tokens[this.position - 1];
  39799. }
  39800. }]);
  39801. return Parser;
  39802. }();
  39803. exports$1["default"] = Parser;
  39804. module.exports = exports$1.default;
  39805. } (parser, parser.exports));
  39806. return parser.exports;
  39807. }
  39808. var hasRequiredProcessor;
  39809. function requireProcessor () {
  39810. if (hasRequiredProcessor) return processor.exports;
  39811. hasRequiredProcessor = 1;
  39812. (function (module, exports$1) {
  39813. exports$1.__esModule = true;
  39814. exports$1["default"] = void 0;
  39815. var _parser = _interopRequireDefault(/*@__PURE__*/ requireParser());
  39816. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39817. var Processor = /*#__PURE__*/function () {
  39818. function Processor(func, options) {
  39819. this.func = func || function noop() {};
  39820. this.funcRes = null;
  39821. this.options = options;
  39822. }
  39823. var _proto = Processor.prototype;
  39824. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39825. if (options === void 0) {
  39826. options = {};
  39827. }
  39828. var merged = Object.assign({}, this.options, options);
  39829. if (merged.updateSelector === false) {
  39830. return false;
  39831. } else {
  39832. return typeof rule !== "string";
  39833. }
  39834. };
  39835. _proto._isLossy = function _isLossy(options) {
  39836. if (options === void 0) {
  39837. options = {};
  39838. }
  39839. var merged = Object.assign({}, this.options, options);
  39840. if (merged.lossless === false) {
  39841. return true;
  39842. } else {
  39843. return false;
  39844. }
  39845. };
  39846. _proto._root = function _root(rule, options) {
  39847. if (options === void 0) {
  39848. options = {};
  39849. }
  39850. var parser = new _parser["default"](rule, this._parseOptions(options));
  39851. return parser.root;
  39852. };
  39853. _proto._parseOptions = function _parseOptions(options) {
  39854. return {
  39855. lossy: this._isLossy(options)
  39856. };
  39857. };
  39858. _proto._run = function _run(rule, options) {
  39859. var _this = this;
  39860. if (options === void 0) {
  39861. options = {};
  39862. }
  39863. return new Promise(function (resolve, reject) {
  39864. try {
  39865. var root = _this._root(rule, options);
  39866. Promise.resolve(_this.func(root)).then(function (transform) {
  39867. var string = undefined;
  39868. if (_this._shouldUpdateSelector(rule, options)) {
  39869. string = root.toString();
  39870. rule.selector = string;
  39871. }
  39872. return {
  39873. transform: transform,
  39874. root: root,
  39875. string: string
  39876. };
  39877. }).then(resolve, reject);
  39878. } catch (e) {
  39879. reject(e);
  39880. return;
  39881. }
  39882. });
  39883. };
  39884. _proto._runSync = function _runSync(rule, options) {
  39885. if (options === void 0) {
  39886. options = {};
  39887. }
  39888. var root = this._root(rule, options);
  39889. var transform = this.func(root);
  39890. if (transform && typeof transform.then === "function") {
  39891. throw new Error("Selector processor returned a promise to a synchronous call.");
  39892. }
  39893. var string = undefined;
  39894. if (options.updateSelector && typeof rule !== "string") {
  39895. string = root.toString();
  39896. rule.selector = string;
  39897. }
  39898. return {
  39899. transform: transform,
  39900. root: root,
  39901. string: string
  39902. };
  39903. }
  39904. /**
  39905. * Process rule into a selector AST.
  39906. *
  39907. * @param rule {postcss.Rule | string} The css selector to be processed
  39908. * @param options The options for processing
  39909. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39910. */;
  39911. _proto.ast = function ast(rule, options) {
  39912. return this._run(rule, options).then(function (result) {
  39913. return result.root;
  39914. });
  39915. }
  39916. /**
  39917. * Process rule into a selector AST synchronously.
  39918. *
  39919. * @param rule {postcss.Rule | string} The css selector to be processed
  39920. * @param options The options for processing
  39921. * @returns {parser.Root} The AST of the selector after processing it.
  39922. */;
  39923. _proto.astSync = function astSync(rule, options) {
  39924. return this._runSync(rule, options).root;
  39925. }
  39926. /**
  39927. * Process a selector into a transformed value asynchronously
  39928. *
  39929. * @param rule {postcss.Rule | string} The css selector to be processed
  39930. * @param options The options for processing
  39931. * @returns {Promise<any>} The value returned by the processor.
  39932. */;
  39933. _proto.transform = function transform(rule, options) {
  39934. return this._run(rule, options).then(function (result) {
  39935. return result.transform;
  39936. });
  39937. }
  39938. /**
  39939. * Process a selector into a transformed value synchronously.
  39940. *
  39941. * @param rule {postcss.Rule | string} The css selector to be processed
  39942. * @param options The options for processing
  39943. * @returns {any} The value returned by the processor.
  39944. */;
  39945. _proto.transformSync = function transformSync(rule, options) {
  39946. return this._runSync(rule, options).transform;
  39947. }
  39948. /**
  39949. * Process a selector into a new selector string asynchronously.
  39950. *
  39951. * @param rule {postcss.Rule | string} The css selector to be processed
  39952. * @param options The options for processing
  39953. * @returns {string} the selector after processing.
  39954. */;
  39955. _proto.process = function process(rule, options) {
  39956. return this._run(rule, options).then(function (result) {
  39957. return result.string || result.root.toString();
  39958. });
  39959. }
  39960. /**
  39961. * Process a selector into a new selector string synchronously.
  39962. *
  39963. * @param rule {postcss.Rule | string} The css selector to be processed
  39964. * @param options The options for processing
  39965. * @returns {string} the selector after processing.
  39966. */;
  39967. _proto.processSync = function processSync(rule, options) {
  39968. var result = this._runSync(rule, options);
  39969. return result.string || result.root.toString();
  39970. };
  39971. return Processor;
  39972. }();
  39973. exports$1["default"] = Processor;
  39974. module.exports = exports$1.default;
  39975. } (processor, processor.exports));
  39976. return processor.exports;
  39977. }
  39978. var selectors = {};
  39979. var constructors = {};
  39980. var hasRequiredConstructors;
  39981. function requireConstructors () {
  39982. if (hasRequiredConstructors) return constructors;
  39983. hasRequiredConstructors = 1;
  39984. constructors.__esModule = true;
  39985. 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;
  39986. var _attribute = _interopRequireDefault(/*@__PURE__*/ requireAttribute());
  39987. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  39988. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  39989. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  39990. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  39991. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  39992. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  39993. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  39994. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  39995. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  39996. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  39997. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  39998. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39999. var attribute = function attribute(opts) {
  40000. return new _attribute["default"](opts);
  40001. };
  40002. constructors.attribute = attribute;
  40003. var className = function className(opts) {
  40004. return new _className["default"](opts);
  40005. };
  40006. constructors.className = className;
  40007. var combinator = function combinator(opts) {
  40008. return new _combinator["default"](opts);
  40009. };
  40010. constructors.combinator = combinator;
  40011. var comment = function comment(opts) {
  40012. return new _comment["default"](opts);
  40013. };
  40014. constructors.comment = comment;
  40015. var id = function id(opts) {
  40016. return new _id["default"](opts);
  40017. };
  40018. constructors.id = id;
  40019. var nesting = function nesting(opts) {
  40020. return new _nesting["default"](opts);
  40021. };
  40022. constructors.nesting = nesting;
  40023. var pseudo = function pseudo(opts) {
  40024. return new _pseudo["default"](opts);
  40025. };
  40026. constructors.pseudo = pseudo;
  40027. var root = function root(opts) {
  40028. return new _root["default"](opts);
  40029. };
  40030. constructors.root = root;
  40031. var selector = function selector(opts) {
  40032. return new _selector["default"](opts);
  40033. };
  40034. constructors.selector = selector;
  40035. var string = function string(opts) {
  40036. return new _string["default"](opts);
  40037. };
  40038. constructors.string = string;
  40039. var tag = function tag(opts) {
  40040. return new _tag["default"](opts);
  40041. };
  40042. constructors.tag = tag;
  40043. var universal = function universal(opts) {
  40044. return new _universal["default"](opts);
  40045. };
  40046. constructors.universal = universal;
  40047. return constructors;
  40048. }
  40049. var guards = {};
  40050. var hasRequiredGuards;
  40051. function requireGuards () {
  40052. if (hasRequiredGuards) return guards;
  40053. hasRequiredGuards = 1;
  40054. guards.__esModule = true;
  40055. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  40056. guards.isContainer = isContainer;
  40057. guards.isIdentifier = void 0;
  40058. guards.isNamespace = isNamespace;
  40059. guards.isNesting = void 0;
  40060. guards.isNode = isNode;
  40061. guards.isPseudo = void 0;
  40062. guards.isPseudoClass = isPseudoClass;
  40063. guards.isPseudoElement = isPseudoElement;
  40064. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  40065. var _types = /*@__PURE__*/ requireTypes();
  40066. var _IS_TYPE;
  40067. 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);
  40068. function isNode(node) {
  40069. return typeof node === "object" && IS_TYPE[node.type];
  40070. }
  40071. function isNodeType(type, node) {
  40072. return isNode(node) && node.type === type;
  40073. }
  40074. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  40075. guards.isAttribute = isAttribute;
  40076. var isClassName = isNodeType.bind(null, _types.CLASS);
  40077. guards.isClassName = isClassName;
  40078. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  40079. guards.isCombinator = isCombinator;
  40080. var isComment = isNodeType.bind(null, _types.COMMENT);
  40081. guards.isComment = isComment;
  40082. var isIdentifier = isNodeType.bind(null, _types.ID);
  40083. guards.isIdentifier = isIdentifier;
  40084. var isNesting = isNodeType.bind(null, _types.NESTING);
  40085. guards.isNesting = isNesting;
  40086. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  40087. guards.isPseudo = isPseudo;
  40088. var isRoot = isNodeType.bind(null, _types.ROOT);
  40089. guards.isRoot = isRoot;
  40090. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  40091. guards.isSelector = isSelector;
  40092. var isString = isNodeType.bind(null, _types.STRING);
  40093. guards.isString = isString;
  40094. var isTag = isNodeType.bind(null, _types.TAG);
  40095. guards.isTag = isTag;
  40096. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  40097. guards.isUniversal = isUniversal;
  40098. function isPseudoElement(node) {
  40099. 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");
  40100. }
  40101. function isPseudoClass(node) {
  40102. return isPseudo(node) && !isPseudoElement(node);
  40103. }
  40104. function isContainer(node) {
  40105. return !!(isNode(node) && node.walk);
  40106. }
  40107. function isNamespace(node) {
  40108. return isAttribute(node) || isTag(node);
  40109. }
  40110. return guards;
  40111. }
  40112. var hasRequiredSelectors;
  40113. function requireSelectors () {
  40114. if (hasRequiredSelectors) return selectors;
  40115. hasRequiredSelectors = 1;
  40116. (function (exports$1) {
  40117. exports$1.__esModule = true;
  40118. var _types = /*@__PURE__*/ requireTypes();
  40119. Object.keys(_types).forEach(function (key) {
  40120. if (key === "default" || key === "__esModule") return;
  40121. if (key in exports$1 && exports$1[key] === _types[key]) return;
  40122. exports$1[key] = _types[key];
  40123. });
  40124. var _constructors = /*@__PURE__*/ requireConstructors();
  40125. Object.keys(_constructors).forEach(function (key) {
  40126. if (key === "default" || key === "__esModule") return;
  40127. if (key in exports$1 && exports$1[key] === _constructors[key]) return;
  40128. exports$1[key] = _constructors[key];
  40129. });
  40130. var _guards = /*@__PURE__*/ requireGuards();
  40131. Object.keys(_guards).forEach(function (key) {
  40132. if (key === "default" || key === "__esModule") return;
  40133. if (key in exports$1 && exports$1[key] === _guards[key]) return;
  40134. exports$1[key] = _guards[key];
  40135. });
  40136. } (selectors));
  40137. return selectors;
  40138. }
  40139. var hasRequiredDist;
  40140. function requireDist () {
  40141. if (hasRequiredDist) return dist.exports;
  40142. hasRequiredDist = 1;
  40143. (function (module, exports$1) {
  40144. exports$1.__esModule = true;
  40145. exports$1["default"] = void 0;
  40146. var _processor = _interopRequireDefault(/*@__PURE__*/ requireProcessor());
  40147. var selectors = _interopRequireWildcard(/*@__PURE__*/ requireSelectors());
  40148. 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); }
  40149. 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; }
  40150. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  40151. var parser = function parser(processor) {
  40152. return new _processor["default"](processor);
  40153. };
  40154. Object.assign(parser, selectors);
  40155. delete parser.__esModule;
  40156. var _default = parser;
  40157. exports$1["default"] = _default;
  40158. module.exports = exports$1.default;
  40159. } (dist, dist.exports));
  40160. return dist.exports;
  40161. }
  40162. var distExports = /*@__PURE__*/ requireDist();
  40163. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  40164. const animationNameRE = /^(?:-\w+-)?animation-name$/;
  40165. const animationRE = /^(?:-\w+-)?animation$/;
  40166. const keyframesRE = /^(?:-\w+-)?keyframes$/;
  40167. const scopedPlugin = (id = "") => {
  40168. const keyframes = /* @__PURE__ */ Object.create(null);
  40169. const shortId = id.replace(/^data-v-/, "");
  40170. return {
  40171. postcssPlugin: "vue-sfc-scoped",
  40172. Rule(rule) {
  40173. processRule(id, rule);
  40174. },
  40175. AtRule(node) {
  40176. if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  40177. keyframes[node.params] = node.params = node.params + "-" + shortId;
  40178. }
  40179. },
  40180. OnceExit(root) {
  40181. if (Object.keys(keyframes).length) {
  40182. root.walkDecls((decl) => {
  40183. if (animationNameRE.test(decl.prop)) {
  40184. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  40185. }
  40186. if (animationRE.test(decl.prop)) {
  40187. decl.value = decl.value.split(",").map((v) => {
  40188. const vals = v.trim().split(/\s+/);
  40189. const i = vals.findIndex((val) => keyframes[val]);
  40190. if (i !== -1) {
  40191. vals.splice(i, 1, keyframes[vals[i]]);
  40192. return vals.join(" ");
  40193. } else {
  40194. return v;
  40195. }
  40196. }).join(",");
  40197. }
  40198. });
  40199. }
  40200. }
  40201. };
  40202. };
  40203. const processedRules = /* @__PURE__ */ new WeakSet();
  40204. function processRule(id, rule) {
  40205. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
  40206. return;
  40207. }
  40208. processedRules.add(rule);
  40209. let deep = false;
  40210. let parent = rule.parent;
  40211. while (parent && parent.type !== "root") {
  40212. if (parent.__deep) {
  40213. deep = true;
  40214. break;
  40215. }
  40216. parent = parent.parent;
  40217. }
  40218. rule.selector = selectorParser((selectorRoot) => {
  40219. selectorRoot.each((selector) => {
  40220. rewriteSelector(id, rule, selector, selectorRoot, deep);
  40221. });
  40222. }).processSync(rule.selector);
  40223. }
  40224. function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
  40225. let node = null;
  40226. let shouldInject = !deep;
  40227. selector.each((n) => {
  40228. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  40229. n.value = " ";
  40230. n.spaces.before = n.spaces.after = "";
  40231. warn(
  40232. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  40233. );
  40234. return false;
  40235. }
  40236. if (n.type === "pseudo") {
  40237. const { value } = n;
  40238. if (value === ":deep" || value === "::v-deep") {
  40239. rule.__deep = true;
  40240. if (n.nodes.length) {
  40241. let last = n;
  40242. n.nodes[0].each((ss) => {
  40243. selector.insertAfter(last, ss);
  40244. last = ss;
  40245. });
  40246. const prev = selector.at(selector.index(n) - 1);
  40247. if (!prev || !isSpaceCombinator(prev)) {
  40248. selector.insertAfter(
  40249. n,
  40250. selectorParser.combinator({
  40251. value: " "
  40252. })
  40253. );
  40254. }
  40255. selector.removeChild(n);
  40256. } else {
  40257. warn(
  40258. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  40259. );
  40260. const prev = selector.at(selector.index(n) - 1);
  40261. if (prev && isSpaceCombinator(prev)) {
  40262. selector.removeChild(prev);
  40263. }
  40264. selector.removeChild(n);
  40265. }
  40266. return false;
  40267. }
  40268. if (value === ":slotted" || value === "::v-slotted") {
  40269. rewriteSelector(
  40270. id,
  40271. rule,
  40272. n.nodes[0],
  40273. selectorRoot,
  40274. deep,
  40275. true
  40276. );
  40277. let last = n;
  40278. n.nodes[0].each((ss) => {
  40279. selector.insertAfter(last, ss);
  40280. last = ss;
  40281. });
  40282. selector.removeChild(n);
  40283. shouldInject = false;
  40284. return false;
  40285. }
  40286. if (value === ":global" || value === "::v-global") {
  40287. selector.replaceWith(n.nodes[0]);
  40288. return false;
  40289. }
  40290. }
  40291. if (n.type === "universal") {
  40292. const prev = selector.at(selector.index(n) - 1);
  40293. const next = selector.at(selector.index(n) + 1);
  40294. if (!prev) {
  40295. if (next) {
  40296. if (next.type === "combinator" && next.value === " ") {
  40297. selector.removeChild(next);
  40298. }
  40299. selector.removeChild(n);
  40300. return;
  40301. } else {
  40302. node = selectorParser.combinator({
  40303. value: ""
  40304. });
  40305. selector.insertBefore(n, node);
  40306. selector.removeChild(n);
  40307. return false;
  40308. }
  40309. }
  40310. if (node) return;
  40311. }
  40312. if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
  40313. node = n;
  40314. }
  40315. });
  40316. if (rule.nodes.some((node2) => node2.type === "rule")) {
  40317. const deep2 = rule.__deep;
  40318. if (!deep2) {
  40319. extractAndWrapNodes(rule);
  40320. const atruleNodes = rule.nodes.filter((node2) => node2.type === "atrule");
  40321. for (const atnode of atruleNodes) {
  40322. extractAndWrapNodes(atnode);
  40323. }
  40324. }
  40325. shouldInject = deep2;
  40326. }
  40327. if (node) {
  40328. const { type, value } = node;
  40329. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  40330. node.nodes.forEach(
  40331. (value2) => rewriteSelector(id, rule, value2, selectorRoot, deep, slotted)
  40332. );
  40333. shouldInject = false;
  40334. }
  40335. }
  40336. if (node) {
  40337. node.spaces.after = "";
  40338. } else {
  40339. selector.first.spaces.before = "";
  40340. }
  40341. if (shouldInject) {
  40342. const idToAdd = slotted ? id + "-s" : id;
  40343. selector.insertAfter(
  40344. // If node is null it means we need to inject [id] at the start
  40345. // insertAfter can handle `null` here
  40346. node,
  40347. selectorParser.attribute({
  40348. attribute: idToAdd,
  40349. value: idToAdd,
  40350. raws: {},
  40351. quoteMark: `"`
  40352. })
  40353. );
  40354. }
  40355. }
  40356. function isSpaceCombinator(node) {
  40357. return node.type === "combinator" && /^\s+$/.test(node.value);
  40358. }
  40359. function extractAndWrapNodes(parentNode) {
  40360. if (!parentNode.nodes) return;
  40361. const nodes = parentNode.nodes.filter(
  40362. (node) => node.type === "decl" || node.type === "comment"
  40363. );
  40364. if (nodes.length) {
  40365. for (const node of nodes) {
  40366. parentNode.removeChild(node);
  40367. }
  40368. const wrappedRule = new Rule({
  40369. nodes,
  40370. selector: "&"
  40371. });
  40372. parentNode.prepend(wrappedRule);
  40373. }
  40374. }
  40375. scopedPlugin.postcss = true;
  40376. var sourceMap = {};
  40377. var sourceMapGenerator = {};
  40378. var base64Vlq = {};
  40379. var base64 = {};
  40380. /* -*- Mode: js; js-indent-level: 2; -*- */
  40381. var hasRequiredBase64;
  40382. function requireBase64 () {
  40383. if (hasRequiredBase64) return base64;
  40384. hasRequiredBase64 = 1;
  40385. /*
  40386. * Copyright 2011 Mozilla Foundation and contributors
  40387. * Licensed under the New BSD license. See LICENSE or:
  40388. * http://opensource.org/licenses/BSD-3-Clause
  40389. */
  40390. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  40391. /**
  40392. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  40393. */
  40394. base64.encode = function (number) {
  40395. if (0 <= number && number < intToCharMap.length) {
  40396. return intToCharMap[number];
  40397. }
  40398. throw new TypeError("Must be between 0 and 63: " + number);
  40399. };
  40400. /**
  40401. * Decode a single base 64 character code digit to an integer. Returns -1 on
  40402. * failure.
  40403. */
  40404. base64.decode = function (charCode) {
  40405. var bigA = 65; // 'A'
  40406. var bigZ = 90; // 'Z'
  40407. var littleA = 97; // 'a'
  40408. var littleZ = 122; // 'z'
  40409. var zero = 48; // '0'
  40410. var nine = 57; // '9'
  40411. var plus = 43; // '+'
  40412. var slash = 47; // '/'
  40413. var littleOffset = 26;
  40414. var numberOffset = 52;
  40415. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  40416. if (bigA <= charCode && charCode <= bigZ) {
  40417. return (charCode - bigA);
  40418. }
  40419. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  40420. if (littleA <= charCode && charCode <= littleZ) {
  40421. return (charCode - littleA + littleOffset);
  40422. }
  40423. // 52 - 61: 0123456789
  40424. if (zero <= charCode && charCode <= nine) {
  40425. return (charCode - zero + numberOffset);
  40426. }
  40427. // 62: +
  40428. if (charCode == plus) {
  40429. return 62;
  40430. }
  40431. // 63: /
  40432. if (charCode == slash) {
  40433. return 63;
  40434. }
  40435. // Invalid base64 digit.
  40436. return -1;
  40437. };
  40438. return base64;
  40439. }
  40440. /* -*- Mode: js; js-indent-level: 2; -*- */
  40441. var hasRequiredBase64Vlq;
  40442. function requireBase64Vlq () {
  40443. if (hasRequiredBase64Vlq) return base64Vlq;
  40444. hasRequiredBase64Vlq = 1;
  40445. /*
  40446. * Copyright 2011 Mozilla Foundation and contributors
  40447. * Licensed under the New BSD license. See LICENSE or:
  40448. * http://opensource.org/licenses/BSD-3-Clause
  40449. *
  40450. * Based on the Base 64 VLQ implementation in Closure Compiler:
  40451. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  40452. *
  40453. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  40454. * Redistribution and use in source and binary forms, with or without
  40455. * modification, are permitted provided that the following conditions are
  40456. * met:
  40457. *
  40458. * * Redistributions of source code must retain the above copyright
  40459. * notice, this list of conditions and the following disclaimer.
  40460. * * Redistributions in binary form must reproduce the above
  40461. * copyright notice, this list of conditions and the following
  40462. * disclaimer in the documentation and/or other materials provided
  40463. * with the distribution.
  40464. * * Neither the name of Google Inc. nor the names of its
  40465. * contributors may be used to endorse or promote products derived
  40466. * from this software without specific prior written permission.
  40467. *
  40468. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40469. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40470. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  40471. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40472. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40473. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40474. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40475. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  40476. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40477. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40478. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40479. */
  40480. var base64 = /*@__PURE__*/ requireBase64();
  40481. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  40482. // length quantities we use in the source map spec, the first bit is the sign,
  40483. // the next four bits are the actual value, and the 6th bit is the
  40484. // continuation bit. The continuation bit tells us whether there are more
  40485. // digits in this value following this digit.
  40486. //
  40487. // Continuation
  40488. // | Sign
  40489. // | |
  40490. // V V
  40491. // 101011
  40492. var VLQ_BASE_SHIFT = 5;
  40493. // binary: 100000
  40494. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  40495. // binary: 011111
  40496. var VLQ_BASE_MASK = VLQ_BASE - 1;
  40497. // binary: 100000
  40498. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  40499. /**
  40500. * Converts from a two-complement value to a value where the sign bit is
  40501. * placed in the least significant bit. For example, as decimals:
  40502. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  40503. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  40504. */
  40505. function toVLQSigned(aValue) {
  40506. return aValue < 0
  40507. ? ((-aValue) << 1) + 1
  40508. : (aValue << 1) + 0;
  40509. }
  40510. /**
  40511. * Converts to a two-complement value from a value where the sign bit is
  40512. * placed in the least significant bit. For example, as decimals:
  40513. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  40514. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  40515. */
  40516. function fromVLQSigned(aValue) {
  40517. var isNegative = (aValue & 1) === 1;
  40518. var shifted = aValue >> 1;
  40519. return isNegative
  40520. ? -shifted
  40521. : shifted;
  40522. }
  40523. /**
  40524. * Returns the base 64 VLQ encoded value.
  40525. */
  40526. base64Vlq.encode = function base64VLQ_encode(aValue) {
  40527. var encoded = "";
  40528. var digit;
  40529. var vlq = toVLQSigned(aValue);
  40530. do {
  40531. digit = vlq & VLQ_BASE_MASK;
  40532. vlq >>>= VLQ_BASE_SHIFT;
  40533. if (vlq > 0) {
  40534. // There are still more digits in this value, so we must make sure the
  40535. // continuation bit is marked.
  40536. digit |= VLQ_CONTINUATION_BIT;
  40537. }
  40538. encoded += base64.encode(digit);
  40539. } while (vlq > 0);
  40540. return encoded;
  40541. };
  40542. /**
  40543. * Decodes the next base 64 VLQ value from the given string and returns the
  40544. * value and the rest of the string via the out parameter.
  40545. */
  40546. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  40547. var strLen = aStr.length;
  40548. var result = 0;
  40549. var shift = 0;
  40550. var continuation, digit;
  40551. do {
  40552. if (aIndex >= strLen) {
  40553. throw new Error("Expected more digits in base 64 VLQ value.");
  40554. }
  40555. digit = base64.decode(aStr.charCodeAt(aIndex++));
  40556. if (digit === -1) {
  40557. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  40558. }
  40559. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  40560. digit &= VLQ_BASE_MASK;
  40561. result = result + (digit << shift);
  40562. shift += VLQ_BASE_SHIFT;
  40563. } while (continuation);
  40564. aOutParam.value = fromVLQSigned(result);
  40565. aOutParam.rest = aIndex;
  40566. };
  40567. return base64Vlq;
  40568. }
  40569. var util = {};
  40570. /* -*- Mode: js; js-indent-level: 2; -*- */
  40571. var hasRequiredUtil;
  40572. function requireUtil () {
  40573. if (hasRequiredUtil) return util;
  40574. hasRequiredUtil = 1;
  40575. (function (exports$1) {
  40576. /*
  40577. * Copyright 2011 Mozilla Foundation and contributors
  40578. * Licensed under the New BSD license. See LICENSE or:
  40579. * http://opensource.org/licenses/BSD-3-Clause
  40580. */
  40581. /**
  40582. * This is a helper function for getting values from parameter/options
  40583. * objects.
  40584. *
  40585. * @param args The object we are extracting values from
  40586. * @param name The name of the property we are getting.
  40587. * @param defaultValue An optional value to return if the property is missing
  40588. * from the object. If this is not specified and the property is missing, an
  40589. * error will be thrown.
  40590. */
  40591. function getArg(aArgs, aName, aDefaultValue) {
  40592. if (aName in aArgs) {
  40593. return aArgs[aName];
  40594. } else if (arguments.length === 3) {
  40595. return aDefaultValue;
  40596. } else {
  40597. throw new Error('"' + aName + '" is a required argument.');
  40598. }
  40599. }
  40600. exports$1.getArg = getArg;
  40601. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  40602. var dataUrlRegexp = /^data:.+\,.+$/;
  40603. function urlParse(aUrl) {
  40604. var match = aUrl.match(urlRegexp);
  40605. if (!match) {
  40606. return null;
  40607. }
  40608. return {
  40609. scheme: match[1],
  40610. auth: match[2],
  40611. host: match[3],
  40612. port: match[4],
  40613. path: match[5]
  40614. };
  40615. }
  40616. exports$1.urlParse = urlParse;
  40617. function urlGenerate(aParsedUrl) {
  40618. var url = '';
  40619. if (aParsedUrl.scheme) {
  40620. url += aParsedUrl.scheme + ':';
  40621. }
  40622. url += '//';
  40623. if (aParsedUrl.auth) {
  40624. url += aParsedUrl.auth + '@';
  40625. }
  40626. if (aParsedUrl.host) {
  40627. url += aParsedUrl.host;
  40628. }
  40629. if (aParsedUrl.port) {
  40630. url += ":" + aParsedUrl.port;
  40631. }
  40632. if (aParsedUrl.path) {
  40633. url += aParsedUrl.path;
  40634. }
  40635. return url;
  40636. }
  40637. exports$1.urlGenerate = urlGenerate;
  40638. /**
  40639. * Normalizes a path, or the path portion of a URL:
  40640. *
  40641. * - Replaces consecutive slashes with one slash.
  40642. * - Removes unnecessary '.' parts.
  40643. * - Removes unnecessary '<dir>/..' parts.
  40644. *
  40645. * Based on code in the Node.js 'path' core module.
  40646. *
  40647. * @param aPath The path or url to normalize.
  40648. */
  40649. function normalize(aPath) {
  40650. var path = aPath;
  40651. var url = urlParse(aPath);
  40652. if (url) {
  40653. if (!url.path) {
  40654. return aPath;
  40655. }
  40656. path = url.path;
  40657. }
  40658. var isAbsolute = exports$1.isAbsolute(path);
  40659. var parts = path.split(/\/+/);
  40660. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  40661. part = parts[i];
  40662. if (part === '.') {
  40663. parts.splice(i, 1);
  40664. } else if (part === '..') {
  40665. up++;
  40666. } else if (up > 0) {
  40667. if (part === '') {
  40668. // The first part is blank if the path is absolute. Trying to go
  40669. // above the root is a no-op. Therefore we can remove all '..' parts
  40670. // directly after the root.
  40671. parts.splice(i + 1, up);
  40672. up = 0;
  40673. } else {
  40674. parts.splice(i, 2);
  40675. up--;
  40676. }
  40677. }
  40678. }
  40679. path = parts.join('/');
  40680. if (path === '') {
  40681. path = isAbsolute ? '/' : '.';
  40682. }
  40683. if (url) {
  40684. url.path = path;
  40685. return urlGenerate(url);
  40686. }
  40687. return path;
  40688. }
  40689. exports$1.normalize = normalize;
  40690. /**
  40691. * Joins two paths/URLs.
  40692. *
  40693. * @param aRoot The root path or URL.
  40694. * @param aPath The path or URL to be joined with the root.
  40695. *
  40696. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  40697. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  40698. * first.
  40699. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  40700. * is updated with the result and aRoot is returned. Otherwise the result
  40701. * is returned.
  40702. * - If aPath is absolute, the result is aPath.
  40703. * - Otherwise the two paths are joined with a slash.
  40704. * - Joining for example 'http://' and 'www.example.com' is also supported.
  40705. */
  40706. function join(aRoot, aPath) {
  40707. if (aRoot === "") {
  40708. aRoot = ".";
  40709. }
  40710. if (aPath === "") {
  40711. aPath = ".";
  40712. }
  40713. var aPathUrl = urlParse(aPath);
  40714. var aRootUrl = urlParse(aRoot);
  40715. if (aRootUrl) {
  40716. aRoot = aRootUrl.path || '/';
  40717. }
  40718. // `join(foo, '//www.example.org')`
  40719. if (aPathUrl && !aPathUrl.scheme) {
  40720. if (aRootUrl) {
  40721. aPathUrl.scheme = aRootUrl.scheme;
  40722. }
  40723. return urlGenerate(aPathUrl);
  40724. }
  40725. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  40726. return aPath;
  40727. }
  40728. // `join('http://', 'www.example.com')`
  40729. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  40730. aRootUrl.host = aPath;
  40731. return urlGenerate(aRootUrl);
  40732. }
  40733. var joined = aPath.charAt(0) === '/'
  40734. ? aPath
  40735. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  40736. if (aRootUrl) {
  40737. aRootUrl.path = joined;
  40738. return urlGenerate(aRootUrl);
  40739. }
  40740. return joined;
  40741. }
  40742. exports$1.join = join;
  40743. exports$1.isAbsolute = function (aPath) {
  40744. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  40745. };
  40746. /**
  40747. * Make a path relative to a URL or another path.
  40748. *
  40749. * @param aRoot The root path or URL.
  40750. * @param aPath The path or URL to be made relative to aRoot.
  40751. */
  40752. function relative(aRoot, aPath) {
  40753. if (aRoot === "") {
  40754. aRoot = ".";
  40755. }
  40756. aRoot = aRoot.replace(/\/$/, '');
  40757. // It is possible for the path to be above the root. In this case, simply
  40758. // checking whether the root is a prefix of the path won't work. Instead, we
  40759. // need to remove components from the root one by one, until either we find
  40760. // a prefix that fits, or we run out of components to remove.
  40761. var level = 0;
  40762. while (aPath.indexOf(aRoot + '/') !== 0) {
  40763. var index = aRoot.lastIndexOf("/");
  40764. if (index < 0) {
  40765. return aPath;
  40766. }
  40767. // If the only part of the root that is left is the scheme (i.e. http://,
  40768. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40769. // have exhausted all components, so the path is not relative to the root.
  40770. aRoot = aRoot.slice(0, index);
  40771. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40772. return aPath;
  40773. }
  40774. ++level;
  40775. }
  40776. // Make sure we add a "../" for each component we removed from the root.
  40777. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40778. }
  40779. exports$1.relative = relative;
  40780. var supportsNullProto = (function () {
  40781. var obj = Object.create(null);
  40782. return !('__proto__' in obj);
  40783. }());
  40784. function identity (s) {
  40785. return s;
  40786. }
  40787. /**
  40788. * Because behavior goes wacky when you set `__proto__` on objects, we
  40789. * have to prefix all the strings in our set with an arbitrary character.
  40790. *
  40791. * See https://github.com/mozilla/source-map/pull/31 and
  40792. * https://github.com/mozilla/source-map/issues/30
  40793. *
  40794. * @param String aStr
  40795. */
  40796. function toSetString(aStr) {
  40797. if (isProtoString(aStr)) {
  40798. return '$' + aStr;
  40799. }
  40800. return aStr;
  40801. }
  40802. exports$1.toSetString = supportsNullProto ? identity : toSetString;
  40803. function fromSetString(aStr) {
  40804. if (isProtoString(aStr)) {
  40805. return aStr.slice(1);
  40806. }
  40807. return aStr;
  40808. }
  40809. exports$1.fromSetString = supportsNullProto ? identity : fromSetString;
  40810. function isProtoString(s) {
  40811. if (!s) {
  40812. return false;
  40813. }
  40814. var length = s.length;
  40815. if (length < 9 /* "__proto__".length */) {
  40816. return false;
  40817. }
  40818. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40819. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40820. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40821. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40822. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40823. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40824. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40825. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40826. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40827. return false;
  40828. }
  40829. for (var i = length - 10; i >= 0; i--) {
  40830. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40831. return false;
  40832. }
  40833. }
  40834. return true;
  40835. }
  40836. /**
  40837. * Comparator between two mappings where the original positions are compared.
  40838. *
  40839. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40840. * mappings with the same original source/line/column, but different generated
  40841. * line and column the same. Useful when searching for a mapping with a
  40842. * stubbed out mapping.
  40843. */
  40844. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40845. var cmp = strcmp(mappingA.source, mappingB.source);
  40846. if (cmp !== 0) {
  40847. return cmp;
  40848. }
  40849. cmp = mappingA.originalLine - mappingB.originalLine;
  40850. if (cmp !== 0) {
  40851. return cmp;
  40852. }
  40853. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40854. if (cmp !== 0 || onlyCompareOriginal) {
  40855. return cmp;
  40856. }
  40857. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40858. if (cmp !== 0) {
  40859. return cmp;
  40860. }
  40861. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40862. if (cmp !== 0) {
  40863. return cmp;
  40864. }
  40865. return strcmp(mappingA.name, mappingB.name);
  40866. }
  40867. exports$1.compareByOriginalPositions = compareByOriginalPositions;
  40868. /**
  40869. * Comparator between two mappings with deflated source and name indices where
  40870. * the generated positions are compared.
  40871. *
  40872. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40873. * mappings with the same generated line and column, but different
  40874. * source/name/original line and column the same. Useful when searching for a
  40875. * mapping with a stubbed out mapping.
  40876. */
  40877. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40878. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40879. if (cmp !== 0) {
  40880. return cmp;
  40881. }
  40882. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40883. if (cmp !== 0 || onlyCompareGenerated) {
  40884. return cmp;
  40885. }
  40886. cmp = strcmp(mappingA.source, mappingB.source);
  40887. if (cmp !== 0) {
  40888. return cmp;
  40889. }
  40890. cmp = mappingA.originalLine - mappingB.originalLine;
  40891. if (cmp !== 0) {
  40892. return cmp;
  40893. }
  40894. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40895. if (cmp !== 0) {
  40896. return cmp;
  40897. }
  40898. return strcmp(mappingA.name, mappingB.name);
  40899. }
  40900. exports$1.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  40901. function strcmp(aStr1, aStr2) {
  40902. if (aStr1 === aStr2) {
  40903. return 0;
  40904. }
  40905. if (aStr1 === null) {
  40906. return 1; // aStr2 !== null
  40907. }
  40908. if (aStr2 === null) {
  40909. return -1; // aStr1 !== null
  40910. }
  40911. if (aStr1 > aStr2) {
  40912. return 1;
  40913. }
  40914. return -1;
  40915. }
  40916. /**
  40917. * Comparator between two mappings with inflated source and name strings where
  40918. * the generated positions are compared.
  40919. */
  40920. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  40921. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40922. if (cmp !== 0) {
  40923. return cmp;
  40924. }
  40925. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40926. if (cmp !== 0) {
  40927. return cmp;
  40928. }
  40929. cmp = strcmp(mappingA.source, mappingB.source);
  40930. if (cmp !== 0) {
  40931. return cmp;
  40932. }
  40933. cmp = mappingA.originalLine - mappingB.originalLine;
  40934. if (cmp !== 0) {
  40935. return cmp;
  40936. }
  40937. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40938. if (cmp !== 0) {
  40939. return cmp;
  40940. }
  40941. return strcmp(mappingA.name, mappingB.name);
  40942. }
  40943. exports$1.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  40944. /**
  40945. * Strip any JSON XSSI avoidance prefix from the string (as documented
  40946. * in the source maps specification), and then parse the string as
  40947. * JSON.
  40948. */
  40949. function parseSourceMapInput(str) {
  40950. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  40951. }
  40952. exports$1.parseSourceMapInput = parseSourceMapInput;
  40953. /**
  40954. * Compute the URL of a source given the the source root, the source's
  40955. * URL, and the source map's URL.
  40956. */
  40957. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  40958. sourceURL = sourceURL || '';
  40959. if (sourceRoot) {
  40960. // This follows what Chrome does.
  40961. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  40962. sourceRoot += '/';
  40963. }
  40964. // The spec says:
  40965. // Line 4: An optional source root, useful for relocating source
  40966. // files on a server or removing repeated values in the
  40967. // “sources” entry. This value is prepended to the individual
  40968. // entries in the “source” field.
  40969. sourceURL = sourceRoot + sourceURL;
  40970. }
  40971. // Historically, SourceMapConsumer did not take the sourceMapURL as
  40972. // a parameter. This mode is still somewhat supported, which is why
  40973. // this code block is conditional. However, it's preferable to pass
  40974. // the source map URL to SourceMapConsumer, so that this function
  40975. // can implement the source URL resolution algorithm as outlined in
  40976. // the spec. This block is basically the equivalent of:
  40977. // new URL(sourceURL, sourceMapURL).toString()
  40978. // ... except it avoids using URL, which wasn't available in the
  40979. // older releases of node still supported by this library.
  40980. //
  40981. // The spec says:
  40982. // If the sources are not absolute URLs after prepending of the
  40983. // “sourceRoot”, the sources are resolved relative to the
  40984. // SourceMap (like resolving script src in a html document).
  40985. if (sourceMapURL) {
  40986. var parsed = urlParse(sourceMapURL);
  40987. if (!parsed) {
  40988. throw new Error("sourceMapURL could not be parsed");
  40989. }
  40990. if (parsed.path) {
  40991. // Strip the last path component, but keep the "/".
  40992. var index = parsed.path.lastIndexOf('/');
  40993. if (index >= 0) {
  40994. parsed.path = parsed.path.substring(0, index + 1);
  40995. }
  40996. }
  40997. sourceURL = join(urlGenerate(parsed), sourceURL);
  40998. }
  40999. return normalize(sourceURL);
  41000. }
  41001. exports$1.computeSourceURL = computeSourceURL;
  41002. } (util));
  41003. return util;
  41004. }
  41005. var arraySet = {};
  41006. /* -*- Mode: js; js-indent-level: 2; -*- */
  41007. var hasRequiredArraySet;
  41008. function requireArraySet () {
  41009. if (hasRequiredArraySet) return arraySet;
  41010. hasRequiredArraySet = 1;
  41011. /*
  41012. * Copyright 2011 Mozilla Foundation and contributors
  41013. * Licensed under the New BSD license. See LICENSE or:
  41014. * http://opensource.org/licenses/BSD-3-Clause
  41015. */
  41016. var util = /*@__PURE__*/ requireUtil();
  41017. var has = Object.prototype.hasOwnProperty;
  41018. var hasNativeMap = typeof Map !== "undefined";
  41019. /**
  41020. * A data structure which is a combination of an array and a set. Adding a new
  41021. * member is O(1), testing for membership is O(1), and finding the index of an
  41022. * element is O(1). Removing elements from the set is not supported. Only
  41023. * strings are supported for membership.
  41024. */
  41025. function ArraySet() {
  41026. this._array = [];
  41027. this._set = hasNativeMap ? new Map() : Object.create(null);
  41028. }
  41029. /**
  41030. * Static method for creating ArraySet instances from an existing array.
  41031. */
  41032. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  41033. var set = new ArraySet();
  41034. for (var i = 0, len = aArray.length; i < len; i++) {
  41035. set.add(aArray[i], aAllowDuplicates);
  41036. }
  41037. return set;
  41038. };
  41039. /**
  41040. * Return how many unique items are in this ArraySet. If duplicates have been
  41041. * added, than those do not count towards the size.
  41042. *
  41043. * @returns Number
  41044. */
  41045. ArraySet.prototype.size = function ArraySet_size() {
  41046. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  41047. };
  41048. /**
  41049. * Add the given string to this set.
  41050. *
  41051. * @param String aStr
  41052. */
  41053. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  41054. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  41055. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  41056. var idx = this._array.length;
  41057. if (!isDuplicate || aAllowDuplicates) {
  41058. this._array.push(aStr);
  41059. }
  41060. if (!isDuplicate) {
  41061. if (hasNativeMap) {
  41062. this._set.set(aStr, idx);
  41063. } else {
  41064. this._set[sStr] = idx;
  41065. }
  41066. }
  41067. };
  41068. /**
  41069. * Is the given string a member of this set?
  41070. *
  41071. * @param String aStr
  41072. */
  41073. ArraySet.prototype.has = function ArraySet_has(aStr) {
  41074. if (hasNativeMap) {
  41075. return this._set.has(aStr);
  41076. } else {
  41077. var sStr = util.toSetString(aStr);
  41078. return has.call(this._set, sStr);
  41079. }
  41080. };
  41081. /**
  41082. * What is the index of the given string in the array?
  41083. *
  41084. * @param String aStr
  41085. */
  41086. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  41087. if (hasNativeMap) {
  41088. var idx = this._set.get(aStr);
  41089. if (idx >= 0) {
  41090. return idx;
  41091. }
  41092. } else {
  41093. var sStr = util.toSetString(aStr);
  41094. if (has.call(this._set, sStr)) {
  41095. return this._set[sStr];
  41096. }
  41097. }
  41098. throw new Error('"' + aStr + '" is not in the set.');
  41099. };
  41100. /**
  41101. * What is the element at the given index?
  41102. *
  41103. * @param Number aIdx
  41104. */
  41105. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  41106. if (aIdx >= 0 && aIdx < this._array.length) {
  41107. return this._array[aIdx];
  41108. }
  41109. throw new Error('No element indexed by ' + aIdx);
  41110. };
  41111. /**
  41112. * Returns the array representation of this set (which has the proper indices
  41113. * indicated by indexOf). Note that this is a copy of the internal array used
  41114. * for storing the members so that no one can mess with internal state.
  41115. */
  41116. ArraySet.prototype.toArray = function ArraySet_toArray() {
  41117. return this._array.slice();
  41118. };
  41119. arraySet.ArraySet = ArraySet;
  41120. return arraySet;
  41121. }
  41122. var mappingList = {};
  41123. /* -*- Mode: js; js-indent-level: 2; -*- */
  41124. var hasRequiredMappingList;
  41125. function requireMappingList () {
  41126. if (hasRequiredMappingList) return mappingList;
  41127. hasRequiredMappingList = 1;
  41128. /*
  41129. * Copyright 2014 Mozilla Foundation and contributors
  41130. * Licensed under the New BSD license. See LICENSE or:
  41131. * http://opensource.org/licenses/BSD-3-Clause
  41132. */
  41133. var util = /*@__PURE__*/ requireUtil();
  41134. /**
  41135. * Determine whether mappingB is after mappingA with respect to generated
  41136. * position.
  41137. */
  41138. function generatedPositionAfter(mappingA, mappingB) {
  41139. // Optimized for most common case
  41140. var lineA = mappingA.generatedLine;
  41141. var lineB = mappingB.generatedLine;
  41142. var columnA = mappingA.generatedColumn;
  41143. var columnB = mappingB.generatedColumn;
  41144. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  41145. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  41146. }
  41147. /**
  41148. * A data structure to provide a sorted view of accumulated mappings in a
  41149. * performance conscious manner. It trades a neglibable overhead in general
  41150. * case for a large speedup in case of mappings being added in order.
  41151. */
  41152. function MappingList() {
  41153. this._array = [];
  41154. this._sorted = true;
  41155. // Serves as infimum
  41156. this._last = {generatedLine: -1, generatedColumn: 0};
  41157. }
  41158. /**
  41159. * Iterate through internal items. This method takes the same arguments that
  41160. * `Array.prototype.forEach` takes.
  41161. *
  41162. * NOTE: The order of the mappings is NOT guaranteed.
  41163. */
  41164. MappingList.prototype.unsortedForEach =
  41165. function MappingList_forEach(aCallback, aThisArg) {
  41166. this._array.forEach(aCallback, aThisArg);
  41167. };
  41168. /**
  41169. * Add the given source mapping.
  41170. *
  41171. * @param Object aMapping
  41172. */
  41173. MappingList.prototype.add = function MappingList_add(aMapping) {
  41174. if (generatedPositionAfter(this._last, aMapping)) {
  41175. this._last = aMapping;
  41176. this._array.push(aMapping);
  41177. } else {
  41178. this._sorted = false;
  41179. this._array.push(aMapping);
  41180. }
  41181. };
  41182. /**
  41183. * Returns the flat, sorted array of mappings. The mappings are sorted by
  41184. * generated position.
  41185. *
  41186. * WARNING: This method returns internal data without copying, for
  41187. * performance. The return value must NOT be mutated, and should be treated as
  41188. * an immutable borrow. If you want to take ownership, you must make your own
  41189. * copy.
  41190. */
  41191. MappingList.prototype.toArray = function MappingList_toArray() {
  41192. if (!this._sorted) {
  41193. this._array.sort(util.compareByGeneratedPositionsInflated);
  41194. this._sorted = true;
  41195. }
  41196. return this._array;
  41197. };
  41198. mappingList.MappingList = MappingList;
  41199. return mappingList;
  41200. }
  41201. /* -*- Mode: js; js-indent-level: 2; -*- */
  41202. var hasRequiredSourceMapGenerator;
  41203. function requireSourceMapGenerator () {
  41204. if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
  41205. hasRequiredSourceMapGenerator = 1;
  41206. /*
  41207. * Copyright 2011 Mozilla Foundation and contributors
  41208. * Licensed under the New BSD license. See LICENSE or:
  41209. * http://opensource.org/licenses/BSD-3-Clause
  41210. */
  41211. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41212. var util = /*@__PURE__*/ requireUtil();
  41213. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41214. var MappingList = /*@__PURE__*/ requireMappingList().MappingList;
  41215. /**
  41216. * An instance of the SourceMapGenerator represents a source map which is
  41217. * being built incrementally. You may pass an object with the following
  41218. * properties:
  41219. *
  41220. * - file: The filename of the generated source.
  41221. * - sourceRoot: A root for all relative URLs in this source map.
  41222. */
  41223. function SourceMapGenerator(aArgs) {
  41224. if (!aArgs) {
  41225. aArgs = {};
  41226. }
  41227. this._file = util.getArg(aArgs, 'file', null);
  41228. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  41229. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  41230. this._sources = new ArraySet();
  41231. this._names = new ArraySet();
  41232. this._mappings = new MappingList();
  41233. this._sourcesContents = null;
  41234. }
  41235. SourceMapGenerator.prototype._version = 3;
  41236. /**
  41237. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  41238. *
  41239. * @param aSourceMapConsumer The SourceMap.
  41240. */
  41241. SourceMapGenerator.fromSourceMap =
  41242. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  41243. var sourceRoot = aSourceMapConsumer.sourceRoot;
  41244. var generator = new SourceMapGenerator({
  41245. file: aSourceMapConsumer.file,
  41246. sourceRoot: sourceRoot
  41247. });
  41248. aSourceMapConsumer.eachMapping(function (mapping) {
  41249. var newMapping = {
  41250. generated: {
  41251. line: mapping.generatedLine,
  41252. column: mapping.generatedColumn
  41253. }
  41254. };
  41255. if (mapping.source != null) {
  41256. newMapping.source = mapping.source;
  41257. if (sourceRoot != null) {
  41258. newMapping.source = util.relative(sourceRoot, newMapping.source);
  41259. }
  41260. newMapping.original = {
  41261. line: mapping.originalLine,
  41262. column: mapping.originalColumn
  41263. };
  41264. if (mapping.name != null) {
  41265. newMapping.name = mapping.name;
  41266. }
  41267. }
  41268. generator.addMapping(newMapping);
  41269. });
  41270. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41271. var sourceRelative = sourceFile;
  41272. if (sourceRoot !== null) {
  41273. sourceRelative = util.relative(sourceRoot, sourceFile);
  41274. }
  41275. if (!generator._sources.has(sourceRelative)) {
  41276. generator._sources.add(sourceRelative);
  41277. }
  41278. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41279. if (content != null) {
  41280. generator.setSourceContent(sourceFile, content);
  41281. }
  41282. });
  41283. return generator;
  41284. };
  41285. /**
  41286. * Add a single mapping from original source line and column to the generated
  41287. * source's line and column for this source map being created. The mapping
  41288. * object should have the following properties:
  41289. *
  41290. * - generated: An object with the generated line and column positions.
  41291. * - original: An object with the original line and column positions.
  41292. * - source: The original source file (relative to the sourceRoot).
  41293. * - name: An optional original token name for this mapping.
  41294. */
  41295. SourceMapGenerator.prototype.addMapping =
  41296. function SourceMapGenerator_addMapping(aArgs) {
  41297. var generated = util.getArg(aArgs, 'generated');
  41298. var original = util.getArg(aArgs, 'original', null);
  41299. var source = util.getArg(aArgs, 'source', null);
  41300. var name = util.getArg(aArgs, 'name', null);
  41301. if (!this._skipValidation) {
  41302. this._validateMapping(generated, original, source, name);
  41303. }
  41304. if (source != null) {
  41305. source = String(source);
  41306. if (!this._sources.has(source)) {
  41307. this._sources.add(source);
  41308. }
  41309. }
  41310. if (name != null) {
  41311. name = String(name);
  41312. if (!this._names.has(name)) {
  41313. this._names.add(name);
  41314. }
  41315. }
  41316. this._mappings.add({
  41317. generatedLine: generated.line,
  41318. generatedColumn: generated.column,
  41319. originalLine: original != null && original.line,
  41320. originalColumn: original != null && original.column,
  41321. source: source,
  41322. name: name
  41323. });
  41324. };
  41325. /**
  41326. * Set the source content for a source file.
  41327. */
  41328. SourceMapGenerator.prototype.setSourceContent =
  41329. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  41330. var source = aSourceFile;
  41331. if (this._sourceRoot != null) {
  41332. source = util.relative(this._sourceRoot, source);
  41333. }
  41334. if (aSourceContent != null) {
  41335. // Add the source content to the _sourcesContents map.
  41336. // Create a new _sourcesContents map if the property is null.
  41337. if (!this._sourcesContents) {
  41338. this._sourcesContents = Object.create(null);
  41339. }
  41340. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  41341. } else if (this._sourcesContents) {
  41342. // Remove the source file from the _sourcesContents map.
  41343. // If the _sourcesContents map is empty, set the property to null.
  41344. delete this._sourcesContents[util.toSetString(source)];
  41345. if (Object.keys(this._sourcesContents).length === 0) {
  41346. this._sourcesContents = null;
  41347. }
  41348. }
  41349. };
  41350. /**
  41351. * Applies the mappings of a sub-source-map for a specific source file to the
  41352. * source map being generated. Each mapping to the supplied source file is
  41353. * rewritten using the supplied source map. Note: The resolution for the
  41354. * resulting mappings is the minimium of this map and the supplied map.
  41355. *
  41356. * @param aSourceMapConsumer The source map to be applied.
  41357. * @param aSourceFile Optional. The filename of the source file.
  41358. * If omitted, SourceMapConsumer's file property will be used.
  41359. * @param aSourceMapPath Optional. The dirname of the path to the source map
  41360. * to be applied. If relative, it is relative to the SourceMapConsumer.
  41361. * This parameter is needed when the two source maps aren't in the same
  41362. * directory, and the source map to be applied contains relative source
  41363. * paths. If so, those relative source paths need to be rewritten
  41364. * relative to the SourceMapGenerator.
  41365. */
  41366. SourceMapGenerator.prototype.applySourceMap =
  41367. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  41368. var sourceFile = aSourceFile;
  41369. // If aSourceFile is omitted, we will use the file property of the SourceMap
  41370. if (aSourceFile == null) {
  41371. if (aSourceMapConsumer.file == null) {
  41372. throw new Error(
  41373. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  41374. 'or the source map\'s "file" property. Both were omitted.'
  41375. );
  41376. }
  41377. sourceFile = aSourceMapConsumer.file;
  41378. }
  41379. var sourceRoot = this._sourceRoot;
  41380. // Make "sourceFile" relative if an absolute Url is passed.
  41381. if (sourceRoot != null) {
  41382. sourceFile = util.relative(sourceRoot, sourceFile);
  41383. }
  41384. // Applying the SourceMap can add and remove items from the sources and
  41385. // the names array.
  41386. var newSources = new ArraySet();
  41387. var newNames = new ArraySet();
  41388. // Find mappings for the "sourceFile"
  41389. this._mappings.unsortedForEach(function (mapping) {
  41390. if (mapping.source === sourceFile && mapping.originalLine != null) {
  41391. // Check if it can be mapped by the source map, then update the mapping.
  41392. var original = aSourceMapConsumer.originalPositionFor({
  41393. line: mapping.originalLine,
  41394. column: mapping.originalColumn
  41395. });
  41396. if (original.source != null) {
  41397. // Copy mapping
  41398. mapping.source = original.source;
  41399. if (aSourceMapPath != null) {
  41400. mapping.source = util.join(aSourceMapPath, mapping.source);
  41401. }
  41402. if (sourceRoot != null) {
  41403. mapping.source = util.relative(sourceRoot, mapping.source);
  41404. }
  41405. mapping.originalLine = original.line;
  41406. mapping.originalColumn = original.column;
  41407. if (original.name != null) {
  41408. mapping.name = original.name;
  41409. }
  41410. }
  41411. }
  41412. var source = mapping.source;
  41413. if (source != null && !newSources.has(source)) {
  41414. newSources.add(source);
  41415. }
  41416. var name = mapping.name;
  41417. if (name != null && !newNames.has(name)) {
  41418. newNames.add(name);
  41419. }
  41420. }, this);
  41421. this._sources = newSources;
  41422. this._names = newNames;
  41423. // Copy sourcesContents of applied map.
  41424. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41425. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41426. if (content != null) {
  41427. if (aSourceMapPath != null) {
  41428. sourceFile = util.join(aSourceMapPath, sourceFile);
  41429. }
  41430. if (sourceRoot != null) {
  41431. sourceFile = util.relative(sourceRoot, sourceFile);
  41432. }
  41433. this.setSourceContent(sourceFile, content);
  41434. }
  41435. }, this);
  41436. };
  41437. /**
  41438. * A mapping can have one of the three levels of data:
  41439. *
  41440. * 1. Just the generated position.
  41441. * 2. The Generated position, original position, and original source.
  41442. * 3. Generated and original position, original source, as well as a name
  41443. * token.
  41444. *
  41445. * To maintain consistency, we validate that any new mapping being added falls
  41446. * in to one of these categories.
  41447. */
  41448. SourceMapGenerator.prototype._validateMapping =
  41449. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  41450. aName) {
  41451. // When aOriginal is truthy but has empty values for .line and .column,
  41452. // it is most likely a programmer error. In this case we throw a very
  41453. // specific error message to try to guide them the right way.
  41454. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  41455. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  41456. throw new Error(
  41457. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  41458. 'the original mapping entirely and only map the generated position. If so, pass ' +
  41459. 'null for the original mapping instead of an object with empty or null values.'
  41460. );
  41461. }
  41462. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41463. && aGenerated.line > 0 && aGenerated.column >= 0
  41464. && !aOriginal && !aSource && !aName) {
  41465. // Case 1.
  41466. return;
  41467. }
  41468. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41469. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  41470. && aGenerated.line > 0 && aGenerated.column >= 0
  41471. && aOriginal.line > 0 && aOriginal.column >= 0
  41472. && aSource) {
  41473. // Cases 2 and 3.
  41474. return;
  41475. }
  41476. else {
  41477. throw new Error('Invalid mapping: ' + JSON.stringify({
  41478. generated: aGenerated,
  41479. source: aSource,
  41480. original: aOriginal,
  41481. name: aName
  41482. }));
  41483. }
  41484. };
  41485. /**
  41486. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  41487. * specified by the source map format.
  41488. */
  41489. SourceMapGenerator.prototype._serializeMappings =
  41490. function SourceMapGenerator_serializeMappings() {
  41491. var previousGeneratedColumn = 0;
  41492. var previousGeneratedLine = 1;
  41493. var previousOriginalColumn = 0;
  41494. var previousOriginalLine = 0;
  41495. var previousName = 0;
  41496. var previousSource = 0;
  41497. var result = '';
  41498. var next;
  41499. var mapping;
  41500. var nameIdx;
  41501. var sourceIdx;
  41502. var mappings = this._mappings.toArray();
  41503. for (var i = 0, len = mappings.length; i < len; i++) {
  41504. mapping = mappings[i];
  41505. next = '';
  41506. if (mapping.generatedLine !== previousGeneratedLine) {
  41507. previousGeneratedColumn = 0;
  41508. while (mapping.generatedLine !== previousGeneratedLine) {
  41509. next += ';';
  41510. previousGeneratedLine++;
  41511. }
  41512. }
  41513. else {
  41514. if (i > 0) {
  41515. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  41516. continue;
  41517. }
  41518. next += ',';
  41519. }
  41520. }
  41521. next += base64VLQ.encode(mapping.generatedColumn
  41522. - previousGeneratedColumn);
  41523. previousGeneratedColumn = mapping.generatedColumn;
  41524. if (mapping.source != null) {
  41525. sourceIdx = this._sources.indexOf(mapping.source);
  41526. next += base64VLQ.encode(sourceIdx - previousSource);
  41527. previousSource = sourceIdx;
  41528. // lines are stored 0-based in SourceMap spec version 3
  41529. next += base64VLQ.encode(mapping.originalLine - 1
  41530. - previousOriginalLine);
  41531. previousOriginalLine = mapping.originalLine - 1;
  41532. next += base64VLQ.encode(mapping.originalColumn
  41533. - previousOriginalColumn);
  41534. previousOriginalColumn = mapping.originalColumn;
  41535. if (mapping.name != null) {
  41536. nameIdx = this._names.indexOf(mapping.name);
  41537. next += base64VLQ.encode(nameIdx - previousName);
  41538. previousName = nameIdx;
  41539. }
  41540. }
  41541. result += next;
  41542. }
  41543. return result;
  41544. };
  41545. SourceMapGenerator.prototype._generateSourcesContent =
  41546. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  41547. return aSources.map(function (source) {
  41548. if (!this._sourcesContents) {
  41549. return null;
  41550. }
  41551. if (aSourceRoot != null) {
  41552. source = util.relative(aSourceRoot, source);
  41553. }
  41554. var key = util.toSetString(source);
  41555. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  41556. ? this._sourcesContents[key]
  41557. : null;
  41558. }, this);
  41559. };
  41560. /**
  41561. * Externalize the source map.
  41562. */
  41563. SourceMapGenerator.prototype.toJSON =
  41564. function SourceMapGenerator_toJSON() {
  41565. var map = {
  41566. version: this._version,
  41567. sources: this._sources.toArray(),
  41568. names: this._names.toArray(),
  41569. mappings: this._serializeMappings()
  41570. };
  41571. if (this._file != null) {
  41572. map.file = this._file;
  41573. }
  41574. if (this._sourceRoot != null) {
  41575. map.sourceRoot = this._sourceRoot;
  41576. }
  41577. if (this._sourcesContents) {
  41578. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  41579. }
  41580. return map;
  41581. };
  41582. /**
  41583. * Render the source map being generated to a string.
  41584. */
  41585. SourceMapGenerator.prototype.toString =
  41586. function SourceMapGenerator_toString() {
  41587. return JSON.stringify(this.toJSON());
  41588. };
  41589. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
  41590. return sourceMapGenerator;
  41591. }
  41592. var sourceMapConsumer = {};
  41593. var binarySearch = {};
  41594. /* -*- Mode: js; js-indent-level: 2; -*- */
  41595. var hasRequiredBinarySearch;
  41596. function requireBinarySearch () {
  41597. if (hasRequiredBinarySearch) return binarySearch;
  41598. hasRequiredBinarySearch = 1;
  41599. (function (exports$1) {
  41600. /*
  41601. * Copyright 2011 Mozilla Foundation and contributors
  41602. * Licensed under the New BSD license. See LICENSE or:
  41603. * http://opensource.org/licenses/BSD-3-Clause
  41604. */
  41605. exports$1.GREATEST_LOWER_BOUND = 1;
  41606. exports$1.LEAST_UPPER_BOUND = 2;
  41607. /**
  41608. * Recursive implementation of binary search.
  41609. *
  41610. * @param aLow Indices here and lower do not contain the needle.
  41611. * @param aHigh Indices here and higher do not contain the needle.
  41612. * @param aNeedle The element being searched for.
  41613. * @param aHaystack The non-empty array being searched.
  41614. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  41615. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41616. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41617. * closest element that is smaller than or greater than the one we are
  41618. * searching for, respectively, if the exact element cannot be found.
  41619. */
  41620. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  41621. // This function terminates when one of the following is true:
  41622. //
  41623. // 1. We find the exact element we are looking for.
  41624. //
  41625. // 2. We did not find the exact element, but we can return the index of
  41626. // the next-closest element.
  41627. //
  41628. // 3. We did not find the exact element, and there is no next-closest
  41629. // element than the one we are searching for, so we return -1.
  41630. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  41631. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  41632. if (cmp === 0) {
  41633. // Found the element we are looking for.
  41634. return mid;
  41635. }
  41636. else if (cmp > 0) {
  41637. // Our needle is greater than aHaystack[mid].
  41638. if (aHigh - mid > 1) {
  41639. // The element is in the upper half.
  41640. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  41641. }
  41642. // The exact needle element was not found in this haystack. Determine if
  41643. // we are in termination case (3) or (2) and return the appropriate thing.
  41644. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41645. return aHigh < aHaystack.length ? aHigh : -1;
  41646. } else {
  41647. return mid;
  41648. }
  41649. }
  41650. else {
  41651. // Our needle is less than aHaystack[mid].
  41652. if (mid - aLow > 1) {
  41653. // The element is in the lower half.
  41654. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  41655. }
  41656. // we are in termination case (3) or (2) and return the appropriate thing.
  41657. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41658. return mid;
  41659. } else {
  41660. return aLow < 0 ? -1 : aLow;
  41661. }
  41662. }
  41663. }
  41664. /**
  41665. * This is an implementation of binary search which will always try and return
  41666. * the index of the closest element if there is no exact hit. This is because
  41667. * mappings between original and generated line/col pairs are single points,
  41668. * and there is an implicit region between each of them, so a miss just means
  41669. * that you aren't on the very start of a region.
  41670. *
  41671. * @param aNeedle The element you are looking for.
  41672. * @param aHaystack The array that is being searched.
  41673. * @param aCompare A function which takes the needle and an element in the
  41674. * array and returns -1, 0, or 1 depending on whether the needle is less
  41675. * than, equal to, or greater than the element, respectively.
  41676. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41677. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41678. * closest element that is smaller than or greater than the one we are
  41679. * searching for, respectively, if the exact element cannot be found.
  41680. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  41681. */
  41682. exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  41683. if (aHaystack.length === 0) {
  41684. return -1;
  41685. }
  41686. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  41687. aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
  41688. if (index < 0) {
  41689. return -1;
  41690. }
  41691. // We have found either the exact element, or the next-closest element than
  41692. // the one we are searching for. However, there may be more than one such
  41693. // element. Make sure we always return the smallest of these.
  41694. while (index - 1 >= 0) {
  41695. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  41696. break;
  41697. }
  41698. --index;
  41699. }
  41700. return index;
  41701. };
  41702. } (binarySearch));
  41703. return binarySearch;
  41704. }
  41705. var quickSort = {};
  41706. /* -*- Mode: js; js-indent-level: 2; -*- */
  41707. var hasRequiredQuickSort;
  41708. function requireQuickSort () {
  41709. if (hasRequiredQuickSort) return quickSort;
  41710. hasRequiredQuickSort = 1;
  41711. /*
  41712. * Copyright 2011 Mozilla Foundation and contributors
  41713. * Licensed under the New BSD license. See LICENSE or:
  41714. * http://opensource.org/licenses/BSD-3-Clause
  41715. */
  41716. // It turns out that some (most?) JavaScript engines don't self-host
  41717. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  41718. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  41719. // custom comparator function, calling back and forth between the VM's C++ and
  41720. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  41721. // worse generated code for the comparator function than would be optimal. In
  41722. // fact, when sorting with a comparator, these costs outweigh the benefits of
  41723. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  41724. // a ~3500ms mean speed-up in `bench/bench.html`.
  41725. /**
  41726. * Swap the elements indexed by `x` and `y` in the array `ary`.
  41727. *
  41728. * @param {Array} ary
  41729. * The array.
  41730. * @param {Number} x
  41731. * The index of the first item.
  41732. * @param {Number} y
  41733. * The index of the second item.
  41734. */
  41735. function swap(ary, x, y) {
  41736. var temp = ary[x];
  41737. ary[x] = ary[y];
  41738. ary[y] = temp;
  41739. }
  41740. /**
  41741. * Returns a random integer within the range `low .. high` inclusive.
  41742. *
  41743. * @param {Number} low
  41744. * The lower bound on the range.
  41745. * @param {Number} high
  41746. * The upper bound on the range.
  41747. */
  41748. function randomIntInRange(low, high) {
  41749. return Math.round(low + (Math.random() * (high - low)));
  41750. }
  41751. /**
  41752. * The Quick Sort algorithm.
  41753. *
  41754. * @param {Array} ary
  41755. * An array to sort.
  41756. * @param {function} comparator
  41757. * Function to use to compare two items.
  41758. * @param {Number} p
  41759. * Start index of the array
  41760. * @param {Number} r
  41761. * End index of the array
  41762. */
  41763. function doQuickSort(ary, comparator, p, r) {
  41764. // If our lower bound is less than our upper bound, we (1) partition the
  41765. // array into two pieces and (2) recurse on each half. If it is not, this is
  41766. // the empty array and our base case.
  41767. if (p < r) {
  41768. // (1) Partitioning.
  41769. //
  41770. // The partitioning chooses a pivot between `p` and `r` and moves all
  41771. // elements that are less than or equal to the pivot to the before it, and
  41772. // all the elements that are greater than it after it. The effect is that
  41773. // once partition is done, the pivot is in the exact place it will be when
  41774. // the array is put in sorted order, and it will not need to be moved
  41775. // again. This runs in O(n) time.
  41776. // Always choose a random pivot so that an input array which is reverse
  41777. // sorted does not cause O(n^2) running time.
  41778. var pivotIndex = randomIntInRange(p, r);
  41779. var i = p - 1;
  41780. swap(ary, pivotIndex, r);
  41781. var pivot = ary[r];
  41782. // Immediately after `j` is incremented in this loop, the following hold
  41783. // true:
  41784. //
  41785. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  41786. //
  41787. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41788. for (var j = p; j < r; j++) {
  41789. if (comparator(ary[j], pivot) <= 0) {
  41790. i += 1;
  41791. swap(ary, i, j);
  41792. }
  41793. }
  41794. swap(ary, i + 1, j);
  41795. var q = i + 1;
  41796. // (2) Recurse on each half.
  41797. doQuickSort(ary, comparator, p, q - 1);
  41798. doQuickSort(ary, comparator, q + 1, r);
  41799. }
  41800. }
  41801. /**
  41802. * Sort the given array in-place with the given comparator function.
  41803. *
  41804. * @param {Array} ary
  41805. * An array to sort.
  41806. * @param {function} comparator
  41807. * Function to use to compare two items.
  41808. */
  41809. quickSort.quickSort = function (ary, comparator) {
  41810. doQuickSort(ary, comparator, 0, ary.length - 1);
  41811. };
  41812. return quickSort;
  41813. }
  41814. /* -*- Mode: js; js-indent-level: 2; -*- */
  41815. var hasRequiredSourceMapConsumer;
  41816. function requireSourceMapConsumer () {
  41817. if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
  41818. hasRequiredSourceMapConsumer = 1;
  41819. /*
  41820. * Copyright 2011 Mozilla Foundation and contributors
  41821. * Licensed under the New BSD license. See LICENSE or:
  41822. * http://opensource.org/licenses/BSD-3-Clause
  41823. */
  41824. var util = /*@__PURE__*/ requireUtil();
  41825. var binarySearch = /*@__PURE__*/ requireBinarySearch();
  41826. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41827. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41828. var quickSort = /*@__PURE__*/ requireQuickSort().quickSort;
  41829. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  41830. var sourceMap = aSourceMap;
  41831. if (typeof aSourceMap === 'string') {
  41832. sourceMap = util.parseSourceMapInput(aSourceMap);
  41833. }
  41834. return sourceMap.sections != null
  41835. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41836. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41837. }
  41838. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41839. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41840. };
  41841. /**
  41842. * The version of the source mapping spec that we are consuming.
  41843. */
  41844. SourceMapConsumer.prototype._version = 3;
  41845. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41846. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41847. // are lazily instantiated, accessed via the `_generatedMappings` and
  41848. // `_originalMappings` getters respectively, and we only parse the mappings
  41849. // and create these arrays once queried for a source location. We jump through
  41850. // these hoops because there can be many thousands of mappings, and parsing
  41851. // them is expensive, so we only want to do it if we must.
  41852. //
  41853. // Each object in the arrays is of the form:
  41854. //
  41855. // {
  41856. // generatedLine: The line number in the generated code,
  41857. // generatedColumn: The column number in the generated code,
  41858. // source: The path to the original source file that generated this
  41859. // chunk of code,
  41860. // originalLine: The line number in the original source that
  41861. // corresponds to this chunk of generated code,
  41862. // originalColumn: The column number in the original source that
  41863. // corresponds to this chunk of generated code,
  41864. // name: The name of the original symbol which generated this chunk of
  41865. // code.
  41866. // }
  41867. //
  41868. // All properties except for `generatedLine` and `generatedColumn` can be
  41869. // `null`.
  41870. //
  41871. // `_generatedMappings` is ordered by the generated positions.
  41872. //
  41873. // `_originalMappings` is ordered by the original positions.
  41874. SourceMapConsumer.prototype.__generatedMappings = null;
  41875. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  41876. configurable: true,
  41877. enumerable: true,
  41878. get: function () {
  41879. if (!this.__generatedMappings) {
  41880. this._parseMappings(this._mappings, this.sourceRoot);
  41881. }
  41882. return this.__generatedMappings;
  41883. }
  41884. });
  41885. SourceMapConsumer.prototype.__originalMappings = null;
  41886. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  41887. configurable: true,
  41888. enumerable: true,
  41889. get: function () {
  41890. if (!this.__originalMappings) {
  41891. this._parseMappings(this._mappings, this.sourceRoot);
  41892. }
  41893. return this.__originalMappings;
  41894. }
  41895. });
  41896. SourceMapConsumer.prototype._charIsMappingSeparator =
  41897. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  41898. var c = aStr.charAt(index);
  41899. return c === ";" || c === ",";
  41900. };
  41901. /**
  41902. * Parse the mappings in a string in to a data structure which we can easily
  41903. * query (the ordered arrays in the `this.__generatedMappings` and
  41904. * `this.__originalMappings` properties).
  41905. */
  41906. SourceMapConsumer.prototype._parseMappings =
  41907. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41908. throw new Error("Subclasses must implement _parseMappings");
  41909. };
  41910. SourceMapConsumer.GENERATED_ORDER = 1;
  41911. SourceMapConsumer.ORIGINAL_ORDER = 2;
  41912. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  41913. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  41914. /**
  41915. * Iterate over each mapping between an original source/line/column and a
  41916. * generated line/column in this source map.
  41917. *
  41918. * @param Function aCallback
  41919. * The function that is called with each mapping.
  41920. * @param Object aContext
  41921. * Optional. If specified, this object will be the value of `this` every
  41922. * time that `aCallback` is called.
  41923. * @param aOrder
  41924. * Either `SourceMapConsumer.GENERATED_ORDER` or
  41925. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  41926. * iterate over the mappings sorted by the generated file's line/column
  41927. * order or the original's source/line/column order, respectively. Defaults to
  41928. * `SourceMapConsumer.GENERATED_ORDER`.
  41929. */
  41930. SourceMapConsumer.prototype.eachMapping =
  41931. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  41932. var context = aContext || null;
  41933. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  41934. var mappings;
  41935. switch (order) {
  41936. case SourceMapConsumer.GENERATED_ORDER:
  41937. mappings = this._generatedMappings;
  41938. break;
  41939. case SourceMapConsumer.ORIGINAL_ORDER:
  41940. mappings = this._originalMappings;
  41941. break;
  41942. default:
  41943. throw new Error("Unknown order of iteration.");
  41944. }
  41945. var sourceRoot = this.sourceRoot;
  41946. mappings.map(function (mapping) {
  41947. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  41948. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  41949. return {
  41950. source: source,
  41951. generatedLine: mapping.generatedLine,
  41952. generatedColumn: mapping.generatedColumn,
  41953. originalLine: mapping.originalLine,
  41954. originalColumn: mapping.originalColumn,
  41955. name: mapping.name === null ? null : this._names.at(mapping.name)
  41956. };
  41957. }, this).forEach(aCallback, context);
  41958. };
  41959. /**
  41960. * Returns all generated line and column information for the original source,
  41961. * line, and column provided. If no column is provided, returns all mappings
  41962. * corresponding to a either the line we are searching for or the next
  41963. * closest line that has any mappings. Otherwise, returns all mappings
  41964. * corresponding to the given line and either the column we are searching for
  41965. * or the next closest column that has any offsets.
  41966. *
  41967. * The only argument is an object with the following properties:
  41968. *
  41969. * - source: The filename of the original source.
  41970. * - line: The line number in the original source. The line number is 1-based.
  41971. * - column: Optional. the column number in the original source.
  41972. * The column number is 0-based.
  41973. *
  41974. * and an array of objects is returned, each with the following properties:
  41975. *
  41976. * - line: The line number in the generated source, or null. The
  41977. * line number is 1-based.
  41978. * - column: The column number in the generated source, or null.
  41979. * The column number is 0-based.
  41980. */
  41981. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  41982. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  41983. var line = util.getArg(aArgs, 'line');
  41984. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  41985. // returns the index of the closest mapping less than the needle. By
  41986. // setting needle.originalColumn to 0, we thus find the last mapping for
  41987. // the given line, provided such a mapping exists.
  41988. var needle = {
  41989. source: util.getArg(aArgs, 'source'),
  41990. originalLine: line,
  41991. originalColumn: util.getArg(aArgs, 'column', 0)
  41992. };
  41993. needle.source = this._findSourceIndex(needle.source);
  41994. if (needle.source < 0) {
  41995. return [];
  41996. }
  41997. var mappings = [];
  41998. var index = this._findMapping(needle,
  41999. this._originalMappings,
  42000. "originalLine",
  42001. "originalColumn",
  42002. util.compareByOriginalPositions,
  42003. binarySearch.LEAST_UPPER_BOUND);
  42004. if (index >= 0) {
  42005. var mapping = this._originalMappings[index];
  42006. if (aArgs.column === undefined) {
  42007. var originalLine = mapping.originalLine;
  42008. // Iterate until either we run out of mappings, or we run into
  42009. // a mapping for a different line than the one we found. Since
  42010. // mappings are sorted, this is guaranteed to find all mappings for
  42011. // the line we found.
  42012. while (mapping && mapping.originalLine === originalLine) {
  42013. mappings.push({
  42014. line: util.getArg(mapping, 'generatedLine', null),
  42015. column: util.getArg(mapping, 'generatedColumn', null),
  42016. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42017. });
  42018. mapping = this._originalMappings[++index];
  42019. }
  42020. } else {
  42021. var originalColumn = mapping.originalColumn;
  42022. // Iterate until either we run out of mappings, or we run into
  42023. // a mapping for a different line than the one we were searching for.
  42024. // Since mappings are sorted, this is guaranteed to find all mappings for
  42025. // the line we are searching for.
  42026. while (mapping &&
  42027. mapping.originalLine === line &&
  42028. mapping.originalColumn == originalColumn) {
  42029. mappings.push({
  42030. line: util.getArg(mapping, 'generatedLine', null),
  42031. column: util.getArg(mapping, 'generatedColumn', null),
  42032. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42033. });
  42034. mapping = this._originalMappings[++index];
  42035. }
  42036. }
  42037. }
  42038. return mappings;
  42039. };
  42040. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
  42041. /**
  42042. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  42043. * query for information about the original file positions by giving it a file
  42044. * position in the generated source.
  42045. *
  42046. * The first parameter is the raw source map (either as a JSON string, or
  42047. * already parsed to an object). According to the spec, source maps have the
  42048. * following attributes:
  42049. *
  42050. * - version: Which version of the source map spec this map is following.
  42051. * - sources: An array of URLs to the original source files.
  42052. * - names: An array of identifiers which can be referrenced by individual mappings.
  42053. * - sourceRoot: Optional. The URL root from which all sources are relative.
  42054. * - sourcesContent: Optional. An array of contents of the original source files.
  42055. * - mappings: A string of base64 VLQs which contain the actual mappings.
  42056. * - file: Optional. The generated file this source map is associated with.
  42057. *
  42058. * Here is an example source map, taken from the source map spec[0]:
  42059. *
  42060. * {
  42061. * version : 3,
  42062. * file: "out.js",
  42063. * sourceRoot : "",
  42064. * sources: ["foo.js", "bar.js"],
  42065. * names: ["src", "maps", "are", "fun"],
  42066. * mappings: "AA,AB;;ABCDE;"
  42067. * }
  42068. *
  42069. * The second parameter, if given, is a string whose value is the URL
  42070. * at which the source map was found. This URL is used to compute the
  42071. * sources array.
  42072. *
  42073. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  42074. */
  42075. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42076. var sourceMap = aSourceMap;
  42077. if (typeof aSourceMap === 'string') {
  42078. sourceMap = util.parseSourceMapInput(aSourceMap);
  42079. }
  42080. var version = util.getArg(sourceMap, 'version');
  42081. var sources = util.getArg(sourceMap, 'sources');
  42082. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  42083. // requires the array) to play nice here.
  42084. var names = util.getArg(sourceMap, 'names', []);
  42085. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  42086. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  42087. var mappings = util.getArg(sourceMap, 'mappings');
  42088. var file = util.getArg(sourceMap, 'file', null);
  42089. // Once again, Sass deviates from the spec and supplies the version as a
  42090. // string rather than a number, so we use loose equality checking here.
  42091. if (version != this._version) {
  42092. throw new Error('Unsupported version: ' + version);
  42093. }
  42094. if (sourceRoot) {
  42095. sourceRoot = util.normalize(sourceRoot);
  42096. }
  42097. sources = sources
  42098. .map(String)
  42099. // Some source maps produce relative source paths like "./foo.js" instead of
  42100. // "foo.js". Normalize these first so that future comparisons will succeed.
  42101. // See bugzil.la/1090768.
  42102. .map(util.normalize)
  42103. // Always ensure that absolute sources are internally stored relative to
  42104. // the source root, if the source root is absolute. Not doing this would
  42105. // be particularly problematic when the source root is a prefix of the
  42106. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  42107. .map(function (source) {
  42108. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  42109. ? util.relative(sourceRoot, source)
  42110. : source;
  42111. });
  42112. // Pass `true` below to allow duplicate names and sources. While source maps
  42113. // are intended to be compressed and deduplicated, the TypeScript compiler
  42114. // sometimes generates source maps with duplicates in them. See Github issue
  42115. // #72 and bugzil.la/889492.
  42116. this._names = ArraySet.fromArray(names.map(String), true);
  42117. this._sources = ArraySet.fromArray(sources, true);
  42118. this._absoluteSources = this._sources.toArray().map(function (s) {
  42119. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  42120. });
  42121. this.sourceRoot = sourceRoot;
  42122. this.sourcesContent = sourcesContent;
  42123. this._mappings = mappings;
  42124. this._sourceMapURL = aSourceMapURL;
  42125. this.file = file;
  42126. }
  42127. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42128. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  42129. /**
  42130. * Utility function to find the index of a source. Returns -1 if not
  42131. * found.
  42132. */
  42133. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  42134. var relativeSource = aSource;
  42135. if (this.sourceRoot != null) {
  42136. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42137. }
  42138. if (this._sources.has(relativeSource)) {
  42139. return this._sources.indexOf(relativeSource);
  42140. }
  42141. // Maybe aSource is an absolute URL as returned by |sources|. In
  42142. // this case we can't simply undo the transform.
  42143. var i;
  42144. for (i = 0; i < this._absoluteSources.length; ++i) {
  42145. if (this._absoluteSources[i] == aSource) {
  42146. return i;
  42147. }
  42148. }
  42149. return -1;
  42150. };
  42151. /**
  42152. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  42153. *
  42154. * @param SourceMapGenerator aSourceMap
  42155. * The source map that will be consumed.
  42156. * @param String aSourceMapURL
  42157. * The URL at which the source map can be found (optional)
  42158. * @returns BasicSourceMapConsumer
  42159. */
  42160. BasicSourceMapConsumer.fromSourceMap =
  42161. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  42162. var smc = Object.create(BasicSourceMapConsumer.prototype);
  42163. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  42164. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  42165. smc.sourceRoot = aSourceMap._sourceRoot;
  42166. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  42167. smc.sourceRoot);
  42168. smc.file = aSourceMap._file;
  42169. smc._sourceMapURL = aSourceMapURL;
  42170. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  42171. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  42172. });
  42173. // Because we are modifying the entries (by converting string sources and
  42174. // names to indices into the sources and names ArraySets), we have to make
  42175. // a copy of the entry or else bad things happen. Shared mutable state
  42176. // strikes again! See github issue #191.
  42177. var generatedMappings = aSourceMap._mappings.toArray().slice();
  42178. var destGeneratedMappings = smc.__generatedMappings = [];
  42179. var destOriginalMappings = smc.__originalMappings = [];
  42180. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  42181. var srcMapping = generatedMappings[i];
  42182. var destMapping = new Mapping;
  42183. destMapping.generatedLine = srcMapping.generatedLine;
  42184. destMapping.generatedColumn = srcMapping.generatedColumn;
  42185. if (srcMapping.source) {
  42186. destMapping.source = sources.indexOf(srcMapping.source);
  42187. destMapping.originalLine = srcMapping.originalLine;
  42188. destMapping.originalColumn = srcMapping.originalColumn;
  42189. if (srcMapping.name) {
  42190. destMapping.name = names.indexOf(srcMapping.name);
  42191. }
  42192. destOriginalMappings.push(destMapping);
  42193. }
  42194. destGeneratedMappings.push(destMapping);
  42195. }
  42196. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  42197. return smc;
  42198. };
  42199. /**
  42200. * The version of the source mapping spec that we are consuming.
  42201. */
  42202. BasicSourceMapConsumer.prototype._version = 3;
  42203. /**
  42204. * The list of original sources.
  42205. */
  42206. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  42207. get: function () {
  42208. return this._absoluteSources.slice();
  42209. }
  42210. });
  42211. /**
  42212. * Provide the JIT with a nice shape / hidden class.
  42213. */
  42214. function Mapping() {
  42215. this.generatedLine = 0;
  42216. this.generatedColumn = 0;
  42217. this.source = null;
  42218. this.originalLine = null;
  42219. this.originalColumn = null;
  42220. this.name = null;
  42221. }
  42222. /**
  42223. * Parse the mappings in a string in to a data structure which we can easily
  42224. * query (the ordered arrays in the `this.__generatedMappings` and
  42225. * `this.__originalMappings` properties).
  42226. */
  42227. BasicSourceMapConsumer.prototype._parseMappings =
  42228. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42229. var generatedLine = 1;
  42230. var previousGeneratedColumn = 0;
  42231. var previousOriginalLine = 0;
  42232. var previousOriginalColumn = 0;
  42233. var previousSource = 0;
  42234. var previousName = 0;
  42235. var length = aStr.length;
  42236. var index = 0;
  42237. var cachedSegments = {};
  42238. var temp = {};
  42239. var originalMappings = [];
  42240. var generatedMappings = [];
  42241. var mapping, str, segment, end, value;
  42242. while (index < length) {
  42243. if (aStr.charAt(index) === ';') {
  42244. generatedLine++;
  42245. index++;
  42246. previousGeneratedColumn = 0;
  42247. }
  42248. else if (aStr.charAt(index) === ',') {
  42249. index++;
  42250. }
  42251. else {
  42252. mapping = new Mapping();
  42253. mapping.generatedLine = generatedLine;
  42254. // Because each offset is encoded relative to the previous one,
  42255. // many segments often have the same encoding. We can exploit this
  42256. // fact by caching the parsed variable length fields of each segment,
  42257. // allowing us to avoid a second parse if we encounter the same
  42258. // segment again.
  42259. for (end = index; end < length; end++) {
  42260. if (this._charIsMappingSeparator(aStr, end)) {
  42261. break;
  42262. }
  42263. }
  42264. str = aStr.slice(index, end);
  42265. segment = cachedSegments[str];
  42266. if (segment) {
  42267. index += str.length;
  42268. } else {
  42269. segment = [];
  42270. while (index < end) {
  42271. base64VLQ.decode(aStr, index, temp);
  42272. value = temp.value;
  42273. index = temp.rest;
  42274. segment.push(value);
  42275. }
  42276. if (segment.length === 2) {
  42277. throw new Error('Found a source, but no line and column');
  42278. }
  42279. if (segment.length === 3) {
  42280. throw new Error('Found a source and line, but no column');
  42281. }
  42282. cachedSegments[str] = segment;
  42283. }
  42284. // Generated column.
  42285. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  42286. previousGeneratedColumn = mapping.generatedColumn;
  42287. if (segment.length > 1) {
  42288. // Original source.
  42289. mapping.source = previousSource + segment[1];
  42290. previousSource += segment[1];
  42291. // Original line.
  42292. mapping.originalLine = previousOriginalLine + segment[2];
  42293. previousOriginalLine = mapping.originalLine;
  42294. // Lines are stored 0-based
  42295. mapping.originalLine += 1;
  42296. // Original column.
  42297. mapping.originalColumn = previousOriginalColumn + segment[3];
  42298. previousOriginalColumn = mapping.originalColumn;
  42299. if (segment.length > 4) {
  42300. // Original name.
  42301. mapping.name = previousName + segment[4];
  42302. previousName += segment[4];
  42303. }
  42304. }
  42305. generatedMappings.push(mapping);
  42306. if (typeof mapping.originalLine === 'number') {
  42307. originalMappings.push(mapping);
  42308. }
  42309. }
  42310. }
  42311. quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
  42312. this.__generatedMappings = generatedMappings;
  42313. quickSort(originalMappings, util.compareByOriginalPositions);
  42314. this.__originalMappings = originalMappings;
  42315. };
  42316. /**
  42317. * Find the mapping that best matches the hypothetical "needle" mapping that
  42318. * we are searching for in the given "haystack" of mappings.
  42319. */
  42320. BasicSourceMapConsumer.prototype._findMapping =
  42321. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  42322. aColumnName, aComparator, aBias) {
  42323. // To return the position we are searching for, we must first find the
  42324. // mapping for the given position and then return the opposite position it
  42325. // points to. Because the mappings are sorted, we can use binary search to
  42326. // find the best mapping.
  42327. if (aNeedle[aLineName] <= 0) {
  42328. throw new TypeError('Line must be greater than or equal to 1, got '
  42329. + aNeedle[aLineName]);
  42330. }
  42331. if (aNeedle[aColumnName] < 0) {
  42332. throw new TypeError('Column must be greater than or equal to 0, got '
  42333. + aNeedle[aColumnName]);
  42334. }
  42335. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  42336. };
  42337. /**
  42338. * Compute the last column for each generated mapping. The last column is
  42339. * inclusive.
  42340. */
  42341. BasicSourceMapConsumer.prototype.computeColumnSpans =
  42342. function SourceMapConsumer_computeColumnSpans() {
  42343. for (var index = 0; index < this._generatedMappings.length; ++index) {
  42344. var mapping = this._generatedMappings[index];
  42345. // Mappings do not contain a field for the last generated columnt. We
  42346. // can come up with an optimistic estimate, however, by assuming that
  42347. // mappings are contiguous (i.e. given two consecutive mappings, the
  42348. // first mapping ends where the second one starts).
  42349. if (index + 1 < this._generatedMappings.length) {
  42350. var nextMapping = this._generatedMappings[index + 1];
  42351. if (mapping.generatedLine === nextMapping.generatedLine) {
  42352. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  42353. continue;
  42354. }
  42355. }
  42356. // The last mapping for each line spans the entire line.
  42357. mapping.lastGeneratedColumn = Infinity;
  42358. }
  42359. };
  42360. /**
  42361. * Returns the original source, line, and column information for the generated
  42362. * source's line and column positions provided. The only argument is an object
  42363. * with the following properties:
  42364. *
  42365. * - line: The line number in the generated source. The line number
  42366. * is 1-based.
  42367. * - column: The column number in the generated source. The column
  42368. * number is 0-based.
  42369. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42370. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42371. * closest element that is smaller than or greater than the one we are
  42372. * searching for, respectively, if the exact element cannot be found.
  42373. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42374. *
  42375. * and an object is returned with the following properties:
  42376. *
  42377. * - source: The original source file, or null.
  42378. * - line: The line number in the original source, or null. The
  42379. * line number is 1-based.
  42380. * - column: The column number in the original source, or null. The
  42381. * column number is 0-based.
  42382. * - name: The original identifier, or null.
  42383. */
  42384. BasicSourceMapConsumer.prototype.originalPositionFor =
  42385. function SourceMapConsumer_originalPositionFor(aArgs) {
  42386. var needle = {
  42387. generatedLine: util.getArg(aArgs, 'line'),
  42388. generatedColumn: util.getArg(aArgs, 'column')
  42389. };
  42390. var index = this._findMapping(
  42391. needle,
  42392. this._generatedMappings,
  42393. "generatedLine",
  42394. "generatedColumn",
  42395. util.compareByGeneratedPositionsDeflated,
  42396. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42397. );
  42398. if (index >= 0) {
  42399. var mapping = this._generatedMappings[index];
  42400. if (mapping.generatedLine === needle.generatedLine) {
  42401. var source = util.getArg(mapping, 'source', null);
  42402. if (source !== null) {
  42403. source = this._sources.at(source);
  42404. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  42405. }
  42406. var name = util.getArg(mapping, 'name', null);
  42407. if (name !== null) {
  42408. name = this._names.at(name);
  42409. }
  42410. return {
  42411. source: source,
  42412. line: util.getArg(mapping, 'originalLine', null),
  42413. column: util.getArg(mapping, 'originalColumn', null),
  42414. name: name
  42415. };
  42416. }
  42417. }
  42418. return {
  42419. source: null,
  42420. line: null,
  42421. column: null,
  42422. name: null
  42423. };
  42424. };
  42425. /**
  42426. * Return true if we have the source content for every source in the source
  42427. * map, false otherwise.
  42428. */
  42429. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  42430. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  42431. if (!this.sourcesContent) {
  42432. return false;
  42433. }
  42434. return this.sourcesContent.length >= this._sources.size() &&
  42435. !this.sourcesContent.some(function (sc) { return sc == null; });
  42436. };
  42437. /**
  42438. * Returns the original source content. The only argument is the url of the
  42439. * original source file. Returns null if no original source content is
  42440. * available.
  42441. */
  42442. BasicSourceMapConsumer.prototype.sourceContentFor =
  42443. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42444. if (!this.sourcesContent) {
  42445. return null;
  42446. }
  42447. var index = this._findSourceIndex(aSource);
  42448. if (index >= 0) {
  42449. return this.sourcesContent[index];
  42450. }
  42451. var relativeSource = aSource;
  42452. if (this.sourceRoot != null) {
  42453. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42454. }
  42455. var url;
  42456. if (this.sourceRoot != null
  42457. && (url = util.urlParse(this.sourceRoot))) {
  42458. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  42459. // many users. We can help them out when they expect file:// URIs to
  42460. // behave like it would if they were running a local HTTP server. See
  42461. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  42462. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  42463. if (url.scheme == "file"
  42464. && this._sources.has(fileUriAbsPath)) {
  42465. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  42466. }
  42467. if ((!url.path || url.path == "/")
  42468. && this._sources.has("/" + relativeSource)) {
  42469. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  42470. }
  42471. }
  42472. // This function is used recursively from
  42473. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  42474. // don't want to throw if we can't find the source - we just want to
  42475. // return null, so we provide a flag to exit gracefully.
  42476. if (nullOnMissing) {
  42477. return null;
  42478. }
  42479. else {
  42480. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  42481. }
  42482. };
  42483. /**
  42484. * Returns the generated line and column information for the original source,
  42485. * line, and column positions provided. The only argument is an object with
  42486. * the following properties:
  42487. *
  42488. * - source: The filename of the original source.
  42489. * - line: The line number in the original source. The line number
  42490. * is 1-based.
  42491. * - column: The column number in the original source. The column
  42492. * number is 0-based.
  42493. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42494. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42495. * closest element that is smaller than or greater than the one we are
  42496. * searching for, respectively, if the exact element cannot be found.
  42497. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42498. *
  42499. * and an object is returned with the following properties:
  42500. *
  42501. * - line: The line number in the generated source, or null. The
  42502. * line number is 1-based.
  42503. * - column: The column number in the generated source, or null.
  42504. * The column number is 0-based.
  42505. */
  42506. BasicSourceMapConsumer.prototype.generatedPositionFor =
  42507. function SourceMapConsumer_generatedPositionFor(aArgs) {
  42508. var source = util.getArg(aArgs, 'source');
  42509. source = this._findSourceIndex(source);
  42510. if (source < 0) {
  42511. return {
  42512. line: null,
  42513. column: null,
  42514. lastColumn: null
  42515. };
  42516. }
  42517. var needle = {
  42518. source: source,
  42519. originalLine: util.getArg(aArgs, 'line'),
  42520. originalColumn: util.getArg(aArgs, 'column')
  42521. };
  42522. var index = this._findMapping(
  42523. needle,
  42524. this._originalMappings,
  42525. "originalLine",
  42526. "originalColumn",
  42527. util.compareByOriginalPositions,
  42528. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42529. );
  42530. if (index >= 0) {
  42531. var mapping = this._originalMappings[index];
  42532. if (mapping.source === needle.source) {
  42533. return {
  42534. line: util.getArg(mapping, 'generatedLine', null),
  42535. column: util.getArg(mapping, 'generatedColumn', null),
  42536. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42537. };
  42538. }
  42539. }
  42540. return {
  42541. line: null,
  42542. column: null,
  42543. lastColumn: null
  42544. };
  42545. };
  42546. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  42547. /**
  42548. * An IndexedSourceMapConsumer instance represents a parsed source map which
  42549. * we can query for information. It differs from BasicSourceMapConsumer in
  42550. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  42551. * input.
  42552. *
  42553. * The first parameter is a raw source map (either as a JSON string, or already
  42554. * parsed to an object). According to the spec for indexed source maps, they
  42555. * have the following attributes:
  42556. *
  42557. * - version: Which version of the source map spec this map is following.
  42558. * - file: Optional. The generated file this source map is associated with.
  42559. * - sections: A list of section definitions.
  42560. *
  42561. * Each value under the "sections" field has two fields:
  42562. * - offset: The offset into the original specified at which this section
  42563. * begins to apply, defined as an object with a "line" and "column"
  42564. * field.
  42565. * - map: A source map definition. This source map could also be indexed,
  42566. * but doesn't have to be.
  42567. *
  42568. * Instead of the "map" field, it's also possible to have a "url" field
  42569. * specifying a URL to retrieve a source map from, but that's currently
  42570. * unsupported.
  42571. *
  42572. * Here's an example source map, taken from the source map spec[0], but
  42573. * modified to omit a section which uses the "url" field.
  42574. *
  42575. * {
  42576. * version : 3,
  42577. * file: "app.js",
  42578. * sections: [{
  42579. * offset: {line:100, column:10},
  42580. * map: {
  42581. * version : 3,
  42582. * file: "section.js",
  42583. * sources: ["foo.js", "bar.js"],
  42584. * names: ["src", "maps", "are", "fun"],
  42585. * mappings: "AAAA,E;;ABCDE;"
  42586. * }
  42587. * }],
  42588. * }
  42589. *
  42590. * The second parameter, if given, is a string whose value is the URL
  42591. * at which the source map was found. This URL is used to compute the
  42592. * sources array.
  42593. *
  42594. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  42595. */
  42596. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42597. var sourceMap = aSourceMap;
  42598. if (typeof aSourceMap === 'string') {
  42599. sourceMap = util.parseSourceMapInput(aSourceMap);
  42600. }
  42601. var version = util.getArg(sourceMap, 'version');
  42602. var sections = util.getArg(sourceMap, 'sections');
  42603. if (version != this._version) {
  42604. throw new Error('Unsupported version: ' + version);
  42605. }
  42606. this._sources = new ArraySet();
  42607. this._names = new ArraySet();
  42608. var lastOffset = {
  42609. line: -1,
  42610. column: 0
  42611. };
  42612. this._sections = sections.map(function (s) {
  42613. if (s.url) {
  42614. // The url field will require support for asynchronicity.
  42615. // See https://github.com/mozilla/source-map/issues/16
  42616. throw new Error('Support for url field in sections not implemented.');
  42617. }
  42618. var offset = util.getArg(s, 'offset');
  42619. var offsetLine = util.getArg(offset, 'line');
  42620. var offsetColumn = util.getArg(offset, 'column');
  42621. if (offsetLine < lastOffset.line ||
  42622. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  42623. throw new Error('Section offsets must be ordered and non-overlapping.');
  42624. }
  42625. lastOffset = offset;
  42626. return {
  42627. generatedOffset: {
  42628. // The offset fields are 0-based, but we use 1-based indices when
  42629. // encoding/decoding from VLQ.
  42630. generatedLine: offsetLine + 1,
  42631. generatedColumn: offsetColumn + 1
  42632. },
  42633. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  42634. }
  42635. });
  42636. }
  42637. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42638. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  42639. /**
  42640. * The version of the source mapping spec that we are consuming.
  42641. */
  42642. IndexedSourceMapConsumer.prototype._version = 3;
  42643. /**
  42644. * The list of original sources.
  42645. */
  42646. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  42647. get: function () {
  42648. var sources = [];
  42649. for (var i = 0; i < this._sections.length; i++) {
  42650. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  42651. sources.push(this._sections[i].consumer.sources[j]);
  42652. }
  42653. }
  42654. return sources;
  42655. }
  42656. });
  42657. /**
  42658. * Returns the original source, line, and column information for the generated
  42659. * source's line and column positions provided. The only argument is an object
  42660. * with the following properties:
  42661. *
  42662. * - line: The line number in the generated source. The line number
  42663. * is 1-based.
  42664. * - column: The column number in the generated source. The column
  42665. * number is 0-based.
  42666. *
  42667. * and an object is returned with the following properties:
  42668. *
  42669. * - source: The original source file, or null.
  42670. * - line: The line number in the original source, or null. The
  42671. * line number is 1-based.
  42672. * - column: The column number in the original source, or null. The
  42673. * column number is 0-based.
  42674. * - name: The original identifier, or null.
  42675. */
  42676. IndexedSourceMapConsumer.prototype.originalPositionFor =
  42677. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  42678. var needle = {
  42679. generatedLine: util.getArg(aArgs, 'line'),
  42680. generatedColumn: util.getArg(aArgs, 'column')
  42681. };
  42682. // Find the section containing the generated position we're trying to map
  42683. // to an original position.
  42684. var sectionIndex = binarySearch.search(needle, this._sections,
  42685. function(needle, section) {
  42686. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  42687. if (cmp) {
  42688. return cmp;
  42689. }
  42690. return (needle.generatedColumn -
  42691. section.generatedOffset.generatedColumn);
  42692. });
  42693. var section = this._sections[sectionIndex];
  42694. if (!section) {
  42695. return {
  42696. source: null,
  42697. line: null,
  42698. column: null,
  42699. name: null
  42700. };
  42701. }
  42702. return section.consumer.originalPositionFor({
  42703. line: needle.generatedLine -
  42704. (section.generatedOffset.generatedLine - 1),
  42705. column: needle.generatedColumn -
  42706. (section.generatedOffset.generatedLine === needle.generatedLine
  42707. ? section.generatedOffset.generatedColumn - 1
  42708. : 0),
  42709. bias: aArgs.bias
  42710. });
  42711. };
  42712. /**
  42713. * Return true if we have the source content for every source in the source
  42714. * map, false otherwise.
  42715. */
  42716. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  42717. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  42718. return this._sections.every(function (s) {
  42719. return s.consumer.hasContentsOfAllSources();
  42720. });
  42721. };
  42722. /**
  42723. * Returns the original source content. The only argument is the url of the
  42724. * original source file. Returns null if no original source content is
  42725. * available.
  42726. */
  42727. IndexedSourceMapConsumer.prototype.sourceContentFor =
  42728. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42729. for (var i = 0; i < this._sections.length; i++) {
  42730. var section = this._sections[i];
  42731. var content = section.consumer.sourceContentFor(aSource, true);
  42732. if (content) {
  42733. return content;
  42734. }
  42735. }
  42736. if (nullOnMissing) {
  42737. return null;
  42738. }
  42739. else {
  42740. throw new Error('"' + aSource + '" is not in the SourceMap.');
  42741. }
  42742. };
  42743. /**
  42744. * Returns the generated line and column information for the original source,
  42745. * line, and column positions provided. The only argument is an object with
  42746. * the following properties:
  42747. *
  42748. * - source: The filename of the original source.
  42749. * - line: The line number in the original source. The line number
  42750. * is 1-based.
  42751. * - column: The column number in the original source. The column
  42752. * number is 0-based.
  42753. *
  42754. * and an object is returned with the following properties:
  42755. *
  42756. * - line: The line number in the generated source, or null. The
  42757. * line number is 1-based.
  42758. * - column: The column number in the generated source, or null.
  42759. * The column number is 0-based.
  42760. */
  42761. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  42762. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  42763. for (var i = 0; i < this._sections.length; i++) {
  42764. var section = this._sections[i];
  42765. // Only consider this section if the requested source is in the list of
  42766. // sources of the consumer.
  42767. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  42768. continue;
  42769. }
  42770. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  42771. if (generatedPosition) {
  42772. var ret = {
  42773. line: generatedPosition.line +
  42774. (section.generatedOffset.generatedLine - 1),
  42775. column: generatedPosition.column +
  42776. (section.generatedOffset.generatedLine === generatedPosition.line
  42777. ? section.generatedOffset.generatedColumn - 1
  42778. : 0)
  42779. };
  42780. return ret;
  42781. }
  42782. }
  42783. return {
  42784. line: null,
  42785. column: null
  42786. };
  42787. };
  42788. /**
  42789. * Parse the mappings in a string in to a data structure which we can easily
  42790. * query (the ordered arrays in the `this.__generatedMappings` and
  42791. * `this.__originalMappings` properties).
  42792. */
  42793. IndexedSourceMapConsumer.prototype._parseMappings =
  42794. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42795. this.__generatedMappings = [];
  42796. this.__originalMappings = [];
  42797. for (var i = 0; i < this._sections.length; i++) {
  42798. var section = this._sections[i];
  42799. var sectionMappings = section.consumer._generatedMappings;
  42800. for (var j = 0; j < sectionMappings.length; j++) {
  42801. var mapping = sectionMappings[j];
  42802. var source = section.consumer._sources.at(mapping.source);
  42803. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42804. this._sources.add(source);
  42805. source = this._sources.indexOf(source);
  42806. var name = null;
  42807. if (mapping.name) {
  42808. name = section.consumer._names.at(mapping.name);
  42809. this._names.add(name);
  42810. name = this._names.indexOf(name);
  42811. }
  42812. // The mappings coming from the consumer for the section have
  42813. // generated positions relative to the start of the section, so we
  42814. // need to offset them to be relative to the start of the concatenated
  42815. // generated file.
  42816. var adjustedMapping = {
  42817. source: source,
  42818. generatedLine: mapping.generatedLine +
  42819. (section.generatedOffset.generatedLine - 1),
  42820. generatedColumn: mapping.generatedColumn +
  42821. (section.generatedOffset.generatedLine === mapping.generatedLine
  42822. ? section.generatedOffset.generatedColumn - 1
  42823. : 0),
  42824. originalLine: mapping.originalLine,
  42825. originalColumn: mapping.originalColumn,
  42826. name: name
  42827. };
  42828. this.__generatedMappings.push(adjustedMapping);
  42829. if (typeof adjustedMapping.originalLine === 'number') {
  42830. this.__originalMappings.push(adjustedMapping);
  42831. }
  42832. }
  42833. }
  42834. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  42835. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  42836. };
  42837. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42838. return sourceMapConsumer;
  42839. }
  42840. var sourceNode = {};
  42841. /* -*- Mode: js; js-indent-level: 2; -*- */
  42842. var hasRequiredSourceNode;
  42843. function requireSourceNode () {
  42844. if (hasRequiredSourceNode) return sourceNode;
  42845. hasRequiredSourceNode = 1;
  42846. /*
  42847. * Copyright 2011 Mozilla Foundation and contributors
  42848. * Licensed under the New BSD license. See LICENSE or:
  42849. * http://opensource.org/licenses/BSD-3-Clause
  42850. */
  42851. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  42852. var util = /*@__PURE__*/ requireUtil();
  42853. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42854. // operating systems these days (capturing the result).
  42855. var REGEX_NEWLINE = /(\r?\n)/;
  42856. // Newline character code for charCodeAt() comparisons
  42857. var NEWLINE_CODE = 10;
  42858. // Private symbol for identifying `SourceNode`s when multiple versions of
  42859. // the source-map library are loaded. This MUST NOT CHANGE across
  42860. // versions!
  42861. var isSourceNode = "$$$isSourceNode$$$";
  42862. /**
  42863. * SourceNodes provide a way to abstract over interpolating/concatenating
  42864. * snippets of generated JavaScript source code while maintaining the line and
  42865. * column information associated with the original source code.
  42866. *
  42867. * @param aLine The original line number.
  42868. * @param aColumn The original column number.
  42869. * @param aSource The original source's filename.
  42870. * @param aChunks Optional. An array of strings which are snippets of
  42871. * generated JS, or other SourceNodes.
  42872. * @param aName The original identifier.
  42873. */
  42874. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42875. this.children = [];
  42876. this.sourceContents = {};
  42877. this.line = aLine == null ? null : aLine;
  42878. this.column = aColumn == null ? null : aColumn;
  42879. this.source = aSource == null ? null : aSource;
  42880. this.name = aName == null ? null : aName;
  42881. this[isSourceNode] = true;
  42882. if (aChunks != null) this.add(aChunks);
  42883. }
  42884. /**
  42885. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42886. *
  42887. * @param aGeneratedCode The generated code
  42888. * @param aSourceMapConsumer The SourceMap for the generated code
  42889. * @param aRelativePath Optional. The path that relative sources in the
  42890. * SourceMapConsumer should be relative to.
  42891. */
  42892. SourceNode.fromStringWithSourceMap =
  42893. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42894. // The SourceNode we want to fill with the generated code
  42895. // and the SourceMap
  42896. var node = new SourceNode();
  42897. // All even indices of this array are one line of the generated code,
  42898. // while all odd indices are the newlines between two adjacent lines
  42899. // (since `REGEX_NEWLINE` captures its match).
  42900. // Processed fragments are accessed by calling `shiftNextLine`.
  42901. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  42902. var remainingLinesIndex = 0;
  42903. var shiftNextLine = function() {
  42904. var lineContents = getNextLine();
  42905. // The last line of a file might not have a newline.
  42906. var newLine = getNextLine() || "";
  42907. return lineContents + newLine;
  42908. function getNextLine() {
  42909. return remainingLinesIndex < remainingLines.length ?
  42910. remainingLines[remainingLinesIndex++] : undefined;
  42911. }
  42912. };
  42913. // We need to remember the position of "remainingLines"
  42914. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  42915. // The generate SourceNodes we need a code range.
  42916. // To extract it current and last mapping is used.
  42917. // Here we store the last mapping.
  42918. var lastMapping = null;
  42919. aSourceMapConsumer.eachMapping(function (mapping) {
  42920. if (lastMapping !== null) {
  42921. // We add the code from "lastMapping" to "mapping":
  42922. // First check if there is a new line in between.
  42923. if (lastGeneratedLine < mapping.generatedLine) {
  42924. // Associate first line with "lastMapping"
  42925. addMappingWithCode(lastMapping, shiftNextLine());
  42926. lastGeneratedLine++;
  42927. lastGeneratedColumn = 0;
  42928. // The remaining code is added without mapping
  42929. } else {
  42930. // There is no new line in between.
  42931. // Associate the code between "lastGeneratedColumn" and
  42932. // "mapping.generatedColumn" with "lastMapping"
  42933. var nextLine = remainingLines[remainingLinesIndex] || '';
  42934. var code = nextLine.substr(0, mapping.generatedColumn -
  42935. lastGeneratedColumn);
  42936. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  42937. lastGeneratedColumn);
  42938. lastGeneratedColumn = mapping.generatedColumn;
  42939. addMappingWithCode(lastMapping, code);
  42940. // No more remaining code, continue
  42941. lastMapping = mapping;
  42942. return;
  42943. }
  42944. }
  42945. // We add the generated code until the first mapping
  42946. // to the SourceNode without any mapping.
  42947. // Each line is added as separate string.
  42948. while (lastGeneratedLine < mapping.generatedLine) {
  42949. node.add(shiftNextLine());
  42950. lastGeneratedLine++;
  42951. }
  42952. if (lastGeneratedColumn < mapping.generatedColumn) {
  42953. var nextLine = remainingLines[remainingLinesIndex] || '';
  42954. node.add(nextLine.substr(0, mapping.generatedColumn));
  42955. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  42956. lastGeneratedColumn = mapping.generatedColumn;
  42957. }
  42958. lastMapping = mapping;
  42959. }, this);
  42960. // We have processed all mappings.
  42961. if (remainingLinesIndex < remainingLines.length) {
  42962. if (lastMapping) {
  42963. // Associate the remaining code in the current line with "lastMapping"
  42964. addMappingWithCode(lastMapping, shiftNextLine());
  42965. }
  42966. // and add the remaining lines without any mapping
  42967. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  42968. }
  42969. // Copy sourcesContent into SourceNode
  42970. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  42971. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  42972. if (content != null) {
  42973. if (aRelativePath != null) {
  42974. sourceFile = util.join(aRelativePath, sourceFile);
  42975. }
  42976. node.setSourceContent(sourceFile, content);
  42977. }
  42978. });
  42979. return node;
  42980. function addMappingWithCode(mapping, code) {
  42981. if (mapping === null || mapping.source === undefined) {
  42982. node.add(code);
  42983. } else {
  42984. var source = aRelativePath
  42985. ? util.join(aRelativePath, mapping.source)
  42986. : mapping.source;
  42987. node.add(new SourceNode(mapping.originalLine,
  42988. mapping.originalColumn,
  42989. source,
  42990. code,
  42991. mapping.name));
  42992. }
  42993. }
  42994. };
  42995. /**
  42996. * Add a chunk of generated JS to this source node.
  42997. *
  42998. * @param aChunk A string snippet of generated JS code, another instance of
  42999. * SourceNode, or an array where each member is one of those things.
  43000. */
  43001. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  43002. if (Array.isArray(aChunk)) {
  43003. aChunk.forEach(function (chunk) {
  43004. this.add(chunk);
  43005. }, this);
  43006. }
  43007. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43008. if (aChunk) {
  43009. this.children.push(aChunk);
  43010. }
  43011. }
  43012. else {
  43013. throw new TypeError(
  43014. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43015. );
  43016. }
  43017. return this;
  43018. };
  43019. /**
  43020. * Add a chunk of generated JS to the beginning of this source node.
  43021. *
  43022. * @param aChunk A string snippet of generated JS code, another instance of
  43023. * SourceNode, or an array where each member is one of those things.
  43024. */
  43025. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  43026. if (Array.isArray(aChunk)) {
  43027. for (var i = aChunk.length-1; i >= 0; i--) {
  43028. this.prepend(aChunk[i]);
  43029. }
  43030. }
  43031. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43032. this.children.unshift(aChunk);
  43033. }
  43034. else {
  43035. throw new TypeError(
  43036. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43037. );
  43038. }
  43039. return this;
  43040. };
  43041. /**
  43042. * Walk over the tree of JS snippets in this node and its children. The
  43043. * walking function is called once for each snippet of JS and is passed that
  43044. * snippet and the its original associated source's line/column location.
  43045. *
  43046. * @param aFn The traversal function.
  43047. */
  43048. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  43049. var chunk;
  43050. for (var i = 0, len = this.children.length; i < len; i++) {
  43051. chunk = this.children[i];
  43052. if (chunk[isSourceNode]) {
  43053. chunk.walk(aFn);
  43054. }
  43055. else {
  43056. if (chunk !== '') {
  43057. aFn(chunk, { source: this.source,
  43058. line: this.line,
  43059. column: this.column,
  43060. name: this.name });
  43061. }
  43062. }
  43063. }
  43064. };
  43065. /**
  43066. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  43067. * each of `this.children`.
  43068. *
  43069. * @param aSep The separator.
  43070. */
  43071. SourceNode.prototype.join = function SourceNode_join(aSep) {
  43072. var newChildren;
  43073. var i;
  43074. var len = this.children.length;
  43075. if (len > 0) {
  43076. newChildren = [];
  43077. for (i = 0; i < len-1; i++) {
  43078. newChildren.push(this.children[i]);
  43079. newChildren.push(aSep);
  43080. }
  43081. newChildren.push(this.children[i]);
  43082. this.children = newChildren;
  43083. }
  43084. return this;
  43085. };
  43086. /**
  43087. * Call String.prototype.replace on the very right-most source snippet. Useful
  43088. * for trimming whitespace from the end of a source node, etc.
  43089. *
  43090. * @param aPattern The pattern to replace.
  43091. * @param aReplacement The thing to replace the pattern with.
  43092. */
  43093. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  43094. var lastChild = this.children[this.children.length - 1];
  43095. if (lastChild[isSourceNode]) {
  43096. lastChild.replaceRight(aPattern, aReplacement);
  43097. }
  43098. else if (typeof lastChild === 'string') {
  43099. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  43100. }
  43101. else {
  43102. this.children.push(''.replace(aPattern, aReplacement));
  43103. }
  43104. return this;
  43105. };
  43106. /**
  43107. * Set the source content for a source file. This will be added to the SourceMapGenerator
  43108. * in the sourcesContent field.
  43109. *
  43110. * @param aSourceFile The filename of the source file
  43111. * @param aSourceContent The content of the source file
  43112. */
  43113. SourceNode.prototype.setSourceContent =
  43114. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  43115. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  43116. };
  43117. /**
  43118. * Walk over the tree of SourceNodes. The walking function is called for each
  43119. * source file content and is passed the filename and source content.
  43120. *
  43121. * @param aFn The traversal function.
  43122. */
  43123. SourceNode.prototype.walkSourceContents =
  43124. function SourceNode_walkSourceContents(aFn) {
  43125. for (var i = 0, len = this.children.length; i < len; i++) {
  43126. if (this.children[i][isSourceNode]) {
  43127. this.children[i].walkSourceContents(aFn);
  43128. }
  43129. }
  43130. var sources = Object.keys(this.sourceContents);
  43131. for (var i = 0, len = sources.length; i < len; i++) {
  43132. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  43133. }
  43134. };
  43135. /**
  43136. * Return the string representation of this source node. Walks over the tree
  43137. * and concatenates all the various snippets together to one string.
  43138. */
  43139. SourceNode.prototype.toString = function SourceNode_toString() {
  43140. var str = "";
  43141. this.walk(function (chunk) {
  43142. str += chunk;
  43143. });
  43144. return str;
  43145. };
  43146. /**
  43147. * Returns the string representation of this source node along with a source
  43148. * map.
  43149. */
  43150. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  43151. var generated = {
  43152. code: "",
  43153. line: 1,
  43154. column: 0
  43155. };
  43156. var map = new SourceMapGenerator(aArgs);
  43157. var sourceMappingActive = false;
  43158. var lastOriginalSource = null;
  43159. var lastOriginalLine = null;
  43160. var lastOriginalColumn = null;
  43161. var lastOriginalName = null;
  43162. this.walk(function (chunk, original) {
  43163. generated.code += chunk;
  43164. if (original.source !== null
  43165. && original.line !== null
  43166. && original.column !== null) {
  43167. if(lastOriginalSource !== original.source
  43168. || lastOriginalLine !== original.line
  43169. || lastOriginalColumn !== original.column
  43170. || lastOriginalName !== original.name) {
  43171. map.addMapping({
  43172. source: original.source,
  43173. original: {
  43174. line: original.line,
  43175. column: original.column
  43176. },
  43177. generated: {
  43178. line: generated.line,
  43179. column: generated.column
  43180. },
  43181. name: original.name
  43182. });
  43183. }
  43184. lastOriginalSource = original.source;
  43185. lastOriginalLine = original.line;
  43186. lastOriginalColumn = original.column;
  43187. lastOriginalName = original.name;
  43188. sourceMappingActive = true;
  43189. } else if (sourceMappingActive) {
  43190. map.addMapping({
  43191. generated: {
  43192. line: generated.line,
  43193. column: generated.column
  43194. }
  43195. });
  43196. lastOriginalSource = null;
  43197. sourceMappingActive = false;
  43198. }
  43199. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  43200. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  43201. generated.line++;
  43202. generated.column = 0;
  43203. // Mappings end at eol
  43204. if (idx + 1 === length) {
  43205. lastOriginalSource = null;
  43206. sourceMappingActive = false;
  43207. } else if (sourceMappingActive) {
  43208. map.addMapping({
  43209. source: original.source,
  43210. original: {
  43211. line: original.line,
  43212. column: original.column
  43213. },
  43214. generated: {
  43215. line: generated.line,
  43216. column: generated.column
  43217. },
  43218. name: original.name
  43219. });
  43220. }
  43221. } else {
  43222. generated.column++;
  43223. }
  43224. }
  43225. });
  43226. this.walkSourceContents(function (sourceFile, sourceContent) {
  43227. map.setSourceContent(sourceFile, sourceContent);
  43228. });
  43229. return { code: generated.code, map: map };
  43230. };
  43231. sourceNode.SourceNode = SourceNode;
  43232. return sourceNode;
  43233. }
  43234. /*
  43235. * Copyright 2009-2011 Mozilla Foundation and contributors
  43236. * Licensed under the New BSD license. See LICENSE.txt or:
  43237. * http://opensource.org/licenses/BSD-3-Clause
  43238. */
  43239. var hasRequiredSourceMap;
  43240. function requireSourceMap () {
  43241. if (hasRequiredSourceMap) return sourceMap;
  43242. hasRequiredSourceMap = 1;
  43243. sourceMap.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  43244. sourceMap.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer().SourceMapConsumer;
  43245. sourceMap.SourceNode = /*@__PURE__*/ requireSourceNode().SourceNode;
  43246. return sourceMap;
  43247. }
  43248. var mergeSourceMap;
  43249. var hasRequiredMergeSourceMap;
  43250. function requireMergeSourceMap () {
  43251. if (hasRequiredMergeSourceMap) return mergeSourceMap;
  43252. hasRequiredMergeSourceMap = 1;
  43253. var sourceMap = /*@__PURE__*/ requireSourceMap();
  43254. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  43255. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  43256. mergeSourceMap = merge;
  43257. /**
  43258. * Merge old source map and new source map and return merged.
  43259. * If old or new source map value is falsy, return another one as it is.
  43260. *
  43261. * @param {object|string} [oldMap] old source map object
  43262. * @param {object|string} [newmap] new source map object
  43263. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  43264. */
  43265. function merge(oldMap, newMap) {
  43266. if (!oldMap) return newMap
  43267. if (!newMap) return oldMap
  43268. var oldMapConsumer = new SourceMapConsumer(oldMap);
  43269. var newMapConsumer = new SourceMapConsumer(newMap);
  43270. var mergedMapGenerator = new SourceMapGenerator();
  43271. // iterate on new map and overwrite original position of new map with one of old map
  43272. newMapConsumer.eachMapping(function(m) {
  43273. // pass when `originalLine` is null.
  43274. // It occurs in case that the node does not have origin in original code.
  43275. if (m.originalLine == null) return
  43276. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  43277. line: m.originalLine,
  43278. column: m.originalColumn
  43279. });
  43280. if (origPosInOldMap.source == null) return
  43281. mergedMapGenerator.addMapping({
  43282. original: {
  43283. line: origPosInOldMap.line,
  43284. column: origPosInOldMap.column
  43285. },
  43286. generated: {
  43287. line: m.generatedLine,
  43288. column: m.generatedColumn
  43289. },
  43290. source: origPosInOldMap.source,
  43291. name: origPosInOldMap.name
  43292. });
  43293. });
  43294. var consumers = [oldMapConsumer, newMapConsumer];
  43295. consumers.forEach(function(consumer) {
  43296. consumer.sources.forEach(function(sourceFile) {
  43297. mergedMapGenerator._sources.add(sourceFile);
  43298. var sourceContent = consumer.sourceContentFor(sourceFile);
  43299. if (sourceContent != null) {
  43300. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  43301. }
  43302. });
  43303. });
  43304. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  43305. mergedMapGenerator._file = oldMap.file;
  43306. return JSON.parse(mergedMapGenerator.toString())
  43307. }
  43308. return mergeSourceMap;
  43309. }
  43310. var mergeSourceMapExports = /*@__PURE__*/ requireMergeSourceMap();
  43311. var merge = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMapExports);
  43312. var __defProp$5 = Object.defineProperty;
  43313. var __defProps$4 = Object.defineProperties;
  43314. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  43315. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  43316. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  43317. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  43318. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43319. var __spreadValues$5 = (a, b) => {
  43320. for (var prop in b || (b = {}))
  43321. if (__hasOwnProp$5.call(b, prop))
  43322. __defNormalProp$5(a, prop, b[prop]);
  43323. if (__getOwnPropSymbols$5)
  43324. for (var prop of __getOwnPropSymbols$5(b)) {
  43325. if (__propIsEnum$5.call(b, prop))
  43326. __defNormalProp$5(a, prop, b[prop]);
  43327. }
  43328. return a;
  43329. };
  43330. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  43331. const scss = (source, map, options, load = require) => {
  43332. const nodeSass = load("sass");
  43333. const { compileString, renderSync } = nodeSass;
  43334. const data = getSource(source, options.filename, options.additionalData);
  43335. let css;
  43336. let dependencies;
  43337. let sourceMap;
  43338. try {
  43339. if (compileString) {
  43340. const { pathToFileURL, fileURLToPath } = load("url");
  43341. const result = compileString(data, __spreadProps$4(__spreadValues$5({}, options), {
  43342. url: pathToFileURL(options.filename),
  43343. sourceMap: !!map
  43344. }));
  43345. css = result.css;
  43346. dependencies = result.loadedUrls.map((url) => fileURLToPath(url));
  43347. sourceMap = map ? result.sourceMap : void 0;
  43348. } else {
  43349. const result = renderSync(__spreadProps$4(__spreadValues$5({}, options), {
  43350. data,
  43351. file: options.filename,
  43352. outFile: options.filename,
  43353. sourceMap: !!map
  43354. }));
  43355. css = result.css.toString();
  43356. dependencies = result.stats.includedFiles;
  43357. sourceMap = map ? JSON.parse(result.map.toString()) : void 0;
  43358. }
  43359. if (map) {
  43360. return {
  43361. code: css,
  43362. errors: [],
  43363. dependencies,
  43364. map: merge(map, sourceMap)
  43365. };
  43366. }
  43367. return { code: css, errors: [], dependencies };
  43368. } catch (e) {
  43369. return { code: "", errors: [e], dependencies: [] };
  43370. }
  43371. };
  43372. const sass = (source, map, options, load) => scss(
  43373. source,
  43374. map,
  43375. __spreadProps$4(__spreadValues$5({}, options), {
  43376. indentedSyntax: true
  43377. }),
  43378. load
  43379. );
  43380. const less = (source, map, options, load = require) => {
  43381. const nodeLess = load("less");
  43382. let result;
  43383. let error = null;
  43384. nodeLess.render(
  43385. getSource(source, options.filename, options.additionalData),
  43386. __spreadProps$4(__spreadValues$5({}, options), { syncImport: true }),
  43387. (err, output) => {
  43388. error = err;
  43389. result = output;
  43390. }
  43391. );
  43392. if (error) return { code: "", errors: [error], dependencies: [] };
  43393. const dependencies = result.imports;
  43394. if (map) {
  43395. return {
  43396. code: result.css.toString(),
  43397. map: merge(map, result.map),
  43398. errors: [],
  43399. dependencies
  43400. };
  43401. }
  43402. return {
  43403. code: result.css.toString(),
  43404. errors: [],
  43405. dependencies
  43406. };
  43407. };
  43408. const styl = (source, map, options, load = require) => {
  43409. const nodeStylus = load("stylus");
  43410. try {
  43411. const ref = nodeStylus(source, options);
  43412. if (map) ref.set("sourcemap", { inline: false, comment: false });
  43413. const result = ref.render();
  43414. const dependencies = ref.deps();
  43415. if (map) {
  43416. return {
  43417. code: result,
  43418. map: merge(map, ref.sourcemap),
  43419. errors: [],
  43420. dependencies
  43421. };
  43422. }
  43423. return { code: result, errors: [], dependencies };
  43424. } catch (e) {
  43425. return { code: "", errors: [e], dependencies: [] };
  43426. }
  43427. };
  43428. function getSource(source, filename, additionalData) {
  43429. if (!additionalData) return source;
  43430. if (isFunction$1(additionalData)) {
  43431. return additionalData(source, filename);
  43432. }
  43433. return additionalData + source;
  43434. }
  43435. const processors = {
  43436. less,
  43437. sass,
  43438. scss,
  43439. styl,
  43440. stylus: styl
  43441. };
  43442. var __defProp$4 = Object.defineProperty;
  43443. var __defProps$3 = Object.defineProperties;
  43444. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43445. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  43446. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  43447. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  43448. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43449. var __spreadValues$4 = (a, b) => {
  43450. for (var prop in b || (b = {}))
  43451. if (__hasOwnProp$4.call(b, prop))
  43452. __defNormalProp$4(a, prop, b[prop]);
  43453. if (__getOwnPropSymbols$4)
  43454. for (var prop of __getOwnPropSymbols$4(b)) {
  43455. if (__propIsEnum$4.call(b, prop))
  43456. __defNormalProp$4(a, prop, b[prop]);
  43457. }
  43458. return a;
  43459. };
  43460. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43461. function compileStyle(options) {
  43462. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43463. isAsync: false
  43464. }));
  43465. }
  43466. function compileStyleAsync(options) {
  43467. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43468. isAsync: true
  43469. }));
  43470. }
  43471. function doCompileStyle(options) {
  43472. const {
  43473. filename,
  43474. id,
  43475. scoped = false,
  43476. trim = true,
  43477. isProd = false,
  43478. modules = false,
  43479. modulesOptions = {},
  43480. preprocessLang,
  43481. postcssOptions,
  43482. postcssPlugins
  43483. } = options;
  43484. const preprocessor = preprocessLang && processors[preprocessLang];
  43485. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  43486. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  43487. const source = preProcessedSource ? preProcessedSource.code : options.source;
  43488. const shortId = id.replace(/^data-v-/, "");
  43489. const longId = `data-v-${shortId}`;
  43490. const plugins = (postcssPlugins || []).slice();
  43491. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  43492. if (trim) {
  43493. plugins.push(trimPlugin());
  43494. }
  43495. if (scoped) {
  43496. plugins.push(scopedPlugin(longId));
  43497. }
  43498. let cssModules;
  43499. if (modules) {
  43500. {
  43501. throw new Error(
  43502. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  43503. );
  43504. }
  43505. }
  43506. const postCSSOptions = __spreadProps$3(__spreadValues$4({}, postcssOptions), {
  43507. to: filename,
  43508. from: filename
  43509. });
  43510. if (map) {
  43511. postCSSOptions.map = {
  43512. inline: false,
  43513. annotation: false,
  43514. prev: map
  43515. };
  43516. }
  43517. let result;
  43518. let code;
  43519. let outMap;
  43520. const dependencies = new Set(
  43521. preProcessedSource ? preProcessedSource.dependencies : []
  43522. );
  43523. dependencies.delete(filename);
  43524. const errors = [];
  43525. if (preProcessedSource && preProcessedSource.errors.length) {
  43526. errors.push(...preProcessedSource.errors);
  43527. }
  43528. const recordPlainCssDependencies = (messages) => {
  43529. messages.forEach((msg) => {
  43530. if (msg.type === "dependency") {
  43531. dependencies.add(msg.file);
  43532. }
  43533. });
  43534. return dependencies;
  43535. };
  43536. try {
  43537. result = postcss(plugins).process(source, postCSSOptions);
  43538. if (options.isAsync) {
  43539. return result.then((result2) => ({
  43540. code: result2.css || "",
  43541. map: result2.map && result2.map.toJSON(),
  43542. errors,
  43543. modules: cssModules,
  43544. rawResult: result2,
  43545. dependencies: recordPlainCssDependencies(result2.messages)
  43546. })).catch((error) => ({
  43547. code: "",
  43548. map: void 0,
  43549. errors: [...errors, error],
  43550. rawResult: void 0,
  43551. dependencies
  43552. }));
  43553. }
  43554. recordPlainCssDependencies(result.messages);
  43555. code = result.css;
  43556. outMap = result.map;
  43557. } catch (e) {
  43558. errors.push(e);
  43559. }
  43560. return {
  43561. code: code || ``,
  43562. map: outMap && outMap.toJSON(),
  43563. errors,
  43564. rawResult: result,
  43565. dependencies
  43566. };
  43567. }
  43568. function preprocess(options, preprocessor) {
  43569. if (!options.preprocessCustomRequire) {
  43570. throw new Error(
  43571. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  43572. );
  43573. }
  43574. return preprocessor(
  43575. options.source,
  43576. options.inMap || options.map,
  43577. __spreadValues$4({
  43578. filename: options.filename
  43579. }, options.preprocessOptions),
  43580. options.preprocessCustomRequire
  43581. );
  43582. }
  43583. const UNKNOWN_TYPE = "Unknown";
  43584. function resolveObjectKey(node, computed) {
  43585. switch (node.type) {
  43586. case "StringLiteral":
  43587. case "NumericLiteral":
  43588. return String(node.value);
  43589. case "Identifier":
  43590. if (!computed) return node.name;
  43591. }
  43592. return void 0;
  43593. }
  43594. function concatStrings(strs) {
  43595. return strs.filter((s) => !!s).join(", ");
  43596. }
  43597. function isLiteralNode(node) {
  43598. return node.type.endsWith("Literal");
  43599. }
  43600. function isCallOf(node, test) {
  43601. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  43602. }
  43603. function toRuntimeTypeString(types) {
  43604. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  43605. }
  43606. function getImportedName(specifier) {
  43607. if (specifier.type === "ImportSpecifier")
  43608. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  43609. else if (specifier.type === "ImportNamespaceSpecifier") return "*";
  43610. return "default";
  43611. }
  43612. function getId(node) {
  43613. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  43614. }
  43615. function getStringLiteralKey(node) {
  43616. 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;
  43617. }
  43618. const normalize = (path.posix || path).normalize;
  43619. const windowsSlashRE = /\\/g;
  43620. function normalizePath(p) {
  43621. return normalize(p.replace(windowsSlashRE, "/"));
  43622. }
  43623. const joinPaths = (path.posix || path).join;
  43624. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  43625. function getEscapedPropName(key) {
  43626. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  43627. }
  43628. const isJS = (...langs) => langs.some((lang) => lang === "js" || lang === "jsx");
  43629. const isTS = (...langs) => langs.some((lang) => lang === "ts" || lang === "tsx");
  43630. function analyzeScriptBindings(ast) {
  43631. for (const node of ast) {
  43632. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  43633. return analyzeBindingsFromOptions(node.declaration);
  43634. }
  43635. }
  43636. return {};
  43637. }
  43638. function analyzeBindingsFromOptions(node) {
  43639. const bindings = {};
  43640. Object.defineProperty(bindings, "__isScriptSetup", {
  43641. enumerable: false,
  43642. value: false
  43643. });
  43644. for (const property of node.properties) {
  43645. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  43646. if (property.key.name === "props") {
  43647. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43648. bindings[key] = "props";
  43649. }
  43650. } else if (property.key.name === "inject") {
  43651. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43652. bindings[key] = "options";
  43653. }
  43654. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  43655. for (const key of getObjectExpressionKeys(property.value)) {
  43656. bindings[key] = "options";
  43657. }
  43658. }
  43659. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  43660. for (const bodyItem of property.body.body) {
  43661. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  43662. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  43663. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  43664. }
  43665. }
  43666. }
  43667. }
  43668. }
  43669. return bindings;
  43670. }
  43671. function getObjectExpressionKeys(node) {
  43672. const keys = [];
  43673. for (const prop of node.properties) {
  43674. if (prop.type === "SpreadElement") continue;
  43675. const key = resolveObjectKey(prop.key, prop.computed);
  43676. if (key) keys.push(String(key));
  43677. }
  43678. return keys;
  43679. }
  43680. function getArrayExpressionKeys(node) {
  43681. const keys = [];
  43682. for (const element of node.elements) {
  43683. if (element && element.type === "StringLiteral") {
  43684. keys.push(element.value);
  43685. }
  43686. }
  43687. return keys;
  43688. }
  43689. function getObjectOrArrayExpressionKeys(value) {
  43690. if (value.type === "ArrayExpression") {
  43691. return getArrayExpressionKeys(value);
  43692. }
  43693. if (value.type === "ObjectExpression") {
  43694. return getObjectExpressionKeys(value);
  43695. }
  43696. return [];
  43697. }
  43698. // src/vlq.ts
  43699. var comma = ",".charCodeAt(0);
  43700. var semicolon = ";".charCodeAt(0);
  43701. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  43702. var intToChar = new Uint8Array(64);
  43703. var charToInt = new Uint8Array(128);
  43704. for (let i = 0; i < chars.length; i++) {
  43705. const c = chars.charCodeAt(i);
  43706. intToChar[i] = c;
  43707. charToInt[c] = i;
  43708. }
  43709. function encodeInteger(builder, num, relative) {
  43710. let delta = num - relative;
  43711. delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
  43712. do {
  43713. let clamped = delta & 31;
  43714. delta >>>= 5;
  43715. if (delta > 0) clamped |= 32;
  43716. builder.write(intToChar[clamped]);
  43717. } while (delta > 0);
  43718. return num;
  43719. }
  43720. // src/strings.ts
  43721. var bufLength = 1024 * 16;
  43722. var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
  43723. decode(buf) {
  43724. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  43725. return out.toString();
  43726. }
  43727. } : {
  43728. decode(buf) {
  43729. let out = "";
  43730. for (let i = 0; i < buf.length; i++) {
  43731. out += String.fromCharCode(buf[i]);
  43732. }
  43733. return out;
  43734. }
  43735. };
  43736. var StringWriter = class {
  43737. constructor() {
  43738. this.pos = 0;
  43739. this.out = "";
  43740. this.buffer = new Uint8Array(bufLength);
  43741. }
  43742. write(v) {
  43743. const { buffer } = this;
  43744. buffer[this.pos++] = v;
  43745. if (this.pos === bufLength) {
  43746. this.out += td.decode(buffer);
  43747. this.pos = 0;
  43748. }
  43749. }
  43750. flush() {
  43751. const { buffer, out, pos } = this;
  43752. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  43753. }
  43754. };
  43755. function encode(decoded) {
  43756. const writer = new StringWriter();
  43757. let sourcesIndex = 0;
  43758. let sourceLine = 0;
  43759. let sourceColumn = 0;
  43760. let namesIndex = 0;
  43761. for (let i = 0; i < decoded.length; i++) {
  43762. const line = decoded[i];
  43763. if (i > 0) writer.write(semicolon);
  43764. if (line.length === 0) continue;
  43765. let genColumn = 0;
  43766. for (let j = 0; j < line.length; j++) {
  43767. const segment = line[j];
  43768. if (j > 0) writer.write(comma);
  43769. genColumn = encodeInteger(writer, segment[0], genColumn);
  43770. if (segment.length === 1) continue;
  43771. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  43772. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  43773. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  43774. if (segment.length === 4) continue;
  43775. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  43776. }
  43777. }
  43778. return writer.flush();
  43779. }
  43780. class BitSet {
  43781. constructor(arg) {
  43782. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  43783. }
  43784. add(n) {
  43785. this.bits[n >> 5] |= 1 << (n & 31);
  43786. }
  43787. has(n) {
  43788. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  43789. }
  43790. }
  43791. class Chunk {
  43792. constructor(start, end, content) {
  43793. this.start = start;
  43794. this.end = end;
  43795. this.original = content;
  43796. this.intro = '';
  43797. this.outro = '';
  43798. this.content = content;
  43799. this.storeName = false;
  43800. this.edited = false;
  43801. {
  43802. this.previous = null;
  43803. this.next = null;
  43804. }
  43805. }
  43806. appendLeft(content) {
  43807. this.outro += content;
  43808. }
  43809. appendRight(content) {
  43810. this.intro = this.intro + content;
  43811. }
  43812. clone() {
  43813. const chunk = new Chunk(this.start, this.end, this.original);
  43814. chunk.intro = this.intro;
  43815. chunk.outro = this.outro;
  43816. chunk.content = this.content;
  43817. chunk.storeName = this.storeName;
  43818. chunk.edited = this.edited;
  43819. return chunk;
  43820. }
  43821. contains(index) {
  43822. return this.start < index && index < this.end;
  43823. }
  43824. eachNext(fn) {
  43825. let chunk = this;
  43826. while (chunk) {
  43827. fn(chunk);
  43828. chunk = chunk.next;
  43829. }
  43830. }
  43831. eachPrevious(fn) {
  43832. let chunk = this;
  43833. while (chunk) {
  43834. fn(chunk);
  43835. chunk = chunk.previous;
  43836. }
  43837. }
  43838. edit(content, storeName, contentOnly) {
  43839. this.content = content;
  43840. if (!contentOnly) {
  43841. this.intro = '';
  43842. this.outro = '';
  43843. }
  43844. this.storeName = storeName;
  43845. this.edited = true;
  43846. return this;
  43847. }
  43848. prependLeft(content) {
  43849. this.outro = content + this.outro;
  43850. }
  43851. prependRight(content) {
  43852. this.intro = content + this.intro;
  43853. }
  43854. reset() {
  43855. this.intro = '';
  43856. this.outro = '';
  43857. if (this.edited) {
  43858. this.content = this.original;
  43859. this.storeName = false;
  43860. this.edited = false;
  43861. }
  43862. }
  43863. split(index) {
  43864. const sliceIndex = index - this.start;
  43865. const originalBefore = this.original.slice(0, sliceIndex);
  43866. const originalAfter = this.original.slice(sliceIndex);
  43867. this.original = originalBefore;
  43868. const newChunk = new Chunk(index, this.end, originalAfter);
  43869. newChunk.outro = this.outro;
  43870. this.outro = '';
  43871. this.end = index;
  43872. if (this.edited) {
  43873. // after split we should save the edit content record into the correct chunk
  43874. // to make sure sourcemap correct
  43875. // For example:
  43876. // ' test'.trim()
  43877. // split -> ' ' + 'test'
  43878. // ✔️ edit -> '' + 'test'
  43879. // ✖️ edit -> 'test' + ''
  43880. // TODO is this block necessary?...
  43881. newChunk.edit('', false);
  43882. this.content = '';
  43883. } else {
  43884. this.content = originalBefore;
  43885. }
  43886. newChunk.next = this.next;
  43887. if (newChunk.next) newChunk.next.previous = newChunk;
  43888. newChunk.previous = this;
  43889. this.next = newChunk;
  43890. return newChunk;
  43891. }
  43892. toString() {
  43893. return this.intro + this.content + this.outro;
  43894. }
  43895. trimEnd(rx) {
  43896. this.outro = this.outro.replace(rx, '');
  43897. if (this.outro.length) return true;
  43898. const trimmed = this.content.replace(rx, '');
  43899. if (trimmed.length) {
  43900. if (trimmed !== this.content) {
  43901. this.split(this.start + trimmed.length).edit('', undefined, true);
  43902. if (this.edited) {
  43903. // save the change, if it has been edited
  43904. this.edit(trimmed, this.storeName, true);
  43905. }
  43906. }
  43907. return true;
  43908. } else {
  43909. this.edit('', undefined, true);
  43910. this.intro = this.intro.replace(rx, '');
  43911. if (this.intro.length) return true;
  43912. }
  43913. }
  43914. trimStart(rx) {
  43915. this.intro = this.intro.replace(rx, '');
  43916. if (this.intro.length) return true;
  43917. const trimmed = this.content.replace(rx, '');
  43918. if (trimmed.length) {
  43919. if (trimmed !== this.content) {
  43920. const newChunk = this.split(this.end - trimmed.length);
  43921. if (this.edited) {
  43922. // save the change, if it has been edited
  43923. newChunk.edit(trimmed, this.storeName, true);
  43924. }
  43925. this.edit('', undefined, true);
  43926. }
  43927. return true;
  43928. } else {
  43929. this.edit('', undefined, true);
  43930. this.outro = this.outro.replace(rx, '');
  43931. if (this.outro.length) return true;
  43932. }
  43933. }
  43934. }
  43935. function getBtoa() {
  43936. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  43937. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  43938. } else if (typeof Buffer === 'function') {
  43939. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  43940. } else {
  43941. return () => {
  43942. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  43943. };
  43944. }
  43945. }
  43946. const btoa = /*#__PURE__*/ getBtoa();
  43947. class SourceMap {
  43948. constructor(properties) {
  43949. this.version = 3;
  43950. this.file = properties.file;
  43951. this.sources = properties.sources;
  43952. this.sourcesContent = properties.sourcesContent;
  43953. this.names = properties.names;
  43954. this.mappings = encode(properties.mappings);
  43955. if (typeof properties.x_google_ignoreList !== 'undefined') {
  43956. this.x_google_ignoreList = properties.x_google_ignoreList;
  43957. }
  43958. if (typeof properties.debugId !== 'undefined') {
  43959. this.debugId = properties.debugId;
  43960. }
  43961. }
  43962. toString() {
  43963. return JSON.stringify(this);
  43964. }
  43965. toUrl() {
  43966. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  43967. }
  43968. }
  43969. function guessIndent(code) {
  43970. const lines = code.split('\n');
  43971. const tabbed = lines.filter((line) => /^\t+/.test(line));
  43972. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  43973. if (tabbed.length === 0 && spaced.length === 0) {
  43974. return null;
  43975. }
  43976. // More lines tabbed than spaced? Assume tabs, and
  43977. // default to tabs in the case of a tie (or nothing
  43978. // to go on)
  43979. if (tabbed.length >= spaced.length) {
  43980. return '\t';
  43981. }
  43982. // Otherwise, we need to guess the multiple
  43983. const min = spaced.reduce((previous, current) => {
  43984. const numSpaces = /^ +/.exec(current)[0].length;
  43985. return Math.min(numSpaces, previous);
  43986. }, Infinity);
  43987. return new Array(min + 1).join(' ');
  43988. }
  43989. function getRelativePath(from, to) {
  43990. const fromParts = from.split(/[/\\]/);
  43991. const toParts = to.split(/[/\\]/);
  43992. fromParts.pop(); // get dirname
  43993. while (fromParts[0] === toParts[0]) {
  43994. fromParts.shift();
  43995. toParts.shift();
  43996. }
  43997. if (fromParts.length) {
  43998. let i = fromParts.length;
  43999. while (i--) fromParts[i] = '..';
  44000. }
  44001. return fromParts.concat(toParts).join('/');
  44002. }
  44003. const toString = Object.prototype.toString;
  44004. function isObject(thing) {
  44005. return toString.call(thing) === '[object Object]';
  44006. }
  44007. function getLocator(source) {
  44008. const originalLines = source.split('\n');
  44009. const lineOffsets = [];
  44010. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  44011. lineOffsets.push(pos);
  44012. pos += originalLines[i].length + 1;
  44013. }
  44014. return function locate(index) {
  44015. let i = 0;
  44016. let j = lineOffsets.length;
  44017. while (i < j) {
  44018. const m = (i + j) >> 1;
  44019. if (index < lineOffsets[m]) {
  44020. j = m;
  44021. } else {
  44022. i = m + 1;
  44023. }
  44024. }
  44025. const line = i - 1;
  44026. const column = index - lineOffsets[line];
  44027. return { line, column };
  44028. };
  44029. }
  44030. const wordRegex = /\w/;
  44031. class Mappings {
  44032. constructor(hires) {
  44033. this.hires = hires;
  44034. this.generatedCodeLine = 0;
  44035. this.generatedCodeColumn = 0;
  44036. this.raw = [];
  44037. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  44038. this.pending = null;
  44039. }
  44040. addEdit(sourceIndex, content, loc, nameIndex) {
  44041. if (content.length) {
  44042. const contentLengthMinusOne = content.length - 1;
  44043. let contentLineEnd = content.indexOf('\n', 0);
  44044. let previousContentLineEnd = -1;
  44045. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  44046. // else code afterwards would fill one line too many
  44047. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  44048. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44049. if (nameIndex >= 0) {
  44050. segment.push(nameIndex);
  44051. }
  44052. this.rawSegments.push(segment);
  44053. this.generatedCodeLine += 1;
  44054. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44055. this.generatedCodeColumn = 0;
  44056. previousContentLineEnd = contentLineEnd;
  44057. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  44058. }
  44059. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44060. if (nameIndex >= 0) {
  44061. segment.push(nameIndex);
  44062. }
  44063. this.rawSegments.push(segment);
  44064. this.advance(content.slice(previousContentLineEnd + 1));
  44065. } else if (this.pending) {
  44066. this.rawSegments.push(this.pending);
  44067. this.advance(content);
  44068. }
  44069. this.pending = null;
  44070. }
  44071. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  44072. let originalCharIndex = chunk.start;
  44073. let first = true;
  44074. // when iterating each char, check if it's in a word boundary
  44075. let charInHiresBoundary = false;
  44076. while (originalCharIndex < chunk.end) {
  44077. if (original[originalCharIndex] === '\n') {
  44078. loc.line += 1;
  44079. loc.column = 0;
  44080. this.generatedCodeLine += 1;
  44081. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44082. this.generatedCodeColumn = 0;
  44083. first = true;
  44084. charInHiresBoundary = false;
  44085. } else {
  44086. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  44087. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44088. if (this.hires === 'boundary') {
  44089. // in hires "boundary", group segments per word boundary than per char
  44090. if (wordRegex.test(original[originalCharIndex])) {
  44091. // for first char in the boundary found, start the boundary by pushing a segment
  44092. if (!charInHiresBoundary) {
  44093. this.rawSegments.push(segment);
  44094. charInHiresBoundary = true;
  44095. }
  44096. } else {
  44097. // for non-word char, end the boundary by pushing a segment
  44098. this.rawSegments.push(segment);
  44099. charInHiresBoundary = false;
  44100. }
  44101. } else {
  44102. this.rawSegments.push(segment);
  44103. }
  44104. }
  44105. loc.column += 1;
  44106. this.generatedCodeColumn += 1;
  44107. first = false;
  44108. }
  44109. originalCharIndex += 1;
  44110. }
  44111. this.pending = null;
  44112. }
  44113. advance(str) {
  44114. if (!str) return;
  44115. const lines = str.split('\n');
  44116. if (lines.length > 1) {
  44117. for (let i = 0; i < lines.length - 1; i++) {
  44118. this.generatedCodeLine++;
  44119. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44120. }
  44121. this.generatedCodeColumn = 0;
  44122. }
  44123. this.generatedCodeColumn += lines[lines.length - 1].length;
  44124. }
  44125. }
  44126. const n = '\n';
  44127. const warned = {
  44128. insertLeft: false,
  44129. insertRight: false,
  44130. storeName: false,
  44131. };
  44132. class MagicString {
  44133. constructor(string, options = {}) {
  44134. const chunk = new Chunk(0, string.length, string);
  44135. Object.defineProperties(this, {
  44136. original: { writable: true, value: string },
  44137. outro: { writable: true, value: '' },
  44138. intro: { writable: true, value: '' },
  44139. firstChunk: { writable: true, value: chunk },
  44140. lastChunk: { writable: true, value: chunk },
  44141. lastSearchedChunk: { writable: true, value: chunk },
  44142. byStart: { writable: true, value: {} },
  44143. byEnd: { writable: true, value: {} },
  44144. filename: { writable: true, value: options.filename },
  44145. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  44146. sourcemapLocations: { writable: true, value: new BitSet() },
  44147. storedNames: { writable: true, value: {} },
  44148. indentStr: { writable: true, value: undefined },
  44149. ignoreList: { writable: true, value: options.ignoreList },
  44150. offset: { writable: true, value: options.offset || 0 },
  44151. });
  44152. this.byStart[0] = chunk;
  44153. this.byEnd[string.length] = chunk;
  44154. }
  44155. addSourcemapLocation(char) {
  44156. this.sourcemapLocations.add(char);
  44157. }
  44158. append(content) {
  44159. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44160. this.outro += content;
  44161. return this;
  44162. }
  44163. appendLeft(index, content) {
  44164. index = index + this.offset;
  44165. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44166. this._split(index);
  44167. const chunk = this.byEnd[index];
  44168. if (chunk) {
  44169. chunk.appendLeft(content);
  44170. } else {
  44171. this.intro += content;
  44172. }
  44173. return this;
  44174. }
  44175. appendRight(index, content) {
  44176. index = index + this.offset;
  44177. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44178. this._split(index);
  44179. const chunk = this.byStart[index];
  44180. if (chunk) {
  44181. chunk.appendRight(content);
  44182. } else {
  44183. this.outro += content;
  44184. }
  44185. return this;
  44186. }
  44187. clone() {
  44188. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  44189. let originalChunk = this.firstChunk;
  44190. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  44191. while (originalChunk) {
  44192. cloned.byStart[clonedChunk.start] = clonedChunk;
  44193. cloned.byEnd[clonedChunk.end] = clonedChunk;
  44194. const nextOriginalChunk = originalChunk.next;
  44195. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  44196. if (nextClonedChunk) {
  44197. clonedChunk.next = nextClonedChunk;
  44198. nextClonedChunk.previous = clonedChunk;
  44199. clonedChunk = nextClonedChunk;
  44200. }
  44201. originalChunk = nextOriginalChunk;
  44202. }
  44203. cloned.lastChunk = clonedChunk;
  44204. if (this.indentExclusionRanges) {
  44205. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  44206. }
  44207. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  44208. cloned.intro = this.intro;
  44209. cloned.outro = this.outro;
  44210. return cloned;
  44211. }
  44212. generateDecodedMap(options) {
  44213. options = options || {};
  44214. const sourceIndex = 0;
  44215. const names = Object.keys(this.storedNames);
  44216. const mappings = new Mappings(options.hires);
  44217. const locate = getLocator(this.original);
  44218. if (this.intro) {
  44219. mappings.advance(this.intro);
  44220. }
  44221. this.firstChunk.eachNext((chunk) => {
  44222. const loc = locate(chunk.start);
  44223. if (chunk.intro.length) mappings.advance(chunk.intro);
  44224. if (chunk.edited) {
  44225. mappings.addEdit(
  44226. sourceIndex,
  44227. chunk.content,
  44228. loc,
  44229. chunk.storeName ? names.indexOf(chunk.original) : -1,
  44230. );
  44231. } else {
  44232. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  44233. }
  44234. if (chunk.outro.length) mappings.advance(chunk.outro);
  44235. });
  44236. if (this.outro) {
  44237. mappings.advance(this.outro);
  44238. }
  44239. return {
  44240. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  44241. sources: [
  44242. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  44243. ],
  44244. sourcesContent: options.includeContent ? [this.original] : undefined,
  44245. names,
  44246. mappings: mappings.raw,
  44247. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  44248. };
  44249. }
  44250. generateMap(options) {
  44251. return new SourceMap(this.generateDecodedMap(options));
  44252. }
  44253. _ensureindentStr() {
  44254. if (this.indentStr === undefined) {
  44255. this.indentStr = guessIndent(this.original);
  44256. }
  44257. }
  44258. _getRawIndentString() {
  44259. this._ensureindentStr();
  44260. return this.indentStr;
  44261. }
  44262. getIndentString() {
  44263. this._ensureindentStr();
  44264. return this.indentStr === null ? '\t' : this.indentStr;
  44265. }
  44266. indent(indentStr, options) {
  44267. const pattern = /^[^\r\n]/gm;
  44268. if (isObject(indentStr)) {
  44269. options = indentStr;
  44270. indentStr = undefined;
  44271. }
  44272. if (indentStr === undefined) {
  44273. this._ensureindentStr();
  44274. indentStr = this.indentStr || '\t';
  44275. }
  44276. if (indentStr === '') return this; // noop
  44277. options = options || {};
  44278. // Process exclusion ranges
  44279. const isExcluded = {};
  44280. if (options.exclude) {
  44281. const exclusions =
  44282. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  44283. exclusions.forEach((exclusion) => {
  44284. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  44285. isExcluded[i] = true;
  44286. }
  44287. });
  44288. }
  44289. let shouldIndentNextCharacter = options.indentStart !== false;
  44290. const replacer = (match) => {
  44291. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  44292. shouldIndentNextCharacter = true;
  44293. return match;
  44294. };
  44295. this.intro = this.intro.replace(pattern, replacer);
  44296. let charIndex = 0;
  44297. let chunk = this.firstChunk;
  44298. while (chunk) {
  44299. const end = chunk.end;
  44300. if (chunk.edited) {
  44301. if (!isExcluded[charIndex]) {
  44302. chunk.content = chunk.content.replace(pattern, replacer);
  44303. if (chunk.content.length) {
  44304. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  44305. }
  44306. }
  44307. } else {
  44308. charIndex = chunk.start;
  44309. while (charIndex < end) {
  44310. if (!isExcluded[charIndex]) {
  44311. const char = this.original[charIndex];
  44312. if (char === '\n') {
  44313. shouldIndentNextCharacter = true;
  44314. } else if (char !== '\r' && shouldIndentNextCharacter) {
  44315. shouldIndentNextCharacter = false;
  44316. if (charIndex === chunk.start) {
  44317. chunk.prependRight(indentStr);
  44318. } else {
  44319. this._splitChunk(chunk, charIndex);
  44320. chunk = chunk.next;
  44321. chunk.prependRight(indentStr);
  44322. }
  44323. }
  44324. }
  44325. charIndex += 1;
  44326. }
  44327. }
  44328. charIndex = chunk.end;
  44329. chunk = chunk.next;
  44330. }
  44331. this.outro = this.outro.replace(pattern, replacer);
  44332. return this;
  44333. }
  44334. insert() {
  44335. throw new Error(
  44336. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  44337. );
  44338. }
  44339. insertLeft(index, content) {
  44340. if (!warned.insertLeft) {
  44341. console.warn(
  44342. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  44343. );
  44344. warned.insertLeft = true;
  44345. }
  44346. return this.appendLeft(index, content);
  44347. }
  44348. insertRight(index, content) {
  44349. if (!warned.insertRight) {
  44350. console.warn(
  44351. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  44352. );
  44353. warned.insertRight = true;
  44354. }
  44355. return this.prependRight(index, content);
  44356. }
  44357. move(start, end, index) {
  44358. start = start + this.offset;
  44359. end = end + this.offset;
  44360. index = index + this.offset;
  44361. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  44362. this._split(start);
  44363. this._split(end);
  44364. this._split(index);
  44365. const first = this.byStart[start];
  44366. const last = this.byEnd[end];
  44367. const oldLeft = first.previous;
  44368. const oldRight = last.next;
  44369. const newRight = this.byStart[index];
  44370. if (!newRight && last === this.lastChunk) return this;
  44371. const newLeft = newRight ? newRight.previous : this.lastChunk;
  44372. if (oldLeft) oldLeft.next = oldRight;
  44373. if (oldRight) oldRight.previous = oldLeft;
  44374. if (newLeft) newLeft.next = first;
  44375. if (newRight) newRight.previous = last;
  44376. if (!first.previous) this.firstChunk = last.next;
  44377. if (!last.next) {
  44378. this.lastChunk = first.previous;
  44379. this.lastChunk.next = null;
  44380. }
  44381. first.previous = newLeft;
  44382. last.next = newRight || null;
  44383. if (!newLeft) this.firstChunk = first;
  44384. if (!newRight) this.lastChunk = last;
  44385. return this;
  44386. }
  44387. overwrite(start, end, content, options) {
  44388. options = options || {};
  44389. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  44390. }
  44391. update(start, end, content, options) {
  44392. start = start + this.offset;
  44393. end = end + this.offset;
  44394. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  44395. if (this.original.length !== 0) {
  44396. while (start < 0) start += this.original.length;
  44397. while (end < 0) end += this.original.length;
  44398. }
  44399. if (end > this.original.length) throw new Error('end is out of bounds');
  44400. if (start === end)
  44401. throw new Error(
  44402. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  44403. );
  44404. this._split(start);
  44405. this._split(end);
  44406. if (options === true) {
  44407. if (!warned.storeName) {
  44408. console.warn(
  44409. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  44410. );
  44411. warned.storeName = true;
  44412. }
  44413. options = { storeName: true };
  44414. }
  44415. const storeName = options !== undefined ? options.storeName : false;
  44416. const overwrite = options !== undefined ? options.overwrite : false;
  44417. if (storeName) {
  44418. const original = this.original.slice(start, end);
  44419. Object.defineProperty(this.storedNames, original, {
  44420. writable: true,
  44421. value: true,
  44422. enumerable: true,
  44423. });
  44424. }
  44425. const first = this.byStart[start];
  44426. const last = this.byEnd[end];
  44427. if (first) {
  44428. let chunk = first;
  44429. while (chunk !== last) {
  44430. if (chunk.next !== this.byStart[chunk.end]) {
  44431. throw new Error('Cannot overwrite across a split point');
  44432. }
  44433. chunk = chunk.next;
  44434. chunk.edit('', false);
  44435. }
  44436. first.edit(content, storeName, !overwrite);
  44437. } else {
  44438. // must be inserting at the end
  44439. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  44440. // TODO last chunk in the array may not be the last chunk, if it's moved...
  44441. last.next = newChunk;
  44442. newChunk.previous = last;
  44443. }
  44444. return this;
  44445. }
  44446. prepend(content) {
  44447. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44448. this.intro = content + this.intro;
  44449. return this;
  44450. }
  44451. prependLeft(index, content) {
  44452. index = index + this.offset;
  44453. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44454. this._split(index);
  44455. const chunk = this.byEnd[index];
  44456. if (chunk) {
  44457. chunk.prependLeft(content);
  44458. } else {
  44459. this.intro = content + this.intro;
  44460. }
  44461. return this;
  44462. }
  44463. prependRight(index, content) {
  44464. index = index + this.offset;
  44465. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44466. this._split(index);
  44467. const chunk = this.byStart[index];
  44468. if (chunk) {
  44469. chunk.prependRight(content);
  44470. } else {
  44471. this.outro = content + this.outro;
  44472. }
  44473. return this;
  44474. }
  44475. remove(start, end) {
  44476. start = start + this.offset;
  44477. end = end + this.offset;
  44478. if (this.original.length !== 0) {
  44479. while (start < 0) start += this.original.length;
  44480. while (end < 0) end += this.original.length;
  44481. }
  44482. if (start === end) return this;
  44483. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44484. if (start > end) throw new Error('end must be greater than start');
  44485. this._split(start);
  44486. this._split(end);
  44487. let chunk = this.byStart[start];
  44488. while (chunk) {
  44489. chunk.intro = '';
  44490. chunk.outro = '';
  44491. chunk.edit('');
  44492. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44493. }
  44494. return this;
  44495. }
  44496. reset(start, end) {
  44497. start = start + this.offset;
  44498. end = end + this.offset;
  44499. if (this.original.length !== 0) {
  44500. while (start < 0) start += this.original.length;
  44501. while (end < 0) end += this.original.length;
  44502. }
  44503. if (start === end) return this;
  44504. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44505. if (start > end) throw new Error('end must be greater than start');
  44506. this._split(start);
  44507. this._split(end);
  44508. let chunk = this.byStart[start];
  44509. while (chunk) {
  44510. chunk.reset();
  44511. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44512. }
  44513. return this;
  44514. }
  44515. lastChar() {
  44516. if (this.outro.length) return this.outro[this.outro.length - 1];
  44517. let chunk = this.lastChunk;
  44518. do {
  44519. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  44520. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  44521. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  44522. } while ((chunk = chunk.previous));
  44523. if (this.intro.length) return this.intro[this.intro.length - 1];
  44524. return '';
  44525. }
  44526. lastLine() {
  44527. let lineIndex = this.outro.lastIndexOf(n);
  44528. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  44529. let lineStr = this.outro;
  44530. let chunk = this.lastChunk;
  44531. do {
  44532. if (chunk.outro.length > 0) {
  44533. lineIndex = chunk.outro.lastIndexOf(n);
  44534. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  44535. lineStr = chunk.outro + lineStr;
  44536. }
  44537. if (chunk.content.length > 0) {
  44538. lineIndex = chunk.content.lastIndexOf(n);
  44539. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  44540. lineStr = chunk.content + lineStr;
  44541. }
  44542. if (chunk.intro.length > 0) {
  44543. lineIndex = chunk.intro.lastIndexOf(n);
  44544. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  44545. lineStr = chunk.intro + lineStr;
  44546. }
  44547. } while ((chunk = chunk.previous));
  44548. lineIndex = this.intro.lastIndexOf(n);
  44549. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  44550. return this.intro + lineStr;
  44551. }
  44552. slice(start = 0, end = this.original.length - this.offset) {
  44553. start = start + this.offset;
  44554. end = end + this.offset;
  44555. if (this.original.length !== 0) {
  44556. while (start < 0) start += this.original.length;
  44557. while (end < 0) end += this.original.length;
  44558. }
  44559. let result = '';
  44560. // find start chunk
  44561. let chunk = this.firstChunk;
  44562. while (chunk && (chunk.start > start || chunk.end <= start)) {
  44563. // found end chunk before start
  44564. if (chunk.start < end && chunk.end >= end) {
  44565. return result;
  44566. }
  44567. chunk = chunk.next;
  44568. }
  44569. if (chunk && chunk.edited && chunk.start !== start)
  44570. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  44571. const startChunk = chunk;
  44572. while (chunk) {
  44573. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  44574. result += chunk.intro;
  44575. }
  44576. const containsEnd = chunk.start < end && chunk.end >= end;
  44577. if (containsEnd && chunk.edited && chunk.end !== end)
  44578. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  44579. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  44580. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  44581. result += chunk.content.slice(sliceStart, sliceEnd);
  44582. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  44583. result += chunk.outro;
  44584. }
  44585. if (containsEnd) {
  44586. break;
  44587. }
  44588. chunk = chunk.next;
  44589. }
  44590. return result;
  44591. }
  44592. // TODO deprecate this? not really very useful
  44593. snip(start, end) {
  44594. const clone = this.clone();
  44595. clone.remove(0, start);
  44596. clone.remove(end, clone.original.length);
  44597. return clone;
  44598. }
  44599. _split(index) {
  44600. if (this.byStart[index] || this.byEnd[index]) return;
  44601. let chunk = this.lastSearchedChunk;
  44602. let previousChunk = chunk;
  44603. const searchForward = index > chunk.end;
  44604. while (chunk) {
  44605. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  44606. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  44607. // Prevent infinite loop (e.g. via empty chunks, where start === end)
  44608. if (chunk === previousChunk) return;
  44609. previousChunk = chunk;
  44610. }
  44611. }
  44612. _splitChunk(chunk, index) {
  44613. if (chunk.edited && chunk.content.length) {
  44614. // zero-length edited chunks are a special case (overlapping replacements)
  44615. const loc = getLocator(this.original)(index);
  44616. throw new Error(
  44617. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  44618. );
  44619. }
  44620. const newChunk = chunk.split(index);
  44621. this.byEnd[index] = chunk;
  44622. this.byStart[index] = newChunk;
  44623. this.byEnd[newChunk.end] = newChunk;
  44624. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  44625. this.lastSearchedChunk = chunk;
  44626. return true;
  44627. }
  44628. toString() {
  44629. let str = this.intro;
  44630. let chunk = this.firstChunk;
  44631. while (chunk) {
  44632. str += chunk.toString();
  44633. chunk = chunk.next;
  44634. }
  44635. return str + this.outro;
  44636. }
  44637. isEmpty() {
  44638. let chunk = this.firstChunk;
  44639. do {
  44640. if (
  44641. (chunk.intro.length && chunk.intro.trim()) ||
  44642. (chunk.content.length && chunk.content.trim()) ||
  44643. (chunk.outro.length && chunk.outro.trim())
  44644. )
  44645. return false;
  44646. } while ((chunk = chunk.next));
  44647. return true;
  44648. }
  44649. length() {
  44650. let chunk = this.firstChunk;
  44651. let length = 0;
  44652. do {
  44653. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  44654. } while ((chunk = chunk.next));
  44655. return length;
  44656. }
  44657. trimLines() {
  44658. return this.trim('[\\r\\n]');
  44659. }
  44660. trim(charType) {
  44661. return this.trimStart(charType).trimEnd(charType);
  44662. }
  44663. trimEndAborted(charType) {
  44664. const rx = new RegExp((charType || '\\s') + '+$');
  44665. this.outro = this.outro.replace(rx, '');
  44666. if (this.outro.length) return true;
  44667. let chunk = this.lastChunk;
  44668. do {
  44669. const end = chunk.end;
  44670. const aborted = chunk.trimEnd(rx);
  44671. // if chunk was trimmed, we have a new lastChunk
  44672. if (chunk.end !== end) {
  44673. if (this.lastChunk === chunk) {
  44674. this.lastChunk = chunk.next;
  44675. }
  44676. this.byEnd[chunk.end] = chunk;
  44677. this.byStart[chunk.next.start] = chunk.next;
  44678. this.byEnd[chunk.next.end] = chunk.next;
  44679. }
  44680. if (aborted) return true;
  44681. chunk = chunk.previous;
  44682. } while (chunk);
  44683. return false;
  44684. }
  44685. trimEnd(charType) {
  44686. this.trimEndAborted(charType);
  44687. return this;
  44688. }
  44689. trimStartAborted(charType) {
  44690. const rx = new RegExp('^' + (charType || '\\s') + '+');
  44691. this.intro = this.intro.replace(rx, '');
  44692. if (this.intro.length) return true;
  44693. let chunk = this.firstChunk;
  44694. do {
  44695. const end = chunk.end;
  44696. const aborted = chunk.trimStart(rx);
  44697. if (chunk.end !== end) {
  44698. // special case...
  44699. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  44700. this.byEnd[chunk.end] = chunk;
  44701. this.byStart[chunk.next.start] = chunk.next;
  44702. this.byEnd[chunk.next.end] = chunk.next;
  44703. }
  44704. if (aborted) return true;
  44705. chunk = chunk.next;
  44706. } while (chunk);
  44707. return false;
  44708. }
  44709. trimStart(charType) {
  44710. this.trimStartAborted(charType);
  44711. return this;
  44712. }
  44713. hasChanged() {
  44714. return this.original !== this.toString();
  44715. }
  44716. _replaceRegexp(searchValue, replacement) {
  44717. function getReplacement(match, str) {
  44718. if (typeof replacement === 'string') {
  44719. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  44720. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  44721. if (i === '$') return '$';
  44722. if (i === '&') return match[0];
  44723. const num = +i;
  44724. if (num < match.length) return match[+i];
  44725. return `$${i}`;
  44726. });
  44727. } else {
  44728. return replacement(...match, match.index, str, match.groups);
  44729. }
  44730. }
  44731. function matchAll(re, str) {
  44732. let match;
  44733. const matches = [];
  44734. while ((match = re.exec(str))) {
  44735. matches.push(match);
  44736. }
  44737. return matches;
  44738. }
  44739. if (searchValue.global) {
  44740. const matches = matchAll(searchValue, this.original);
  44741. matches.forEach((match) => {
  44742. if (match.index != null) {
  44743. const replacement = getReplacement(match, this.original);
  44744. if (replacement !== match[0]) {
  44745. this.overwrite(match.index, match.index + match[0].length, replacement);
  44746. }
  44747. }
  44748. });
  44749. } else {
  44750. const match = this.original.match(searchValue);
  44751. if (match && match.index != null) {
  44752. const replacement = getReplacement(match, this.original);
  44753. if (replacement !== match[0]) {
  44754. this.overwrite(match.index, match.index + match[0].length, replacement);
  44755. }
  44756. }
  44757. }
  44758. return this;
  44759. }
  44760. _replaceString(string, replacement) {
  44761. const { original } = this;
  44762. const index = original.indexOf(string);
  44763. if (index !== -1) {
  44764. if (typeof replacement === 'function') {
  44765. replacement = replacement(string, index, original);
  44766. }
  44767. if (string !== replacement) {
  44768. this.overwrite(index, index + string.length, replacement);
  44769. }
  44770. }
  44771. return this;
  44772. }
  44773. replace(searchValue, replacement) {
  44774. if (typeof searchValue === 'string') {
  44775. return this._replaceString(searchValue, replacement);
  44776. }
  44777. return this._replaceRegexp(searchValue, replacement);
  44778. }
  44779. _replaceAllString(string, replacement) {
  44780. const { original } = this;
  44781. const stringLength = string.length;
  44782. for (
  44783. let index = original.indexOf(string);
  44784. index !== -1;
  44785. index = original.indexOf(string, index + stringLength)
  44786. ) {
  44787. const previous = original.slice(index, index + stringLength);
  44788. let _replacement = replacement;
  44789. if (typeof replacement === 'function') {
  44790. _replacement = replacement(previous, index, original);
  44791. }
  44792. if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
  44793. }
  44794. return this;
  44795. }
  44796. replaceAll(searchValue, replacement) {
  44797. if (typeof searchValue === 'string') {
  44798. return this._replaceAllString(searchValue, replacement);
  44799. }
  44800. if (!searchValue.global) {
  44801. throw new TypeError(
  44802. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  44803. );
  44804. }
  44805. return this._replaceRegexp(searchValue, replacement);
  44806. }
  44807. }
  44808. var _a, _b;
  44809. class ScriptCompileContext {
  44810. constructor(descriptor, options) {
  44811. this.descriptor = descriptor;
  44812. this.options = options;
  44813. this.isCE = false;
  44814. this.source = this.descriptor.source;
  44815. this.filename = this.descriptor.filename;
  44816. this.s = new MagicString(this.source);
  44817. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44818. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44819. this.userImports = /* @__PURE__ */ Object.create(null);
  44820. // macros presence check
  44821. this.hasDefinePropsCall = false;
  44822. this.hasDefineEmitCall = false;
  44823. this.hasDefineExposeCall = false;
  44824. this.hasDefaultExportName = false;
  44825. this.hasDefaultExportRender = false;
  44826. this.hasDefineOptionsCall = false;
  44827. this.hasDefineSlotsCall = false;
  44828. this.hasDefineModelCall = false;
  44829. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44830. // defineModel
  44831. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44832. // codegen
  44833. this.bindingMetadata = {};
  44834. this.helperImports = /* @__PURE__ */ new Set();
  44835. const { script, scriptSetup } = descriptor;
  44836. const scriptLang = script && script.lang;
  44837. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44838. this.isJS = isJS(scriptLang, scriptSetupLang);
  44839. this.isTS = isTS(scriptLang, scriptSetupLang);
  44840. const customElement = options.customElement;
  44841. const filename = this.descriptor.filename;
  44842. if (customElement) {
  44843. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44844. }
  44845. const plugins = resolveParserPlugins(
  44846. scriptLang || scriptSetupLang,
  44847. options.babelParserPlugins
  44848. );
  44849. function parse(input, offset) {
  44850. try {
  44851. return libExports.parse(input, {
  44852. plugins,
  44853. sourceType: "module"
  44854. }).program;
  44855. } catch (e) {
  44856. e.message = `[vue/compiler-sfc] ${e.message}
  44857. ${descriptor.filename}
  44858. ${generateCodeFrame(
  44859. descriptor.source,
  44860. e.pos + offset,
  44861. e.pos + offset + 1
  44862. )}`;
  44863. throw e;
  44864. }
  44865. }
  44866. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44867. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44868. }
  44869. helper(key) {
  44870. this.helperImports.add(key);
  44871. return `_${key}`;
  44872. }
  44873. getString(node, scriptSetup = true) {
  44874. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44875. return block.content.slice(node.start, node.end);
  44876. }
  44877. warn(msg, node, scope) {
  44878. warn(generateError(msg, node, this, scope));
  44879. }
  44880. error(msg, node, scope) {
  44881. throw new Error(
  44882. `[@vue/compiler-sfc] ${generateError(msg, node, this, scope)}`
  44883. );
  44884. }
  44885. }
  44886. function generateError(msg, node, ctx, scope) {
  44887. const offset = scope ? scope.offset : ctx.startOffset;
  44888. return `${msg}
  44889. ${(scope || ctx.descriptor).filename}
  44890. ${generateCodeFrame(
  44891. (scope || ctx.descriptor).source,
  44892. node.start + offset,
  44893. node.end + offset
  44894. )}`;
  44895. }
  44896. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44897. const plugins = [];
  44898. if (!userPlugins || !userPlugins.some(
  44899. (p) => p === "importAssertions" || p === "importAttributes" || isArray$3(p) && p[0] === "importAttributes"
  44900. )) {
  44901. plugins.push("importAttributes");
  44902. }
  44903. if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
  44904. plugins.push("jsx");
  44905. } else if (userPlugins) {
  44906. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44907. }
  44908. if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "cts" || lang === "mtsx") {
  44909. plugins.push(["typescript", { dts }], "explicitResourceManagement");
  44910. if (!userPlugins || !userPlugins.includes("decorators")) {
  44911. plugins.push("decorators-legacy");
  44912. }
  44913. }
  44914. if (userPlugins) {
  44915. plugins.push(...userPlugins);
  44916. }
  44917. return plugins;
  44918. }
  44919. function rewriteDefault(input, as, parserPlugins) {
  44920. const ast = libExports.parse(input, {
  44921. sourceType: "module",
  44922. plugins: resolveParserPlugins("js", parserPlugins)
  44923. }).program.body;
  44924. const s = new MagicString(input);
  44925. rewriteDefaultAST(ast, s, as);
  44926. return s.toString();
  44927. }
  44928. function rewriteDefaultAST(ast, s, as) {
  44929. if (!hasDefaultExport(ast)) {
  44930. s.append(`
  44931. const ${as} = {}`);
  44932. return;
  44933. }
  44934. ast.forEach((node) => {
  44935. if (node.type === "ExportDefaultDeclaration") {
  44936. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  44937. const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44938. s.overwrite(start, node.declaration.id.start, ` class `);
  44939. s.append(`
  44940. const ${as} = ${node.declaration.id.name}`);
  44941. } else {
  44942. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44943. }
  44944. } else if (node.type === "ExportNamedDeclaration") {
  44945. for (const specifier of node.specifiers) {
  44946. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44947. if (node.source) {
  44948. if (specifier.local.name === "default") {
  44949. s.prepend(
  44950. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44951. `
  44952. );
  44953. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44954. s.remove(specifier.start, end2);
  44955. s.append(`
  44956. const ${as} = __VUE_DEFAULT__`);
  44957. continue;
  44958. } else {
  44959. s.prepend(
  44960. `import { ${s.slice(
  44961. specifier.local.start,
  44962. specifier.local.end
  44963. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44964. `
  44965. );
  44966. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  44967. s.remove(specifier.start, end2);
  44968. s.append(`
  44969. const ${as} = __VUE_DEFAULT__`);
  44970. continue;
  44971. }
  44972. }
  44973. const end = specifierEnd(s, specifier.end, node.end);
  44974. s.remove(specifier.start, end);
  44975. s.append(`
  44976. const ${as} = ${specifier.local.name}`);
  44977. }
  44978. }
  44979. }
  44980. });
  44981. }
  44982. function hasDefaultExport(ast) {
  44983. for (const stmt of ast) {
  44984. if (stmt.type === "ExportDefaultDeclaration") {
  44985. return true;
  44986. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  44987. (spec) => spec.exported.name === "default"
  44988. )) {
  44989. return true;
  44990. }
  44991. }
  44992. return false;
  44993. }
  44994. function specifierEnd(s, end, nodeEnd) {
  44995. let hasCommas = false;
  44996. let oldEnd = end;
  44997. while (end < nodeEnd) {
  44998. if (/\s/.test(s.slice(end, end + 1))) {
  44999. end++;
  45000. } else if (s.slice(end, end + 1) === ",") {
  45001. end++;
  45002. hasCommas = true;
  45003. break;
  45004. } else if (s.slice(end, end + 1) === "}") {
  45005. break;
  45006. }
  45007. }
  45008. return hasCommas ? end : oldEnd;
  45009. }
  45010. var __defProp$3 = Object.defineProperty;
  45011. var __defProps$2 = Object.defineProperties;
  45012. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  45013. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  45014. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  45015. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  45016. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45017. var __spreadValues$3 = (a, b) => {
  45018. for (var prop in b || (b = {}))
  45019. if (__hasOwnProp$3.call(b, prop))
  45020. __defNormalProp$3(a, prop, b[prop]);
  45021. if (__getOwnPropSymbols$3)
  45022. for (var prop of __getOwnPropSymbols$3(b)) {
  45023. if (__propIsEnum$3.call(b, prop))
  45024. __defNormalProp$3(a, prop, b[prop]);
  45025. }
  45026. return a;
  45027. };
  45028. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  45029. const normalScriptDefaultVar = `__default__`;
  45030. function processNormalScript(ctx, scopeId) {
  45031. var _a;
  45032. const script = ctx.descriptor.script;
  45033. try {
  45034. let content = script.content;
  45035. let map = script.map;
  45036. const scriptAst = ctx.scriptAst;
  45037. const bindings = analyzeScriptBindings(scriptAst.body);
  45038. const { cssVars } = ctx.descriptor;
  45039. const { genDefaultAs, isProd } = ctx.options;
  45040. if (cssVars.length || genDefaultAs) {
  45041. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  45042. const s = new MagicString(content);
  45043. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  45044. content = s.toString();
  45045. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  45046. content += genNormalScriptCssVarsCode(
  45047. cssVars,
  45048. bindings,
  45049. scopeId,
  45050. !!isProd,
  45051. defaultVar
  45052. );
  45053. }
  45054. if (!genDefaultAs) {
  45055. content += `
  45056. export default ${defaultVar}`;
  45057. }
  45058. }
  45059. return __spreadProps$2(__spreadValues$3({}, script), {
  45060. content,
  45061. map,
  45062. bindings,
  45063. scriptAst: scriptAst.body
  45064. });
  45065. } catch (e) {
  45066. return script;
  45067. }
  45068. }
  45069. var __defProp$2 = Object.defineProperty;
  45070. var __defProps$1 = Object.defineProperties;
  45071. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  45072. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  45073. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  45074. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  45075. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45076. var __spreadValues$2 = (a, b) => {
  45077. for (var prop in b || (b = {}))
  45078. if (__hasOwnProp$2.call(b, prop))
  45079. __defNormalProp$2(a, prop, b[prop]);
  45080. if (__getOwnPropSymbols$2)
  45081. for (var prop of __getOwnPropSymbols$2(b)) {
  45082. if (__propIsEnum$2.call(b, prop))
  45083. __defNormalProp$2(a, prop, b[prop]);
  45084. }
  45085. return a;
  45086. };
  45087. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  45088. class TypeScope {
  45089. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  45090. this.filename = filename;
  45091. this.source = source;
  45092. this.offset = offset;
  45093. this.imports = imports;
  45094. this.types = types;
  45095. this.declares = declares;
  45096. this.isGenericScope = false;
  45097. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  45098. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  45099. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  45100. }
  45101. }
  45102. function resolveTypeElements(ctx, node, scope, typeParameters) {
  45103. const canCache = !typeParameters;
  45104. if (canCache && node._resolvedElements) {
  45105. return node._resolvedElements;
  45106. }
  45107. const resolved = innerResolveTypeElements(
  45108. ctx,
  45109. node,
  45110. node._ownerScope || scope || ctxToScope(ctx),
  45111. typeParameters
  45112. );
  45113. return canCache ? node._resolvedElements = resolved : resolved;
  45114. }
  45115. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  45116. var _a, _b;
  45117. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  45118. return { props: {} };
  45119. }
  45120. switch (node.type) {
  45121. case "TSTypeLiteral":
  45122. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  45123. case "TSInterfaceDeclaration":
  45124. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  45125. case "TSTypeAliasDeclaration":
  45126. case "TSTypeAnnotation":
  45127. case "TSParenthesizedType":
  45128. return resolveTypeElements(
  45129. ctx,
  45130. node.typeAnnotation,
  45131. scope,
  45132. typeParameters
  45133. );
  45134. case "TSFunctionType": {
  45135. return { props: {}, calls: [node] };
  45136. }
  45137. case "TSUnionType":
  45138. case "TSIntersectionType":
  45139. return mergeElements(
  45140. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  45141. node.type
  45142. );
  45143. case "TSMappedType":
  45144. return resolveMappedType(ctx, node, scope, typeParameters);
  45145. case "TSIndexedAccessType": {
  45146. const types = resolveIndexType(ctx, node, scope);
  45147. return mergeElements(
  45148. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  45149. "TSUnionType"
  45150. );
  45151. }
  45152. case "TSExpressionWithTypeArguments":
  45153. // referenced by interface extends
  45154. case "TSTypeReference": {
  45155. const typeName = getReferenceName(node);
  45156. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  45157. return resolveExtractPropTypes(
  45158. resolveTypeElements(
  45159. ctx,
  45160. node.typeParameters.params[0],
  45161. scope,
  45162. typeParameters
  45163. ),
  45164. scope
  45165. );
  45166. }
  45167. const resolved = resolveTypeReference(ctx, node, scope);
  45168. if (resolved) {
  45169. let typeParams;
  45170. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  45171. typeParams = /* @__PURE__ */ Object.create(null);
  45172. resolved.typeParameters.params.forEach((p, i) => {
  45173. let param = typeParameters && typeParameters[p.name];
  45174. if (!param) param = node.typeParameters.params[i];
  45175. typeParams[p.name] = param;
  45176. });
  45177. }
  45178. return resolveTypeElements(
  45179. ctx,
  45180. resolved,
  45181. resolved._ownerScope,
  45182. typeParams
  45183. );
  45184. } else {
  45185. if (typeof typeName === "string") {
  45186. if (typeParameters && typeParameters[typeName]) {
  45187. return resolveTypeElements(
  45188. ctx,
  45189. typeParameters[typeName],
  45190. scope,
  45191. typeParameters
  45192. );
  45193. }
  45194. if (
  45195. // @ts-expect-error
  45196. SupportedBuiltinsSet.has(typeName)
  45197. ) {
  45198. return resolveBuiltin(
  45199. ctx,
  45200. node,
  45201. typeName,
  45202. scope,
  45203. typeParameters
  45204. );
  45205. } else if (typeName === "ReturnType" && node.typeParameters) {
  45206. const ret = resolveReturnType(
  45207. ctx,
  45208. node.typeParameters.params[0],
  45209. scope
  45210. );
  45211. if (ret) {
  45212. return resolveTypeElements(ctx, ret, scope);
  45213. }
  45214. }
  45215. }
  45216. return ctx.error(
  45217. `Unresolvable type reference or unsupported built-in utility type`,
  45218. node,
  45219. scope
  45220. );
  45221. }
  45222. }
  45223. case "TSImportType": {
  45224. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  45225. return resolveExtractPropTypes(
  45226. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  45227. scope
  45228. );
  45229. }
  45230. const sourceScope = importSourceToScope(
  45231. ctx,
  45232. node.argument,
  45233. scope,
  45234. node.argument.value
  45235. );
  45236. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45237. if (resolved) {
  45238. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45239. }
  45240. break;
  45241. }
  45242. case "TSTypeQuery":
  45243. {
  45244. const resolved = resolveTypeReference(ctx, node, scope);
  45245. if (resolved) {
  45246. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45247. }
  45248. }
  45249. break;
  45250. }
  45251. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  45252. }
  45253. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  45254. const res = { props: {} };
  45255. for (const e of elements) {
  45256. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  45257. if (typeParameters) {
  45258. scope = createChildScope(scope);
  45259. scope.isGenericScope = true;
  45260. Object.assign(scope.types, typeParameters);
  45261. }
  45262. e._ownerScope = scope;
  45263. const name = getStringLiteralKey(e);
  45264. if (name !== null) {
  45265. res.props[name] = e;
  45266. } else {
  45267. ctx.error(
  45268. `Unsupported computed key in type referenced by a macro`,
  45269. e.key,
  45270. scope
  45271. );
  45272. }
  45273. } else if (e.type === "TSCallSignatureDeclaration") {
  45274. (res.calls || (res.calls = [])).push(e);
  45275. }
  45276. }
  45277. return res;
  45278. }
  45279. function mergeElements(maps, type) {
  45280. if (maps.length === 1) return maps[0];
  45281. const res = { props: {} };
  45282. const { props: baseProps } = res;
  45283. for (const { props, calls } of maps) {
  45284. for (const key in props) {
  45285. if (!hasOwn(baseProps, key)) {
  45286. baseProps[key] = props[key];
  45287. } else {
  45288. baseProps[key] = createProperty(
  45289. baseProps[key].key,
  45290. {
  45291. type,
  45292. // @ts-expect-error
  45293. types: [baseProps[key], props[key]]
  45294. },
  45295. baseProps[key]._ownerScope,
  45296. baseProps[key].optional || props[key].optional
  45297. );
  45298. }
  45299. }
  45300. if (calls) {
  45301. (res.calls || (res.calls = [])).push(...calls);
  45302. }
  45303. }
  45304. return res;
  45305. }
  45306. function createProperty(key, typeAnnotation, scope, optional) {
  45307. return {
  45308. type: "TSPropertySignature",
  45309. key,
  45310. kind: "get",
  45311. optional,
  45312. typeAnnotation: {
  45313. type: "TSTypeAnnotation",
  45314. typeAnnotation
  45315. },
  45316. _ownerScope: scope
  45317. };
  45318. }
  45319. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  45320. const base = typeElementsToMap(
  45321. ctx,
  45322. node.body.body,
  45323. node._ownerScope,
  45324. typeParameters
  45325. );
  45326. if (node.extends) {
  45327. for (const ext of node.extends) {
  45328. try {
  45329. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  45330. for (const key in props) {
  45331. if (!hasOwn(base.props, key)) {
  45332. base.props[key] = props[key];
  45333. }
  45334. }
  45335. if (calls) {
  45336. ;
  45337. (base.calls || (base.calls = [])).push(...calls);
  45338. }
  45339. } catch (e) {
  45340. if (!ctx.silentOnExtendsFailure) {
  45341. ctx.error(
  45342. `Failed to resolve extends base type.
  45343. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  45344. interface Props extends /* @vue-ignore */ Base {}
  45345. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  45346. ext,
  45347. scope
  45348. );
  45349. }
  45350. }
  45351. }
  45352. }
  45353. return base;
  45354. }
  45355. function resolveMappedType(ctx, node, scope, typeParameters) {
  45356. const res = { props: {} };
  45357. let keys;
  45358. if (node.nameType) {
  45359. const { name, constraint } = node.typeParameter;
  45360. scope = createChildScope(scope);
  45361. Object.assign(scope.types, __spreadProps$1(__spreadValues$2({}, typeParameters), { [name]: constraint }));
  45362. keys = resolveStringType(ctx, node.nameType, scope);
  45363. } else {
  45364. keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  45365. }
  45366. for (const key of keys) {
  45367. res.props[key] = createProperty(
  45368. {
  45369. type: "Identifier",
  45370. name: key
  45371. },
  45372. node.typeAnnotation,
  45373. scope,
  45374. !!node.optional
  45375. );
  45376. }
  45377. return res;
  45378. }
  45379. function resolveIndexType(ctx, node, scope) {
  45380. var _a, _b;
  45381. if (node.indexType.type === "TSNumberKeyword") {
  45382. return resolveArrayElementType(ctx, node.objectType, scope);
  45383. }
  45384. const { indexType, objectType } = node;
  45385. const types = [];
  45386. let keys;
  45387. let resolved;
  45388. if (indexType.type === "TSStringKeyword") {
  45389. resolved = resolveTypeElements(ctx, objectType, scope);
  45390. keys = Object.keys(resolved.props);
  45391. } else {
  45392. keys = resolveStringType(ctx, indexType, scope);
  45393. resolved = resolveTypeElements(ctx, objectType, scope);
  45394. }
  45395. for (const key of keys) {
  45396. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45397. if (targetType) {
  45398. targetType._ownerScope = resolved.props[key]._ownerScope;
  45399. types.push(targetType);
  45400. }
  45401. }
  45402. return types;
  45403. }
  45404. function resolveArrayElementType(ctx, node, scope) {
  45405. if (node.type === "TSArrayType") {
  45406. return [node.elementType];
  45407. }
  45408. if (node.type === "TSTupleType") {
  45409. return node.elementTypes.map(
  45410. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45411. );
  45412. }
  45413. if (node.type === "TSTypeReference") {
  45414. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45415. return node.typeParameters.params;
  45416. } else {
  45417. const resolved = resolveTypeReference(ctx, node, scope);
  45418. if (resolved) {
  45419. return resolveArrayElementType(ctx, resolved, scope);
  45420. }
  45421. }
  45422. }
  45423. return ctx.error(
  45424. "Failed to resolve element type from target type",
  45425. node,
  45426. scope
  45427. );
  45428. }
  45429. function resolveStringType(ctx, node, scope, typeParameters) {
  45430. switch (node.type) {
  45431. case "StringLiteral":
  45432. return [node.value];
  45433. case "TSLiteralType":
  45434. return resolveStringType(ctx, node.literal, scope, typeParameters);
  45435. case "TSUnionType":
  45436. return node.types.map((t) => resolveStringType(ctx, t, scope, typeParameters)).flat();
  45437. case "TemplateLiteral": {
  45438. return resolveTemplateKeys(ctx, node, scope);
  45439. }
  45440. case "TSTypeReference": {
  45441. const resolved = resolveTypeReference(ctx, node, scope);
  45442. if (resolved) {
  45443. return resolveStringType(ctx, resolved, scope, typeParameters);
  45444. }
  45445. if (node.typeName.type === "Identifier") {
  45446. const name = node.typeName.name;
  45447. if (typeParameters && typeParameters[name]) {
  45448. return resolveStringType(
  45449. ctx,
  45450. typeParameters[name],
  45451. scope,
  45452. typeParameters
  45453. );
  45454. }
  45455. const getParam = (index = 0) => resolveStringType(
  45456. ctx,
  45457. node.typeParameters.params[index],
  45458. scope,
  45459. typeParameters
  45460. );
  45461. switch (name) {
  45462. case "Extract":
  45463. return getParam(1);
  45464. case "Exclude": {
  45465. const excluded = getParam(1);
  45466. return getParam().filter((s) => !excluded.includes(s));
  45467. }
  45468. case "Uppercase":
  45469. return getParam().map((s) => s.toUpperCase());
  45470. case "Lowercase":
  45471. return getParam().map((s) => s.toLowerCase());
  45472. case "Capitalize":
  45473. return getParam().map(capitalize);
  45474. case "Uncapitalize":
  45475. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45476. default:
  45477. ctx.error(
  45478. "Unsupported type when resolving index type",
  45479. node.typeName,
  45480. scope
  45481. );
  45482. }
  45483. }
  45484. }
  45485. }
  45486. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45487. }
  45488. function resolveTemplateKeys(ctx, node, scope) {
  45489. if (!node.expressions.length) {
  45490. return [node.quasis[0].value.raw];
  45491. }
  45492. const res = [];
  45493. const e = node.expressions[0];
  45494. const q = node.quasis[0];
  45495. const leading = q ? q.value.raw : ``;
  45496. const resolved = resolveStringType(ctx, e, scope);
  45497. const restResolved = resolveTemplateKeys(
  45498. ctx,
  45499. __spreadProps$1(__spreadValues$2({}, node), {
  45500. expressions: node.expressions.slice(1),
  45501. quasis: q ? node.quasis.slice(1) : node.quasis
  45502. }),
  45503. scope
  45504. );
  45505. for (const r of resolved) {
  45506. for (const rr of restResolved) {
  45507. res.push(leading + r + rr);
  45508. }
  45509. }
  45510. return res;
  45511. }
  45512. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45513. "Partial",
  45514. "Required",
  45515. "Readonly",
  45516. "Pick",
  45517. "Omit"
  45518. ]);
  45519. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45520. const t = resolveTypeElements(
  45521. ctx,
  45522. node.typeParameters.params[0],
  45523. scope,
  45524. typeParameters
  45525. );
  45526. switch (name) {
  45527. case "Partial": {
  45528. const res2 = { props: {}, calls: t.calls };
  45529. Object.keys(t.props).forEach((key) => {
  45530. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: true });
  45531. });
  45532. return res2;
  45533. }
  45534. case "Required": {
  45535. const res2 = { props: {}, calls: t.calls };
  45536. Object.keys(t.props).forEach((key) => {
  45537. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: false });
  45538. });
  45539. return res2;
  45540. }
  45541. case "Readonly":
  45542. return t;
  45543. case "Pick": {
  45544. const picked = resolveStringType(
  45545. ctx,
  45546. node.typeParameters.params[1],
  45547. scope,
  45548. typeParameters
  45549. );
  45550. const res2 = { props: {}, calls: t.calls };
  45551. for (const key of picked) {
  45552. res2.props[key] = t.props[key];
  45553. }
  45554. return res2;
  45555. }
  45556. case "Omit":
  45557. const omitted = resolveStringType(
  45558. ctx,
  45559. node.typeParameters.params[1],
  45560. scope,
  45561. typeParameters
  45562. );
  45563. const res = { props: {}, calls: t.calls };
  45564. for (const key in t.props) {
  45565. if (!omitted.includes(key)) {
  45566. res.props[key] = t.props[key];
  45567. }
  45568. }
  45569. return res;
  45570. }
  45571. }
  45572. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45573. const canCache = !(scope == null ? void 0 : scope.isGenericScope);
  45574. if (canCache && node._resolvedReference) {
  45575. return node._resolvedReference;
  45576. }
  45577. const resolved = innerResolveTypeReference(
  45578. ctx,
  45579. scope || ctxToScope(ctx),
  45580. name || getReferenceName(node),
  45581. node,
  45582. onlyExported
  45583. );
  45584. return canCache ? node._resolvedReference = resolved : resolved;
  45585. }
  45586. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45587. if (typeof name === "string") {
  45588. if (scope.imports[name]) {
  45589. return resolveTypeFromImport(ctx, node, name, scope);
  45590. } else {
  45591. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45592. if (lookupSource[name]) {
  45593. return lookupSource[name];
  45594. } else {
  45595. const globalScopes = resolveGlobalScope(ctx);
  45596. if (globalScopes) {
  45597. for (const s of globalScopes) {
  45598. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45599. if (src[name]) {
  45600. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45601. return src[name];
  45602. }
  45603. }
  45604. }
  45605. }
  45606. }
  45607. } else {
  45608. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45609. if (ns) {
  45610. if (ns.type !== "TSModuleDeclaration") {
  45611. ns = ns._ns;
  45612. }
  45613. if (ns) {
  45614. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45615. return innerResolveTypeReference(
  45616. ctx,
  45617. childScope,
  45618. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45619. node,
  45620. !ns.declare
  45621. );
  45622. }
  45623. }
  45624. }
  45625. }
  45626. function getReferenceName(node) {
  45627. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45628. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45629. return ref.name;
  45630. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45631. return qualifiedNameToPath(ref);
  45632. } else {
  45633. return "default";
  45634. }
  45635. }
  45636. function qualifiedNameToPath(node) {
  45637. if (node.type === "Identifier") {
  45638. return [node.name];
  45639. } else {
  45640. return [...qualifiedNameToPath(node.left), node.right.name];
  45641. }
  45642. }
  45643. function resolveGlobalScope(ctx) {
  45644. if (ctx.options.globalTypeFiles) {
  45645. const fs = resolveFS(ctx);
  45646. if (!fs) {
  45647. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45648. }
  45649. return ctx.options.globalTypeFiles.map(
  45650. (file) => fileToScope(ctx, normalizePath(file), true)
  45651. );
  45652. }
  45653. }
  45654. let ts;
  45655. let loadTS;
  45656. function registerTS(_loadTS) {
  45657. loadTS = () => {
  45658. try {
  45659. return _loadTS();
  45660. } catch (err) {
  45661. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45662. throw new Error(
  45663. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
  45664. );
  45665. } else {
  45666. throw new Error(
  45667. "Failed to load TypeScript for resolving imported types."
  45668. );
  45669. }
  45670. }
  45671. };
  45672. }
  45673. function resolveFS(ctx) {
  45674. if (ctx.fs) {
  45675. return ctx.fs;
  45676. }
  45677. if (!ts && loadTS) {
  45678. ts = loadTS();
  45679. }
  45680. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45681. if (!fs) {
  45682. return;
  45683. }
  45684. return ctx.fs = {
  45685. fileExists(file) {
  45686. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45687. file = file.replace(/\.ts$/, "");
  45688. }
  45689. return fs.fileExists(file);
  45690. },
  45691. readFile(file) {
  45692. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45693. file = file.replace(/\.ts$/, "");
  45694. }
  45695. return fs.readFile(file);
  45696. },
  45697. realpath: fs.realpath
  45698. };
  45699. }
  45700. function resolveTypeFromImport(ctx, node, name, scope) {
  45701. const { source, imported } = scope.imports[name];
  45702. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45703. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45704. }
  45705. function importSourceToScope(ctx, node, scope, source) {
  45706. let fs;
  45707. try {
  45708. fs = resolveFS(ctx);
  45709. } catch (err) {
  45710. return ctx.error(err.message, node, scope);
  45711. }
  45712. if (!fs) {
  45713. return ctx.error(
  45714. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45715. node,
  45716. scope
  45717. );
  45718. }
  45719. let resolved = scope.resolvedImportSources[source];
  45720. if (!resolved) {
  45721. if (source.startsWith("..")) {
  45722. const osSpecificJoinFn = joinPaths;
  45723. const filename = osSpecificJoinFn(dirname(scope.filename), source);
  45724. resolved = resolveExt(filename, fs);
  45725. } else if (source[0] === ".") {
  45726. const filename = joinPaths(dirname(scope.filename), source);
  45727. resolved = resolveExt(filename, fs);
  45728. } else {
  45729. {
  45730. return ctx.error(
  45731. `Type import from non-relative sources is not supported in the browser build.`,
  45732. node,
  45733. scope
  45734. );
  45735. }
  45736. }
  45737. if (resolved) {
  45738. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45739. }
  45740. }
  45741. if (resolved) {
  45742. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45743. return fileToScope(ctx, resolved);
  45744. } else {
  45745. return ctx.error(
  45746. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45747. node,
  45748. scope
  45749. );
  45750. }
  45751. }
  45752. function resolveExt(filename, fs) {
  45753. let moduleType = "u";
  45754. if (filename.endsWith(".mjs")) {
  45755. moduleType = "m";
  45756. } else if (filename.endsWith(".cjs")) {
  45757. moduleType = "c";
  45758. }
  45759. filename = filename.replace(/\.[cm]?jsx?$/, "");
  45760. const tryResolve = (filename2) => {
  45761. if (fs.fileExists(filename2)) return filename2;
  45762. };
  45763. const resolveTs = () => tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`);
  45764. const resolveMts = () => tryResolve(filename + `.mts`) || tryResolve(filename + `.d.mts`);
  45765. const resolveCts = () => tryResolve(filename + `.cts`) || tryResolve(filename + `.d.cts`);
  45766. return tryResolve(filename) || // For explicit .mjs/.cjs imports, prefer .mts/.cts declarations first.
  45767. (moduleType === "m" ? resolveMts() || resolveTs() : moduleType === "c" ? resolveCts() || resolveTs() : resolveTs() || resolveMts() || resolveCts()) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.tsx`)) || tryResolve(joinPaths(filename, `index.d.ts`));
  45768. }
  45769. const tsConfigCache = createCache();
  45770. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45771. const fileToScopeCache = createCache();
  45772. function invalidateTypeCache(filename) {
  45773. filename = normalizePath(filename);
  45774. fileToScopeCache.delete(filename);
  45775. tsConfigCache.delete(filename);
  45776. const affectedConfig = tsConfigRefMap.get(filename);
  45777. if (affectedConfig) tsConfigCache.delete(affectedConfig);
  45778. }
  45779. function fileToScope(ctx, filename, asGlobal = false) {
  45780. const cached = fileToScopeCache.get(filename);
  45781. if (cached) {
  45782. return cached;
  45783. }
  45784. const fs = resolveFS(ctx);
  45785. const source = fs.readFile(filename) || "";
  45786. const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
  45787. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45788. recordTypes(ctx, body, scope, asGlobal);
  45789. fileToScopeCache.set(filename, scope);
  45790. return scope;
  45791. }
  45792. function parseFile(filename, content, fs, parserPlugins) {
  45793. const ext = extname(filename);
  45794. if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".cts" || ext === ".mtsx") {
  45795. return libExports.parse(content, {
  45796. plugins: resolveParserPlugins(
  45797. ext.slice(1),
  45798. parserPlugins,
  45799. /\.d\.[cm]?ts$/.test(filename)
  45800. ),
  45801. sourceType: "module"
  45802. }).program.body;
  45803. }
  45804. const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
  45805. const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
  45806. const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
  45807. if (hasArbitraryTypeDeclaration) {
  45808. return libExports.parse(fs.readFile(arbitraryTypeSource), {
  45809. plugins: resolveParserPlugins("ts", parserPlugins, true),
  45810. sourceType: "module"
  45811. }).program.body;
  45812. }
  45813. if (ext === ".vue") {
  45814. const {
  45815. descriptor: { script, scriptSetup }
  45816. } = parse$2(content);
  45817. if (!script && !scriptSetup) {
  45818. return [];
  45819. }
  45820. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45821. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45822. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45823. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45824. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45825. if (secondBlock) {
  45826. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45827. }
  45828. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45829. return libExports.parse(scriptContent, {
  45830. plugins: resolveParserPlugins(lang, parserPlugins),
  45831. sourceType: "module"
  45832. }).program.body;
  45833. }
  45834. return [];
  45835. }
  45836. function ctxToScope(ctx) {
  45837. if (ctx.scope) {
  45838. return ctx.scope;
  45839. }
  45840. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45841. const scope = new TypeScope(
  45842. ctx.filename,
  45843. ctx.source,
  45844. "startOffset" in ctx ? ctx.startOffset : 0,
  45845. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45846. );
  45847. recordTypes(ctx, body, scope);
  45848. return ctx.scope = scope;
  45849. }
  45850. function moduleDeclToScope(ctx, node, parentScope) {
  45851. if (node._resolvedChildScope) {
  45852. return node._resolvedChildScope;
  45853. }
  45854. const scope = createChildScope(parentScope);
  45855. if (node.body.type === "TSModuleDeclaration") {
  45856. const decl = node.body;
  45857. decl._ownerScope = scope;
  45858. const id = getId(decl.id);
  45859. scope.types[id] = scope.exportedTypes[id] = decl;
  45860. } else {
  45861. recordTypes(ctx, node.body.body, scope);
  45862. }
  45863. return node._resolvedChildScope = scope;
  45864. }
  45865. function createChildScope(parentScope) {
  45866. return new TypeScope(
  45867. parentScope.filename,
  45868. parentScope.source,
  45869. parentScope.offset,
  45870. Object.create(parentScope.imports),
  45871. Object.create(parentScope.types),
  45872. Object.create(parentScope.declares)
  45873. );
  45874. }
  45875. const importExportRE = /^Import|^Export/;
  45876. function recordTypes(ctx, body, scope, asGlobal = false) {
  45877. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45878. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45879. for (const stmt of body) {
  45880. if (asGlobal) {
  45881. if (isAmbient) {
  45882. if (stmt.declare) {
  45883. recordType(stmt, types, declares);
  45884. }
  45885. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45886. for (const s of stmt.body.body) {
  45887. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  45888. recordType(s.declaration, types, declares);
  45889. } else {
  45890. recordType(s, types, declares);
  45891. }
  45892. }
  45893. }
  45894. } else {
  45895. recordType(stmt, types, declares);
  45896. }
  45897. }
  45898. if (!asGlobal) {
  45899. for (const stmt of body) {
  45900. if (stmt.type === "ExportNamedDeclaration") {
  45901. if (stmt.declaration) {
  45902. recordType(stmt.declaration, types, declares);
  45903. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45904. } else {
  45905. for (const spec of stmt.specifiers) {
  45906. if (spec.type === "ExportSpecifier") {
  45907. const local = spec.local.name;
  45908. const exported = getId(spec.exported);
  45909. if (stmt.source) {
  45910. imports[exported] = {
  45911. source: stmt.source.value,
  45912. imported: local
  45913. };
  45914. exportedTypes[exported] = {
  45915. type: "TSTypeReference",
  45916. typeName: {
  45917. type: "Identifier",
  45918. name: local
  45919. },
  45920. _ownerScope: scope
  45921. };
  45922. } else if (types[local]) {
  45923. exportedTypes[exported] = types[local];
  45924. }
  45925. }
  45926. }
  45927. }
  45928. } else if (stmt.type === "ExportAllDeclaration") {
  45929. const sourceScope = importSourceToScope(
  45930. ctx,
  45931. stmt.source,
  45932. scope,
  45933. stmt.source.value
  45934. );
  45935. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45936. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45937. if (stmt.declaration.type !== "Identifier") {
  45938. recordType(stmt.declaration, types, declares, "default");
  45939. recordType(
  45940. stmt.declaration,
  45941. exportedTypes,
  45942. exportedDeclares,
  45943. "default"
  45944. );
  45945. } else if (types[stmt.declaration.name]) {
  45946. exportedTypes["default"] = types[stmt.declaration.name];
  45947. }
  45948. }
  45949. }
  45950. }
  45951. for (const key of Object.keys(types)) {
  45952. const node = types[key];
  45953. node._ownerScope = scope;
  45954. if (node._ns) node._ns._ownerScope = scope;
  45955. }
  45956. for (const key of Object.keys(declares)) {
  45957. declares[key]._ownerScope = scope;
  45958. }
  45959. }
  45960. function recordType(node, types, declares, overwriteId) {
  45961. switch (node.type) {
  45962. case "TSInterfaceDeclaration":
  45963. case "TSEnumDeclaration":
  45964. case "TSModuleDeclaration": {
  45965. if (node.type === "TSModuleDeclaration" && node.global) {
  45966. const body = node.body;
  45967. for (const s of body.body) {
  45968. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  45969. recordType(s.declaration, types, declares);
  45970. } else {
  45971. recordType(s, types, declares);
  45972. }
  45973. }
  45974. break;
  45975. }
  45976. const id = overwriteId || getId(node.id);
  45977. let existing = types[id];
  45978. if (existing) {
  45979. if (node.type === "TSModuleDeclaration") {
  45980. if (existing.type === "TSModuleDeclaration") {
  45981. mergeNamespaces(existing, node);
  45982. } else {
  45983. attachNamespace(existing, node);
  45984. }
  45985. break;
  45986. }
  45987. if (existing.type === "TSModuleDeclaration") {
  45988. types[id] = node;
  45989. attachNamespace(node, existing);
  45990. break;
  45991. }
  45992. if (existing.type !== node.type) {
  45993. break;
  45994. }
  45995. if (node.type === "TSInterfaceDeclaration") {
  45996. existing.body.body.push(...node.body.body);
  45997. } else {
  45998. existing.members.push(...node.members);
  45999. }
  46000. } else {
  46001. types[id] = node;
  46002. }
  46003. break;
  46004. }
  46005. case "ClassDeclaration":
  46006. if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
  46007. break;
  46008. case "TSTypeAliasDeclaration":
  46009. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  46010. break;
  46011. case "TSDeclareFunction":
  46012. if (node.id) declares[node.id.name] = node;
  46013. break;
  46014. case "VariableDeclaration": {
  46015. if (node.declare) {
  46016. for (const decl of node.declarations) {
  46017. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  46018. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  46019. }
  46020. }
  46021. }
  46022. break;
  46023. }
  46024. }
  46025. }
  46026. function mergeNamespaces(to, from) {
  46027. const toBody = to.body;
  46028. const fromBody = from.body;
  46029. if (toBody.type === "TSModuleDeclaration") {
  46030. if (fromBody.type === "TSModuleDeclaration") {
  46031. mergeNamespaces(toBody, fromBody);
  46032. } else {
  46033. fromBody.body.push({
  46034. type: "ExportNamedDeclaration",
  46035. declaration: toBody,
  46036. exportKind: "type",
  46037. specifiers: []
  46038. });
  46039. }
  46040. } else if (fromBody.type === "TSModuleDeclaration") {
  46041. toBody.body.push({
  46042. type: "ExportNamedDeclaration",
  46043. declaration: fromBody,
  46044. exportKind: "type",
  46045. specifiers: []
  46046. });
  46047. } else {
  46048. toBody.body.push(...fromBody.body);
  46049. }
  46050. }
  46051. function attachNamespace(to, ns) {
  46052. if (!to._ns) {
  46053. to._ns = ns;
  46054. } else {
  46055. mergeNamespaces(to._ns, ns);
  46056. }
  46057. }
  46058. function recordImports(body) {
  46059. const imports = /* @__PURE__ */ Object.create(null);
  46060. for (const s of body) {
  46061. recordImport(s, imports);
  46062. }
  46063. return imports;
  46064. }
  46065. function recordImport(node, imports) {
  46066. if (node.type !== "ImportDeclaration") {
  46067. return;
  46068. }
  46069. for (const s of node.specifiers) {
  46070. imports[s.local.name] = {
  46071. imported: getImportedName(s),
  46072. source: node.source.value
  46073. };
  46074. }
  46075. }
  46076. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
  46077. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  46078. return [UNKNOWN_TYPE];
  46079. }
  46080. const prevSilent = ctx.silentOnExtendsFailure;
  46081. ctx.silentOnExtendsFailure = true;
  46082. try {
  46083. switch (node.type) {
  46084. case "TSStringKeyword":
  46085. return ["String"];
  46086. case "TSNumberKeyword":
  46087. return ["Number"];
  46088. case "TSBooleanKeyword":
  46089. return ["Boolean"];
  46090. case "TSObjectKeyword":
  46091. return ["Object"];
  46092. case "TSNullKeyword":
  46093. return ["null"];
  46094. case "TSTypeLiteral":
  46095. case "TSInterfaceDeclaration": {
  46096. const types = /* @__PURE__ */ new Set();
  46097. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  46098. for (const m of members) {
  46099. if (isKeyOf) {
  46100. if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
  46101. types.add("Number");
  46102. } else if (m.type === "TSIndexSignature") {
  46103. const annotation = m.parameters[0].typeAnnotation;
  46104. if (annotation && annotation.type !== "Noop") {
  46105. const type = inferRuntimeType(
  46106. ctx,
  46107. annotation.typeAnnotation,
  46108. scope
  46109. )[0];
  46110. if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
  46111. types.add(type);
  46112. }
  46113. } else {
  46114. types.add("String");
  46115. }
  46116. } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  46117. types.add("Function");
  46118. } else {
  46119. types.add("Object");
  46120. }
  46121. }
  46122. return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
  46123. }
  46124. case "TSPropertySignature":
  46125. if (node.typeAnnotation) {
  46126. return inferRuntimeType(
  46127. ctx,
  46128. node.typeAnnotation.typeAnnotation,
  46129. scope
  46130. );
  46131. }
  46132. break;
  46133. case "TSMethodSignature":
  46134. case "TSFunctionType":
  46135. return ["Function"];
  46136. case "TSArrayType":
  46137. case "TSTupleType":
  46138. return ["Array"];
  46139. case "TSLiteralType":
  46140. switch (node.literal.type) {
  46141. case "StringLiteral":
  46142. return ["String"];
  46143. case "BooleanLiteral":
  46144. return ["Boolean"];
  46145. case "NumericLiteral":
  46146. case "BigIntLiteral":
  46147. return ["Number"];
  46148. default:
  46149. return [UNKNOWN_TYPE];
  46150. }
  46151. case "TSTypeReference": {
  46152. const resolved = resolveTypeReference(ctx, node, scope);
  46153. if (resolved) {
  46154. if (resolved.type === "TSTypeAliasDeclaration") {
  46155. if (resolved.typeAnnotation.type === "TSFunctionType") {
  46156. return ["Function"];
  46157. }
  46158. if (node.typeParameters) {
  46159. const typeParams = /* @__PURE__ */ Object.create(null);
  46160. if (resolved.typeParameters) {
  46161. resolved.typeParameters.params.forEach((p, i) => {
  46162. typeParams[p.name] = node.typeParameters.params[i];
  46163. });
  46164. }
  46165. return inferRuntimeType(
  46166. ctx,
  46167. resolved.typeAnnotation,
  46168. resolved._ownerScope,
  46169. isKeyOf,
  46170. typeParams
  46171. );
  46172. }
  46173. }
  46174. return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
  46175. }
  46176. if (node.typeName.type === "Identifier") {
  46177. if (typeParameters && typeParameters[node.typeName.name]) {
  46178. return inferRuntimeType(
  46179. ctx,
  46180. typeParameters[node.typeName.name],
  46181. scope,
  46182. isKeyOf,
  46183. typeParameters
  46184. );
  46185. }
  46186. if (isKeyOf) {
  46187. switch (node.typeName.name) {
  46188. case "String":
  46189. case "Array":
  46190. case "ArrayLike":
  46191. case "Parameters":
  46192. case "ConstructorParameters":
  46193. case "ReadonlyArray":
  46194. return ["String", "Number"];
  46195. // TS built-in utility types
  46196. case "Record":
  46197. case "Partial":
  46198. case "Required":
  46199. case "Readonly":
  46200. if (node.typeParameters && node.typeParameters.params[0]) {
  46201. return inferRuntimeType(
  46202. ctx,
  46203. node.typeParameters.params[0],
  46204. scope,
  46205. true
  46206. );
  46207. }
  46208. break;
  46209. case "Pick":
  46210. case "Extract":
  46211. if (node.typeParameters && node.typeParameters.params[1]) {
  46212. return inferRuntimeType(
  46213. ctx,
  46214. node.typeParameters.params[1],
  46215. scope
  46216. );
  46217. }
  46218. break;
  46219. case "Function":
  46220. case "Object":
  46221. case "Set":
  46222. case "Map":
  46223. case "WeakSet":
  46224. case "WeakMap":
  46225. case "Date":
  46226. case "Promise":
  46227. case "Error":
  46228. case "Uppercase":
  46229. case "Lowercase":
  46230. case "Capitalize":
  46231. case "Uncapitalize":
  46232. case "ReadonlyMap":
  46233. case "ReadonlySet":
  46234. return ["String"];
  46235. }
  46236. } else {
  46237. switch (node.typeName.name) {
  46238. case "Array":
  46239. case "Function":
  46240. case "Object":
  46241. case "Set":
  46242. case "Map":
  46243. case "WeakSet":
  46244. case "WeakMap":
  46245. case "Date":
  46246. case "Promise":
  46247. case "Error":
  46248. return [node.typeName.name];
  46249. // TS built-in utility types
  46250. // https://www.typescriptlang.org/docs/handbook/utility-types.html
  46251. case "Partial":
  46252. case "Required":
  46253. case "Readonly":
  46254. case "Record":
  46255. case "Pick":
  46256. case "Omit":
  46257. case "InstanceType":
  46258. return ["Object"];
  46259. case "Uppercase":
  46260. case "Lowercase":
  46261. case "Capitalize":
  46262. case "Uncapitalize":
  46263. return ["String"];
  46264. case "Parameters":
  46265. case "ConstructorParameters":
  46266. case "ReadonlyArray":
  46267. return ["Array"];
  46268. case "ReadonlyMap":
  46269. return ["Map"];
  46270. case "ReadonlySet":
  46271. return ["Set"];
  46272. case "NonNullable":
  46273. if (node.typeParameters && node.typeParameters.params[0]) {
  46274. return inferRuntimeType(
  46275. ctx,
  46276. node.typeParameters.params[0],
  46277. scope
  46278. ).filter((t) => t !== "null");
  46279. }
  46280. break;
  46281. case "Extract":
  46282. if (node.typeParameters && node.typeParameters.params[1]) {
  46283. return inferRuntimeType(
  46284. ctx,
  46285. node.typeParameters.params[1],
  46286. scope
  46287. );
  46288. }
  46289. break;
  46290. case "Exclude":
  46291. case "OmitThisParameter":
  46292. if (node.typeParameters && node.typeParameters.params[0]) {
  46293. return inferRuntimeType(
  46294. ctx,
  46295. node.typeParameters.params[0],
  46296. scope
  46297. );
  46298. }
  46299. break;
  46300. }
  46301. }
  46302. }
  46303. break;
  46304. }
  46305. case "TSParenthesizedType":
  46306. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  46307. case "TSUnionType":
  46308. return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
  46309. case "TSIntersectionType": {
  46310. return flattenTypes(
  46311. ctx,
  46312. node.types,
  46313. scope,
  46314. isKeyOf,
  46315. typeParameters
  46316. ).filter((t) => t !== UNKNOWN_TYPE);
  46317. }
  46318. case "TSMappedType": {
  46319. const { typeAnnotation, typeParameter } = node;
  46320. if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
  46321. const constraint = typeParameter.constraint;
  46322. if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
  46323. const typeName = constraint.typeAnnotation.typeName.name;
  46324. const index = typeAnnotation.indexType;
  46325. const obj = typeAnnotation.objectType;
  46326. 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) {
  46327. const targetType = typeParameters[typeName];
  46328. if (targetType) {
  46329. return inferRuntimeType(ctx, targetType, scope);
  46330. }
  46331. }
  46332. }
  46333. }
  46334. return [UNKNOWN_TYPE];
  46335. }
  46336. case "TSEnumDeclaration":
  46337. return inferEnumType(node);
  46338. case "TSSymbolKeyword":
  46339. return ["Symbol"];
  46340. case "TSIndexedAccessType": {
  46341. const types = resolveIndexType(ctx, node, scope);
  46342. return flattenTypes(ctx, types, scope, isKeyOf);
  46343. }
  46344. case "ClassDeclaration":
  46345. return ["Object"];
  46346. case "TSImportType": {
  46347. const sourceScope = importSourceToScope(
  46348. ctx,
  46349. node.argument,
  46350. scope,
  46351. node.argument.value
  46352. );
  46353. const resolved = resolveTypeReference(ctx, node, sourceScope);
  46354. if (resolved) {
  46355. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  46356. }
  46357. break;
  46358. }
  46359. case "TSTypeQuery": {
  46360. const id = node.exprName;
  46361. if (id.type === "Identifier") {
  46362. const matched = scope.declares[id.name];
  46363. if (matched) {
  46364. return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
  46365. }
  46366. }
  46367. break;
  46368. }
  46369. // e.g. readonly
  46370. case "TSTypeOperator": {
  46371. return inferRuntimeType(
  46372. ctx,
  46373. node.typeAnnotation,
  46374. scope,
  46375. node.operator === "keyof"
  46376. );
  46377. }
  46378. case "TSAnyKeyword": {
  46379. if (isKeyOf) {
  46380. return ["String", "Number", "Symbol"];
  46381. }
  46382. break;
  46383. }
  46384. }
  46385. } catch (e) {
  46386. } finally {
  46387. ctx.silentOnExtendsFailure = prevSilent;
  46388. }
  46389. return [UNKNOWN_TYPE];
  46390. }
  46391. function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
  46392. if (types.length === 1) {
  46393. return inferRuntimeType(
  46394. ctx,
  46395. types[0],
  46396. types[0]._ownerScope || scope,
  46397. isKeyOf,
  46398. typeParameters
  46399. );
  46400. }
  46401. return [
  46402. ...new Set(
  46403. [].concat(
  46404. ...types.map(
  46405. (t) => inferRuntimeType(
  46406. ctx,
  46407. t,
  46408. t._ownerScope || scope,
  46409. isKeyOf,
  46410. typeParameters
  46411. )
  46412. )
  46413. )
  46414. )
  46415. ];
  46416. }
  46417. function inferEnumType(node) {
  46418. const types = /* @__PURE__ */ new Set();
  46419. for (const m of node.members) {
  46420. if (m.initializer) {
  46421. switch (m.initializer.type) {
  46422. case "StringLiteral":
  46423. types.add("String");
  46424. break;
  46425. case "NumericLiteral":
  46426. types.add("Number");
  46427. break;
  46428. }
  46429. }
  46430. }
  46431. return types.size ? [...types] : ["Number"];
  46432. }
  46433. function resolveExtractPropTypes({ props }, scope) {
  46434. const res = { props: {} };
  46435. for (const key in props) {
  46436. const raw = props[key];
  46437. res.props[key] = reverseInferType(
  46438. raw.key,
  46439. raw.typeAnnotation.typeAnnotation,
  46440. scope
  46441. );
  46442. }
  46443. return res;
  46444. }
  46445. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  46446. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  46447. const typeType = findStaticPropertyType(node, "type");
  46448. if (typeType) {
  46449. const requiredType = findStaticPropertyType(node, "required");
  46450. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  46451. return reverseInferType(key, typeType, scope, optional2, false);
  46452. }
  46453. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  46454. if (node.typeName.name.endsWith("Constructor")) {
  46455. return createProperty(
  46456. key,
  46457. ctorToType(node.typeName.name),
  46458. scope,
  46459. optional
  46460. );
  46461. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  46462. return createProperty(key, node.typeParameters.params[0], scope, optional);
  46463. }
  46464. }
  46465. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  46466. for (const t of node.typeParameters.params) {
  46467. const inferred = reverseInferType(key, t, scope, optional);
  46468. if (inferred) return inferred;
  46469. }
  46470. }
  46471. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  46472. }
  46473. function ctorToType(ctorType) {
  46474. const ctor = ctorType.slice(0, -11);
  46475. switch (ctor) {
  46476. case "String":
  46477. case "Number":
  46478. case "Boolean":
  46479. return { type: `TS${ctor}Keyword` };
  46480. case "Array":
  46481. case "Function":
  46482. case "Object":
  46483. case "Set":
  46484. case "Map":
  46485. case "WeakSet":
  46486. case "WeakMap":
  46487. case "Date":
  46488. case "Promise":
  46489. return {
  46490. type: "TSTypeReference",
  46491. typeName: { type: "Identifier", name: ctor }
  46492. };
  46493. }
  46494. return { type: `TSNullKeyword` };
  46495. }
  46496. function findStaticPropertyType(node, key) {
  46497. const prop = node.members.find(
  46498. (m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
  46499. );
  46500. return prop && prop.typeAnnotation.typeAnnotation;
  46501. }
  46502. function resolveReturnType(ctx, arg, scope) {
  46503. var _a;
  46504. let resolved = arg;
  46505. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  46506. resolved = resolveTypeReference(ctx, arg, scope);
  46507. }
  46508. if (!resolved) return;
  46509. if (resolved.type === "TSFunctionType") {
  46510. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  46511. }
  46512. if (resolved.type === "TSDeclareFunction") {
  46513. return resolved.returnType;
  46514. }
  46515. }
  46516. function resolveUnionType(ctx, node, scope) {
  46517. if (node.type === "TSTypeReference") {
  46518. const resolved = resolveTypeReference(ctx, node, scope);
  46519. if (resolved) node = resolved;
  46520. }
  46521. let types;
  46522. if (node.type === "TSUnionType") {
  46523. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  46524. } else {
  46525. types = [node];
  46526. }
  46527. return types;
  46528. }
  46529. const DEFINE_MODEL = "defineModel";
  46530. function processDefineModel(ctx, node, declId) {
  46531. if (!isCallOf(node, DEFINE_MODEL)) {
  46532. return false;
  46533. }
  46534. ctx.hasDefineModelCall = true;
  46535. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  46536. let modelName;
  46537. let options;
  46538. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  46539. const hasName = arg0 && (arg0.type === "StringLiteral" || arg0.type === "TemplateLiteral" && arg0.expressions.length === 0);
  46540. if (hasName) {
  46541. modelName = arg0.type === "StringLiteral" ? arg0.value : arg0.quasis[0].value.cooked;
  46542. options = node.arguments[1];
  46543. } else {
  46544. modelName = "modelValue";
  46545. options = arg0;
  46546. }
  46547. if (ctx.modelDecls[modelName]) {
  46548. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  46549. }
  46550. let optionsString = options && ctx.getString(options);
  46551. let optionsRemoved = !options;
  46552. const runtimeOptionNodes = [];
  46553. if (options && options.type === "ObjectExpression" && !options.properties.some((p) => p.type === "SpreadElement" || p.computed)) {
  46554. let removed = 0;
  46555. for (let i = options.properties.length - 1; i >= 0; i--) {
  46556. const p = options.properties[i];
  46557. const next = options.properties[i + 1];
  46558. const start = p.start;
  46559. const end = next ? next.start : options.end - 1;
  46560. 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"))) {
  46561. optionsString = optionsString.slice(0, start - options.start) + optionsString.slice(end - options.start);
  46562. } else {
  46563. removed++;
  46564. ctx.s.remove(ctx.startOffset + start, ctx.startOffset + end);
  46565. runtimeOptionNodes.push(p);
  46566. }
  46567. }
  46568. if (removed === options.properties.length) {
  46569. optionsRemoved = true;
  46570. ctx.s.remove(
  46571. ctx.startOffset + (hasName ? arg0.end : options.start),
  46572. ctx.startOffset + options.end
  46573. );
  46574. }
  46575. }
  46576. ctx.modelDecls[modelName] = {
  46577. type,
  46578. options: optionsString,
  46579. runtimeOptionNodes,
  46580. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  46581. };
  46582. ctx.bindingMetadata[modelName] = "props";
  46583. ctx.s.overwrite(
  46584. ctx.startOffset + node.callee.start,
  46585. ctx.startOffset + node.callee.end,
  46586. ctx.helper("useModel")
  46587. );
  46588. ctx.s.appendLeft(
  46589. ctx.startOffset + (node.arguments.length ? node.arguments[0].start : node.end - 1),
  46590. `__props, ` + (hasName ? `` : `${JSON.stringify(modelName)}${optionsRemoved ? `` : `, `}`)
  46591. );
  46592. return true;
  46593. }
  46594. function genModelProps(ctx) {
  46595. if (!ctx.hasDefineModelCall) return;
  46596. const isProd = !!ctx.options.isProd;
  46597. let modelPropsDecl = "";
  46598. for (const [name, { type, options: runtimeOptions }] of Object.entries(
  46599. ctx.modelDecls
  46600. )) {
  46601. let skipCheck = false;
  46602. let codegenOptions = ``;
  46603. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46604. if (runtimeTypes) {
  46605. const hasBoolean = runtimeTypes.includes("Boolean");
  46606. const hasFunction = runtimeTypes.includes("Function");
  46607. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46608. if (hasUnknownType) {
  46609. if (hasBoolean || hasFunction) {
  46610. runtimeTypes = runtimeTypes.filter((t) => t !== UNKNOWN_TYPE);
  46611. skipCheck = true;
  46612. } else {
  46613. runtimeTypes = ["null"];
  46614. }
  46615. }
  46616. if (!isProd) {
  46617. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}` + (skipCheck ? ", skipCheck: true" : "");
  46618. } else if (hasBoolean || runtimeOptions && hasFunction) {
  46619. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}`;
  46620. } else ;
  46621. }
  46622. let decl;
  46623. if (codegenOptions && runtimeOptions) {
  46624. decl = ctx.isTS ? `{ ${codegenOptions}, ...${runtimeOptions} }` : `Object.assign({ ${codegenOptions} }, ${runtimeOptions})`;
  46625. } else if (codegenOptions) {
  46626. decl = `{ ${codegenOptions} }`;
  46627. } else if (runtimeOptions) {
  46628. decl = runtimeOptions;
  46629. } else {
  46630. decl = `{}`;
  46631. }
  46632. modelPropsDecl += `
  46633. ${JSON.stringify(name)}: ${decl},`;
  46634. const modifierPropName = JSON.stringify(
  46635. name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
  46636. );
  46637. modelPropsDecl += `
  46638. ${modifierPropName}: {},`;
  46639. }
  46640. return `{${modelPropsDecl}
  46641. }`;
  46642. }
  46643. const DEFINE_PROPS = "defineProps";
  46644. const WITH_DEFAULTS = "withDefaults";
  46645. function processDefineProps(ctx, node, declId, isWithDefaults = false) {
  46646. if (!isCallOf(node, DEFINE_PROPS)) {
  46647. return processWithDefaults(ctx, node, declId);
  46648. }
  46649. if (ctx.hasDefinePropsCall) {
  46650. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46651. }
  46652. ctx.hasDefinePropsCall = true;
  46653. ctx.propsRuntimeDecl = node.arguments[0];
  46654. if (ctx.propsRuntimeDecl) {
  46655. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46656. if (!(key in ctx.bindingMetadata)) {
  46657. ctx.bindingMetadata[key] = "props";
  46658. }
  46659. }
  46660. }
  46661. if (node.typeParameters) {
  46662. if (ctx.propsRuntimeDecl) {
  46663. ctx.error(
  46664. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46665. node
  46666. );
  46667. }
  46668. ctx.propsTypeDecl = node.typeParameters.params[0];
  46669. }
  46670. if (!isWithDefaults && declId && declId.type === "ObjectPattern") {
  46671. processPropsDestructure(ctx, declId);
  46672. }
  46673. ctx.propsCall = node;
  46674. ctx.propsDecl = declId;
  46675. return true;
  46676. }
  46677. function processWithDefaults(ctx, node, declId) {
  46678. if (!isCallOf(node, WITH_DEFAULTS)) {
  46679. return false;
  46680. }
  46681. if (!processDefineProps(
  46682. ctx,
  46683. node.arguments[0],
  46684. declId,
  46685. true
  46686. )) {
  46687. ctx.error(
  46688. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46689. node.arguments[0] || node
  46690. );
  46691. }
  46692. if (ctx.propsRuntimeDecl) {
  46693. ctx.error(
  46694. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46695. node
  46696. );
  46697. }
  46698. if (declId && declId.type === "ObjectPattern") {
  46699. ctx.warn(
  46700. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46701. Reactive destructure will be disabled when using withDefaults().
  46702. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `,
  46703. node.callee
  46704. );
  46705. }
  46706. ctx.propsRuntimeDefaults = node.arguments[1];
  46707. if (!ctx.propsRuntimeDefaults) {
  46708. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46709. }
  46710. ctx.propsCall = node;
  46711. return true;
  46712. }
  46713. function genRuntimeProps(ctx) {
  46714. let propsDecls;
  46715. if (ctx.propsRuntimeDecl) {
  46716. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46717. if (ctx.propsDestructureDecl) {
  46718. const defaults = [];
  46719. for (const key in ctx.propsDestructuredBindings) {
  46720. const d = genDestructuredDefaultValue(ctx, key);
  46721. const finalKey = getEscapedPropName(key);
  46722. if (d)
  46723. defaults.push(
  46724. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46725. );
  46726. }
  46727. if (defaults.length) {
  46728. propsDecls = `/*@__PURE__*/${ctx.helper(
  46729. `mergeDefaults`
  46730. )}(${propsDecls}, {
  46731. ${defaults.join(",\n ")}
  46732. })`;
  46733. }
  46734. }
  46735. } else if (ctx.propsTypeDecl) {
  46736. propsDecls = extractRuntimeProps(ctx);
  46737. }
  46738. const modelsDecls = genModelProps(ctx);
  46739. if (propsDecls && modelsDecls) {
  46740. return `/*@__PURE__*/${ctx.helper(
  46741. "mergeModels"
  46742. )}(${propsDecls}, ${modelsDecls})`;
  46743. } else {
  46744. return modelsDecls || propsDecls;
  46745. }
  46746. }
  46747. function extractRuntimeProps(ctx) {
  46748. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46749. if (!props.length) {
  46750. return;
  46751. }
  46752. const propStrings = [];
  46753. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46754. for (const prop of props) {
  46755. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46756. if ("bindingMetadata" in ctx && !(prop.key in ctx.bindingMetadata)) {
  46757. ctx.bindingMetadata[prop.key] = "props";
  46758. }
  46759. }
  46760. let propsDecls = `{
  46761. ${propStrings.join(",\n ")}
  46762. }`;
  46763. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46764. propsDecls = `/*@__PURE__*/${ctx.helper(
  46765. "mergeDefaults"
  46766. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46767. }
  46768. return propsDecls;
  46769. }
  46770. function resolveRuntimePropsFromType(ctx, node) {
  46771. const props = [];
  46772. const elements = resolveTypeElements(ctx, node);
  46773. for (const key in elements.props) {
  46774. const e = elements.props[key];
  46775. let type = inferRuntimeType(ctx, e);
  46776. let skipCheck = false;
  46777. if (type.includes(UNKNOWN_TYPE)) {
  46778. if (type.includes("Boolean") || type.includes("Function")) {
  46779. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46780. skipCheck = true;
  46781. } else {
  46782. type = ["null"];
  46783. }
  46784. }
  46785. props.push({
  46786. key,
  46787. required: !e.optional,
  46788. type: type || [`null`],
  46789. skipCheck
  46790. });
  46791. }
  46792. return props;
  46793. }
  46794. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46795. let defaultString;
  46796. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46797. if (destructured) {
  46798. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46799. } else if (hasStaticDefaults) {
  46800. const prop = ctx.propsRuntimeDefaults.properties.find(
  46801. (node) => {
  46802. if (node.type === "SpreadElement") return false;
  46803. return resolveObjectKey(node.key, node.computed) === key;
  46804. }
  46805. );
  46806. if (prop) {
  46807. if (prop.type === "ObjectProperty") {
  46808. defaultString = `default: ${ctx.getString(prop.value)}`;
  46809. } else {
  46810. let paramsString = "";
  46811. if (prop.params.length) {
  46812. const start = prop.params[0].start;
  46813. const end = prop.params[prop.params.length - 1].end;
  46814. paramsString = ctx.getString({ start, end });
  46815. }
  46816. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default(${paramsString}) ${ctx.getString(prop.body)}`;
  46817. }
  46818. }
  46819. }
  46820. const finalKey = getEscapedPropName(key);
  46821. if (!ctx.options.isProd) {
  46822. return `${finalKey}: { ${concatStrings([
  46823. `type: ${toRuntimeTypeString(type)}`,
  46824. `required: ${required}`,
  46825. skipCheck && "skipCheck: true",
  46826. defaultString
  46827. ])} }`;
  46828. } else if (type.some(
  46829. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46830. )) {
  46831. return `${finalKey}: { ${concatStrings([
  46832. `type: ${toRuntimeTypeString(type)}`,
  46833. defaultString
  46834. ])} }`;
  46835. } else {
  46836. if (ctx.isCE) {
  46837. if (defaultString) {
  46838. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46839. type
  46840. )} }`}`;
  46841. } else {
  46842. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46843. }
  46844. }
  46845. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46846. }
  46847. }
  46848. function hasStaticWithDefaults(ctx) {
  46849. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46850. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46851. ));
  46852. }
  46853. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46854. const destructured = ctx.propsDestructuredBindings[key];
  46855. const defaultVal = destructured && destructured.default;
  46856. if (defaultVal) {
  46857. const value = ctx.getString(defaultVal);
  46858. const unwrapped = unwrapTSNode(defaultVal);
  46859. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46860. const valueType = inferValueType(unwrapped);
  46861. if (valueType && !inferredType.includes(valueType)) {
  46862. ctx.error(
  46863. `Default value of prop "${key}" does not match declared type.`,
  46864. unwrapped
  46865. );
  46866. }
  46867. }
  46868. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46869. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46870. return {
  46871. valueString: needFactoryWrap ? `() => (${value})` : value,
  46872. needSkipFactory
  46873. };
  46874. }
  46875. }
  46876. function inferValueType(node) {
  46877. switch (node.type) {
  46878. case "StringLiteral":
  46879. return "String";
  46880. case "NumericLiteral":
  46881. return "Number";
  46882. case "BooleanLiteral":
  46883. return "Boolean";
  46884. case "ObjectExpression":
  46885. return "Object";
  46886. case "ArrayExpression":
  46887. return "Array";
  46888. case "FunctionExpression":
  46889. case "ArrowFunctionExpression":
  46890. return "Function";
  46891. }
  46892. }
  46893. function processPropsDestructure(ctx, declId) {
  46894. if (ctx.options.propsDestructure === "error") {
  46895. ctx.error(`Props destructure is explicitly prohibited via config.`, declId);
  46896. } else if (ctx.options.propsDestructure === false) {
  46897. return;
  46898. }
  46899. ctx.propsDestructureDecl = declId;
  46900. const registerBinding = (key, local, defaultValue) => {
  46901. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  46902. if (local !== key) {
  46903. ctx.bindingMetadata[local] = "props-aliased";
  46904. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  46905. }
  46906. };
  46907. for (const prop of declId.properties) {
  46908. if (prop.type === "ObjectProperty") {
  46909. const propKey = resolveObjectKey(prop.key, prop.computed);
  46910. if (!propKey) {
  46911. ctx.error(
  46912. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  46913. prop.key
  46914. );
  46915. }
  46916. if (prop.value.type === "AssignmentPattern") {
  46917. const { left, right } = prop.value;
  46918. if (left.type !== "Identifier") {
  46919. ctx.error(
  46920. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46921. left
  46922. );
  46923. }
  46924. registerBinding(propKey, left.name, right);
  46925. } else if (prop.value.type === "Identifier") {
  46926. registerBinding(propKey, prop.value.name);
  46927. } else {
  46928. ctx.error(
  46929. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46930. prop.value
  46931. );
  46932. }
  46933. } else {
  46934. ctx.propsDestructureRestId = prop.argument.name;
  46935. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  46936. }
  46937. }
  46938. }
  46939. function transformDestructuredProps(ctx, vueImportAliases) {
  46940. if (ctx.options.propsDestructure === false) {
  46941. return;
  46942. }
  46943. const rootScope = /* @__PURE__ */ Object.create(null);
  46944. const scopeStack = [rootScope];
  46945. let currentScope = rootScope;
  46946. const excludedIds = /* @__PURE__ */ new WeakSet();
  46947. const parentStack = [];
  46948. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  46949. for (const key in ctx.propsDestructuredBindings) {
  46950. const { local } = ctx.propsDestructuredBindings[key];
  46951. rootScope[local] = true;
  46952. propsLocalToPublicMap[local] = key;
  46953. }
  46954. function pushScope() {
  46955. scopeStack.push(currentScope = Object.create(currentScope));
  46956. }
  46957. function popScope() {
  46958. scopeStack.pop();
  46959. currentScope = scopeStack[scopeStack.length - 1] || null;
  46960. }
  46961. function registerLocalBinding(id) {
  46962. excludedIds.add(id);
  46963. if (currentScope) {
  46964. currentScope[id.name] = false;
  46965. } else {
  46966. ctx.error(
  46967. "registerBinding called without active scope, something is wrong.",
  46968. id
  46969. );
  46970. }
  46971. }
  46972. function walkScope(node, isRoot = false) {
  46973. for (const stmt of node.body) {
  46974. if (stmt.type === "VariableDeclaration") {
  46975. walkVariableDeclaration(stmt, isRoot);
  46976. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  46977. if (stmt.declare || !stmt.id) continue;
  46978. registerLocalBinding(stmt.id);
  46979. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  46980. walkVariableDeclaration(stmt.declaration, isRoot);
  46981. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  46982. walkVariableDeclaration(stmt.body, isRoot);
  46983. }
  46984. }
  46985. }
  46986. function walkVariableDeclaration(stmt, isRoot = false) {
  46987. if (stmt.declare) {
  46988. return;
  46989. }
  46990. for (const decl of stmt.declarations) {
  46991. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  46992. for (const id of extractIdentifiers$1(decl.id)) {
  46993. if (isDefineProps) {
  46994. excludedIds.add(id);
  46995. } else {
  46996. registerLocalBinding(id);
  46997. }
  46998. }
  46999. }
  47000. }
  47001. function rewriteId(id, parent, parentStack2) {
  47002. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  47003. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  47004. }
  47005. if (isStaticProperty(parent) && parent.shorthand) {
  47006. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  47007. ctx.s.appendLeft(
  47008. id.end + ctx.startOffset,
  47009. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  47010. );
  47011. }
  47012. } else {
  47013. ctx.s.overwrite(
  47014. id.start + ctx.startOffset,
  47015. id.end + ctx.startOffset,
  47016. genPropsAccessExp(propsLocalToPublicMap[id.name])
  47017. );
  47018. }
  47019. }
  47020. function checkUsage(node, method, alias = method) {
  47021. if (isCallOf(node, alias)) {
  47022. const arg = unwrapTSNode(node.arguments[0]);
  47023. if (arg.type === "Identifier" && currentScope[arg.name]) {
  47024. ctx.error(
  47025. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  47026. arg
  47027. );
  47028. }
  47029. }
  47030. }
  47031. const ast = ctx.scriptSetupAst;
  47032. walkScope(ast, true);
  47033. walk$2(ast, {
  47034. enter(node, parent) {
  47035. parent && parentStack.push(parent);
  47036. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  47037. return this.skip();
  47038. }
  47039. checkUsage(node, "watch", vueImportAliases.watch);
  47040. checkUsage(node, "toRef", vueImportAliases.toRef);
  47041. if (isFunctionType(node)) {
  47042. pushScope();
  47043. walkFunctionParams(node, registerLocalBinding);
  47044. if (node.body.type === "BlockStatement") {
  47045. walkScope(node.body);
  47046. }
  47047. return;
  47048. }
  47049. if (node.type === "CatchClause") {
  47050. pushScope();
  47051. if (node.param && node.param.type === "Identifier") {
  47052. registerLocalBinding(node.param);
  47053. }
  47054. walkScope(node.body);
  47055. return;
  47056. }
  47057. if (node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47058. pushScope();
  47059. const varDecl = node.type === "ForStatement" ? node.init : node.left;
  47060. if (varDecl && varDecl.type === "VariableDeclaration") {
  47061. walkVariableDeclaration(varDecl);
  47062. }
  47063. if (node.body.type === "BlockStatement") {
  47064. walkScope(node.body);
  47065. }
  47066. return;
  47067. }
  47068. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  47069. pushScope();
  47070. walkScope(node);
  47071. return;
  47072. }
  47073. if (node.type === "Identifier") {
  47074. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  47075. if (currentScope[node.name]) {
  47076. rewriteId(node, parent, parentStack);
  47077. }
  47078. }
  47079. }
  47080. },
  47081. leave(node, parent) {
  47082. parent && parentStack.pop();
  47083. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node) || node.type === "CatchClause" || node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47084. popScope();
  47085. }
  47086. }
  47087. });
  47088. }
  47089. const DEFINE_EMITS = "defineEmits";
  47090. function processDefineEmits(ctx, node, declId) {
  47091. if (!isCallOf(node, DEFINE_EMITS)) {
  47092. return false;
  47093. }
  47094. if (ctx.hasDefineEmitCall) {
  47095. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  47096. }
  47097. ctx.hasDefineEmitCall = true;
  47098. ctx.emitsRuntimeDecl = node.arguments[0];
  47099. if (node.typeParameters) {
  47100. if (ctx.emitsRuntimeDecl) {
  47101. ctx.error(
  47102. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  47103. node
  47104. );
  47105. }
  47106. ctx.emitsTypeDecl = node.typeParameters.params[0];
  47107. }
  47108. ctx.emitDecl = declId;
  47109. return true;
  47110. }
  47111. function genRuntimeEmits(ctx) {
  47112. let emitsDecl = "";
  47113. if (ctx.emitsRuntimeDecl) {
  47114. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  47115. } else if (ctx.emitsTypeDecl) {
  47116. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  47117. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  47118. }
  47119. if (ctx.hasDefineModelCall) {
  47120. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  47121. emitsDecl = emitsDecl ? `/*@__PURE__*/${ctx.helper(
  47122. "mergeModels"
  47123. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  47124. }
  47125. return emitsDecl;
  47126. }
  47127. function extractRuntimeEmits(ctx) {
  47128. const emits = /* @__PURE__ */ new Set();
  47129. const node = ctx.emitsTypeDecl;
  47130. if (node.type === "TSFunctionType") {
  47131. extractEventNames(ctx, node.parameters[0], emits);
  47132. return emits;
  47133. }
  47134. const { props, calls } = resolveTypeElements(ctx, node);
  47135. let hasProperty = false;
  47136. for (const key in props) {
  47137. emits.add(key);
  47138. hasProperty = true;
  47139. }
  47140. if (calls) {
  47141. if (hasProperty) {
  47142. ctx.error(
  47143. `defineEmits() type cannot mixed call signature and property syntax.`,
  47144. node
  47145. );
  47146. }
  47147. for (const call of calls) {
  47148. extractEventNames(ctx, call.parameters[0], emits);
  47149. }
  47150. }
  47151. return emits;
  47152. }
  47153. function extractEventNames(ctx, eventName, emits) {
  47154. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  47155. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  47156. for (const type of types) {
  47157. if (type.type === "TSLiteralType") {
  47158. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  47159. emits.add(String(type.literal.value));
  47160. }
  47161. }
  47162. }
  47163. }
  47164. }
  47165. const DEFINE_EXPOSE = "defineExpose";
  47166. function processDefineExpose(ctx, node) {
  47167. if (isCallOf(node, DEFINE_EXPOSE)) {
  47168. if (ctx.hasDefineExposeCall) {
  47169. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  47170. }
  47171. ctx.hasDefineExposeCall = true;
  47172. return true;
  47173. }
  47174. return false;
  47175. }
  47176. const DEFINE_SLOTS = "defineSlots";
  47177. function processDefineSlots(ctx, node, declId) {
  47178. if (!isCallOf(node, DEFINE_SLOTS)) {
  47179. return false;
  47180. }
  47181. if (ctx.hasDefineSlotsCall) {
  47182. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  47183. }
  47184. ctx.hasDefineSlotsCall = true;
  47185. if (node.arguments.length > 0) {
  47186. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  47187. }
  47188. if (declId) {
  47189. ctx.s.overwrite(
  47190. ctx.startOffset + node.start,
  47191. ctx.startOffset + node.end,
  47192. `${ctx.helper("useSlots")}()`
  47193. );
  47194. }
  47195. return true;
  47196. }
  47197. const DEFINE_OPTIONS = "defineOptions";
  47198. function processDefineOptions(ctx, node) {
  47199. if (!isCallOf(node, DEFINE_OPTIONS)) {
  47200. return false;
  47201. }
  47202. if (ctx.hasDefineOptionsCall) {
  47203. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  47204. }
  47205. if (node.typeParameters) {
  47206. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  47207. }
  47208. if (!node.arguments[0]) return true;
  47209. ctx.hasDefineOptionsCall = true;
  47210. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  47211. let propsOption = void 0;
  47212. let emitsOption = void 0;
  47213. let exposeOption = void 0;
  47214. let slotsOption = void 0;
  47215. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  47216. for (const prop of ctx.optionsRuntimeDecl.properties) {
  47217. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  47218. switch (prop.key.name) {
  47219. case "props":
  47220. propsOption = prop;
  47221. break;
  47222. case "emits":
  47223. emitsOption = prop;
  47224. break;
  47225. case "expose":
  47226. exposeOption = prop;
  47227. break;
  47228. case "slots":
  47229. slotsOption = prop;
  47230. break;
  47231. }
  47232. }
  47233. }
  47234. }
  47235. if (propsOption) {
  47236. ctx.error(
  47237. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  47238. propsOption
  47239. );
  47240. }
  47241. if (emitsOption) {
  47242. ctx.error(
  47243. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  47244. emitsOption
  47245. );
  47246. }
  47247. if (exposeOption) {
  47248. ctx.error(
  47249. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  47250. exposeOption
  47251. );
  47252. }
  47253. if (slotsOption) {
  47254. ctx.error(
  47255. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  47256. slotsOption
  47257. );
  47258. }
  47259. return true;
  47260. }
  47261. function processAwait(ctx, node, needSemi, isStatement) {
  47262. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  47263. const startOffset = ctx.startOffset;
  47264. const argumentStr = ctx.descriptor.source.slice(
  47265. argumentStart + startOffset,
  47266. node.argument.end + startOffset
  47267. );
  47268. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  47269. ctx.s.overwrite(
  47270. node.start + startOffset,
  47271. argumentStart + startOffset,
  47272. `${needSemi ? `;` : ``}(
  47273. ([__temp,__restore] = ${ctx.helper(
  47274. `withAsyncContext`
  47275. )}(${containsNestedAwait ? `async ` : ``}() => `
  47276. );
  47277. ctx.s.appendLeft(
  47278. node.end + startOffset,
  47279. `)),
  47280. ${isStatement ? `` : `__temp = `}await __temp,
  47281. __restore()${isStatement ? `` : `,
  47282. __temp`}
  47283. )`
  47284. );
  47285. }
  47286. var __defProp$1 = Object.defineProperty;
  47287. var __defProps = Object.defineProperties;
  47288. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  47289. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  47290. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  47291. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  47292. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  47293. var __spreadValues$1 = (a, b) => {
  47294. for (var prop in b || (b = {}))
  47295. if (__hasOwnProp$1.call(b, prop))
  47296. __defNormalProp$1(a, prop, b[prop]);
  47297. if (__getOwnPropSymbols$1)
  47298. for (var prop of __getOwnPropSymbols$1(b)) {
  47299. if (__propIsEnum$1.call(b, prop))
  47300. __defNormalProp$1(a, prop, b[prop]);
  47301. }
  47302. return a;
  47303. };
  47304. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  47305. const MACROS = [
  47306. DEFINE_PROPS,
  47307. DEFINE_EMITS,
  47308. DEFINE_EXPOSE,
  47309. DEFINE_OPTIONS,
  47310. DEFINE_SLOTS,
  47311. DEFINE_MODEL,
  47312. WITH_DEFAULTS
  47313. ];
  47314. function compileScript(sfc, options) {
  47315. var _a, _b, _c;
  47316. if (!options.id) {
  47317. warnOnce$1(
  47318. `compileScript now requires passing the \`id\` option.
  47319. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  47320. );
  47321. }
  47322. const { script, scriptSetup, source, filename } = sfc;
  47323. const hoistStatic = options.hoistStatic !== false && !script;
  47324. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  47325. const scriptLang = script && script.lang;
  47326. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  47327. const isJSOrTS = isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang);
  47328. if (script && scriptSetup && scriptLang !== scriptSetupLang) {
  47329. throw new Error(
  47330. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  47331. );
  47332. }
  47333. if (!scriptSetup) {
  47334. if (!script) {
  47335. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  47336. }
  47337. if (script.lang && !isJSOrTS) {
  47338. return script;
  47339. }
  47340. const ctx2 = new ScriptCompileContext(sfc, options);
  47341. return processNormalScript(ctx2, scopeId);
  47342. }
  47343. if (scriptSetupLang && !isJSOrTS) {
  47344. return scriptSetup;
  47345. }
  47346. const ctx = new ScriptCompileContext(sfc, options);
  47347. const scriptBindings = /* @__PURE__ */ Object.create(null);
  47348. const setupBindings = /* @__PURE__ */ Object.create(null);
  47349. let defaultExport;
  47350. let hasAwait = false;
  47351. let hasInlinedSsrRenderFn = false;
  47352. const startOffset = ctx.startOffset;
  47353. const endOffset = ctx.endOffset;
  47354. const scriptStartOffset = script && script.loc.start.offset;
  47355. const scriptEndOffset = script && script.loc.end.offset;
  47356. function hoistNode(node) {
  47357. const start = node.start + startOffset;
  47358. let end = node.end + startOffset;
  47359. if (node.trailingComments && node.trailingComments.length > 0) {
  47360. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  47361. end = lastCommentNode.end + startOffset;
  47362. }
  47363. while (end <= source.length) {
  47364. if (!/\s/.test(source.charAt(end))) {
  47365. break;
  47366. }
  47367. end++;
  47368. }
  47369. ctx.s.move(start, end, 0);
  47370. }
  47371. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  47372. let isUsedInTemplate = needTemplateUsageCheck;
  47373. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  47374. isUsedInTemplate = isImportUsed(local, sfc);
  47375. }
  47376. ctx.userImports[local] = {
  47377. isType,
  47378. imported,
  47379. local,
  47380. source: source2,
  47381. isFromSetup,
  47382. isUsedInTemplate
  47383. };
  47384. }
  47385. function checkInvalidScopeReference(node, method) {
  47386. if (!node) return;
  47387. walkIdentifiers(node, (id) => {
  47388. const binding = setupBindings[id.name];
  47389. if (binding && binding !== "literal-const") {
  47390. ctx.error(
  47391. `\`${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.`,
  47392. id
  47393. );
  47394. }
  47395. });
  47396. }
  47397. const scriptAst = ctx.scriptAst;
  47398. const scriptSetupAst = ctx.scriptSetupAst;
  47399. if (scriptAst) {
  47400. for (const node of scriptAst.body) {
  47401. if (node.type === "ImportDeclaration") {
  47402. for (const specifier of node.specifiers) {
  47403. const imported = getImportedName(specifier);
  47404. registerUserImport(
  47405. node.source.value,
  47406. specifier.local.name,
  47407. imported,
  47408. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47409. false,
  47410. !options.inlineTemplate
  47411. );
  47412. }
  47413. }
  47414. }
  47415. }
  47416. for (const node of scriptSetupAst.body) {
  47417. if (node.type === "ImportDeclaration") {
  47418. hoistNode(node);
  47419. let removed = 0;
  47420. const removeSpecifier = (i) => {
  47421. const removeLeft = i > removed;
  47422. removed++;
  47423. const current = node.specifiers[i];
  47424. const next = node.specifiers[i + 1];
  47425. ctx.s.remove(
  47426. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  47427. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  47428. );
  47429. };
  47430. for (let i = 0; i < node.specifiers.length; i++) {
  47431. const specifier = node.specifiers[i];
  47432. const local = specifier.local.name;
  47433. const imported = getImportedName(specifier);
  47434. const source2 = node.source.value;
  47435. const existing = ctx.userImports[local];
  47436. if (source2 === "vue" && MACROS.includes(imported)) {
  47437. if (local === imported) {
  47438. warnOnce$1(
  47439. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  47440. );
  47441. } else {
  47442. ctx.error(
  47443. `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
  47444. specifier
  47445. );
  47446. }
  47447. removeSpecifier(i);
  47448. } else if (existing) {
  47449. if (existing.source === source2 && existing.imported === imported) {
  47450. removeSpecifier(i);
  47451. } else {
  47452. ctx.error(
  47453. `different imports aliased to same local name.`,
  47454. specifier
  47455. );
  47456. }
  47457. } else {
  47458. registerUserImport(
  47459. source2,
  47460. local,
  47461. imported,
  47462. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47463. true,
  47464. !options.inlineTemplate
  47465. );
  47466. }
  47467. }
  47468. if (node.specifiers.length && removed === node.specifiers.length) {
  47469. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47470. }
  47471. }
  47472. }
  47473. const vueImportAliases = {};
  47474. for (const key in ctx.userImports) {
  47475. const { source: source2, imported, local } = ctx.userImports[key];
  47476. if (source2 === "vue") vueImportAliases[imported] = local;
  47477. }
  47478. if (script && scriptAst) {
  47479. for (const node of scriptAst.body) {
  47480. if (node.type === "ExportDefaultDeclaration") {
  47481. defaultExport = node;
  47482. let optionProperties;
  47483. if (defaultExport.declaration.type === "ObjectExpression") {
  47484. optionProperties = defaultExport.declaration.properties;
  47485. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  47486. optionProperties = defaultExport.declaration.arguments[0].properties;
  47487. }
  47488. if (optionProperties) {
  47489. for (const p of optionProperties) {
  47490. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  47491. ctx.hasDefaultExportName = true;
  47492. }
  47493. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  47494. ctx.hasDefaultExportRender = true;
  47495. }
  47496. }
  47497. }
  47498. const start = node.start + scriptStartOffset;
  47499. const end = node.declaration.start + scriptStartOffset;
  47500. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  47501. } else if (node.type === "ExportNamedDeclaration") {
  47502. const defaultSpecifier = node.specifiers.find(
  47503. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  47504. );
  47505. if (defaultSpecifier) {
  47506. defaultExport = node;
  47507. if (node.specifiers.length > 1) {
  47508. ctx.s.remove(
  47509. defaultSpecifier.start + scriptStartOffset,
  47510. defaultSpecifier.end + scriptStartOffset
  47511. );
  47512. } else {
  47513. ctx.s.remove(
  47514. node.start + scriptStartOffset,
  47515. node.end + scriptStartOffset
  47516. );
  47517. }
  47518. if (node.source) {
  47519. ctx.s.prepend(
  47520. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  47521. `
  47522. );
  47523. } else {
  47524. ctx.s.appendLeft(
  47525. scriptEndOffset,
  47526. `
  47527. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  47528. `
  47529. );
  47530. }
  47531. }
  47532. if (node.declaration) {
  47533. walkDeclaration(
  47534. "script",
  47535. node.declaration,
  47536. scriptBindings,
  47537. vueImportAliases,
  47538. hoistStatic
  47539. );
  47540. }
  47541. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47542. walkDeclaration(
  47543. "script",
  47544. node,
  47545. scriptBindings,
  47546. vueImportAliases,
  47547. hoistStatic
  47548. );
  47549. }
  47550. }
  47551. if (scriptStartOffset > startOffset) {
  47552. if (!/\n$/.test(script.content.trim())) {
  47553. ctx.s.appendLeft(scriptEndOffset, `
  47554. `);
  47555. }
  47556. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  47557. }
  47558. }
  47559. for (const node of scriptSetupAst.body) {
  47560. if (node.type === "ExpressionStatement") {
  47561. const expr = unwrapTSNode(node.expression);
  47562. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  47563. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47564. } else if (processDefineExpose(ctx, expr)) {
  47565. const callee = expr.callee;
  47566. ctx.s.overwrite(
  47567. callee.start + startOffset,
  47568. callee.end + startOffset,
  47569. "__expose"
  47570. );
  47571. } else {
  47572. processDefineModel(ctx, expr);
  47573. }
  47574. }
  47575. if (node.type === "VariableDeclaration" && !node.declare) {
  47576. const total = node.declarations.length;
  47577. let left = total;
  47578. let lastNonRemoved;
  47579. for (let i = 0; i < total; i++) {
  47580. const decl = node.declarations[i];
  47581. const init = decl.init && unwrapTSNode(decl.init);
  47582. if (init) {
  47583. if (processDefineOptions(ctx, init)) {
  47584. ctx.error(
  47585. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  47586. node
  47587. );
  47588. }
  47589. const isDefineProps = processDefineProps(ctx, init, decl.id);
  47590. if (ctx.propsDestructureRestId) {
  47591. setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
  47592. }
  47593. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  47594. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  47595. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  47596. if (left === 1) {
  47597. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47598. } else {
  47599. let start = decl.start + startOffset;
  47600. let end = decl.end + startOffset;
  47601. if (i === total - 1) {
  47602. start = node.declarations[lastNonRemoved].end + startOffset;
  47603. } else {
  47604. end = node.declarations[i + 1].start + startOffset;
  47605. }
  47606. ctx.s.remove(start, end);
  47607. left--;
  47608. }
  47609. } else if (isDefineEmits) {
  47610. ctx.s.overwrite(
  47611. startOffset + init.start,
  47612. startOffset + init.end,
  47613. "__emit"
  47614. );
  47615. } else {
  47616. lastNonRemoved = i;
  47617. }
  47618. }
  47619. }
  47620. }
  47621. let isAllLiteral = false;
  47622. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47623. isAllLiteral = walkDeclaration(
  47624. "scriptSetup",
  47625. node,
  47626. setupBindings,
  47627. vueImportAliases,
  47628. hoistStatic,
  47629. !!ctx.propsDestructureDecl
  47630. );
  47631. }
  47632. if (hoistStatic && isAllLiteral) {
  47633. hoistNode(node);
  47634. }
  47635. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  47636. const scope = [scriptSetupAst.body];
  47637. walk$2(node, {
  47638. enter(child, parent) {
  47639. if (isFunctionType(child)) {
  47640. this.skip();
  47641. }
  47642. if (child.type === "BlockStatement") {
  47643. scope.push(child.body);
  47644. }
  47645. if (child.type === "AwaitExpression") {
  47646. hasAwait = true;
  47647. const currentScope = scope[scope.length - 1];
  47648. const needsSemi = currentScope.some((n, i) => {
  47649. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47650. });
  47651. processAwait(
  47652. ctx,
  47653. child,
  47654. needsSemi,
  47655. parent.type === "ExpressionStatement"
  47656. );
  47657. }
  47658. },
  47659. exit(node2) {
  47660. if (node2.type === "BlockStatement") scope.pop();
  47661. }
  47662. });
  47663. }
  47664. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47665. ctx.error(
  47666. `<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.`,
  47667. node
  47668. );
  47669. }
  47670. if (ctx.isTS) {
  47671. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47672. if (node.type !== "TSEnumDeclaration") {
  47673. hoistNode(node);
  47674. }
  47675. }
  47676. }
  47677. }
  47678. if (ctx.propsDestructureDecl) {
  47679. transformDestructuredProps(ctx, vueImportAliases);
  47680. }
  47681. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47682. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47683. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47684. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47685. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47686. for (const { runtimeOptionNodes } of Object.values(ctx.modelDecls)) {
  47687. for (const node of runtimeOptionNodes) {
  47688. checkInvalidScopeReference(node, DEFINE_MODEL);
  47689. }
  47690. }
  47691. if (script) {
  47692. if (startOffset < scriptStartOffset) {
  47693. ctx.s.remove(0, startOffset);
  47694. ctx.s.remove(endOffset, scriptStartOffset);
  47695. ctx.s.remove(scriptEndOffset, source.length);
  47696. } else {
  47697. ctx.s.remove(0, scriptStartOffset);
  47698. ctx.s.remove(scriptEndOffset, startOffset);
  47699. ctx.s.remove(endOffset, source.length);
  47700. }
  47701. } else {
  47702. ctx.s.remove(0, startOffset);
  47703. ctx.s.remove(endOffset, source.length);
  47704. }
  47705. if (scriptAst) {
  47706. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47707. }
  47708. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47709. ctx.userImports
  47710. )) {
  47711. if (isType) continue;
  47712. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47713. }
  47714. for (const key in scriptBindings) {
  47715. ctx.bindingMetadata[key] = scriptBindings[key];
  47716. }
  47717. for (const key in setupBindings) {
  47718. ctx.bindingMetadata[key] = setupBindings[key];
  47719. }
  47720. if (sfc.template && !sfc.template.src && sfc.template.ast) {
  47721. const vModelIds = resolveTemplateVModelIdentifiers(sfc);
  47722. if (vModelIds.size) {
  47723. const toDemote = /* @__PURE__ */ new Set();
  47724. for (const id of vModelIds) {
  47725. if (setupBindings[id] === "setup-reactive-const") {
  47726. toDemote.add(id);
  47727. }
  47728. }
  47729. if (toDemote.size) {
  47730. for (const node of scriptSetupAst.body) {
  47731. if (node.type === "VariableDeclaration" && node.kind === "const" && !node.declare) {
  47732. const demotedInDecl = [];
  47733. for (const decl of node.declarations) {
  47734. if (decl.id.type === "Identifier" && toDemote.has(decl.id.name)) {
  47735. demotedInDecl.push(decl.id.name);
  47736. }
  47737. }
  47738. if (demotedInDecl.length) {
  47739. ctx.s.overwrite(
  47740. node.start + startOffset,
  47741. node.start + startOffset + "const".length,
  47742. "let"
  47743. );
  47744. for (const id of demotedInDecl) {
  47745. setupBindings[id] = "setup-let";
  47746. ctx.bindingMetadata[id] = "setup-let";
  47747. warnOnce$1(
  47748. `\`v-model\` cannot update a \`const\` reactive binding \`${id}\`. The compiler has transformed it to \`let\` to make the update work.`
  47749. );
  47750. }
  47751. }
  47752. }
  47753. }
  47754. }
  47755. }
  47756. }
  47757. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47758. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47759. ctx.helperImports.add(CSS_VARS_HELPER);
  47760. ctx.helperImports.add("unref");
  47761. ctx.s.prependLeft(
  47762. startOffset,
  47763. `
  47764. ${genCssVarsCode(
  47765. sfc.cssVars,
  47766. ctx.bindingMetadata,
  47767. scopeId,
  47768. !!options.isProd
  47769. )}
  47770. `
  47771. );
  47772. }
  47773. let args = `__props`;
  47774. if (ctx.propsTypeDecl) {
  47775. args += `: any`;
  47776. }
  47777. if (ctx.propsDecl) {
  47778. if (ctx.propsDestructureRestId) {
  47779. ctx.s.overwrite(
  47780. startOffset + ctx.propsCall.start,
  47781. startOffset + ctx.propsCall.end,
  47782. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47783. Object.keys(ctx.propsDestructuredBindings)
  47784. )})`
  47785. );
  47786. ctx.s.overwrite(
  47787. startOffset + ctx.propsDestructureDecl.start,
  47788. startOffset + ctx.propsDestructureDecl.end,
  47789. ctx.propsDestructureRestId
  47790. );
  47791. } else if (!ctx.propsDestructureDecl) {
  47792. ctx.s.overwrite(
  47793. startOffset + ctx.propsCall.start,
  47794. startOffset + ctx.propsCall.end,
  47795. "__props"
  47796. );
  47797. }
  47798. }
  47799. if (hasAwait) {
  47800. const any = ctx.isTS ? `: any` : ``;
  47801. ctx.s.prependLeft(startOffset, `
  47802. let __temp${any}, __restore${any}
  47803. `);
  47804. }
  47805. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47806. if (ctx.emitDecl) {
  47807. destructureElements.push(`emit: __emit`);
  47808. }
  47809. if (destructureElements.length) {
  47810. args += `, { ${destructureElements.join(", ")} }`;
  47811. }
  47812. let templateMap;
  47813. let returned;
  47814. const propsDecl = genRuntimeProps(ctx);
  47815. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47816. const allBindings = __spreadValues$1(__spreadValues$1({}, scriptBindings), setupBindings);
  47817. for (const key in ctx.userImports) {
  47818. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47819. allBindings[key] = true;
  47820. }
  47821. }
  47822. returned = `{ `;
  47823. for (const key in allBindings) {
  47824. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47825. returned += `get ${key}() { return ${key} }, `;
  47826. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47827. const setArg = key === "v" ? `_v` : `v`;
  47828. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47829. } else {
  47830. returned += `${key}, `;
  47831. }
  47832. }
  47833. returned = returned.replace(/, $/, "") + ` }`;
  47834. } else {
  47835. if (sfc.template && !sfc.template.src) {
  47836. if (options.templateOptions && options.templateOptions.ssr) {
  47837. hasInlinedSsrRenderFn = true;
  47838. }
  47839. const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
  47840. filename,
  47841. ast: sfc.template.ast,
  47842. source: sfc.template.content,
  47843. inMap: sfc.template.map
  47844. }, options.templateOptions), {
  47845. id: scopeId,
  47846. scoped: sfc.styles.some((s) => s.scoped),
  47847. isProd: options.isProd,
  47848. ssrCssVars: sfc.cssVars,
  47849. compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47850. inline: true,
  47851. isTS: ctx.isTS,
  47852. bindingMetadata: ctx.bindingMetadata
  47853. })
  47854. }));
  47855. templateMap = map2;
  47856. if (tips.length) {
  47857. tips.forEach(warnOnce$1);
  47858. }
  47859. const err = errors[0];
  47860. if (typeof err === "string") {
  47861. throw new Error(err);
  47862. } else if (err) {
  47863. if (err.loc) {
  47864. err.message += `
  47865. ` + sfc.filename + "\n" + generateCodeFrame(
  47866. source,
  47867. err.loc.start.offset,
  47868. err.loc.end.offset
  47869. ) + `
  47870. `;
  47871. }
  47872. throw err;
  47873. }
  47874. if (preamble) {
  47875. ctx.s.prepend(preamble);
  47876. }
  47877. if (ast && ast.helpers.has(UNREF)) {
  47878. ctx.helperImports.delete("unref");
  47879. }
  47880. returned = code;
  47881. } else {
  47882. returned = `() => {}`;
  47883. }
  47884. }
  47885. if (!options.inlineTemplate && true) {
  47886. ctx.s.appendRight(
  47887. endOffset,
  47888. `
  47889. const __returned__ = ${returned}
  47890. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47891. return __returned__
  47892. }
  47893. `
  47894. );
  47895. } else {
  47896. ctx.s.appendRight(endOffset, `
  47897. return ${returned}
  47898. }
  47899. `);
  47900. }
  47901. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  47902. let runtimeOptions = ``;
  47903. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  47904. const match = filename.match(/([^/\\]+)\.\w+$/);
  47905. if (match) {
  47906. runtimeOptions += `
  47907. __name: '${match[1]}',`;
  47908. }
  47909. }
  47910. if (hasInlinedSsrRenderFn) {
  47911. runtimeOptions += `
  47912. __ssrInlineRender: true,`;
  47913. }
  47914. if (propsDecl) runtimeOptions += `
  47915. props: ${propsDecl},`;
  47916. const emitsDecl = genRuntimeEmits(ctx);
  47917. if (emitsDecl) runtimeOptions += `
  47918. emits: ${emitsDecl},`;
  47919. let definedOptions = "";
  47920. if (ctx.optionsRuntimeDecl) {
  47921. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  47922. }
  47923. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  47924. `;
  47925. if (ctx.isTS) {
  47926. const def = (defaultExport ? `
  47927. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  47928. ...${definedOptions},` : "");
  47929. ctx.s.prependLeft(
  47930. startOffset,
  47931. `
  47932. ${genDefaultAs} /*@__PURE__*/${ctx.helper(
  47933. `defineComponent`
  47934. )}({${def}${runtimeOptions}
  47935. ${hasAwait ? `async ` : ``}setup(${args}) {
  47936. ${exposeCall}`
  47937. );
  47938. ctx.s.appendRight(endOffset, `})`);
  47939. } else {
  47940. if (defaultExport || definedOptions) {
  47941. ctx.s.prependLeft(
  47942. startOffset,
  47943. `
  47944. ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  47945. ${hasAwait ? `async ` : ``}setup(${args}) {
  47946. ${exposeCall}`
  47947. );
  47948. ctx.s.appendRight(endOffset, `})`);
  47949. } else {
  47950. ctx.s.prependLeft(
  47951. startOffset,
  47952. `
  47953. ${genDefaultAs} {${runtimeOptions}
  47954. ${hasAwait ? `async ` : ``}setup(${args}) {
  47955. ${exposeCall}`
  47956. );
  47957. ctx.s.appendRight(endOffset, `}`);
  47958. }
  47959. }
  47960. if (ctx.helperImports.size > 0) {
  47961. const runtimeModuleName = (_c = (_b = options.templateOptions) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.runtimeModuleName;
  47962. const importSrc = runtimeModuleName ? JSON.stringify(runtimeModuleName) : `'vue'`;
  47963. ctx.s.prepend(
  47964. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from ${importSrc}
  47965. `
  47966. );
  47967. }
  47968. const content = ctx.s.toString();
  47969. let map = options.sourceMap !== false ? ctx.s.generateMap({
  47970. source: filename,
  47971. hires: true,
  47972. includeContent: true
  47973. }) : void 0;
  47974. if (templateMap && map) {
  47975. const offset = content.indexOf(returned);
  47976. const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
  47977. map = mergeSourceMaps(map, templateMap, templateLineOffset);
  47978. }
  47979. return __spreadProps(__spreadValues$1({}, scriptSetup), {
  47980. bindings: ctx.bindingMetadata,
  47981. imports: ctx.userImports,
  47982. content,
  47983. map,
  47984. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  47985. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  47986. deps: ctx.deps ? [...ctx.deps] : void 0
  47987. });
  47988. }
  47989. function registerBinding(bindings, node, type) {
  47990. bindings[node.name] = type;
  47991. }
  47992. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
  47993. let isAllLiteral = false;
  47994. if (node.type === "VariableDeclaration") {
  47995. const isConst = node.kind === "const";
  47996. isAllLiteral = isConst && node.declarations.every(
  47997. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  47998. );
  47999. for (const { id, init: _init } of node.declarations) {
  48000. const init = _init && unwrapTSNode(_init);
  48001. const isConstMacroCall = isConst && isCallOf(
  48002. init,
  48003. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
  48004. );
  48005. if (id.type === "Identifier") {
  48006. let bindingType;
  48007. const userReactiveBinding = userImportAliases["reactive"];
  48008. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  48009. bindingType = "literal-const";
  48010. } else if (isCallOf(init, userReactiveBinding)) {
  48011. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  48012. } else if (
  48013. // if a declaration is a const literal, we can mark it so that
  48014. // the generated render fn code doesn't need to unref() it
  48015. isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
  48016. ) {
  48017. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  48018. } else if (isConst) {
  48019. if (isCallOf(
  48020. init,
  48021. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
  48022. )) {
  48023. bindingType = "setup-ref";
  48024. } else {
  48025. bindingType = "setup-maybe-ref";
  48026. }
  48027. } else {
  48028. bindingType = "setup-let";
  48029. }
  48030. registerBinding(bindings, id, bindingType);
  48031. } else {
  48032. if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
  48033. continue;
  48034. }
  48035. if (id.type === "ObjectPattern") {
  48036. walkObjectPattern(id, bindings, isConst, isConstMacroCall);
  48037. } else if (id.type === "ArrayPattern") {
  48038. walkArrayPattern(id, bindings, isConst, isConstMacroCall);
  48039. }
  48040. }
  48041. }
  48042. } else if (node.type === "TSEnumDeclaration") {
  48043. isAllLiteral = node.members.every(
  48044. (member) => !member.initializer || isStaticNode(member.initializer)
  48045. );
  48046. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  48047. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  48048. bindings[node.id.name] = "setup-const";
  48049. }
  48050. return isAllLiteral;
  48051. }
  48052. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  48053. for (const p of node.properties) {
  48054. if (p.type === "ObjectProperty") {
  48055. if (p.key.type === "Identifier" && p.key === p.value) {
  48056. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48057. registerBinding(bindings, p.key, type);
  48058. } else {
  48059. walkPattern(p.value, bindings, isConst, isDefineCall);
  48060. }
  48061. } else {
  48062. const type = isConst ? "setup-const" : "setup-let";
  48063. registerBinding(bindings, p.argument, type);
  48064. }
  48065. }
  48066. }
  48067. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  48068. for (const e of node.elements) {
  48069. e && walkPattern(e, bindings, isConst, isDefineCall);
  48070. }
  48071. }
  48072. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  48073. if (node.type === "Identifier") {
  48074. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48075. registerBinding(bindings, node, type);
  48076. } else if (node.type === "RestElement") {
  48077. const type = isConst ? "setup-const" : "setup-let";
  48078. registerBinding(bindings, node.argument, type);
  48079. } else if (node.type === "ObjectPattern") {
  48080. walkObjectPattern(node, bindings, isConst);
  48081. } else if (node.type === "ArrayPattern") {
  48082. walkArrayPattern(node, bindings, isConst);
  48083. } else if (node.type === "AssignmentPattern") {
  48084. if (node.left.type === "Identifier") {
  48085. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48086. registerBinding(bindings, node.left, type);
  48087. } else {
  48088. walkPattern(node.left, bindings, isConst);
  48089. }
  48090. }
  48091. }
  48092. function canNeverBeRef(node, userReactiveImport) {
  48093. if (isCallOf(node, userReactiveImport)) {
  48094. return true;
  48095. }
  48096. switch (node.type) {
  48097. case "UnaryExpression":
  48098. case "BinaryExpression":
  48099. case "ArrayExpression":
  48100. case "ObjectExpression":
  48101. case "FunctionExpression":
  48102. case "ArrowFunctionExpression":
  48103. case "UpdateExpression":
  48104. case "ClassExpression":
  48105. case "TaggedTemplateExpression":
  48106. return true;
  48107. case "SequenceExpression":
  48108. return canNeverBeRef(
  48109. node.expressions[node.expressions.length - 1],
  48110. userReactiveImport
  48111. );
  48112. default:
  48113. if (isLiteralNode(node)) {
  48114. return true;
  48115. }
  48116. return false;
  48117. }
  48118. }
  48119. function isStaticNode(node) {
  48120. node = unwrapTSNode(node);
  48121. switch (node.type) {
  48122. case "UnaryExpression":
  48123. return isStaticNode(node.argument);
  48124. case "LogicalExpression":
  48125. // 1 > 2
  48126. case "BinaryExpression":
  48127. return isStaticNode(node.left) && isStaticNode(node.right);
  48128. case "ConditionalExpression": {
  48129. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  48130. }
  48131. case "SequenceExpression":
  48132. // (1, 2)
  48133. case "TemplateLiteral":
  48134. return node.expressions.every((expr) => isStaticNode(expr));
  48135. case "ParenthesizedExpression":
  48136. return isStaticNode(node.expression);
  48137. case "StringLiteral":
  48138. case "NumericLiteral":
  48139. case "BooleanLiteral":
  48140. case "NullLiteral":
  48141. case "BigIntLiteral":
  48142. return true;
  48143. }
  48144. return false;
  48145. }
  48146. function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
  48147. const generator = new sourceMapExports.SourceMapGenerator();
  48148. const addMapping = (map, lineOffset = 0) => {
  48149. const consumer = new sourceMapExports.SourceMapConsumer(map);
  48150. consumer.sources.forEach((sourceFile) => {
  48151. generator._sources.add(sourceFile);
  48152. const sourceContent = consumer.sourceContentFor(sourceFile);
  48153. if (sourceContent != null) {
  48154. generator.setSourceContent(sourceFile, sourceContent);
  48155. }
  48156. });
  48157. consumer.eachMapping((m) => {
  48158. if (m.originalLine == null) return;
  48159. generator.addMapping({
  48160. generated: {
  48161. line: m.generatedLine + lineOffset,
  48162. column: m.generatedColumn
  48163. },
  48164. original: {
  48165. line: m.originalLine,
  48166. column: m.originalColumn
  48167. },
  48168. source: m.source,
  48169. name: m.name
  48170. });
  48171. });
  48172. };
  48173. addMapping(scriptMap);
  48174. addMapping(templateMap, templateLineOffset);
  48175. generator._sourceRoot = scriptMap.sourceRoot;
  48176. generator._file = scriptMap.file;
  48177. return generator.toJSON();
  48178. }
  48179. var __defProp = Object.defineProperty;
  48180. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  48181. var __hasOwnProp = Object.prototype.hasOwnProperty;
  48182. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  48183. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  48184. var __spreadValues = (a, b) => {
  48185. for (var prop in b || (b = {}))
  48186. if (__hasOwnProp.call(b, prop))
  48187. __defNormalProp(a, prop, b[prop]);
  48188. if (__getOwnPropSymbols)
  48189. for (var prop of __getOwnPropSymbols(b)) {
  48190. if (__propIsEnum.call(b, prop))
  48191. __defNormalProp(a, prop, b[prop]);
  48192. }
  48193. return a;
  48194. };
  48195. const version = "3.5.32";
  48196. const parseCache = parseCache$1;
  48197. const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
  48198. const walk = walk$2;
  48199. const shouldTransformRef = () => false;
  48200. var parse$4 = libExports.parse;
  48201. 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 };