compiler-sfc.esm-browser.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939
  1. /**
  2. * @vue/compiler-sfc v3.5.33
  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. // Escapes sequences that could break out of an HTML <style> context.
  33081. // Uses CSS unicode escaping (\3c = '<') which is valid CSS and parsed
  33082. // correctly by all compliant CSS consumers.
  33083. const STYLE_TAG = /(<)(\/?style\b)/gi;
  33084. const COMMENT_OPEN = /(<)(!--)/g;
  33085. function escapeHTMLInCSS(str) {
  33086. if (typeof str !== 'string') return str
  33087. if (!str.includes('<')) return str
  33088. return str.replace(STYLE_TAG, '\\3c $2').replace(COMMENT_OPEN, '\\3c $2')
  33089. }
  33090. const DEFAULT_RAW = {
  33091. after: '\n',
  33092. beforeClose: '\n',
  33093. beforeComment: '\n',
  33094. beforeDecl: '\n',
  33095. beforeOpen: ' ',
  33096. beforeRule: '\n',
  33097. colon: ': ',
  33098. commentLeft: ' ',
  33099. commentRight: ' ',
  33100. emptyBody: '',
  33101. indent: ' ',
  33102. semicolon: false
  33103. };
  33104. function capitalize(str) {
  33105. return str[0].toUpperCase() + str.slice(1)
  33106. }
  33107. class Stringifier {
  33108. constructor(builder) {
  33109. this.builder = builder;
  33110. }
  33111. atrule(node, semicolon) {
  33112. let name = '@' + node.name;
  33113. let params = node.params ? this.rawValue(node, 'params') : '';
  33114. if (typeof node.raws.afterName !== 'undefined') {
  33115. name += node.raws.afterName;
  33116. } else if (params) {
  33117. name += ' ';
  33118. }
  33119. if (node.nodes) {
  33120. this.block(node, name + params);
  33121. } else {
  33122. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  33123. this.builder(escapeHTMLInCSS(name + params + end), node);
  33124. }
  33125. }
  33126. beforeAfter(node, detect) {
  33127. let value;
  33128. if (node.type === 'decl') {
  33129. value = this.raw(node, null, 'beforeDecl');
  33130. } else if (node.type === 'comment') {
  33131. value = this.raw(node, null, 'beforeComment');
  33132. } else if (detect === 'before') {
  33133. value = this.raw(node, null, 'beforeRule');
  33134. } else {
  33135. value = this.raw(node, null, 'beforeClose');
  33136. }
  33137. let buf = node.parent;
  33138. let depth = 0;
  33139. while (buf && buf.type !== 'root') {
  33140. depth += 1;
  33141. buf = buf.parent;
  33142. }
  33143. if (value.includes('\n')) {
  33144. let indent = this.raw(node, null, 'indent');
  33145. if (indent.length) {
  33146. for (let step = 0; step < depth; step++) value += indent;
  33147. }
  33148. }
  33149. return value
  33150. }
  33151. block(node, start) {
  33152. let between = this.raw(node, 'between', 'beforeOpen');
  33153. this.builder(escapeHTMLInCSS(start + between) + '{', node, 'start');
  33154. let after;
  33155. if (node.nodes && node.nodes.length) {
  33156. this.body(node);
  33157. after = this.raw(node, 'after');
  33158. } else {
  33159. after = this.raw(node, 'after', 'emptyBody');
  33160. }
  33161. if (after) this.builder(escapeHTMLInCSS(after));
  33162. this.builder('}', node, 'end');
  33163. }
  33164. body(node) {
  33165. let last = node.nodes.length - 1;
  33166. while (last > 0) {
  33167. if (node.nodes[last].type !== 'comment') break
  33168. last -= 1;
  33169. }
  33170. let semicolon = this.raw(node, 'semicolon');
  33171. let isDocument = node.type === 'document';
  33172. for (let i = 0; i < node.nodes.length; i++) {
  33173. let child = node.nodes[i];
  33174. let before = this.raw(child, 'before');
  33175. if (before) this.builder(isDocument ? before : escapeHTMLInCSS(before));
  33176. this.stringify(child, last !== i || semicolon);
  33177. }
  33178. }
  33179. comment(node) {
  33180. let left = this.raw(node, 'left', 'commentLeft');
  33181. let right = this.raw(node, 'right', 'commentRight');
  33182. this.builder(escapeHTMLInCSS('/*' + left + node.text + right + '*/'), node);
  33183. }
  33184. decl(node, semicolon) {
  33185. let between = this.raw(node, 'between', 'colon');
  33186. let string = node.prop + between + this.rawValue(node, 'value');
  33187. if (node.important) {
  33188. string += node.raws.important || ' !important';
  33189. }
  33190. if (semicolon) string += ';';
  33191. this.builder(escapeHTMLInCSS(string), node);
  33192. }
  33193. document(node) {
  33194. this.body(node);
  33195. }
  33196. raw(node, own, detect) {
  33197. let value;
  33198. if (!detect) detect = own;
  33199. // Already had
  33200. if (own) {
  33201. value = node.raws[own];
  33202. if (typeof value !== 'undefined') return value
  33203. }
  33204. let parent = node.parent;
  33205. if (detect === 'before') {
  33206. // Hack for first rule in CSS
  33207. if (!parent || (parent.type === 'root' && parent.first === node)) {
  33208. return ''
  33209. }
  33210. // `root` nodes in `document` should use only their own raws
  33211. if (parent && parent.type === 'document') {
  33212. return ''
  33213. }
  33214. }
  33215. // Floating child without parent
  33216. if (!parent) return DEFAULT_RAW[detect]
  33217. // Detect style by other nodes
  33218. let root = node.root();
  33219. if (!root.rawCache) root.rawCache = {};
  33220. if (typeof root.rawCache[detect] !== 'undefined') {
  33221. return root.rawCache[detect]
  33222. }
  33223. if (detect === 'before' || detect === 'after') {
  33224. return this.beforeAfter(node, detect)
  33225. } else {
  33226. let method = 'raw' + capitalize(detect);
  33227. if (this[method]) {
  33228. value = this[method](root, node);
  33229. } else {
  33230. root.walk(i => {
  33231. value = i.raws[own];
  33232. if (typeof value !== 'undefined') return false
  33233. });
  33234. }
  33235. }
  33236. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33237. root.rawCache[detect] = value;
  33238. return value
  33239. }
  33240. rawBeforeClose(root) {
  33241. let value;
  33242. root.walk(i => {
  33243. if (i.nodes && i.nodes.length > 0) {
  33244. if (typeof i.raws.after !== 'undefined') {
  33245. value = i.raws.after;
  33246. if (value.includes('\n')) {
  33247. value = value.replace(/[^\n]+$/, '');
  33248. }
  33249. return false
  33250. }
  33251. }
  33252. });
  33253. if (value) value = value.replace(/\S/g, '');
  33254. return value
  33255. }
  33256. rawBeforeComment(root, node) {
  33257. let value;
  33258. root.walkComments(i => {
  33259. if (typeof i.raws.before !== 'undefined') {
  33260. value = i.raws.before;
  33261. if (value.includes('\n')) {
  33262. value = value.replace(/[^\n]+$/, '');
  33263. }
  33264. return false
  33265. }
  33266. });
  33267. if (typeof value === 'undefined') {
  33268. value = this.raw(node, null, 'beforeDecl');
  33269. } else if (value) {
  33270. value = value.replace(/\S/g, '');
  33271. }
  33272. return value
  33273. }
  33274. rawBeforeDecl(root, node) {
  33275. let value;
  33276. root.walkDecls(i => {
  33277. if (typeof i.raws.before !== 'undefined') {
  33278. value = i.raws.before;
  33279. if (value.includes('\n')) {
  33280. value = value.replace(/[^\n]+$/, '');
  33281. }
  33282. return false
  33283. }
  33284. });
  33285. if (typeof value === 'undefined') {
  33286. value = this.raw(node, null, 'beforeRule');
  33287. } else if (value) {
  33288. value = value.replace(/\S/g, '');
  33289. }
  33290. return value
  33291. }
  33292. rawBeforeOpen(root) {
  33293. let value;
  33294. root.walk(i => {
  33295. if (i.type !== 'decl') {
  33296. value = i.raws.between;
  33297. if (typeof value !== 'undefined') return false
  33298. }
  33299. });
  33300. return value
  33301. }
  33302. rawBeforeRule(root) {
  33303. let value;
  33304. root.walk(i => {
  33305. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33306. if (typeof i.raws.before !== 'undefined') {
  33307. value = i.raws.before;
  33308. if (value.includes('\n')) {
  33309. value = value.replace(/[^\n]+$/, '');
  33310. }
  33311. return false
  33312. }
  33313. }
  33314. });
  33315. if (value) value = value.replace(/\S/g, '');
  33316. return value
  33317. }
  33318. rawColon(root) {
  33319. let value;
  33320. root.walkDecls(i => {
  33321. if (typeof i.raws.between !== 'undefined') {
  33322. value = i.raws.between.replace(/[^\s:]/g, '');
  33323. return false
  33324. }
  33325. });
  33326. return value
  33327. }
  33328. rawEmptyBody(root) {
  33329. let value;
  33330. root.walk(i => {
  33331. if (i.nodes && i.nodes.length === 0) {
  33332. value = i.raws.after;
  33333. if (typeof value !== 'undefined') return false
  33334. }
  33335. });
  33336. return value
  33337. }
  33338. rawIndent(root) {
  33339. if (root.raws.indent) return root.raws.indent
  33340. let value;
  33341. root.walk(i => {
  33342. let p = i.parent;
  33343. if (p && p !== root && p.parent && p.parent === root) {
  33344. if (typeof i.raws.before !== 'undefined') {
  33345. let parts = i.raws.before.split('\n');
  33346. value = parts[parts.length - 1];
  33347. value = value.replace(/\S/g, '');
  33348. return false
  33349. }
  33350. }
  33351. });
  33352. return value
  33353. }
  33354. rawSemicolon(root) {
  33355. let value;
  33356. root.walk(i => {
  33357. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33358. value = i.raws.semicolon;
  33359. if (typeof value !== 'undefined') return false
  33360. }
  33361. });
  33362. return value
  33363. }
  33364. rawValue(node, prop) {
  33365. let value = node[prop];
  33366. let raw = node.raws[prop];
  33367. if (raw && raw.value === value) {
  33368. return raw.raw
  33369. }
  33370. return value
  33371. }
  33372. root(node) {
  33373. this.body(node);
  33374. if (node.raws.after) {
  33375. let after = node.raws.after;
  33376. let isDocument = node.parent && node.parent.type === 'document';
  33377. this.builder(isDocument ? after : escapeHTMLInCSS(after));
  33378. }
  33379. }
  33380. rule(node) {
  33381. this.block(node, this.rawValue(node, 'selector'));
  33382. if (node.raws.ownSemicolon) {
  33383. this.builder(escapeHTMLInCSS(node.raws.ownSemicolon), node, 'end');
  33384. }
  33385. }
  33386. stringify(node, semicolon) {
  33387. /* c8 ignore start */
  33388. if (!this[node.type]) {
  33389. throw new Error(
  33390. 'Unknown AST node type ' +
  33391. node.type +
  33392. '. ' +
  33393. 'Maybe you need to change PostCSS stringifier.'
  33394. )
  33395. }
  33396. /* c8 ignore stop */
  33397. this[node.type](node, semicolon);
  33398. }
  33399. }
  33400. stringifier = Stringifier;
  33401. Stringifier.default = Stringifier;
  33402. return stringifier;
  33403. }
  33404. var stringify_1;
  33405. var hasRequiredStringify;
  33406. function requireStringify () {
  33407. if (hasRequiredStringify) return stringify_1;
  33408. hasRequiredStringify = 1;
  33409. let Stringifier = /*@__PURE__*/ requireStringifier();
  33410. function stringify(node, builder) {
  33411. let str = new Stringifier(builder);
  33412. str.stringify(node);
  33413. }
  33414. stringify_1 = stringify;
  33415. stringify.default = stringify;
  33416. return stringify_1;
  33417. }
  33418. var symbols = {};
  33419. var hasRequiredSymbols;
  33420. function requireSymbols () {
  33421. if (hasRequiredSymbols) return symbols;
  33422. hasRequiredSymbols = 1;
  33423. symbols.isClean = Symbol('isClean');
  33424. symbols.my = Symbol('my');
  33425. return symbols;
  33426. }
  33427. var node$2;
  33428. var hasRequiredNode$2;
  33429. function requireNode$2 () {
  33430. if (hasRequiredNode$2) return node$2;
  33431. hasRequiredNode$2 = 1;
  33432. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  33433. let Stringifier = /*@__PURE__*/ requireStringifier();
  33434. let stringify = /*@__PURE__*/ requireStringify();
  33435. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33436. function cloneNode(obj, parent) {
  33437. let cloned = new obj.constructor();
  33438. for (let i in obj) {
  33439. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33440. /* c8 ignore next 2 */
  33441. continue
  33442. }
  33443. if (i === 'proxyCache') continue
  33444. let value = obj[i];
  33445. let type = typeof value;
  33446. if (i === 'parent' && type === 'object') {
  33447. if (parent) cloned[i] = parent;
  33448. } else if (i === 'source') {
  33449. cloned[i] = value;
  33450. } else if (Array.isArray(value)) {
  33451. cloned[i] = value.map(j => cloneNode(j, cloned));
  33452. } else {
  33453. if (type === 'object' && value !== null) value = cloneNode(value);
  33454. cloned[i] = value;
  33455. }
  33456. }
  33457. return cloned
  33458. }
  33459. function sourceOffset(inputCSS, position) {
  33460. // Not all custom syntaxes support `offset` in `source.start` and `source.end`
  33461. if (position && typeof position.offset !== 'undefined') {
  33462. return position.offset
  33463. }
  33464. let column = 1;
  33465. let line = 1;
  33466. let offset = 0;
  33467. for (let i = 0; i < inputCSS.length; i++) {
  33468. if (line === position.line && column === position.column) {
  33469. offset = i;
  33470. break
  33471. }
  33472. if (inputCSS[i] === '\n') {
  33473. column = 1;
  33474. line += 1;
  33475. } else {
  33476. column += 1;
  33477. }
  33478. }
  33479. return offset
  33480. }
  33481. class Node {
  33482. get proxyOf() {
  33483. return this
  33484. }
  33485. constructor(defaults = {}) {
  33486. this.raws = {};
  33487. this[isClean] = false;
  33488. this[my] = true;
  33489. for (let name in defaults) {
  33490. if (name === 'nodes') {
  33491. this.nodes = [];
  33492. for (let node of defaults[name]) {
  33493. if (typeof node.clone === 'function') {
  33494. this.append(node.clone());
  33495. } else {
  33496. this.append(node);
  33497. }
  33498. }
  33499. } else {
  33500. this[name] = defaults[name];
  33501. }
  33502. }
  33503. }
  33504. addToError(error) {
  33505. error.postcssNode = this;
  33506. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33507. let s = this.source;
  33508. error.stack = error.stack.replace(
  33509. /\n\s{4}at /,
  33510. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33511. );
  33512. }
  33513. return error
  33514. }
  33515. after(add) {
  33516. this.parent.insertAfter(this, add);
  33517. return this
  33518. }
  33519. assign(overrides = {}) {
  33520. for (let name in overrides) {
  33521. this[name] = overrides[name];
  33522. }
  33523. return this
  33524. }
  33525. before(add) {
  33526. this.parent.insertBefore(this, add);
  33527. return this
  33528. }
  33529. cleanRaws(keepBetween) {
  33530. delete this.raws.before;
  33531. delete this.raws.after;
  33532. if (!keepBetween) delete this.raws.between;
  33533. }
  33534. clone(overrides = {}) {
  33535. let cloned = cloneNode(this);
  33536. for (let name in overrides) {
  33537. cloned[name] = overrides[name];
  33538. }
  33539. return cloned
  33540. }
  33541. cloneAfter(overrides = {}) {
  33542. let cloned = this.clone(overrides);
  33543. this.parent.insertAfter(this, cloned);
  33544. return cloned
  33545. }
  33546. cloneBefore(overrides = {}) {
  33547. let cloned = this.clone(overrides);
  33548. this.parent.insertBefore(this, cloned);
  33549. return cloned
  33550. }
  33551. error(message, opts = {}) {
  33552. if (this.source) {
  33553. let { end, start } = this.rangeBy(opts);
  33554. return this.source.input.error(
  33555. message,
  33556. { column: start.column, line: start.line },
  33557. { column: end.column, line: end.line },
  33558. opts
  33559. )
  33560. }
  33561. return new CssSyntaxError(message)
  33562. }
  33563. getProxyProcessor() {
  33564. return {
  33565. get(node, prop) {
  33566. if (prop === 'proxyOf') {
  33567. return node
  33568. } else if (prop === 'root') {
  33569. return () => node.root().toProxy()
  33570. } else {
  33571. return node[prop]
  33572. }
  33573. },
  33574. set(node, prop, value) {
  33575. if (node[prop] === value) return true
  33576. node[prop] = value;
  33577. if (
  33578. prop === 'prop' ||
  33579. prop === 'value' ||
  33580. prop === 'name' ||
  33581. prop === 'params' ||
  33582. prop === 'important' ||
  33583. /* c8 ignore next */
  33584. prop === 'text'
  33585. ) {
  33586. node.markDirty();
  33587. }
  33588. return true
  33589. }
  33590. }
  33591. }
  33592. /* c8 ignore next 3 */
  33593. markClean() {
  33594. this[isClean] = true;
  33595. }
  33596. markDirty() {
  33597. if (this[isClean]) {
  33598. this[isClean] = false;
  33599. let next = this;
  33600. while ((next = next.parent)) {
  33601. next[isClean] = false;
  33602. }
  33603. }
  33604. }
  33605. next() {
  33606. if (!this.parent) return undefined
  33607. let index = this.parent.index(this);
  33608. return this.parent.nodes[index + 1]
  33609. }
  33610. positionBy(opts = {}) {
  33611. let pos = this.source.start;
  33612. if (opts.index) {
  33613. pos = this.positionInside(opts.index);
  33614. } else if (opts.word) {
  33615. let inputString =
  33616. 'document' in this.source.input
  33617. ? this.source.input.document
  33618. : this.source.input.css;
  33619. let stringRepresentation = inputString.slice(
  33620. sourceOffset(inputString, this.source.start),
  33621. sourceOffset(inputString, this.source.end)
  33622. );
  33623. let index = stringRepresentation.indexOf(opts.word);
  33624. if (index !== -1) pos = this.positionInside(index);
  33625. }
  33626. return pos
  33627. }
  33628. positionInside(index) {
  33629. let column = this.source.start.column;
  33630. let line = this.source.start.line;
  33631. let inputString =
  33632. 'document' in this.source.input
  33633. ? this.source.input.document
  33634. : this.source.input.css;
  33635. let offset = sourceOffset(inputString, this.source.start);
  33636. let end = offset + index;
  33637. for (let i = offset; i < end; i++) {
  33638. if (inputString[i] === '\n') {
  33639. column = 1;
  33640. line += 1;
  33641. } else {
  33642. column += 1;
  33643. }
  33644. }
  33645. return { column, line, offset: end }
  33646. }
  33647. prev() {
  33648. if (!this.parent) return undefined
  33649. let index = this.parent.index(this);
  33650. return this.parent.nodes[index - 1]
  33651. }
  33652. rangeBy(opts = {}) {
  33653. let inputString =
  33654. 'document' in this.source.input
  33655. ? this.source.input.document
  33656. : this.source.input.css;
  33657. let start = {
  33658. column: this.source.start.column,
  33659. line: this.source.start.line,
  33660. offset: sourceOffset(inputString, this.source.start)
  33661. };
  33662. let end = this.source.end
  33663. ? {
  33664. column: this.source.end.column + 1,
  33665. line: this.source.end.line,
  33666. offset:
  33667. typeof this.source.end.offset === 'number'
  33668. ? // `source.end.offset` is exclusive, so we don't need to add 1
  33669. this.source.end.offset
  33670. : // Since line/column in this.source.end is inclusive,
  33671. // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
  33672. // So, we add 1 to convert it to exclusive.
  33673. sourceOffset(inputString, this.source.end) + 1
  33674. }
  33675. : {
  33676. column: start.column + 1,
  33677. line: start.line,
  33678. offset: start.offset + 1
  33679. };
  33680. if (opts.word) {
  33681. let stringRepresentation = inputString.slice(
  33682. sourceOffset(inputString, this.source.start),
  33683. sourceOffset(inputString, this.source.end)
  33684. );
  33685. let index = stringRepresentation.indexOf(opts.word);
  33686. if (index !== -1) {
  33687. start = this.positionInside(index);
  33688. end = this.positionInside(index + opts.word.length);
  33689. }
  33690. } else {
  33691. if (opts.start) {
  33692. start = {
  33693. column: opts.start.column,
  33694. line: opts.start.line,
  33695. offset: sourceOffset(inputString, opts.start)
  33696. };
  33697. } else if (opts.index) {
  33698. start = this.positionInside(opts.index);
  33699. }
  33700. if (opts.end) {
  33701. end = {
  33702. column: opts.end.column,
  33703. line: opts.end.line,
  33704. offset: sourceOffset(inputString, opts.end)
  33705. };
  33706. } else if (typeof opts.endIndex === 'number') {
  33707. end = this.positionInside(opts.endIndex);
  33708. } else if (opts.index) {
  33709. end = this.positionInside(opts.index + 1);
  33710. }
  33711. }
  33712. if (
  33713. end.line < start.line ||
  33714. (end.line === start.line && end.column <= start.column)
  33715. ) {
  33716. end = {
  33717. column: start.column + 1,
  33718. line: start.line,
  33719. offset: start.offset + 1
  33720. };
  33721. }
  33722. return { end, start }
  33723. }
  33724. raw(prop, defaultType) {
  33725. let str = new Stringifier();
  33726. return str.raw(this, prop, defaultType)
  33727. }
  33728. remove() {
  33729. if (this.parent) {
  33730. this.parent.removeChild(this);
  33731. }
  33732. this.parent = undefined;
  33733. return this
  33734. }
  33735. replaceWith(...nodes) {
  33736. if (this.parent) {
  33737. let bookmark = this;
  33738. let foundSelf = false;
  33739. for (let node of nodes) {
  33740. if (node === this) {
  33741. foundSelf = true;
  33742. } else if (foundSelf) {
  33743. this.parent.insertAfter(bookmark, node);
  33744. bookmark = node;
  33745. } else {
  33746. this.parent.insertBefore(bookmark, node);
  33747. }
  33748. }
  33749. if (!foundSelf) {
  33750. this.remove();
  33751. }
  33752. }
  33753. return this
  33754. }
  33755. root() {
  33756. let result = this;
  33757. while (result.parent && result.parent.type !== 'document') {
  33758. result = result.parent;
  33759. }
  33760. return result
  33761. }
  33762. toJSON(_, inputs) {
  33763. let fixed = {};
  33764. let emitInputs = inputs == null;
  33765. inputs = inputs || new Map();
  33766. let inputsNextIndex = 0;
  33767. for (let name in this) {
  33768. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33769. /* c8 ignore next 2 */
  33770. continue
  33771. }
  33772. if (name === 'parent' || name === 'proxyCache') continue
  33773. let value = this[name];
  33774. if (Array.isArray(value)) {
  33775. fixed[name] = value.map(i => {
  33776. if (typeof i === 'object' && i.toJSON) {
  33777. return i.toJSON(null, inputs)
  33778. } else {
  33779. return i
  33780. }
  33781. });
  33782. } else if (typeof value === 'object' && value.toJSON) {
  33783. fixed[name] = value.toJSON(null, inputs);
  33784. } else if (name === 'source') {
  33785. if (value == null) continue
  33786. let inputId = inputs.get(value.input);
  33787. if (inputId == null) {
  33788. inputId = inputsNextIndex;
  33789. inputs.set(value.input, inputsNextIndex);
  33790. inputsNextIndex++;
  33791. }
  33792. fixed[name] = {
  33793. end: value.end,
  33794. inputId,
  33795. start: value.start
  33796. };
  33797. } else {
  33798. fixed[name] = value;
  33799. }
  33800. }
  33801. if (emitInputs) {
  33802. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33803. }
  33804. return fixed
  33805. }
  33806. toProxy() {
  33807. if (!this.proxyCache) {
  33808. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33809. }
  33810. return this.proxyCache
  33811. }
  33812. toString(stringifier = stringify) {
  33813. if (stringifier.stringify) stringifier = stringifier.stringify;
  33814. let result = '';
  33815. stringifier(this, i => {
  33816. result += i;
  33817. });
  33818. return result
  33819. }
  33820. warn(result, text, opts = {}) {
  33821. let data = { node: this };
  33822. for (let i in opts) data[i] = opts[i];
  33823. return result.warn(text, data)
  33824. }
  33825. }
  33826. node$2 = Node;
  33827. Node.default = Node;
  33828. return node$2;
  33829. }
  33830. var comment$1;
  33831. var hasRequiredComment$1;
  33832. function requireComment$1 () {
  33833. if (hasRequiredComment$1) return comment$1;
  33834. hasRequiredComment$1 = 1;
  33835. let Node = /*@__PURE__*/ requireNode$2();
  33836. class Comment extends Node {
  33837. constructor(defaults) {
  33838. super(defaults);
  33839. this.type = 'comment';
  33840. }
  33841. }
  33842. comment$1 = Comment;
  33843. Comment.default = Comment;
  33844. return comment$1;
  33845. }
  33846. var declaration;
  33847. var hasRequiredDeclaration;
  33848. function requireDeclaration () {
  33849. if (hasRequiredDeclaration) return declaration;
  33850. hasRequiredDeclaration = 1;
  33851. let Node = /*@__PURE__*/ requireNode$2();
  33852. class Declaration extends Node {
  33853. get variable() {
  33854. return this.prop.startsWith('--') || this.prop[0] === '$'
  33855. }
  33856. constructor(defaults) {
  33857. if (
  33858. defaults &&
  33859. typeof defaults.value !== 'undefined' &&
  33860. typeof defaults.value !== 'string'
  33861. ) {
  33862. defaults = { ...defaults, value: String(defaults.value) };
  33863. }
  33864. super(defaults);
  33865. this.type = 'decl';
  33866. }
  33867. }
  33868. declaration = Declaration;
  33869. Declaration.default = Declaration;
  33870. return declaration;
  33871. }
  33872. var container$1;
  33873. var hasRequiredContainer$1;
  33874. function requireContainer$1 () {
  33875. if (hasRequiredContainer$1) return container$1;
  33876. hasRequiredContainer$1 = 1;
  33877. let Comment = /*@__PURE__*/ requireComment$1();
  33878. let Declaration = /*@__PURE__*/ requireDeclaration();
  33879. let Node = /*@__PURE__*/ requireNode$2();
  33880. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33881. let AtRule, parse, Root, Rule;
  33882. function cleanSource(nodes) {
  33883. return nodes.map(i => {
  33884. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33885. delete i.source;
  33886. return i
  33887. })
  33888. }
  33889. function markTreeDirty(node) {
  33890. node[isClean] = false;
  33891. if (node.proxyOf.nodes) {
  33892. for (let i of node.proxyOf.nodes) {
  33893. markTreeDirty(i);
  33894. }
  33895. }
  33896. }
  33897. class Container extends Node {
  33898. get first() {
  33899. if (!this.proxyOf.nodes) return undefined
  33900. return this.proxyOf.nodes[0]
  33901. }
  33902. get last() {
  33903. if (!this.proxyOf.nodes) return undefined
  33904. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  33905. }
  33906. append(...children) {
  33907. for (let child of children) {
  33908. let nodes = this.normalize(child, this.last);
  33909. for (let node of nodes) this.proxyOf.nodes.push(node);
  33910. }
  33911. this.markDirty();
  33912. return this
  33913. }
  33914. cleanRaws(keepBetween) {
  33915. super.cleanRaws(keepBetween);
  33916. if (this.nodes) {
  33917. for (let node of this.nodes) node.cleanRaws(keepBetween);
  33918. }
  33919. }
  33920. each(callback) {
  33921. if (!this.proxyOf.nodes) return undefined
  33922. let iterator = this.getIterator();
  33923. let index, result;
  33924. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  33925. index = this.indexes[iterator];
  33926. result = callback(this.proxyOf.nodes[index], index);
  33927. if (result === false) break
  33928. this.indexes[iterator] += 1;
  33929. }
  33930. delete this.indexes[iterator];
  33931. return result
  33932. }
  33933. every(condition) {
  33934. return this.nodes.every(condition)
  33935. }
  33936. getIterator() {
  33937. if (!this.lastEach) this.lastEach = 0;
  33938. if (!this.indexes) this.indexes = {};
  33939. this.lastEach += 1;
  33940. let iterator = this.lastEach;
  33941. this.indexes[iterator] = 0;
  33942. return iterator
  33943. }
  33944. getProxyProcessor() {
  33945. return {
  33946. get(node, prop) {
  33947. if (prop === 'proxyOf') {
  33948. return node
  33949. } else if (!node[prop]) {
  33950. return node[prop]
  33951. } else if (
  33952. prop === 'each' ||
  33953. (typeof prop === 'string' && prop.startsWith('walk'))
  33954. ) {
  33955. return (...args) => {
  33956. return node[prop](
  33957. ...args.map(i => {
  33958. if (typeof i === 'function') {
  33959. return (child, index) => i(child.toProxy(), index)
  33960. } else {
  33961. return i
  33962. }
  33963. })
  33964. )
  33965. }
  33966. } else if (prop === 'every' || prop === 'some') {
  33967. return cb => {
  33968. return node[prop]((child, ...other) =>
  33969. cb(child.toProxy(), ...other)
  33970. )
  33971. }
  33972. } else if (prop === 'root') {
  33973. return () => node.root().toProxy()
  33974. } else if (prop === 'nodes') {
  33975. return node.nodes.map(i => i.toProxy())
  33976. } else if (prop === 'first' || prop === 'last') {
  33977. return node[prop].toProxy()
  33978. } else {
  33979. return node[prop]
  33980. }
  33981. },
  33982. set(node, prop, value) {
  33983. if (node[prop] === value) return true
  33984. node[prop] = value;
  33985. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  33986. node.markDirty();
  33987. }
  33988. return true
  33989. }
  33990. }
  33991. }
  33992. index(child) {
  33993. if (typeof child === 'number') return child
  33994. if (child.proxyOf) child = child.proxyOf;
  33995. return this.proxyOf.nodes.indexOf(child)
  33996. }
  33997. insertAfter(exist, add) {
  33998. let existIndex = this.index(exist);
  33999. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  34000. existIndex = this.index(exist);
  34001. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  34002. let index;
  34003. for (let id in this.indexes) {
  34004. index = this.indexes[id];
  34005. if (existIndex < index) {
  34006. this.indexes[id] = index + nodes.length;
  34007. }
  34008. }
  34009. this.markDirty();
  34010. return this
  34011. }
  34012. insertBefore(exist, add) {
  34013. let existIndex = this.index(exist);
  34014. let type = existIndex === 0 ? 'prepend' : false;
  34015. let nodes = this.normalize(
  34016. add,
  34017. this.proxyOf.nodes[existIndex],
  34018. type
  34019. ).reverse();
  34020. existIndex = this.index(exist);
  34021. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  34022. let index;
  34023. for (let id in this.indexes) {
  34024. index = this.indexes[id];
  34025. if (existIndex <= index) {
  34026. this.indexes[id] = index + nodes.length;
  34027. }
  34028. }
  34029. this.markDirty();
  34030. return this
  34031. }
  34032. normalize(nodes, sample) {
  34033. if (typeof nodes === 'string') {
  34034. nodes = cleanSource(parse(nodes).nodes);
  34035. } else if (typeof nodes === 'undefined') {
  34036. nodes = [];
  34037. } else if (Array.isArray(nodes)) {
  34038. nodes = nodes.slice(0);
  34039. for (let i of nodes) {
  34040. if (i.parent) i.parent.removeChild(i, 'ignore');
  34041. }
  34042. } else if (nodes.type === 'root' && this.type !== 'document') {
  34043. nodes = nodes.nodes.slice(0);
  34044. for (let i of nodes) {
  34045. if (i.parent) i.parent.removeChild(i, 'ignore');
  34046. }
  34047. } else if (nodes.type) {
  34048. nodes = [nodes];
  34049. } else if (nodes.prop) {
  34050. if (typeof nodes.value === 'undefined') {
  34051. throw new Error('Value field is missed in node creation')
  34052. } else if (typeof nodes.value !== 'string') {
  34053. nodes.value = String(nodes.value);
  34054. }
  34055. nodes = [new Declaration(nodes)];
  34056. } else if (nodes.selector || nodes.selectors) {
  34057. nodes = [new Rule(nodes)];
  34058. } else if (nodes.name) {
  34059. nodes = [new AtRule(nodes)];
  34060. } else if (nodes.text) {
  34061. nodes = [new Comment(nodes)];
  34062. } else {
  34063. throw new Error('Unknown node type in node creation')
  34064. }
  34065. let processed = nodes.map(i => {
  34066. /* c8 ignore next */
  34067. if (!i[my]) Container.rebuild(i);
  34068. i = i.proxyOf;
  34069. if (i.parent) i.parent.removeChild(i);
  34070. if (i[isClean]) markTreeDirty(i);
  34071. if (!i.raws) i.raws = {};
  34072. if (typeof i.raws.before === 'undefined') {
  34073. if (sample && typeof sample.raws.before !== 'undefined') {
  34074. i.raws.before = sample.raws.before.replace(/\S/g, '');
  34075. }
  34076. }
  34077. i.parent = this.proxyOf;
  34078. return i
  34079. });
  34080. return processed
  34081. }
  34082. prepend(...children) {
  34083. children = children.reverse();
  34084. for (let child of children) {
  34085. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  34086. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  34087. for (let id in this.indexes) {
  34088. this.indexes[id] = this.indexes[id] + nodes.length;
  34089. }
  34090. }
  34091. this.markDirty();
  34092. return this
  34093. }
  34094. push(child) {
  34095. child.parent = this;
  34096. this.proxyOf.nodes.push(child);
  34097. return this
  34098. }
  34099. removeAll() {
  34100. for (let node of this.proxyOf.nodes) node.parent = undefined;
  34101. this.proxyOf.nodes = [];
  34102. this.markDirty();
  34103. return this
  34104. }
  34105. removeChild(child) {
  34106. child = this.index(child);
  34107. this.proxyOf.nodes[child].parent = undefined;
  34108. this.proxyOf.nodes.splice(child, 1);
  34109. let index;
  34110. for (let id in this.indexes) {
  34111. index = this.indexes[id];
  34112. if (index >= child) {
  34113. this.indexes[id] = index - 1;
  34114. }
  34115. }
  34116. this.markDirty();
  34117. return this
  34118. }
  34119. replaceValues(pattern, opts, callback) {
  34120. if (!callback) {
  34121. callback = opts;
  34122. opts = {};
  34123. }
  34124. this.walkDecls(decl => {
  34125. if (opts.props && !opts.props.includes(decl.prop)) return
  34126. if (opts.fast && !decl.value.includes(opts.fast)) return
  34127. decl.value = decl.value.replace(pattern, callback);
  34128. });
  34129. this.markDirty();
  34130. return this
  34131. }
  34132. some(condition) {
  34133. return this.nodes.some(condition)
  34134. }
  34135. walk(callback) {
  34136. return this.each((child, i) => {
  34137. let result;
  34138. try {
  34139. result = callback(child, i);
  34140. } catch (e) {
  34141. throw child.addToError(e)
  34142. }
  34143. if (result !== false && child.walk) {
  34144. result = child.walk(callback);
  34145. }
  34146. return result
  34147. })
  34148. }
  34149. walkAtRules(name, callback) {
  34150. if (!callback) {
  34151. callback = name;
  34152. return this.walk((child, i) => {
  34153. if (child.type === 'atrule') {
  34154. return callback(child, i)
  34155. }
  34156. })
  34157. }
  34158. if (name instanceof RegExp) {
  34159. return this.walk((child, i) => {
  34160. if (child.type === 'atrule' && name.test(child.name)) {
  34161. return callback(child, i)
  34162. }
  34163. })
  34164. }
  34165. return this.walk((child, i) => {
  34166. if (child.type === 'atrule' && child.name === name) {
  34167. return callback(child, i)
  34168. }
  34169. })
  34170. }
  34171. walkComments(callback) {
  34172. return this.walk((child, i) => {
  34173. if (child.type === 'comment') {
  34174. return callback(child, i)
  34175. }
  34176. })
  34177. }
  34178. walkDecls(prop, callback) {
  34179. if (!callback) {
  34180. callback = prop;
  34181. return this.walk((child, i) => {
  34182. if (child.type === 'decl') {
  34183. return callback(child, i)
  34184. }
  34185. })
  34186. }
  34187. if (prop instanceof RegExp) {
  34188. return this.walk((child, i) => {
  34189. if (child.type === 'decl' && prop.test(child.prop)) {
  34190. return callback(child, i)
  34191. }
  34192. })
  34193. }
  34194. return this.walk((child, i) => {
  34195. if (child.type === 'decl' && child.prop === prop) {
  34196. return callback(child, i)
  34197. }
  34198. })
  34199. }
  34200. walkRules(selector, callback) {
  34201. if (!callback) {
  34202. callback = selector;
  34203. return this.walk((child, i) => {
  34204. if (child.type === 'rule') {
  34205. return callback(child, i)
  34206. }
  34207. })
  34208. }
  34209. if (selector instanceof RegExp) {
  34210. return this.walk((child, i) => {
  34211. if (child.type === 'rule' && selector.test(child.selector)) {
  34212. return callback(child, i)
  34213. }
  34214. })
  34215. }
  34216. return this.walk((child, i) => {
  34217. if (child.type === 'rule' && child.selector === selector) {
  34218. return callback(child, i)
  34219. }
  34220. })
  34221. }
  34222. }
  34223. Container.registerParse = dependant => {
  34224. parse = dependant;
  34225. };
  34226. Container.registerRule = dependant => {
  34227. Rule = dependant;
  34228. };
  34229. Container.registerAtRule = dependant => {
  34230. AtRule = dependant;
  34231. };
  34232. Container.registerRoot = dependant => {
  34233. Root = dependant;
  34234. };
  34235. container$1 = Container;
  34236. Container.default = Container;
  34237. /* c8 ignore start */
  34238. Container.rebuild = node => {
  34239. if (node.type === 'atrule') {
  34240. Object.setPrototypeOf(node, AtRule.prototype);
  34241. } else if (node.type === 'rule') {
  34242. Object.setPrototypeOf(node, Rule.prototype);
  34243. } else if (node.type === 'decl') {
  34244. Object.setPrototypeOf(node, Declaration.prototype);
  34245. } else if (node.type === 'comment') {
  34246. Object.setPrototypeOf(node, Comment.prototype);
  34247. } else if (node.type === 'root') {
  34248. Object.setPrototypeOf(node, Root.prototype);
  34249. }
  34250. node[my] = true;
  34251. if (node.nodes) {
  34252. node.nodes.forEach(child => {
  34253. Container.rebuild(child);
  34254. });
  34255. }
  34256. };
  34257. /* c8 ignore stop */
  34258. return container$1;
  34259. }
  34260. var atRule;
  34261. var hasRequiredAtRule;
  34262. function requireAtRule () {
  34263. if (hasRequiredAtRule) return atRule;
  34264. hasRequiredAtRule = 1;
  34265. let Container = /*@__PURE__*/ requireContainer$1();
  34266. class AtRule extends Container {
  34267. constructor(defaults) {
  34268. super(defaults);
  34269. this.type = 'atrule';
  34270. }
  34271. append(...children) {
  34272. if (!this.proxyOf.nodes) this.nodes = [];
  34273. return super.append(...children)
  34274. }
  34275. prepend(...children) {
  34276. if (!this.proxyOf.nodes) this.nodes = [];
  34277. return super.prepend(...children)
  34278. }
  34279. }
  34280. atRule = AtRule;
  34281. AtRule.default = AtRule;
  34282. Container.registerAtRule(AtRule);
  34283. return atRule;
  34284. }
  34285. var document;
  34286. var hasRequiredDocument;
  34287. function requireDocument () {
  34288. if (hasRequiredDocument) return document;
  34289. hasRequiredDocument = 1;
  34290. let Container = /*@__PURE__*/ requireContainer$1();
  34291. let LazyResult, Processor;
  34292. class Document extends Container {
  34293. constructor(defaults) {
  34294. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34295. super({ type: 'document', ...defaults });
  34296. if (!this.nodes) {
  34297. this.nodes = [];
  34298. }
  34299. }
  34300. toResult(opts = {}) {
  34301. let lazy = new LazyResult(new Processor(), this, opts);
  34302. return lazy.stringify()
  34303. }
  34304. }
  34305. Document.registerLazyResult = dependant => {
  34306. LazyResult = dependant;
  34307. };
  34308. Document.registerProcessor = dependant => {
  34309. Processor = dependant;
  34310. };
  34311. document = Document;
  34312. Document.default = Document;
  34313. return document;
  34314. }
  34315. var nonSecure;
  34316. var hasRequiredNonSecure;
  34317. function requireNonSecure () {
  34318. if (hasRequiredNonSecure) return nonSecure;
  34319. hasRequiredNonSecure = 1;
  34320. // This alphabet uses `A-Za-z0-9_-` symbols.
  34321. // The order of characters is optimized for better gzip and brotli compression.
  34322. // References to the same file (works both for gzip and brotli):
  34323. // `'use`, `andom`, and `rict'`
  34324. // References to the brotli default dictionary:
  34325. // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
  34326. let urlAlphabet =
  34327. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  34328. let customAlphabet = (alphabet, defaultSize = 21) => {
  34329. return (size = defaultSize) => {
  34330. let id = '';
  34331. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34332. let i = size | 0;
  34333. while (i--) {
  34334. // `| 0` is more compact and faster than `Math.floor()`.
  34335. id += alphabet[(Math.random() * alphabet.length) | 0];
  34336. }
  34337. return id
  34338. }
  34339. };
  34340. let nanoid = (size = 21) => {
  34341. let id = '';
  34342. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34343. let i = size | 0;
  34344. while (i--) {
  34345. // `| 0` is more compact and faster than `Math.floor()`.
  34346. id += urlAlphabet[(Math.random() * 64) | 0];
  34347. }
  34348. return id
  34349. };
  34350. nonSecure = { nanoid, customAlphabet };
  34351. return nonSecure;
  34352. }
  34353. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  34354. var previousMap;
  34355. var hasRequiredPreviousMap;
  34356. function requirePreviousMap () {
  34357. if (hasRequiredPreviousMap) return previousMap;
  34358. hasRequiredPreviousMap = 1;
  34359. let { existsSync, readFileSync } = require$$0$1;
  34360. let { dirname, join } = require$$1;
  34361. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34362. function fromBase64(str) {
  34363. if (Buffer$1) {
  34364. return Buffer$1.from(str, 'base64').toString()
  34365. } else {
  34366. /* c8 ignore next 2 */
  34367. return window.atob(str)
  34368. }
  34369. }
  34370. class PreviousMap {
  34371. constructor(css, opts) {
  34372. if (opts.map === false) return
  34373. this.loadAnnotation(css);
  34374. this.inline = this.startWith(this.annotation, 'data:');
  34375. let prev = opts.map ? opts.map.prev : undefined;
  34376. let text = this.loadMap(opts.from, prev);
  34377. if (!this.mapFile && opts.from) {
  34378. this.mapFile = opts.from;
  34379. }
  34380. if (this.mapFile) this.root = dirname(this.mapFile);
  34381. if (text) this.text = text;
  34382. }
  34383. consumer() {
  34384. if (!this.consumerCache) {
  34385. this.consumerCache = new SourceMapConsumer(this.text);
  34386. }
  34387. return this.consumerCache
  34388. }
  34389. decodeInline(text) {
  34390. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  34391. let baseUri = /^data:application\/json;base64,/;
  34392. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  34393. let uri = /^data:application\/json,/;
  34394. let uriMatch = text.match(charsetUri) || text.match(uri);
  34395. if (uriMatch) {
  34396. return decodeURIComponent(text.substr(uriMatch[0].length))
  34397. }
  34398. let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
  34399. if (baseUriMatch) {
  34400. return fromBase64(text.substr(baseUriMatch[0].length))
  34401. }
  34402. let encoding = text.slice('data:application/json;'.length);
  34403. encoding = encoding.slice(0, encoding.indexOf(','));
  34404. throw new Error('Unsupported source map encoding ' + encoding)
  34405. }
  34406. getAnnotationURL(sourceMapString) {
  34407. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  34408. }
  34409. isMap(map) {
  34410. if (typeof map !== 'object') return false
  34411. return (
  34412. typeof map.mappings === 'string' ||
  34413. typeof map._mappings === 'string' ||
  34414. Array.isArray(map.sections)
  34415. )
  34416. }
  34417. loadAnnotation(css) {
  34418. let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
  34419. if (!comments) return
  34420. // sourceMappingURLs from comments, strings, etc.
  34421. let start = css.lastIndexOf(comments.pop());
  34422. let end = css.indexOf('*/', start);
  34423. if (start > -1 && end > -1) {
  34424. // Locate the last sourceMappingURL to avoid pickin
  34425. this.annotation = this.getAnnotationURL(css.substring(start, end));
  34426. }
  34427. }
  34428. loadFile(path) {
  34429. this.root = dirname(path);
  34430. if (existsSync(path)) {
  34431. this.mapFile = path;
  34432. return readFileSync(path, 'utf-8').toString().trim()
  34433. }
  34434. }
  34435. loadMap(file, prev) {
  34436. if (prev === false) return false
  34437. if (prev) {
  34438. if (typeof prev === 'string') {
  34439. return prev
  34440. } else if (typeof prev === 'function') {
  34441. let prevPath = prev(file);
  34442. if (prevPath) {
  34443. let map = this.loadFile(prevPath);
  34444. if (!map) {
  34445. throw new Error(
  34446. 'Unable to load previous source map: ' + prevPath.toString()
  34447. )
  34448. }
  34449. return map
  34450. }
  34451. } else if (prev instanceof SourceMapConsumer) {
  34452. return SourceMapGenerator.fromSourceMap(prev).toString()
  34453. } else if (prev instanceof SourceMapGenerator) {
  34454. return prev.toString()
  34455. } else if (this.isMap(prev)) {
  34456. return JSON.stringify(prev)
  34457. } else {
  34458. throw new Error(
  34459. 'Unsupported previous source map format: ' + prev.toString()
  34460. )
  34461. }
  34462. } else if (this.inline) {
  34463. return this.decodeInline(this.annotation)
  34464. } else if (this.annotation) {
  34465. let map = this.annotation;
  34466. if (file) map = join(dirname(file), map);
  34467. return this.loadFile(map)
  34468. }
  34469. }
  34470. startWith(string, start) {
  34471. if (!string) return false
  34472. return string.substr(0, start.length) === start
  34473. }
  34474. withContent() {
  34475. return !!(
  34476. this.consumer().sourcesContent &&
  34477. this.consumer().sourcesContent.length > 0
  34478. )
  34479. }
  34480. }
  34481. previousMap = PreviousMap;
  34482. PreviousMap.default = PreviousMap;
  34483. return previousMap;
  34484. }
  34485. var input;
  34486. var hasRequiredInput;
  34487. function requireInput () {
  34488. if (hasRequiredInput) return input;
  34489. hasRequiredInput = 1;
  34490. let { nanoid } = /*@__PURE__*/ requireNonSecure();
  34491. let { isAbsolute, resolve } = require$$1;
  34492. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34493. let { fileURLToPath, pathToFileURL } = require$$2;
  34494. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  34495. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34496. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  34497. let lineToIndexCache = Symbol('lineToIndexCache');
  34498. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34499. let pathAvailable = Boolean(resolve && isAbsolute);
  34500. function getLineToIndex(input) {
  34501. if (input[lineToIndexCache]) return input[lineToIndexCache]
  34502. let lines = input.css.split('\n');
  34503. let lineToIndex = new Array(lines.length);
  34504. let prevIndex = 0;
  34505. for (let i = 0, l = lines.length; i < l; i++) {
  34506. lineToIndex[i] = prevIndex;
  34507. prevIndex += lines[i].length + 1;
  34508. }
  34509. input[lineToIndexCache] = lineToIndex;
  34510. return lineToIndex
  34511. }
  34512. class Input {
  34513. get from() {
  34514. return this.file || this.id
  34515. }
  34516. constructor(css, opts = {}) {
  34517. if (
  34518. css === null ||
  34519. typeof css === 'undefined' ||
  34520. (typeof css === 'object' && !css.toString)
  34521. ) {
  34522. throw new Error(`PostCSS received ${css} instead of CSS string`)
  34523. }
  34524. this.css = css.toString();
  34525. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  34526. this.hasBOM = true;
  34527. this.css = this.css.slice(1);
  34528. } else {
  34529. this.hasBOM = false;
  34530. }
  34531. this.document = this.css;
  34532. if (opts.document) this.document = opts.document.toString();
  34533. if (opts.from) {
  34534. if (
  34535. !pathAvailable ||
  34536. /^\w+:\/\//.test(opts.from) ||
  34537. isAbsolute(opts.from)
  34538. ) {
  34539. this.file = opts.from;
  34540. } else {
  34541. this.file = resolve(opts.from);
  34542. }
  34543. }
  34544. if (pathAvailable && sourceMapAvailable) {
  34545. let map = new PreviousMap(this.css, opts);
  34546. if (map.text) {
  34547. this.map = map;
  34548. let file = map.consumer().file;
  34549. if (!this.file && file) this.file = this.mapResolve(file);
  34550. }
  34551. }
  34552. if (!this.file) {
  34553. this.id = '<input css ' + nanoid(6) + '>';
  34554. }
  34555. if (this.map) this.map.file = this.from;
  34556. }
  34557. error(message, line, column, opts = {}) {
  34558. let endColumn, endLine, endOffset, offset, result;
  34559. if (line && typeof line === 'object') {
  34560. let start = line;
  34561. let end = column;
  34562. if (typeof start.offset === 'number') {
  34563. offset = start.offset;
  34564. let pos = this.fromOffset(offset);
  34565. line = pos.line;
  34566. column = pos.col;
  34567. } else {
  34568. line = start.line;
  34569. column = start.column;
  34570. offset = this.fromLineAndColumn(line, column);
  34571. }
  34572. if (typeof end.offset === 'number') {
  34573. endOffset = end.offset;
  34574. let pos = this.fromOffset(endOffset);
  34575. endLine = pos.line;
  34576. endColumn = pos.col;
  34577. } else {
  34578. endLine = end.line;
  34579. endColumn = end.column;
  34580. endOffset = this.fromLineAndColumn(end.line, end.column);
  34581. }
  34582. } else if (!column) {
  34583. offset = line;
  34584. let pos = this.fromOffset(offset);
  34585. line = pos.line;
  34586. column = pos.col;
  34587. } else {
  34588. offset = this.fromLineAndColumn(line, column);
  34589. }
  34590. let origin = this.origin(line, column, endLine, endColumn);
  34591. if (origin) {
  34592. result = new CssSyntaxError(
  34593. message,
  34594. origin.endLine === undefined
  34595. ? origin.line
  34596. : { column: origin.column, line: origin.line },
  34597. origin.endLine === undefined
  34598. ? origin.column
  34599. : { column: origin.endColumn, line: origin.endLine },
  34600. origin.source,
  34601. origin.file,
  34602. opts.plugin
  34603. );
  34604. } else {
  34605. result = new CssSyntaxError(
  34606. message,
  34607. endLine === undefined ? line : { column, line },
  34608. endLine === undefined ? column : { column: endColumn, line: endLine },
  34609. this.css,
  34610. this.file,
  34611. opts.plugin
  34612. );
  34613. }
  34614. result.input = {
  34615. column,
  34616. endColumn,
  34617. endLine,
  34618. endOffset,
  34619. line,
  34620. offset,
  34621. source: this.css
  34622. };
  34623. if (this.file) {
  34624. if (pathToFileURL) {
  34625. result.input.url = pathToFileURL(this.file).toString();
  34626. }
  34627. result.input.file = this.file;
  34628. }
  34629. return result
  34630. }
  34631. fromLineAndColumn(line, column) {
  34632. let lineToIndex = getLineToIndex(this);
  34633. let index = lineToIndex[line - 1];
  34634. return index + column - 1
  34635. }
  34636. fromOffset(offset) {
  34637. let lineToIndex = getLineToIndex(this);
  34638. let lastLine = lineToIndex[lineToIndex.length - 1];
  34639. let min = 0;
  34640. if (offset >= lastLine) {
  34641. min = lineToIndex.length - 1;
  34642. } else {
  34643. let max = lineToIndex.length - 2;
  34644. let mid;
  34645. while (min < max) {
  34646. mid = min + ((max - min) >> 1);
  34647. if (offset < lineToIndex[mid]) {
  34648. max = mid - 1;
  34649. } else if (offset >= lineToIndex[mid + 1]) {
  34650. min = mid + 1;
  34651. } else {
  34652. min = mid;
  34653. break
  34654. }
  34655. }
  34656. }
  34657. return {
  34658. col: offset - lineToIndex[min] + 1,
  34659. line: min + 1
  34660. }
  34661. }
  34662. mapResolve(file) {
  34663. if (/^\w+:\/\//.test(file)) {
  34664. return file
  34665. }
  34666. return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
  34667. }
  34668. origin(line, column, endLine, endColumn) {
  34669. if (!this.map) return false
  34670. let consumer = this.map.consumer();
  34671. let from = consumer.originalPositionFor({ column, line });
  34672. if (!from.source) return false
  34673. let to;
  34674. if (typeof endLine === 'number') {
  34675. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  34676. }
  34677. let fromUrl;
  34678. if (isAbsolute(from.source)) {
  34679. fromUrl = pathToFileURL(from.source);
  34680. } else {
  34681. fromUrl = new URL(
  34682. from.source,
  34683. this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
  34684. );
  34685. }
  34686. let result = {
  34687. column: from.column,
  34688. endColumn: to && to.column,
  34689. endLine: to && to.line,
  34690. line: from.line,
  34691. url: fromUrl.toString()
  34692. };
  34693. if (fromUrl.protocol === 'file:') {
  34694. if (fileURLToPath) {
  34695. result.file = fileURLToPath(fromUrl);
  34696. } else {
  34697. /* c8 ignore next 2 */
  34698. throw new Error(`file: protocol is not available in this PostCSS build`)
  34699. }
  34700. }
  34701. let source = consumer.sourceContentFor(from.source);
  34702. if (source) result.source = source;
  34703. return result
  34704. }
  34705. toJSON() {
  34706. let json = {};
  34707. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  34708. if (this[name] != null) {
  34709. json[name] = this[name];
  34710. }
  34711. }
  34712. if (this.map) {
  34713. json.map = { ...this.map };
  34714. if (json.map.consumerCache) {
  34715. json.map.consumerCache = undefined;
  34716. }
  34717. }
  34718. return json
  34719. }
  34720. }
  34721. input = Input;
  34722. Input.default = Input;
  34723. if (terminalHighlight && terminalHighlight.registerInput) {
  34724. terminalHighlight.registerInput(Input);
  34725. }
  34726. return input;
  34727. }
  34728. var root$1;
  34729. var hasRequiredRoot$1;
  34730. function requireRoot$1 () {
  34731. if (hasRequiredRoot$1) return root$1;
  34732. hasRequiredRoot$1 = 1;
  34733. let Container = /*@__PURE__*/ requireContainer$1();
  34734. let LazyResult, Processor;
  34735. class Root extends Container {
  34736. constructor(defaults) {
  34737. super(defaults);
  34738. this.type = 'root';
  34739. if (!this.nodes) this.nodes = [];
  34740. }
  34741. normalize(child, sample, type) {
  34742. let nodes = super.normalize(child);
  34743. if (sample) {
  34744. if (type === 'prepend') {
  34745. if (this.nodes.length > 1) {
  34746. sample.raws.before = this.nodes[1].raws.before;
  34747. } else {
  34748. delete sample.raws.before;
  34749. }
  34750. } else if (this.first !== sample) {
  34751. for (let node of nodes) {
  34752. node.raws.before = sample.raws.before;
  34753. }
  34754. }
  34755. }
  34756. return nodes
  34757. }
  34758. removeChild(child, ignore) {
  34759. let index = this.index(child);
  34760. if (!ignore && index === 0 && this.nodes.length > 1) {
  34761. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34762. }
  34763. return super.removeChild(child)
  34764. }
  34765. toResult(opts = {}) {
  34766. let lazy = new LazyResult(new Processor(), this, opts);
  34767. return lazy.stringify()
  34768. }
  34769. }
  34770. Root.registerLazyResult = dependant => {
  34771. LazyResult = dependant;
  34772. };
  34773. Root.registerProcessor = dependant => {
  34774. Processor = dependant;
  34775. };
  34776. root$1 = Root;
  34777. Root.default = Root;
  34778. Container.registerRoot(Root);
  34779. return root$1;
  34780. }
  34781. var list_1;
  34782. var hasRequiredList;
  34783. function requireList () {
  34784. if (hasRequiredList) return list_1;
  34785. hasRequiredList = 1;
  34786. let list = {
  34787. comma(string) {
  34788. return list.split(string, [','], true)
  34789. },
  34790. space(string) {
  34791. let spaces = [' ', '\n', '\t'];
  34792. return list.split(string, spaces)
  34793. },
  34794. split(string, separators, last) {
  34795. let array = [];
  34796. let current = '';
  34797. let split = false;
  34798. let func = 0;
  34799. let inQuote = false;
  34800. let prevQuote = '';
  34801. let escape = false;
  34802. for (let letter of string) {
  34803. if (escape) {
  34804. escape = false;
  34805. } else if (letter === '\\') {
  34806. escape = true;
  34807. } else if (inQuote) {
  34808. if (letter === prevQuote) {
  34809. inQuote = false;
  34810. }
  34811. } else if (letter === '"' || letter === "'") {
  34812. inQuote = true;
  34813. prevQuote = letter;
  34814. } else if (letter === '(') {
  34815. func += 1;
  34816. } else if (letter === ')') {
  34817. if (func > 0) func -= 1;
  34818. } else if (func === 0) {
  34819. if (separators.includes(letter)) split = true;
  34820. }
  34821. if (split) {
  34822. if (current !== '') array.push(current.trim());
  34823. current = '';
  34824. split = false;
  34825. } else {
  34826. current += letter;
  34827. }
  34828. }
  34829. if (last || current !== '') array.push(current.trim());
  34830. return array
  34831. }
  34832. };
  34833. list_1 = list;
  34834. list.default = list;
  34835. return list_1;
  34836. }
  34837. var rule;
  34838. var hasRequiredRule;
  34839. function requireRule () {
  34840. if (hasRequiredRule) return rule;
  34841. hasRequiredRule = 1;
  34842. let Container = /*@__PURE__*/ requireContainer$1();
  34843. let list = /*@__PURE__*/ requireList();
  34844. class Rule extends Container {
  34845. get selectors() {
  34846. return list.comma(this.selector)
  34847. }
  34848. set selectors(values) {
  34849. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34850. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34851. this.selector = values.join(sep);
  34852. }
  34853. constructor(defaults) {
  34854. super(defaults);
  34855. this.type = 'rule';
  34856. if (!this.nodes) this.nodes = [];
  34857. }
  34858. }
  34859. rule = Rule;
  34860. Rule.default = Rule;
  34861. Container.registerRule(Rule);
  34862. return rule;
  34863. }
  34864. var fromJSON_1;
  34865. var hasRequiredFromJSON;
  34866. function requireFromJSON () {
  34867. if (hasRequiredFromJSON) return fromJSON_1;
  34868. hasRequiredFromJSON = 1;
  34869. let AtRule = /*@__PURE__*/ requireAtRule();
  34870. let Comment = /*@__PURE__*/ requireComment$1();
  34871. let Declaration = /*@__PURE__*/ requireDeclaration();
  34872. let Input = /*@__PURE__*/ requireInput();
  34873. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34874. let Root = /*@__PURE__*/ requireRoot$1();
  34875. let Rule = /*@__PURE__*/ requireRule();
  34876. function fromJSON(json, inputs) {
  34877. if (Array.isArray(json)) return json.map(n => fromJSON(n))
  34878. let { inputs: ownInputs, ...defaults } = json;
  34879. if (ownInputs) {
  34880. inputs = [];
  34881. for (let input of ownInputs) {
  34882. let inputHydrated = { ...input, __proto__: Input.prototype };
  34883. if (inputHydrated.map) {
  34884. inputHydrated.map = {
  34885. ...inputHydrated.map,
  34886. __proto__: PreviousMap.prototype
  34887. };
  34888. }
  34889. inputs.push(inputHydrated);
  34890. }
  34891. }
  34892. if (defaults.nodes) {
  34893. defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
  34894. }
  34895. if (defaults.source) {
  34896. let { inputId, ...source } = defaults.source;
  34897. defaults.source = source;
  34898. if (inputId != null) {
  34899. defaults.source.input = inputs[inputId];
  34900. }
  34901. }
  34902. if (defaults.type === 'root') {
  34903. return new Root(defaults)
  34904. } else if (defaults.type === 'decl') {
  34905. return new Declaration(defaults)
  34906. } else if (defaults.type === 'rule') {
  34907. return new Rule(defaults)
  34908. } else if (defaults.type === 'comment') {
  34909. return new Comment(defaults)
  34910. } else if (defaults.type === 'atrule') {
  34911. return new AtRule(defaults)
  34912. } else {
  34913. throw new Error('Unknown node type: ' + json.type)
  34914. }
  34915. }
  34916. fromJSON_1 = fromJSON;
  34917. fromJSON.default = fromJSON;
  34918. return fromJSON_1;
  34919. }
  34920. var mapGenerator;
  34921. var hasRequiredMapGenerator;
  34922. function requireMapGenerator () {
  34923. if (hasRequiredMapGenerator) return mapGenerator;
  34924. hasRequiredMapGenerator = 1;
  34925. let { dirname, relative, resolve, sep } = require$$1;
  34926. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34927. let { pathToFileURL } = require$$2;
  34928. let Input = /*@__PURE__*/ requireInput();
  34929. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34930. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  34931. class MapGenerator {
  34932. constructor(stringify, root, opts, cssString) {
  34933. this.stringify = stringify;
  34934. this.mapOpts = opts.map || {};
  34935. this.root = root;
  34936. this.opts = opts;
  34937. this.css = cssString;
  34938. this.originalCSS = cssString;
  34939. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  34940. this.memoizedFileURLs = new Map();
  34941. this.memoizedPaths = new Map();
  34942. this.memoizedURLs = new Map();
  34943. }
  34944. addAnnotation() {
  34945. let content;
  34946. if (this.isInline()) {
  34947. content =
  34948. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  34949. } else if (typeof this.mapOpts.annotation === 'string') {
  34950. content = this.mapOpts.annotation;
  34951. } else if (typeof this.mapOpts.annotation === 'function') {
  34952. content = this.mapOpts.annotation(this.opts.to, this.root);
  34953. } else {
  34954. content = this.outputFile() + '.map';
  34955. }
  34956. let eol = '\n';
  34957. if (this.css.includes('\r\n')) eol = '\r\n';
  34958. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  34959. }
  34960. applyPrevMaps() {
  34961. for (let prev of this.previous()) {
  34962. let from = this.toUrl(this.path(prev.file));
  34963. let root = prev.root || dirname(prev.file);
  34964. let map;
  34965. if (this.mapOpts.sourcesContent === false) {
  34966. map = new SourceMapConsumer(prev.text);
  34967. if (map.sourcesContent) {
  34968. map.sourcesContent = null;
  34969. }
  34970. } else {
  34971. map = prev.consumer();
  34972. }
  34973. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  34974. }
  34975. }
  34976. clearAnnotation() {
  34977. if (this.mapOpts.annotation === false) return
  34978. if (this.root) {
  34979. let node;
  34980. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  34981. node = this.root.nodes[i];
  34982. if (node.type !== 'comment') continue
  34983. if (node.text.startsWith('# sourceMappingURL=')) {
  34984. this.root.removeChild(i);
  34985. }
  34986. }
  34987. } else if (this.css) {
  34988. let startIndex;
  34989. while ((startIndex = this.css.lastIndexOf('/*#')) !== -1) {
  34990. let endIndex = this.css.indexOf('*/', startIndex + 3);
  34991. if (endIndex === -1) break
  34992. while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
  34993. startIndex--;
  34994. }
  34995. this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2);
  34996. }
  34997. }
  34998. }
  34999. generate() {
  35000. this.clearAnnotation();
  35001. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  35002. return this.generateMap()
  35003. } else {
  35004. let result = '';
  35005. this.stringify(this.root, i => {
  35006. result += i;
  35007. });
  35008. return [result]
  35009. }
  35010. }
  35011. generateMap() {
  35012. if (this.root) {
  35013. this.generateString();
  35014. } else if (this.previous().length === 1) {
  35015. let prev = this.previous()[0].consumer();
  35016. prev.file = this.outputFile();
  35017. this.map = SourceMapGenerator.fromSourceMap(prev, {
  35018. ignoreInvalidMapping: true
  35019. });
  35020. } else {
  35021. this.map = new SourceMapGenerator({
  35022. file: this.outputFile(),
  35023. ignoreInvalidMapping: true
  35024. });
  35025. this.map.addMapping({
  35026. generated: { column: 0, line: 1 },
  35027. original: { column: 0, line: 1 },
  35028. source: this.opts.from
  35029. ? this.toUrl(this.path(this.opts.from))
  35030. : '<no source>'
  35031. });
  35032. }
  35033. if (this.isSourcesContent()) this.setSourcesContent();
  35034. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  35035. if (this.isAnnotation()) this.addAnnotation();
  35036. if (this.isInline()) {
  35037. return [this.css]
  35038. } else {
  35039. return [this.css, this.map]
  35040. }
  35041. }
  35042. generateString() {
  35043. this.css = '';
  35044. this.map = new SourceMapGenerator({
  35045. file: this.outputFile(),
  35046. ignoreInvalidMapping: true
  35047. });
  35048. let line = 1;
  35049. let column = 1;
  35050. let noSource = '<no source>';
  35051. let mapping = {
  35052. generated: { column: 0, line: 0 },
  35053. original: { column: 0, line: 0 },
  35054. source: ''
  35055. };
  35056. let last, lines;
  35057. this.stringify(this.root, (str, node, type) => {
  35058. this.css += str;
  35059. if (node && type !== 'end') {
  35060. mapping.generated.line = line;
  35061. mapping.generated.column = column - 1;
  35062. if (node.source && node.source.start) {
  35063. mapping.source = this.sourcePath(node);
  35064. mapping.original.line = node.source.start.line;
  35065. mapping.original.column = node.source.start.column - 1;
  35066. this.map.addMapping(mapping);
  35067. } else {
  35068. mapping.source = noSource;
  35069. mapping.original.line = 1;
  35070. mapping.original.column = 0;
  35071. this.map.addMapping(mapping);
  35072. }
  35073. }
  35074. lines = str.match(/\n/g);
  35075. if (lines) {
  35076. line += lines.length;
  35077. last = str.lastIndexOf('\n');
  35078. column = str.length - last;
  35079. } else {
  35080. column += str.length;
  35081. }
  35082. if (node && type !== 'start') {
  35083. let p = node.parent || { raws: {} };
  35084. let childless =
  35085. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  35086. if (!childless || node !== p.last || p.raws.semicolon) {
  35087. if (node.source && node.source.end) {
  35088. mapping.source = this.sourcePath(node);
  35089. mapping.original.line = node.source.end.line;
  35090. mapping.original.column = node.source.end.column - 1;
  35091. mapping.generated.line = line;
  35092. mapping.generated.column = column - 2;
  35093. this.map.addMapping(mapping);
  35094. } else {
  35095. mapping.source = noSource;
  35096. mapping.original.line = 1;
  35097. mapping.original.column = 0;
  35098. mapping.generated.line = line;
  35099. mapping.generated.column = column - 1;
  35100. this.map.addMapping(mapping);
  35101. }
  35102. }
  35103. }
  35104. });
  35105. }
  35106. isAnnotation() {
  35107. if (this.isInline()) {
  35108. return true
  35109. }
  35110. if (typeof this.mapOpts.annotation !== 'undefined') {
  35111. return this.mapOpts.annotation
  35112. }
  35113. if (this.previous().length) {
  35114. return this.previous().some(i => i.annotation)
  35115. }
  35116. return true
  35117. }
  35118. isInline() {
  35119. if (typeof this.mapOpts.inline !== 'undefined') {
  35120. return this.mapOpts.inline
  35121. }
  35122. let annotation = this.mapOpts.annotation;
  35123. if (typeof annotation !== 'undefined' && annotation !== true) {
  35124. return false
  35125. }
  35126. if (this.previous().length) {
  35127. return this.previous().some(i => i.inline)
  35128. }
  35129. return true
  35130. }
  35131. isMap() {
  35132. if (typeof this.opts.map !== 'undefined') {
  35133. return !!this.opts.map
  35134. }
  35135. return this.previous().length > 0
  35136. }
  35137. isSourcesContent() {
  35138. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  35139. return this.mapOpts.sourcesContent
  35140. }
  35141. if (this.previous().length) {
  35142. return this.previous().some(i => i.withContent())
  35143. }
  35144. return true
  35145. }
  35146. outputFile() {
  35147. if (this.opts.to) {
  35148. return this.path(this.opts.to)
  35149. } else if (this.opts.from) {
  35150. return this.path(this.opts.from)
  35151. } else {
  35152. return 'to.css'
  35153. }
  35154. }
  35155. path(file) {
  35156. if (this.mapOpts.absolute) return file
  35157. if (file.charCodeAt(0) === 60 /* `<` */) return file
  35158. if (/^\w+:\/\//.test(file)) return file
  35159. let cached = this.memoizedPaths.get(file);
  35160. if (cached) return cached
  35161. let from = this.opts.to ? dirname(this.opts.to) : '.';
  35162. if (typeof this.mapOpts.annotation === 'string') {
  35163. from = dirname(resolve(from, this.mapOpts.annotation));
  35164. }
  35165. let path = relative(from, file);
  35166. this.memoizedPaths.set(file, path);
  35167. return path
  35168. }
  35169. previous() {
  35170. if (!this.previousMaps) {
  35171. this.previousMaps = [];
  35172. if (this.root) {
  35173. this.root.walk(node => {
  35174. if (node.source && node.source.input.map) {
  35175. let map = node.source.input.map;
  35176. if (!this.previousMaps.includes(map)) {
  35177. this.previousMaps.push(map);
  35178. }
  35179. }
  35180. });
  35181. } else {
  35182. let input = new Input(this.originalCSS, this.opts);
  35183. if (input.map) this.previousMaps.push(input.map);
  35184. }
  35185. }
  35186. return this.previousMaps
  35187. }
  35188. setSourcesContent() {
  35189. let already = {};
  35190. if (this.root) {
  35191. this.root.walk(node => {
  35192. if (node.source) {
  35193. let from = node.source.input.from;
  35194. if (from && !already[from]) {
  35195. already[from] = true;
  35196. let fromUrl = this.usesFileUrls
  35197. ? this.toFileUrl(from)
  35198. : this.toUrl(this.path(from));
  35199. this.map.setSourceContent(fromUrl, node.source.input.css);
  35200. }
  35201. }
  35202. });
  35203. } else if (this.css) {
  35204. let from = this.opts.from
  35205. ? this.toUrl(this.path(this.opts.from))
  35206. : '<no source>';
  35207. this.map.setSourceContent(from, this.css);
  35208. }
  35209. }
  35210. sourcePath(node) {
  35211. if (this.mapOpts.from) {
  35212. return this.toUrl(this.mapOpts.from)
  35213. } else if (this.usesFileUrls) {
  35214. return this.toFileUrl(node.source.input.from)
  35215. } else {
  35216. return this.toUrl(this.path(node.source.input.from))
  35217. }
  35218. }
  35219. toBase64(str) {
  35220. if (Buffer$1) {
  35221. return Buffer$1.from(str).toString('base64')
  35222. } else {
  35223. return window.btoa(unescape(encodeURIComponent(str)))
  35224. }
  35225. }
  35226. toFileUrl(path) {
  35227. let cached = this.memoizedFileURLs.get(path);
  35228. if (cached) return cached
  35229. if (pathToFileURL) {
  35230. let fileURL = pathToFileURL(path).toString();
  35231. this.memoizedFileURLs.set(path, fileURL);
  35232. return fileURL
  35233. } else {
  35234. throw new Error(
  35235. '`map.absolute` option is not available in this PostCSS build'
  35236. )
  35237. }
  35238. }
  35239. toUrl(path) {
  35240. let cached = this.memoizedURLs.get(path);
  35241. if (cached) return cached
  35242. if (sep === '\\') {
  35243. path = path.replace(/\\/g, '/');
  35244. }
  35245. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  35246. this.memoizedURLs.set(path, url);
  35247. return url
  35248. }
  35249. }
  35250. mapGenerator = MapGenerator;
  35251. return mapGenerator;
  35252. }
  35253. var parser$1;
  35254. var hasRequiredParser$1;
  35255. function requireParser$1 () {
  35256. if (hasRequiredParser$1) return parser$1;
  35257. hasRequiredParser$1 = 1;
  35258. let AtRule = /*@__PURE__*/ requireAtRule();
  35259. let Comment = /*@__PURE__*/ requireComment$1();
  35260. let Declaration = /*@__PURE__*/ requireDeclaration();
  35261. let Root = /*@__PURE__*/ requireRoot$1();
  35262. let Rule = /*@__PURE__*/ requireRule();
  35263. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  35264. const SAFE_COMMENT_NEIGHBOR = {
  35265. empty: true,
  35266. space: true
  35267. };
  35268. function findLastWithPosition(tokens) {
  35269. for (let i = tokens.length - 1; i >= 0; i--) {
  35270. let token = tokens[i];
  35271. let pos = token[3] || token[2];
  35272. if (pos) return pos
  35273. }
  35274. }
  35275. class Parser {
  35276. constructor(input) {
  35277. this.input = input;
  35278. this.root = new Root();
  35279. this.current = this.root;
  35280. this.spaces = '';
  35281. this.semicolon = false;
  35282. this.createTokenizer();
  35283. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  35284. }
  35285. atrule(token) {
  35286. let node = new AtRule();
  35287. node.name = token[1].slice(1);
  35288. if (node.name === '') {
  35289. this.unnamedAtrule(node, token);
  35290. }
  35291. this.init(node, token[2]);
  35292. let type;
  35293. let prev;
  35294. let shift;
  35295. let last = false;
  35296. let open = false;
  35297. let params = [];
  35298. let brackets = [];
  35299. while (!this.tokenizer.endOfFile()) {
  35300. token = this.tokenizer.nextToken();
  35301. type = token[0];
  35302. if (type === '(' || type === '[') {
  35303. brackets.push(type === '(' ? ')' : ']');
  35304. } else if (type === '{' && brackets.length > 0) {
  35305. brackets.push('}');
  35306. } else if (type === brackets[brackets.length - 1]) {
  35307. brackets.pop();
  35308. }
  35309. if (brackets.length === 0) {
  35310. if (type === ';') {
  35311. node.source.end = this.getPosition(token[2]);
  35312. node.source.end.offset++;
  35313. this.semicolon = true;
  35314. break
  35315. } else if (type === '{') {
  35316. open = true;
  35317. break
  35318. } else if (type === '}') {
  35319. if (params.length > 0) {
  35320. shift = params.length - 1;
  35321. prev = params[shift];
  35322. while (prev && prev[0] === 'space') {
  35323. prev = params[--shift];
  35324. }
  35325. if (prev) {
  35326. node.source.end = this.getPosition(prev[3] || prev[2]);
  35327. node.source.end.offset++;
  35328. }
  35329. }
  35330. this.end(token);
  35331. break
  35332. } else {
  35333. params.push(token);
  35334. }
  35335. } else {
  35336. params.push(token);
  35337. }
  35338. if (this.tokenizer.endOfFile()) {
  35339. last = true;
  35340. break
  35341. }
  35342. }
  35343. node.raws.between = this.spacesAndCommentsFromEnd(params);
  35344. if (params.length) {
  35345. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  35346. this.raw(node, 'params', params);
  35347. if (last) {
  35348. token = params[params.length - 1];
  35349. node.source.end = this.getPosition(token[3] || token[2]);
  35350. node.source.end.offset++;
  35351. this.spaces = node.raws.between;
  35352. node.raws.between = '';
  35353. }
  35354. } else {
  35355. node.raws.afterName = '';
  35356. node.params = '';
  35357. }
  35358. if (open) {
  35359. node.nodes = [];
  35360. this.current = node;
  35361. }
  35362. }
  35363. checkMissedSemicolon(tokens) {
  35364. let colon = this.colon(tokens);
  35365. if (colon === false) return
  35366. let founded = 0;
  35367. let token;
  35368. for (let j = colon - 1; j >= 0; j--) {
  35369. token = tokens[j];
  35370. if (token[0] !== 'space') {
  35371. founded += 1;
  35372. if (founded === 2) break
  35373. }
  35374. }
  35375. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35376. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35377. // And because we need it after that one we do +1 to get the next one.
  35378. throw this.input.error(
  35379. 'Missed semicolon',
  35380. token[0] === 'word' ? token[3] + 1 : token[2]
  35381. )
  35382. }
  35383. colon(tokens) {
  35384. let brackets = 0;
  35385. let prev, token, type;
  35386. for (let [i, element] of tokens.entries()) {
  35387. token = element;
  35388. type = token[0];
  35389. if (type === '(') {
  35390. brackets += 1;
  35391. }
  35392. if (type === ')') {
  35393. brackets -= 1;
  35394. }
  35395. if (brackets === 0 && type === ':') {
  35396. if (!prev) {
  35397. this.doubleColon(token);
  35398. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  35399. continue
  35400. } else {
  35401. return i
  35402. }
  35403. }
  35404. prev = token;
  35405. }
  35406. return false
  35407. }
  35408. comment(token) {
  35409. let node = new Comment();
  35410. this.init(node, token[2]);
  35411. node.source.end = this.getPosition(token[3] || token[2]);
  35412. node.source.end.offset++;
  35413. let text = token[1].slice(2, -2);
  35414. if (!text.trim()) {
  35415. node.text = '';
  35416. node.raws.left = text;
  35417. node.raws.right = '';
  35418. } else {
  35419. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  35420. node.text = match[2];
  35421. node.raws.left = match[1];
  35422. node.raws.right = match[3];
  35423. }
  35424. }
  35425. createTokenizer() {
  35426. this.tokenizer = tokenizer(this.input);
  35427. }
  35428. decl(tokens, customProperty) {
  35429. let node = new Declaration();
  35430. this.init(node, tokens[0][2]);
  35431. let last = tokens[tokens.length - 1];
  35432. if (last[0] === ';') {
  35433. this.semicolon = true;
  35434. tokens.pop();
  35435. }
  35436. node.source.end = this.getPosition(
  35437. last[3] || last[2] || findLastWithPosition(tokens)
  35438. );
  35439. node.source.end.offset++;
  35440. while (tokens[0][0] !== 'word') {
  35441. if (tokens.length === 1) this.unknownWord(tokens);
  35442. node.raws.before += tokens.shift()[1];
  35443. }
  35444. node.source.start = this.getPosition(tokens[0][2]);
  35445. node.prop = '';
  35446. while (tokens.length) {
  35447. let type = tokens[0][0];
  35448. if (type === ':' || type === 'space' || type === 'comment') {
  35449. break
  35450. }
  35451. node.prop += tokens.shift()[1];
  35452. }
  35453. node.raws.between = '';
  35454. let token;
  35455. while (tokens.length) {
  35456. token = tokens.shift();
  35457. if (token[0] === ':') {
  35458. node.raws.between += token[1];
  35459. break
  35460. } else {
  35461. if (token[0] === 'word' && /\w/.test(token[1])) {
  35462. this.unknownWord([token]);
  35463. }
  35464. node.raws.between += token[1];
  35465. }
  35466. }
  35467. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35468. node.raws.before += node.prop[0];
  35469. node.prop = node.prop.slice(1);
  35470. }
  35471. let firstSpaces = [];
  35472. let next;
  35473. while (tokens.length) {
  35474. next = tokens[0][0];
  35475. if (next !== 'space' && next !== 'comment') break
  35476. firstSpaces.push(tokens.shift());
  35477. }
  35478. this.precheckMissedSemicolon(tokens);
  35479. for (let i = tokens.length - 1; i >= 0; i--) {
  35480. token = tokens[i];
  35481. if (token[1].toLowerCase() === '!important') {
  35482. node.important = true;
  35483. let string = this.stringFrom(tokens, i);
  35484. string = this.spacesFromEnd(tokens) + string;
  35485. if (string !== ' !important') node.raws.important = string;
  35486. break
  35487. } else if (token[1].toLowerCase() === 'important') {
  35488. let cache = tokens.slice(0);
  35489. let str = '';
  35490. for (let j = i; j > 0; j--) {
  35491. let type = cache[j][0];
  35492. if (str.trim().startsWith('!') && type !== 'space') {
  35493. break
  35494. }
  35495. str = cache.pop()[1] + str;
  35496. }
  35497. if (str.trim().startsWith('!')) {
  35498. node.important = true;
  35499. node.raws.important = str;
  35500. tokens = cache;
  35501. }
  35502. }
  35503. if (token[0] !== 'space' && token[0] !== 'comment') {
  35504. break
  35505. }
  35506. }
  35507. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35508. if (hasWord) {
  35509. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35510. firstSpaces = [];
  35511. }
  35512. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35513. if (node.value.includes(':') && !customProperty) {
  35514. this.checkMissedSemicolon(tokens);
  35515. }
  35516. }
  35517. doubleColon(token) {
  35518. throw this.input.error(
  35519. 'Double colon',
  35520. { offset: token[2] },
  35521. { offset: token[2] + token[1].length }
  35522. )
  35523. }
  35524. emptyRule(token) {
  35525. let node = new Rule();
  35526. this.init(node, token[2]);
  35527. node.selector = '';
  35528. node.raws.between = '';
  35529. this.current = node;
  35530. }
  35531. end(token) {
  35532. if (this.current.nodes && this.current.nodes.length) {
  35533. this.current.raws.semicolon = this.semicolon;
  35534. }
  35535. this.semicolon = false;
  35536. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35537. this.spaces = '';
  35538. if (this.current.parent) {
  35539. this.current.source.end = this.getPosition(token[2]);
  35540. this.current.source.end.offset++;
  35541. this.current = this.current.parent;
  35542. } else {
  35543. this.unexpectedClose(token);
  35544. }
  35545. }
  35546. endFile() {
  35547. if (this.current.parent) this.unclosedBlock();
  35548. if (this.current.nodes && this.current.nodes.length) {
  35549. this.current.raws.semicolon = this.semicolon;
  35550. }
  35551. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35552. this.root.source.end = this.getPosition(this.tokenizer.position());
  35553. }
  35554. freeSemicolon(token) {
  35555. this.spaces += token[1];
  35556. if (this.current.nodes) {
  35557. let prev = this.current.nodes[this.current.nodes.length - 1];
  35558. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35559. prev.raws.ownSemicolon = this.spaces;
  35560. this.spaces = '';
  35561. prev.source.end = this.getPosition(token[2]);
  35562. prev.source.end.offset += prev.raws.ownSemicolon.length;
  35563. }
  35564. }
  35565. }
  35566. // Helpers
  35567. getPosition(offset) {
  35568. let pos = this.input.fromOffset(offset);
  35569. return {
  35570. column: pos.col,
  35571. line: pos.line,
  35572. offset
  35573. }
  35574. }
  35575. init(node, offset) {
  35576. this.current.push(node);
  35577. node.source = {
  35578. input: this.input,
  35579. start: this.getPosition(offset)
  35580. };
  35581. node.raws.before = this.spaces;
  35582. this.spaces = '';
  35583. if (node.type !== 'comment') this.semicolon = false;
  35584. }
  35585. other(start) {
  35586. let end = false;
  35587. let type = null;
  35588. let colon = false;
  35589. let bracket = null;
  35590. let brackets = [];
  35591. let customProperty = start[1].startsWith('--');
  35592. let tokens = [];
  35593. let token = start;
  35594. while (token) {
  35595. type = token[0];
  35596. tokens.push(token);
  35597. if (type === '(' || type === '[') {
  35598. if (!bracket) bracket = token;
  35599. brackets.push(type === '(' ? ')' : ']');
  35600. } else if (customProperty && colon && type === '{') {
  35601. if (!bracket) bracket = token;
  35602. brackets.push('}');
  35603. } else if (brackets.length === 0) {
  35604. if (type === ';') {
  35605. if (colon) {
  35606. this.decl(tokens, customProperty);
  35607. return
  35608. } else {
  35609. break
  35610. }
  35611. } else if (type === '{') {
  35612. this.rule(tokens);
  35613. return
  35614. } else if (type === '}') {
  35615. this.tokenizer.back(tokens.pop());
  35616. end = true;
  35617. break
  35618. } else if (type === ':') {
  35619. colon = true;
  35620. }
  35621. } else if (type === brackets[brackets.length - 1]) {
  35622. brackets.pop();
  35623. if (brackets.length === 0) bracket = null;
  35624. }
  35625. token = this.tokenizer.nextToken();
  35626. }
  35627. if (this.tokenizer.endOfFile()) end = true;
  35628. if (brackets.length > 0) this.unclosedBracket(bracket);
  35629. if (end && colon) {
  35630. if (!customProperty) {
  35631. while (tokens.length) {
  35632. token = tokens[tokens.length - 1][0];
  35633. if (token !== 'space' && token !== 'comment') break
  35634. this.tokenizer.back(tokens.pop());
  35635. }
  35636. }
  35637. this.decl(tokens, customProperty);
  35638. } else {
  35639. this.unknownWord(tokens);
  35640. }
  35641. }
  35642. parse() {
  35643. let token;
  35644. while (!this.tokenizer.endOfFile()) {
  35645. token = this.tokenizer.nextToken();
  35646. switch (token[0]) {
  35647. case 'space':
  35648. this.spaces += token[1];
  35649. break
  35650. case ';':
  35651. this.freeSemicolon(token);
  35652. break
  35653. case '}':
  35654. this.end(token);
  35655. break
  35656. case 'comment':
  35657. this.comment(token);
  35658. break
  35659. case 'at-word':
  35660. this.atrule(token);
  35661. break
  35662. case '{':
  35663. this.emptyRule(token);
  35664. break
  35665. default:
  35666. this.other(token);
  35667. break
  35668. }
  35669. }
  35670. this.endFile();
  35671. }
  35672. precheckMissedSemicolon(/* tokens */) {
  35673. // Hook for Safe Parser
  35674. }
  35675. raw(node, prop, tokens, customProperty) {
  35676. let token, type;
  35677. let length = tokens.length;
  35678. let value = '';
  35679. let clean = true;
  35680. let next, prev;
  35681. for (let i = 0; i < length; i += 1) {
  35682. token = tokens[i];
  35683. type = token[0];
  35684. if (type === 'space' && i === length - 1 && !customProperty) {
  35685. clean = false;
  35686. } else if (type === 'comment') {
  35687. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35688. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35689. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35690. if (value.slice(-1) === ',') {
  35691. clean = false;
  35692. } else {
  35693. value += token[1];
  35694. }
  35695. } else {
  35696. clean = false;
  35697. }
  35698. } else {
  35699. value += token[1];
  35700. }
  35701. }
  35702. if (!clean) {
  35703. let raw = tokens.reduce((all, i) => all + i[1], '');
  35704. node.raws[prop] = { raw, value };
  35705. }
  35706. node[prop] = value;
  35707. }
  35708. rule(tokens) {
  35709. tokens.pop();
  35710. let node = new Rule();
  35711. this.init(node, tokens[0][2]);
  35712. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35713. this.raw(node, 'selector', tokens);
  35714. this.current = node;
  35715. }
  35716. spacesAndCommentsFromEnd(tokens) {
  35717. let lastTokenType;
  35718. let spaces = '';
  35719. while (tokens.length) {
  35720. lastTokenType = tokens[tokens.length - 1][0];
  35721. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35722. spaces = tokens.pop()[1] + spaces;
  35723. }
  35724. return spaces
  35725. }
  35726. // Errors
  35727. spacesAndCommentsFromStart(tokens) {
  35728. let next;
  35729. let spaces = '';
  35730. while (tokens.length) {
  35731. next = tokens[0][0];
  35732. if (next !== 'space' && next !== 'comment') break
  35733. spaces += tokens.shift()[1];
  35734. }
  35735. return spaces
  35736. }
  35737. spacesFromEnd(tokens) {
  35738. let lastTokenType;
  35739. let spaces = '';
  35740. while (tokens.length) {
  35741. lastTokenType = tokens[tokens.length - 1][0];
  35742. if (lastTokenType !== 'space') break
  35743. spaces = tokens.pop()[1] + spaces;
  35744. }
  35745. return spaces
  35746. }
  35747. stringFrom(tokens, from) {
  35748. let result = '';
  35749. for (let i = from; i < tokens.length; i++) {
  35750. result += tokens[i][1];
  35751. }
  35752. tokens.splice(from, tokens.length - from);
  35753. return result
  35754. }
  35755. unclosedBlock() {
  35756. let pos = this.current.source.start;
  35757. throw this.input.error('Unclosed block', pos.line, pos.column)
  35758. }
  35759. unclosedBracket(bracket) {
  35760. throw this.input.error(
  35761. 'Unclosed bracket',
  35762. { offset: bracket[2] },
  35763. { offset: bracket[2] + 1 }
  35764. )
  35765. }
  35766. unexpectedClose(token) {
  35767. throw this.input.error(
  35768. 'Unexpected }',
  35769. { offset: token[2] },
  35770. { offset: token[2] + 1 }
  35771. )
  35772. }
  35773. unknownWord(tokens) {
  35774. throw this.input.error(
  35775. 'Unknown word ' + tokens[0][1],
  35776. { offset: tokens[0][2] },
  35777. { offset: tokens[0][2] + tokens[0][1].length }
  35778. )
  35779. }
  35780. unnamedAtrule(node, token) {
  35781. throw this.input.error(
  35782. 'At-rule without name',
  35783. { offset: token[2] },
  35784. { offset: token[2] + token[1].length }
  35785. )
  35786. }
  35787. }
  35788. parser$1 = Parser;
  35789. return parser$1;
  35790. }
  35791. var parse_1;
  35792. var hasRequiredParse;
  35793. function requireParse () {
  35794. if (hasRequiredParse) return parse_1;
  35795. hasRequiredParse = 1;
  35796. let Container = /*@__PURE__*/ requireContainer$1();
  35797. let Input = /*@__PURE__*/ requireInput();
  35798. let Parser = /*@__PURE__*/ requireParser$1();
  35799. function parse(css, opts) {
  35800. let input = new Input(css, opts);
  35801. let parser = new Parser(input);
  35802. try {
  35803. parser.parse();
  35804. } catch (e) {
  35805. if (browser$1.env.NODE_ENV !== 'production') {
  35806. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35807. if (/\.scss$/i.test(opts.from)) {
  35808. e.message +=
  35809. '\nYou tried to parse SCSS with ' +
  35810. 'the standard CSS parser; ' +
  35811. 'try again with the postcss-scss parser';
  35812. } else if (/\.sass/i.test(opts.from)) {
  35813. e.message +=
  35814. '\nYou tried to parse Sass with ' +
  35815. 'the standard CSS parser; ' +
  35816. 'try again with the postcss-sass parser';
  35817. } else if (/\.less$/i.test(opts.from)) {
  35818. e.message +=
  35819. '\nYou tried to parse Less with ' +
  35820. 'the standard CSS parser; ' +
  35821. 'try again with the postcss-less parser';
  35822. }
  35823. }
  35824. }
  35825. throw e
  35826. }
  35827. return parser.root
  35828. }
  35829. parse_1 = parse;
  35830. parse.default = parse;
  35831. Container.registerParse(parse);
  35832. return parse_1;
  35833. }
  35834. var warning;
  35835. var hasRequiredWarning;
  35836. function requireWarning () {
  35837. if (hasRequiredWarning) return warning;
  35838. hasRequiredWarning = 1;
  35839. class Warning {
  35840. constructor(text, opts = {}) {
  35841. this.type = 'warning';
  35842. this.text = text;
  35843. if (opts.node && opts.node.source) {
  35844. let range = opts.node.rangeBy(opts);
  35845. this.line = range.start.line;
  35846. this.column = range.start.column;
  35847. this.endLine = range.end.line;
  35848. this.endColumn = range.end.column;
  35849. }
  35850. for (let opt in opts) this[opt] = opts[opt];
  35851. }
  35852. toString() {
  35853. if (this.node) {
  35854. return this.node.error(this.text, {
  35855. index: this.index,
  35856. plugin: this.plugin,
  35857. word: this.word
  35858. }).message
  35859. }
  35860. if (this.plugin) {
  35861. return this.plugin + ': ' + this.text
  35862. }
  35863. return this.text
  35864. }
  35865. }
  35866. warning = Warning;
  35867. Warning.default = Warning;
  35868. return warning;
  35869. }
  35870. var result;
  35871. var hasRequiredResult;
  35872. function requireResult () {
  35873. if (hasRequiredResult) return result;
  35874. hasRequiredResult = 1;
  35875. let Warning = /*@__PURE__*/ requireWarning();
  35876. class Result {
  35877. get content() {
  35878. return this.css
  35879. }
  35880. constructor(processor, root, opts) {
  35881. this.processor = processor;
  35882. this.messages = [];
  35883. this.root = root;
  35884. this.opts = opts;
  35885. this.css = '';
  35886. this.map = undefined;
  35887. }
  35888. toString() {
  35889. return this.css
  35890. }
  35891. warn(text, opts = {}) {
  35892. if (!opts.plugin) {
  35893. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  35894. opts.plugin = this.lastPlugin.postcssPlugin;
  35895. }
  35896. }
  35897. let warning = new Warning(text, opts);
  35898. this.messages.push(warning);
  35899. return warning
  35900. }
  35901. warnings() {
  35902. return this.messages.filter(i => i.type === 'warning')
  35903. }
  35904. }
  35905. result = Result;
  35906. Result.default = Result;
  35907. return result;
  35908. }
  35909. /* eslint-disable no-console */
  35910. var warnOnce;
  35911. var hasRequiredWarnOnce;
  35912. function requireWarnOnce () {
  35913. if (hasRequiredWarnOnce) return warnOnce;
  35914. hasRequiredWarnOnce = 1;
  35915. let printed = {};
  35916. warnOnce = function warnOnce(message) {
  35917. if (printed[message]) return
  35918. printed[message] = true;
  35919. if (typeof console !== 'undefined' && console.warn) {
  35920. console.warn(message);
  35921. }
  35922. };
  35923. return warnOnce;
  35924. }
  35925. var lazyResult;
  35926. var hasRequiredLazyResult;
  35927. function requireLazyResult () {
  35928. if (hasRequiredLazyResult) return lazyResult;
  35929. hasRequiredLazyResult = 1;
  35930. let Container = /*@__PURE__*/ requireContainer$1();
  35931. let Document = /*@__PURE__*/ requireDocument();
  35932. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  35933. let parse = /*@__PURE__*/ requireParse();
  35934. let Result = /*@__PURE__*/ requireResult();
  35935. let Root = /*@__PURE__*/ requireRoot$1();
  35936. let stringify = /*@__PURE__*/ requireStringify();
  35937. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  35938. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  35939. const TYPE_TO_CLASS_NAME = {
  35940. atrule: 'AtRule',
  35941. comment: 'Comment',
  35942. decl: 'Declaration',
  35943. document: 'Document',
  35944. root: 'Root',
  35945. rule: 'Rule'
  35946. };
  35947. const PLUGIN_PROPS = {
  35948. AtRule: true,
  35949. AtRuleExit: true,
  35950. Comment: true,
  35951. CommentExit: true,
  35952. Declaration: true,
  35953. DeclarationExit: true,
  35954. Document: true,
  35955. DocumentExit: true,
  35956. Once: true,
  35957. OnceExit: true,
  35958. postcssPlugin: true,
  35959. prepare: true,
  35960. Root: true,
  35961. RootExit: true,
  35962. Rule: true,
  35963. RuleExit: true
  35964. };
  35965. const NOT_VISITORS = {
  35966. Once: true,
  35967. postcssPlugin: true,
  35968. prepare: true
  35969. };
  35970. const CHILDREN = 0;
  35971. function isPromise(obj) {
  35972. return typeof obj === 'object' && typeof obj.then === 'function'
  35973. }
  35974. function getEvents(node) {
  35975. let key = false;
  35976. let type = TYPE_TO_CLASS_NAME[node.type];
  35977. if (node.type === 'decl') {
  35978. key = node.prop.toLowerCase();
  35979. } else if (node.type === 'atrule') {
  35980. key = node.name.toLowerCase();
  35981. }
  35982. if (key && node.append) {
  35983. return [
  35984. type,
  35985. type + '-' + key,
  35986. CHILDREN,
  35987. type + 'Exit',
  35988. type + 'Exit-' + key
  35989. ]
  35990. } else if (key) {
  35991. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35992. } else if (node.append) {
  35993. return [type, CHILDREN, type + 'Exit']
  35994. } else {
  35995. return [type, type + 'Exit']
  35996. }
  35997. }
  35998. function toStack(node) {
  35999. let events;
  36000. if (node.type === 'document') {
  36001. events = ['Document', CHILDREN, 'DocumentExit'];
  36002. } else if (node.type === 'root') {
  36003. events = ['Root', CHILDREN, 'RootExit'];
  36004. } else {
  36005. events = getEvents(node);
  36006. }
  36007. return {
  36008. eventIndex: 0,
  36009. events,
  36010. iterator: 0,
  36011. node,
  36012. visitorIndex: 0,
  36013. visitors: []
  36014. }
  36015. }
  36016. function cleanMarks(node) {
  36017. node[isClean] = false;
  36018. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  36019. return node
  36020. }
  36021. let postcss = {};
  36022. class LazyResult {
  36023. get content() {
  36024. return this.stringify().content
  36025. }
  36026. get css() {
  36027. return this.stringify().css
  36028. }
  36029. get map() {
  36030. return this.stringify().map
  36031. }
  36032. get messages() {
  36033. return this.sync().messages
  36034. }
  36035. get opts() {
  36036. return this.result.opts
  36037. }
  36038. get processor() {
  36039. return this.result.processor
  36040. }
  36041. get root() {
  36042. return this.sync().root
  36043. }
  36044. get [Symbol.toStringTag]() {
  36045. return 'LazyResult'
  36046. }
  36047. constructor(processor, css, opts) {
  36048. this.stringified = false;
  36049. this.processed = false;
  36050. let root;
  36051. if (
  36052. typeof css === 'object' &&
  36053. css !== null &&
  36054. (css.type === 'root' || css.type === 'document')
  36055. ) {
  36056. root = cleanMarks(css);
  36057. } else if (css instanceof LazyResult || css instanceof Result) {
  36058. root = cleanMarks(css.root);
  36059. if (css.map) {
  36060. if (typeof opts.map === 'undefined') opts.map = {};
  36061. if (!opts.map.inline) opts.map.inline = false;
  36062. opts.map.prev = css.map;
  36063. }
  36064. } else {
  36065. let parser = parse;
  36066. if (opts.syntax) parser = opts.syntax.parse;
  36067. if (opts.parser) parser = opts.parser;
  36068. if (parser.parse) parser = parser.parse;
  36069. try {
  36070. root = parser(css, opts);
  36071. } catch (error) {
  36072. this.processed = true;
  36073. this.error = error;
  36074. }
  36075. if (root && !root[my]) {
  36076. /* c8 ignore next 2 */
  36077. Container.rebuild(root);
  36078. }
  36079. }
  36080. this.result = new Result(processor, root, opts);
  36081. this.helpers = { ...postcss, postcss, result: this.result };
  36082. this.plugins = this.processor.plugins.map(plugin => {
  36083. if (typeof plugin === 'object' && plugin.prepare) {
  36084. return { ...plugin, ...plugin.prepare(this.result) }
  36085. } else {
  36086. return plugin
  36087. }
  36088. });
  36089. }
  36090. async() {
  36091. if (this.error) return Promise.reject(this.error)
  36092. if (this.processed) return Promise.resolve(this.result)
  36093. if (!this.processing) {
  36094. this.processing = this.runAsync();
  36095. }
  36096. return this.processing
  36097. }
  36098. catch(onRejected) {
  36099. return this.async().catch(onRejected)
  36100. }
  36101. finally(onFinally) {
  36102. return this.async().then(onFinally, onFinally)
  36103. }
  36104. getAsyncError() {
  36105. throw new Error('Use process(css).then(cb) to work with async plugins')
  36106. }
  36107. handleError(error, node) {
  36108. let plugin = this.result.lastPlugin;
  36109. try {
  36110. if (node) node.addToError(error);
  36111. this.error = error;
  36112. if (error.name === 'CssSyntaxError' && !error.plugin) {
  36113. error.plugin = plugin.postcssPlugin;
  36114. error.setMessage();
  36115. } else if (plugin.postcssVersion) {
  36116. if (browser$1.env.NODE_ENV !== 'production') {
  36117. let pluginName = plugin.postcssPlugin;
  36118. let pluginVer = plugin.postcssVersion;
  36119. let runtimeVer = this.result.processor.version;
  36120. let a = pluginVer.split('.');
  36121. let b = runtimeVer.split('.');
  36122. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  36123. // eslint-disable-next-line no-console
  36124. console.error(
  36125. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  36126. 'version is ' +
  36127. runtimeVer +
  36128. ', but ' +
  36129. pluginName +
  36130. ' uses ' +
  36131. pluginVer +
  36132. '. Perhaps this is the source of the error below.'
  36133. );
  36134. }
  36135. }
  36136. }
  36137. } catch (err) {
  36138. /* c8 ignore next 3 */
  36139. // eslint-disable-next-line no-console
  36140. if (console && console.error) console.error(err);
  36141. }
  36142. return error
  36143. }
  36144. prepareVisitors() {
  36145. this.listeners = {};
  36146. let add = (plugin, type, cb) => {
  36147. if (!this.listeners[type]) this.listeners[type] = [];
  36148. this.listeners[type].push([plugin, cb]);
  36149. };
  36150. for (let plugin of this.plugins) {
  36151. if (typeof plugin === 'object') {
  36152. for (let event in plugin) {
  36153. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  36154. throw new Error(
  36155. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  36156. `Try to update PostCSS (${this.processor.version} now).`
  36157. )
  36158. }
  36159. if (!NOT_VISITORS[event]) {
  36160. if (typeof plugin[event] === 'object') {
  36161. for (let filter in plugin[event]) {
  36162. if (filter === '*') {
  36163. add(plugin, event, plugin[event][filter]);
  36164. } else {
  36165. add(
  36166. plugin,
  36167. event + '-' + filter.toLowerCase(),
  36168. plugin[event][filter]
  36169. );
  36170. }
  36171. }
  36172. } else if (typeof plugin[event] === 'function') {
  36173. add(plugin, event, plugin[event]);
  36174. }
  36175. }
  36176. }
  36177. }
  36178. }
  36179. this.hasListener = Object.keys(this.listeners).length > 0;
  36180. }
  36181. async runAsync() {
  36182. this.plugin = 0;
  36183. for (let i = 0; i < this.plugins.length; i++) {
  36184. let plugin = this.plugins[i];
  36185. let promise = this.runOnRoot(plugin);
  36186. if (isPromise(promise)) {
  36187. try {
  36188. await promise;
  36189. } catch (error) {
  36190. throw this.handleError(error)
  36191. }
  36192. }
  36193. }
  36194. this.prepareVisitors();
  36195. if (this.hasListener) {
  36196. let root = this.result.root;
  36197. while (!root[isClean]) {
  36198. root[isClean] = true;
  36199. let stack = [toStack(root)];
  36200. while (stack.length > 0) {
  36201. let promise = this.visitTick(stack);
  36202. if (isPromise(promise)) {
  36203. try {
  36204. await promise;
  36205. } catch (e) {
  36206. let node = stack[stack.length - 1].node;
  36207. throw this.handleError(e, node)
  36208. }
  36209. }
  36210. }
  36211. }
  36212. if (this.listeners.OnceExit) {
  36213. for (let [plugin, visitor] of this.listeners.OnceExit) {
  36214. this.result.lastPlugin = plugin;
  36215. try {
  36216. if (root.type === 'document') {
  36217. let roots = root.nodes.map(subRoot =>
  36218. visitor(subRoot, this.helpers)
  36219. );
  36220. await Promise.all(roots);
  36221. } else {
  36222. await visitor(root, this.helpers);
  36223. }
  36224. } catch (e) {
  36225. throw this.handleError(e)
  36226. }
  36227. }
  36228. }
  36229. }
  36230. this.processed = true;
  36231. return this.stringify()
  36232. }
  36233. runOnRoot(plugin) {
  36234. this.result.lastPlugin = plugin;
  36235. try {
  36236. if (typeof plugin === 'object' && plugin.Once) {
  36237. if (this.result.root.type === 'document') {
  36238. let roots = this.result.root.nodes.map(root =>
  36239. plugin.Once(root, this.helpers)
  36240. );
  36241. if (isPromise(roots[0])) {
  36242. return Promise.all(roots)
  36243. }
  36244. return roots
  36245. }
  36246. return plugin.Once(this.result.root, this.helpers)
  36247. } else if (typeof plugin === 'function') {
  36248. return plugin(this.result.root, this.result)
  36249. }
  36250. } catch (error) {
  36251. throw this.handleError(error)
  36252. }
  36253. }
  36254. stringify() {
  36255. if (this.error) throw this.error
  36256. if (this.stringified) return this.result
  36257. this.stringified = true;
  36258. this.sync();
  36259. let opts = this.result.opts;
  36260. let str = stringify;
  36261. if (opts.syntax) str = opts.syntax.stringify;
  36262. if (opts.stringifier) str = opts.stringifier;
  36263. if (str.stringify) str = str.stringify;
  36264. let map = new MapGenerator(str, this.result.root, this.result.opts);
  36265. let data = map.generate();
  36266. this.result.css = data[0];
  36267. this.result.map = data[1];
  36268. return this.result
  36269. }
  36270. sync() {
  36271. if (this.error) throw this.error
  36272. if (this.processed) return this.result
  36273. this.processed = true;
  36274. if (this.processing) {
  36275. throw this.getAsyncError()
  36276. }
  36277. for (let plugin of this.plugins) {
  36278. let promise = this.runOnRoot(plugin);
  36279. if (isPromise(promise)) {
  36280. throw this.getAsyncError()
  36281. }
  36282. }
  36283. this.prepareVisitors();
  36284. if (this.hasListener) {
  36285. let root = this.result.root;
  36286. while (!root[isClean]) {
  36287. root[isClean] = true;
  36288. this.walkSync(root);
  36289. }
  36290. if (this.listeners.OnceExit) {
  36291. if (root.type === 'document') {
  36292. for (let subRoot of root.nodes) {
  36293. this.visitSync(this.listeners.OnceExit, subRoot);
  36294. }
  36295. } else {
  36296. this.visitSync(this.listeners.OnceExit, root);
  36297. }
  36298. }
  36299. }
  36300. return this.result
  36301. }
  36302. then(onFulfilled, onRejected) {
  36303. if (browser$1.env.NODE_ENV !== 'production') {
  36304. if (!('from' in this.opts)) {
  36305. warnOnce(
  36306. 'Without `from` option PostCSS could generate wrong source map ' +
  36307. 'and will not find Browserslist config. Set it to CSS file path ' +
  36308. 'or to `undefined` to prevent this warning.'
  36309. );
  36310. }
  36311. }
  36312. return this.async().then(onFulfilled, onRejected)
  36313. }
  36314. toString() {
  36315. return this.css
  36316. }
  36317. visitSync(visitors, node) {
  36318. for (let [plugin, visitor] of visitors) {
  36319. this.result.lastPlugin = plugin;
  36320. let promise;
  36321. try {
  36322. promise = visitor(node, this.helpers);
  36323. } catch (e) {
  36324. throw this.handleError(e, node.proxyOf)
  36325. }
  36326. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36327. return true
  36328. }
  36329. if (isPromise(promise)) {
  36330. throw this.getAsyncError()
  36331. }
  36332. }
  36333. }
  36334. visitTick(stack) {
  36335. let visit = stack[stack.length - 1];
  36336. let { node, visitors } = visit;
  36337. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36338. stack.pop();
  36339. return
  36340. }
  36341. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  36342. let [plugin, visitor] = visitors[visit.visitorIndex];
  36343. visit.visitorIndex += 1;
  36344. if (visit.visitorIndex === visitors.length) {
  36345. visit.visitors = [];
  36346. visit.visitorIndex = 0;
  36347. }
  36348. this.result.lastPlugin = plugin;
  36349. try {
  36350. return visitor(node.toProxy(), this.helpers)
  36351. } catch (e) {
  36352. throw this.handleError(e, node)
  36353. }
  36354. }
  36355. if (visit.iterator !== 0) {
  36356. let iterator = visit.iterator;
  36357. let child;
  36358. while ((child = node.nodes[node.indexes[iterator]])) {
  36359. node.indexes[iterator] += 1;
  36360. if (!child[isClean]) {
  36361. child[isClean] = true;
  36362. stack.push(toStack(child));
  36363. return
  36364. }
  36365. }
  36366. visit.iterator = 0;
  36367. delete node.indexes[iterator];
  36368. }
  36369. let events = visit.events;
  36370. while (visit.eventIndex < events.length) {
  36371. let event = events[visit.eventIndex];
  36372. visit.eventIndex += 1;
  36373. if (event === CHILDREN) {
  36374. if (node.nodes && node.nodes.length) {
  36375. node[isClean] = true;
  36376. visit.iterator = node.getIterator();
  36377. }
  36378. return
  36379. } else if (this.listeners[event]) {
  36380. visit.visitors = this.listeners[event];
  36381. return
  36382. }
  36383. }
  36384. stack.pop();
  36385. }
  36386. walkSync(node) {
  36387. node[isClean] = true;
  36388. let events = getEvents(node);
  36389. for (let event of events) {
  36390. if (event === CHILDREN) {
  36391. if (node.nodes) {
  36392. node.each(child => {
  36393. if (!child[isClean]) this.walkSync(child);
  36394. });
  36395. }
  36396. } else {
  36397. let visitors = this.listeners[event];
  36398. if (visitors) {
  36399. if (this.visitSync(visitors, node.toProxy())) return
  36400. }
  36401. }
  36402. }
  36403. }
  36404. warnings() {
  36405. return this.sync().warnings()
  36406. }
  36407. }
  36408. LazyResult.registerPostcss = dependant => {
  36409. postcss = dependant;
  36410. };
  36411. lazyResult = LazyResult;
  36412. LazyResult.default = LazyResult;
  36413. Root.registerLazyResult(LazyResult);
  36414. Document.registerLazyResult(LazyResult);
  36415. return lazyResult;
  36416. }
  36417. var noWorkResult;
  36418. var hasRequiredNoWorkResult;
  36419. function requireNoWorkResult () {
  36420. if (hasRequiredNoWorkResult) return noWorkResult;
  36421. hasRequiredNoWorkResult = 1;
  36422. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  36423. let parse = /*@__PURE__*/ requireParse();
  36424. let Result = /*@__PURE__*/ requireResult();
  36425. let stringify = /*@__PURE__*/ requireStringify();
  36426. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  36427. class NoWorkResult {
  36428. get content() {
  36429. return this.result.css
  36430. }
  36431. get css() {
  36432. return this.result.css
  36433. }
  36434. get map() {
  36435. return this.result.map
  36436. }
  36437. get messages() {
  36438. return []
  36439. }
  36440. get opts() {
  36441. return this.result.opts
  36442. }
  36443. get processor() {
  36444. return this.result.processor
  36445. }
  36446. get root() {
  36447. if (this._root) {
  36448. return this._root
  36449. }
  36450. let root;
  36451. let parser = parse;
  36452. try {
  36453. root = parser(this._css, this._opts);
  36454. } catch (error) {
  36455. this.error = error;
  36456. }
  36457. if (this.error) {
  36458. throw this.error
  36459. } else {
  36460. this._root = root;
  36461. return root
  36462. }
  36463. }
  36464. get [Symbol.toStringTag]() {
  36465. return 'NoWorkResult'
  36466. }
  36467. constructor(processor, css, opts) {
  36468. css = css.toString();
  36469. this.stringified = false;
  36470. this._processor = processor;
  36471. this._css = css;
  36472. this._opts = opts;
  36473. this._map = undefined;
  36474. let str = stringify;
  36475. this.result = new Result(this._processor, undefined, this._opts);
  36476. this.result.css = css;
  36477. let self = this;
  36478. Object.defineProperty(this.result, 'root', {
  36479. get() {
  36480. return self.root
  36481. }
  36482. });
  36483. let map = new MapGenerator(str, undefined, this._opts, css);
  36484. if (map.isMap()) {
  36485. let [generatedCSS, generatedMap] = map.generate();
  36486. if (generatedCSS) {
  36487. this.result.css = generatedCSS;
  36488. }
  36489. if (generatedMap) {
  36490. this.result.map = generatedMap;
  36491. }
  36492. } else {
  36493. map.clearAnnotation();
  36494. this.result.css = map.css;
  36495. }
  36496. }
  36497. async() {
  36498. if (this.error) return Promise.reject(this.error)
  36499. return Promise.resolve(this.result)
  36500. }
  36501. catch(onRejected) {
  36502. return this.async().catch(onRejected)
  36503. }
  36504. finally(onFinally) {
  36505. return this.async().then(onFinally, onFinally)
  36506. }
  36507. sync() {
  36508. if (this.error) throw this.error
  36509. return this.result
  36510. }
  36511. then(onFulfilled, onRejected) {
  36512. if (browser$1.env.NODE_ENV !== 'production') {
  36513. if (!('from' in this._opts)) {
  36514. warnOnce(
  36515. 'Without `from` option PostCSS could generate wrong source map ' +
  36516. 'and will not find Browserslist config. Set it to CSS file path ' +
  36517. 'or to `undefined` to prevent this warning.'
  36518. );
  36519. }
  36520. }
  36521. return this.async().then(onFulfilled, onRejected)
  36522. }
  36523. toString() {
  36524. return this._css
  36525. }
  36526. warnings() {
  36527. return []
  36528. }
  36529. }
  36530. noWorkResult = NoWorkResult;
  36531. NoWorkResult.default = NoWorkResult;
  36532. return noWorkResult;
  36533. }
  36534. var processor$1;
  36535. var hasRequiredProcessor$1;
  36536. function requireProcessor$1 () {
  36537. if (hasRequiredProcessor$1) return processor$1;
  36538. hasRequiredProcessor$1 = 1;
  36539. let Document = /*@__PURE__*/ requireDocument();
  36540. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36541. let NoWorkResult = /*@__PURE__*/ requireNoWorkResult();
  36542. let Root = /*@__PURE__*/ requireRoot$1();
  36543. class Processor {
  36544. constructor(plugins = []) {
  36545. this.version = '8.5.10';
  36546. this.plugins = this.normalize(plugins);
  36547. }
  36548. normalize(plugins) {
  36549. let normalized = [];
  36550. for (let i of plugins) {
  36551. if (i.postcss === true) {
  36552. i = i();
  36553. } else if (i.postcss) {
  36554. i = i.postcss;
  36555. }
  36556. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  36557. normalized = normalized.concat(i.plugins);
  36558. } else if (typeof i === 'object' && i.postcssPlugin) {
  36559. normalized.push(i);
  36560. } else if (typeof i === 'function') {
  36561. normalized.push(i);
  36562. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36563. if (browser$1.env.NODE_ENV !== 'production') {
  36564. throw new Error(
  36565. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36566. 'one of the syntax/parser/stringifier options as outlined ' +
  36567. 'in your PostCSS runner documentation.'
  36568. )
  36569. }
  36570. } else {
  36571. throw new Error(i + ' is not a PostCSS plugin')
  36572. }
  36573. }
  36574. return normalized
  36575. }
  36576. process(css, opts = {}) {
  36577. if (
  36578. !this.plugins.length &&
  36579. !opts.parser &&
  36580. !opts.stringifier &&
  36581. !opts.syntax
  36582. ) {
  36583. return new NoWorkResult(this, css, opts)
  36584. } else {
  36585. return new LazyResult(this, css, opts)
  36586. }
  36587. }
  36588. use(plugin) {
  36589. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36590. return this
  36591. }
  36592. }
  36593. processor$1 = Processor;
  36594. Processor.default = Processor;
  36595. Root.registerProcessor(Processor);
  36596. Document.registerProcessor(Processor);
  36597. return processor$1;
  36598. }
  36599. var postcss_1;
  36600. var hasRequiredPostcss;
  36601. function requirePostcss () {
  36602. if (hasRequiredPostcss) return postcss_1;
  36603. hasRequiredPostcss = 1;
  36604. let AtRule = /*@__PURE__*/ requireAtRule();
  36605. let Comment = /*@__PURE__*/ requireComment$1();
  36606. let Container = /*@__PURE__*/ requireContainer$1();
  36607. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  36608. let Declaration = /*@__PURE__*/ requireDeclaration();
  36609. let Document = /*@__PURE__*/ requireDocument();
  36610. let fromJSON = /*@__PURE__*/ requireFromJSON();
  36611. let Input = /*@__PURE__*/ requireInput();
  36612. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36613. let list = /*@__PURE__*/ requireList();
  36614. let Node = /*@__PURE__*/ requireNode$2();
  36615. let parse = /*@__PURE__*/ requireParse();
  36616. let Processor = /*@__PURE__*/ requireProcessor$1();
  36617. let Result = /*@__PURE__*/ requireResult();
  36618. let Root = /*@__PURE__*/ requireRoot$1();
  36619. let Rule = /*@__PURE__*/ requireRule();
  36620. let stringify = /*@__PURE__*/ requireStringify();
  36621. let Warning = /*@__PURE__*/ requireWarning();
  36622. function postcss(...plugins) {
  36623. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36624. plugins = plugins[0];
  36625. }
  36626. return new Processor(plugins)
  36627. }
  36628. postcss.plugin = function plugin(name, initializer) {
  36629. let warningPrinted = false;
  36630. function creator(...args) {
  36631. // eslint-disable-next-line no-console
  36632. if (console && console.warn && !warningPrinted) {
  36633. warningPrinted = true;
  36634. // eslint-disable-next-line no-console
  36635. console.warn(
  36636. name +
  36637. ': postcss.plugin was deprecated. Migration guide:\n' +
  36638. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36639. );
  36640. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36641. /* c8 ignore next 7 */
  36642. // eslint-disable-next-line no-console
  36643. console.warn(
  36644. name +
  36645. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36646. 'https://www.w3ctech.com/topic/2226'
  36647. );
  36648. }
  36649. }
  36650. let transformer = initializer(...args);
  36651. transformer.postcssPlugin = name;
  36652. transformer.postcssVersion = new Processor().version;
  36653. return transformer
  36654. }
  36655. let cache;
  36656. Object.defineProperty(creator, 'postcss', {
  36657. get() {
  36658. if (!cache) cache = creator();
  36659. return cache
  36660. }
  36661. });
  36662. creator.process = function (css, processOpts, pluginOpts) {
  36663. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36664. };
  36665. return creator
  36666. };
  36667. postcss.stringify = stringify;
  36668. postcss.parse = parse;
  36669. postcss.fromJSON = fromJSON;
  36670. postcss.list = list;
  36671. postcss.comment = defaults => new Comment(defaults);
  36672. postcss.atRule = defaults => new AtRule(defaults);
  36673. postcss.decl = defaults => new Declaration(defaults);
  36674. postcss.rule = defaults => new Rule(defaults);
  36675. postcss.root = defaults => new Root(defaults);
  36676. postcss.document = defaults => new Document(defaults);
  36677. postcss.CssSyntaxError = CssSyntaxError;
  36678. postcss.Declaration = Declaration;
  36679. postcss.Container = Container;
  36680. postcss.Processor = Processor;
  36681. postcss.Document = Document;
  36682. postcss.Comment = Comment;
  36683. postcss.Warning = Warning;
  36684. postcss.AtRule = AtRule;
  36685. postcss.Result = Result;
  36686. postcss.Input = Input;
  36687. postcss.Rule = Rule;
  36688. postcss.Root = Root;
  36689. postcss.Node = Node;
  36690. LazyResult.registerPostcss(postcss);
  36691. postcss_1 = postcss;
  36692. postcss.default = postcss;
  36693. return postcss_1;
  36694. }
  36695. var postcssExports = /*@__PURE__*/ requirePostcss();
  36696. var postcss = /*@__PURE__*/getDefaultExportFromCjs(postcssExports);
  36697. postcss.stringify;
  36698. postcss.fromJSON;
  36699. postcss.plugin;
  36700. postcss.parse;
  36701. postcss.list;
  36702. postcss.document;
  36703. postcss.comment;
  36704. postcss.atRule;
  36705. postcss.rule;
  36706. postcss.decl;
  36707. postcss.root;
  36708. postcss.CssSyntaxError;
  36709. postcss.Declaration;
  36710. postcss.Container;
  36711. postcss.Processor;
  36712. postcss.Document;
  36713. postcss.Comment;
  36714. postcss.Warning;
  36715. postcss.AtRule;
  36716. postcss.Result;
  36717. postcss.Input;
  36718. const Rule = postcss.Rule;
  36719. postcss.Root;
  36720. postcss.Node;
  36721. const trimPlugin = () => {
  36722. return {
  36723. postcssPlugin: "vue-sfc-trim",
  36724. Once(root) {
  36725. root.walk(({ type, raws }) => {
  36726. if (type === "rule" || type === "atrule") {
  36727. if (raws.before) raws.before = "\n";
  36728. if ("after" in raws && raws.after) raws.after = "\n";
  36729. }
  36730. });
  36731. }
  36732. };
  36733. };
  36734. trimPlugin.postcss = true;
  36735. var dist = {exports: {}};
  36736. var processor = {exports: {}};
  36737. var parser = {exports: {}};
  36738. var root = {exports: {}};
  36739. var container = {exports: {}};
  36740. var node$1 = {exports: {}};
  36741. var util$1 = {};
  36742. var unesc = {exports: {}};
  36743. var hasRequiredUnesc;
  36744. function requireUnesc () {
  36745. if (hasRequiredUnesc) return unesc.exports;
  36746. hasRequiredUnesc = 1;
  36747. (function (module, exports$1) {
  36748. exports$1.__esModule = true;
  36749. exports$1["default"] = unesc;
  36750. // Many thanks for this post which made this migration much easier.
  36751. // https://mathiasbynens.be/notes/css-escapes
  36752. /**
  36753. *
  36754. * @param {string} str
  36755. * @returns {[string, number]|undefined}
  36756. */
  36757. function gobbleHex(str) {
  36758. var lower = str.toLowerCase();
  36759. var hex = '';
  36760. var spaceTerminated = false;
  36761. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36762. var code = lower.charCodeAt(i);
  36763. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36764. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36765. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36766. spaceTerminated = code === 32;
  36767. if (!valid) {
  36768. break;
  36769. }
  36770. hex += lower[i];
  36771. }
  36772. if (hex.length === 0) {
  36773. return undefined;
  36774. }
  36775. var codePoint = parseInt(hex, 16);
  36776. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36777. // Add special case for
  36778. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36779. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36780. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36781. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36782. }
  36783. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36784. }
  36785. var CONTAINS_ESCAPE = /\\/;
  36786. function unesc(str) {
  36787. var needToProcess = CONTAINS_ESCAPE.test(str);
  36788. if (!needToProcess) {
  36789. return str;
  36790. }
  36791. var ret = "";
  36792. for (var i = 0; i < str.length; i++) {
  36793. if (str[i] === "\\") {
  36794. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36795. if (gobbled !== undefined) {
  36796. ret += gobbled[0];
  36797. i += gobbled[1];
  36798. continue;
  36799. }
  36800. // Retain a pair of \\ if double escaped `\\\\`
  36801. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36802. if (str[i + 1] === "\\") {
  36803. ret += "\\";
  36804. i++;
  36805. continue;
  36806. }
  36807. // if \\ is at the end of the string retain it
  36808. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36809. if (str.length === i + 1) {
  36810. ret += str[i];
  36811. }
  36812. continue;
  36813. }
  36814. ret += str[i];
  36815. }
  36816. return ret;
  36817. }
  36818. module.exports = exports$1.default;
  36819. } (unesc, unesc.exports));
  36820. return unesc.exports;
  36821. }
  36822. var getProp = {exports: {}};
  36823. var hasRequiredGetProp;
  36824. function requireGetProp () {
  36825. if (hasRequiredGetProp) return getProp.exports;
  36826. hasRequiredGetProp = 1;
  36827. (function (module, exports$1) {
  36828. exports$1.__esModule = true;
  36829. exports$1["default"] = getProp;
  36830. function getProp(obj) {
  36831. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36832. props[_key - 1] = arguments[_key];
  36833. }
  36834. while (props.length > 0) {
  36835. var prop = props.shift();
  36836. if (!obj[prop]) {
  36837. return undefined;
  36838. }
  36839. obj = obj[prop];
  36840. }
  36841. return obj;
  36842. }
  36843. module.exports = exports$1.default;
  36844. } (getProp, getProp.exports));
  36845. return getProp.exports;
  36846. }
  36847. var ensureObject = {exports: {}};
  36848. var hasRequiredEnsureObject;
  36849. function requireEnsureObject () {
  36850. if (hasRequiredEnsureObject) return ensureObject.exports;
  36851. hasRequiredEnsureObject = 1;
  36852. (function (module, exports$1) {
  36853. exports$1.__esModule = true;
  36854. exports$1["default"] = ensureObject;
  36855. function ensureObject(obj) {
  36856. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36857. props[_key - 1] = arguments[_key];
  36858. }
  36859. while (props.length > 0) {
  36860. var prop = props.shift();
  36861. if (!obj[prop]) {
  36862. obj[prop] = {};
  36863. }
  36864. obj = obj[prop];
  36865. }
  36866. }
  36867. module.exports = exports$1.default;
  36868. } (ensureObject, ensureObject.exports));
  36869. return ensureObject.exports;
  36870. }
  36871. var stripComments = {exports: {}};
  36872. var hasRequiredStripComments;
  36873. function requireStripComments () {
  36874. if (hasRequiredStripComments) return stripComments.exports;
  36875. hasRequiredStripComments = 1;
  36876. (function (module, exports$1) {
  36877. exports$1.__esModule = true;
  36878. exports$1["default"] = stripComments;
  36879. function stripComments(str) {
  36880. var s = "";
  36881. var commentStart = str.indexOf("/*");
  36882. var lastEnd = 0;
  36883. while (commentStart >= 0) {
  36884. s = s + str.slice(lastEnd, commentStart);
  36885. var commentEnd = str.indexOf("*/", commentStart + 2);
  36886. if (commentEnd < 0) {
  36887. return s;
  36888. }
  36889. lastEnd = commentEnd + 2;
  36890. commentStart = str.indexOf("/*", lastEnd);
  36891. }
  36892. s = s + str.slice(lastEnd);
  36893. return s;
  36894. }
  36895. module.exports = exports$1.default;
  36896. } (stripComments, stripComments.exports));
  36897. return stripComments.exports;
  36898. }
  36899. var hasRequiredUtil$1;
  36900. function requireUtil$1 () {
  36901. if (hasRequiredUtil$1) return util$1;
  36902. hasRequiredUtil$1 = 1;
  36903. util$1.__esModule = true;
  36904. util$1.unesc = util$1.stripComments = util$1.getProp = util$1.ensureObject = void 0;
  36905. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  36906. util$1.unesc = _unesc["default"];
  36907. var _getProp = _interopRequireDefault(/*@__PURE__*/ requireGetProp());
  36908. util$1.getProp = _getProp["default"];
  36909. var _ensureObject = _interopRequireDefault(/*@__PURE__*/ requireEnsureObject());
  36910. util$1.ensureObject = _ensureObject["default"];
  36911. var _stripComments = _interopRequireDefault(/*@__PURE__*/ requireStripComments());
  36912. util$1.stripComments = _stripComments["default"];
  36913. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36914. return util$1;
  36915. }
  36916. var hasRequiredNode$1;
  36917. function requireNode$1 () {
  36918. if (hasRequiredNode$1) return node$1.exports;
  36919. hasRequiredNode$1 = 1;
  36920. (function (module, exports$1) {
  36921. exports$1.__esModule = true;
  36922. exports$1["default"] = void 0;
  36923. var _util = /*@__PURE__*/ requireUtil$1();
  36924. 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); } }
  36925. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36926. var cloneNode = function cloneNode(obj, parent) {
  36927. if (typeof obj !== 'object' || obj === null) {
  36928. return obj;
  36929. }
  36930. var cloned = new obj.constructor();
  36931. for (var i in obj) {
  36932. if (!obj.hasOwnProperty(i)) {
  36933. continue;
  36934. }
  36935. var value = obj[i];
  36936. var type = typeof value;
  36937. if (i === 'parent' && type === 'object') {
  36938. if (parent) {
  36939. cloned[i] = parent;
  36940. }
  36941. } else if (value instanceof Array) {
  36942. cloned[i] = value.map(function (j) {
  36943. return cloneNode(j, cloned);
  36944. });
  36945. } else {
  36946. cloned[i] = cloneNode(value, cloned);
  36947. }
  36948. }
  36949. return cloned;
  36950. };
  36951. var Node = /*#__PURE__*/function () {
  36952. function Node(opts) {
  36953. if (opts === void 0) {
  36954. opts = {};
  36955. }
  36956. Object.assign(this, opts);
  36957. this.spaces = this.spaces || {};
  36958. this.spaces.before = this.spaces.before || '';
  36959. this.spaces.after = this.spaces.after || '';
  36960. }
  36961. var _proto = Node.prototype;
  36962. _proto.remove = function remove() {
  36963. if (this.parent) {
  36964. this.parent.removeChild(this);
  36965. }
  36966. this.parent = undefined;
  36967. return this;
  36968. };
  36969. _proto.replaceWith = function replaceWith() {
  36970. if (this.parent) {
  36971. for (var index in arguments) {
  36972. this.parent.insertBefore(this, arguments[index]);
  36973. }
  36974. this.remove();
  36975. }
  36976. return this;
  36977. };
  36978. _proto.next = function next() {
  36979. return this.parent.at(this.parent.index(this) + 1);
  36980. };
  36981. _proto.prev = function prev() {
  36982. return this.parent.at(this.parent.index(this) - 1);
  36983. };
  36984. _proto.clone = function clone(overrides) {
  36985. if (overrides === void 0) {
  36986. overrides = {};
  36987. }
  36988. var cloned = cloneNode(this);
  36989. for (var name in overrides) {
  36990. cloned[name] = overrides[name];
  36991. }
  36992. return cloned;
  36993. }
  36994. /**
  36995. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36996. * This allows non standard syntax to be appended to an existing property
  36997. * by specifying the escaped value. By specifying the escaped value,
  36998. * illegal characters are allowed to be directly inserted into css output.
  36999. * @param {string} name the property to set
  37000. * @param {any} value the unescaped value of the property
  37001. * @param {string} valueEscaped optional. the escaped value of the property.
  37002. */;
  37003. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  37004. if (!this.raws) {
  37005. this.raws = {};
  37006. }
  37007. var originalValue = this[name];
  37008. var originalEscaped = this.raws[name];
  37009. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  37010. if (originalEscaped || valueEscaped !== value) {
  37011. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  37012. } else {
  37013. delete this.raws[name]; // delete any escaped value that was created by the setter.
  37014. }
  37015. }
  37016. /**
  37017. * Some non-standard syntax doesn't follow normal escaping rules for css.
  37018. * This allows the escaped value to be specified directly, allowing illegal
  37019. * characters to be directly inserted into css output.
  37020. * @param {string} name the property to set
  37021. * @param {any} value the unescaped value of the property
  37022. * @param {string} valueEscaped the escaped value of the property.
  37023. */;
  37024. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  37025. if (!this.raws) {
  37026. this.raws = {};
  37027. }
  37028. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37029. this.raws[name] = valueEscaped;
  37030. }
  37031. /**
  37032. * When you want a value to passed through to CSS directly. This method
  37033. * deletes the corresponding raw value causing the stringifier to fallback
  37034. * to the unescaped value.
  37035. * @param {string} name the property to set.
  37036. * @param {any} value The value that is both escaped and unescaped.
  37037. */;
  37038. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  37039. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  37040. if (this.raws) {
  37041. delete this.raws[name];
  37042. }
  37043. }
  37044. /**
  37045. *
  37046. * @param {number} line The number (starting with 1)
  37047. * @param {number} column The column number (starting with 1)
  37048. */;
  37049. _proto.isAtPosition = function isAtPosition(line, column) {
  37050. if (this.source && this.source.start && this.source.end) {
  37051. if (this.source.start.line > line) {
  37052. return false;
  37053. }
  37054. if (this.source.end.line < line) {
  37055. return false;
  37056. }
  37057. if (this.source.start.line === line && this.source.start.column > column) {
  37058. return false;
  37059. }
  37060. if (this.source.end.line === line && this.source.end.column < column) {
  37061. return false;
  37062. }
  37063. return true;
  37064. }
  37065. return undefined;
  37066. };
  37067. _proto.stringifyProperty = function stringifyProperty(name) {
  37068. return this.raws && this.raws[name] || this[name];
  37069. };
  37070. _proto.valueToString = function valueToString() {
  37071. return String(this.stringifyProperty("value"));
  37072. };
  37073. _proto.toString = function toString() {
  37074. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  37075. };
  37076. _createClass(Node, [{
  37077. key: "rawSpaceBefore",
  37078. get: function get() {
  37079. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  37080. if (rawSpace === undefined) {
  37081. rawSpace = this.spaces && this.spaces.before;
  37082. }
  37083. return rawSpace || "";
  37084. },
  37085. set: function set(raw) {
  37086. (0, _util.ensureObject)(this, "raws", "spaces");
  37087. this.raws.spaces.before = raw;
  37088. }
  37089. }, {
  37090. key: "rawSpaceAfter",
  37091. get: function get() {
  37092. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  37093. if (rawSpace === undefined) {
  37094. rawSpace = this.spaces.after;
  37095. }
  37096. return rawSpace || "";
  37097. },
  37098. set: function set(raw) {
  37099. (0, _util.ensureObject)(this, "raws", "spaces");
  37100. this.raws.spaces.after = raw;
  37101. }
  37102. }]);
  37103. return Node;
  37104. }();
  37105. exports$1["default"] = Node;
  37106. module.exports = exports$1.default;
  37107. } (node$1, node$1.exports));
  37108. return node$1.exports;
  37109. }
  37110. var types = {};
  37111. var hasRequiredTypes;
  37112. function requireTypes () {
  37113. if (hasRequiredTypes) return types;
  37114. hasRequiredTypes = 1;
  37115. types.__esModule = true;
  37116. 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;
  37117. var TAG = 'tag';
  37118. types.TAG = TAG;
  37119. var STRING = 'string';
  37120. types.STRING = STRING;
  37121. var SELECTOR = 'selector';
  37122. types.SELECTOR = SELECTOR;
  37123. var ROOT = 'root';
  37124. types.ROOT = ROOT;
  37125. var PSEUDO = 'pseudo';
  37126. types.PSEUDO = PSEUDO;
  37127. var NESTING = 'nesting';
  37128. types.NESTING = NESTING;
  37129. var ID = 'id';
  37130. types.ID = ID;
  37131. var COMMENT = 'comment';
  37132. types.COMMENT = COMMENT;
  37133. var COMBINATOR = 'combinator';
  37134. types.COMBINATOR = COMBINATOR;
  37135. var CLASS = 'class';
  37136. types.CLASS = CLASS;
  37137. var ATTRIBUTE = 'attribute';
  37138. types.ATTRIBUTE = ATTRIBUTE;
  37139. var UNIVERSAL = 'universal';
  37140. types.UNIVERSAL = UNIVERSAL;
  37141. return types;
  37142. }
  37143. var hasRequiredContainer;
  37144. function requireContainer () {
  37145. if (hasRequiredContainer) return container.exports;
  37146. hasRequiredContainer = 1;
  37147. (function (module, exports$1) {
  37148. exports$1.__esModule = true;
  37149. exports$1["default"] = void 0;
  37150. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37151. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  37152. 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); }
  37153. 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; }
  37154. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37155. 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."); }
  37156. 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); }
  37157. 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; }
  37158. 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); } }
  37159. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37160. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37161. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37162. var Container = /*#__PURE__*/function (_Node) {
  37163. _inheritsLoose(Container, _Node);
  37164. function Container(opts) {
  37165. var _this;
  37166. _this = _Node.call(this, opts) || this;
  37167. if (!_this.nodes) {
  37168. _this.nodes = [];
  37169. }
  37170. return _this;
  37171. }
  37172. var _proto = Container.prototype;
  37173. _proto.append = function append(selector) {
  37174. selector.parent = this;
  37175. this.nodes.push(selector);
  37176. return this;
  37177. };
  37178. _proto.prepend = function prepend(selector) {
  37179. selector.parent = this;
  37180. this.nodes.unshift(selector);
  37181. for (var id in this.indexes) {
  37182. this.indexes[id]++;
  37183. }
  37184. return this;
  37185. };
  37186. _proto.at = function at(index) {
  37187. return this.nodes[index];
  37188. };
  37189. _proto.index = function index(child) {
  37190. if (typeof child === 'number') {
  37191. return child;
  37192. }
  37193. return this.nodes.indexOf(child);
  37194. };
  37195. _proto.removeChild = function removeChild(child) {
  37196. child = this.index(child);
  37197. this.at(child).parent = undefined;
  37198. this.nodes.splice(child, 1);
  37199. var index;
  37200. for (var id in this.indexes) {
  37201. index = this.indexes[id];
  37202. if (index >= child) {
  37203. this.indexes[id] = index - 1;
  37204. }
  37205. }
  37206. return this;
  37207. };
  37208. _proto.removeAll = function removeAll() {
  37209. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  37210. var node = _step.value;
  37211. node.parent = undefined;
  37212. }
  37213. this.nodes = [];
  37214. return this;
  37215. };
  37216. _proto.empty = function empty() {
  37217. return this.removeAll();
  37218. };
  37219. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  37220. var _this$nodes;
  37221. newNode.parent = this;
  37222. var oldIndex = this.index(oldNode);
  37223. var resetNode = [];
  37224. for (var i = 2; i < arguments.length; i++) {
  37225. resetNode.push(arguments[i]);
  37226. }
  37227. (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
  37228. newNode.parent = this;
  37229. var index;
  37230. for (var id in this.indexes) {
  37231. index = this.indexes[id];
  37232. if (oldIndex < index) {
  37233. this.indexes[id] = index + arguments.length - 1;
  37234. }
  37235. }
  37236. return this;
  37237. };
  37238. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  37239. var _this$nodes2;
  37240. newNode.parent = this;
  37241. var oldIndex = this.index(oldNode);
  37242. var resetNode = [];
  37243. for (var i = 2; i < arguments.length; i++) {
  37244. resetNode.push(arguments[i]);
  37245. }
  37246. (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
  37247. newNode.parent = this;
  37248. var index;
  37249. for (var id in this.indexes) {
  37250. index = this.indexes[id];
  37251. if (index >= oldIndex) {
  37252. this.indexes[id] = index + arguments.length - 1;
  37253. }
  37254. }
  37255. return this;
  37256. };
  37257. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  37258. var found = undefined;
  37259. this.each(function (node) {
  37260. if (node.atPosition) {
  37261. var foundChild = node.atPosition(line, col);
  37262. if (foundChild) {
  37263. found = foundChild;
  37264. return false;
  37265. }
  37266. } else if (node.isAtPosition(line, col)) {
  37267. found = node;
  37268. return false;
  37269. }
  37270. });
  37271. return found;
  37272. }
  37273. /**
  37274. * Return the most specific node at the line and column number given.
  37275. * The source location is based on the original parsed location, locations aren't
  37276. * updated as selector nodes are mutated.
  37277. *
  37278. * Note that this location is relative to the location of the first character
  37279. * of the selector, and not the location of the selector in the overall document
  37280. * when used in conjunction with postcss.
  37281. *
  37282. * If not found, returns undefined.
  37283. * @param {number} line The line number of the node to find. (1-based index)
  37284. * @param {number} col The column number of the node to find. (1-based index)
  37285. */;
  37286. _proto.atPosition = function atPosition(line, col) {
  37287. if (this.isAtPosition(line, col)) {
  37288. return this._findChildAtPosition(line, col) || this;
  37289. } else {
  37290. return undefined;
  37291. }
  37292. };
  37293. _proto._inferEndPosition = function _inferEndPosition() {
  37294. if (this.last && this.last.source && this.last.source.end) {
  37295. this.source = this.source || {};
  37296. this.source.end = this.source.end || {};
  37297. Object.assign(this.source.end, this.last.source.end);
  37298. }
  37299. };
  37300. _proto.each = function each(callback) {
  37301. if (!this.lastEach) {
  37302. this.lastEach = 0;
  37303. }
  37304. if (!this.indexes) {
  37305. this.indexes = {};
  37306. }
  37307. this.lastEach++;
  37308. var id = this.lastEach;
  37309. this.indexes[id] = 0;
  37310. if (!this.length) {
  37311. return undefined;
  37312. }
  37313. var index, result;
  37314. while (this.indexes[id] < this.length) {
  37315. index = this.indexes[id];
  37316. result = callback(this.at(index), index);
  37317. if (result === false) {
  37318. break;
  37319. }
  37320. this.indexes[id] += 1;
  37321. }
  37322. delete this.indexes[id];
  37323. if (result === false) {
  37324. return false;
  37325. }
  37326. };
  37327. _proto.walk = function walk(callback) {
  37328. return this.each(function (node, i) {
  37329. var result = callback(node, i);
  37330. if (result !== false && node.length) {
  37331. result = node.walk(callback);
  37332. }
  37333. if (result === false) {
  37334. return false;
  37335. }
  37336. });
  37337. };
  37338. _proto.walkAttributes = function walkAttributes(callback) {
  37339. var _this2 = this;
  37340. return this.walk(function (selector) {
  37341. if (selector.type === types.ATTRIBUTE) {
  37342. return callback.call(_this2, selector);
  37343. }
  37344. });
  37345. };
  37346. _proto.walkClasses = function walkClasses(callback) {
  37347. var _this3 = this;
  37348. return this.walk(function (selector) {
  37349. if (selector.type === types.CLASS) {
  37350. return callback.call(_this3, selector);
  37351. }
  37352. });
  37353. };
  37354. _proto.walkCombinators = function walkCombinators(callback) {
  37355. var _this4 = this;
  37356. return this.walk(function (selector) {
  37357. if (selector.type === types.COMBINATOR) {
  37358. return callback.call(_this4, selector);
  37359. }
  37360. });
  37361. };
  37362. _proto.walkComments = function walkComments(callback) {
  37363. var _this5 = this;
  37364. return this.walk(function (selector) {
  37365. if (selector.type === types.COMMENT) {
  37366. return callback.call(_this5, selector);
  37367. }
  37368. });
  37369. };
  37370. _proto.walkIds = function walkIds(callback) {
  37371. var _this6 = this;
  37372. return this.walk(function (selector) {
  37373. if (selector.type === types.ID) {
  37374. return callback.call(_this6, selector);
  37375. }
  37376. });
  37377. };
  37378. _proto.walkNesting = function walkNesting(callback) {
  37379. var _this7 = this;
  37380. return this.walk(function (selector) {
  37381. if (selector.type === types.NESTING) {
  37382. return callback.call(_this7, selector);
  37383. }
  37384. });
  37385. };
  37386. _proto.walkPseudos = function walkPseudos(callback) {
  37387. var _this8 = this;
  37388. return this.walk(function (selector) {
  37389. if (selector.type === types.PSEUDO) {
  37390. return callback.call(_this8, selector);
  37391. }
  37392. });
  37393. };
  37394. _proto.walkTags = function walkTags(callback) {
  37395. var _this9 = this;
  37396. return this.walk(function (selector) {
  37397. if (selector.type === types.TAG) {
  37398. return callback.call(_this9, selector);
  37399. }
  37400. });
  37401. };
  37402. _proto.walkUniversals = function walkUniversals(callback) {
  37403. var _this10 = this;
  37404. return this.walk(function (selector) {
  37405. if (selector.type === types.UNIVERSAL) {
  37406. return callback.call(_this10, selector);
  37407. }
  37408. });
  37409. };
  37410. _proto.split = function split(callback) {
  37411. var _this11 = this;
  37412. var current = [];
  37413. return this.reduce(function (memo, node, index) {
  37414. var split = callback.call(_this11, node);
  37415. current.push(node);
  37416. if (split) {
  37417. memo.push(current);
  37418. current = [];
  37419. } else if (index === _this11.length - 1) {
  37420. memo.push(current);
  37421. }
  37422. return memo;
  37423. }, []);
  37424. };
  37425. _proto.map = function map(callback) {
  37426. return this.nodes.map(callback);
  37427. };
  37428. _proto.reduce = function reduce(callback, memo) {
  37429. return this.nodes.reduce(callback, memo);
  37430. };
  37431. _proto.every = function every(callback) {
  37432. return this.nodes.every(callback);
  37433. };
  37434. _proto.some = function some(callback) {
  37435. return this.nodes.some(callback);
  37436. };
  37437. _proto.filter = function filter(callback) {
  37438. return this.nodes.filter(callback);
  37439. };
  37440. _proto.sort = function sort(callback) {
  37441. return this.nodes.sort(callback);
  37442. };
  37443. _proto.toString = function toString() {
  37444. return this.map(String).join('');
  37445. };
  37446. _createClass(Container, [{
  37447. key: "first",
  37448. get: function get() {
  37449. return this.at(0);
  37450. }
  37451. }, {
  37452. key: "last",
  37453. get: function get() {
  37454. return this.at(this.length - 1);
  37455. }
  37456. }, {
  37457. key: "length",
  37458. get: function get() {
  37459. return this.nodes.length;
  37460. }
  37461. }]);
  37462. return Container;
  37463. }(_node["default"]);
  37464. exports$1["default"] = Container;
  37465. module.exports = exports$1.default;
  37466. } (container, container.exports));
  37467. return container.exports;
  37468. }
  37469. var hasRequiredRoot;
  37470. function requireRoot () {
  37471. if (hasRequiredRoot) return root.exports;
  37472. hasRequiredRoot = 1;
  37473. (function (module, exports$1) {
  37474. exports$1.__esModule = true;
  37475. exports$1["default"] = void 0;
  37476. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37477. var _types = /*@__PURE__*/ requireTypes();
  37478. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37479. 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); } }
  37480. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37481. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37482. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37483. var Root = /*#__PURE__*/function (_Container) {
  37484. _inheritsLoose(Root, _Container);
  37485. function Root(opts) {
  37486. var _this;
  37487. _this = _Container.call(this, opts) || this;
  37488. _this.type = _types.ROOT;
  37489. return _this;
  37490. }
  37491. var _proto = Root.prototype;
  37492. _proto.toString = function toString() {
  37493. var str = this.reduce(function (memo, selector) {
  37494. memo.push(String(selector));
  37495. return memo;
  37496. }, []).join(',');
  37497. return this.trailingComma ? str + ',' : str;
  37498. };
  37499. _proto.error = function error(message, options) {
  37500. if (this._error) {
  37501. return this._error(message, options);
  37502. } else {
  37503. return new Error(message);
  37504. }
  37505. };
  37506. _createClass(Root, [{
  37507. key: "errorGenerator",
  37508. set: function set(handler) {
  37509. this._error = handler;
  37510. }
  37511. }]);
  37512. return Root;
  37513. }(_container["default"]);
  37514. exports$1["default"] = Root;
  37515. module.exports = exports$1.default;
  37516. } (root, root.exports));
  37517. return root.exports;
  37518. }
  37519. var selector = {exports: {}};
  37520. var hasRequiredSelector;
  37521. function requireSelector () {
  37522. if (hasRequiredSelector) return selector.exports;
  37523. hasRequiredSelector = 1;
  37524. (function (module, exports$1) {
  37525. exports$1.__esModule = true;
  37526. exports$1["default"] = void 0;
  37527. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37528. var _types = /*@__PURE__*/ requireTypes();
  37529. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37530. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37531. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37532. var Selector = /*#__PURE__*/function (_Container) {
  37533. _inheritsLoose(Selector, _Container);
  37534. function Selector(opts) {
  37535. var _this;
  37536. _this = _Container.call(this, opts) || this;
  37537. _this.type = _types.SELECTOR;
  37538. return _this;
  37539. }
  37540. return Selector;
  37541. }(_container["default"]);
  37542. exports$1["default"] = Selector;
  37543. module.exports = exports$1.default;
  37544. } (selector, selector.exports));
  37545. return selector.exports;
  37546. }
  37547. var className = {exports: {}};
  37548. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  37549. var cssesc_1;
  37550. var hasRequiredCssesc;
  37551. function requireCssesc () {
  37552. if (hasRequiredCssesc) return cssesc_1;
  37553. hasRequiredCssesc = 1;
  37554. var object = {};
  37555. var hasOwnProperty = object.hasOwnProperty;
  37556. var merge = function merge(options, defaults) {
  37557. if (!options) {
  37558. return defaults;
  37559. }
  37560. var result = {};
  37561. for (var key in defaults) {
  37562. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  37563. // only recognized option names are used.
  37564. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  37565. }
  37566. return result;
  37567. };
  37568. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  37569. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  37570. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  37571. // https://mathiasbynens.be/notes/css-escapes#css
  37572. var cssesc = function cssesc(string, options) {
  37573. options = merge(options, cssesc.options);
  37574. if (options.quotes != 'single' && options.quotes != 'double') {
  37575. options.quotes = 'single';
  37576. }
  37577. var quote = options.quotes == 'double' ? '"' : '\'';
  37578. var isIdentifier = options.isIdentifier;
  37579. var firstChar = string.charAt(0);
  37580. var output = '';
  37581. var counter = 0;
  37582. var length = string.length;
  37583. while (counter < length) {
  37584. var character = string.charAt(counter++);
  37585. var codePoint = character.charCodeAt();
  37586. var value = void 0;
  37587. // If it’s not a printable ASCII character…
  37588. if (codePoint < 0x20 || codePoint > 0x7E) {
  37589. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37590. // It’s a high surrogate, and there is a next character.
  37591. var extra = string.charCodeAt(counter++);
  37592. if ((extra & 0xFC00) == 0xDC00) {
  37593. // next character is low surrogate
  37594. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37595. } else {
  37596. // It’s an unmatched surrogate; only append this code unit, in case
  37597. // the next code unit is the high surrogate of a surrogate pair.
  37598. counter--;
  37599. }
  37600. }
  37601. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37602. } else {
  37603. if (options.escapeEverything) {
  37604. if (regexAnySingleEscape.test(character)) {
  37605. value = '\\' + character;
  37606. } else {
  37607. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37608. }
  37609. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37610. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37611. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37612. value = '\\' + character;
  37613. } else {
  37614. value = character;
  37615. }
  37616. }
  37617. output += value;
  37618. }
  37619. if (isIdentifier) {
  37620. if (/^-[-\d]/.test(output)) {
  37621. output = '\\-' + output.slice(1);
  37622. } else if (/\d/.test(firstChar)) {
  37623. output = '\\3' + firstChar + ' ' + output.slice(1);
  37624. }
  37625. }
  37626. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37627. // since they’re redundant. Note that this is only possible if the escape
  37628. // sequence isn’t preceded by an odd number of backslashes.
  37629. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37630. if ($1 && $1.length % 2) {
  37631. // It’s not safe to remove the space, so don’t.
  37632. return $0;
  37633. }
  37634. // Strip the space.
  37635. return ($1 || '') + $2;
  37636. });
  37637. if (!isIdentifier && options.wrap) {
  37638. return quote + output + quote;
  37639. }
  37640. return output;
  37641. };
  37642. // Expose default options (so they can be overridden globally).
  37643. cssesc.options = {
  37644. 'escapeEverything': false,
  37645. 'isIdentifier': false,
  37646. 'quotes': 'single',
  37647. 'wrap': false
  37648. };
  37649. cssesc.version = '3.0.0';
  37650. cssesc_1 = cssesc;
  37651. return cssesc_1;
  37652. }
  37653. var hasRequiredClassName;
  37654. function requireClassName () {
  37655. if (hasRequiredClassName) return className.exports;
  37656. hasRequiredClassName = 1;
  37657. (function (module, exports$1) {
  37658. exports$1.__esModule = true;
  37659. exports$1["default"] = void 0;
  37660. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37661. var _util = /*@__PURE__*/ requireUtil$1();
  37662. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37663. var _types = /*@__PURE__*/ requireTypes();
  37664. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37665. 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); } }
  37666. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37667. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37668. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37669. var ClassName = /*#__PURE__*/function (_Node) {
  37670. _inheritsLoose(ClassName, _Node);
  37671. function ClassName(opts) {
  37672. var _this;
  37673. _this = _Node.call(this, opts) || this;
  37674. _this.type = _types.CLASS;
  37675. _this._constructed = true;
  37676. return _this;
  37677. }
  37678. var _proto = ClassName.prototype;
  37679. _proto.valueToString = function valueToString() {
  37680. return '.' + _Node.prototype.valueToString.call(this);
  37681. };
  37682. _createClass(ClassName, [{
  37683. key: "value",
  37684. get: function get() {
  37685. return this._value;
  37686. },
  37687. set: function set(v) {
  37688. if (this._constructed) {
  37689. var escaped = (0, _cssesc["default"])(v, {
  37690. isIdentifier: true
  37691. });
  37692. if (escaped !== v) {
  37693. (0, _util.ensureObject)(this, "raws");
  37694. this.raws.value = escaped;
  37695. } else if (this.raws) {
  37696. delete this.raws.value;
  37697. }
  37698. }
  37699. this._value = v;
  37700. }
  37701. }]);
  37702. return ClassName;
  37703. }(_node["default"]);
  37704. exports$1["default"] = ClassName;
  37705. module.exports = exports$1.default;
  37706. } (className, className.exports));
  37707. return className.exports;
  37708. }
  37709. var comment = {exports: {}};
  37710. var hasRequiredComment;
  37711. function requireComment () {
  37712. if (hasRequiredComment) return comment.exports;
  37713. hasRequiredComment = 1;
  37714. (function (module, exports$1) {
  37715. exports$1.__esModule = true;
  37716. exports$1["default"] = void 0;
  37717. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37718. var _types = /*@__PURE__*/ requireTypes();
  37719. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37720. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37721. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37722. var Comment = /*#__PURE__*/function (_Node) {
  37723. _inheritsLoose(Comment, _Node);
  37724. function Comment(opts) {
  37725. var _this;
  37726. _this = _Node.call(this, opts) || this;
  37727. _this.type = _types.COMMENT;
  37728. return _this;
  37729. }
  37730. return Comment;
  37731. }(_node["default"]);
  37732. exports$1["default"] = Comment;
  37733. module.exports = exports$1.default;
  37734. } (comment, comment.exports));
  37735. return comment.exports;
  37736. }
  37737. var id = {exports: {}};
  37738. var hasRequiredId;
  37739. function requireId () {
  37740. if (hasRequiredId) return id.exports;
  37741. hasRequiredId = 1;
  37742. (function (module, exports$1) {
  37743. exports$1.__esModule = true;
  37744. exports$1["default"] = void 0;
  37745. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37746. var _types = /*@__PURE__*/ requireTypes();
  37747. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37748. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37749. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37750. var ID = /*#__PURE__*/function (_Node) {
  37751. _inheritsLoose(ID, _Node);
  37752. function ID(opts) {
  37753. var _this;
  37754. _this = _Node.call(this, opts) || this;
  37755. _this.type = _types.ID;
  37756. return _this;
  37757. }
  37758. var _proto = ID.prototype;
  37759. _proto.valueToString = function valueToString() {
  37760. return '#' + _Node.prototype.valueToString.call(this);
  37761. };
  37762. return ID;
  37763. }(_node["default"]);
  37764. exports$1["default"] = ID;
  37765. module.exports = exports$1.default;
  37766. } (id, id.exports));
  37767. return id.exports;
  37768. }
  37769. var tag = {exports: {}};
  37770. var namespace = {exports: {}};
  37771. var hasRequiredNamespace;
  37772. function requireNamespace () {
  37773. if (hasRequiredNamespace) return namespace.exports;
  37774. hasRequiredNamespace = 1;
  37775. (function (module, exports$1) {
  37776. exports$1.__esModule = true;
  37777. exports$1["default"] = void 0;
  37778. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37779. var _util = /*@__PURE__*/ requireUtil$1();
  37780. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37781. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37782. 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); } }
  37783. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37784. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37785. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37786. var Namespace = /*#__PURE__*/function (_Node) {
  37787. _inheritsLoose(Namespace, _Node);
  37788. function Namespace() {
  37789. return _Node.apply(this, arguments) || this;
  37790. }
  37791. var _proto = Namespace.prototype;
  37792. _proto.qualifiedName = function qualifiedName(value) {
  37793. if (this.namespace) {
  37794. return this.namespaceString + "|" + value;
  37795. } else {
  37796. return value;
  37797. }
  37798. };
  37799. _proto.valueToString = function valueToString() {
  37800. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37801. };
  37802. _createClass(Namespace, [{
  37803. key: "namespace",
  37804. get: function get() {
  37805. return this._namespace;
  37806. },
  37807. set: function set(namespace) {
  37808. if (namespace === true || namespace === "*" || namespace === "&") {
  37809. this._namespace = namespace;
  37810. if (this.raws) {
  37811. delete this.raws.namespace;
  37812. }
  37813. return;
  37814. }
  37815. var escaped = (0, _cssesc["default"])(namespace, {
  37816. isIdentifier: true
  37817. });
  37818. this._namespace = namespace;
  37819. if (escaped !== namespace) {
  37820. (0, _util.ensureObject)(this, "raws");
  37821. this.raws.namespace = escaped;
  37822. } else if (this.raws) {
  37823. delete this.raws.namespace;
  37824. }
  37825. }
  37826. }, {
  37827. key: "ns",
  37828. get: function get() {
  37829. return this._namespace;
  37830. },
  37831. set: function set(namespace) {
  37832. this.namespace = namespace;
  37833. }
  37834. }, {
  37835. key: "namespaceString",
  37836. get: function get() {
  37837. if (this.namespace) {
  37838. var ns = this.stringifyProperty("namespace");
  37839. if (ns === true) {
  37840. return '';
  37841. } else {
  37842. return ns;
  37843. }
  37844. } else {
  37845. return '';
  37846. }
  37847. }
  37848. }]);
  37849. return Namespace;
  37850. }(_node["default"]);
  37851. exports$1["default"] = Namespace;
  37852. module.exports = exports$1.default;
  37853. } (namespace, namespace.exports));
  37854. return namespace.exports;
  37855. }
  37856. var hasRequiredTag;
  37857. function requireTag () {
  37858. if (hasRequiredTag) return tag.exports;
  37859. hasRequiredTag = 1;
  37860. (function (module, exports$1) {
  37861. exports$1.__esModule = true;
  37862. exports$1["default"] = void 0;
  37863. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37864. var _types = /*@__PURE__*/ requireTypes();
  37865. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37866. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37867. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37868. var Tag = /*#__PURE__*/function (_Namespace) {
  37869. _inheritsLoose(Tag, _Namespace);
  37870. function Tag(opts) {
  37871. var _this;
  37872. _this = _Namespace.call(this, opts) || this;
  37873. _this.type = _types.TAG;
  37874. return _this;
  37875. }
  37876. return Tag;
  37877. }(_namespace["default"]);
  37878. exports$1["default"] = Tag;
  37879. module.exports = exports$1.default;
  37880. } (tag, tag.exports));
  37881. return tag.exports;
  37882. }
  37883. var string = {exports: {}};
  37884. var hasRequiredString;
  37885. function requireString () {
  37886. if (hasRequiredString) return string.exports;
  37887. hasRequiredString = 1;
  37888. (function (module, exports$1) {
  37889. exports$1.__esModule = true;
  37890. exports$1["default"] = void 0;
  37891. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37892. var _types = /*@__PURE__*/ requireTypes();
  37893. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37894. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37895. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37896. var String = /*#__PURE__*/function (_Node) {
  37897. _inheritsLoose(String, _Node);
  37898. function String(opts) {
  37899. var _this;
  37900. _this = _Node.call(this, opts) || this;
  37901. _this.type = _types.STRING;
  37902. return _this;
  37903. }
  37904. return String;
  37905. }(_node["default"]);
  37906. exports$1["default"] = String;
  37907. module.exports = exports$1.default;
  37908. } (string, string.exports));
  37909. return string.exports;
  37910. }
  37911. var pseudo = {exports: {}};
  37912. var hasRequiredPseudo;
  37913. function requirePseudo () {
  37914. if (hasRequiredPseudo) return pseudo.exports;
  37915. hasRequiredPseudo = 1;
  37916. (function (module, exports$1) {
  37917. exports$1.__esModule = true;
  37918. exports$1["default"] = void 0;
  37919. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37920. var _types = /*@__PURE__*/ requireTypes();
  37921. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37922. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37923. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37924. var Pseudo = /*#__PURE__*/function (_Container) {
  37925. _inheritsLoose(Pseudo, _Container);
  37926. function Pseudo(opts) {
  37927. var _this;
  37928. _this = _Container.call(this, opts) || this;
  37929. _this.type = _types.PSEUDO;
  37930. return _this;
  37931. }
  37932. var _proto = Pseudo.prototype;
  37933. _proto.toString = function toString() {
  37934. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37935. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37936. };
  37937. return Pseudo;
  37938. }(_container["default"]);
  37939. exports$1["default"] = Pseudo;
  37940. module.exports = exports$1.default;
  37941. } (pseudo, pseudo.exports));
  37942. return pseudo.exports;
  37943. }
  37944. var attribute = {};
  37945. var node;
  37946. var hasRequiredNode;
  37947. function requireNode () {
  37948. if (hasRequiredNode) return node;
  37949. hasRequiredNode = 1;
  37950. /**
  37951. * For Node.js, simply re-export the core `util.deprecate` function.
  37952. */
  37953. node = require$$0.deprecate;
  37954. return node;
  37955. }
  37956. var hasRequiredAttribute;
  37957. function requireAttribute () {
  37958. if (hasRequiredAttribute) return attribute;
  37959. hasRequiredAttribute = 1;
  37960. (function (exports$1) {
  37961. exports$1.__esModule = true;
  37962. exports$1["default"] = void 0;
  37963. exports$1.unescapeValue = unescapeValue;
  37964. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37965. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  37966. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37967. var _types = /*@__PURE__*/ requireTypes();
  37968. var _CSSESC_QUOTE_OPTIONS;
  37969. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37970. 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); } }
  37971. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37972. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37973. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37974. var deprecate = /*@__PURE__*/ requireNode();
  37975. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37976. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37977. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37978. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37979. function unescapeValue(value) {
  37980. var deprecatedUsage = false;
  37981. var quoteMark = null;
  37982. var unescaped = value;
  37983. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37984. if (m) {
  37985. quoteMark = m[1];
  37986. unescaped = m[2];
  37987. }
  37988. unescaped = (0, _unesc["default"])(unescaped);
  37989. if (unescaped !== value) {
  37990. deprecatedUsage = true;
  37991. }
  37992. return {
  37993. deprecatedUsage: deprecatedUsage,
  37994. unescaped: unescaped,
  37995. quoteMark: quoteMark
  37996. };
  37997. }
  37998. function handleDeprecatedContructorOpts(opts) {
  37999. if (opts.quoteMark !== undefined) {
  38000. return opts;
  38001. }
  38002. if (opts.value === undefined) {
  38003. return opts;
  38004. }
  38005. warnOfDeprecatedConstructor();
  38006. var _unescapeValue = unescapeValue(opts.value),
  38007. quoteMark = _unescapeValue.quoteMark,
  38008. unescaped = _unescapeValue.unescaped;
  38009. if (!opts.raws) {
  38010. opts.raws = {};
  38011. }
  38012. if (opts.raws.value === undefined) {
  38013. opts.raws.value = opts.value;
  38014. }
  38015. opts.value = unescaped;
  38016. opts.quoteMark = quoteMark;
  38017. return opts;
  38018. }
  38019. var Attribute = /*#__PURE__*/function (_Namespace) {
  38020. _inheritsLoose(Attribute, _Namespace);
  38021. function Attribute(opts) {
  38022. var _this;
  38023. if (opts === void 0) {
  38024. opts = {};
  38025. }
  38026. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  38027. _this.type = _types.ATTRIBUTE;
  38028. _this.raws = _this.raws || {};
  38029. Object.defineProperty(_this.raws, 'unquoted', {
  38030. get: deprecate(function () {
  38031. return _this.value;
  38032. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  38033. set: deprecate(function () {
  38034. return _this.value;
  38035. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  38036. });
  38037. _this._constructed = true;
  38038. return _this;
  38039. }
  38040. /**
  38041. * Returns the Attribute's value quoted such that it would be legal to use
  38042. * in the value of a css file. The original value's quotation setting
  38043. * used for stringification is left unchanged. See `setValue(value, options)`
  38044. * if you want to control the quote settings of a new value for the attribute.
  38045. *
  38046. * You can also change the quotation used for the current value by setting quoteMark.
  38047. *
  38048. * Options:
  38049. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  38050. * option is not set, the original value for quoteMark will be used. If
  38051. * indeterminate, a double quote is used. The legal values are:
  38052. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  38053. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  38054. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  38055. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  38056. * over the quoteMark option value.
  38057. * * smart {boolean} - if true, will select a quote mark based on the value
  38058. * and the other options specified here. See the `smartQuoteMark()`
  38059. * method.
  38060. **/
  38061. var _proto = Attribute.prototype;
  38062. _proto.getQuotedValue = function getQuotedValue(options) {
  38063. if (options === void 0) {
  38064. options = {};
  38065. }
  38066. var quoteMark = this._determineQuoteMark(options);
  38067. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  38068. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  38069. return escaped;
  38070. };
  38071. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  38072. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  38073. }
  38074. /**
  38075. * Set the unescaped value with the specified quotation options. The value
  38076. * provided must not include any wrapping quote marks -- those quotes will
  38077. * be interpreted as part of the value and escaped accordingly.
  38078. */;
  38079. _proto.setValue = function setValue(value, options) {
  38080. if (options === void 0) {
  38081. options = {};
  38082. }
  38083. this._value = value;
  38084. this._quoteMark = this._determineQuoteMark(options);
  38085. this._syncRawValue();
  38086. }
  38087. /**
  38088. * Intelligently select a quoteMark value based on the value's contents. If
  38089. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  38090. * mark will be picked that minimizes the number of escapes.
  38091. *
  38092. * If there's no clear winner, the quote mark from these options is used,
  38093. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  38094. * true). If the quoteMark is unspecified, a double quote is used.
  38095. *
  38096. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  38097. * from the quoteValue method.
  38098. */;
  38099. _proto.smartQuoteMark = function smartQuoteMark(options) {
  38100. var v = this.value;
  38101. var numSingleQuotes = v.replace(/[^']/g, '').length;
  38102. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  38103. if (numSingleQuotes + numDoubleQuotes === 0) {
  38104. var escaped = (0, _cssesc["default"])(v, {
  38105. isIdentifier: true
  38106. });
  38107. if (escaped === v) {
  38108. return Attribute.NO_QUOTE;
  38109. } else {
  38110. var pref = this.preferredQuoteMark(options);
  38111. if (pref === Attribute.NO_QUOTE) {
  38112. // pick a quote mark that isn't none and see if it's smaller
  38113. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  38114. var opts = CSSESC_QUOTE_OPTIONS[quote];
  38115. var quoteValue = (0, _cssesc["default"])(v, opts);
  38116. if (quoteValue.length < escaped.length) {
  38117. return quote;
  38118. }
  38119. }
  38120. return pref;
  38121. }
  38122. } else if (numDoubleQuotes === numSingleQuotes) {
  38123. return this.preferredQuoteMark(options);
  38124. } else if (numDoubleQuotes < numSingleQuotes) {
  38125. return Attribute.DOUBLE_QUOTE;
  38126. } else {
  38127. return Attribute.SINGLE_QUOTE;
  38128. }
  38129. }
  38130. /**
  38131. * Selects the preferred quote mark based on the options and the current quote mark value.
  38132. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  38133. * instead.
  38134. */;
  38135. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  38136. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  38137. if (quoteMark === undefined) {
  38138. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  38139. }
  38140. if (quoteMark === undefined) {
  38141. quoteMark = Attribute.DOUBLE_QUOTE;
  38142. }
  38143. return quoteMark;
  38144. };
  38145. _proto._syncRawValue = function _syncRawValue() {
  38146. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  38147. if (rawValue === this._value) {
  38148. if (this.raws) {
  38149. delete this.raws.value;
  38150. }
  38151. } else {
  38152. this.raws.value = rawValue;
  38153. }
  38154. };
  38155. _proto._handleEscapes = function _handleEscapes(prop, value) {
  38156. if (this._constructed) {
  38157. var escaped = (0, _cssesc["default"])(value, {
  38158. isIdentifier: true
  38159. });
  38160. if (escaped !== value) {
  38161. this.raws[prop] = escaped;
  38162. } else {
  38163. delete this.raws[prop];
  38164. }
  38165. }
  38166. };
  38167. _proto._spacesFor = function _spacesFor(name) {
  38168. var attrSpaces = {
  38169. before: '',
  38170. after: ''
  38171. };
  38172. var spaces = this.spaces[name] || {};
  38173. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  38174. return Object.assign(attrSpaces, spaces, rawSpaces);
  38175. };
  38176. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  38177. if (spaceName === void 0) {
  38178. spaceName = name;
  38179. }
  38180. if (concat === void 0) {
  38181. concat = defaultAttrConcat;
  38182. }
  38183. var attrSpaces = this._spacesFor(spaceName);
  38184. return concat(this.stringifyProperty(name), attrSpaces);
  38185. }
  38186. /**
  38187. * returns the offset of the attribute part specified relative to the
  38188. * start of the node of the output string.
  38189. *
  38190. * * "ns" - alias for "namespace"
  38191. * * "namespace" - the namespace if it exists.
  38192. * * "attribute" - the attribute name
  38193. * * "attributeNS" - the start of the attribute or its namespace
  38194. * * "operator" - the match operator of the attribute
  38195. * * "value" - The value (string or identifier)
  38196. * * "insensitive" - the case insensitivity flag;
  38197. * @param part One of the possible values inside an attribute.
  38198. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  38199. */;
  38200. _proto.offsetOf = function offsetOf(name) {
  38201. var count = 1;
  38202. var attributeSpaces = this._spacesFor("attribute");
  38203. count += attributeSpaces.before.length;
  38204. if (name === "namespace" || name === "ns") {
  38205. return this.namespace ? count : -1;
  38206. }
  38207. if (name === "attributeNS") {
  38208. return count;
  38209. }
  38210. count += this.namespaceString.length;
  38211. if (this.namespace) {
  38212. count += 1;
  38213. }
  38214. if (name === "attribute") {
  38215. return count;
  38216. }
  38217. count += this.stringifyProperty("attribute").length;
  38218. count += attributeSpaces.after.length;
  38219. var operatorSpaces = this._spacesFor("operator");
  38220. count += operatorSpaces.before.length;
  38221. var operator = this.stringifyProperty("operator");
  38222. if (name === "operator") {
  38223. return operator ? count : -1;
  38224. }
  38225. count += operator.length;
  38226. count += operatorSpaces.after.length;
  38227. var valueSpaces = this._spacesFor("value");
  38228. count += valueSpaces.before.length;
  38229. var value = this.stringifyProperty("value");
  38230. if (name === "value") {
  38231. return value ? count : -1;
  38232. }
  38233. count += value.length;
  38234. count += valueSpaces.after.length;
  38235. var insensitiveSpaces = this._spacesFor("insensitive");
  38236. count += insensitiveSpaces.before.length;
  38237. if (name === "insensitive") {
  38238. return this.insensitive ? count : -1;
  38239. }
  38240. return -1;
  38241. };
  38242. _proto.toString = function toString() {
  38243. var _this2 = this;
  38244. var selector = [this.rawSpaceBefore, '['];
  38245. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  38246. if (this.operator && (this.value || this.value === '')) {
  38247. selector.push(this._stringFor('operator'));
  38248. selector.push(this._stringFor('value'));
  38249. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  38250. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  38251. attrSpaces.before = " ";
  38252. }
  38253. return defaultAttrConcat(attrValue, attrSpaces);
  38254. }));
  38255. }
  38256. selector.push(']');
  38257. selector.push(this.rawSpaceAfter);
  38258. return selector.join('');
  38259. };
  38260. _createClass(Attribute, [{
  38261. key: "quoted",
  38262. get: function get() {
  38263. var qm = this.quoteMark;
  38264. return qm === "'" || qm === '"';
  38265. },
  38266. set: function set(value) {
  38267. warnOfDeprecatedQuotedAssignment();
  38268. }
  38269. /**
  38270. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  38271. * returns `null` if the value is not quoted.
  38272. * returns `undefined` if the quotation state is unknown (this can happen when
  38273. * the attribute is constructed without specifying a quote mark.)
  38274. */
  38275. }, {
  38276. key: "quoteMark",
  38277. get: function get() {
  38278. return this._quoteMark;
  38279. }
  38280. /**
  38281. * Set the quote mark to be used by this attribute's value.
  38282. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  38283. * value is updated accordingly.
  38284. *
  38285. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  38286. */,
  38287. set: function set(quoteMark) {
  38288. if (!this._constructed) {
  38289. this._quoteMark = quoteMark;
  38290. return;
  38291. }
  38292. if (this._quoteMark !== quoteMark) {
  38293. this._quoteMark = quoteMark;
  38294. this._syncRawValue();
  38295. }
  38296. }
  38297. }, {
  38298. key: "qualifiedAttribute",
  38299. get: function get() {
  38300. return this.qualifiedName(this.raws.attribute || this.attribute);
  38301. }
  38302. }, {
  38303. key: "insensitiveFlag",
  38304. get: function get() {
  38305. return this.insensitive ? 'i' : '';
  38306. }
  38307. }, {
  38308. key: "value",
  38309. get: function get() {
  38310. return this._value;
  38311. },
  38312. set:
  38313. /**
  38314. * Before 3.0, the value had to be set to an escaped value including any wrapped
  38315. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  38316. * is unescaped during parsing and any quote marks are removed.
  38317. *
  38318. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  38319. * a deprecation warning is raised when the new value contains any characters that would
  38320. * require escaping (including if it contains wrapped quotes).
  38321. *
  38322. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  38323. * how the new value is quoted.
  38324. */
  38325. function set(v) {
  38326. if (this._constructed) {
  38327. var _unescapeValue2 = unescapeValue(v),
  38328. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  38329. unescaped = _unescapeValue2.unescaped,
  38330. quoteMark = _unescapeValue2.quoteMark;
  38331. if (deprecatedUsage) {
  38332. warnOfDeprecatedValueAssignment();
  38333. }
  38334. if (unescaped === this._value && quoteMark === this._quoteMark) {
  38335. return;
  38336. }
  38337. this._value = unescaped;
  38338. this._quoteMark = quoteMark;
  38339. this._syncRawValue();
  38340. } else {
  38341. this._value = v;
  38342. }
  38343. }
  38344. }, {
  38345. key: "insensitive",
  38346. get: function get() {
  38347. return this._insensitive;
  38348. }
  38349. /**
  38350. * Set the case insensitive flag.
  38351. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  38352. * of the attribute is updated accordingly.
  38353. *
  38354. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  38355. */,
  38356. set: function set(insensitive) {
  38357. if (!insensitive) {
  38358. this._insensitive = false;
  38359. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  38360. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  38361. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  38362. this.raws.insensitiveFlag = undefined;
  38363. }
  38364. }
  38365. this._insensitive = insensitive;
  38366. }
  38367. }, {
  38368. key: "attribute",
  38369. get: function get() {
  38370. return this._attribute;
  38371. },
  38372. set: function set(name) {
  38373. this._handleEscapes("attribute", name);
  38374. this._attribute = name;
  38375. }
  38376. }]);
  38377. return Attribute;
  38378. }(_namespace["default"]);
  38379. exports$1["default"] = Attribute;
  38380. Attribute.NO_QUOTE = null;
  38381. Attribute.SINGLE_QUOTE = "'";
  38382. Attribute.DOUBLE_QUOTE = '"';
  38383. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  38384. "'": {
  38385. quotes: 'single',
  38386. wrap: true
  38387. },
  38388. '"': {
  38389. quotes: 'double',
  38390. wrap: true
  38391. }
  38392. }, _CSSESC_QUOTE_OPTIONS[null] = {
  38393. isIdentifier: true
  38394. }, _CSSESC_QUOTE_OPTIONS);
  38395. function defaultAttrConcat(attrValue, attrSpaces) {
  38396. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  38397. }
  38398. } (attribute));
  38399. return attribute;
  38400. }
  38401. var universal = {exports: {}};
  38402. var hasRequiredUniversal;
  38403. function requireUniversal () {
  38404. if (hasRequiredUniversal) return universal.exports;
  38405. hasRequiredUniversal = 1;
  38406. (function (module, exports$1) {
  38407. exports$1.__esModule = true;
  38408. exports$1["default"] = void 0;
  38409. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  38410. var _types = /*@__PURE__*/ requireTypes();
  38411. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38412. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38413. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38414. var Universal = /*#__PURE__*/function (_Namespace) {
  38415. _inheritsLoose(Universal, _Namespace);
  38416. function Universal(opts) {
  38417. var _this;
  38418. _this = _Namespace.call(this, opts) || this;
  38419. _this.type = _types.UNIVERSAL;
  38420. _this.value = '*';
  38421. return _this;
  38422. }
  38423. return Universal;
  38424. }(_namespace["default"]);
  38425. exports$1["default"] = Universal;
  38426. module.exports = exports$1.default;
  38427. } (universal, universal.exports));
  38428. return universal.exports;
  38429. }
  38430. var combinator = {exports: {}};
  38431. var hasRequiredCombinator;
  38432. function requireCombinator () {
  38433. if (hasRequiredCombinator) return combinator.exports;
  38434. hasRequiredCombinator = 1;
  38435. (function (module, exports$1) {
  38436. exports$1.__esModule = true;
  38437. exports$1["default"] = void 0;
  38438. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38439. var _types = /*@__PURE__*/ requireTypes();
  38440. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38441. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38442. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38443. var Combinator = /*#__PURE__*/function (_Node) {
  38444. _inheritsLoose(Combinator, _Node);
  38445. function Combinator(opts) {
  38446. var _this;
  38447. _this = _Node.call(this, opts) || this;
  38448. _this.type = _types.COMBINATOR;
  38449. return _this;
  38450. }
  38451. return Combinator;
  38452. }(_node["default"]);
  38453. exports$1["default"] = Combinator;
  38454. module.exports = exports$1.default;
  38455. } (combinator, combinator.exports));
  38456. return combinator.exports;
  38457. }
  38458. var nesting = {exports: {}};
  38459. var hasRequiredNesting;
  38460. function requireNesting () {
  38461. if (hasRequiredNesting) return nesting.exports;
  38462. hasRequiredNesting = 1;
  38463. (function (module, exports$1) {
  38464. exports$1.__esModule = true;
  38465. exports$1["default"] = void 0;
  38466. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38467. var _types = /*@__PURE__*/ requireTypes();
  38468. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38469. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38470. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38471. var Nesting = /*#__PURE__*/function (_Node) {
  38472. _inheritsLoose(Nesting, _Node);
  38473. function Nesting(opts) {
  38474. var _this;
  38475. _this = _Node.call(this, opts) || this;
  38476. _this.type = _types.NESTING;
  38477. _this.value = '&';
  38478. return _this;
  38479. }
  38480. return Nesting;
  38481. }(_node["default"]);
  38482. exports$1["default"] = Nesting;
  38483. module.exports = exports$1.default;
  38484. } (nesting, nesting.exports));
  38485. return nesting.exports;
  38486. }
  38487. var sortAscending = {exports: {}};
  38488. var hasRequiredSortAscending;
  38489. function requireSortAscending () {
  38490. if (hasRequiredSortAscending) return sortAscending.exports;
  38491. hasRequiredSortAscending = 1;
  38492. (function (module, exports$1) {
  38493. exports$1.__esModule = true;
  38494. exports$1["default"] = sortAscending;
  38495. function sortAscending(list) {
  38496. return list.sort(function (a, b) {
  38497. return a - b;
  38498. });
  38499. }
  38500. module.exports = exports$1.default;
  38501. } (sortAscending, sortAscending.exports));
  38502. return sortAscending.exports;
  38503. }
  38504. var tokenize = {};
  38505. var tokenTypes = {};
  38506. var hasRequiredTokenTypes;
  38507. function requireTokenTypes () {
  38508. if (hasRequiredTokenTypes) return tokenTypes;
  38509. hasRequiredTokenTypes = 1;
  38510. tokenTypes.__esModule = true;
  38511. 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;
  38512. var ampersand = 38; // `&`.charCodeAt(0);
  38513. tokenTypes.ampersand = ampersand;
  38514. var asterisk = 42; // `*`.charCodeAt(0);
  38515. tokenTypes.asterisk = asterisk;
  38516. var at = 64; // `@`.charCodeAt(0);
  38517. tokenTypes.at = at;
  38518. var comma = 44; // `,`.charCodeAt(0);
  38519. tokenTypes.comma = comma;
  38520. var colon = 58; // `:`.charCodeAt(0);
  38521. tokenTypes.colon = colon;
  38522. var semicolon = 59; // `;`.charCodeAt(0);
  38523. tokenTypes.semicolon = semicolon;
  38524. var openParenthesis = 40; // `(`.charCodeAt(0);
  38525. tokenTypes.openParenthesis = openParenthesis;
  38526. var closeParenthesis = 41; // `)`.charCodeAt(0);
  38527. tokenTypes.closeParenthesis = closeParenthesis;
  38528. var openSquare = 91; // `[`.charCodeAt(0);
  38529. tokenTypes.openSquare = openSquare;
  38530. var closeSquare = 93; // `]`.charCodeAt(0);
  38531. tokenTypes.closeSquare = closeSquare;
  38532. var dollar = 36; // `$`.charCodeAt(0);
  38533. tokenTypes.dollar = dollar;
  38534. var tilde = 126; // `~`.charCodeAt(0);
  38535. tokenTypes.tilde = tilde;
  38536. var caret = 94; // `^`.charCodeAt(0);
  38537. tokenTypes.caret = caret;
  38538. var plus = 43; // `+`.charCodeAt(0);
  38539. tokenTypes.plus = plus;
  38540. var equals = 61; // `=`.charCodeAt(0);
  38541. tokenTypes.equals = equals;
  38542. var pipe = 124; // `|`.charCodeAt(0);
  38543. tokenTypes.pipe = pipe;
  38544. var greaterThan = 62; // `>`.charCodeAt(0);
  38545. tokenTypes.greaterThan = greaterThan;
  38546. var space = 32; // ` `.charCodeAt(0);
  38547. tokenTypes.space = space;
  38548. var singleQuote = 39; // `'`.charCodeAt(0);
  38549. tokenTypes.singleQuote = singleQuote;
  38550. var doubleQuote = 34; // `"`.charCodeAt(0);
  38551. tokenTypes.doubleQuote = doubleQuote;
  38552. var slash = 47; // `/`.charCodeAt(0);
  38553. tokenTypes.slash = slash;
  38554. var bang = 33; // `!`.charCodeAt(0);
  38555. tokenTypes.bang = bang;
  38556. var backslash = 92; // '\\'.charCodeAt(0);
  38557. tokenTypes.backslash = backslash;
  38558. var cr = 13; // '\r'.charCodeAt(0);
  38559. tokenTypes.cr = cr;
  38560. var feed = 12; // '\f'.charCodeAt(0);
  38561. tokenTypes.feed = feed;
  38562. var newline = 10; // '\n'.charCodeAt(0);
  38563. tokenTypes.newline = newline;
  38564. var tab = 9; // '\t'.charCodeAt(0);
  38565. // Expose aliases primarily for readability.
  38566. tokenTypes.tab = tab;
  38567. var str = singleQuote;
  38568. // No good single character representation!
  38569. tokenTypes.str = str;
  38570. var comment = -1;
  38571. tokenTypes.comment = comment;
  38572. var word = -2;
  38573. tokenTypes.word = word;
  38574. var combinator = -3;
  38575. tokenTypes.combinator = combinator;
  38576. return tokenTypes;
  38577. }
  38578. var hasRequiredTokenize;
  38579. function requireTokenize () {
  38580. if (hasRequiredTokenize) return tokenize;
  38581. hasRequiredTokenize = 1;
  38582. (function (exports$1) {
  38583. exports$1.__esModule = true;
  38584. exports$1.FIELDS = void 0;
  38585. exports$1["default"] = tokenize;
  38586. var t = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38587. var _unescapable, _wordDelimiters;
  38588. 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); }
  38589. 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; }
  38590. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  38591. 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);
  38592. var hex = {};
  38593. var hexChars = "0123456789abcdefABCDEF";
  38594. for (var i = 0; i < hexChars.length; i++) {
  38595. hex[hexChars.charCodeAt(i)] = true;
  38596. }
  38597. /**
  38598. * Returns the last index of the bar css word
  38599. * @param {string} css The string in which the word begins
  38600. * @param {number} start The index into the string where word's first letter occurs
  38601. */
  38602. function consumeWord(css, start) {
  38603. var next = start;
  38604. var code;
  38605. do {
  38606. code = css.charCodeAt(next);
  38607. if (wordDelimiters[code]) {
  38608. return next - 1;
  38609. } else if (code === t.backslash) {
  38610. next = consumeEscape(css, next) + 1;
  38611. } else {
  38612. // All other characters are part of the word
  38613. next++;
  38614. }
  38615. } while (next < css.length);
  38616. return next - 1;
  38617. }
  38618. /**
  38619. * Returns the last index of the escape sequence
  38620. * @param {string} css The string in which the sequence begins
  38621. * @param {number} start The index into the string where escape character (`\`) occurs.
  38622. */
  38623. function consumeEscape(css, start) {
  38624. var next = start;
  38625. var code = css.charCodeAt(next + 1);
  38626. if (unescapable[code]) ; else if (hex[code]) {
  38627. var hexDigits = 0;
  38628. // consume up to 6 hex chars
  38629. do {
  38630. next++;
  38631. hexDigits++;
  38632. code = css.charCodeAt(next + 1);
  38633. } while (hex[code] && hexDigits < 6);
  38634. // if fewer than 6 hex chars, a trailing space ends the escape
  38635. if (hexDigits < 6 && code === t.space) {
  38636. next++;
  38637. }
  38638. } else {
  38639. // the next char is part of the current word
  38640. next++;
  38641. }
  38642. return next;
  38643. }
  38644. var FIELDS = {
  38645. TYPE: 0,
  38646. START_LINE: 1,
  38647. START_COL: 2,
  38648. END_LINE: 3,
  38649. END_COL: 4,
  38650. START_POS: 5,
  38651. END_POS: 6
  38652. };
  38653. exports$1.FIELDS = FIELDS;
  38654. function tokenize(input) {
  38655. var tokens = [];
  38656. var css = input.css.valueOf();
  38657. var _css = css,
  38658. length = _css.length;
  38659. var offset = -1;
  38660. var line = 1;
  38661. var start = 0;
  38662. var end = 0;
  38663. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  38664. function unclosed(what, fix) {
  38665. if (input.safe) {
  38666. // fyi: this is never set to true.
  38667. css += fix;
  38668. next = css.length - 1;
  38669. } else {
  38670. throw input.error('Unclosed ' + what, line, start - offset, start);
  38671. }
  38672. }
  38673. while (start < length) {
  38674. code = css.charCodeAt(start);
  38675. if (code === t.newline) {
  38676. offset = start;
  38677. line += 1;
  38678. }
  38679. switch (code) {
  38680. case t.space:
  38681. case t.tab:
  38682. case t.newline:
  38683. case t.cr:
  38684. case t.feed:
  38685. next = start;
  38686. do {
  38687. next += 1;
  38688. code = css.charCodeAt(next);
  38689. if (code === t.newline) {
  38690. offset = next;
  38691. line += 1;
  38692. }
  38693. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38694. tokenType = t.space;
  38695. endLine = line;
  38696. endColumn = next - offset - 1;
  38697. end = next;
  38698. break;
  38699. case t.plus:
  38700. case t.greaterThan:
  38701. case t.tilde:
  38702. case t.pipe:
  38703. next = start;
  38704. do {
  38705. next += 1;
  38706. code = css.charCodeAt(next);
  38707. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38708. tokenType = t.combinator;
  38709. endLine = line;
  38710. endColumn = start - offset;
  38711. end = next;
  38712. break;
  38713. // Consume these characters as single tokens.
  38714. case t.asterisk:
  38715. case t.ampersand:
  38716. case t.bang:
  38717. case t.comma:
  38718. case t.equals:
  38719. case t.dollar:
  38720. case t.caret:
  38721. case t.openSquare:
  38722. case t.closeSquare:
  38723. case t.colon:
  38724. case t.semicolon:
  38725. case t.openParenthesis:
  38726. case t.closeParenthesis:
  38727. next = start;
  38728. tokenType = code;
  38729. endLine = line;
  38730. endColumn = start - offset;
  38731. end = next + 1;
  38732. break;
  38733. case t.singleQuote:
  38734. case t.doubleQuote:
  38735. quote = code === t.singleQuote ? "'" : '"';
  38736. next = start;
  38737. do {
  38738. escaped = false;
  38739. next = css.indexOf(quote, next + 1);
  38740. if (next === -1) {
  38741. unclosed('quote', quote);
  38742. }
  38743. escapePos = next;
  38744. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38745. escapePos -= 1;
  38746. escaped = !escaped;
  38747. }
  38748. } while (escaped);
  38749. tokenType = t.str;
  38750. endLine = line;
  38751. endColumn = start - offset;
  38752. end = next + 1;
  38753. break;
  38754. default:
  38755. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38756. next = css.indexOf('*/', start + 2) + 1;
  38757. if (next === 0) {
  38758. unclosed('comment', '*/');
  38759. }
  38760. content = css.slice(start, next + 1);
  38761. lines = content.split('\n');
  38762. last = lines.length - 1;
  38763. if (last > 0) {
  38764. nextLine = line + last;
  38765. nextOffset = next - lines[last].length;
  38766. } else {
  38767. nextLine = line;
  38768. nextOffset = offset;
  38769. }
  38770. tokenType = t.comment;
  38771. line = nextLine;
  38772. endLine = nextLine;
  38773. endColumn = next - nextOffset;
  38774. } else if (code === t.slash) {
  38775. next = start;
  38776. tokenType = code;
  38777. endLine = line;
  38778. endColumn = start - offset;
  38779. end = next + 1;
  38780. } else {
  38781. next = consumeWord(css, start);
  38782. tokenType = t.word;
  38783. endLine = line;
  38784. endColumn = next - offset;
  38785. }
  38786. end = next + 1;
  38787. break;
  38788. }
  38789. // Ensure that the token structure remains consistent
  38790. tokens.push([tokenType,
  38791. // [0] Token type
  38792. line,
  38793. // [1] Starting line
  38794. start - offset,
  38795. // [2] Starting column
  38796. endLine,
  38797. // [3] Ending line
  38798. endColumn,
  38799. // [4] Ending column
  38800. start,
  38801. // [5] Start position / Source index
  38802. end // [6] End position
  38803. ]);
  38804. // Reset offset for the next token
  38805. if (nextOffset) {
  38806. offset = nextOffset;
  38807. nextOffset = null;
  38808. }
  38809. start = end;
  38810. }
  38811. return tokens;
  38812. }
  38813. } (tokenize));
  38814. return tokenize;
  38815. }
  38816. var hasRequiredParser;
  38817. function requireParser () {
  38818. if (hasRequiredParser) return parser.exports;
  38819. hasRequiredParser = 1;
  38820. (function (module, exports$1) {
  38821. exports$1.__esModule = true;
  38822. exports$1["default"] = void 0;
  38823. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  38824. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  38825. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  38826. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  38827. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  38828. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  38829. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  38830. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  38831. var _attribute = _interopRequireWildcard(/*@__PURE__*/ requireAttribute());
  38832. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  38833. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  38834. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  38835. var _sortAscending = _interopRequireDefault(/*@__PURE__*/ requireSortAscending());
  38836. var _tokenize = _interopRequireWildcard(/*@__PURE__*/ requireTokenize());
  38837. var tokens = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38838. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  38839. var _util = /*@__PURE__*/ requireUtil$1();
  38840. var _WHITESPACE_TOKENS, _Object$assign;
  38841. 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); }
  38842. 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; }
  38843. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38844. 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); } }
  38845. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38846. 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);
  38847. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38848. function tokenStart(token) {
  38849. return {
  38850. line: token[_tokenize.FIELDS.START_LINE],
  38851. column: token[_tokenize.FIELDS.START_COL]
  38852. };
  38853. }
  38854. function tokenEnd(token) {
  38855. return {
  38856. line: token[_tokenize.FIELDS.END_LINE],
  38857. column: token[_tokenize.FIELDS.END_COL]
  38858. };
  38859. }
  38860. function getSource(startLine, startColumn, endLine, endColumn) {
  38861. return {
  38862. start: {
  38863. line: startLine,
  38864. column: startColumn
  38865. },
  38866. end: {
  38867. line: endLine,
  38868. column: endColumn
  38869. }
  38870. };
  38871. }
  38872. function getTokenSource(token) {
  38873. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38874. }
  38875. function getTokenSourceSpan(startToken, endToken) {
  38876. if (!startToken) {
  38877. return undefined;
  38878. }
  38879. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38880. }
  38881. function unescapeProp(node, prop) {
  38882. var value = node[prop];
  38883. if (typeof value !== "string") {
  38884. return;
  38885. }
  38886. if (value.indexOf("\\") !== -1) {
  38887. (0, _util.ensureObject)(node, 'raws');
  38888. node[prop] = (0, _util.unesc)(value);
  38889. if (node.raws[prop] === undefined) {
  38890. node.raws[prop] = value;
  38891. }
  38892. }
  38893. return node;
  38894. }
  38895. function indexesOf(array, item) {
  38896. var i = -1;
  38897. var indexes = [];
  38898. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38899. indexes.push(i);
  38900. }
  38901. return indexes;
  38902. }
  38903. function uniqs() {
  38904. var list = Array.prototype.concat.apply([], arguments);
  38905. return list.filter(function (item, i) {
  38906. return i === list.indexOf(item);
  38907. });
  38908. }
  38909. var Parser = /*#__PURE__*/function () {
  38910. function Parser(rule, options) {
  38911. if (options === void 0) {
  38912. options = {};
  38913. }
  38914. this.rule = rule;
  38915. this.options = Object.assign({
  38916. lossy: false,
  38917. safe: false
  38918. }, options);
  38919. this.position = 0;
  38920. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38921. this.tokens = (0, _tokenize["default"])({
  38922. css: this.css,
  38923. error: this._errorGenerator(),
  38924. safe: this.options.safe
  38925. });
  38926. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38927. this.root = new _root["default"]({
  38928. source: rootSource
  38929. });
  38930. this.root.errorGenerator = this._errorGenerator();
  38931. var selector = new _selector["default"]({
  38932. source: {
  38933. start: {
  38934. line: 1,
  38935. column: 1
  38936. }
  38937. },
  38938. sourceIndex: 0
  38939. });
  38940. this.root.append(selector);
  38941. this.current = selector;
  38942. this.loop();
  38943. }
  38944. var _proto = Parser.prototype;
  38945. _proto._errorGenerator = function _errorGenerator() {
  38946. var _this = this;
  38947. return function (message, errorOptions) {
  38948. if (typeof _this.rule === 'string') {
  38949. return new Error(message);
  38950. }
  38951. return _this.rule.error(message, errorOptions);
  38952. };
  38953. };
  38954. _proto.attribute = function attribute() {
  38955. var attr = [];
  38956. var startingToken = this.currToken;
  38957. this.position++;
  38958. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38959. attr.push(this.currToken);
  38960. this.position++;
  38961. }
  38962. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38963. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38964. }
  38965. var len = attr.length;
  38966. var node = {
  38967. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38968. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38969. };
  38970. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38971. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38972. }
  38973. var pos = 0;
  38974. var spaceBefore = '';
  38975. var commentBefore = '';
  38976. var lastAdded = null;
  38977. var spaceAfterMeaningfulToken = false;
  38978. while (pos < len) {
  38979. var token = attr[pos];
  38980. var content = this.content(token);
  38981. var next = attr[pos + 1];
  38982. switch (token[_tokenize.FIELDS.TYPE]) {
  38983. case tokens.space:
  38984. // if (
  38985. // len === 1 ||
  38986. // pos === 0 && this.content(next) === '|'
  38987. // ) {
  38988. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38989. // }
  38990. spaceAfterMeaningfulToken = true;
  38991. if (this.options.lossy) {
  38992. break;
  38993. }
  38994. if (lastAdded) {
  38995. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38996. var prevContent = node.spaces[lastAdded].after || '';
  38997. node.spaces[lastAdded].after = prevContent + content;
  38998. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38999. if (existingComment) {
  39000. node.raws.spaces[lastAdded].after = existingComment + content;
  39001. }
  39002. } else {
  39003. spaceBefore = spaceBefore + content;
  39004. commentBefore = commentBefore + content;
  39005. }
  39006. break;
  39007. case tokens.asterisk:
  39008. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39009. node.operator = content;
  39010. lastAdded = 'operator';
  39011. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  39012. if (spaceBefore) {
  39013. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  39014. node.spaces.attribute.before = spaceBefore;
  39015. spaceBefore = '';
  39016. }
  39017. if (commentBefore) {
  39018. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  39019. node.raws.spaces.attribute.before = spaceBefore;
  39020. commentBefore = '';
  39021. }
  39022. node.namespace = (node.namespace || "") + content;
  39023. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  39024. if (rawValue) {
  39025. node.raws.namespace += content;
  39026. }
  39027. lastAdded = 'namespace';
  39028. }
  39029. spaceAfterMeaningfulToken = false;
  39030. break;
  39031. case tokens.dollar:
  39032. if (lastAdded === "value") {
  39033. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  39034. node.value += "$";
  39035. if (oldRawValue) {
  39036. node.raws.value = oldRawValue + "$";
  39037. }
  39038. break;
  39039. }
  39040. // Falls through
  39041. case tokens.caret:
  39042. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39043. node.operator = content;
  39044. lastAdded = 'operator';
  39045. }
  39046. spaceAfterMeaningfulToken = false;
  39047. break;
  39048. case tokens.combinator:
  39049. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39050. node.operator = content;
  39051. lastAdded = 'operator';
  39052. }
  39053. if (content !== '|') {
  39054. spaceAfterMeaningfulToken = false;
  39055. break;
  39056. }
  39057. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  39058. node.operator = content;
  39059. lastAdded = 'operator';
  39060. } else if (!node.namespace && !node.attribute) {
  39061. node.namespace = true;
  39062. }
  39063. spaceAfterMeaningfulToken = false;
  39064. break;
  39065. case tokens.word:
  39066. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  39067. // this look-ahead probably fails with comment nodes involved.
  39068. !node.operator && !node.namespace) {
  39069. node.namespace = content;
  39070. lastAdded = 'namespace';
  39071. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  39072. if (spaceBefore) {
  39073. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  39074. node.spaces.attribute.before = spaceBefore;
  39075. spaceBefore = '';
  39076. }
  39077. if (commentBefore) {
  39078. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  39079. node.raws.spaces.attribute.before = commentBefore;
  39080. commentBefore = '';
  39081. }
  39082. node.attribute = (node.attribute || "") + content;
  39083. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  39084. if (_rawValue) {
  39085. node.raws.attribute += content;
  39086. }
  39087. lastAdded = 'attribute';
  39088. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  39089. var _unescaped = (0, _util.unesc)(content);
  39090. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  39091. var oldValue = node.value || '';
  39092. node.value = oldValue + _unescaped;
  39093. node.quoteMark = null;
  39094. if (_unescaped !== content || _oldRawValue) {
  39095. (0, _util.ensureObject)(node, 'raws');
  39096. node.raws.value = (_oldRawValue || oldValue) + content;
  39097. }
  39098. lastAdded = 'value';
  39099. } else {
  39100. var insensitive = content === 'i' || content === "I";
  39101. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  39102. node.insensitive = insensitive;
  39103. if (!insensitive || content === "I") {
  39104. (0, _util.ensureObject)(node, 'raws');
  39105. node.raws.insensitiveFlag = content;
  39106. }
  39107. lastAdded = 'insensitive';
  39108. if (spaceBefore) {
  39109. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  39110. node.spaces.insensitive.before = spaceBefore;
  39111. spaceBefore = '';
  39112. }
  39113. if (commentBefore) {
  39114. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  39115. node.raws.spaces.insensitive.before = commentBefore;
  39116. commentBefore = '';
  39117. }
  39118. } else if (node.value || node.value === '') {
  39119. lastAdded = 'value';
  39120. node.value += content;
  39121. if (node.raws.value) {
  39122. node.raws.value += content;
  39123. }
  39124. }
  39125. }
  39126. spaceAfterMeaningfulToken = false;
  39127. break;
  39128. case tokens.str:
  39129. if (!node.attribute || !node.operator) {
  39130. return this.error("Expected an attribute followed by an operator preceding the string.", {
  39131. index: token[_tokenize.FIELDS.START_POS]
  39132. });
  39133. }
  39134. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  39135. unescaped = _unescapeValue.unescaped,
  39136. quoteMark = _unescapeValue.quoteMark;
  39137. node.value = unescaped;
  39138. node.quoteMark = quoteMark;
  39139. lastAdded = 'value';
  39140. (0, _util.ensureObject)(node, 'raws');
  39141. node.raws.value = content;
  39142. spaceAfterMeaningfulToken = false;
  39143. break;
  39144. case tokens.equals:
  39145. if (!node.attribute) {
  39146. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  39147. }
  39148. if (node.value) {
  39149. return this.error('Unexpected "=" found; an operator was already defined.', {
  39150. index: token[_tokenize.FIELDS.START_POS]
  39151. });
  39152. }
  39153. node.operator = node.operator ? node.operator + content : content;
  39154. lastAdded = 'operator';
  39155. spaceAfterMeaningfulToken = false;
  39156. break;
  39157. case tokens.comment:
  39158. if (lastAdded) {
  39159. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  39160. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  39161. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  39162. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  39163. node.raws.spaces[lastAdded].after = rawLastComment + content;
  39164. } else {
  39165. var lastValue = node[lastAdded] || '';
  39166. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  39167. (0, _util.ensureObject)(node, 'raws');
  39168. node.raws[lastAdded] = rawLastValue + content;
  39169. }
  39170. } else {
  39171. commentBefore = commentBefore + content;
  39172. }
  39173. break;
  39174. default:
  39175. return this.error("Unexpected \"" + content + "\" found.", {
  39176. index: token[_tokenize.FIELDS.START_POS]
  39177. });
  39178. }
  39179. pos++;
  39180. }
  39181. unescapeProp(node, "attribute");
  39182. unescapeProp(node, "namespace");
  39183. this.newNode(new _attribute["default"](node));
  39184. this.position++;
  39185. }
  39186. /**
  39187. * return a node containing meaningless garbage up to (but not including) the specified token position.
  39188. * if the token position is negative, all remaining tokens are consumed.
  39189. *
  39190. * This returns an array containing a single string node if all whitespace,
  39191. * otherwise an array of comment nodes with space before and after.
  39192. *
  39193. * These tokens are not added to the current selector, the caller can add them or use them to amend
  39194. * a previous node's space metadata.
  39195. *
  39196. * In lossy mode, this returns only comments.
  39197. */;
  39198. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  39199. if (stopPosition < 0) {
  39200. stopPosition = this.tokens.length;
  39201. }
  39202. var startPosition = this.position;
  39203. var nodes = [];
  39204. var space = "";
  39205. var lastComment = undefined;
  39206. do {
  39207. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  39208. if (!this.options.lossy) {
  39209. space += this.content();
  39210. }
  39211. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  39212. var spaces = {};
  39213. if (space) {
  39214. spaces.before = space;
  39215. space = "";
  39216. }
  39217. lastComment = new _comment["default"]({
  39218. value: this.content(),
  39219. source: getTokenSource(this.currToken),
  39220. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39221. spaces: spaces
  39222. });
  39223. nodes.push(lastComment);
  39224. }
  39225. } while (++this.position < stopPosition);
  39226. if (space) {
  39227. if (lastComment) {
  39228. lastComment.spaces.after = space;
  39229. } else if (!this.options.lossy) {
  39230. var firstToken = this.tokens[startPosition];
  39231. var lastToken = this.tokens[this.position - 1];
  39232. nodes.push(new _string["default"]({
  39233. value: '',
  39234. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  39235. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39236. spaces: {
  39237. before: space,
  39238. after: ''
  39239. }
  39240. }));
  39241. }
  39242. }
  39243. return nodes;
  39244. }
  39245. /**
  39246. *
  39247. * @param {*} nodes
  39248. */;
  39249. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  39250. var _this2 = this;
  39251. if (requiredSpace === void 0) {
  39252. requiredSpace = false;
  39253. }
  39254. var space = "";
  39255. var rawSpace = "";
  39256. nodes.forEach(function (n) {
  39257. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  39258. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  39259. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  39260. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  39261. });
  39262. if (rawSpace === space) {
  39263. rawSpace = undefined;
  39264. }
  39265. var result = {
  39266. space: space,
  39267. rawSpace: rawSpace
  39268. };
  39269. return result;
  39270. };
  39271. _proto.isNamedCombinator = function isNamedCombinator(position) {
  39272. if (position === void 0) {
  39273. position = this.position;
  39274. }
  39275. 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;
  39276. };
  39277. _proto.namedCombinator = function namedCombinator() {
  39278. if (this.isNamedCombinator()) {
  39279. var nameRaw = this.content(this.tokens[this.position + 1]);
  39280. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  39281. var raws = {};
  39282. if (name !== nameRaw) {
  39283. raws.value = "/" + nameRaw + "/";
  39284. }
  39285. var node = new _combinator["default"]({
  39286. value: "/" + name + "/",
  39287. 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]),
  39288. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39289. raws: raws
  39290. });
  39291. this.position = this.position + 3;
  39292. return node;
  39293. } else {
  39294. this.unexpected();
  39295. }
  39296. };
  39297. _proto.combinator = function combinator() {
  39298. var _this3 = this;
  39299. if (this.content() === '|') {
  39300. return this.namespace();
  39301. }
  39302. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  39303. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  39304. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39305. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39306. if (nodes.length > 0) {
  39307. var last = this.current.last;
  39308. if (last) {
  39309. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  39310. space = _this$convertWhitespa.space,
  39311. rawSpace = _this$convertWhitespa.rawSpace;
  39312. if (rawSpace !== undefined) {
  39313. last.rawSpaceAfter += rawSpace;
  39314. }
  39315. last.spaces.after += space;
  39316. } else {
  39317. nodes.forEach(function (n) {
  39318. return _this3.newNode(n);
  39319. });
  39320. }
  39321. }
  39322. return;
  39323. }
  39324. var firstToken = this.currToken;
  39325. var spaceOrDescendantSelectorNodes = undefined;
  39326. if (nextSigTokenPos > this.position) {
  39327. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39328. }
  39329. var node;
  39330. if (this.isNamedCombinator()) {
  39331. node = this.namedCombinator();
  39332. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  39333. node = new _combinator["default"]({
  39334. value: this.content(),
  39335. source: getTokenSource(this.currToken),
  39336. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  39337. });
  39338. this.position++;
  39339. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  39340. this.unexpected();
  39341. }
  39342. if (node) {
  39343. if (spaceOrDescendantSelectorNodes) {
  39344. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  39345. _space = _this$convertWhitespa2.space,
  39346. _rawSpace = _this$convertWhitespa2.rawSpace;
  39347. node.spaces.before = _space;
  39348. node.rawSpaceBefore = _rawSpace;
  39349. }
  39350. } else {
  39351. // descendant combinator
  39352. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  39353. _space2 = _this$convertWhitespa3.space,
  39354. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  39355. if (!_rawSpace2) {
  39356. _rawSpace2 = _space2;
  39357. }
  39358. var spaces = {};
  39359. var raws = {
  39360. spaces: {}
  39361. };
  39362. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  39363. spaces.before = _space2.slice(0, _space2.length - 1);
  39364. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  39365. } else if (_space2[0] === ' ' && _rawSpace2[0] === ' ') {
  39366. spaces.after = _space2.slice(1);
  39367. raws.spaces.after = _rawSpace2.slice(1);
  39368. } else {
  39369. raws.value = _rawSpace2;
  39370. }
  39371. node = new _combinator["default"]({
  39372. value: ' ',
  39373. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  39374. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39375. spaces: spaces,
  39376. raws: raws
  39377. });
  39378. }
  39379. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  39380. node.spaces.after = this.optionalSpace(this.content());
  39381. this.position++;
  39382. }
  39383. return this.newNode(node);
  39384. };
  39385. _proto.comma = function comma() {
  39386. if (this.position === this.tokens.length - 1) {
  39387. this.root.trailingComma = true;
  39388. this.position++;
  39389. return;
  39390. }
  39391. this.current._inferEndPosition();
  39392. var selector = new _selector["default"]({
  39393. source: {
  39394. start: tokenStart(this.tokens[this.position + 1])
  39395. },
  39396. sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
  39397. });
  39398. this.current.parent.append(selector);
  39399. this.current = selector;
  39400. this.position++;
  39401. };
  39402. _proto.comment = function comment() {
  39403. var current = this.currToken;
  39404. this.newNode(new _comment["default"]({
  39405. value: this.content(),
  39406. source: getTokenSource(current),
  39407. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39408. }));
  39409. this.position++;
  39410. };
  39411. _proto.error = function error(message, opts) {
  39412. throw this.root.error(message, opts);
  39413. };
  39414. _proto.missingBackslash = function missingBackslash() {
  39415. return this.error('Expected a backslash preceding the semicolon.', {
  39416. index: this.currToken[_tokenize.FIELDS.START_POS]
  39417. });
  39418. };
  39419. _proto.missingParenthesis = function missingParenthesis() {
  39420. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39421. };
  39422. _proto.missingSquareBracket = function missingSquareBracket() {
  39423. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  39424. };
  39425. _proto.unexpected = function unexpected() {
  39426. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  39427. };
  39428. _proto.unexpectedPipe = function unexpectedPipe() {
  39429. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  39430. };
  39431. _proto.namespace = function namespace() {
  39432. var before = this.prevToken && this.content(this.prevToken) || true;
  39433. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39434. this.position++;
  39435. return this.word(before);
  39436. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  39437. this.position++;
  39438. return this.universal(before);
  39439. }
  39440. this.unexpectedPipe();
  39441. };
  39442. _proto.nesting = function nesting() {
  39443. if (this.nextToken) {
  39444. var nextContent = this.content(this.nextToken);
  39445. if (nextContent === "|") {
  39446. this.position++;
  39447. return;
  39448. }
  39449. }
  39450. var current = this.currToken;
  39451. this.newNode(new _nesting["default"]({
  39452. value: this.content(),
  39453. source: getTokenSource(current),
  39454. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39455. }));
  39456. this.position++;
  39457. };
  39458. _proto.parentheses = function parentheses() {
  39459. var last = this.current.last;
  39460. var unbalanced = 1;
  39461. this.position++;
  39462. if (last && last.type === types.PSEUDO) {
  39463. var selector = new _selector["default"]({
  39464. source: {
  39465. start: tokenStart(this.tokens[this.position])
  39466. },
  39467. sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
  39468. });
  39469. var cache = this.current;
  39470. last.append(selector);
  39471. this.current = selector;
  39472. while (this.position < this.tokens.length && unbalanced) {
  39473. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39474. unbalanced++;
  39475. }
  39476. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39477. unbalanced--;
  39478. }
  39479. if (unbalanced) {
  39480. this.parse();
  39481. } else {
  39482. this.current.source.end = tokenEnd(this.currToken);
  39483. this.current.parent.source.end = tokenEnd(this.currToken);
  39484. this.position++;
  39485. }
  39486. }
  39487. this.current = cache;
  39488. } else {
  39489. // I think this case should be an error. It's used to implement a basic parse of media queries
  39490. // but I don't think it's a good idea.
  39491. var parenStart = this.currToken;
  39492. var parenValue = "(";
  39493. var parenEnd;
  39494. while (this.position < this.tokens.length && unbalanced) {
  39495. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39496. unbalanced++;
  39497. }
  39498. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39499. unbalanced--;
  39500. }
  39501. parenEnd = this.currToken;
  39502. parenValue += this.parseParenthesisToken(this.currToken);
  39503. this.position++;
  39504. }
  39505. if (last) {
  39506. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  39507. } else {
  39508. this.newNode(new _string["default"]({
  39509. value: parenValue,
  39510. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  39511. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  39512. }));
  39513. }
  39514. }
  39515. if (unbalanced) {
  39516. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39517. }
  39518. };
  39519. _proto.pseudo = function pseudo() {
  39520. var _this4 = this;
  39521. var pseudoStr = '';
  39522. var startingToken = this.currToken;
  39523. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  39524. pseudoStr += this.content();
  39525. this.position++;
  39526. }
  39527. if (!this.currToken) {
  39528. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  39529. }
  39530. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39531. this.splitWord(false, function (first, length) {
  39532. pseudoStr += first;
  39533. _this4.newNode(new _pseudo["default"]({
  39534. value: pseudoStr,
  39535. source: getTokenSourceSpan(startingToken, _this4.currToken),
  39536. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  39537. }));
  39538. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39539. _this4.error('Misplaced parenthesis.', {
  39540. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  39541. });
  39542. }
  39543. });
  39544. } else {
  39545. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  39546. }
  39547. };
  39548. _proto.space = function space() {
  39549. var content = this.content();
  39550. // Handle space before and after the selector
  39551. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  39552. return node.type === 'comment';
  39553. })) {
  39554. this.spaces = this.optionalSpace(content);
  39555. this.position++;
  39556. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39557. this.current.last.spaces.after = this.optionalSpace(content);
  39558. this.position++;
  39559. } else {
  39560. this.combinator();
  39561. }
  39562. };
  39563. _proto.string = function string() {
  39564. var current = this.currToken;
  39565. this.newNode(new _string["default"]({
  39566. value: this.content(),
  39567. source: getTokenSource(current),
  39568. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39569. }));
  39570. this.position++;
  39571. };
  39572. _proto.universal = function universal(namespace) {
  39573. var nextToken = this.nextToken;
  39574. if (nextToken && this.content(nextToken) === '|') {
  39575. this.position++;
  39576. return this.namespace();
  39577. }
  39578. var current = this.currToken;
  39579. this.newNode(new _universal["default"]({
  39580. value: this.content(),
  39581. source: getTokenSource(current),
  39582. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39583. }), namespace);
  39584. this.position++;
  39585. };
  39586. _proto.splitWord = function splitWord(namespace, firstCallback) {
  39587. var _this5 = this;
  39588. var nextToken = this.nextToken;
  39589. var word = this.content();
  39590. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  39591. this.position++;
  39592. var current = this.content();
  39593. word += current;
  39594. if (current.lastIndexOf('\\') === current.length - 1) {
  39595. var next = this.nextToken;
  39596. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  39597. word += this.requiredSpace(this.content(next));
  39598. this.position++;
  39599. }
  39600. }
  39601. nextToken = this.nextToken;
  39602. }
  39603. var hasClass = indexesOf(word, '.').filter(function (i) {
  39604. // Allow escaped dot within class name
  39605. var escapedDot = word[i - 1] === '\\';
  39606. // Allow decimal numbers percent in @keyframes
  39607. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  39608. return !escapedDot && !isKeyframesPercent;
  39609. });
  39610. var hasId = indexesOf(word, '#').filter(function (i) {
  39611. return word[i - 1] !== '\\';
  39612. });
  39613. // Eliminate Sass interpolations from the list of id indexes
  39614. var interpolations = indexesOf(word, '#{');
  39615. if (interpolations.length) {
  39616. hasId = hasId.filter(function (hashIndex) {
  39617. return !~interpolations.indexOf(hashIndex);
  39618. });
  39619. }
  39620. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  39621. indices.forEach(function (ind, i) {
  39622. var index = indices[i + 1] || word.length;
  39623. var value = word.slice(ind, index);
  39624. if (i === 0 && firstCallback) {
  39625. return firstCallback.call(_this5, value, indices.length);
  39626. }
  39627. var node;
  39628. var current = _this5.currToken;
  39629. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  39630. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  39631. if (~hasClass.indexOf(ind)) {
  39632. var classNameOpts = {
  39633. value: value.slice(1),
  39634. source: source,
  39635. sourceIndex: sourceIndex
  39636. };
  39637. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  39638. } else if (~hasId.indexOf(ind)) {
  39639. var idOpts = {
  39640. value: value.slice(1),
  39641. source: source,
  39642. sourceIndex: sourceIndex
  39643. };
  39644. node = new _id["default"](unescapeProp(idOpts, "value"));
  39645. } else {
  39646. var tagOpts = {
  39647. value: value,
  39648. source: source,
  39649. sourceIndex: sourceIndex
  39650. };
  39651. unescapeProp(tagOpts, "value");
  39652. node = new _tag["default"](tagOpts);
  39653. }
  39654. _this5.newNode(node, namespace);
  39655. // Ensure that the namespace is used only once
  39656. namespace = null;
  39657. });
  39658. this.position++;
  39659. };
  39660. _proto.word = function word(namespace) {
  39661. var nextToken = this.nextToken;
  39662. if (nextToken && this.content(nextToken) === '|') {
  39663. this.position++;
  39664. return this.namespace();
  39665. }
  39666. return this.splitWord(namespace);
  39667. };
  39668. _proto.loop = function loop() {
  39669. while (this.position < this.tokens.length) {
  39670. this.parse(true);
  39671. }
  39672. this.current._inferEndPosition();
  39673. return this.root;
  39674. };
  39675. _proto.parse = function parse(throwOnParenthesis) {
  39676. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  39677. case tokens.space:
  39678. this.space();
  39679. break;
  39680. case tokens.comment:
  39681. this.comment();
  39682. break;
  39683. case tokens.openParenthesis:
  39684. this.parentheses();
  39685. break;
  39686. case tokens.closeParenthesis:
  39687. if (throwOnParenthesis) {
  39688. this.missingParenthesis();
  39689. }
  39690. break;
  39691. case tokens.openSquare:
  39692. this.attribute();
  39693. break;
  39694. case tokens.dollar:
  39695. case tokens.caret:
  39696. case tokens.equals:
  39697. case tokens.word:
  39698. this.word();
  39699. break;
  39700. case tokens.colon:
  39701. this.pseudo();
  39702. break;
  39703. case tokens.comma:
  39704. this.comma();
  39705. break;
  39706. case tokens.asterisk:
  39707. this.universal();
  39708. break;
  39709. case tokens.ampersand:
  39710. this.nesting();
  39711. break;
  39712. case tokens.slash:
  39713. case tokens.combinator:
  39714. this.combinator();
  39715. break;
  39716. case tokens.str:
  39717. this.string();
  39718. break;
  39719. // These cases throw; no break needed.
  39720. case tokens.closeSquare:
  39721. this.missingSquareBracket();
  39722. case tokens.semicolon:
  39723. this.missingBackslash();
  39724. default:
  39725. this.unexpected();
  39726. }
  39727. }
  39728. /**
  39729. * Helpers
  39730. */;
  39731. _proto.expected = function expected(description, index, found) {
  39732. if (Array.isArray(description)) {
  39733. var last = description.pop();
  39734. description = description.join(', ') + " or " + last;
  39735. }
  39736. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39737. if (!found) {
  39738. return this.error("Expected " + an + " " + description + ".", {
  39739. index: index
  39740. });
  39741. }
  39742. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39743. index: index
  39744. });
  39745. };
  39746. _proto.requiredSpace = function requiredSpace(space) {
  39747. return this.options.lossy ? ' ' : space;
  39748. };
  39749. _proto.optionalSpace = function optionalSpace(space) {
  39750. return this.options.lossy ? '' : space;
  39751. };
  39752. _proto.lossySpace = function lossySpace(space, required) {
  39753. if (this.options.lossy) {
  39754. return required ? ' ' : '';
  39755. } else {
  39756. return space;
  39757. }
  39758. };
  39759. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39760. var content = this.content(token);
  39761. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39762. return this.requiredSpace(content);
  39763. } else {
  39764. return content;
  39765. }
  39766. };
  39767. _proto.newNode = function newNode(node, namespace) {
  39768. if (namespace) {
  39769. if (/^ +$/.test(namespace)) {
  39770. if (!this.options.lossy) {
  39771. this.spaces = (this.spaces || '') + namespace;
  39772. }
  39773. namespace = true;
  39774. }
  39775. node.namespace = namespace;
  39776. unescapeProp(node, "namespace");
  39777. }
  39778. if (this.spaces) {
  39779. node.spaces.before = this.spaces;
  39780. this.spaces = '';
  39781. }
  39782. return this.current.append(node);
  39783. };
  39784. _proto.content = function content(token) {
  39785. if (token === void 0) {
  39786. token = this.currToken;
  39787. }
  39788. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39789. };
  39790. /**
  39791. * returns the index of the next non-whitespace, non-comment token.
  39792. * returns -1 if no meaningful token is found.
  39793. */
  39794. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39795. if (startPosition === void 0) {
  39796. startPosition = this.position + 1;
  39797. }
  39798. var searchPosition = startPosition;
  39799. while (searchPosition < this.tokens.length) {
  39800. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39801. searchPosition++;
  39802. continue;
  39803. } else {
  39804. return searchPosition;
  39805. }
  39806. }
  39807. return -1;
  39808. };
  39809. _createClass(Parser, [{
  39810. key: "currToken",
  39811. get: function get() {
  39812. return this.tokens[this.position];
  39813. }
  39814. }, {
  39815. key: "nextToken",
  39816. get: function get() {
  39817. return this.tokens[this.position + 1];
  39818. }
  39819. }, {
  39820. key: "prevToken",
  39821. get: function get() {
  39822. return this.tokens[this.position - 1];
  39823. }
  39824. }]);
  39825. return Parser;
  39826. }();
  39827. exports$1["default"] = Parser;
  39828. module.exports = exports$1.default;
  39829. } (parser, parser.exports));
  39830. return parser.exports;
  39831. }
  39832. var hasRequiredProcessor;
  39833. function requireProcessor () {
  39834. if (hasRequiredProcessor) return processor.exports;
  39835. hasRequiredProcessor = 1;
  39836. (function (module, exports$1) {
  39837. exports$1.__esModule = true;
  39838. exports$1["default"] = void 0;
  39839. var _parser = _interopRequireDefault(/*@__PURE__*/ requireParser());
  39840. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39841. var Processor = /*#__PURE__*/function () {
  39842. function Processor(func, options) {
  39843. this.func = func || function noop() {};
  39844. this.funcRes = null;
  39845. this.options = options;
  39846. }
  39847. var _proto = Processor.prototype;
  39848. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39849. if (options === void 0) {
  39850. options = {};
  39851. }
  39852. var merged = Object.assign({}, this.options, options);
  39853. if (merged.updateSelector === false) {
  39854. return false;
  39855. } else {
  39856. return typeof rule !== "string";
  39857. }
  39858. };
  39859. _proto._isLossy = function _isLossy(options) {
  39860. if (options === void 0) {
  39861. options = {};
  39862. }
  39863. var merged = Object.assign({}, this.options, options);
  39864. if (merged.lossless === false) {
  39865. return true;
  39866. } else {
  39867. return false;
  39868. }
  39869. };
  39870. _proto._root = function _root(rule, options) {
  39871. if (options === void 0) {
  39872. options = {};
  39873. }
  39874. var parser = new _parser["default"](rule, this._parseOptions(options));
  39875. return parser.root;
  39876. };
  39877. _proto._parseOptions = function _parseOptions(options) {
  39878. return {
  39879. lossy: this._isLossy(options)
  39880. };
  39881. };
  39882. _proto._run = function _run(rule, options) {
  39883. var _this = this;
  39884. if (options === void 0) {
  39885. options = {};
  39886. }
  39887. return new Promise(function (resolve, reject) {
  39888. try {
  39889. var root = _this._root(rule, options);
  39890. Promise.resolve(_this.func(root)).then(function (transform) {
  39891. var string = undefined;
  39892. if (_this._shouldUpdateSelector(rule, options)) {
  39893. string = root.toString();
  39894. rule.selector = string;
  39895. }
  39896. return {
  39897. transform: transform,
  39898. root: root,
  39899. string: string
  39900. };
  39901. }).then(resolve, reject);
  39902. } catch (e) {
  39903. reject(e);
  39904. return;
  39905. }
  39906. });
  39907. };
  39908. _proto._runSync = function _runSync(rule, options) {
  39909. if (options === void 0) {
  39910. options = {};
  39911. }
  39912. var root = this._root(rule, options);
  39913. var transform = this.func(root);
  39914. if (transform && typeof transform.then === "function") {
  39915. throw new Error("Selector processor returned a promise to a synchronous call.");
  39916. }
  39917. var string = undefined;
  39918. if (options.updateSelector && typeof rule !== "string") {
  39919. string = root.toString();
  39920. rule.selector = string;
  39921. }
  39922. return {
  39923. transform: transform,
  39924. root: root,
  39925. string: string
  39926. };
  39927. }
  39928. /**
  39929. * Process rule into a selector AST.
  39930. *
  39931. * @param rule {postcss.Rule | string} The css selector to be processed
  39932. * @param options The options for processing
  39933. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39934. */;
  39935. _proto.ast = function ast(rule, options) {
  39936. return this._run(rule, options).then(function (result) {
  39937. return result.root;
  39938. });
  39939. }
  39940. /**
  39941. * Process rule into a selector AST synchronously.
  39942. *
  39943. * @param rule {postcss.Rule | string} The css selector to be processed
  39944. * @param options The options for processing
  39945. * @returns {parser.Root} The AST of the selector after processing it.
  39946. */;
  39947. _proto.astSync = function astSync(rule, options) {
  39948. return this._runSync(rule, options).root;
  39949. }
  39950. /**
  39951. * Process a selector into a transformed value asynchronously
  39952. *
  39953. * @param rule {postcss.Rule | string} The css selector to be processed
  39954. * @param options The options for processing
  39955. * @returns {Promise<any>} The value returned by the processor.
  39956. */;
  39957. _proto.transform = function transform(rule, options) {
  39958. return this._run(rule, options).then(function (result) {
  39959. return result.transform;
  39960. });
  39961. }
  39962. /**
  39963. * Process a selector into a transformed value synchronously.
  39964. *
  39965. * @param rule {postcss.Rule | string} The css selector to be processed
  39966. * @param options The options for processing
  39967. * @returns {any} The value returned by the processor.
  39968. */;
  39969. _proto.transformSync = function transformSync(rule, options) {
  39970. return this._runSync(rule, options).transform;
  39971. }
  39972. /**
  39973. * Process a selector into a new selector string asynchronously.
  39974. *
  39975. * @param rule {postcss.Rule | string} The css selector to be processed
  39976. * @param options The options for processing
  39977. * @returns {string} the selector after processing.
  39978. */;
  39979. _proto.process = function process(rule, options) {
  39980. return this._run(rule, options).then(function (result) {
  39981. return result.string || result.root.toString();
  39982. });
  39983. }
  39984. /**
  39985. * Process a selector into a new selector string synchronously.
  39986. *
  39987. * @param rule {postcss.Rule | string} The css selector to be processed
  39988. * @param options The options for processing
  39989. * @returns {string} the selector after processing.
  39990. */;
  39991. _proto.processSync = function processSync(rule, options) {
  39992. var result = this._runSync(rule, options);
  39993. return result.string || result.root.toString();
  39994. };
  39995. return Processor;
  39996. }();
  39997. exports$1["default"] = Processor;
  39998. module.exports = exports$1.default;
  39999. } (processor, processor.exports));
  40000. return processor.exports;
  40001. }
  40002. var selectors = {};
  40003. var constructors = {};
  40004. var hasRequiredConstructors;
  40005. function requireConstructors () {
  40006. if (hasRequiredConstructors) return constructors;
  40007. hasRequiredConstructors = 1;
  40008. constructors.__esModule = true;
  40009. 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;
  40010. var _attribute = _interopRequireDefault(/*@__PURE__*/ requireAttribute());
  40011. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  40012. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  40013. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  40014. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  40015. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  40016. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  40017. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  40018. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  40019. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  40020. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  40021. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  40022. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  40023. var attribute = function attribute(opts) {
  40024. return new _attribute["default"](opts);
  40025. };
  40026. constructors.attribute = attribute;
  40027. var className = function className(opts) {
  40028. return new _className["default"](opts);
  40029. };
  40030. constructors.className = className;
  40031. var combinator = function combinator(opts) {
  40032. return new _combinator["default"](opts);
  40033. };
  40034. constructors.combinator = combinator;
  40035. var comment = function comment(opts) {
  40036. return new _comment["default"](opts);
  40037. };
  40038. constructors.comment = comment;
  40039. var id = function id(opts) {
  40040. return new _id["default"](opts);
  40041. };
  40042. constructors.id = id;
  40043. var nesting = function nesting(opts) {
  40044. return new _nesting["default"](opts);
  40045. };
  40046. constructors.nesting = nesting;
  40047. var pseudo = function pseudo(opts) {
  40048. return new _pseudo["default"](opts);
  40049. };
  40050. constructors.pseudo = pseudo;
  40051. var root = function root(opts) {
  40052. return new _root["default"](opts);
  40053. };
  40054. constructors.root = root;
  40055. var selector = function selector(opts) {
  40056. return new _selector["default"](opts);
  40057. };
  40058. constructors.selector = selector;
  40059. var string = function string(opts) {
  40060. return new _string["default"](opts);
  40061. };
  40062. constructors.string = string;
  40063. var tag = function tag(opts) {
  40064. return new _tag["default"](opts);
  40065. };
  40066. constructors.tag = tag;
  40067. var universal = function universal(opts) {
  40068. return new _universal["default"](opts);
  40069. };
  40070. constructors.universal = universal;
  40071. return constructors;
  40072. }
  40073. var guards = {};
  40074. var hasRequiredGuards;
  40075. function requireGuards () {
  40076. if (hasRequiredGuards) return guards;
  40077. hasRequiredGuards = 1;
  40078. guards.__esModule = true;
  40079. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  40080. guards.isContainer = isContainer;
  40081. guards.isIdentifier = void 0;
  40082. guards.isNamespace = isNamespace;
  40083. guards.isNesting = void 0;
  40084. guards.isNode = isNode;
  40085. guards.isPseudo = void 0;
  40086. guards.isPseudoClass = isPseudoClass;
  40087. guards.isPseudoElement = isPseudoElement;
  40088. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  40089. var _types = /*@__PURE__*/ requireTypes();
  40090. var _IS_TYPE;
  40091. 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);
  40092. function isNode(node) {
  40093. return typeof node === "object" && IS_TYPE[node.type];
  40094. }
  40095. function isNodeType(type, node) {
  40096. return isNode(node) && node.type === type;
  40097. }
  40098. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  40099. guards.isAttribute = isAttribute;
  40100. var isClassName = isNodeType.bind(null, _types.CLASS);
  40101. guards.isClassName = isClassName;
  40102. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  40103. guards.isCombinator = isCombinator;
  40104. var isComment = isNodeType.bind(null, _types.COMMENT);
  40105. guards.isComment = isComment;
  40106. var isIdentifier = isNodeType.bind(null, _types.ID);
  40107. guards.isIdentifier = isIdentifier;
  40108. var isNesting = isNodeType.bind(null, _types.NESTING);
  40109. guards.isNesting = isNesting;
  40110. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  40111. guards.isPseudo = isPseudo;
  40112. var isRoot = isNodeType.bind(null, _types.ROOT);
  40113. guards.isRoot = isRoot;
  40114. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  40115. guards.isSelector = isSelector;
  40116. var isString = isNodeType.bind(null, _types.STRING);
  40117. guards.isString = isString;
  40118. var isTag = isNodeType.bind(null, _types.TAG);
  40119. guards.isTag = isTag;
  40120. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  40121. guards.isUniversal = isUniversal;
  40122. function isPseudoElement(node) {
  40123. 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");
  40124. }
  40125. function isPseudoClass(node) {
  40126. return isPseudo(node) && !isPseudoElement(node);
  40127. }
  40128. function isContainer(node) {
  40129. return !!(isNode(node) && node.walk);
  40130. }
  40131. function isNamespace(node) {
  40132. return isAttribute(node) || isTag(node);
  40133. }
  40134. return guards;
  40135. }
  40136. var hasRequiredSelectors;
  40137. function requireSelectors () {
  40138. if (hasRequiredSelectors) return selectors;
  40139. hasRequiredSelectors = 1;
  40140. (function (exports$1) {
  40141. exports$1.__esModule = true;
  40142. var _types = /*@__PURE__*/ requireTypes();
  40143. Object.keys(_types).forEach(function (key) {
  40144. if (key === "default" || key === "__esModule") return;
  40145. if (key in exports$1 && exports$1[key] === _types[key]) return;
  40146. exports$1[key] = _types[key];
  40147. });
  40148. var _constructors = /*@__PURE__*/ requireConstructors();
  40149. Object.keys(_constructors).forEach(function (key) {
  40150. if (key === "default" || key === "__esModule") return;
  40151. if (key in exports$1 && exports$1[key] === _constructors[key]) return;
  40152. exports$1[key] = _constructors[key];
  40153. });
  40154. var _guards = /*@__PURE__*/ requireGuards();
  40155. Object.keys(_guards).forEach(function (key) {
  40156. if (key === "default" || key === "__esModule") return;
  40157. if (key in exports$1 && exports$1[key] === _guards[key]) return;
  40158. exports$1[key] = _guards[key];
  40159. });
  40160. } (selectors));
  40161. return selectors;
  40162. }
  40163. var hasRequiredDist;
  40164. function requireDist () {
  40165. if (hasRequiredDist) return dist.exports;
  40166. hasRequiredDist = 1;
  40167. (function (module, exports$1) {
  40168. exports$1.__esModule = true;
  40169. exports$1["default"] = void 0;
  40170. var _processor = _interopRequireDefault(/*@__PURE__*/ requireProcessor());
  40171. var selectors = _interopRequireWildcard(/*@__PURE__*/ requireSelectors());
  40172. 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); }
  40173. 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; }
  40174. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  40175. var parser = function parser(processor) {
  40176. return new _processor["default"](processor);
  40177. };
  40178. Object.assign(parser, selectors);
  40179. delete parser.__esModule;
  40180. var _default = parser;
  40181. exports$1["default"] = _default;
  40182. module.exports = exports$1.default;
  40183. } (dist, dist.exports));
  40184. return dist.exports;
  40185. }
  40186. var distExports = /*@__PURE__*/ requireDist();
  40187. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  40188. const animationNameRE = /^(?:-\w+-)?animation-name$/;
  40189. const animationRE = /^(?:-\w+-)?animation$/;
  40190. const keyframesRE = /^(?:-\w+-)?keyframes$/;
  40191. const scopedPlugin = (id = "") => {
  40192. const keyframes = /* @__PURE__ */ Object.create(null);
  40193. const shortId = id.replace(/^data-v-/, "");
  40194. return {
  40195. postcssPlugin: "vue-sfc-scoped",
  40196. Rule(rule) {
  40197. processRule(id, rule);
  40198. },
  40199. AtRule(node) {
  40200. if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  40201. keyframes[node.params] = node.params = node.params + "-" + shortId;
  40202. }
  40203. },
  40204. OnceExit(root) {
  40205. if (Object.keys(keyframes).length) {
  40206. root.walkDecls((decl) => {
  40207. if (animationNameRE.test(decl.prop)) {
  40208. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  40209. }
  40210. if (animationRE.test(decl.prop)) {
  40211. decl.value = decl.value.split(",").map((v) => {
  40212. const vals = v.trim().split(/\s+/);
  40213. const i = vals.findIndex((val) => keyframes[val]);
  40214. if (i !== -1) {
  40215. vals.splice(i, 1, keyframes[vals[i]]);
  40216. return vals.join(" ");
  40217. } else {
  40218. return v;
  40219. }
  40220. }).join(",");
  40221. }
  40222. });
  40223. }
  40224. }
  40225. };
  40226. };
  40227. const processedRules = /* @__PURE__ */ new WeakSet();
  40228. function processRule(id, rule) {
  40229. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
  40230. return;
  40231. }
  40232. processedRules.add(rule);
  40233. let deep = false;
  40234. let parent = rule.parent;
  40235. while (parent && parent.type !== "root") {
  40236. if (parent.__deep) {
  40237. deep = true;
  40238. break;
  40239. }
  40240. parent = parent.parent;
  40241. }
  40242. rule.selector = selectorParser((selectorRoot) => {
  40243. selectorRoot.each((selector) => {
  40244. rewriteSelector(id, rule, selector, selectorRoot, deep);
  40245. });
  40246. }).processSync(rule.selector);
  40247. }
  40248. function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
  40249. let node = null;
  40250. let shouldInject = !deep;
  40251. let hasNestedDeep = false;
  40252. let splitForNestedDeep = false;
  40253. selector.each((n) => {
  40254. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  40255. n.value = " ";
  40256. n.spaces.before = n.spaces.after = "";
  40257. warn(
  40258. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  40259. );
  40260. return false;
  40261. }
  40262. if (n.type === "pseudo") {
  40263. const { value } = n;
  40264. if (isDeepContainerPseudo(n)) {
  40265. const hasDeepSelectors = n.nodes.some(
  40266. (selector2) => selector2.some(isDeepSelector)
  40267. );
  40268. if (hasDeepSelectors) {
  40269. const hasScopeAnchor = !!node;
  40270. const hasMixedSelectors = n.nodes.some(
  40271. (selector2) => !selector2.some(isDeepSelector)
  40272. );
  40273. const hasTrailingNodes = selector.index(n) < selector.length - 1;
  40274. if (canSplitDeepContainerPseudo(n) && !deep && !hasScopeAnchor && hasMixedSelectors && hasTrailingNodes) {
  40275. splitSelectorForNestedDeep(
  40276. id,
  40277. rule,
  40278. selector,
  40279. selectorRoot,
  40280. n,
  40281. deep,
  40282. slotted
  40283. );
  40284. splitForNestedDeep = true;
  40285. return false;
  40286. }
  40287. if (value === ":not" && !deep && !hasScopeAnchor && hasMixedSelectors && hasTrailingNodes) {
  40288. return;
  40289. }
  40290. n.nodes.forEach(
  40291. (selector2) => rewriteSelector(
  40292. id,
  40293. rule,
  40294. selector2,
  40295. selectorRoot,
  40296. deep || hasScopeAnchor,
  40297. slotted
  40298. )
  40299. );
  40300. if (!hasScopeAnchor) {
  40301. node = n;
  40302. shouldInject = false;
  40303. }
  40304. hasNestedDeep = true;
  40305. }
  40306. }
  40307. if (value === ":deep" || value === "::v-deep") {
  40308. rule.__deep = true;
  40309. if (n.nodes.length) {
  40310. let last = n;
  40311. n.nodes[0].each((ss) => {
  40312. selector.insertAfter(last, ss);
  40313. last = ss;
  40314. });
  40315. const prev = selector.at(selector.index(n) - 1);
  40316. if (!prev || !isSpaceCombinator(prev)) {
  40317. selector.insertAfter(
  40318. n,
  40319. selectorParser.combinator({
  40320. value: " "
  40321. })
  40322. );
  40323. }
  40324. selector.removeChild(n);
  40325. } else {
  40326. warn(
  40327. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  40328. );
  40329. const prev = selector.at(selector.index(n) - 1);
  40330. if (prev && isSpaceCombinator(prev)) {
  40331. selector.removeChild(prev);
  40332. }
  40333. selector.removeChild(n);
  40334. }
  40335. return false;
  40336. }
  40337. if (value === ":slotted" || value === "::v-slotted") {
  40338. rewriteSelector(
  40339. id,
  40340. rule,
  40341. n.nodes[0],
  40342. selectorRoot,
  40343. deep,
  40344. true
  40345. );
  40346. let last = n;
  40347. n.nodes[0].each((ss) => {
  40348. selector.insertAfter(last, ss);
  40349. last = ss;
  40350. });
  40351. selector.removeChild(n);
  40352. shouldInject = false;
  40353. return false;
  40354. }
  40355. if (value === ":global" || value === "::v-global") {
  40356. selector.replaceWith(n.nodes[0]);
  40357. return false;
  40358. }
  40359. }
  40360. if (n.type === "universal") {
  40361. const prev = selector.at(selector.index(n) - 1);
  40362. const next = selector.at(selector.index(n) + 1);
  40363. if (!prev) {
  40364. if (next) {
  40365. if (next.type === "combinator" && next.value === " ") {
  40366. selector.removeChild(next);
  40367. }
  40368. selector.removeChild(n);
  40369. return;
  40370. } else {
  40371. node = selectorParser.combinator({
  40372. value: ""
  40373. });
  40374. selector.insertBefore(n, node);
  40375. selector.removeChild(n);
  40376. return false;
  40377. }
  40378. }
  40379. if (node) return;
  40380. }
  40381. if (!hasNestedDeep && (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node)) {
  40382. node = n;
  40383. }
  40384. });
  40385. if (splitForNestedDeep) {
  40386. return;
  40387. }
  40388. if (rule.nodes.some((node2) => node2.type === "rule")) {
  40389. const deep2 = rule.__deep;
  40390. if (!deep2) {
  40391. extractAndWrapNodes(rule);
  40392. const atruleNodes = rule.nodes.filter((node2) => node2.type === "atrule");
  40393. for (const atnode of atruleNodes) {
  40394. extractAndWrapNodes(atnode);
  40395. }
  40396. }
  40397. shouldInject = deep2;
  40398. }
  40399. if (node && !hasNestedDeep) {
  40400. const { type, value } = node;
  40401. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  40402. node.nodes.forEach(
  40403. (value2) => rewriteSelector(id, rule, value2, selectorRoot, deep, slotted)
  40404. );
  40405. shouldInject = false;
  40406. }
  40407. }
  40408. if (node) {
  40409. node.spaces.after = "";
  40410. } else {
  40411. selector.first.spaces.before = "";
  40412. }
  40413. if (shouldInject) {
  40414. const idToAdd = slotted ? id + "-s" : id;
  40415. selector.insertAfter(
  40416. // If node is null it means we need to inject [id] at the start
  40417. // insertAfter can handle `null` here
  40418. node,
  40419. selectorParser.attribute({
  40420. attribute: idToAdd,
  40421. value: idToAdd,
  40422. raws: {},
  40423. quoteMark: `"`
  40424. })
  40425. );
  40426. }
  40427. }
  40428. function isSpaceCombinator(node) {
  40429. return node.type === "combinator" && /^\s+$/.test(node.value);
  40430. }
  40431. function isDeepSelector(node) {
  40432. var _a;
  40433. if (node.type === "pseudo" && (node.value === ":deep" || node.value === "::v-deep")) {
  40434. return true;
  40435. }
  40436. return !!((_a = node.nodes) == null ? void 0 : _a.some((child) => isDeepSelector(child)));
  40437. }
  40438. function isDeepContainerPseudo(node) {
  40439. return node.type === "pseudo" && (node.value === ":is" || node.value === ":where" || node.value === ":has" || node.value === ":not");
  40440. }
  40441. function canSplitDeepContainerPseudo(node) {
  40442. return node.value === ":is" || node.value === ":where" || node.value === ":has";
  40443. }
  40444. function splitSelectorForNestedDeep(id, rule, selector, selectorRoot, pseudo, deep, slotted) {
  40445. const pseudoIndex = selector.index(pseudo);
  40446. const selectors = pseudo.nodes.map((branch, index) => {
  40447. const branchSelector = selector.clone();
  40448. if (branchSelector.first) {
  40449. branchSelector.first.spaces.before = index === 0 ? selector.first.spaces.before : " ";
  40450. }
  40451. const branchPseudo = branchSelector.at(pseudoIndex);
  40452. const branchClone = branch.clone();
  40453. if (branchClone.first) {
  40454. branchClone.first.spaces.before = "";
  40455. }
  40456. branchPseudo.removeAll();
  40457. branchPseudo.append(branchClone);
  40458. rewriteSelector(id, rule, branchSelector, selectorRoot, deep, slotted);
  40459. return branchSelector;
  40460. });
  40461. selector.replaceWith(...selectors);
  40462. }
  40463. function extractAndWrapNodes(parentNode) {
  40464. if (!parentNode.nodes) return;
  40465. const nodes = parentNode.nodes.filter(
  40466. (node) => node.type === "decl" || node.type === "comment"
  40467. );
  40468. if (nodes.length) {
  40469. for (const node of nodes) {
  40470. parentNode.removeChild(node);
  40471. }
  40472. const wrappedRule = new Rule({
  40473. nodes,
  40474. selector: "&"
  40475. });
  40476. parentNode.prepend(wrappedRule);
  40477. }
  40478. }
  40479. scopedPlugin.postcss = true;
  40480. var sourceMap = {};
  40481. var sourceMapGenerator = {};
  40482. var base64Vlq = {};
  40483. var base64 = {};
  40484. /* -*- Mode: js; js-indent-level: 2; -*- */
  40485. var hasRequiredBase64;
  40486. function requireBase64 () {
  40487. if (hasRequiredBase64) return base64;
  40488. hasRequiredBase64 = 1;
  40489. /*
  40490. * Copyright 2011 Mozilla Foundation and contributors
  40491. * Licensed under the New BSD license. See LICENSE or:
  40492. * http://opensource.org/licenses/BSD-3-Clause
  40493. */
  40494. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  40495. /**
  40496. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  40497. */
  40498. base64.encode = function (number) {
  40499. if (0 <= number && number < intToCharMap.length) {
  40500. return intToCharMap[number];
  40501. }
  40502. throw new TypeError("Must be between 0 and 63: " + number);
  40503. };
  40504. /**
  40505. * Decode a single base 64 character code digit to an integer. Returns -1 on
  40506. * failure.
  40507. */
  40508. base64.decode = function (charCode) {
  40509. var bigA = 65; // 'A'
  40510. var bigZ = 90; // 'Z'
  40511. var littleA = 97; // 'a'
  40512. var littleZ = 122; // 'z'
  40513. var zero = 48; // '0'
  40514. var nine = 57; // '9'
  40515. var plus = 43; // '+'
  40516. var slash = 47; // '/'
  40517. var littleOffset = 26;
  40518. var numberOffset = 52;
  40519. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  40520. if (bigA <= charCode && charCode <= bigZ) {
  40521. return (charCode - bigA);
  40522. }
  40523. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  40524. if (littleA <= charCode && charCode <= littleZ) {
  40525. return (charCode - littleA + littleOffset);
  40526. }
  40527. // 52 - 61: 0123456789
  40528. if (zero <= charCode && charCode <= nine) {
  40529. return (charCode - zero + numberOffset);
  40530. }
  40531. // 62: +
  40532. if (charCode == plus) {
  40533. return 62;
  40534. }
  40535. // 63: /
  40536. if (charCode == slash) {
  40537. return 63;
  40538. }
  40539. // Invalid base64 digit.
  40540. return -1;
  40541. };
  40542. return base64;
  40543. }
  40544. /* -*- Mode: js; js-indent-level: 2; -*- */
  40545. var hasRequiredBase64Vlq;
  40546. function requireBase64Vlq () {
  40547. if (hasRequiredBase64Vlq) return base64Vlq;
  40548. hasRequiredBase64Vlq = 1;
  40549. /*
  40550. * Copyright 2011 Mozilla Foundation and contributors
  40551. * Licensed under the New BSD license. See LICENSE or:
  40552. * http://opensource.org/licenses/BSD-3-Clause
  40553. *
  40554. * Based on the Base 64 VLQ implementation in Closure Compiler:
  40555. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  40556. *
  40557. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  40558. * Redistribution and use in source and binary forms, with or without
  40559. * modification, are permitted provided that the following conditions are
  40560. * met:
  40561. *
  40562. * * Redistributions of source code must retain the above copyright
  40563. * notice, this list of conditions and the following disclaimer.
  40564. * * Redistributions in binary form must reproduce the above
  40565. * copyright notice, this list of conditions and the following
  40566. * disclaimer in the documentation and/or other materials provided
  40567. * with the distribution.
  40568. * * Neither the name of Google Inc. nor the names of its
  40569. * contributors may be used to endorse or promote products derived
  40570. * from this software without specific prior written permission.
  40571. *
  40572. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40573. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40574. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  40575. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40576. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40577. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40578. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40579. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  40580. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40581. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40582. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40583. */
  40584. var base64 = /*@__PURE__*/ requireBase64();
  40585. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  40586. // length quantities we use in the source map spec, the first bit is the sign,
  40587. // the next four bits are the actual value, and the 6th bit is the
  40588. // continuation bit. The continuation bit tells us whether there are more
  40589. // digits in this value following this digit.
  40590. //
  40591. // Continuation
  40592. // | Sign
  40593. // | |
  40594. // V V
  40595. // 101011
  40596. var VLQ_BASE_SHIFT = 5;
  40597. // binary: 100000
  40598. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  40599. // binary: 011111
  40600. var VLQ_BASE_MASK = VLQ_BASE - 1;
  40601. // binary: 100000
  40602. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  40603. /**
  40604. * Converts from a two-complement value to a value where the sign bit is
  40605. * placed in the least significant bit. For example, as decimals:
  40606. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  40607. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  40608. */
  40609. function toVLQSigned(aValue) {
  40610. return aValue < 0
  40611. ? ((-aValue) << 1) + 1
  40612. : (aValue << 1) + 0;
  40613. }
  40614. /**
  40615. * Converts to a two-complement value from a value where the sign bit is
  40616. * placed in the least significant bit. For example, as decimals:
  40617. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  40618. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  40619. */
  40620. function fromVLQSigned(aValue) {
  40621. var isNegative = (aValue & 1) === 1;
  40622. var shifted = aValue >> 1;
  40623. return isNegative
  40624. ? -shifted
  40625. : shifted;
  40626. }
  40627. /**
  40628. * Returns the base 64 VLQ encoded value.
  40629. */
  40630. base64Vlq.encode = function base64VLQ_encode(aValue) {
  40631. var encoded = "";
  40632. var digit;
  40633. var vlq = toVLQSigned(aValue);
  40634. do {
  40635. digit = vlq & VLQ_BASE_MASK;
  40636. vlq >>>= VLQ_BASE_SHIFT;
  40637. if (vlq > 0) {
  40638. // There are still more digits in this value, so we must make sure the
  40639. // continuation bit is marked.
  40640. digit |= VLQ_CONTINUATION_BIT;
  40641. }
  40642. encoded += base64.encode(digit);
  40643. } while (vlq > 0);
  40644. return encoded;
  40645. };
  40646. /**
  40647. * Decodes the next base 64 VLQ value from the given string and returns the
  40648. * value and the rest of the string via the out parameter.
  40649. */
  40650. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  40651. var strLen = aStr.length;
  40652. var result = 0;
  40653. var shift = 0;
  40654. var continuation, digit;
  40655. do {
  40656. if (aIndex >= strLen) {
  40657. throw new Error("Expected more digits in base 64 VLQ value.");
  40658. }
  40659. digit = base64.decode(aStr.charCodeAt(aIndex++));
  40660. if (digit === -1) {
  40661. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  40662. }
  40663. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  40664. digit &= VLQ_BASE_MASK;
  40665. result = result + (digit << shift);
  40666. shift += VLQ_BASE_SHIFT;
  40667. } while (continuation);
  40668. aOutParam.value = fromVLQSigned(result);
  40669. aOutParam.rest = aIndex;
  40670. };
  40671. return base64Vlq;
  40672. }
  40673. var util = {};
  40674. /* -*- Mode: js; js-indent-level: 2; -*- */
  40675. var hasRequiredUtil;
  40676. function requireUtil () {
  40677. if (hasRequiredUtil) return util;
  40678. hasRequiredUtil = 1;
  40679. (function (exports$1) {
  40680. /*
  40681. * Copyright 2011 Mozilla Foundation and contributors
  40682. * Licensed under the New BSD license. See LICENSE or:
  40683. * http://opensource.org/licenses/BSD-3-Clause
  40684. */
  40685. /**
  40686. * This is a helper function for getting values from parameter/options
  40687. * objects.
  40688. *
  40689. * @param args The object we are extracting values from
  40690. * @param name The name of the property we are getting.
  40691. * @param defaultValue An optional value to return if the property is missing
  40692. * from the object. If this is not specified and the property is missing, an
  40693. * error will be thrown.
  40694. */
  40695. function getArg(aArgs, aName, aDefaultValue) {
  40696. if (aName in aArgs) {
  40697. return aArgs[aName];
  40698. } else if (arguments.length === 3) {
  40699. return aDefaultValue;
  40700. } else {
  40701. throw new Error('"' + aName + '" is a required argument.');
  40702. }
  40703. }
  40704. exports$1.getArg = getArg;
  40705. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  40706. var dataUrlRegexp = /^data:.+\,.+$/;
  40707. function urlParse(aUrl) {
  40708. var match = aUrl.match(urlRegexp);
  40709. if (!match) {
  40710. return null;
  40711. }
  40712. return {
  40713. scheme: match[1],
  40714. auth: match[2],
  40715. host: match[3],
  40716. port: match[4],
  40717. path: match[5]
  40718. };
  40719. }
  40720. exports$1.urlParse = urlParse;
  40721. function urlGenerate(aParsedUrl) {
  40722. var url = '';
  40723. if (aParsedUrl.scheme) {
  40724. url += aParsedUrl.scheme + ':';
  40725. }
  40726. url += '//';
  40727. if (aParsedUrl.auth) {
  40728. url += aParsedUrl.auth + '@';
  40729. }
  40730. if (aParsedUrl.host) {
  40731. url += aParsedUrl.host;
  40732. }
  40733. if (aParsedUrl.port) {
  40734. url += ":" + aParsedUrl.port;
  40735. }
  40736. if (aParsedUrl.path) {
  40737. url += aParsedUrl.path;
  40738. }
  40739. return url;
  40740. }
  40741. exports$1.urlGenerate = urlGenerate;
  40742. /**
  40743. * Normalizes a path, or the path portion of a URL:
  40744. *
  40745. * - Replaces consecutive slashes with one slash.
  40746. * - Removes unnecessary '.' parts.
  40747. * - Removes unnecessary '<dir>/..' parts.
  40748. *
  40749. * Based on code in the Node.js 'path' core module.
  40750. *
  40751. * @param aPath The path or url to normalize.
  40752. */
  40753. function normalize(aPath) {
  40754. var path = aPath;
  40755. var url = urlParse(aPath);
  40756. if (url) {
  40757. if (!url.path) {
  40758. return aPath;
  40759. }
  40760. path = url.path;
  40761. }
  40762. var isAbsolute = exports$1.isAbsolute(path);
  40763. var parts = path.split(/\/+/);
  40764. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  40765. part = parts[i];
  40766. if (part === '.') {
  40767. parts.splice(i, 1);
  40768. } else if (part === '..') {
  40769. up++;
  40770. } else if (up > 0) {
  40771. if (part === '') {
  40772. // The first part is blank if the path is absolute. Trying to go
  40773. // above the root is a no-op. Therefore we can remove all '..' parts
  40774. // directly after the root.
  40775. parts.splice(i + 1, up);
  40776. up = 0;
  40777. } else {
  40778. parts.splice(i, 2);
  40779. up--;
  40780. }
  40781. }
  40782. }
  40783. path = parts.join('/');
  40784. if (path === '') {
  40785. path = isAbsolute ? '/' : '.';
  40786. }
  40787. if (url) {
  40788. url.path = path;
  40789. return urlGenerate(url);
  40790. }
  40791. return path;
  40792. }
  40793. exports$1.normalize = normalize;
  40794. /**
  40795. * Joins two paths/URLs.
  40796. *
  40797. * @param aRoot The root path or URL.
  40798. * @param aPath The path or URL to be joined with the root.
  40799. *
  40800. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  40801. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  40802. * first.
  40803. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  40804. * is updated with the result and aRoot is returned. Otherwise the result
  40805. * is returned.
  40806. * - If aPath is absolute, the result is aPath.
  40807. * - Otherwise the two paths are joined with a slash.
  40808. * - Joining for example 'http://' and 'www.example.com' is also supported.
  40809. */
  40810. function join(aRoot, aPath) {
  40811. if (aRoot === "") {
  40812. aRoot = ".";
  40813. }
  40814. if (aPath === "") {
  40815. aPath = ".";
  40816. }
  40817. var aPathUrl = urlParse(aPath);
  40818. var aRootUrl = urlParse(aRoot);
  40819. if (aRootUrl) {
  40820. aRoot = aRootUrl.path || '/';
  40821. }
  40822. // `join(foo, '//www.example.org')`
  40823. if (aPathUrl && !aPathUrl.scheme) {
  40824. if (aRootUrl) {
  40825. aPathUrl.scheme = aRootUrl.scheme;
  40826. }
  40827. return urlGenerate(aPathUrl);
  40828. }
  40829. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  40830. return aPath;
  40831. }
  40832. // `join('http://', 'www.example.com')`
  40833. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  40834. aRootUrl.host = aPath;
  40835. return urlGenerate(aRootUrl);
  40836. }
  40837. var joined = aPath.charAt(0) === '/'
  40838. ? aPath
  40839. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  40840. if (aRootUrl) {
  40841. aRootUrl.path = joined;
  40842. return urlGenerate(aRootUrl);
  40843. }
  40844. return joined;
  40845. }
  40846. exports$1.join = join;
  40847. exports$1.isAbsolute = function (aPath) {
  40848. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  40849. };
  40850. /**
  40851. * Make a path relative to a URL or another path.
  40852. *
  40853. * @param aRoot The root path or URL.
  40854. * @param aPath The path or URL to be made relative to aRoot.
  40855. */
  40856. function relative(aRoot, aPath) {
  40857. if (aRoot === "") {
  40858. aRoot = ".";
  40859. }
  40860. aRoot = aRoot.replace(/\/$/, '');
  40861. // It is possible for the path to be above the root. In this case, simply
  40862. // checking whether the root is a prefix of the path won't work. Instead, we
  40863. // need to remove components from the root one by one, until either we find
  40864. // a prefix that fits, or we run out of components to remove.
  40865. var level = 0;
  40866. while (aPath.indexOf(aRoot + '/') !== 0) {
  40867. var index = aRoot.lastIndexOf("/");
  40868. if (index < 0) {
  40869. return aPath;
  40870. }
  40871. // If the only part of the root that is left is the scheme (i.e. http://,
  40872. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40873. // have exhausted all components, so the path is not relative to the root.
  40874. aRoot = aRoot.slice(0, index);
  40875. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40876. return aPath;
  40877. }
  40878. ++level;
  40879. }
  40880. // Make sure we add a "../" for each component we removed from the root.
  40881. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40882. }
  40883. exports$1.relative = relative;
  40884. var supportsNullProto = (function () {
  40885. var obj = Object.create(null);
  40886. return !('__proto__' in obj);
  40887. }());
  40888. function identity (s) {
  40889. return s;
  40890. }
  40891. /**
  40892. * Because behavior goes wacky when you set `__proto__` on objects, we
  40893. * have to prefix all the strings in our set with an arbitrary character.
  40894. *
  40895. * See https://github.com/mozilla/source-map/pull/31 and
  40896. * https://github.com/mozilla/source-map/issues/30
  40897. *
  40898. * @param String aStr
  40899. */
  40900. function toSetString(aStr) {
  40901. if (isProtoString(aStr)) {
  40902. return '$' + aStr;
  40903. }
  40904. return aStr;
  40905. }
  40906. exports$1.toSetString = supportsNullProto ? identity : toSetString;
  40907. function fromSetString(aStr) {
  40908. if (isProtoString(aStr)) {
  40909. return aStr.slice(1);
  40910. }
  40911. return aStr;
  40912. }
  40913. exports$1.fromSetString = supportsNullProto ? identity : fromSetString;
  40914. function isProtoString(s) {
  40915. if (!s) {
  40916. return false;
  40917. }
  40918. var length = s.length;
  40919. if (length < 9 /* "__proto__".length */) {
  40920. return false;
  40921. }
  40922. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40923. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40924. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40925. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40926. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40927. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40928. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40929. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40930. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40931. return false;
  40932. }
  40933. for (var i = length - 10; i >= 0; i--) {
  40934. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40935. return false;
  40936. }
  40937. }
  40938. return true;
  40939. }
  40940. /**
  40941. * Comparator between two mappings where the original positions are compared.
  40942. *
  40943. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40944. * mappings with the same original source/line/column, but different generated
  40945. * line and column the same. Useful when searching for a mapping with a
  40946. * stubbed out mapping.
  40947. */
  40948. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40949. var cmp = strcmp(mappingA.source, mappingB.source);
  40950. if (cmp !== 0) {
  40951. return cmp;
  40952. }
  40953. cmp = mappingA.originalLine - mappingB.originalLine;
  40954. if (cmp !== 0) {
  40955. return cmp;
  40956. }
  40957. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40958. if (cmp !== 0 || onlyCompareOriginal) {
  40959. return cmp;
  40960. }
  40961. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40962. if (cmp !== 0) {
  40963. return cmp;
  40964. }
  40965. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40966. if (cmp !== 0) {
  40967. return cmp;
  40968. }
  40969. return strcmp(mappingA.name, mappingB.name);
  40970. }
  40971. exports$1.compareByOriginalPositions = compareByOriginalPositions;
  40972. /**
  40973. * Comparator between two mappings with deflated source and name indices where
  40974. * the generated positions are compared.
  40975. *
  40976. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40977. * mappings with the same generated line and column, but different
  40978. * source/name/original line and column the same. Useful when searching for a
  40979. * mapping with a stubbed out mapping.
  40980. */
  40981. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40982. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40983. if (cmp !== 0) {
  40984. return cmp;
  40985. }
  40986. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40987. if (cmp !== 0 || onlyCompareGenerated) {
  40988. return cmp;
  40989. }
  40990. cmp = strcmp(mappingA.source, mappingB.source);
  40991. if (cmp !== 0) {
  40992. return cmp;
  40993. }
  40994. cmp = mappingA.originalLine - mappingB.originalLine;
  40995. if (cmp !== 0) {
  40996. return cmp;
  40997. }
  40998. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40999. if (cmp !== 0) {
  41000. return cmp;
  41001. }
  41002. return strcmp(mappingA.name, mappingB.name);
  41003. }
  41004. exports$1.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  41005. function strcmp(aStr1, aStr2) {
  41006. if (aStr1 === aStr2) {
  41007. return 0;
  41008. }
  41009. if (aStr1 === null) {
  41010. return 1; // aStr2 !== null
  41011. }
  41012. if (aStr2 === null) {
  41013. return -1; // aStr1 !== null
  41014. }
  41015. if (aStr1 > aStr2) {
  41016. return 1;
  41017. }
  41018. return -1;
  41019. }
  41020. /**
  41021. * Comparator between two mappings with inflated source and name strings where
  41022. * the generated positions are compared.
  41023. */
  41024. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  41025. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  41026. if (cmp !== 0) {
  41027. return cmp;
  41028. }
  41029. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  41030. if (cmp !== 0) {
  41031. return cmp;
  41032. }
  41033. cmp = strcmp(mappingA.source, mappingB.source);
  41034. if (cmp !== 0) {
  41035. return cmp;
  41036. }
  41037. cmp = mappingA.originalLine - mappingB.originalLine;
  41038. if (cmp !== 0) {
  41039. return cmp;
  41040. }
  41041. cmp = mappingA.originalColumn - mappingB.originalColumn;
  41042. if (cmp !== 0) {
  41043. return cmp;
  41044. }
  41045. return strcmp(mappingA.name, mappingB.name);
  41046. }
  41047. exports$1.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  41048. /**
  41049. * Strip any JSON XSSI avoidance prefix from the string (as documented
  41050. * in the source maps specification), and then parse the string as
  41051. * JSON.
  41052. */
  41053. function parseSourceMapInput(str) {
  41054. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  41055. }
  41056. exports$1.parseSourceMapInput = parseSourceMapInput;
  41057. /**
  41058. * Compute the URL of a source given the the source root, the source's
  41059. * URL, and the source map's URL.
  41060. */
  41061. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  41062. sourceURL = sourceURL || '';
  41063. if (sourceRoot) {
  41064. // This follows what Chrome does.
  41065. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  41066. sourceRoot += '/';
  41067. }
  41068. // The spec says:
  41069. // Line 4: An optional source root, useful for relocating source
  41070. // files on a server or removing repeated values in the
  41071. // “sources” entry. This value is prepended to the individual
  41072. // entries in the “source” field.
  41073. sourceURL = sourceRoot + sourceURL;
  41074. }
  41075. // Historically, SourceMapConsumer did not take the sourceMapURL as
  41076. // a parameter. This mode is still somewhat supported, which is why
  41077. // this code block is conditional. However, it's preferable to pass
  41078. // the source map URL to SourceMapConsumer, so that this function
  41079. // can implement the source URL resolution algorithm as outlined in
  41080. // the spec. This block is basically the equivalent of:
  41081. // new URL(sourceURL, sourceMapURL).toString()
  41082. // ... except it avoids using URL, which wasn't available in the
  41083. // older releases of node still supported by this library.
  41084. //
  41085. // The spec says:
  41086. // If the sources are not absolute URLs after prepending of the
  41087. // “sourceRoot”, the sources are resolved relative to the
  41088. // SourceMap (like resolving script src in a html document).
  41089. if (sourceMapURL) {
  41090. var parsed = urlParse(sourceMapURL);
  41091. if (!parsed) {
  41092. throw new Error("sourceMapURL could not be parsed");
  41093. }
  41094. if (parsed.path) {
  41095. // Strip the last path component, but keep the "/".
  41096. var index = parsed.path.lastIndexOf('/');
  41097. if (index >= 0) {
  41098. parsed.path = parsed.path.substring(0, index + 1);
  41099. }
  41100. }
  41101. sourceURL = join(urlGenerate(parsed), sourceURL);
  41102. }
  41103. return normalize(sourceURL);
  41104. }
  41105. exports$1.computeSourceURL = computeSourceURL;
  41106. } (util));
  41107. return util;
  41108. }
  41109. var arraySet = {};
  41110. /* -*- Mode: js; js-indent-level: 2; -*- */
  41111. var hasRequiredArraySet;
  41112. function requireArraySet () {
  41113. if (hasRequiredArraySet) return arraySet;
  41114. hasRequiredArraySet = 1;
  41115. /*
  41116. * Copyright 2011 Mozilla Foundation and contributors
  41117. * Licensed under the New BSD license. See LICENSE or:
  41118. * http://opensource.org/licenses/BSD-3-Clause
  41119. */
  41120. var util = /*@__PURE__*/ requireUtil();
  41121. var has = Object.prototype.hasOwnProperty;
  41122. var hasNativeMap = typeof Map !== "undefined";
  41123. /**
  41124. * A data structure which is a combination of an array and a set. Adding a new
  41125. * member is O(1), testing for membership is O(1), and finding the index of an
  41126. * element is O(1). Removing elements from the set is not supported. Only
  41127. * strings are supported for membership.
  41128. */
  41129. function ArraySet() {
  41130. this._array = [];
  41131. this._set = hasNativeMap ? new Map() : Object.create(null);
  41132. }
  41133. /**
  41134. * Static method for creating ArraySet instances from an existing array.
  41135. */
  41136. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  41137. var set = new ArraySet();
  41138. for (var i = 0, len = aArray.length; i < len; i++) {
  41139. set.add(aArray[i], aAllowDuplicates);
  41140. }
  41141. return set;
  41142. };
  41143. /**
  41144. * Return how many unique items are in this ArraySet. If duplicates have been
  41145. * added, than those do not count towards the size.
  41146. *
  41147. * @returns Number
  41148. */
  41149. ArraySet.prototype.size = function ArraySet_size() {
  41150. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  41151. };
  41152. /**
  41153. * Add the given string to this set.
  41154. *
  41155. * @param String aStr
  41156. */
  41157. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  41158. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  41159. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  41160. var idx = this._array.length;
  41161. if (!isDuplicate || aAllowDuplicates) {
  41162. this._array.push(aStr);
  41163. }
  41164. if (!isDuplicate) {
  41165. if (hasNativeMap) {
  41166. this._set.set(aStr, idx);
  41167. } else {
  41168. this._set[sStr] = idx;
  41169. }
  41170. }
  41171. };
  41172. /**
  41173. * Is the given string a member of this set?
  41174. *
  41175. * @param String aStr
  41176. */
  41177. ArraySet.prototype.has = function ArraySet_has(aStr) {
  41178. if (hasNativeMap) {
  41179. return this._set.has(aStr);
  41180. } else {
  41181. var sStr = util.toSetString(aStr);
  41182. return has.call(this._set, sStr);
  41183. }
  41184. };
  41185. /**
  41186. * What is the index of the given string in the array?
  41187. *
  41188. * @param String aStr
  41189. */
  41190. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  41191. if (hasNativeMap) {
  41192. var idx = this._set.get(aStr);
  41193. if (idx >= 0) {
  41194. return idx;
  41195. }
  41196. } else {
  41197. var sStr = util.toSetString(aStr);
  41198. if (has.call(this._set, sStr)) {
  41199. return this._set[sStr];
  41200. }
  41201. }
  41202. throw new Error('"' + aStr + '" is not in the set.');
  41203. };
  41204. /**
  41205. * What is the element at the given index?
  41206. *
  41207. * @param Number aIdx
  41208. */
  41209. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  41210. if (aIdx >= 0 && aIdx < this._array.length) {
  41211. return this._array[aIdx];
  41212. }
  41213. throw new Error('No element indexed by ' + aIdx);
  41214. };
  41215. /**
  41216. * Returns the array representation of this set (which has the proper indices
  41217. * indicated by indexOf). Note that this is a copy of the internal array used
  41218. * for storing the members so that no one can mess with internal state.
  41219. */
  41220. ArraySet.prototype.toArray = function ArraySet_toArray() {
  41221. return this._array.slice();
  41222. };
  41223. arraySet.ArraySet = ArraySet;
  41224. return arraySet;
  41225. }
  41226. var mappingList = {};
  41227. /* -*- Mode: js; js-indent-level: 2; -*- */
  41228. var hasRequiredMappingList;
  41229. function requireMappingList () {
  41230. if (hasRequiredMappingList) return mappingList;
  41231. hasRequiredMappingList = 1;
  41232. /*
  41233. * Copyright 2014 Mozilla Foundation and contributors
  41234. * Licensed under the New BSD license. See LICENSE or:
  41235. * http://opensource.org/licenses/BSD-3-Clause
  41236. */
  41237. var util = /*@__PURE__*/ requireUtil();
  41238. /**
  41239. * Determine whether mappingB is after mappingA with respect to generated
  41240. * position.
  41241. */
  41242. function generatedPositionAfter(mappingA, mappingB) {
  41243. // Optimized for most common case
  41244. var lineA = mappingA.generatedLine;
  41245. var lineB = mappingB.generatedLine;
  41246. var columnA = mappingA.generatedColumn;
  41247. var columnB = mappingB.generatedColumn;
  41248. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  41249. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  41250. }
  41251. /**
  41252. * A data structure to provide a sorted view of accumulated mappings in a
  41253. * performance conscious manner. It trades a neglibable overhead in general
  41254. * case for a large speedup in case of mappings being added in order.
  41255. */
  41256. function MappingList() {
  41257. this._array = [];
  41258. this._sorted = true;
  41259. // Serves as infimum
  41260. this._last = {generatedLine: -1, generatedColumn: 0};
  41261. }
  41262. /**
  41263. * Iterate through internal items. This method takes the same arguments that
  41264. * `Array.prototype.forEach` takes.
  41265. *
  41266. * NOTE: The order of the mappings is NOT guaranteed.
  41267. */
  41268. MappingList.prototype.unsortedForEach =
  41269. function MappingList_forEach(aCallback, aThisArg) {
  41270. this._array.forEach(aCallback, aThisArg);
  41271. };
  41272. /**
  41273. * Add the given source mapping.
  41274. *
  41275. * @param Object aMapping
  41276. */
  41277. MappingList.prototype.add = function MappingList_add(aMapping) {
  41278. if (generatedPositionAfter(this._last, aMapping)) {
  41279. this._last = aMapping;
  41280. this._array.push(aMapping);
  41281. } else {
  41282. this._sorted = false;
  41283. this._array.push(aMapping);
  41284. }
  41285. };
  41286. /**
  41287. * Returns the flat, sorted array of mappings. The mappings are sorted by
  41288. * generated position.
  41289. *
  41290. * WARNING: This method returns internal data without copying, for
  41291. * performance. The return value must NOT be mutated, and should be treated as
  41292. * an immutable borrow. If you want to take ownership, you must make your own
  41293. * copy.
  41294. */
  41295. MappingList.prototype.toArray = function MappingList_toArray() {
  41296. if (!this._sorted) {
  41297. this._array.sort(util.compareByGeneratedPositionsInflated);
  41298. this._sorted = true;
  41299. }
  41300. return this._array;
  41301. };
  41302. mappingList.MappingList = MappingList;
  41303. return mappingList;
  41304. }
  41305. /* -*- Mode: js; js-indent-level: 2; -*- */
  41306. var hasRequiredSourceMapGenerator;
  41307. function requireSourceMapGenerator () {
  41308. if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
  41309. hasRequiredSourceMapGenerator = 1;
  41310. /*
  41311. * Copyright 2011 Mozilla Foundation and contributors
  41312. * Licensed under the New BSD license. See LICENSE or:
  41313. * http://opensource.org/licenses/BSD-3-Clause
  41314. */
  41315. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41316. var util = /*@__PURE__*/ requireUtil();
  41317. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41318. var MappingList = /*@__PURE__*/ requireMappingList().MappingList;
  41319. /**
  41320. * An instance of the SourceMapGenerator represents a source map which is
  41321. * being built incrementally. You may pass an object with the following
  41322. * properties:
  41323. *
  41324. * - file: The filename of the generated source.
  41325. * - sourceRoot: A root for all relative URLs in this source map.
  41326. */
  41327. function SourceMapGenerator(aArgs) {
  41328. if (!aArgs) {
  41329. aArgs = {};
  41330. }
  41331. this._file = util.getArg(aArgs, 'file', null);
  41332. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  41333. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  41334. this._sources = new ArraySet();
  41335. this._names = new ArraySet();
  41336. this._mappings = new MappingList();
  41337. this._sourcesContents = null;
  41338. }
  41339. SourceMapGenerator.prototype._version = 3;
  41340. /**
  41341. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  41342. *
  41343. * @param aSourceMapConsumer The SourceMap.
  41344. */
  41345. SourceMapGenerator.fromSourceMap =
  41346. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  41347. var sourceRoot = aSourceMapConsumer.sourceRoot;
  41348. var generator = new SourceMapGenerator({
  41349. file: aSourceMapConsumer.file,
  41350. sourceRoot: sourceRoot
  41351. });
  41352. aSourceMapConsumer.eachMapping(function (mapping) {
  41353. var newMapping = {
  41354. generated: {
  41355. line: mapping.generatedLine,
  41356. column: mapping.generatedColumn
  41357. }
  41358. };
  41359. if (mapping.source != null) {
  41360. newMapping.source = mapping.source;
  41361. if (sourceRoot != null) {
  41362. newMapping.source = util.relative(sourceRoot, newMapping.source);
  41363. }
  41364. newMapping.original = {
  41365. line: mapping.originalLine,
  41366. column: mapping.originalColumn
  41367. };
  41368. if (mapping.name != null) {
  41369. newMapping.name = mapping.name;
  41370. }
  41371. }
  41372. generator.addMapping(newMapping);
  41373. });
  41374. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41375. var sourceRelative = sourceFile;
  41376. if (sourceRoot !== null) {
  41377. sourceRelative = util.relative(sourceRoot, sourceFile);
  41378. }
  41379. if (!generator._sources.has(sourceRelative)) {
  41380. generator._sources.add(sourceRelative);
  41381. }
  41382. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41383. if (content != null) {
  41384. generator.setSourceContent(sourceFile, content);
  41385. }
  41386. });
  41387. return generator;
  41388. };
  41389. /**
  41390. * Add a single mapping from original source line and column to the generated
  41391. * source's line and column for this source map being created. The mapping
  41392. * object should have the following properties:
  41393. *
  41394. * - generated: An object with the generated line and column positions.
  41395. * - original: An object with the original line and column positions.
  41396. * - source: The original source file (relative to the sourceRoot).
  41397. * - name: An optional original token name for this mapping.
  41398. */
  41399. SourceMapGenerator.prototype.addMapping =
  41400. function SourceMapGenerator_addMapping(aArgs) {
  41401. var generated = util.getArg(aArgs, 'generated');
  41402. var original = util.getArg(aArgs, 'original', null);
  41403. var source = util.getArg(aArgs, 'source', null);
  41404. var name = util.getArg(aArgs, 'name', null);
  41405. if (!this._skipValidation) {
  41406. this._validateMapping(generated, original, source, name);
  41407. }
  41408. if (source != null) {
  41409. source = String(source);
  41410. if (!this._sources.has(source)) {
  41411. this._sources.add(source);
  41412. }
  41413. }
  41414. if (name != null) {
  41415. name = String(name);
  41416. if (!this._names.has(name)) {
  41417. this._names.add(name);
  41418. }
  41419. }
  41420. this._mappings.add({
  41421. generatedLine: generated.line,
  41422. generatedColumn: generated.column,
  41423. originalLine: original != null && original.line,
  41424. originalColumn: original != null && original.column,
  41425. source: source,
  41426. name: name
  41427. });
  41428. };
  41429. /**
  41430. * Set the source content for a source file.
  41431. */
  41432. SourceMapGenerator.prototype.setSourceContent =
  41433. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  41434. var source = aSourceFile;
  41435. if (this._sourceRoot != null) {
  41436. source = util.relative(this._sourceRoot, source);
  41437. }
  41438. if (aSourceContent != null) {
  41439. // Add the source content to the _sourcesContents map.
  41440. // Create a new _sourcesContents map if the property is null.
  41441. if (!this._sourcesContents) {
  41442. this._sourcesContents = Object.create(null);
  41443. }
  41444. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  41445. } else if (this._sourcesContents) {
  41446. // Remove the source file from the _sourcesContents map.
  41447. // If the _sourcesContents map is empty, set the property to null.
  41448. delete this._sourcesContents[util.toSetString(source)];
  41449. if (Object.keys(this._sourcesContents).length === 0) {
  41450. this._sourcesContents = null;
  41451. }
  41452. }
  41453. };
  41454. /**
  41455. * Applies the mappings of a sub-source-map for a specific source file to the
  41456. * source map being generated. Each mapping to the supplied source file is
  41457. * rewritten using the supplied source map. Note: The resolution for the
  41458. * resulting mappings is the minimium of this map and the supplied map.
  41459. *
  41460. * @param aSourceMapConsumer The source map to be applied.
  41461. * @param aSourceFile Optional. The filename of the source file.
  41462. * If omitted, SourceMapConsumer's file property will be used.
  41463. * @param aSourceMapPath Optional. The dirname of the path to the source map
  41464. * to be applied. If relative, it is relative to the SourceMapConsumer.
  41465. * This parameter is needed when the two source maps aren't in the same
  41466. * directory, and the source map to be applied contains relative source
  41467. * paths. If so, those relative source paths need to be rewritten
  41468. * relative to the SourceMapGenerator.
  41469. */
  41470. SourceMapGenerator.prototype.applySourceMap =
  41471. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  41472. var sourceFile = aSourceFile;
  41473. // If aSourceFile is omitted, we will use the file property of the SourceMap
  41474. if (aSourceFile == null) {
  41475. if (aSourceMapConsumer.file == null) {
  41476. throw new Error(
  41477. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  41478. 'or the source map\'s "file" property. Both were omitted.'
  41479. );
  41480. }
  41481. sourceFile = aSourceMapConsumer.file;
  41482. }
  41483. var sourceRoot = this._sourceRoot;
  41484. // Make "sourceFile" relative if an absolute Url is passed.
  41485. if (sourceRoot != null) {
  41486. sourceFile = util.relative(sourceRoot, sourceFile);
  41487. }
  41488. // Applying the SourceMap can add and remove items from the sources and
  41489. // the names array.
  41490. var newSources = new ArraySet();
  41491. var newNames = new ArraySet();
  41492. // Find mappings for the "sourceFile"
  41493. this._mappings.unsortedForEach(function (mapping) {
  41494. if (mapping.source === sourceFile && mapping.originalLine != null) {
  41495. // Check if it can be mapped by the source map, then update the mapping.
  41496. var original = aSourceMapConsumer.originalPositionFor({
  41497. line: mapping.originalLine,
  41498. column: mapping.originalColumn
  41499. });
  41500. if (original.source != null) {
  41501. // Copy mapping
  41502. mapping.source = original.source;
  41503. if (aSourceMapPath != null) {
  41504. mapping.source = util.join(aSourceMapPath, mapping.source);
  41505. }
  41506. if (sourceRoot != null) {
  41507. mapping.source = util.relative(sourceRoot, mapping.source);
  41508. }
  41509. mapping.originalLine = original.line;
  41510. mapping.originalColumn = original.column;
  41511. if (original.name != null) {
  41512. mapping.name = original.name;
  41513. }
  41514. }
  41515. }
  41516. var source = mapping.source;
  41517. if (source != null && !newSources.has(source)) {
  41518. newSources.add(source);
  41519. }
  41520. var name = mapping.name;
  41521. if (name != null && !newNames.has(name)) {
  41522. newNames.add(name);
  41523. }
  41524. }, this);
  41525. this._sources = newSources;
  41526. this._names = newNames;
  41527. // Copy sourcesContents of applied map.
  41528. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41529. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41530. if (content != null) {
  41531. if (aSourceMapPath != null) {
  41532. sourceFile = util.join(aSourceMapPath, sourceFile);
  41533. }
  41534. if (sourceRoot != null) {
  41535. sourceFile = util.relative(sourceRoot, sourceFile);
  41536. }
  41537. this.setSourceContent(sourceFile, content);
  41538. }
  41539. }, this);
  41540. };
  41541. /**
  41542. * A mapping can have one of the three levels of data:
  41543. *
  41544. * 1. Just the generated position.
  41545. * 2. The Generated position, original position, and original source.
  41546. * 3. Generated and original position, original source, as well as a name
  41547. * token.
  41548. *
  41549. * To maintain consistency, we validate that any new mapping being added falls
  41550. * in to one of these categories.
  41551. */
  41552. SourceMapGenerator.prototype._validateMapping =
  41553. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  41554. aName) {
  41555. // When aOriginal is truthy but has empty values for .line and .column,
  41556. // it is most likely a programmer error. In this case we throw a very
  41557. // specific error message to try to guide them the right way.
  41558. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  41559. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  41560. throw new Error(
  41561. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  41562. 'the original mapping entirely and only map the generated position. If so, pass ' +
  41563. 'null for the original mapping instead of an object with empty or null values.'
  41564. );
  41565. }
  41566. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41567. && aGenerated.line > 0 && aGenerated.column >= 0
  41568. && !aOriginal && !aSource && !aName) {
  41569. // Case 1.
  41570. return;
  41571. }
  41572. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41573. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  41574. && aGenerated.line > 0 && aGenerated.column >= 0
  41575. && aOriginal.line > 0 && aOriginal.column >= 0
  41576. && aSource) {
  41577. // Cases 2 and 3.
  41578. return;
  41579. }
  41580. else {
  41581. throw new Error('Invalid mapping: ' + JSON.stringify({
  41582. generated: aGenerated,
  41583. source: aSource,
  41584. original: aOriginal,
  41585. name: aName
  41586. }));
  41587. }
  41588. };
  41589. /**
  41590. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  41591. * specified by the source map format.
  41592. */
  41593. SourceMapGenerator.prototype._serializeMappings =
  41594. function SourceMapGenerator_serializeMappings() {
  41595. var previousGeneratedColumn = 0;
  41596. var previousGeneratedLine = 1;
  41597. var previousOriginalColumn = 0;
  41598. var previousOriginalLine = 0;
  41599. var previousName = 0;
  41600. var previousSource = 0;
  41601. var result = '';
  41602. var next;
  41603. var mapping;
  41604. var nameIdx;
  41605. var sourceIdx;
  41606. var mappings = this._mappings.toArray();
  41607. for (var i = 0, len = mappings.length; i < len; i++) {
  41608. mapping = mappings[i];
  41609. next = '';
  41610. if (mapping.generatedLine !== previousGeneratedLine) {
  41611. previousGeneratedColumn = 0;
  41612. while (mapping.generatedLine !== previousGeneratedLine) {
  41613. next += ';';
  41614. previousGeneratedLine++;
  41615. }
  41616. }
  41617. else {
  41618. if (i > 0) {
  41619. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  41620. continue;
  41621. }
  41622. next += ',';
  41623. }
  41624. }
  41625. next += base64VLQ.encode(mapping.generatedColumn
  41626. - previousGeneratedColumn);
  41627. previousGeneratedColumn = mapping.generatedColumn;
  41628. if (mapping.source != null) {
  41629. sourceIdx = this._sources.indexOf(mapping.source);
  41630. next += base64VLQ.encode(sourceIdx - previousSource);
  41631. previousSource = sourceIdx;
  41632. // lines are stored 0-based in SourceMap spec version 3
  41633. next += base64VLQ.encode(mapping.originalLine - 1
  41634. - previousOriginalLine);
  41635. previousOriginalLine = mapping.originalLine - 1;
  41636. next += base64VLQ.encode(mapping.originalColumn
  41637. - previousOriginalColumn);
  41638. previousOriginalColumn = mapping.originalColumn;
  41639. if (mapping.name != null) {
  41640. nameIdx = this._names.indexOf(mapping.name);
  41641. next += base64VLQ.encode(nameIdx - previousName);
  41642. previousName = nameIdx;
  41643. }
  41644. }
  41645. result += next;
  41646. }
  41647. return result;
  41648. };
  41649. SourceMapGenerator.prototype._generateSourcesContent =
  41650. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  41651. return aSources.map(function (source) {
  41652. if (!this._sourcesContents) {
  41653. return null;
  41654. }
  41655. if (aSourceRoot != null) {
  41656. source = util.relative(aSourceRoot, source);
  41657. }
  41658. var key = util.toSetString(source);
  41659. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  41660. ? this._sourcesContents[key]
  41661. : null;
  41662. }, this);
  41663. };
  41664. /**
  41665. * Externalize the source map.
  41666. */
  41667. SourceMapGenerator.prototype.toJSON =
  41668. function SourceMapGenerator_toJSON() {
  41669. var map = {
  41670. version: this._version,
  41671. sources: this._sources.toArray(),
  41672. names: this._names.toArray(),
  41673. mappings: this._serializeMappings()
  41674. };
  41675. if (this._file != null) {
  41676. map.file = this._file;
  41677. }
  41678. if (this._sourceRoot != null) {
  41679. map.sourceRoot = this._sourceRoot;
  41680. }
  41681. if (this._sourcesContents) {
  41682. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  41683. }
  41684. return map;
  41685. };
  41686. /**
  41687. * Render the source map being generated to a string.
  41688. */
  41689. SourceMapGenerator.prototype.toString =
  41690. function SourceMapGenerator_toString() {
  41691. return JSON.stringify(this.toJSON());
  41692. };
  41693. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
  41694. return sourceMapGenerator;
  41695. }
  41696. var sourceMapConsumer = {};
  41697. var binarySearch = {};
  41698. /* -*- Mode: js; js-indent-level: 2; -*- */
  41699. var hasRequiredBinarySearch;
  41700. function requireBinarySearch () {
  41701. if (hasRequiredBinarySearch) return binarySearch;
  41702. hasRequiredBinarySearch = 1;
  41703. (function (exports$1) {
  41704. /*
  41705. * Copyright 2011 Mozilla Foundation and contributors
  41706. * Licensed under the New BSD license. See LICENSE or:
  41707. * http://opensource.org/licenses/BSD-3-Clause
  41708. */
  41709. exports$1.GREATEST_LOWER_BOUND = 1;
  41710. exports$1.LEAST_UPPER_BOUND = 2;
  41711. /**
  41712. * Recursive implementation of binary search.
  41713. *
  41714. * @param aLow Indices here and lower do not contain the needle.
  41715. * @param aHigh Indices here and higher do not contain the needle.
  41716. * @param aNeedle The element being searched for.
  41717. * @param aHaystack The non-empty array being searched.
  41718. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  41719. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41720. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41721. * closest element that is smaller than or greater than the one we are
  41722. * searching for, respectively, if the exact element cannot be found.
  41723. */
  41724. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  41725. // This function terminates when one of the following is true:
  41726. //
  41727. // 1. We find the exact element we are looking for.
  41728. //
  41729. // 2. We did not find the exact element, but we can return the index of
  41730. // the next-closest element.
  41731. //
  41732. // 3. We did not find the exact element, and there is no next-closest
  41733. // element than the one we are searching for, so we return -1.
  41734. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  41735. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  41736. if (cmp === 0) {
  41737. // Found the element we are looking for.
  41738. return mid;
  41739. }
  41740. else if (cmp > 0) {
  41741. // Our needle is greater than aHaystack[mid].
  41742. if (aHigh - mid > 1) {
  41743. // The element is in the upper half.
  41744. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  41745. }
  41746. // The exact needle element was not found in this haystack. Determine if
  41747. // we are in termination case (3) or (2) and return the appropriate thing.
  41748. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41749. return aHigh < aHaystack.length ? aHigh : -1;
  41750. } else {
  41751. return mid;
  41752. }
  41753. }
  41754. else {
  41755. // Our needle is less than aHaystack[mid].
  41756. if (mid - aLow > 1) {
  41757. // The element is in the lower half.
  41758. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  41759. }
  41760. // we are in termination case (3) or (2) and return the appropriate thing.
  41761. if (aBias == exports$1.LEAST_UPPER_BOUND) {
  41762. return mid;
  41763. } else {
  41764. return aLow < 0 ? -1 : aLow;
  41765. }
  41766. }
  41767. }
  41768. /**
  41769. * This is an implementation of binary search which will always try and return
  41770. * the index of the closest element if there is no exact hit. This is because
  41771. * mappings between original and generated line/col pairs are single points,
  41772. * and there is an implicit region between each of them, so a miss just means
  41773. * that you aren't on the very start of a region.
  41774. *
  41775. * @param aNeedle The element you are looking for.
  41776. * @param aHaystack The array that is being searched.
  41777. * @param aCompare A function which takes the needle and an element in the
  41778. * array and returns -1, 0, or 1 depending on whether the needle is less
  41779. * than, equal to, or greater than the element, respectively.
  41780. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41781. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41782. * closest element that is smaller than or greater than the one we are
  41783. * searching for, respectively, if the exact element cannot be found.
  41784. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  41785. */
  41786. exports$1.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  41787. if (aHaystack.length === 0) {
  41788. return -1;
  41789. }
  41790. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  41791. aCompare, aBias || exports$1.GREATEST_LOWER_BOUND);
  41792. if (index < 0) {
  41793. return -1;
  41794. }
  41795. // We have found either the exact element, or the next-closest element than
  41796. // the one we are searching for. However, there may be more than one such
  41797. // element. Make sure we always return the smallest of these.
  41798. while (index - 1 >= 0) {
  41799. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  41800. break;
  41801. }
  41802. --index;
  41803. }
  41804. return index;
  41805. };
  41806. } (binarySearch));
  41807. return binarySearch;
  41808. }
  41809. var quickSort = {};
  41810. /* -*- Mode: js; js-indent-level: 2; -*- */
  41811. var hasRequiredQuickSort;
  41812. function requireQuickSort () {
  41813. if (hasRequiredQuickSort) return quickSort;
  41814. hasRequiredQuickSort = 1;
  41815. /*
  41816. * Copyright 2011 Mozilla Foundation and contributors
  41817. * Licensed under the New BSD license. See LICENSE or:
  41818. * http://opensource.org/licenses/BSD-3-Clause
  41819. */
  41820. // It turns out that some (most?) JavaScript engines don't self-host
  41821. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  41822. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  41823. // custom comparator function, calling back and forth between the VM's C++ and
  41824. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  41825. // worse generated code for the comparator function than would be optimal. In
  41826. // fact, when sorting with a comparator, these costs outweigh the benefits of
  41827. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  41828. // a ~3500ms mean speed-up in `bench/bench.html`.
  41829. /**
  41830. * Swap the elements indexed by `x` and `y` in the array `ary`.
  41831. *
  41832. * @param {Array} ary
  41833. * The array.
  41834. * @param {Number} x
  41835. * The index of the first item.
  41836. * @param {Number} y
  41837. * The index of the second item.
  41838. */
  41839. function swap(ary, x, y) {
  41840. var temp = ary[x];
  41841. ary[x] = ary[y];
  41842. ary[y] = temp;
  41843. }
  41844. /**
  41845. * Returns a random integer within the range `low .. high` inclusive.
  41846. *
  41847. * @param {Number} low
  41848. * The lower bound on the range.
  41849. * @param {Number} high
  41850. * The upper bound on the range.
  41851. */
  41852. function randomIntInRange(low, high) {
  41853. return Math.round(low + (Math.random() * (high - low)));
  41854. }
  41855. /**
  41856. * The Quick Sort algorithm.
  41857. *
  41858. * @param {Array} ary
  41859. * An array to sort.
  41860. * @param {function} comparator
  41861. * Function to use to compare two items.
  41862. * @param {Number} p
  41863. * Start index of the array
  41864. * @param {Number} r
  41865. * End index of the array
  41866. */
  41867. function doQuickSort(ary, comparator, p, r) {
  41868. // If our lower bound is less than our upper bound, we (1) partition the
  41869. // array into two pieces and (2) recurse on each half. If it is not, this is
  41870. // the empty array and our base case.
  41871. if (p < r) {
  41872. // (1) Partitioning.
  41873. //
  41874. // The partitioning chooses a pivot between `p` and `r` and moves all
  41875. // elements that are less than or equal to the pivot to the before it, and
  41876. // all the elements that are greater than it after it. The effect is that
  41877. // once partition is done, the pivot is in the exact place it will be when
  41878. // the array is put in sorted order, and it will not need to be moved
  41879. // again. This runs in O(n) time.
  41880. // Always choose a random pivot so that an input array which is reverse
  41881. // sorted does not cause O(n^2) running time.
  41882. var pivotIndex = randomIntInRange(p, r);
  41883. var i = p - 1;
  41884. swap(ary, pivotIndex, r);
  41885. var pivot = ary[r];
  41886. // Immediately after `j` is incremented in this loop, the following hold
  41887. // true:
  41888. //
  41889. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  41890. //
  41891. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41892. for (var j = p; j < r; j++) {
  41893. if (comparator(ary[j], pivot) <= 0) {
  41894. i += 1;
  41895. swap(ary, i, j);
  41896. }
  41897. }
  41898. swap(ary, i + 1, j);
  41899. var q = i + 1;
  41900. // (2) Recurse on each half.
  41901. doQuickSort(ary, comparator, p, q - 1);
  41902. doQuickSort(ary, comparator, q + 1, r);
  41903. }
  41904. }
  41905. /**
  41906. * Sort the given array in-place with the given comparator function.
  41907. *
  41908. * @param {Array} ary
  41909. * An array to sort.
  41910. * @param {function} comparator
  41911. * Function to use to compare two items.
  41912. */
  41913. quickSort.quickSort = function (ary, comparator) {
  41914. doQuickSort(ary, comparator, 0, ary.length - 1);
  41915. };
  41916. return quickSort;
  41917. }
  41918. /* -*- Mode: js; js-indent-level: 2; -*- */
  41919. var hasRequiredSourceMapConsumer;
  41920. function requireSourceMapConsumer () {
  41921. if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
  41922. hasRequiredSourceMapConsumer = 1;
  41923. /*
  41924. * Copyright 2011 Mozilla Foundation and contributors
  41925. * Licensed under the New BSD license. See LICENSE or:
  41926. * http://opensource.org/licenses/BSD-3-Clause
  41927. */
  41928. var util = /*@__PURE__*/ requireUtil();
  41929. var binarySearch = /*@__PURE__*/ requireBinarySearch();
  41930. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41931. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41932. var quickSort = /*@__PURE__*/ requireQuickSort().quickSort;
  41933. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  41934. var sourceMap = aSourceMap;
  41935. if (typeof aSourceMap === 'string') {
  41936. sourceMap = util.parseSourceMapInput(aSourceMap);
  41937. }
  41938. return sourceMap.sections != null
  41939. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41940. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41941. }
  41942. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41943. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41944. };
  41945. /**
  41946. * The version of the source mapping spec that we are consuming.
  41947. */
  41948. SourceMapConsumer.prototype._version = 3;
  41949. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41950. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41951. // are lazily instantiated, accessed via the `_generatedMappings` and
  41952. // `_originalMappings` getters respectively, and we only parse the mappings
  41953. // and create these arrays once queried for a source location. We jump through
  41954. // these hoops because there can be many thousands of mappings, and parsing
  41955. // them is expensive, so we only want to do it if we must.
  41956. //
  41957. // Each object in the arrays is of the form:
  41958. //
  41959. // {
  41960. // generatedLine: The line number in the generated code,
  41961. // generatedColumn: The column number in the generated code,
  41962. // source: The path to the original source file that generated this
  41963. // chunk of code,
  41964. // originalLine: The line number in the original source that
  41965. // corresponds to this chunk of generated code,
  41966. // originalColumn: The column number in the original source that
  41967. // corresponds to this chunk of generated code,
  41968. // name: The name of the original symbol which generated this chunk of
  41969. // code.
  41970. // }
  41971. //
  41972. // All properties except for `generatedLine` and `generatedColumn` can be
  41973. // `null`.
  41974. //
  41975. // `_generatedMappings` is ordered by the generated positions.
  41976. //
  41977. // `_originalMappings` is ordered by the original positions.
  41978. SourceMapConsumer.prototype.__generatedMappings = null;
  41979. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  41980. configurable: true,
  41981. enumerable: true,
  41982. get: function () {
  41983. if (!this.__generatedMappings) {
  41984. this._parseMappings(this._mappings, this.sourceRoot);
  41985. }
  41986. return this.__generatedMappings;
  41987. }
  41988. });
  41989. SourceMapConsumer.prototype.__originalMappings = null;
  41990. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  41991. configurable: true,
  41992. enumerable: true,
  41993. get: function () {
  41994. if (!this.__originalMappings) {
  41995. this._parseMappings(this._mappings, this.sourceRoot);
  41996. }
  41997. return this.__originalMappings;
  41998. }
  41999. });
  42000. SourceMapConsumer.prototype._charIsMappingSeparator =
  42001. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  42002. var c = aStr.charAt(index);
  42003. return c === ";" || c === ",";
  42004. };
  42005. /**
  42006. * Parse the mappings in a string in to a data structure which we can easily
  42007. * query (the ordered arrays in the `this.__generatedMappings` and
  42008. * `this.__originalMappings` properties).
  42009. */
  42010. SourceMapConsumer.prototype._parseMappings =
  42011. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42012. throw new Error("Subclasses must implement _parseMappings");
  42013. };
  42014. SourceMapConsumer.GENERATED_ORDER = 1;
  42015. SourceMapConsumer.ORIGINAL_ORDER = 2;
  42016. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  42017. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  42018. /**
  42019. * Iterate over each mapping between an original source/line/column and a
  42020. * generated line/column in this source map.
  42021. *
  42022. * @param Function aCallback
  42023. * The function that is called with each mapping.
  42024. * @param Object aContext
  42025. * Optional. If specified, this object will be the value of `this` every
  42026. * time that `aCallback` is called.
  42027. * @param aOrder
  42028. * Either `SourceMapConsumer.GENERATED_ORDER` or
  42029. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  42030. * iterate over the mappings sorted by the generated file's line/column
  42031. * order or the original's source/line/column order, respectively. Defaults to
  42032. * `SourceMapConsumer.GENERATED_ORDER`.
  42033. */
  42034. SourceMapConsumer.prototype.eachMapping =
  42035. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  42036. var context = aContext || null;
  42037. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  42038. var mappings;
  42039. switch (order) {
  42040. case SourceMapConsumer.GENERATED_ORDER:
  42041. mappings = this._generatedMappings;
  42042. break;
  42043. case SourceMapConsumer.ORIGINAL_ORDER:
  42044. mappings = this._originalMappings;
  42045. break;
  42046. default:
  42047. throw new Error("Unknown order of iteration.");
  42048. }
  42049. var sourceRoot = this.sourceRoot;
  42050. mappings.map(function (mapping) {
  42051. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  42052. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  42053. return {
  42054. source: source,
  42055. generatedLine: mapping.generatedLine,
  42056. generatedColumn: mapping.generatedColumn,
  42057. originalLine: mapping.originalLine,
  42058. originalColumn: mapping.originalColumn,
  42059. name: mapping.name === null ? null : this._names.at(mapping.name)
  42060. };
  42061. }, this).forEach(aCallback, context);
  42062. };
  42063. /**
  42064. * Returns all generated line and column information for the original source,
  42065. * line, and column provided. If no column is provided, returns all mappings
  42066. * corresponding to a either the line we are searching for or the next
  42067. * closest line that has any mappings. Otherwise, returns all mappings
  42068. * corresponding to the given line and either the column we are searching for
  42069. * or the next closest column that has any offsets.
  42070. *
  42071. * The only argument is an object with the following properties:
  42072. *
  42073. * - source: The filename of the original source.
  42074. * - line: The line number in the original source. The line number is 1-based.
  42075. * - column: Optional. the column number in the original source.
  42076. * The column number is 0-based.
  42077. *
  42078. * and an array of objects is returned, each with the following properties:
  42079. *
  42080. * - line: The line number in the generated source, or null. The
  42081. * line number is 1-based.
  42082. * - column: The column number in the generated source, or null.
  42083. * The column number is 0-based.
  42084. */
  42085. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  42086. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  42087. var line = util.getArg(aArgs, 'line');
  42088. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  42089. // returns the index of the closest mapping less than the needle. By
  42090. // setting needle.originalColumn to 0, we thus find the last mapping for
  42091. // the given line, provided such a mapping exists.
  42092. var needle = {
  42093. source: util.getArg(aArgs, 'source'),
  42094. originalLine: line,
  42095. originalColumn: util.getArg(aArgs, 'column', 0)
  42096. };
  42097. needle.source = this._findSourceIndex(needle.source);
  42098. if (needle.source < 0) {
  42099. return [];
  42100. }
  42101. var mappings = [];
  42102. var index = this._findMapping(needle,
  42103. this._originalMappings,
  42104. "originalLine",
  42105. "originalColumn",
  42106. util.compareByOriginalPositions,
  42107. binarySearch.LEAST_UPPER_BOUND);
  42108. if (index >= 0) {
  42109. var mapping = this._originalMappings[index];
  42110. if (aArgs.column === undefined) {
  42111. var originalLine = mapping.originalLine;
  42112. // Iterate until either we run out of mappings, or we run into
  42113. // a mapping for a different line than the one we found. Since
  42114. // mappings are sorted, this is guaranteed to find all mappings for
  42115. // the line we found.
  42116. while (mapping && mapping.originalLine === originalLine) {
  42117. mappings.push({
  42118. line: util.getArg(mapping, 'generatedLine', null),
  42119. column: util.getArg(mapping, 'generatedColumn', null),
  42120. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42121. });
  42122. mapping = this._originalMappings[++index];
  42123. }
  42124. } else {
  42125. var originalColumn = mapping.originalColumn;
  42126. // Iterate until either we run out of mappings, or we run into
  42127. // a mapping for a different line than the one we were searching for.
  42128. // Since mappings are sorted, this is guaranteed to find all mappings for
  42129. // the line we are searching for.
  42130. while (mapping &&
  42131. mapping.originalLine === line &&
  42132. mapping.originalColumn == originalColumn) {
  42133. mappings.push({
  42134. line: util.getArg(mapping, 'generatedLine', null),
  42135. column: util.getArg(mapping, 'generatedColumn', null),
  42136. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42137. });
  42138. mapping = this._originalMappings[++index];
  42139. }
  42140. }
  42141. }
  42142. return mappings;
  42143. };
  42144. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
  42145. /**
  42146. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  42147. * query for information about the original file positions by giving it a file
  42148. * position in the generated source.
  42149. *
  42150. * The first parameter is the raw source map (either as a JSON string, or
  42151. * already parsed to an object). According to the spec, source maps have the
  42152. * following attributes:
  42153. *
  42154. * - version: Which version of the source map spec this map is following.
  42155. * - sources: An array of URLs to the original source files.
  42156. * - names: An array of identifiers which can be referrenced by individual mappings.
  42157. * - sourceRoot: Optional. The URL root from which all sources are relative.
  42158. * - sourcesContent: Optional. An array of contents of the original source files.
  42159. * - mappings: A string of base64 VLQs which contain the actual mappings.
  42160. * - file: Optional. The generated file this source map is associated with.
  42161. *
  42162. * Here is an example source map, taken from the source map spec[0]:
  42163. *
  42164. * {
  42165. * version : 3,
  42166. * file: "out.js",
  42167. * sourceRoot : "",
  42168. * sources: ["foo.js", "bar.js"],
  42169. * names: ["src", "maps", "are", "fun"],
  42170. * mappings: "AA,AB;;ABCDE;"
  42171. * }
  42172. *
  42173. * The second parameter, if given, is a string whose value is the URL
  42174. * at which the source map was found. This URL is used to compute the
  42175. * sources array.
  42176. *
  42177. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  42178. */
  42179. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42180. var sourceMap = aSourceMap;
  42181. if (typeof aSourceMap === 'string') {
  42182. sourceMap = util.parseSourceMapInput(aSourceMap);
  42183. }
  42184. var version = util.getArg(sourceMap, 'version');
  42185. var sources = util.getArg(sourceMap, 'sources');
  42186. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  42187. // requires the array) to play nice here.
  42188. var names = util.getArg(sourceMap, 'names', []);
  42189. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  42190. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  42191. var mappings = util.getArg(sourceMap, 'mappings');
  42192. var file = util.getArg(sourceMap, 'file', null);
  42193. // Once again, Sass deviates from the spec and supplies the version as a
  42194. // string rather than a number, so we use loose equality checking here.
  42195. if (version != this._version) {
  42196. throw new Error('Unsupported version: ' + version);
  42197. }
  42198. if (sourceRoot) {
  42199. sourceRoot = util.normalize(sourceRoot);
  42200. }
  42201. sources = sources
  42202. .map(String)
  42203. // Some source maps produce relative source paths like "./foo.js" instead of
  42204. // "foo.js". Normalize these first so that future comparisons will succeed.
  42205. // See bugzil.la/1090768.
  42206. .map(util.normalize)
  42207. // Always ensure that absolute sources are internally stored relative to
  42208. // the source root, if the source root is absolute. Not doing this would
  42209. // be particularly problematic when the source root is a prefix of the
  42210. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  42211. .map(function (source) {
  42212. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  42213. ? util.relative(sourceRoot, source)
  42214. : source;
  42215. });
  42216. // Pass `true` below to allow duplicate names and sources. While source maps
  42217. // are intended to be compressed and deduplicated, the TypeScript compiler
  42218. // sometimes generates source maps with duplicates in them. See Github issue
  42219. // #72 and bugzil.la/889492.
  42220. this._names = ArraySet.fromArray(names.map(String), true);
  42221. this._sources = ArraySet.fromArray(sources, true);
  42222. this._absoluteSources = this._sources.toArray().map(function (s) {
  42223. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  42224. });
  42225. this.sourceRoot = sourceRoot;
  42226. this.sourcesContent = sourcesContent;
  42227. this._mappings = mappings;
  42228. this._sourceMapURL = aSourceMapURL;
  42229. this.file = file;
  42230. }
  42231. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42232. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  42233. /**
  42234. * Utility function to find the index of a source. Returns -1 if not
  42235. * found.
  42236. */
  42237. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  42238. var relativeSource = aSource;
  42239. if (this.sourceRoot != null) {
  42240. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42241. }
  42242. if (this._sources.has(relativeSource)) {
  42243. return this._sources.indexOf(relativeSource);
  42244. }
  42245. // Maybe aSource is an absolute URL as returned by |sources|. In
  42246. // this case we can't simply undo the transform.
  42247. var i;
  42248. for (i = 0; i < this._absoluteSources.length; ++i) {
  42249. if (this._absoluteSources[i] == aSource) {
  42250. return i;
  42251. }
  42252. }
  42253. return -1;
  42254. };
  42255. /**
  42256. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  42257. *
  42258. * @param SourceMapGenerator aSourceMap
  42259. * The source map that will be consumed.
  42260. * @param String aSourceMapURL
  42261. * The URL at which the source map can be found (optional)
  42262. * @returns BasicSourceMapConsumer
  42263. */
  42264. BasicSourceMapConsumer.fromSourceMap =
  42265. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  42266. var smc = Object.create(BasicSourceMapConsumer.prototype);
  42267. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  42268. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  42269. smc.sourceRoot = aSourceMap._sourceRoot;
  42270. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  42271. smc.sourceRoot);
  42272. smc.file = aSourceMap._file;
  42273. smc._sourceMapURL = aSourceMapURL;
  42274. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  42275. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  42276. });
  42277. // Because we are modifying the entries (by converting string sources and
  42278. // names to indices into the sources and names ArraySets), we have to make
  42279. // a copy of the entry or else bad things happen. Shared mutable state
  42280. // strikes again! See github issue #191.
  42281. var generatedMappings = aSourceMap._mappings.toArray().slice();
  42282. var destGeneratedMappings = smc.__generatedMappings = [];
  42283. var destOriginalMappings = smc.__originalMappings = [];
  42284. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  42285. var srcMapping = generatedMappings[i];
  42286. var destMapping = new Mapping;
  42287. destMapping.generatedLine = srcMapping.generatedLine;
  42288. destMapping.generatedColumn = srcMapping.generatedColumn;
  42289. if (srcMapping.source) {
  42290. destMapping.source = sources.indexOf(srcMapping.source);
  42291. destMapping.originalLine = srcMapping.originalLine;
  42292. destMapping.originalColumn = srcMapping.originalColumn;
  42293. if (srcMapping.name) {
  42294. destMapping.name = names.indexOf(srcMapping.name);
  42295. }
  42296. destOriginalMappings.push(destMapping);
  42297. }
  42298. destGeneratedMappings.push(destMapping);
  42299. }
  42300. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  42301. return smc;
  42302. };
  42303. /**
  42304. * The version of the source mapping spec that we are consuming.
  42305. */
  42306. BasicSourceMapConsumer.prototype._version = 3;
  42307. /**
  42308. * The list of original sources.
  42309. */
  42310. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  42311. get: function () {
  42312. return this._absoluteSources.slice();
  42313. }
  42314. });
  42315. /**
  42316. * Provide the JIT with a nice shape / hidden class.
  42317. */
  42318. function Mapping() {
  42319. this.generatedLine = 0;
  42320. this.generatedColumn = 0;
  42321. this.source = null;
  42322. this.originalLine = null;
  42323. this.originalColumn = null;
  42324. this.name = null;
  42325. }
  42326. /**
  42327. * Parse the mappings in a string in to a data structure which we can easily
  42328. * query (the ordered arrays in the `this.__generatedMappings` and
  42329. * `this.__originalMappings` properties).
  42330. */
  42331. BasicSourceMapConsumer.prototype._parseMappings =
  42332. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42333. var generatedLine = 1;
  42334. var previousGeneratedColumn = 0;
  42335. var previousOriginalLine = 0;
  42336. var previousOriginalColumn = 0;
  42337. var previousSource = 0;
  42338. var previousName = 0;
  42339. var length = aStr.length;
  42340. var index = 0;
  42341. var cachedSegments = {};
  42342. var temp = {};
  42343. var originalMappings = [];
  42344. var generatedMappings = [];
  42345. var mapping, str, segment, end, value;
  42346. while (index < length) {
  42347. if (aStr.charAt(index) === ';') {
  42348. generatedLine++;
  42349. index++;
  42350. previousGeneratedColumn = 0;
  42351. }
  42352. else if (aStr.charAt(index) === ',') {
  42353. index++;
  42354. }
  42355. else {
  42356. mapping = new Mapping();
  42357. mapping.generatedLine = generatedLine;
  42358. // Because each offset is encoded relative to the previous one,
  42359. // many segments often have the same encoding. We can exploit this
  42360. // fact by caching the parsed variable length fields of each segment,
  42361. // allowing us to avoid a second parse if we encounter the same
  42362. // segment again.
  42363. for (end = index; end < length; end++) {
  42364. if (this._charIsMappingSeparator(aStr, end)) {
  42365. break;
  42366. }
  42367. }
  42368. str = aStr.slice(index, end);
  42369. segment = cachedSegments[str];
  42370. if (segment) {
  42371. index += str.length;
  42372. } else {
  42373. segment = [];
  42374. while (index < end) {
  42375. base64VLQ.decode(aStr, index, temp);
  42376. value = temp.value;
  42377. index = temp.rest;
  42378. segment.push(value);
  42379. }
  42380. if (segment.length === 2) {
  42381. throw new Error('Found a source, but no line and column');
  42382. }
  42383. if (segment.length === 3) {
  42384. throw new Error('Found a source and line, but no column');
  42385. }
  42386. cachedSegments[str] = segment;
  42387. }
  42388. // Generated column.
  42389. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  42390. previousGeneratedColumn = mapping.generatedColumn;
  42391. if (segment.length > 1) {
  42392. // Original source.
  42393. mapping.source = previousSource + segment[1];
  42394. previousSource += segment[1];
  42395. // Original line.
  42396. mapping.originalLine = previousOriginalLine + segment[2];
  42397. previousOriginalLine = mapping.originalLine;
  42398. // Lines are stored 0-based
  42399. mapping.originalLine += 1;
  42400. // Original column.
  42401. mapping.originalColumn = previousOriginalColumn + segment[3];
  42402. previousOriginalColumn = mapping.originalColumn;
  42403. if (segment.length > 4) {
  42404. // Original name.
  42405. mapping.name = previousName + segment[4];
  42406. previousName += segment[4];
  42407. }
  42408. }
  42409. generatedMappings.push(mapping);
  42410. if (typeof mapping.originalLine === 'number') {
  42411. originalMappings.push(mapping);
  42412. }
  42413. }
  42414. }
  42415. quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
  42416. this.__generatedMappings = generatedMappings;
  42417. quickSort(originalMappings, util.compareByOriginalPositions);
  42418. this.__originalMappings = originalMappings;
  42419. };
  42420. /**
  42421. * Find the mapping that best matches the hypothetical "needle" mapping that
  42422. * we are searching for in the given "haystack" of mappings.
  42423. */
  42424. BasicSourceMapConsumer.prototype._findMapping =
  42425. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  42426. aColumnName, aComparator, aBias) {
  42427. // To return the position we are searching for, we must first find the
  42428. // mapping for the given position and then return the opposite position it
  42429. // points to. Because the mappings are sorted, we can use binary search to
  42430. // find the best mapping.
  42431. if (aNeedle[aLineName] <= 0) {
  42432. throw new TypeError('Line must be greater than or equal to 1, got '
  42433. + aNeedle[aLineName]);
  42434. }
  42435. if (aNeedle[aColumnName] < 0) {
  42436. throw new TypeError('Column must be greater than or equal to 0, got '
  42437. + aNeedle[aColumnName]);
  42438. }
  42439. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  42440. };
  42441. /**
  42442. * Compute the last column for each generated mapping. The last column is
  42443. * inclusive.
  42444. */
  42445. BasicSourceMapConsumer.prototype.computeColumnSpans =
  42446. function SourceMapConsumer_computeColumnSpans() {
  42447. for (var index = 0; index < this._generatedMappings.length; ++index) {
  42448. var mapping = this._generatedMappings[index];
  42449. // Mappings do not contain a field for the last generated columnt. We
  42450. // can come up with an optimistic estimate, however, by assuming that
  42451. // mappings are contiguous (i.e. given two consecutive mappings, the
  42452. // first mapping ends where the second one starts).
  42453. if (index + 1 < this._generatedMappings.length) {
  42454. var nextMapping = this._generatedMappings[index + 1];
  42455. if (mapping.generatedLine === nextMapping.generatedLine) {
  42456. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  42457. continue;
  42458. }
  42459. }
  42460. // The last mapping for each line spans the entire line.
  42461. mapping.lastGeneratedColumn = Infinity;
  42462. }
  42463. };
  42464. /**
  42465. * Returns the original source, line, and column information for the generated
  42466. * source's line and column positions provided. The only argument is an object
  42467. * with the following properties:
  42468. *
  42469. * - line: The line number in the generated source. The line number
  42470. * is 1-based.
  42471. * - column: The column number in the generated source. The column
  42472. * number is 0-based.
  42473. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42474. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42475. * closest element that is smaller than or greater than the one we are
  42476. * searching for, respectively, if the exact element cannot be found.
  42477. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42478. *
  42479. * and an object is returned with the following properties:
  42480. *
  42481. * - source: The original source file, or null.
  42482. * - line: The line number in the original source, or null. The
  42483. * line number is 1-based.
  42484. * - column: The column number in the original source, or null. The
  42485. * column number is 0-based.
  42486. * - name: The original identifier, or null.
  42487. */
  42488. BasicSourceMapConsumer.prototype.originalPositionFor =
  42489. function SourceMapConsumer_originalPositionFor(aArgs) {
  42490. var needle = {
  42491. generatedLine: util.getArg(aArgs, 'line'),
  42492. generatedColumn: util.getArg(aArgs, 'column')
  42493. };
  42494. var index = this._findMapping(
  42495. needle,
  42496. this._generatedMappings,
  42497. "generatedLine",
  42498. "generatedColumn",
  42499. util.compareByGeneratedPositionsDeflated,
  42500. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42501. );
  42502. if (index >= 0) {
  42503. var mapping = this._generatedMappings[index];
  42504. if (mapping.generatedLine === needle.generatedLine) {
  42505. var source = util.getArg(mapping, 'source', null);
  42506. if (source !== null) {
  42507. source = this._sources.at(source);
  42508. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  42509. }
  42510. var name = util.getArg(mapping, 'name', null);
  42511. if (name !== null) {
  42512. name = this._names.at(name);
  42513. }
  42514. return {
  42515. source: source,
  42516. line: util.getArg(mapping, 'originalLine', null),
  42517. column: util.getArg(mapping, 'originalColumn', null),
  42518. name: name
  42519. };
  42520. }
  42521. }
  42522. return {
  42523. source: null,
  42524. line: null,
  42525. column: null,
  42526. name: null
  42527. };
  42528. };
  42529. /**
  42530. * Return true if we have the source content for every source in the source
  42531. * map, false otherwise.
  42532. */
  42533. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  42534. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  42535. if (!this.sourcesContent) {
  42536. return false;
  42537. }
  42538. return this.sourcesContent.length >= this._sources.size() &&
  42539. !this.sourcesContent.some(function (sc) { return sc == null; });
  42540. };
  42541. /**
  42542. * Returns the original source content. The only argument is the url of the
  42543. * original source file. Returns null if no original source content is
  42544. * available.
  42545. */
  42546. BasicSourceMapConsumer.prototype.sourceContentFor =
  42547. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42548. if (!this.sourcesContent) {
  42549. return null;
  42550. }
  42551. var index = this._findSourceIndex(aSource);
  42552. if (index >= 0) {
  42553. return this.sourcesContent[index];
  42554. }
  42555. var relativeSource = aSource;
  42556. if (this.sourceRoot != null) {
  42557. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42558. }
  42559. var url;
  42560. if (this.sourceRoot != null
  42561. && (url = util.urlParse(this.sourceRoot))) {
  42562. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  42563. // many users. We can help them out when they expect file:// URIs to
  42564. // behave like it would if they were running a local HTTP server. See
  42565. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  42566. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  42567. if (url.scheme == "file"
  42568. && this._sources.has(fileUriAbsPath)) {
  42569. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  42570. }
  42571. if ((!url.path || url.path == "/")
  42572. && this._sources.has("/" + relativeSource)) {
  42573. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  42574. }
  42575. }
  42576. // This function is used recursively from
  42577. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  42578. // don't want to throw if we can't find the source - we just want to
  42579. // return null, so we provide a flag to exit gracefully.
  42580. if (nullOnMissing) {
  42581. return null;
  42582. }
  42583. else {
  42584. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  42585. }
  42586. };
  42587. /**
  42588. * Returns the generated line and column information for the original source,
  42589. * line, and column positions provided. The only argument is an object with
  42590. * the following properties:
  42591. *
  42592. * - source: The filename of the original source.
  42593. * - line: The line number in the original source. The line number
  42594. * is 1-based.
  42595. * - column: The column number in the original source. The column
  42596. * number is 0-based.
  42597. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42598. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42599. * closest element that is smaller than or greater than the one we are
  42600. * searching for, respectively, if the exact element cannot be found.
  42601. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42602. *
  42603. * and an object is returned with the following properties:
  42604. *
  42605. * - line: The line number in the generated source, or null. The
  42606. * line number is 1-based.
  42607. * - column: The column number in the generated source, or null.
  42608. * The column number is 0-based.
  42609. */
  42610. BasicSourceMapConsumer.prototype.generatedPositionFor =
  42611. function SourceMapConsumer_generatedPositionFor(aArgs) {
  42612. var source = util.getArg(aArgs, 'source');
  42613. source = this._findSourceIndex(source);
  42614. if (source < 0) {
  42615. return {
  42616. line: null,
  42617. column: null,
  42618. lastColumn: null
  42619. };
  42620. }
  42621. var needle = {
  42622. source: source,
  42623. originalLine: util.getArg(aArgs, 'line'),
  42624. originalColumn: util.getArg(aArgs, 'column')
  42625. };
  42626. var index = this._findMapping(
  42627. needle,
  42628. this._originalMappings,
  42629. "originalLine",
  42630. "originalColumn",
  42631. util.compareByOriginalPositions,
  42632. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42633. );
  42634. if (index >= 0) {
  42635. var mapping = this._originalMappings[index];
  42636. if (mapping.source === needle.source) {
  42637. return {
  42638. line: util.getArg(mapping, 'generatedLine', null),
  42639. column: util.getArg(mapping, 'generatedColumn', null),
  42640. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42641. };
  42642. }
  42643. }
  42644. return {
  42645. line: null,
  42646. column: null,
  42647. lastColumn: null
  42648. };
  42649. };
  42650. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  42651. /**
  42652. * An IndexedSourceMapConsumer instance represents a parsed source map which
  42653. * we can query for information. It differs from BasicSourceMapConsumer in
  42654. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  42655. * input.
  42656. *
  42657. * The first parameter is a raw source map (either as a JSON string, or already
  42658. * parsed to an object). According to the spec for indexed source maps, they
  42659. * have the following attributes:
  42660. *
  42661. * - version: Which version of the source map spec this map is following.
  42662. * - file: Optional. The generated file this source map is associated with.
  42663. * - sections: A list of section definitions.
  42664. *
  42665. * Each value under the "sections" field has two fields:
  42666. * - offset: The offset into the original specified at which this section
  42667. * begins to apply, defined as an object with a "line" and "column"
  42668. * field.
  42669. * - map: A source map definition. This source map could also be indexed,
  42670. * but doesn't have to be.
  42671. *
  42672. * Instead of the "map" field, it's also possible to have a "url" field
  42673. * specifying a URL to retrieve a source map from, but that's currently
  42674. * unsupported.
  42675. *
  42676. * Here's an example source map, taken from the source map spec[0], but
  42677. * modified to omit a section which uses the "url" field.
  42678. *
  42679. * {
  42680. * version : 3,
  42681. * file: "app.js",
  42682. * sections: [{
  42683. * offset: {line:100, column:10},
  42684. * map: {
  42685. * version : 3,
  42686. * file: "section.js",
  42687. * sources: ["foo.js", "bar.js"],
  42688. * names: ["src", "maps", "are", "fun"],
  42689. * mappings: "AAAA,E;;ABCDE;"
  42690. * }
  42691. * }],
  42692. * }
  42693. *
  42694. * The second parameter, if given, is a string whose value is the URL
  42695. * at which the source map was found. This URL is used to compute the
  42696. * sources array.
  42697. *
  42698. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  42699. */
  42700. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42701. var sourceMap = aSourceMap;
  42702. if (typeof aSourceMap === 'string') {
  42703. sourceMap = util.parseSourceMapInput(aSourceMap);
  42704. }
  42705. var version = util.getArg(sourceMap, 'version');
  42706. var sections = util.getArg(sourceMap, 'sections');
  42707. if (version != this._version) {
  42708. throw new Error('Unsupported version: ' + version);
  42709. }
  42710. this._sources = new ArraySet();
  42711. this._names = new ArraySet();
  42712. var lastOffset = {
  42713. line: -1,
  42714. column: 0
  42715. };
  42716. this._sections = sections.map(function (s) {
  42717. if (s.url) {
  42718. // The url field will require support for asynchronicity.
  42719. // See https://github.com/mozilla/source-map/issues/16
  42720. throw new Error('Support for url field in sections not implemented.');
  42721. }
  42722. var offset = util.getArg(s, 'offset');
  42723. var offsetLine = util.getArg(offset, 'line');
  42724. var offsetColumn = util.getArg(offset, 'column');
  42725. if (offsetLine < lastOffset.line ||
  42726. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  42727. throw new Error('Section offsets must be ordered and non-overlapping.');
  42728. }
  42729. lastOffset = offset;
  42730. return {
  42731. generatedOffset: {
  42732. // The offset fields are 0-based, but we use 1-based indices when
  42733. // encoding/decoding from VLQ.
  42734. generatedLine: offsetLine + 1,
  42735. generatedColumn: offsetColumn + 1
  42736. },
  42737. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  42738. }
  42739. });
  42740. }
  42741. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42742. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  42743. /**
  42744. * The version of the source mapping spec that we are consuming.
  42745. */
  42746. IndexedSourceMapConsumer.prototype._version = 3;
  42747. /**
  42748. * The list of original sources.
  42749. */
  42750. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  42751. get: function () {
  42752. var sources = [];
  42753. for (var i = 0; i < this._sections.length; i++) {
  42754. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  42755. sources.push(this._sections[i].consumer.sources[j]);
  42756. }
  42757. }
  42758. return sources;
  42759. }
  42760. });
  42761. /**
  42762. * Returns the original source, line, and column information for the generated
  42763. * source's line and column positions provided. The only argument is an object
  42764. * with the following properties:
  42765. *
  42766. * - line: The line number in the generated source. The line number
  42767. * is 1-based.
  42768. * - column: The column number in the generated source. The column
  42769. * number is 0-based.
  42770. *
  42771. * and an object is returned with the following properties:
  42772. *
  42773. * - source: The original source file, or null.
  42774. * - line: The line number in the original source, or null. The
  42775. * line number is 1-based.
  42776. * - column: The column number in the original source, or null. The
  42777. * column number is 0-based.
  42778. * - name: The original identifier, or null.
  42779. */
  42780. IndexedSourceMapConsumer.prototype.originalPositionFor =
  42781. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  42782. var needle = {
  42783. generatedLine: util.getArg(aArgs, 'line'),
  42784. generatedColumn: util.getArg(aArgs, 'column')
  42785. };
  42786. // Find the section containing the generated position we're trying to map
  42787. // to an original position.
  42788. var sectionIndex = binarySearch.search(needle, this._sections,
  42789. function(needle, section) {
  42790. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  42791. if (cmp) {
  42792. return cmp;
  42793. }
  42794. return (needle.generatedColumn -
  42795. section.generatedOffset.generatedColumn);
  42796. });
  42797. var section = this._sections[sectionIndex];
  42798. if (!section) {
  42799. return {
  42800. source: null,
  42801. line: null,
  42802. column: null,
  42803. name: null
  42804. };
  42805. }
  42806. return section.consumer.originalPositionFor({
  42807. line: needle.generatedLine -
  42808. (section.generatedOffset.generatedLine - 1),
  42809. column: needle.generatedColumn -
  42810. (section.generatedOffset.generatedLine === needle.generatedLine
  42811. ? section.generatedOffset.generatedColumn - 1
  42812. : 0),
  42813. bias: aArgs.bias
  42814. });
  42815. };
  42816. /**
  42817. * Return true if we have the source content for every source in the source
  42818. * map, false otherwise.
  42819. */
  42820. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  42821. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  42822. return this._sections.every(function (s) {
  42823. return s.consumer.hasContentsOfAllSources();
  42824. });
  42825. };
  42826. /**
  42827. * Returns the original source content. The only argument is the url of the
  42828. * original source file. Returns null if no original source content is
  42829. * available.
  42830. */
  42831. IndexedSourceMapConsumer.prototype.sourceContentFor =
  42832. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42833. for (var i = 0; i < this._sections.length; i++) {
  42834. var section = this._sections[i];
  42835. var content = section.consumer.sourceContentFor(aSource, true);
  42836. if (content) {
  42837. return content;
  42838. }
  42839. }
  42840. if (nullOnMissing) {
  42841. return null;
  42842. }
  42843. else {
  42844. throw new Error('"' + aSource + '" is not in the SourceMap.');
  42845. }
  42846. };
  42847. /**
  42848. * Returns the generated line and column information for the original source,
  42849. * line, and column positions provided. The only argument is an object with
  42850. * the following properties:
  42851. *
  42852. * - source: The filename of the original source.
  42853. * - line: The line number in the original source. The line number
  42854. * is 1-based.
  42855. * - column: The column number in the original source. The column
  42856. * number is 0-based.
  42857. *
  42858. * and an object is returned with the following properties:
  42859. *
  42860. * - line: The line number in the generated source, or null. The
  42861. * line number is 1-based.
  42862. * - column: The column number in the generated source, or null.
  42863. * The column number is 0-based.
  42864. */
  42865. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  42866. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  42867. for (var i = 0; i < this._sections.length; i++) {
  42868. var section = this._sections[i];
  42869. // Only consider this section if the requested source is in the list of
  42870. // sources of the consumer.
  42871. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  42872. continue;
  42873. }
  42874. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  42875. if (generatedPosition) {
  42876. var ret = {
  42877. line: generatedPosition.line +
  42878. (section.generatedOffset.generatedLine - 1),
  42879. column: generatedPosition.column +
  42880. (section.generatedOffset.generatedLine === generatedPosition.line
  42881. ? section.generatedOffset.generatedColumn - 1
  42882. : 0)
  42883. };
  42884. return ret;
  42885. }
  42886. }
  42887. return {
  42888. line: null,
  42889. column: null
  42890. };
  42891. };
  42892. /**
  42893. * Parse the mappings in a string in to a data structure which we can easily
  42894. * query (the ordered arrays in the `this.__generatedMappings` and
  42895. * `this.__originalMappings` properties).
  42896. */
  42897. IndexedSourceMapConsumer.prototype._parseMappings =
  42898. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42899. this.__generatedMappings = [];
  42900. this.__originalMappings = [];
  42901. for (var i = 0; i < this._sections.length; i++) {
  42902. var section = this._sections[i];
  42903. var sectionMappings = section.consumer._generatedMappings;
  42904. for (var j = 0; j < sectionMappings.length; j++) {
  42905. var mapping = sectionMappings[j];
  42906. var source = section.consumer._sources.at(mapping.source);
  42907. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42908. this._sources.add(source);
  42909. source = this._sources.indexOf(source);
  42910. var name = null;
  42911. if (mapping.name) {
  42912. name = section.consumer._names.at(mapping.name);
  42913. this._names.add(name);
  42914. name = this._names.indexOf(name);
  42915. }
  42916. // The mappings coming from the consumer for the section have
  42917. // generated positions relative to the start of the section, so we
  42918. // need to offset them to be relative to the start of the concatenated
  42919. // generated file.
  42920. var adjustedMapping = {
  42921. source: source,
  42922. generatedLine: mapping.generatedLine +
  42923. (section.generatedOffset.generatedLine - 1),
  42924. generatedColumn: mapping.generatedColumn +
  42925. (section.generatedOffset.generatedLine === mapping.generatedLine
  42926. ? section.generatedOffset.generatedColumn - 1
  42927. : 0),
  42928. originalLine: mapping.originalLine,
  42929. originalColumn: mapping.originalColumn,
  42930. name: name
  42931. };
  42932. this.__generatedMappings.push(adjustedMapping);
  42933. if (typeof adjustedMapping.originalLine === 'number') {
  42934. this.__originalMappings.push(adjustedMapping);
  42935. }
  42936. }
  42937. }
  42938. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  42939. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  42940. };
  42941. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42942. return sourceMapConsumer;
  42943. }
  42944. var sourceNode = {};
  42945. /* -*- Mode: js; js-indent-level: 2; -*- */
  42946. var hasRequiredSourceNode;
  42947. function requireSourceNode () {
  42948. if (hasRequiredSourceNode) return sourceNode;
  42949. hasRequiredSourceNode = 1;
  42950. /*
  42951. * Copyright 2011 Mozilla Foundation and contributors
  42952. * Licensed under the New BSD license. See LICENSE or:
  42953. * http://opensource.org/licenses/BSD-3-Clause
  42954. */
  42955. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  42956. var util = /*@__PURE__*/ requireUtil();
  42957. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42958. // operating systems these days (capturing the result).
  42959. var REGEX_NEWLINE = /(\r?\n)/;
  42960. // Newline character code for charCodeAt() comparisons
  42961. var NEWLINE_CODE = 10;
  42962. // Private symbol for identifying `SourceNode`s when multiple versions of
  42963. // the source-map library are loaded. This MUST NOT CHANGE across
  42964. // versions!
  42965. var isSourceNode = "$$$isSourceNode$$$";
  42966. /**
  42967. * SourceNodes provide a way to abstract over interpolating/concatenating
  42968. * snippets of generated JavaScript source code while maintaining the line and
  42969. * column information associated with the original source code.
  42970. *
  42971. * @param aLine The original line number.
  42972. * @param aColumn The original column number.
  42973. * @param aSource The original source's filename.
  42974. * @param aChunks Optional. An array of strings which are snippets of
  42975. * generated JS, or other SourceNodes.
  42976. * @param aName The original identifier.
  42977. */
  42978. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42979. this.children = [];
  42980. this.sourceContents = {};
  42981. this.line = aLine == null ? null : aLine;
  42982. this.column = aColumn == null ? null : aColumn;
  42983. this.source = aSource == null ? null : aSource;
  42984. this.name = aName == null ? null : aName;
  42985. this[isSourceNode] = true;
  42986. if (aChunks != null) this.add(aChunks);
  42987. }
  42988. /**
  42989. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42990. *
  42991. * @param aGeneratedCode The generated code
  42992. * @param aSourceMapConsumer The SourceMap for the generated code
  42993. * @param aRelativePath Optional. The path that relative sources in the
  42994. * SourceMapConsumer should be relative to.
  42995. */
  42996. SourceNode.fromStringWithSourceMap =
  42997. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42998. // The SourceNode we want to fill with the generated code
  42999. // and the SourceMap
  43000. var node = new SourceNode();
  43001. // All even indices of this array are one line of the generated code,
  43002. // while all odd indices are the newlines between two adjacent lines
  43003. // (since `REGEX_NEWLINE` captures its match).
  43004. // Processed fragments are accessed by calling `shiftNextLine`.
  43005. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  43006. var remainingLinesIndex = 0;
  43007. var shiftNextLine = function() {
  43008. var lineContents = getNextLine();
  43009. // The last line of a file might not have a newline.
  43010. var newLine = getNextLine() || "";
  43011. return lineContents + newLine;
  43012. function getNextLine() {
  43013. return remainingLinesIndex < remainingLines.length ?
  43014. remainingLines[remainingLinesIndex++] : undefined;
  43015. }
  43016. };
  43017. // We need to remember the position of "remainingLines"
  43018. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  43019. // The generate SourceNodes we need a code range.
  43020. // To extract it current and last mapping is used.
  43021. // Here we store the last mapping.
  43022. var lastMapping = null;
  43023. aSourceMapConsumer.eachMapping(function (mapping) {
  43024. if (lastMapping !== null) {
  43025. // We add the code from "lastMapping" to "mapping":
  43026. // First check if there is a new line in between.
  43027. if (lastGeneratedLine < mapping.generatedLine) {
  43028. // Associate first line with "lastMapping"
  43029. addMappingWithCode(lastMapping, shiftNextLine());
  43030. lastGeneratedLine++;
  43031. lastGeneratedColumn = 0;
  43032. // The remaining code is added without mapping
  43033. } else {
  43034. // There is no new line in between.
  43035. // Associate the code between "lastGeneratedColumn" and
  43036. // "mapping.generatedColumn" with "lastMapping"
  43037. var nextLine = remainingLines[remainingLinesIndex] || '';
  43038. var code = nextLine.substr(0, mapping.generatedColumn -
  43039. lastGeneratedColumn);
  43040. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  43041. lastGeneratedColumn);
  43042. lastGeneratedColumn = mapping.generatedColumn;
  43043. addMappingWithCode(lastMapping, code);
  43044. // No more remaining code, continue
  43045. lastMapping = mapping;
  43046. return;
  43047. }
  43048. }
  43049. // We add the generated code until the first mapping
  43050. // to the SourceNode without any mapping.
  43051. // Each line is added as separate string.
  43052. while (lastGeneratedLine < mapping.generatedLine) {
  43053. node.add(shiftNextLine());
  43054. lastGeneratedLine++;
  43055. }
  43056. if (lastGeneratedColumn < mapping.generatedColumn) {
  43057. var nextLine = remainingLines[remainingLinesIndex] || '';
  43058. node.add(nextLine.substr(0, mapping.generatedColumn));
  43059. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  43060. lastGeneratedColumn = mapping.generatedColumn;
  43061. }
  43062. lastMapping = mapping;
  43063. }, this);
  43064. // We have processed all mappings.
  43065. if (remainingLinesIndex < remainingLines.length) {
  43066. if (lastMapping) {
  43067. // Associate the remaining code in the current line with "lastMapping"
  43068. addMappingWithCode(lastMapping, shiftNextLine());
  43069. }
  43070. // and add the remaining lines without any mapping
  43071. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  43072. }
  43073. // Copy sourcesContent into SourceNode
  43074. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  43075. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  43076. if (content != null) {
  43077. if (aRelativePath != null) {
  43078. sourceFile = util.join(aRelativePath, sourceFile);
  43079. }
  43080. node.setSourceContent(sourceFile, content);
  43081. }
  43082. });
  43083. return node;
  43084. function addMappingWithCode(mapping, code) {
  43085. if (mapping === null || mapping.source === undefined) {
  43086. node.add(code);
  43087. } else {
  43088. var source = aRelativePath
  43089. ? util.join(aRelativePath, mapping.source)
  43090. : mapping.source;
  43091. node.add(new SourceNode(mapping.originalLine,
  43092. mapping.originalColumn,
  43093. source,
  43094. code,
  43095. mapping.name));
  43096. }
  43097. }
  43098. };
  43099. /**
  43100. * Add a chunk of generated JS to this source node.
  43101. *
  43102. * @param aChunk A string snippet of generated JS code, another instance of
  43103. * SourceNode, or an array where each member is one of those things.
  43104. */
  43105. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  43106. if (Array.isArray(aChunk)) {
  43107. aChunk.forEach(function (chunk) {
  43108. this.add(chunk);
  43109. }, this);
  43110. }
  43111. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43112. if (aChunk) {
  43113. this.children.push(aChunk);
  43114. }
  43115. }
  43116. else {
  43117. throw new TypeError(
  43118. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43119. );
  43120. }
  43121. return this;
  43122. };
  43123. /**
  43124. * Add a chunk of generated JS to the beginning of this source node.
  43125. *
  43126. * @param aChunk A string snippet of generated JS code, another instance of
  43127. * SourceNode, or an array where each member is one of those things.
  43128. */
  43129. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  43130. if (Array.isArray(aChunk)) {
  43131. for (var i = aChunk.length-1; i >= 0; i--) {
  43132. this.prepend(aChunk[i]);
  43133. }
  43134. }
  43135. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  43136. this.children.unshift(aChunk);
  43137. }
  43138. else {
  43139. throw new TypeError(
  43140. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  43141. );
  43142. }
  43143. return this;
  43144. };
  43145. /**
  43146. * Walk over the tree of JS snippets in this node and its children. The
  43147. * walking function is called once for each snippet of JS and is passed that
  43148. * snippet and the its original associated source's line/column location.
  43149. *
  43150. * @param aFn The traversal function.
  43151. */
  43152. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  43153. var chunk;
  43154. for (var i = 0, len = this.children.length; i < len; i++) {
  43155. chunk = this.children[i];
  43156. if (chunk[isSourceNode]) {
  43157. chunk.walk(aFn);
  43158. }
  43159. else {
  43160. if (chunk !== '') {
  43161. aFn(chunk, { source: this.source,
  43162. line: this.line,
  43163. column: this.column,
  43164. name: this.name });
  43165. }
  43166. }
  43167. }
  43168. };
  43169. /**
  43170. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  43171. * each of `this.children`.
  43172. *
  43173. * @param aSep The separator.
  43174. */
  43175. SourceNode.prototype.join = function SourceNode_join(aSep) {
  43176. var newChildren;
  43177. var i;
  43178. var len = this.children.length;
  43179. if (len > 0) {
  43180. newChildren = [];
  43181. for (i = 0; i < len-1; i++) {
  43182. newChildren.push(this.children[i]);
  43183. newChildren.push(aSep);
  43184. }
  43185. newChildren.push(this.children[i]);
  43186. this.children = newChildren;
  43187. }
  43188. return this;
  43189. };
  43190. /**
  43191. * Call String.prototype.replace on the very right-most source snippet. Useful
  43192. * for trimming whitespace from the end of a source node, etc.
  43193. *
  43194. * @param aPattern The pattern to replace.
  43195. * @param aReplacement The thing to replace the pattern with.
  43196. */
  43197. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  43198. var lastChild = this.children[this.children.length - 1];
  43199. if (lastChild[isSourceNode]) {
  43200. lastChild.replaceRight(aPattern, aReplacement);
  43201. }
  43202. else if (typeof lastChild === 'string') {
  43203. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  43204. }
  43205. else {
  43206. this.children.push(''.replace(aPattern, aReplacement));
  43207. }
  43208. return this;
  43209. };
  43210. /**
  43211. * Set the source content for a source file. This will be added to the SourceMapGenerator
  43212. * in the sourcesContent field.
  43213. *
  43214. * @param aSourceFile The filename of the source file
  43215. * @param aSourceContent The content of the source file
  43216. */
  43217. SourceNode.prototype.setSourceContent =
  43218. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  43219. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  43220. };
  43221. /**
  43222. * Walk over the tree of SourceNodes. The walking function is called for each
  43223. * source file content and is passed the filename and source content.
  43224. *
  43225. * @param aFn The traversal function.
  43226. */
  43227. SourceNode.prototype.walkSourceContents =
  43228. function SourceNode_walkSourceContents(aFn) {
  43229. for (var i = 0, len = this.children.length; i < len; i++) {
  43230. if (this.children[i][isSourceNode]) {
  43231. this.children[i].walkSourceContents(aFn);
  43232. }
  43233. }
  43234. var sources = Object.keys(this.sourceContents);
  43235. for (var i = 0, len = sources.length; i < len; i++) {
  43236. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  43237. }
  43238. };
  43239. /**
  43240. * Return the string representation of this source node. Walks over the tree
  43241. * and concatenates all the various snippets together to one string.
  43242. */
  43243. SourceNode.prototype.toString = function SourceNode_toString() {
  43244. var str = "";
  43245. this.walk(function (chunk) {
  43246. str += chunk;
  43247. });
  43248. return str;
  43249. };
  43250. /**
  43251. * Returns the string representation of this source node along with a source
  43252. * map.
  43253. */
  43254. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  43255. var generated = {
  43256. code: "",
  43257. line: 1,
  43258. column: 0
  43259. };
  43260. var map = new SourceMapGenerator(aArgs);
  43261. var sourceMappingActive = false;
  43262. var lastOriginalSource = null;
  43263. var lastOriginalLine = null;
  43264. var lastOriginalColumn = null;
  43265. var lastOriginalName = null;
  43266. this.walk(function (chunk, original) {
  43267. generated.code += chunk;
  43268. if (original.source !== null
  43269. && original.line !== null
  43270. && original.column !== null) {
  43271. if(lastOriginalSource !== original.source
  43272. || lastOriginalLine !== original.line
  43273. || lastOriginalColumn !== original.column
  43274. || lastOriginalName !== original.name) {
  43275. map.addMapping({
  43276. source: original.source,
  43277. original: {
  43278. line: original.line,
  43279. column: original.column
  43280. },
  43281. generated: {
  43282. line: generated.line,
  43283. column: generated.column
  43284. },
  43285. name: original.name
  43286. });
  43287. }
  43288. lastOriginalSource = original.source;
  43289. lastOriginalLine = original.line;
  43290. lastOriginalColumn = original.column;
  43291. lastOriginalName = original.name;
  43292. sourceMappingActive = true;
  43293. } else if (sourceMappingActive) {
  43294. map.addMapping({
  43295. generated: {
  43296. line: generated.line,
  43297. column: generated.column
  43298. }
  43299. });
  43300. lastOriginalSource = null;
  43301. sourceMappingActive = false;
  43302. }
  43303. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  43304. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  43305. generated.line++;
  43306. generated.column = 0;
  43307. // Mappings end at eol
  43308. if (idx + 1 === length) {
  43309. lastOriginalSource = null;
  43310. sourceMappingActive = false;
  43311. } else if (sourceMappingActive) {
  43312. map.addMapping({
  43313. source: original.source,
  43314. original: {
  43315. line: original.line,
  43316. column: original.column
  43317. },
  43318. generated: {
  43319. line: generated.line,
  43320. column: generated.column
  43321. },
  43322. name: original.name
  43323. });
  43324. }
  43325. } else {
  43326. generated.column++;
  43327. }
  43328. }
  43329. });
  43330. this.walkSourceContents(function (sourceFile, sourceContent) {
  43331. map.setSourceContent(sourceFile, sourceContent);
  43332. });
  43333. return { code: generated.code, map: map };
  43334. };
  43335. sourceNode.SourceNode = SourceNode;
  43336. return sourceNode;
  43337. }
  43338. /*
  43339. * Copyright 2009-2011 Mozilla Foundation and contributors
  43340. * Licensed under the New BSD license. See LICENSE.txt or:
  43341. * http://opensource.org/licenses/BSD-3-Clause
  43342. */
  43343. var hasRequiredSourceMap;
  43344. function requireSourceMap () {
  43345. if (hasRequiredSourceMap) return sourceMap;
  43346. hasRequiredSourceMap = 1;
  43347. sourceMap.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  43348. sourceMap.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer().SourceMapConsumer;
  43349. sourceMap.SourceNode = /*@__PURE__*/ requireSourceNode().SourceNode;
  43350. return sourceMap;
  43351. }
  43352. var mergeSourceMap;
  43353. var hasRequiredMergeSourceMap;
  43354. function requireMergeSourceMap () {
  43355. if (hasRequiredMergeSourceMap) return mergeSourceMap;
  43356. hasRequiredMergeSourceMap = 1;
  43357. var sourceMap = /*@__PURE__*/ requireSourceMap();
  43358. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  43359. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  43360. mergeSourceMap = merge;
  43361. /**
  43362. * Merge old source map and new source map and return merged.
  43363. * If old or new source map value is falsy, return another one as it is.
  43364. *
  43365. * @param {object|string} [oldMap] old source map object
  43366. * @param {object|string} [newmap] new source map object
  43367. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  43368. */
  43369. function merge(oldMap, newMap) {
  43370. if (!oldMap) return newMap
  43371. if (!newMap) return oldMap
  43372. var oldMapConsumer = new SourceMapConsumer(oldMap);
  43373. var newMapConsumer = new SourceMapConsumer(newMap);
  43374. var mergedMapGenerator = new SourceMapGenerator();
  43375. // iterate on new map and overwrite original position of new map with one of old map
  43376. newMapConsumer.eachMapping(function(m) {
  43377. // pass when `originalLine` is null.
  43378. // It occurs in case that the node does not have origin in original code.
  43379. if (m.originalLine == null) return
  43380. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  43381. line: m.originalLine,
  43382. column: m.originalColumn
  43383. });
  43384. if (origPosInOldMap.source == null) return
  43385. mergedMapGenerator.addMapping({
  43386. original: {
  43387. line: origPosInOldMap.line,
  43388. column: origPosInOldMap.column
  43389. },
  43390. generated: {
  43391. line: m.generatedLine,
  43392. column: m.generatedColumn
  43393. },
  43394. source: origPosInOldMap.source,
  43395. name: origPosInOldMap.name
  43396. });
  43397. });
  43398. var consumers = [oldMapConsumer, newMapConsumer];
  43399. consumers.forEach(function(consumer) {
  43400. consumer.sources.forEach(function(sourceFile) {
  43401. mergedMapGenerator._sources.add(sourceFile);
  43402. var sourceContent = consumer.sourceContentFor(sourceFile);
  43403. if (sourceContent != null) {
  43404. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  43405. }
  43406. });
  43407. });
  43408. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  43409. mergedMapGenerator._file = oldMap.file;
  43410. return JSON.parse(mergedMapGenerator.toString())
  43411. }
  43412. return mergeSourceMap;
  43413. }
  43414. var mergeSourceMapExports = /*@__PURE__*/ requireMergeSourceMap();
  43415. var merge = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMapExports);
  43416. var __defProp$5 = Object.defineProperty;
  43417. var __defProps$4 = Object.defineProperties;
  43418. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  43419. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  43420. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  43421. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  43422. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43423. var __spreadValues$5 = (a, b) => {
  43424. for (var prop in b || (b = {}))
  43425. if (__hasOwnProp$5.call(b, prop))
  43426. __defNormalProp$5(a, prop, b[prop]);
  43427. if (__getOwnPropSymbols$5)
  43428. for (var prop of __getOwnPropSymbols$5(b)) {
  43429. if (__propIsEnum$5.call(b, prop))
  43430. __defNormalProp$5(a, prop, b[prop]);
  43431. }
  43432. return a;
  43433. };
  43434. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  43435. const scss = (source, map, options, load = require) => {
  43436. const nodeSass = load("sass");
  43437. const { compileString, renderSync } = nodeSass;
  43438. const data = getSource(source, options.filename, options.additionalData);
  43439. let css;
  43440. let dependencies;
  43441. let sourceMap;
  43442. try {
  43443. if (compileString) {
  43444. const { pathToFileURL, fileURLToPath } = load("url");
  43445. const result = compileString(data, __spreadProps$4(__spreadValues$5({}, options), {
  43446. url: pathToFileURL(options.filename),
  43447. sourceMap: !!map
  43448. }));
  43449. css = result.css;
  43450. dependencies = result.loadedUrls.map((url) => fileURLToPath(url));
  43451. sourceMap = map ? result.sourceMap : void 0;
  43452. } else {
  43453. const result = renderSync(__spreadProps$4(__spreadValues$5({}, options), {
  43454. data,
  43455. file: options.filename,
  43456. outFile: options.filename,
  43457. sourceMap: !!map
  43458. }));
  43459. css = result.css.toString();
  43460. dependencies = result.stats.includedFiles;
  43461. sourceMap = map ? JSON.parse(result.map.toString()) : void 0;
  43462. }
  43463. if (map) {
  43464. return {
  43465. code: css,
  43466. errors: [],
  43467. dependencies,
  43468. map: merge(map, sourceMap)
  43469. };
  43470. }
  43471. return { code: css, errors: [], dependencies };
  43472. } catch (e) {
  43473. return { code: "", errors: [e], dependencies: [] };
  43474. }
  43475. };
  43476. const sass = (source, map, options, load) => scss(
  43477. source,
  43478. map,
  43479. __spreadProps$4(__spreadValues$5({}, options), {
  43480. indentedSyntax: true
  43481. }),
  43482. load
  43483. );
  43484. const less = (source, map, options, load = require) => {
  43485. const nodeLess = load("less");
  43486. let result;
  43487. let error = null;
  43488. nodeLess.render(
  43489. getSource(source, options.filename, options.additionalData),
  43490. __spreadProps$4(__spreadValues$5({}, options), { syncImport: true }),
  43491. (err, output) => {
  43492. error = err;
  43493. result = output;
  43494. }
  43495. );
  43496. if (error) return { code: "", errors: [error], dependencies: [] };
  43497. const dependencies = result.imports;
  43498. if (map) {
  43499. return {
  43500. code: result.css.toString(),
  43501. map: merge(map, result.map),
  43502. errors: [],
  43503. dependencies
  43504. };
  43505. }
  43506. return {
  43507. code: result.css.toString(),
  43508. errors: [],
  43509. dependencies
  43510. };
  43511. };
  43512. const styl = (source, map, options, load = require) => {
  43513. const nodeStylus = load("stylus");
  43514. try {
  43515. const ref = nodeStylus(source, options);
  43516. if (map) ref.set("sourcemap", { inline: false, comment: false });
  43517. const result = ref.render();
  43518. const dependencies = ref.deps();
  43519. if (map) {
  43520. return {
  43521. code: result,
  43522. map: merge(map, ref.sourcemap),
  43523. errors: [],
  43524. dependencies
  43525. };
  43526. }
  43527. return { code: result, errors: [], dependencies };
  43528. } catch (e) {
  43529. return { code: "", errors: [e], dependencies: [] };
  43530. }
  43531. };
  43532. function getSource(source, filename, additionalData) {
  43533. if (!additionalData) return source;
  43534. if (isFunction$1(additionalData)) {
  43535. return additionalData(source, filename);
  43536. }
  43537. return additionalData + source;
  43538. }
  43539. const processors = {
  43540. less,
  43541. sass,
  43542. scss,
  43543. styl,
  43544. stylus: styl
  43545. };
  43546. var __defProp$4 = Object.defineProperty;
  43547. var __defProps$3 = Object.defineProperties;
  43548. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43549. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  43550. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  43551. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  43552. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43553. var __spreadValues$4 = (a, b) => {
  43554. for (var prop in b || (b = {}))
  43555. if (__hasOwnProp$4.call(b, prop))
  43556. __defNormalProp$4(a, prop, b[prop]);
  43557. if (__getOwnPropSymbols$4)
  43558. for (var prop of __getOwnPropSymbols$4(b)) {
  43559. if (__propIsEnum$4.call(b, prop))
  43560. __defNormalProp$4(a, prop, b[prop]);
  43561. }
  43562. return a;
  43563. };
  43564. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43565. function compileStyle(options) {
  43566. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43567. isAsync: false
  43568. }));
  43569. }
  43570. function compileStyleAsync(options) {
  43571. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43572. isAsync: true
  43573. }));
  43574. }
  43575. function doCompileStyle(options) {
  43576. const {
  43577. filename,
  43578. id,
  43579. scoped = false,
  43580. trim = true,
  43581. isProd = false,
  43582. modules = false,
  43583. modulesOptions = {},
  43584. preprocessLang,
  43585. postcssOptions,
  43586. postcssPlugins
  43587. } = options;
  43588. const preprocessor = preprocessLang && processors[preprocessLang];
  43589. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  43590. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  43591. const source = preProcessedSource ? preProcessedSource.code : options.source;
  43592. const shortId = id.replace(/^data-v-/, "");
  43593. const longId = `data-v-${shortId}`;
  43594. const plugins = (postcssPlugins || []).slice();
  43595. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  43596. if (trim) {
  43597. plugins.push(trimPlugin());
  43598. }
  43599. if (scoped) {
  43600. plugins.push(scopedPlugin(longId));
  43601. }
  43602. let cssModules;
  43603. if (modules) {
  43604. {
  43605. throw new Error(
  43606. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  43607. );
  43608. }
  43609. }
  43610. const postCSSOptions = __spreadProps$3(__spreadValues$4({}, postcssOptions), {
  43611. to: filename,
  43612. from: filename
  43613. });
  43614. if (map) {
  43615. postCSSOptions.map = {
  43616. inline: false,
  43617. annotation: false,
  43618. prev: map
  43619. };
  43620. }
  43621. let result;
  43622. let code;
  43623. let outMap;
  43624. const dependencies = new Set(
  43625. preProcessedSource ? preProcessedSource.dependencies : []
  43626. );
  43627. dependencies.delete(filename);
  43628. const errors = [];
  43629. if (preProcessedSource && preProcessedSource.errors.length) {
  43630. errors.push(...preProcessedSource.errors);
  43631. }
  43632. const recordPlainCssDependencies = (messages) => {
  43633. messages.forEach((msg) => {
  43634. if (msg.type === "dependency") {
  43635. dependencies.add(msg.file);
  43636. }
  43637. });
  43638. return dependencies;
  43639. };
  43640. try {
  43641. result = postcss(plugins).process(source, postCSSOptions);
  43642. if (options.isAsync) {
  43643. return result.then((result2) => ({
  43644. code: result2.css || "",
  43645. map: result2.map && result2.map.toJSON(),
  43646. errors,
  43647. modules: cssModules,
  43648. rawResult: result2,
  43649. dependencies: recordPlainCssDependencies(result2.messages)
  43650. })).catch((error) => ({
  43651. code: "",
  43652. map: void 0,
  43653. errors: [...errors, error],
  43654. rawResult: void 0,
  43655. dependencies
  43656. }));
  43657. }
  43658. recordPlainCssDependencies(result.messages);
  43659. code = result.css;
  43660. outMap = result.map;
  43661. } catch (e) {
  43662. errors.push(e);
  43663. }
  43664. return {
  43665. code: code || ``,
  43666. map: outMap && outMap.toJSON(),
  43667. errors,
  43668. rawResult: result,
  43669. dependencies
  43670. };
  43671. }
  43672. function preprocess(options, preprocessor) {
  43673. if (!options.preprocessCustomRequire) {
  43674. throw new Error(
  43675. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  43676. );
  43677. }
  43678. return preprocessor(
  43679. options.source,
  43680. options.inMap || options.map,
  43681. __spreadValues$4({
  43682. filename: options.filename
  43683. }, options.preprocessOptions),
  43684. options.preprocessCustomRequire
  43685. );
  43686. }
  43687. const UNKNOWN_TYPE = "Unknown";
  43688. function resolveObjectKey(node, computed) {
  43689. switch (node.type) {
  43690. case "StringLiteral":
  43691. case "NumericLiteral":
  43692. return String(node.value);
  43693. case "Identifier":
  43694. if (!computed) return node.name;
  43695. }
  43696. return void 0;
  43697. }
  43698. function concatStrings(strs) {
  43699. return strs.filter((s) => !!s).join(", ");
  43700. }
  43701. function isLiteralNode(node) {
  43702. return node.type.endsWith("Literal");
  43703. }
  43704. function isCallOf(node, test) {
  43705. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  43706. }
  43707. function toRuntimeTypeString(types) {
  43708. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  43709. }
  43710. function getImportedName(specifier) {
  43711. if (specifier.type === "ImportSpecifier")
  43712. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  43713. else if (specifier.type === "ImportNamespaceSpecifier") return "*";
  43714. return "default";
  43715. }
  43716. function getId(node) {
  43717. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  43718. }
  43719. function getStringLiteralKey(node) {
  43720. 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;
  43721. }
  43722. const normalize = (path.posix || path).normalize;
  43723. const windowsSlashRE = /\\/g;
  43724. function normalizePath(p) {
  43725. return normalize(p.replace(windowsSlashRE, "/"));
  43726. }
  43727. const joinPaths = (path.posix || path).join;
  43728. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  43729. function getEscapedPropName(key) {
  43730. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  43731. }
  43732. const isJS = (...langs) => langs.some((lang) => lang === "js" || lang === "jsx");
  43733. const isTS = (...langs) => langs.some((lang) => lang === "ts" || lang === "tsx");
  43734. function analyzeScriptBindings(ast) {
  43735. for (const node of ast) {
  43736. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  43737. return analyzeBindingsFromOptions(node.declaration);
  43738. }
  43739. }
  43740. return {};
  43741. }
  43742. function analyzeBindingsFromOptions(node) {
  43743. const bindings = {};
  43744. Object.defineProperty(bindings, "__isScriptSetup", {
  43745. enumerable: false,
  43746. value: false
  43747. });
  43748. for (const property of node.properties) {
  43749. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  43750. if (property.key.name === "props") {
  43751. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43752. bindings[key] = "props";
  43753. }
  43754. } else if (property.key.name === "inject") {
  43755. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43756. bindings[key] = "options";
  43757. }
  43758. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  43759. for (const key of getObjectExpressionKeys(property.value)) {
  43760. bindings[key] = "options";
  43761. }
  43762. }
  43763. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  43764. for (const bodyItem of property.body.body) {
  43765. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  43766. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  43767. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  43768. }
  43769. }
  43770. }
  43771. }
  43772. }
  43773. return bindings;
  43774. }
  43775. function getObjectExpressionKeys(node) {
  43776. const keys = [];
  43777. for (const prop of node.properties) {
  43778. if (prop.type === "SpreadElement") continue;
  43779. const key = resolveObjectKey(prop.key, prop.computed);
  43780. if (key) keys.push(String(key));
  43781. }
  43782. return keys;
  43783. }
  43784. function getArrayExpressionKeys(node) {
  43785. const keys = [];
  43786. for (const element of node.elements) {
  43787. if (element && element.type === "StringLiteral") {
  43788. keys.push(element.value);
  43789. }
  43790. }
  43791. return keys;
  43792. }
  43793. function getObjectOrArrayExpressionKeys(value) {
  43794. if (value.type === "ArrayExpression") {
  43795. return getArrayExpressionKeys(value);
  43796. }
  43797. if (value.type === "ObjectExpression") {
  43798. return getObjectExpressionKeys(value);
  43799. }
  43800. return [];
  43801. }
  43802. // src/vlq.ts
  43803. var comma = ",".charCodeAt(0);
  43804. var semicolon = ";".charCodeAt(0);
  43805. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  43806. var intToChar = new Uint8Array(64);
  43807. var charToInt = new Uint8Array(128);
  43808. for (let i = 0; i < chars.length; i++) {
  43809. const c = chars.charCodeAt(i);
  43810. intToChar[i] = c;
  43811. charToInt[c] = i;
  43812. }
  43813. function encodeInteger(builder, num, relative) {
  43814. let delta = num - relative;
  43815. delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
  43816. do {
  43817. let clamped = delta & 31;
  43818. delta >>>= 5;
  43819. if (delta > 0) clamped |= 32;
  43820. builder.write(intToChar[clamped]);
  43821. } while (delta > 0);
  43822. return num;
  43823. }
  43824. // src/strings.ts
  43825. var bufLength = 1024 * 16;
  43826. var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
  43827. decode(buf) {
  43828. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  43829. return out.toString();
  43830. }
  43831. } : {
  43832. decode(buf) {
  43833. let out = "";
  43834. for (let i = 0; i < buf.length; i++) {
  43835. out += String.fromCharCode(buf[i]);
  43836. }
  43837. return out;
  43838. }
  43839. };
  43840. var StringWriter = class {
  43841. constructor() {
  43842. this.pos = 0;
  43843. this.out = "";
  43844. this.buffer = new Uint8Array(bufLength);
  43845. }
  43846. write(v) {
  43847. const { buffer } = this;
  43848. buffer[this.pos++] = v;
  43849. if (this.pos === bufLength) {
  43850. this.out += td.decode(buffer);
  43851. this.pos = 0;
  43852. }
  43853. }
  43854. flush() {
  43855. const { buffer, out, pos } = this;
  43856. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  43857. }
  43858. };
  43859. function encode(decoded) {
  43860. const writer = new StringWriter();
  43861. let sourcesIndex = 0;
  43862. let sourceLine = 0;
  43863. let sourceColumn = 0;
  43864. let namesIndex = 0;
  43865. for (let i = 0; i < decoded.length; i++) {
  43866. const line = decoded[i];
  43867. if (i > 0) writer.write(semicolon);
  43868. if (line.length === 0) continue;
  43869. let genColumn = 0;
  43870. for (let j = 0; j < line.length; j++) {
  43871. const segment = line[j];
  43872. if (j > 0) writer.write(comma);
  43873. genColumn = encodeInteger(writer, segment[0], genColumn);
  43874. if (segment.length === 1) continue;
  43875. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  43876. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  43877. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  43878. if (segment.length === 4) continue;
  43879. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  43880. }
  43881. }
  43882. return writer.flush();
  43883. }
  43884. class BitSet {
  43885. constructor(arg) {
  43886. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  43887. }
  43888. add(n) {
  43889. this.bits[n >> 5] |= 1 << (n & 31);
  43890. }
  43891. has(n) {
  43892. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  43893. }
  43894. }
  43895. class Chunk {
  43896. constructor(start, end, content) {
  43897. this.start = start;
  43898. this.end = end;
  43899. this.original = content;
  43900. this.intro = '';
  43901. this.outro = '';
  43902. this.content = content;
  43903. this.storeName = false;
  43904. this.edited = false;
  43905. {
  43906. this.previous = null;
  43907. this.next = null;
  43908. }
  43909. }
  43910. appendLeft(content) {
  43911. this.outro += content;
  43912. }
  43913. appendRight(content) {
  43914. this.intro = this.intro + content;
  43915. }
  43916. clone() {
  43917. const chunk = new Chunk(this.start, this.end, this.original);
  43918. chunk.intro = this.intro;
  43919. chunk.outro = this.outro;
  43920. chunk.content = this.content;
  43921. chunk.storeName = this.storeName;
  43922. chunk.edited = this.edited;
  43923. return chunk;
  43924. }
  43925. contains(index) {
  43926. return this.start < index && index < this.end;
  43927. }
  43928. eachNext(fn) {
  43929. let chunk = this;
  43930. while (chunk) {
  43931. fn(chunk);
  43932. chunk = chunk.next;
  43933. }
  43934. }
  43935. eachPrevious(fn) {
  43936. let chunk = this;
  43937. while (chunk) {
  43938. fn(chunk);
  43939. chunk = chunk.previous;
  43940. }
  43941. }
  43942. edit(content, storeName, contentOnly) {
  43943. this.content = content;
  43944. if (!contentOnly) {
  43945. this.intro = '';
  43946. this.outro = '';
  43947. }
  43948. this.storeName = storeName;
  43949. this.edited = true;
  43950. return this;
  43951. }
  43952. prependLeft(content) {
  43953. this.outro = content + this.outro;
  43954. }
  43955. prependRight(content) {
  43956. this.intro = content + this.intro;
  43957. }
  43958. reset() {
  43959. this.intro = '';
  43960. this.outro = '';
  43961. if (this.edited) {
  43962. this.content = this.original;
  43963. this.storeName = false;
  43964. this.edited = false;
  43965. }
  43966. }
  43967. split(index) {
  43968. const sliceIndex = index - this.start;
  43969. const originalBefore = this.original.slice(0, sliceIndex);
  43970. const originalAfter = this.original.slice(sliceIndex);
  43971. this.original = originalBefore;
  43972. const newChunk = new Chunk(index, this.end, originalAfter);
  43973. newChunk.outro = this.outro;
  43974. this.outro = '';
  43975. this.end = index;
  43976. if (this.edited) {
  43977. // after split we should save the edit content record into the correct chunk
  43978. // to make sure sourcemap correct
  43979. // For example:
  43980. // ' test'.trim()
  43981. // split -> ' ' + 'test'
  43982. // ✔️ edit -> '' + 'test'
  43983. // ✖️ edit -> 'test' + ''
  43984. // TODO is this block necessary?...
  43985. newChunk.edit('', false);
  43986. this.content = '';
  43987. } else {
  43988. this.content = originalBefore;
  43989. }
  43990. newChunk.next = this.next;
  43991. if (newChunk.next) newChunk.next.previous = newChunk;
  43992. newChunk.previous = this;
  43993. this.next = newChunk;
  43994. return newChunk;
  43995. }
  43996. toString() {
  43997. return this.intro + this.content + this.outro;
  43998. }
  43999. trimEnd(rx) {
  44000. this.outro = this.outro.replace(rx, '');
  44001. if (this.outro.length) return true;
  44002. const trimmed = this.content.replace(rx, '');
  44003. if (trimmed.length) {
  44004. if (trimmed !== this.content) {
  44005. this.split(this.start + trimmed.length).edit('', undefined, true);
  44006. if (this.edited) {
  44007. // save the change, if it has been edited
  44008. this.edit(trimmed, this.storeName, true);
  44009. }
  44010. }
  44011. return true;
  44012. } else {
  44013. this.edit('', undefined, true);
  44014. this.intro = this.intro.replace(rx, '');
  44015. if (this.intro.length) return true;
  44016. }
  44017. }
  44018. trimStart(rx) {
  44019. this.intro = this.intro.replace(rx, '');
  44020. if (this.intro.length) return true;
  44021. const trimmed = this.content.replace(rx, '');
  44022. if (trimmed.length) {
  44023. if (trimmed !== this.content) {
  44024. const newChunk = this.split(this.end - trimmed.length);
  44025. if (this.edited) {
  44026. // save the change, if it has been edited
  44027. newChunk.edit(trimmed, this.storeName, true);
  44028. }
  44029. this.edit('', undefined, true);
  44030. }
  44031. return true;
  44032. } else {
  44033. this.edit('', undefined, true);
  44034. this.outro = this.outro.replace(rx, '');
  44035. if (this.outro.length) return true;
  44036. }
  44037. }
  44038. }
  44039. function getBtoa() {
  44040. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  44041. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  44042. } else if (typeof Buffer === 'function') {
  44043. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  44044. } else {
  44045. return () => {
  44046. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  44047. };
  44048. }
  44049. }
  44050. const btoa = /*#__PURE__*/ getBtoa();
  44051. class SourceMap {
  44052. constructor(properties) {
  44053. this.version = 3;
  44054. this.file = properties.file;
  44055. this.sources = properties.sources;
  44056. this.sourcesContent = properties.sourcesContent;
  44057. this.names = properties.names;
  44058. this.mappings = encode(properties.mappings);
  44059. if (typeof properties.x_google_ignoreList !== 'undefined') {
  44060. this.x_google_ignoreList = properties.x_google_ignoreList;
  44061. }
  44062. if (typeof properties.debugId !== 'undefined') {
  44063. this.debugId = properties.debugId;
  44064. }
  44065. }
  44066. toString() {
  44067. return JSON.stringify(this);
  44068. }
  44069. toUrl() {
  44070. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  44071. }
  44072. }
  44073. function guessIndent(code) {
  44074. const lines = code.split('\n');
  44075. const tabbed = lines.filter((line) => /^\t+/.test(line));
  44076. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  44077. if (tabbed.length === 0 && spaced.length === 0) {
  44078. return null;
  44079. }
  44080. // More lines tabbed than spaced? Assume tabs, and
  44081. // default to tabs in the case of a tie (or nothing
  44082. // to go on)
  44083. if (tabbed.length >= spaced.length) {
  44084. return '\t';
  44085. }
  44086. // Otherwise, we need to guess the multiple
  44087. const min = spaced.reduce((previous, current) => {
  44088. const numSpaces = /^ +/.exec(current)[0].length;
  44089. return Math.min(numSpaces, previous);
  44090. }, Infinity);
  44091. return new Array(min + 1).join(' ');
  44092. }
  44093. function getRelativePath(from, to) {
  44094. const fromParts = from.split(/[/\\]/);
  44095. const toParts = to.split(/[/\\]/);
  44096. fromParts.pop(); // get dirname
  44097. while (fromParts[0] === toParts[0]) {
  44098. fromParts.shift();
  44099. toParts.shift();
  44100. }
  44101. if (fromParts.length) {
  44102. let i = fromParts.length;
  44103. while (i--) fromParts[i] = '..';
  44104. }
  44105. return fromParts.concat(toParts).join('/');
  44106. }
  44107. const toString = Object.prototype.toString;
  44108. function isObject(thing) {
  44109. return toString.call(thing) === '[object Object]';
  44110. }
  44111. function getLocator(source) {
  44112. const originalLines = source.split('\n');
  44113. const lineOffsets = [];
  44114. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  44115. lineOffsets.push(pos);
  44116. pos += originalLines[i].length + 1;
  44117. }
  44118. return function locate(index) {
  44119. let i = 0;
  44120. let j = lineOffsets.length;
  44121. while (i < j) {
  44122. const m = (i + j) >> 1;
  44123. if (index < lineOffsets[m]) {
  44124. j = m;
  44125. } else {
  44126. i = m + 1;
  44127. }
  44128. }
  44129. const line = i - 1;
  44130. const column = index - lineOffsets[line];
  44131. return { line, column };
  44132. };
  44133. }
  44134. const wordRegex = /\w/;
  44135. class Mappings {
  44136. constructor(hires) {
  44137. this.hires = hires;
  44138. this.generatedCodeLine = 0;
  44139. this.generatedCodeColumn = 0;
  44140. this.raw = [];
  44141. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  44142. this.pending = null;
  44143. }
  44144. addEdit(sourceIndex, content, loc, nameIndex) {
  44145. if (content.length) {
  44146. const contentLengthMinusOne = content.length - 1;
  44147. let contentLineEnd = content.indexOf('\n', 0);
  44148. let previousContentLineEnd = -1;
  44149. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  44150. // else code afterwards would fill one line too many
  44151. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  44152. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44153. if (nameIndex >= 0) {
  44154. segment.push(nameIndex);
  44155. }
  44156. this.rawSegments.push(segment);
  44157. this.generatedCodeLine += 1;
  44158. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44159. this.generatedCodeColumn = 0;
  44160. previousContentLineEnd = contentLineEnd;
  44161. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  44162. }
  44163. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44164. if (nameIndex >= 0) {
  44165. segment.push(nameIndex);
  44166. }
  44167. this.rawSegments.push(segment);
  44168. this.advance(content.slice(previousContentLineEnd + 1));
  44169. } else if (this.pending) {
  44170. this.rawSegments.push(this.pending);
  44171. this.advance(content);
  44172. }
  44173. this.pending = null;
  44174. }
  44175. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  44176. let originalCharIndex = chunk.start;
  44177. let first = true;
  44178. // when iterating each char, check if it's in a word boundary
  44179. let charInHiresBoundary = false;
  44180. while (originalCharIndex < chunk.end) {
  44181. if (original[originalCharIndex] === '\n') {
  44182. loc.line += 1;
  44183. loc.column = 0;
  44184. this.generatedCodeLine += 1;
  44185. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44186. this.generatedCodeColumn = 0;
  44187. first = true;
  44188. charInHiresBoundary = false;
  44189. } else {
  44190. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  44191. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  44192. if (this.hires === 'boundary') {
  44193. // in hires "boundary", group segments per word boundary than per char
  44194. if (wordRegex.test(original[originalCharIndex])) {
  44195. // for first char in the boundary found, start the boundary by pushing a segment
  44196. if (!charInHiresBoundary) {
  44197. this.rawSegments.push(segment);
  44198. charInHiresBoundary = true;
  44199. }
  44200. } else {
  44201. // for non-word char, end the boundary by pushing a segment
  44202. this.rawSegments.push(segment);
  44203. charInHiresBoundary = false;
  44204. }
  44205. } else {
  44206. this.rawSegments.push(segment);
  44207. }
  44208. }
  44209. loc.column += 1;
  44210. this.generatedCodeColumn += 1;
  44211. first = false;
  44212. }
  44213. originalCharIndex += 1;
  44214. }
  44215. this.pending = null;
  44216. }
  44217. advance(str) {
  44218. if (!str) return;
  44219. const lines = str.split('\n');
  44220. if (lines.length > 1) {
  44221. for (let i = 0; i < lines.length - 1; i++) {
  44222. this.generatedCodeLine++;
  44223. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  44224. }
  44225. this.generatedCodeColumn = 0;
  44226. }
  44227. this.generatedCodeColumn += lines[lines.length - 1].length;
  44228. }
  44229. }
  44230. const n = '\n';
  44231. const warned = {
  44232. insertLeft: false,
  44233. insertRight: false,
  44234. storeName: false,
  44235. };
  44236. class MagicString {
  44237. constructor(string, options = {}) {
  44238. const chunk = new Chunk(0, string.length, string);
  44239. Object.defineProperties(this, {
  44240. original: { writable: true, value: string },
  44241. outro: { writable: true, value: '' },
  44242. intro: { writable: true, value: '' },
  44243. firstChunk: { writable: true, value: chunk },
  44244. lastChunk: { writable: true, value: chunk },
  44245. lastSearchedChunk: { writable: true, value: chunk },
  44246. byStart: { writable: true, value: {} },
  44247. byEnd: { writable: true, value: {} },
  44248. filename: { writable: true, value: options.filename },
  44249. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  44250. sourcemapLocations: { writable: true, value: new BitSet() },
  44251. storedNames: { writable: true, value: {} },
  44252. indentStr: { writable: true, value: undefined },
  44253. ignoreList: { writable: true, value: options.ignoreList },
  44254. offset: { writable: true, value: options.offset || 0 },
  44255. });
  44256. this.byStart[0] = chunk;
  44257. this.byEnd[string.length] = chunk;
  44258. }
  44259. addSourcemapLocation(char) {
  44260. this.sourcemapLocations.add(char);
  44261. }
  44262. append(content) {
  44263. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44264. this.outro += content;
  44265. return this;
  44266. }
  44267. appendLeft(index, content) {
  44268. index = index + this.offset;
  44269. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44270. this._split(index);
  44271. const chunk = this.byEnd[index];
  44272. if (chunk) {
  44273. chunk.appendLeft(content);
  44274. } else {
  44275. this.intro += content;
  44276. }
  44277. return this;
  44278. }
  44279. appendRight(index, content) {
  44280. index = index + this.offset;
  44281. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44282. this._split(index);
  44283. const chunk = this.byStart[index];
  44284. if (chunk) {
  44285. chunk.appendRight(content);
  44286. } else {
  44287. this.outro += content;
  44288. }
  44289. return this;
  44290. }
  44291. clone() {
  44292. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  44293. let originalChunk = this.firstChunk;
  44294. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  44295. while (originalChunk) {
  44296. cloned.byStart[clonedChunk.start] = clonedChunk;
  44297. cloned.byEnd[clonedChunk.end] = clonedChunk;
  44298. const nextOriginalChunk = originalChunk.next;
  44299. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  44300. if (nextClonedChunk) {
  44301. clonedChunk.next = nextClonedChunk;
  44302. nextClonedChunk.previous = clonedChunk;
  44303. clonedChunk = nextClonedChunk;
  44304. }
  44305. originalChunk = nextOriginalChunk;
  44306. }
  44307. cloned.lastChunk = clonedChunk;
  44308. if (this.indentExclusionRanges) {
  44309. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  44310. }
  44311. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  44312. cloned.intro = this.intro;
  44313. cloned.outro = this.outro;
  44314. return cloned;
  44315. }
  44316. generateDecodedMap(options) {
  44317. options = options || {};
  44318. const sourceIndex = 0;
  44319. const names = Object.keys(this.storedNames);
  44320. const mappings = new Mappings(options.hires);
  44321. const locate = getLocator(this.original);
  44322. if (this.intro) {
  44323. mappings.advance(this.intro);
  44324. }
  44325. this.firstChunk.eachNext((chunk) => {
  44326. const loc = locate(chunk.start);
  44327. if (chunk.intro.length) mappings.advance(chunk.intro);
  44328. if (chunk.edited) {
  44329. mappings.addEdit(
  44330. sourceIndex,
  44331. chunk.content,
  44332. loc,
  44333. chunk.storeName ? names.indexOf(chunk.original) : -1,
  44334. );
  44335. } else {
  44336. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  44337. }
  44338. if (chunk.outro.length) mappings.advance(chunk.outro);
  44339. });
  44340. if (this.outro) {
  44341. mappings.advance(this.outro);
  44342. }
  44343. return {
  44344. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  44345. sources: [
  44346. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  44347. ],
  44348. sourcesContent: options.includeContent ? [this.original] : undefined,
  44349. names,
  44350. mappings: mappings.raw,
  44351. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  44352. };
  44353. }
  44354. generateMap(options) {
  44355. return new SourceMap(this.generateDecodedMap(options));
  44356. }
  44357. _ensureindentStr() {
  44358. if (this.indentStr === undefined) {
  44359. this.indentStr = guessIndent(this.original);
  44360. }
  44361. }
  44362. _getRawIndentString() {
  44363. this._ensureindentStr();
  44364. return this.indentStr;
  44365. }
  44366. getIndentString() {
  44367. this._ensureindentStr();
  44368. return this.indentStr === null ? '\t' : this.indentStr;
  44369. }
  44370. indent(indentStr, options) {
  44371. const pattern = /^[^\r\n]/gm;
  44372. if (isObject(indentStr)) {
  44373. options = indentStr;
  44374. indentStr = undefined;
  44375. }
  44376. if (indentStr === undefined) {
  44377. this._ensureindentStr();
  44378. indentStr = this.indentStr || '\t';
  44379. }
  44380. if (indentStr === '') return this; // noop
  44381. options = options || {};
  44382. // Process exclusion ranges
  44383. const isExcluded = {};
  44384. if (options.exclude) {
  44385. const exclusions =
  44386. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  44387. exclusions.forEach((exclusion) => {
  44388. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  44389. isExcluded[i] = true;
  44390. }
  44391. });
  44392. }
  44393. let shouldIndentNextCharacter = options.indentStart !== false;
  44394. const replacer = (match) => {
  44395. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  44396. shouldIndentNextCharacter = true;
  44397. return match;
  44398. };
  44399. this.intro = this.intro.replace(pattern, replacer);
  44400. let charIndex = 0;
  44401. let chunk = this.firstChunk;
  44402. while (chunk) {
  44403. const end = chunk.end;
  44404. if (chunk.edited) {
  44405. if (!isExcluded[charIndex]) {
  44406. chunk.content = chunk.content.replace(pattern, replacer);
  44407. if (chunk.content.length) {
  44408. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  44409. }
  44410. }
  44411. } else {
  44412. charIndex = chunk.start;
  44413. while (charIndex < end) {
  44414. if (!isExcluded[charIndex]) {
  44415. const char = this.original[charIndex];
  44416. if (char === '\n') {
  44417. shouldIndentNextCharacter = true;
  44418. } else if (char !== '\r' && shouldIndentNextCharacter) {
  44419. shouldIndentNextCharacter = false;
  44420. if (charIndex === chunk.start) {
  44421. chunk.prependRight(indentStr);
  44422. } else {
  44423. this._splitChunk(chunk, charIndex);
  44424. chunk = chunk.next;
  44425. chunk.prependRight(indentStr);
  44426. }
  44427. }
  44428. }
  44429. charIndex += 1;
  44430. }
  44431. }
  44432. charIndex = chunk.end;
  44433. chunk = chunk.next;
  44434. }
  44435. this.outro = this.outro.replace(pattern, replacer);
  44436. return this;
  44437. }
  44438. insert() {
  44439. throw new Error(
  44440. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  44441. );
  44442. }
  44443. insertLeft(index, content) {
  44444. if (!warned.insertLeft) {
  44445. console.warn(
  44446. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  44447. );
  44448. warned.insertLeft = true;
  44449. }
  44450. return this.appendLeft(index, content);
  44451. }
  44452. insertRight(index, content) {
  44453. if (!warned.insertRight) {
  44454. console.warn(
  44455. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  44456. );
  44457. warned.insertRight = true;
  44458. }
  44459. return this.prependRight(index, content);
  44460. }
  44461. move(start, end, index) {
  44462. start = start + this.offset;
  44463. end = end + this.offset;
  44464. index = index + this.offset;
  44465. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  44466. this._split(start);
  44467. this._split(end);
  44468. this._split(index);
  44469. const first = this.byStart[start];
  44470. const last = this.byEnd[end];
  44471. const oldLeft = first.previous;
  44472. const oldRight = last.next;
  44473. const newRight = this.byStart[index];
  44474. if (!newRight && last === this.lastChunk) return this;
  44475. const newLeft = newRight ? newRight.previous : this.lastChunk;
  44476. if (oldLeft) oldLeft.next = oldRight;
  44477. if (oldRight) oldRight.previous = oldLeft;
  44478. if (newLeft) newLeft.next = first;
  44479. if (newRight) newRight.previous = last;
  44480. if (!first.previous) this.firstChunk = last.next;
  44481. if (!last.next) {
  44482. this.lastChunk = first.previous;
  44483. this.lastChunk.next = null;
  44484. }
  44485. first.previous = newLeft;
  44486. last.next = newRight || null;
  44487. if (!newLeft) this.firstChunk = first;
  44488. if (!newRight) this.lastChunk = last;
  44489. return this;
  44490. }
  44491. overwrite(start, end, content, options) {
  44492. options = options || {};
  44493. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  44494. }
  44495. update(start, end, content, options) {
  44496. start = start + this.offset;
  44497. end = end + this.offset;
  44498. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  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 (end > this.original.length) throw new Error('end is out of bounds');
  44504. if (start === end)
  44505. throw new Error(
  44506. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  44507. );
  44508. this._split(start);
  44509. this._split(end);
  44510. if (options === true) {
  44511. if (!warned.storeName) {
  44512. console.warn(
  44513. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  44514. );
  44515. warned.storeName = true;
  44516. }
  44517. options = { storeName: true };
  44518. }
  44519. const storeName = options !== undefined ? options.storeName : false;
  44520. const overwrite = options !== undefined ? options.overwrite : false;
  44521. if (storeName) {
  44522. const original = this.original.slice(start, end);
  44523. Object.defineProperty(this.storedNames, original, {
  44524. writable: true,
  44525. value: true,
  44526. enumerable: true,
  44527. });
  44528. }
  44529. const first = this.byStart[start];
  44530. const last = this.byEnd[end];
  44531. if (first) {
  44532. let chunk = first;
  44533. while (chunk !== last) {
  44534. if (chunk.next !== this.byStart[chunk.end]) {
  44535. throw new Error('Cannot overwrite across a split point');
  44536. }
  44537. chunk = chunk.next;
  44538. chunk.edit('', false);
  44539. }
  44540. first.edit(content, storeName, !overwrite);
  44541. } else {
  44542. // must be inserting at the end
  44543. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  44544. // TODO last chunk in the array may not be the last chunk, if it's moved...
  44545. last.next = newChunk;
  44546. newChunk.previous = last;
  44547. }
  44548. return this;
  44549. }
  44550. prepend(content) {
  44551. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44552. this.intro = content + this.intro;
  44553. return this;
  44554. }
  44555. prependLeft(index, content) {
  44556. index = index + this.offset;
  44557. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44558. this._split(index);
  44559. const chunk = this.byEnd[index];
  44560. if (chunk) {
  44561. chunk.prependLeft(content);
  44562. } else {
  44563. this.intro = content + this.intro;
  44564. }
  44565. return this;
  44566. }
  44567. prependRight(index, content) {
  44568. index = index + this.offset;
  44569. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44570. this._split(index);
  44571. const chunk = this.byStart[index];
  44572. if (chunk) {
  44573. chunk.prependRight(content);
  44574. } else {
  44575. this.outro = content + this.outro;
  44576. }
  44577. return this;
  44578. }
  44579. remove(start, end) {
  44580. start = start + this.offset;
  44581. end = end + this.offset;
  44582. if (this.original.length !== 0) {
  44583. while (start < 0) start += this.original.length;
  44584. while (end < 0) end += this.original.length;
  44585. }
  44586. if (start === end) return this;
  44587. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44588. if (start > end) throw new Error('end must be greater than start');
  44589. this._split(start);
  44590. this._split(end);
  44591. let chunk = this.byStart[start];
  44592. while (chunk) {
  44593. chunk.intro = '';
  44594. chunk.outro = '';
  44595. chunk.edit('');
  44596. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44597. }
  44598. return this;
  44599. }
  44600. reset(start, end) {
  44601. start = start + this.offset;
  44602. end = end + this.offset;
  44603. if (this.original.length !== 0) {
  44604. while (start < 0) start += this.original.length;
  44605. while (end < 0) end += this.original.length;
  44606. }
  44607. if (start === end) return this;
  44608. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44609. if (start > end) throw new Error('end must be greater than start');
  44610. this._split(start);
  44611. this._split(end);
  44612. let chunk = this.byStart[start];
  44613. while (chunk) {
  44614. chunk.reset();
  44615. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44616. }
  44617. return this;
  44618. }
  44619. lastChar() {
  44620. if (this.outro.length) return this.outro[this.outro.length - 1];
  44621. let chunk = this.lastChunk;
  44622. do {
  44623. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  44624. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  44625. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  44626. } while ((chunk = chunk.previous));
  44627. if (this.intro.length) return this.intro[this.intro.length - 1];
  44628. return '';
  44629. }
  44630. lastLine() {
  44631. let lineIndex = this.outro.lastIndexOf(n);
  44632. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  44633. let lineStr = this.outro;
  44634. let chunk = this.lastChunk;
  44635. do {
  44636. if (chunk.outro.length > 0) {
  44637. lineIndex = chunk.outro.lastIndexOf(n);
  44638. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  44639. lineStr = chunk.outro + lineStr;
  44640. }
  44641. if (chunk.content.length > 0) {
  44642. lineIndex = chunk.content.lastIndexOf(n);
  44643. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  44644. lineStr = chunk.content + lineStr;
  44645. }
  44646. if (chunk.intro.length > 0) {
  44647. lineIndex = chunk.intro.lastIndexOf(n);
  44648. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  44649. lineStr = chunk.intro + lineStr;
  44650. }
  44651. } while ((chunk = chunk.previous));
  44652. lineIndex = this.intro.lastIndexOf(n);
  44653. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  44654. return this.intro + lineStr;
  44655. }
  44656. slice(start = 0, end = this.original.length - this.offset) {
  44657. start = start + this.offset;
  44658. end = end + this.offset;
  44659. if (this.original.length !== 0) {
  44660. while (start < 0) start += this.original.length;
  44661. while (end < 0) end += this.original.length;
  44662. }
  44663. let result = '';
  44664. // find start chunk
  44665. let chunk = this.firstChunk;
  44666. while (chunk && (chunk.start > start || chunk.end <= start)) {
  44667. // found end chunk before start
  44668. if (chunk.start < end && chunk.end >= end) {
  44669. return result;
  44670. }
  44671. chunk = chunk.next;
  44672. }
  44673. if (chunk && chunk.edited && chunk.start !== start)
  44674. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  44675. const startChunk = chunk;
  44676. while (chunk) {
  44677. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  44678. result += chunk.intro;
  44679. }
  44680. const containsEnd = chunk.start < end && chunk.end >= end;
  44681. if (containsEnd && chunk.edited && chunk.end !== end)
  44682. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  44683. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  44684. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  44685. result += chunk.content.slice(sliceStart, sliceEnd);
  44686. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  44687. result += chunk.outro;
  44688. }
  44689. if (containsEnd) {
  44690. break;
  44691. }
  44692. chunk = chunk.next;
  44693. }
  44694. return result;
  44695. }
  44696. // TODO deprecate this? not really very useful
  44697. snip(start, end) {
  44698. const clone = this.clone();
  44699. clone.remove(0, start);
  44700. clone.remove(end, clone.original.length);
  44701. return clone;
  44702. }
  44703. _split(index) {
  44704. if (this.byStart[index] || this.byEnd[index]) return;
  44705. let chunk = this.lastSearchedChunk;
  44706. let previousChunk = chunk;
  44707. const searchForward = index > chunk.end;
  44708. while (chunk) {
  44709. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  44710. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  44711. // Prevent infinite loop (e.g. via empty chunks, where start === end)
  44712. if (chunk === previousChunk) return;
  44713. previousChunk = chunk;
  44714. }
  44715. }
  44716. _splitChunk(chunk, index) {
  44717. if (chunk.edited && chunk.content.length) {
  44718. // zero-length edited chunks are a special case (overlapping replacements)
  44719. const loc = getLocator(this.original)(index);
  44720. throw new Error(
  44721. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  44722. );
  44723. }
  44724. const newChunk = chunk.split(index);
  44725. this.byEnd[index] = chunk;
  44726. this.byStart[index] = newChunk;
  44727. this.byEnd[newChunk.end] = newChunk;
  44728. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  44729. this.lastSearchedChunk = chunk;
  44730. return true;
  44731. }
  44732. toString() {
  44733. let str = this.intro;
  44734. let chunk = this.firstChunk;
  44735. while (chunk) {
  44736. str += chunk.toString();
  44737. chunk = chunk.next;
  44738. }
  44739. return str + this.outro;
  44740. }
  44741. isEmpty() {
  44742. let chunk = this.firstChunk;
  44743. do {
  44744. if (
  44745. (chunk.intro.length && chunk.intro.trim()) ||
  44746. (chunk.content.length && chunk.content.trim()) ||
  44747. (chunk.outro.length && chunk.outro.trim())
  44748. )
  44749. return false;
  44750. } while ((chunk = chunk.next));
  44751. return true;
  44752. }
  44753. length() {
  44754. let chunk = this.firstChunk;
  44755. let length = 0;
  44756. do {
  44757. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  44758. } while ((chunk = chunk.next));
  44759. return length;
  44760. }
  44761. trimLines() {
  44762. return this.trim('[\\r\\n]');
  44763. }
  44764. trim(charType) {
  44765. return this.trimStart(charType).trimEnd(charType);
  44766. }
  44767. trimEndAborted(charType) {
  44768. const rx = new RegExp((charType || '\\s') + '+$');
  44769. this.outro = this.outro.replace(rx, '');
  44770. if (this.outro.length) return true;
  44771. let chunk = this.lastChunk;
  44772. do {
  44773. const end = chunk.end;
  44774. const aborted = chunk.trimEnd(rx);
  44775. // if chunk was trimmed, we have a new lastChunk
  44776. if (chunk.end !== end) {
  44777. if (this.lastChunk === chunk) {
  44778. this.lastChunk = chunk.next;
  44779. }
  44780. this.byEnd[chunk.end] = chunk;
  44781. this.byStart[chunk.next.start] = chunk.next;
  44782. this.byEnd[chunk.next.end] = chunk.next;
  44783. }
  44784. if (aborted) return true;
  44785. chunk = chunk.previous;
  44786. } while (chunk);
  44787. return false;
  44788. }
  44789. trimEnd(charType) {
  44790. this.trimEndAborted(charType);
  44791. return this;
  44792. }
  44793. trimStartAborted(charType) {
  44794. const rx = new RegExp('^' + (charType || '\\s') + '+');
  44795. this.intro = this.intro.replace(rx, '');
  44796. if (this.intro.length) return true;
  44797. let chunk = this.firstChunk;
  44798. do {
  44799. const end = chunk.end;
  44800. const aborted = chunk.trimStart(rx);
  44801. if (chunk.end !== end) {
  44802. // special case...
  44803. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  44804. this.byEnd[chunk.end] = chunk;
  44805. this.byStart[chunk.next.start] = chunk.next;
  44806. this.byEnd[chunk.next.end] = chunk.next;
  44807. }
  44808. if (aborted) return true;
  44809. chunk = chunk.next;
  44810. } while (chunk);
  44811. return false;
  44812. }
  44813. trimStart(charType) {
  44814. this.trimStartAborted(charType);
  44815. return this;
  44816. }
  44817. hasChanged() {
  44818. return this.original !== this.toString();
  44819. }
  44820. _replaceRegexp(searchValue, replacement) {
  44821. function getReplacement(match, str) {
  44822. if (typeof replacement === 'string') {
  44823. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  44824. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  44825. if (i === '$') return '$';
  44826. if (i === '&') return match[0];
  44827. const num = +i;
  44828. if (num < match.length) return match[+i];
  44829. return `$${i}`;
  44830. });
  44831. } else {
  44832. return replacement(...match, match.index, str, match.groups);
  44833. }
  44834. }
  44835. function matchAll(re, str) {
  44836. let match;
  44837. const matches = [];
  44838. while ((match = re.exec(str))) {
  44839. matches.push(match);
  44840. }
  44841. return matches;
  44842. }
  44843. if (searchValue.global) {
  44844. const matches = matchAll(searchValue, this.original);
  44845. matches.forEach((match) => {
  44846. if (match.index != null) {
  44847. const replacement = getReplacement(match, this.original);
  44848. if (replacement !== match[0]) {
  44849. this.overwrite(match.index, match.index + match[0].length, replacement);
  44850. }
  44851. }
  44852. });
  44853. } else {
  44854. const match = this.original.match(searchValue);
  44855. if (match && match.index != null) {
  44856. const replacement = getReplacement(match, this.original);
  44857. if (replacement !== match[0]) {
  44858. this.overwrite(match.index, match.index + match[0].length, replacement);
  44859. }
  44860. }
  44861. }
  44862. return this;
  44863. }
  44864. _replaceString(string, replacement) {
  44865. const { original } = this;
  44866. const index = original.indexOf(string);
  44867. if (index !== -1) {
  44868. if (typeof replacement === 'function') {
  44869. replacement = replacement(string, index, original);
  44870. }
  44871. if (string !== replacement) {
  44872. this.overwrite(index, index + string.length, replacement);
  44873. }
  44874. }
  44875. return this;
  44876. }
  44877. replace(searchValue, replacement) {
  44878. if (typeof searchValue === 'string') {
  44879. return this._replaceString(searchValue, replacement);
  44880. }
  44881. return this._replaceRegexp(searchValue, replacement);
  44882. }
  44883. _replaceAllString(string, replacement) {
  44884. const { original } = this;
  44885. const stringLength = string.length;
  44886. for (
  44887. let index = original.indexOf(string);
  44888. index !== -1;
  44889. index = original.indexOf(string, index + stringLength)
  44890. ) {
  44891. const previous = original.slice(index, index + stringLength);
  44892. let _replacement = replacement;
  44893. if (typeof replacement === 'function') {
  44894. _replacement = replacement(previous, index, original);
  44895. }
  44896. if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
  44897. }
  44898. return this;
  44899. }
  44900. replaceAll(searchValue, replacement) {
  44901. if (typeof searchValue === 'string') {
  44902. return this._replaceAllString(searchValue, replacement);
  44903. }
  44904. if (!searchValue.global) {
  44905. throw new TypeError(
  44906. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  44907. );
  44908. }
  44909. return this._replaceRegexp(searchValue, replacement);
  44910. }
  44911. }
  44912. var _a, _b;
  44913. class ScriptCompileContext {
  44914. constructor(descriptor, options) {
  44915. this.descriptor = descriptor;
  44916. this.options = options;
  44917. this.isCE = false;
  44918. this.source = this.descriptor.source;
  44919. this.filename = this.descriptor.filename;
  44920. this.s = new MagicString(this.source);
  44921. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44922. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44923. this.userImports = /* @__PURE__ */ Object.create(null);
  44924. // macros presence check
  44925. this.hasDefinePropsCall = false;
  44926. this.hasDefineEmitCall = false;
  44927. this.hasDefineExposeCall = false;
  44928. this.hasDefaultExportName = false;
  44929. this.hasDefaultExportRender = false;
  44930. this.hasDefineOptionsCall = false;
  44931. this.hasDefineSlotsCall = false;
  44932. this.hasDefineModelCall = false;
  44933. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44934. // defineModel
  44935. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44936. // codegen
  44937. this.bindingMetadata = {};
  44938. this.helperImports = /* @__PURE__ */ new Set();
  44939. const { script, scriptSetup } = descriptor;
  44940. const scriptLang = script && script.lang;
  44941. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44942. this.isJS = isJS(scriptLang, scriptSetupLang);
  44943. this.isTS = isTS(scriptLang, scriptSetupLang);
  44944. const customElement = options.customElement;
  44945. const filename = this.descriptor.filename;
  44946. if (customElement) {
  44947. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44948. }
  44949. const plugins = resolveParserPlugins(
  44950. scriptLang || scriptSetupLang,
  44951. options.babelParserPlugins
  44952. );
  44953. function parse(input, offset) {
  44954. try {
  44955. return libExports.parse(input, {
  44956. plugins,
  44957. sourceType: "module"
  44958. }).program;
  44959. } catch (e) {
  44960. e.message = `[vue/compiler-sfc] ${e.message}
  44961. ${descriptor.filename}
  44962. ${generateCodeFrame(
  44963. descriptor.source,
  44964. e.pos + offset,
  44965. e.pos + offset + 1
  44966. )}`;
  44967. throw e;
  44968. }
  44969. }
  44970. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44971. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44972. }
  44973. helper(key) {
  44974. this.helperImports.add(key);
  44975. return `_${key}`;
  44976. }
  44977. getString(node, scriptSetup = true) {
  44978. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44979. return block.content.slice(node.start, node.end);
  44980. }
  44981. warn(msg, node, scope) {
  44982. warn(generateError(msg, node, this, scope));
  44983. }
  44984. error(msg, node, scope) {
  44985. throw new Error(
  44986. `[@vue/compiler-sfc] ${generateError(msg, node, this, scope)}`
  44987. );
  44988. }
  44989. }
  44990. function generateError(msg, node, ctx, scope) {
  44991. const offset = scope ? scope.offset : ctx.startOffset;
  44992. return `${msg}
  44993. ${(scope || ctx.descriptor).filename}
  44994. ${generateCodeFrame(
  44995. (scope || ctx.descriptor).source,
  44996. node.start + offset,
  44997. node.end + offset
  44998. )}`;
  44999. }
  45000. function resolveParserPlugins(lang, userPlugins, dts = false) {
  45001. const plugins = [];
  45002. if (!userPlugins || !userPlugins.some(
  45003. (p) => p === "importAssertions" || p === "importAttributes" || isArray$3(p) && p[0] === "importAttributes"
  45004. )) {
  45005. plugins.push("importAttributes");
  45006. }
  45007. if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
  45008. plugins.push("jsx");
  45009. } else if (userPlugins) {
  45010. userPlugins = userPlugins.filter((p) => p !== "jsx");
  45011. }
  45012. if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "cts" || lang === "mtsx") {
  45013. plugins.push(["typescript", { dts }], "explicitResourceManagement");
  45014. if (!userPlugins || !userPlugins.includes("decorators")) {
  45015. plugins.push("decorators-legacy");
  45016. }
  45017. }
  45018. if (userPlugins) {
  45019. plugins.push(...userPlugins);
  45020. }
  45021. return plugins;
  45022. }
  45023. function rewriteDefault(input, as, parserPlugins) {
  45024. const ast = libExports.parse(input, {
  45025. sourceType: "module",
  45026. plugins: resolveParserPlugins("js", parserPlugins)
  45027. }).program.body;
  45028. const s = new MagicString(input);
  45029. rewriteDefaultAST(ast, s, as);
  45030. return s.toString();
  45031. }
  45032. function rewriteDefaultAST(ast, s, as) {
  45033. if (!hasDefaultExport(ast)) {
  45034. s.append(`
  45035. const ${as} = {}`);
  45036. return;
  45037. }
  45038. ast.forEach((node) => {
  45039. if (node.type === "ExportDefaultDeclaration") {
  45040. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  45041. const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  45042. s.overwrite(start, node.declaration.id.start, ` class `);
  45043. s.append(`
  45044. const ${as} = ${node.declaration.id.name}`);
  45045. } else {
  45046. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  45047. }
  45048. } else if (node.type === "ExportNamedDeclaration") {
  45049. for (const specifier of node.specifiers) {
  45050. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  45051. if (node.source) {
  45052. if (specifier.local.name === "default") {
  45053. s.prepend(
  45054. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  45055. `
  45056. );
  45057. const end2 = specifierEnd(s, specifier.local.end, node.end);
  45058. s.remove(specifier.start, end2);
  45059. s.append(`
  45060. const ${as} = __VUE_DEFAULT__`);
  45061. continue;
  45062. } else {
  45063. s.prepend(
  45064. `import { ${s.slice(
  45065. specifier.local.start,
  45066. specifier.local.end
  45067. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  45068. `
  45069. );
  45070. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  45071. s.remove(specifier.start, end2);
  45072. s.append(`
  45073. const ${as} = __VUE_DEFAULT__`);
  45074. continue;
  45075. }
  45076. }
  45077. const end = specifierEnd(s, specifier.end, node.end);
  45078. s.remove(specifier.start, end);
  45079. s.append(`
  45080. const ${as} = ${specifier.local.name}`);
  45081. }
  45082. }
  45083. }
  45084. });
  45085. }
  45086. function hasDefaultExport(ast) {
  45087. for (const stmt of ast) {
  45088. if (stmt.type === "ExportDefaultDeclaration") {
  45089. return true;
  45090. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  45091. (spec) => spec.exported.name === "default"
  45092. )) {
  45093. return true;
  45094. }
  45095. }
  45096. return false;
  45097. }
  45098. function specifierEnd(s, end, nodeEnd) {
  45099. let hasCommas = false;
  45100. let oldEnd = end;
  45101. while (end < nodeEnd) {
  45102. if (/\s/.test(s.slice(end, end + 1))) {
  45103. end++;
  45104. } else if (s.slice(end, end + 1) === ",") {
  45105. end++;
  45106. hasCommas = true;
  45107. break;
  45108. } else if (s.slice(end, end + 1) === "}") {
  45109. break;
  45110. }
  45111. }
  45112. return hasCommas ? end : oldEnd;
  45113. }
  45114. var __defProp$3 = Object.defineProperty;
  45115. var __defProps$2 = Object.defineProperties;
  45116. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  45117. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  45118. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  45119. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  45120. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45121. var __spreadValues$3 = (a, b) => {
  45122. for (var prop in b || (b = {}))
  45123. if (__hasOwnProp$3.call(b, prop))
  45124. __defNormalProp$3(a, prop, b[prop]);
  45125. if (__getOwnPropSymbols$3)
  45126. for (var prop of __getOwnPropSymbols$3(b)) {
  45127. if (__propIsEnum$3.call(b, prop))
  45128. __defNormalProp$3(a, prop, b[prop]);
  45129. }
  45130. return a;
  45131. };
  45132. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  45133. const normalScriptDefaultVar = `__default__`;
  45134. function processNormalScript(ctx, scopeId) {
  45135. var _a;
  45136. const script = ctx.descriptor.script;
  45137. try {
  45138. let content = script.content;
  45139. let map = script.map;
  45140. const scriptAst = ctx.scriptAst;
  45141. const bindings = analyzeScriptBindings(scriptAst.body);
  45142. const { cssVars } = ctx.descriptor;
  45143. const { genDefaultAs, isProd } = ctx.options;
  45144. if (cssVars.length || genDefaultAs) {
  45145. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  45146. const s = new MagicString(content);
  45147. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  45148. content = s.toString();
  45149. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  45150. content += genNormalScriptCssVarsCode(
  45151. cssVars,
  45152. bindings,
  45153. scopeId,
  45154. !!isProd,
  45155. defaultVar
  45156. );
  45157. }
  45158. if (!genDefaultAs) {
  45159. content += `
  45160. export default ${defaultVar}`;
  45161. }
  45162. }
  45163. return __spreadProps$2(__spreadValues$3({}, script), {
  45164. content,
  45165. map,
  45166. bindings,
  45167. scriptAst: scriptAst.body
  45168. });
  45169. } catch (e) {
  45170. return script;
  45171. }
  45172. }
  45173. var __defProp$2 = Object.defineProperty;
  45174. var __defProps$1 = Object.defineProperties;
  45175. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  45176. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  45177. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  45178. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  45179. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  45180. var __spreadValues$2 = (a, b) => {
  45181. for (var prop in b || (b = {}))
  45182. if (__hasOwnProp$2.call(b, prop))
  45183. __defNormalProp$2(a, prop, b[prop]);
  45184. if (__getOwnPropSymbols$2)
  45185. for (var prop of __getOwnPropSymbols$2(b)) {
  45186. if (__propIsEnum$2.call(b, prop))
  45187. __defNormalProp$2(a, prop, b[prop]);
  45188. }
  45189. return a;
  45190. };
  45191. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  45192. class TypeScope {
  45193. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  45194. this.filename = filename;
  45195. this.source = source;
  45196. this.offset = offset;
  45197. this.imports = imports;
  45198. this.types = types;
  45199. this.declares = declares;
  45200. this.isGenericScope = false;
  45201. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  45202. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  45203. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  45204. }
  45205. }
  45206. function resolveTypeElements(ctx, node, scope, typeParameters) {
  45207. const canCache = !typeParameters;
  45208. if (canCache && node._resolvedElements) {
  45209. return node._resolvedElements;
  45210. }
  45211. const resolved = innerResolveTypeElements(
  45212. ctx,
  45213. node,
  45214. node._ownerScope || scope || ctxToScope(ctx),
  45215. typeParameters
  45216. );
  45217. return canCache ? node._resolvedElements = resolved : resolved;
  45218. }
  45219. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  45220. var _a, _b;
  45221. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  45222. return { props: {} };
  45223. }
  45224. switch (node.type) {
  45225. case "TSTypeLiteral":
  45226. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  45227. case "TSInterfaceDeclaration":
  45228. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  45229. case "TSTypeAliasDeclaration":
  45230. case "TSTypeAnnotation":
  45231. case "TSParenthesizedType":
  45232. return resolveTypeElements(
  45233. ctx,
  45234. node.typeAnnotation,
  45235. scope,
  45236. typeParameters
  45237. );
  45238. case "TSFunctionType": {
  45239. return { props: {}, calls: [node] };
  45240. }
  45241. case "TSUnionType":
  45242. case "TSIntersectionType":
  45243. return mergeElements(
  45244. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  45245. node.type
  45246. );
  45247. case "TSMappedType":
  45248. return resolveMappedType(ctx, node, scope, typeParameters);
  45249. case "TSIndexedAccessType": {
  45250. const types = resolveIndexType(ctx, node, scope);
  45251. return mergeElements(
  45252. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  45253. "TSUnionType"
  45254. );
  45255. }
  45256. case "TSExpressionWithTypeArguments":
  45257. // referenced by interface extends
  45258. case "TSTypeReference": {
  45259. const typeName = getReferenceName(node);
  45260. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  45261. return resolveExtractPropTypes(
  45262. resolveTypeElements(
  45263. ctx,
  45264. node.typeParameters.params[0],
  45265. scope,
  45266. typeParameters
  45267. ),
  45268. scope
  45269. );
  45270. }
  45271. const resolved = resolveTypeReference(ctx, node, scope);
  45272. if (resolved) {
  45273. let typeParams;
  45274. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  45275. typeParams = /* @__PURE__ */ Object.create(null);
  45276. resolved.typeParameters.params.forEach((p, i) => {
  45277. let param = typeParameters && typeParameters[p.name];
  45278. if (!param) param = node.typeParameters.params[i];
  45279. typeParams[p.name] = param;
  45280. });
  45281. }
  45282. return resolveTypeElements(
  45283. ctx,
  45284. resolved,
  45285. resolved._ownerScope,
  45286. typeParams
  45287. );
  45288. } else {
  45289. if (typeof typeName === "string") {
  45290. if (typeParameters && typeParameters[typeName]) {
  45291. return resolveTypeElements(
  45292. ctx,
  45293. typeParameters[typeName],
  45294. scope,
  45295. typeParameters
  45296. );
  45297. }
  45298. if (
  45299. // @ts-expect-error
  45300. SupportedBuiltinsSet.has(typeName)
  45301. ) {
  45302. return resolveBuiltin(
  45303. ctx,
  45304. node,
  45305. typeName,
  45306. scope,
  45307. typeParameters
  45308. );
  45309. } else if (typeName === "ReturnType" && node.typeParameters) {
  45310. const ret = resolveReturnType(
  45311. ctx,
  45312. node.typeParameters.params[0],
  45313. scope
  45314. );
  45315. if (ret) {
  45316. return resolveTypeElements(ctx, ret, scope);
  45317. }
  45318. }
  45319. }
  45320. return ctx.error(
  45321. `Unresolvable type reference or unsupported built-in utility type`,
  45322. node,
  45323. scope
  45324. );
  45325. }
  45326. }
  45327. case "TSImportType": {
  45328. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  45329. return resolveExtractPropTypes(
  45330. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  45331. scope
  45332. );
  45333. }
  45334. const sourceScope = importSourceToScope(
  45335. ctx,
  45336. node.argument,
  45337. scope,
  45338. node.argument.value
  45339. );
  45340. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45341. if (resolved) {
  45342. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45343. }
  45344. break;
  45345. }
  45346. case "TSTypeQuery":
  45347. {
  45348. const resolved = resolveTypeReference(ctx, node, scope);
  45349. if (resolved) {
  45350. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45351. }
  45352. }
  45353. break;
  45354. }
  45355. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  45356. }
  45357. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  45358. const res = { props: {} };
  45359. for (const e of elements) {
  45360. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  45361. if (typeParameters) {
  45362. scope = createChildScope(scope);
  45363. scope.isGenericScope = true;
  45364. Object.assign(scope.types, typeParameters);
  45365. }
  45366. e._ownerScope = scope;
  45367. const name = getStringLiteralKey(e);
  45368. if (name !== null) {
  45369. res.props[name] = e;
  45370. } else {
  45371. ctx.error(
  45372. `Unsupported computed key in type referenced by a macro`,
  45373. e.key,
  45374. scope
  45375. );
  45376. }
  45377. } else if (e.type === "TSCallSignatureDeclaration") {
  45378. (res.calls || (res.calls = [])).push(e);
  45379. }
  45380. }
  45381. return res;
  45382. }
  45383. function mergeElements(maps, type) {
  45384. if (maps.length === 1) return maps[0];
  45385. const res = { props: {} };
  45386. const { props: baseProps } = res;
  45387. for (const { props, calls } of maps) {
  45388. for (const key in props) {
  45389. if (!hasOwn(baseProps, key)) {
  45390. baseProps[key] = props[key];
  45391. } else {
  45392. baseProps[key] = createProperty(
  45393. baseProps[key].key,
  45394. {
  45395. type,
  45396. // @ts-expect-error
  45397. types: [baseProps[key], props[key]]
  45398. },
  45399. baseProps[key]._ownerScope,
  45400. baseProps[key].optional || props[key].optional
  45401. );
  45402. }
  45403. }
  45404. if (calls) {
  45405. (res.calls || (res.calls = [])).push(...calls);
  45406. }
  45407. }
  45408. return res;
  45409. }
  45410. function createProperty(key, typeAnnotation, scope, optional) {
  45411. return {
  45412. type: "TSPropertySignature",
  45413. key,
  45414. kind: "get",
  45415. optional,
  45416. typeAnnotation: {
  45417. type: "TSTypeAnnotation",
  45418. typeAnnotation
  45419. },
  45420. _ownerScope: scope
  45421. };
  45422. }
  45423. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  45424. const base = typeElementsToMap(
  45425. ctx,
  45426. node.body.body,
  45427. node._ownerScope,
  45428. typeParameters
  45429. );
  45430. if (node.extends) {
  45431. for (const ext of node.extends) {
  45432. try {
  45433. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  45434. for (const key in props) {
  45435. if (!hasOwn(base.props, key)) {
  45436. base.props[key] = props[key];
  45437. }
  45438. }
  45439. if (calls) {
  45440. ;
  45441. (base.calls || (base.calls = [])).push(...calls);
  45442. }
  45443. } catch (e) {
  45444. if (!ctx.silentOnExtendsFailure) {
  45445. ctx.error(
  45446. `Failed to resolve extends base type.
  45447. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  45448. interface Props extends /* @vue-ignore */ Base {}
  45449. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  45450. ext,
  45451. scope
  45452. );
  45453. }
  45454. }
  45455. }
  45456. }
  45457. return base;
  45458. }
  45459. function resolveMappedType(ctx, node, scope, typeParameters) {
  45460. const res = { props: {} };
  45461. let keys;
  45462. if (node.nameType) {
  45463. const { name, constraint } = node.typeParameter;
  45464. scope = createChildScope(scope);
  45465. Object.assign(scope.types, __spreadProps$1(__spreadValues$2({}, typeParameters), { [name]: constraint }));
  45466. keys = resolveStringType(ctx, node.nameType, scope);
  45467. } else {
  45468. keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  45469. }
  45470. for (const key of keys) {
  45471. res.props[key] = createProperty(
  45472. {
  45473. type: "Identifier",
  45474. name: key
  45475. },
  45476. node.typeAnnotation,
  45477. scope,
  45478. !!node.optional
  45479. );
  45480. }
  45481. return res;
  45482. }
  45483. function resolveIndexType(ctx, node, scope) {
  45484. var _a, _b;
  45485. if (node.indexType.type === "TSNumberKeyword") {
  45486. return resolveArrayElementType(ctx, node.objectType, scope);
  45487. }
  45488. const { indexType, objectType } = node;
  45489. const types = [];
  45490. let keys;
  45491. let resolved;
  45492. if (indexType.type === "TSStringKeyword") {
  45493. resolved = resolveTypeElements(ctx, objectType, scope);
  45494. keys = Object.keys(resolved.props);
  45495. } else {
  45496. keys = resolveStringType(ctx, indexType, scope);
  45497. resolved = resolveTypeElements(ctx, objectType, scope);
  45498. }
  45499. for (const key of keys) {
  45500. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45501. if (targetType) {
  45502. targetType._ownerScope = resolved.props[key]._ownerScope;
  45503. types.push(targetType);
  45504. }
  45505. }
  45506. return types;
  45507. }
  45508. function resolveArrayElementType(ctx, node, scope) {
  45509. if (node.type === "TSArrayType") {
  45510. return [node.elementType];
  45511. }
  45512. if (node.type === "TSTupleType") {
  45513. return node.elementTypes.map(
  45514. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45515. );
  45516. }
  45517. if (node.type === "TSTypeReference") {
  45518. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45519. return node.typeParameters.params;
  45520. } else {
  45521. const resolved = resolveTypeReference(ctx, node, scope);
  45522. if (resolved) {
  45523. return resolveArrayElementType(ctx, resolved, scope);
  45524. }
  45525. }
  45526. }
  45527. return ctx.error(
  45528. "Failed to resolve element type from target type",
  45529. node,
  45530. scope
  45531. );
  45532. }
  45533. function resolveStringType(ctx, node, scope, typeParameters) {
  45534. switch (node.type) {
  45535. case "StringLiteral":
  45536. return [node.value];
  45537. case "TSLiteralType":
  45538. return resolveStringType(ctx, node.literal, scope, typeParameters);
  45539. case "TSUnionType":
  45540. return node.types.map((t) => resolveStringType(ctx, t, scope, typeParameters)).flat();
  45541. case "TemplateLiteral": {
  45542. return resolveTemplateKeys(ctx, node, scope);
  45543. }
  45544. case "TSTypeReference": {
  45545. const resolved = resolveTypeReference(ctx, node, scope);
  45546. if (resolved) {
  45547. return resolveStringType(ctx, resolved, scope, typeParameters);
  45548. }
  45549. if (node.typeName.type === "Identifier") {
  45550. const name = node.typeName.name;
  45551. if (typeParameters && typeParameters[name]) {
  45552. return resolveStringType(
  45553. ctx,
  45554. typeParameters[name],
  45555. scope,
  45556. typeParameters
  45557. );
  45558. }
  45559. const getParam = (index = 0) => resolveStringType(
  45560. ctx,
  45561. node.typeParameters.params[index],
  45562. scope,
  45563. typeParameters
  45564. );
  45565. switch (name) {
  45566. case "Extract":
  45567. return getParam(1);
  45568. case "Exclude": {
  45569. const excluded = getParam(1);
  45570. return getParam().filter((s) => !excluded.includes(s));
  45571. }
  45572. case "Uppercase":
  45573. return getParam().map((s) => s.toUpperCase());
  45574. case "Lowercase":
  45575. return getParam().map((s) => s.toLowerCase());
  45576. case "Capitalize":
  45577. return getParam().map(capitalize);
  45578. case "Uncapitalize":
  45579. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45580. default:
  45581. ctx.error(
  45582. "Unsupported type when resolving index type",
  45583. node.typeName,
  45584. scope
  45585. );
  45586. }
  45587. }
  45588. }
  45589. }
  45590. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45591. }
  45592. function resolveTemplateKeys(ctx, node, scope) {
  45593. if (!node.expressions.length) {
  45594. return [node.quasis[0].value.raw];
  45595. }
  45596. const res = [];
  45597. const e = node.expressions[0];
  45598. const q = node.quasis[0];
  45599. const leading = q ? q.value.raw : ``;
  45600. const resolved = resolveStringType(ctx, e, scope);
  45601. const restResolved = resolveTemplateKeys(
  45602. ctx,
  45603. __spreadProps$1(__spreadValues$2({}, node), {
  45604. expressions: node.expressions.slice(1),
  45605. quasis: q ? node.quasis.slice(1) : node.quasis
  45606. }),
  45607. scope
  45608. );
  45609. for (const r of resolved) {
  45610. for (const rr of restResolved) {
  45611. res.push(leading + r + rr);
  45612. }
  45613. }
  45614. return res;
  45615. }
  45616. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45617. "Partial",
  45618. "Required",
  45619. "Readonly",
  45620. "Pick",
  45621. "Omit"
  45622. ]);
  45623. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45624. const t = resolveTypeElements(
  45625. ctx,
  45626. node.typeParameters.params[0],
  45627. scope,
  45628. typeParameters
  45629. );
  45630. switch (name) {
  45631. case "Partial": {
  45632. const res2 = { props: {}, calls: t.calls };
  45633. Object.keys(t.props).forEach((key) => {
  45634. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: true });
  45635. });
  45636. return res2;
  45637. }
  45638. case "Required": {
  45639. const res2 = { props: {}, calls: t.calls };
  45640. Object.keys(t.props).forEach((key) => {
  45641. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: false });
  45642. });
  45643. return res2;
  45644. }
  45645. case "Readonly":
  45646. return t;
  45647. case "Pick": {
  45648. const picked = resolveStringType(
  45649. ctx,
  45650. node.typeParameters.params[1],
  45651. scope,
  45652. typeParameters
  45653. );
  45654. const res2 = { props: {}, calls: t.calls };
  45655. for (const key of picked) {
  45656. res2.props[key] = t.props[key];
  45657. }
  45658. return res2;
  45659. }
  45660. case "Omit":
  45661. const omitted = resolveStringType(
  45662. ctx,
  45663. node.typeParameters.params[1],
  45664. scope,
  45665. typeParameters
  45666. );
  45667. const res = { props: {}, calls: t.calls };
  45668. for (const key in t.props) {
  45669. if (!omitted.includes(key)) {
  45670. res.props[key] = t.props[key];
  45671. }
  45672. }
  45673. return res;
  45674. }
  45675. }
  45676. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45677. const canCache = !(scope == null ? void 0 : scope.isGenericScope);
  45678. if (canCache && node._resolvedReference) {
  45679. return node._resolvedReference;
  45680. }
  45681. const resolved = innerResolveTypeReference(
  45682. ctx,
  45683. scope || ctxToScope(ctx),
  45684. name || getReferenceName(node),
  45685. node,
  45686. onlyExported
  45687. );
  45688. return canCache ? node._resolvedReference = resolved : resolved;
  45689. }
  45690. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45691. if (typeof name === "string") {
  45692. if (scope.imports[name]) {
  45693. return resolveTypeFromImport(ctx, node, name, scope);
  45694. } else {
  45695. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45696. if (lookupSource[name]) {
  45697. return lookupSource[name];
  45698. } else {
  45699. const globalScopes = resolveGlobalScope(ctx);
  45700. if (globalScopes) {
  45701. for (const s of globalScopes) {
  45702. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45703. if (src[name]) {
  45704. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45705. return src[name];
  45706. }
  45707. }
  45708. }
  45709. }
  45710. }
  45711. } else {
  45712. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45713. if (ns) {
  45714. if (ns.type !== "TSModuleDeclaration") {
  45715. ns = ns._ns;
  45716. }
  45717. if (ns) {
  45718. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45719. return innerResolveTypeReference(
  45720. ctx,
  45721. childScope,
  45722. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45723. node,
  45724. !ns.declare
  45725. );
  45726. }
  45727. }
  45728. }
  45729. }
  45730. function getReferenceName(node) {
  45731. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45732. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45733. return ref.name;
  45734. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45735. return qualifiedNameToPath(ref);
  45736. } else {
  45737. return "default";
  45738. }
  45739. }
  45740. function qualifiedNameToPath(node) {
  45741. if (node.type === "Identifier") {
  45742. return [node.name];
  45743. } else {
  45744. return [...qualifiedNameToPath(node.left), node.right.name];
  45745. }
  45746. }
  45747. function resolveGlobalScope(ctx) {
  45748. if (ctx.options.globalTypeFiles) {
  45749. const fs = resolveFS(ctx);
  45750. if (!fs) {
  45751. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45752. }
  45753. return ctx.options.globalTypeFiles.map(
  45754. (file) => fileToScope(ctx, normalizePath(file), true)
  45755. );
  45756. }
  45757. }
  45758. let ts;
  45759. let loadTS;
  45760. function registerTS(_loadTS) {
  45761. loadTS = () => {
  45762. try {
  45763. return _loadTS();
  45764. } catch (err) {
  45765. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45766. throw new Error(
  45767. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
  45768. );
  45769. } else {
  45770. throw new Error(
  45771. "Failed to load TypeScript for resolving imported types."
  45772. );
  45773. }
  45774. }
  45775. };
  45776. }
  45777. function resolveFS(ctx) {
  45778. if (ctx.fs) {
  45779. return ctx.fs;
  45780. }
  45781. if (!ts && loadTS) {
  45782. ts = loadTS();
  45783. }
  45784. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45785. if (!fs) {
  45786. return;
  45787. }
  45788. return ctx.fs = {
  45789. fileExists(file) {
  45790. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45791. file = file.replace(/\.ts$/, "");
  45792. }
  45793. return fs.fileExists(file);
  45794. },
  45795. readFile(file) {
  45796. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45797. file = file.replace(/\.ts$/, "");
  45798. }
  45799. return fs.readFile(file);
  45800. },
  45801. realpath: fs.realpath
  45802. };
  45803. }
  45804. function resolveTypeFromImport(ctx, node, name, scope) {
  45805. const { source, imported } = scope.imports[name];
  45806. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45807. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45808. }
  45809. function importSourceToScope(ctx, node, scope, source) {
  45810. let fs;
  45811. try {
  45812. fs = resolveFS(ctx);
  45813. } catch (err) {
  45814. return ctx.error(err.message, node, scope);
  45815. }
  45816. if (!fs) {
  45817. return ctx.error(
  45818. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45819. node,
  45820. scope
  45821. );
  45822. }
  45823. let resolved = scope.resolvedImportSources[source];
  45824. if (!resolved) {
  45825. if (source.startsWith("..")) {
  45826. const osSpecificJoinFn = joinPaths;
  45827. const filename = osSpecificJoinFn(dirname(scope.filename), source);
  45828. resolved = resolveExt(filename, fs);
  45829. } else if (source[0] === ".") {
  45830. const filename = joinPaths(dirname(scope.filename), source);
  45831. resolved = resolveExt(filename, fs);
  45832. } else {
  45833. {
  45834. return ctx.error(
  45835. `Type import from non-relative sources is not supported in the browser build.`,
  45836. node,
  45837. scope
  45838. );
  45839. }
  45840. }
  45841. if (resolved) {
  45842. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45843. }
  45844. }
  45845. if (resolved) {
  45846. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45847. return fileToScope(ctx, resolved);
  45848. } else {
  45849. return ctx.error(
  45850. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45851. node,
  45852. scope
  45853. );
  45854. }
  45855. }
  45856. function resolveExt(filename, fs) {
  45857. let moduleType = "u";
  45858. if (filename.endsWith(".mjs")) {
  45859. moduleType = "m";
  45860. } else if (filename.endsWith(".cjs")) {
  45861. moduleType = "c";
  45862. }
  45863. filename = filename.replace(/\.[cm]?jsx?$/, "");
  45864. const tryResolve = (filename2) => {
  45865. if (fs.fileExists(filename2)) return filename2;
  45866. };
  45867. const resolveTs = () => tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`);
  45868. const resolveMts = () => tryResolve(filename + `.mts`) || tryResolve(filename + `.d.mts`);
  45869. const resolveCts = () => tryResolve(filename + `.cts`) || tryResolve(filename + `.d.cts`);
  45870. return tryResolve(filename) || // For explicit .mjs/.cjs imports, prefer .mts/.cts declarations first.
  45871. (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`));
  45872. }
  45873. const tsConfigCache = createCache();
  45874. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45875. const fileToScopeCache = createCache();
  45876. function invalidateTypeCache(filename) {
  45877. filename = normalizePath(filename);
  45878. fileToScopeCache.delete(filename);
  45879. tsConfigCache.delete(filename);
  45880. const affectedConfig = tsConfigRefMap.get(filename);
  45881. if (affectedConfig) tsConfigCache.delete(affectedConfig);
  45882. }
  45883. function fileToScope(ctx, filename, asGlobal = false) {
  45884. const cached = fileToScopeCache.get(filename);
  45885. if (cached) {
  45886. return cached;
  45887. }
  45888. const fs = resolveFS(ctx);
  45889. const source = fs.readFile(filename) || "";
  45890. const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
  45891. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45892. recordTypes(ctx, body, scope, asGlobal);
  45893. fileToScopeCache.set(filename, scope);
  45894. return scope;
  45895. }
  45896. function parseFile(filename, content, fs, parserPlugins) {
  45897. const ext = extname(filename);
  45898. if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".cts" || ext === ".mtsx") {
  45899. return libExports.parse(content, {
  45900. plugins: resolveParserPlugins(
  45901. ext.slice(1),
  45902. parserPlugins,
  45903. /\.d\.[cm]?ts$/.test(filename)
  45904. ),
  45905. sourceType: "module"
  45906. }).program.body;
  45907. }
  45908. const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
  45909. const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
  45910. const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
  45911. if (hasArbitraryTypeDeclaration) {
  45912. return libExports.parse(fs.readFile(arbitraryTypeSource), {
  45913. plugins: resolveParserPlugins("ts", parserPlugins, true),
  45914. sourceType: "module"
  45915. }).program.body;
  45916. }
  45917. if (ext === ".vue") {
  45918. const {
  45919. descriptor: { script, scriptSetup }
  45920. } = parse$2(content);
  45921. if (!script && !scriptSetup) {
  45922. return [];
  45923. }
  45924. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45925. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45926. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45927. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45928. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45929. if (secondBlock) {
  45930. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45931. }
  45932. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45933. return libExports.parse(scriptContent, {
  45934. plugins: resolveParserPlugins(lang, parserPlugins),
  45935. sourceType: "module"
  45936. }).program.body;
  45937. }
  45938. return [];
  45939. }
  45940. function ctxToScope(ctx) {
  45941. if (ctx.scope) {
  45942. return ctx.scope;
  45943. }
  45944. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45945. const scope = new TypeScope(
  45946. ctx.filename,
  45947. ctx.source,
  45948. "startOffset" in ctx ? ctx.startOffset : 0,
  45949. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45950. );
  45951. recordTypes(ctx, body, scope);
  45952. return ctx.scope = scope;
  45953. }
  45954. function moduleDeclToScope(ctx, node, parentScope) {
  45955. if (node._resolvedChildScope) {
  45956. return node._resolvedChildScope;
  45957. }
  45958. const scope = createChildScope(parentScope);
  45959. if (node.body.type === "TSModuleDeclaration") {
  45960. const decl = node.body;
  45961. decl._ownerScope = scope;
  45962. const id = getId(decl.id);
  45963. scope.types[id] = scope.exportedTypes[id] = decl;
  45964. } else {
  45965. recordTypes(ctx, node.body.body, scope);
  45966. }
  45967. return node._resolvedChildScope = scope;
  45968. }
  45969. function createChildScope(parentScope) {
  45970. return new TypeScope(
  45971. parentScope.filename,
  45972. parentScope.source,
  45973. parentScope.offset,
  45974. Object.create(parentScope.imports),
  45975. Object.create(parentScope.types),
  45976. Object.create(parentScope.declares)
  45977. );
  45978. }
  45979. const importExportRE = /^Import|^Export/;
  45980. function recordTypes(ctx, body, scope, asGlobal = false) {
  45981. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45982. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45983. for (const stmt of body) {
  45984. if (asGlobal) {
  45985. if (isAmbient) {
  45986. if (stmt.declare) {
  45987. recordType(stmt, types, declares);
  45988. }
  45989. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45990. for (const s of stmt.body.body) {
  45991. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  45992. recordType(s.declaration, types, declares);
  45993. } else {
  45994. recordType(s, types, declares);
  45995. }
  45996. }
  45997. }
  45998. } else {
  45999. recordType(stmt, types, declares);
  46000. }
  46001. }
  46002. if (!asGlobal) {
  46003. for (const stmt of body) {
  46004. if (stmt.type === "ExportNamedDeclaration") {
  46005. if (stmt.declaration) {
  46006. recordType(stmt.declaration, types, declares);
  46007. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  46008. } else {
  46009. for (const spec of stmt.specifiers) {
  46010. if (spec.type === "ExportSpecifier") {
  46011. const local = spec.local.name;
  46012. const exported = getId(spec.exported);
  46013. if (stmt.source) {
  46014. imports[exported] = {
  46015. source: stmt.source.value,
  46016. imported: local
  46017. };
  46018. exportedTypes[exported] = {
  46019. type: "TSTypeReference",
  46020. typeName: {
  46021. type: "Identifier",
  46022. name: local
  46023. },
  46024. _ownerScope: scope
  46025. };
  46026. } else if (types[local]) {
  46027. exportedTypes[exported] = types[local];
  46028. }
  46029. }
  46030. }
  46031. }
  46032. } else if (stmt.type === "ExportAllDeclaration") {
  46033. const sourceScope = importSourceToScope(
  46034. ctx,
  46035. stmt.source,
  46036. scope,
  46037. stmt.source.value
  46038. );
  46039. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  46040. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  46041. if (stmt.declaration.type !== "Identifier") {
  46042. recordType(stmt.declaration, types, declares, "default");
  46043. recordType(
  46044. stmt.declaration,
  46045. exportedTypes,
  46046. exportedDeclares,
  46047. "default"
  46048. );
  46049. } else if (types[stmt.declaration.name]) {
  46050. exportedTypes["default"] = types[stmt.declaration.name];
  46051. }
  46052. }
  46053. }
  46054. }
  46055. for (const key of Object.keys(types)) {
  46056. const node = types[key];
  46057. node._ownerScope = scope;
  46058. if (node._ns) node._ns._ownerScope = scope;
  46059. }
  46060. for (const key of Object.keys(declares)) {
  46061. declares[key]._ownerScope = scope;
  46062. }
  46063. }
  46064. function recordType(node, types, declares, overwriteId) {
  46065. switch (node.type) {
  46066. case "TSInterfaceDeclaration":
  46067. case "TSEnumDeclaration":
  46068. case "TSModuleDeclaration": {
  46069. if (node.type === "TSModuleDeclaration" && node.global) {
  46070. const body = node.body;
  46071. for (const s of body.body) {
  46072. if (s.type === "ExportNamedDeclaration" && s.declaration) {
  46073. recordType(s.declaration, types, declares);
  46074. } else {
  46075. recordType(s, types, declares);
  46076. }
  46077. }
  46078. break;
  46079. }
  46080. const id = overwriteId || getId(node.id);
  46081. let existing = types[id];
  46082. if (existing) {
  46083. if (node.type === "TSModuleDeclaration") {
  46084. if (existing.type === "TSModuleDeclaration") {
  46085. mergeNamespaces(existing, node);
  46086. } else {
  46087. attachNamespace(existing, node);
  46088. }
  46089. break;
  46090. }
  46091. if (existing.type === "TSModuleDeclaration") {
  46092. types[id] = node;
  46093. attachNamespace(node, existing);
  46094. break;
  46095. }
  46096. if (existing.type !== node.type) {
  46097. break;
  46098. }
  46099. if (node.type === "TSInterfaceDeclaration") {
  46100. existing.body.body.push(...node.body.body);
  46101. } else {
  46102. existing.members.push(...node.members);
  46103. }
  46104. } else {
  46105. types[id] = node;
  46106. }
  46107. break;
  46108. }
  46109. case "ClassDeclaration":
  46110. if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
  46111. break;
  46112. case "TSTypeAliasDeclaration":
  46113. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  46114. break;
  46115. case "TSDeclareFunction":
  46116. if (node.id) declares[node.id.name] = node;
  46117. break;
  46118. case "VariableDeclaration": {
  46119. if (node.declare) {
  46120. for (const decl of node.declarations) {
  46121. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  46122. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  46123. }
  46124. }
  46125. }
  46126. break;
  46127. }
  46128. }
  46129. }
  46130. function mergeNamespaces(to, from) {
  46131. const toBody = to.body;
  46132. const fromBody = from.body;
  46133. if (toBody.type === "TSModuleDeclaration") {
  46134. if (fromBody.type === "TSModuleDeclaration") {
  46135. mergeNamespaces(toBody, fromBody);
  46136. } else {
  46137. fromBody.body.push({
  46138. type: "ExportNamedDeclaration",
  46139. declaration: toBody,
  46140. exportKind: "type",
  46141. specifiers: []
  46142. });
  46143. }
  46144. } else if (fromBody.type === "TSModuleDeclaration") {
  46145. toBody.body.push({
  46146. type: "ExportNamedDeclaration",
  46147. declaration: fromBody,
  46148. exportKind: "type",
  46149. specifiers: []
  46150. });
  46151. } else {
  46152. toBody.body.push(...fromBody.body);
  46153. }
  46154. }
  46155. function attachNamespace(to, ns) {
  46156. if (!to._ns) {
  46157. to._ns = ns;
  46158. } else {
  46159. mergeNamespaces(to._ns, ns);
  46160. }
  46161. }
  46162. function recordImports(body) {
  46163. const imports = /* @__PURE__ */ Object.create(null);
  46164. for (const s of body) {
  46165. recordImport(s, imports);
  46166. }
  46167. return imports;
  46168. }
  46169. function recordImport(node, imports) {
  46170. if (node.type !== "ImportDeclaration") {
  46171. return;
  46172. }
  46173. for (const s of node.specifiers) {
  46174. imports[s.local.name] = {
  46175. imported: getImportedName(s),
  46176. source: node.source.value
  46177. };
  46178. }
  46179. }
  46180. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
  46181. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  46182. return [UNKNOWN_TYPE];
  46183. }
  46184. const prevSilent = ctx.silentOnExtendsFailure;
  46185. ctx.silentOnExtendsFailure = true;
  46186. try {
  46187. switch (node.type) {
  46188. case "TSStringKeyword":
  46189. return ["String"];
  46190. case "TSNumberKeyword":
  46191. return ["Number"];
  46192. case "TSBooleanKeyword":
  46193. return ["Boolean"];
  46194. case "TSObjectKeyword":
  46195. return ["Object"];
  46196. case "TSNullKeyword":
  46197. return ["null"];
  46198. case "TSTypeLiteral":
  46199. case "TSInterfaceDeclaration": {
  46200. const types = /* @__PURE__ */ new Set();
  46201. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  46202. for (const m of members) {
  46203. if (isKeyOf) {
  46204. if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
  46205. types.add("Number");
  46206. } else if (m.type === "TSIndexSignature") {
  46207. const annotation = m.parameters[0].typeAnnotation;
  46208. if (annotation && annotation.type !== "Noop") {
  46209. const type = inferRuntimeType(
  46210. ctx,
  46211. annotation.typeAnnotation,
  46212. scope
  46213. )[0];
  46214. if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
  46215. types.add(type);
  46216. }
  46217. } else {
  46218. types.add("String");
  46219. }
  46220. } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  46221. types.add("Function");
  46222. } else {
  46223. types.add("Object");
  46224. }
  46225. }
  46226. return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
  46227. }
  46228. case "TSPropertySignature":
  46229. if (node.typeAnnotation) {
  46230. return inferRuntimeType(
  46231. ctx,
  46232. node.typeAnnotation.typeAnnotation,
  46233. scope
  46234. );
  46235. }
  46236. break;
  46237. case "TSMethodSignature":
  46238. case "TSFunctionType":
  46239. return ["Function"];
  46240. case "TSArrayType":
  46241. case "TSTupleType":
  46242. return ["Array"];
  46243. case "TSLiteralType":
  46244. switch (node.literal.type) {
  46245. case "StringLiteral":
  46246. return ["String"];
  46247. case "BooleanLiteral":
  46248. return ["Boolean"];
  46249. case "NumericLiteral":
  46250. case "BigIntLiteral":
  46251. return ["Number"];
  46252. default:
  46253. return [UNKNOWN_TYPE];
  46254. }
  46255. case "TSTypeReference": {
  46256. const resolved = resolveTypeReference(ctx, node, scope);
  46257. if (resolved) {
  46258. if (resolved.type === "TSTypeAliasDeclaration") {
  46259. if (resolved.typeAnnotation.type === "TSFunctionType") {
  46260. return ["Function"];
  46261. }
  46262. if (node.typeParameters) {
  46263. const typeParams = /* @__PURE__ */ Object.create(null);
  46264. if (resolved.typeParameters) {
  46265. resolved.typeParameters.params.forEach((p, i) => {
  46266. typeParams[p.name] = node.typeParameters.params[i];
  46267. });
  46268. }
  46269. return inferRuntimeType(
  46270. ctx,
  46271. resolved.typeAnnotation,
  46272. resolved._ownerScope,
  46273. isKeyOf,
  46274. typeParams
  46275. );
  46276. }
  46277. }
  46278. return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
  46279. }
  46280. if (node.typeName.type === "Identifier") {
  46281. if (typeParameters && typeParameters[node.typeName.name]) {
  46282. return inferRuntimeType(
  46283. ctx,
  46284. typeParameters[node.typeName.name],
  46285. scope,
  46286. isKeyOf,
  46287. typeParameters
  46288. );
  46289. }
  46290. if (isKeyOf) {
  46291. switch (node.typeName.name) {
  46292. case "String":
  46293. case "Array":
  46294. case "ArrayLike":
  46295. case "Parameters":
  46296. case "ConstructorParameters":
  46297. case "ReadonlyArray":
  46298. return ["String", "Number"];
  46299. // TS built-in utility types
  46300. case "Record":
  46301. case "Partial":
  46302. case "Required":
  46303. case "Readonly":
  46304. if (node.typeParameters && node.typeParameters.params[0]) {
  46305. return inferRuntimeType(
  46306. ctx,
  46307. node.typeParameters.params[0],
  46308. scope,
  46309. true
  46310. );
  46311. }
  46312. break;
  46313. case "Pick":
  46314. case "Extract":
  46315. if (node.typeParameters && node.typeParameters.params[1]) {
  46316. return inferRuntimeType(
  46317. ctx,
  46318. node.typeParameters.params[1],
  46319. scope
  46320. );
  46321. }
  46322. break;
  46323. case "Function":
  46324. case "Object":
  46325. case "Set":
  46326. case "Map":
  46327. case "WeakSet":
  46328. case "WeakMap":
  46329. case "Date":
  46330. case "Promise":
  46331. case "Error":
  46332. case "Uppercase":
  46333. case "Lowercase":
  46334. case "Capitalize":
  46335. case "Uncapitalize":
  46336. case "ReadonlyMap":
  46337. case "ReadonlySet":
  46338. return ["String"];
  46339. }
  46340. } else {
  46341. switch (node.typeName.name) {
  46342. case "Array":
  46343. case "Function":
  46344. case "Object":
  46345. case "Set":
  46346. case "Map":
  46347. case "WeakSet":
  46348. case "WeakMap":
  46349. case "Date":
  46350. case "Promise":
  46351. case "Error":
  46352. return [node.typeName.name];
  46353. // TS built-in utility types
  46354. // https://www.typescriptlang.org/docs/handbook/utility-types.html
  46355. case "Partial":
  46356. case "Required":
  46357. case "Readonly":
  46358. case "Record":
  46359. case "Pick":
  46360. case "Omit":
  46361. case "InstanceType":
  46362. return ["Object"];
  46363. case "Uppercase":
  46364. case "Lowercase":
  46365. case "Capitalize":
  46366. case "Uncapitalize":
  46367. return ["String"];
  46368. case "Parameters":
  46369. case "ConstructorParameters":
  46370. case "ReadonlyArray":
  46371. return ["Array"];
  46372. case "ReadonlyMap":
  46373. return ["Map"];
  46374. case "ReadonlySet":
  46375. return ["Set"];
  46376. case "NonNullable":
  46377. if (node.typeParameters && node.typeParameters.params[0]) {
  46378. return inferRuntimeType(
  46379. ctx,
  46380. node.typeParameters.params[0],
  46381. scope
  46382. ).filter((t) => t !== "null");
  46383. }
  46384. break;
  46385. case "Extract":
  46386. if (node.typeParameters && node.typeParameters.params[1]) {
  46387. return inferRuntimeType(
  46388. ctx,
  46389. node.typeParameters.params[1],
  46390. scope
  46391. );
  46392. }
  46393. break;
  46394. case "Exclude":
  46395. case "OmitThisParameter":
  46396. if (node.typeParameters && node.typeParameters.params[0]) {
  46397. return inferRuntimeType(
  46398. ctx,
  46399. node.typeParameters.params[0],
  46400. scope
  46401. );
  46402. }
  46403. break;
  46404. }
  46405. }
  46406. }
  46407. break;
  46408. }
  46409. case "TSParenthesizedType":
  46410. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  46411. case "TSUnionType":
  46412. return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
  46413. case "TSIntersectionType": {
  46414. return flattenTypes(
  46415. ctx,
  46416. node.types,
  46417. scope,
  46418. isKeyOf,
  46419. typeParameters
  46420. ).filter((t) => t !== UNKNOWN_TYPE);
  46421. }
  46422. case "TSMappedType": {
  46423. const { typeAnnotation, typeParameter } = node;
  46424. if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
  46425. const constraint = typeParameter.constraint;
  46426. if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
  46427. const typeName = constraint.typeAnnotation.typeName.name;
  46428. const index = typeAnnotation.indexType;
  46429. const obj = typeAnnotation.objectType;
  46430. 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) {
  46431. const targetType = typeParameters[typeName];
  46432. if (targetType) {
  46433. return inferRuntimeType(ctx, targetType, scope);
  46434. }
  46435. }
  46436. }
  46437. }
  46438. return [UNKNOWN_TYPE];
  46439. }
  46440. case "TSEnumDeclaration":
  46441. return inferEnumType(node);
  46442. case "TSSymbolKeyword":
  46443. return ["Symbol"];
  46444. case "TSIndexedAccessType": {
  46445. const types = resolveIndexType(ctx, node, scope);
  46446. return flattenTypes(ctx, types, scope, isKeyOf);
  46447. }
  46448. case "ClassDeclaration":
  46449. return ["Object"];
  46450. case "TSImportType": {
  46451. const sourceScope = importSourceToScope(
  46452. ctx,
  46453. node.argument,
  46454. scope,
  46455. node.argument.value
  46456. );
  46457. const resolved = resolveTypeReference(ctx, node, sourceScope);
  46458. if (resolved) {
  46459. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  46460. }
  46461. break;
  46462. }
  46463. case "TSTypeQuery": {
  46464. const id = node.exprName;
  46465. if (id.type === "Identifier") {
  46466. const matched = scope.declares[id.name];
  46467. if (matched) {
  46468. return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
  46469. }
  46470. }
  46471. break;
  46472. }
  46473. // e.g. readonly
  46474. case "TSTypeOperator": {
  46475. return inferRuntimeType(
  46476. ctx,
  46477. node.typeAnnotation,
  46478. scope,
  46479. node.operator === "keyof"
  46480. );
  46481. }
  46482. case "TSAnyKeyword": {
  46483. if (isKeyOf) {
  46484. return ["String", "Number", "Symbol"];
  46485. }
  46486. break;
  46487. }
  46488. }
  46489. } catch (e) {
  46490. } finally {
  46491. ctx.silentOnExtendsFailure = prevSilent;
  46492. }
  46493. return [UNKNOWN_TYPE];
  46494. }
  46495. function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
  46496. if (types.length === 1) {
  46497. return inferRuntimeType(
  46498. ctx,
  46499. types[0],
  46500. types[0]._ownerScope || scope,
  46501. isKeyOf,
  46502. typeParameters
  46503. );
  46504. }
  46505. return [
  46506. ...new Set(
  46507. [].concat(
  46508. ...types.map(
  46509. (t) => inferRuntimeType(
  46510. ctx,
  46511. t,
  46512. t._ownerScope || scope,
  46513. isKeyOf,
  46514. typeParameters
  46515. )
  46516. )
  46517. )
  46518. )
  46519. ];
  46520. }
  46521. function inferEnumType(node) {
  46522. const types = /* @__PURE__ */ new Set();
  46523. for (const m of node.members) {
  46524. if (m.initializer) {
  46525. switch (m.initializer.type) {
  46526. case "StringLiteral":
  46527. types.add("String");
  46528. break;
  46529. case "NumericLiteral":
  46530. types.add("Number");
  46531. break;
  46532. }
  46533. }
  46534. }
  46535. return types.size ? [...types] : ["Number"];
  46536. }
  46537. function resolveExtractPropTypes({ props }, scope) {
  46538. const res = { props: {} };
  46539. for (const key in props) {
  46540. const raw = props[key];
  46541. res.props[key] = reverseInferType(
  46542. raw.key,
  46543. raw.typeAnnotation.typeAnnotation,
  46544. scope
  46545. );
  46546. }
  46547. return res;
  46548. }
  46549. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  46550. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  46551. const typeType = findStaticPropertyType(node, "type");
  46552. if (typeType) {
  46553. const requiredType = findStaticPropertyType(node, "required");
  46554. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  46555. return reverseInferType(key, typeType, scope, optional2, false);
  46556. }
  46557. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  46558. if (node.typeName.name.endsWith("Constructor")) {
  46559. return createProperty(
  46560. key,
  46561. ctorToType(node.typeName.name),
  46562. scope,
  46563. optional
  46564. );
  46565. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  46566. return createProperty(key, node.typeParameters.params[0], scope, optional);
  46567. }
  46568. }
  46569. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  46570. for (const t of node.typeParameters.params) {
  46571. const inferred = reverseInferType(key, t, scope, optional);
  46572. if (inferred) return inferred;
  46573. }
  46574. }
  46575. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  46576. }
  46577. function ctorToType(ctorType) {
  46578. const ctor = ctorType.slice(0, -11);
  46579. switch (ctor) {
  46580. case "String":
  46581. case "Number":
  46582. case "Boolean":
  46583. return { type: `TS${ctor}Keyword` };
  46584. case "Array":
  46585. case "Function":
  46586. case "Object":
  46587. case "Set":
  46588. case "Map":
  46589. case "WeakSet":
  46590. case "WeakMap":
  46591. case "Date":
  46592. case "Promise":
  46593. return {
  46594. type: "TSTypeReference",
  46595. typeName: { type: "Identifier", name: ctor }
  46596. };
  46597. }
  46598. return { type: `TSNullKeyword` };
  46599. }
  46600. function findStaticPropertyType(node, key) {
  46601. const prop = node.members.find(
  46602. (m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
  46603. );
  46604. return prop && prop.typeAnnotation.typeAnnotation;
  46605. }
  46606. function resolveReturnType(ctx, arg, scope) {
  46607. var _a;
  46608. let resolved = arg;
  46609. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  46610. resolved = resolveTypeReference(ctx, arg, scope);
  46611. }
  46612. if (!resolved) return;
  46613. if (resolved.type === "TSFunctionType") {
  46614. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  46615. }
  46616. if (resolved.type === "TSDeclareFunction") {
  46617. return resolved.returnType;
  46618. }
  46619. }
  46620. function resolveUnionType(ctx, node, scope) {
  46621. if (node.type === "TSTypeReference") {
  46622. const resolved = resolveTypeReference(ctx, node, scope);
  46623. if (resolved) node = resolved;
  46624. }
  46625. let types;
  46626. if (node.type === "TSUnionType") {
  46627. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  46628. } else {
  46629. types = [node];
  46630. }
  46631. return types;
  46632. }
  46633. const DEFINE_MODEL = "defineModel";
  46634. function processDefineModel(ctx, node, declId) {
  46635. if (!isCallOf(node, DEFINE_MODEL)) {
  46636. return false;
  46637. }
  46638. ctx.hasDefineModelCall = true;
  46639. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  46640. let modelName;
  46641. let options;
  46642. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  46643. const hasName = arg0 && (arg0.type === "StringLiteral" || arg0.type === "TemplateLiteral" && arg0.expressions.length === 0);
  46644. if (hasName) {
  46645. modelName = arg0.type === "StringLiteral" ? arg0.value : arg0.quasis[0].value.cooked;
  46646. options = node.arguments[1];
  46647. } else {
  46648. modelName = "modelValue";
  46649. options = arg0;
  46650. }
  46651. if (ctx.modelDecls[modelName]) {
  46652. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  46653. }
  46654. let optionsString = options && ctx.getString(options);
  46655. let optionsRemoved = !options;
  46656. const runtimeOptionNodes = [];
  46657. if (options && options.type === "ObjectExpression" && !options.properties.some((p) => p.type === "SpreadElement" || p.computed)) {
  46658. let removed = 0;
  46659. for (let i = options.properties.length - 1; i >= 0; i--) {
  46660. const p = options.properties[i];
  46661. const next = options.properties[i + 1];
  46662. const start = p.start;
  46663. const end = next ? next.start : options.end - 1;
  46664. 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"))) {
  46665. optionsString = optionsString.slice(0, start - options.start) + optionsString.slice(end - options.start);
  46666. } else {
  46667. removed++;
  46668. ctx.s.remove(ctx.startOffset + start, ctx.startOffset + end);
  46669. runtimeOptionNodes.push(p);
  46670. }
  46671. }
  46672. if (removed === options.properties.length) {
  46673. optionsRemoved = true;
  46674. ctx.s.remove(
  46675. ctx.startOffset + (hasName ? arg0.end : options.start),
  46676. ctx.startOffset + options.end
  46677. );
  46678. }
  46679. }
  46680. ctx.modelDecls[modelName] = {
  46681. type,
  46682. options: optionsString,
  46683. runtimeOptionNodes,
  46684. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  46685. };
  46686. ctx.bindingMetadata[modelName] = "props";
  46687. ctx.s.overwrite(
  46688. ctx.startOffset + node.callee.start,
  46689. ctx.startOffset + node.callee.end,
  46690. ctx.helper("useModel")
  46691. );
  46692. ctx.s.appendLeft(
  46693. ctx.startOffset + (node.arguments.length ? node.arguments[0].start : node.end - 1),
  46694. `__props, ` + (hasName ? `` : `${JSON.stringify(modelName)}${optionsRemoved ? `` : `, `}`)
  46695. );
  46696. return true;
  46697. }
  46698. function genModelProps(ctx) {
  46699. if (!ctx.hasDefineModelCall) return;
  46700. const isProd = !!ctx.options.isProd;
  46701. let modelPropsDecl = "";
  46702. for (const [name, { type, options: runtimeOptions }] of Object.entries(
  46703. ctx.modelDecls
  46704. )) {
  46705. let skipCheck = false;
  46706. let codegenOptions = ``;
  46707. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46708. if (runtimeTypes) {
  46709. const hasBoolean = runtimeTypes.includes("Boolean");
  46710. const hasFunction = runtimeTypes.includes("Function");
  46711. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46712. if (hasUnknownType) {
  46713. if (hasBoolean || hasFunction) {
  46714. runtimeTypes = runtimeTypes.filter((t) => t !== UNKNOWN_TYPE);
  46715. skipCheck = true;
  46716. } else {
  46717. runtimeTypes = ["null"];
  46718. }
  46719. }
  46720. if (!isProd) {
  46721. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}` + (skipCheck ? ", skipCheck: true" : "");
  46722. } else if (hasBoolean || runtimeOptions && hasFunction) {
  46723. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}`;
  46724. } else ;
  46725. }
  46726. let decl;
  46727. if (codegenOptions && runtimeOptions) {
  46728. decl = ctx.isTS ? `{ ${codegenOptions}, ...${runtimeOptions} }` : `Object.assign({ ${codegenOptions} }, ${runtimeOptions})`;
  46729. } else if (codegenOptions) {
  46730. decl = `{ ${codegenOptions} }`;
  46731. } else if (runtimeOptions) {
  46732. decl = runtimeOptions;
  46733. } else {
  46734. decl = `{}`;
  46735. }
  46736. modelPropsDecl += `
  46737. ${JSON.stringify(name)}: ${decl},`;
  46738. const modifierPropName = JSON.stringify(
  46739. name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
  46740. );
  46741. modelPropsDecl += `
  46742. ${modifierPropName}: {},`;
  46743. }
  46744. return `{${modelPropsDecl}
  46745. }`;
  46746. }
  46747. const DEFINE_PROPS = "defineProps";
  46748. const WITH_DEFAULTS = "withDefaults";
  46749. function processDefineProps(ctx, node, declId, isWithDefaults = false) {
  46750. if (!isCallOf(node, DEFINE_PROPS)) {
  46751. return processWithDefaults(ctx, node, declId);
  46752. }
  46753. if (ctx.hasDefinePropsCall) {
  46754. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46755. }
  46756. ctx.hasDefinePropsCall = true;
  46757. ctx.propsRuntimeDecl = node.arguments[0];
  46758. if (ctx.propsRuntimeDecl) {
  46759. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46760. if (!(key in ctx.bindingMetadata)) {
  46761. ctx.bindingMetadata[key] = "props";
  46762. }
  46763. }
  46764. }
  46765. if (node.typeParameters) {
  46766. if (ctx.propsRuntimeDecl) {
  46767. ctx.error(
  46768. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46769. node
  46770. );
  46771. }
  46772. ctx.propsTypeDecl = node.typeParameters.params[0];
  46773. }
  46774. if (!isWithDefaults && declId && declId.type === "ObjectPattern") {
  46775. processPropsDestructure(ctx, declId);
  46776. }
  46777. ctx.propsCall = node;
  46778. ctx.propsDecl = declId;
  46779. return true;
  46780. }
  46781. function processWithDefaults(ctx, node, declId) {
  46782. if (!isCallOf(node, WITH_DEFAULTS)) {
  46783. return false;
  46784. }
  46785. if (!processDefineProps(
  46786. ctx,
  46787. node.arguments[0],
  46788. declId,
  46789. true
  46790. )) {
  46791. ctx.error(
  46792. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46793. node.arguments[0] || node
  46794. );
  46795. }
  46796. if (ctx.propsRuntimeDecl) {
  46797. ctx.error(
  46798. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46799. node
  46800. );
  46801. }
  46802. if (declId && declId.type === "ObjectPattern") {
  46803. ctx.warn(
  46804. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46805. Reactive destructure will be disabled when using withDefaults().
  46806. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `,
  46807. node.callee
  46808. );
  46809. }
  46810. ctx.propsRuntimeDefaults = node.arguments[1];
  46811. if (!ctx.propsRuntimeDefaults) {
  46812. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46813. }
  46814. ctx.propsCall = node;
  46815. return true;
  46816. }
  46817. function genRuntimeProps(ctx) {
  46818. let propsDecls;
  46819. if (ctx.propsRuntimeDecl) {
  46820. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46821. if (ctx.propsDestructureDecl) {
  46822. const defaults = [];
  46823. for (const key in ctx.propsDestructuredBindings) {
  46824. const d = genDestructuredDefaultValue(ctx, key);
  46825. const finalKey = getEscapedPropName(key);
  46826. if (d)
  46827. defaults.push(
  46828. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46829. );
  46830. }
  46831. if (defaults.length) {
  46832. propsDecls = `/*@__PURE__*/${ctx.helper(
  46833. `mergeDefaults`
  46834. )}(${propsDecls}, {
  46835. ${defaults.join(",\n ")}
  46836. })`;
  46837. }
  46838. }
  46839. } else if (ctx.propsTypeDecl) {
  46840. propsDecls = extractRuntimeProps(ctx);
  46841. }
  46842. const modelsDecls = genModelProps(ctx);
  46843. if (propsDecls && modelsDecls) {
  46844. return `/*@__PURE__*/${ctx.helper(
  46845. "mergeModels"
  46846. )}(${propsDecls}, ${modelsDecls})`;
  46847. } else {
  46848. return modelsDecls || propsDecls;
  46849. }
  46850. }
  46851. function extractRuntimeProps(ctx) {
  46852. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46853. if (!props.length) {
  46854. return;
  46855. }
  46856. const propStrings = [];
  46857. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46858. for (const prop of props) {
  46859. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46860. if ("bindingMetadata" in ctx && !(prop.key in ctx.bindingMetadata)) {
  46861. ctx.bindingMetadata[prop.key] = "props";
  46862. }
  46863. }
  46864. let propsDecls = `{
  46865. ${propStrings.join(",\n ")}
  46866. }`;
  46867. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46868. propsDecls = `/*@__PURE__*/${ctx.helper(
  46869. "mergeDefaults"
  46870. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46871. }
  46872. return propsDecls;
  46873. }
  46874. function resolveRuntimePropsFromType(ctx, node) {
  46875. const props = [];
  46876. const elements = resolveTypeElements(ctx, node);
  46877. for (const key in elements.props) {
  46878. const e = elements.props[key];
  46879. let type = inferRuntimeType(ctx, e);
  46880. let skipCheck = false;
  46881. if (type.includes(UNKNOWN_TYPE)) {
  46882. if (type.includes("Boolean") || type.includes("Function")) {
  46883. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46884. skipCheck = true;
  46885. } else {
  46886. type = ["null"];
  46887. }
  46888. }
  46889. props.push({
  46890. key,
  46891. required: !e.optional,
  46892. type: type || [`null`],
  46893. skipCheck
  46894. });
  46895. }
  46896. return props;
  46897. }
  46898. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46899. let defaultString;
  46900. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46901. if (destructured) {
  46902. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46903. } else if (hasStaticDefaults) {
  46904. const prop = ctx.propsRuntimeDefaults.properties.find(
  46905. (node) => {
  46906. if (node.type === "SpreadElement") return false;
  46907. return resolveObjectKey(node.key, node.computed) === key;
  46908. }
  46909. );
  46910. if (prop) {
  46911. if (prop.type === "ObjectProperty") {
  46912. defaultString = `default: ${ctx.getString(prop.value)}`;
  46913. } else {
  46914. let paramsString = "";
  46915. if (prop.params.length) {
  46916. const start = prop.params[0].start;
  46917. const end = prop.params[prop.params.length - 1].end;
  46918. paramsString = ctx.getString({ start, end });
  46919. }
  46920. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default(${paramsString}) ${ctx.getString(prop.body)}`;
  46921. }
  46922. }
  46923. }
  46924. const finalKey = getEscapedPropName(key);
  46925. if (!ctx.options.isProd) {
  46926. return `${finalKey}: { ${concatStrings([
  46927. `type: ${toRuntimeTypeString(type)}`,
  46928. `required: ${required}`,
  46929. skipCheck && "skipCheck: true",
  46930. defaultString
  46931. ])} }`;
  46932. } else if (type.some(
  46933. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46934. )) {
  46935. return `${finalKey}: { ${concatStrings([
  46936. `type: ${toRuntimeTypeString(type)}`,
  46937. defaultString
  46938. ])} }`;
  46939. } else {
  46940. if (ctx.isCE) {
  46941. if (defaultString) {
  46942. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46943. type
  46944. )} }`}`;
  46945. } else {
  46946. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46947. }
  46948. }
  46949. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46950. }
  46951. }
  46952. function hasStaticWithDefaults(ctx) {
  46953. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46954. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46955. ));
  46956. }
  46957. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46958. const destructured = ctx.propsDestructuredBindings[key];
  46959. const defaultVal = destructured && destructured.default;
  46960. if (defaultVal) {
  46961. const value = ctx.getString(defaultVal);
  46962. const unwrapped = unwrapTSNode(defaultVal);
  46963. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46964. const valueType = inferValueType(unwrapped);
  46965. if (valueType && !inferredType.includes(valueType)) {
  46966. ctx.error(
  46967. `Default value of prop "${key}" does not match declared type.`,
  46968. unwrapped
  46969. );
  46970. }
  46971. }
  46972. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46973. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46974. return {
  46975. valueString: needFactoryWrap ? `() => (${value})` : value,
  46976. needSkipFactory
  46977. };
  46978. }
  46979. }
  46980. function inferValueType(node) {
  46981. switch (node.type) {
  46982. case "StringLiteral":
  46983. return "String";
  46984. case "NumericLiteral":
  46985. return "Number";
  46986. case "BooleanLiteral":
  46987. return "Boolean";
  46988. case "ObjectExpression":
  46989. return "Object";
  46990. case "ArrayExpression":
  46991. return "Array";
  46992. case "FunctionExpression":
  46993. case "ArrowFunctionExpression":
  46994. return "Function";
  46995. }
  46996. }
  46997. function processPropsDestructure(ctx, declId) {
  46998. if (ctx.options.propsDestructure === "error") {
  46999. ctx.error(`Props destructure is explicitly prohibited via config.`, declId);
  47000. } else if (ctx.options.propsDestructure === false) {
  47001. return;
  47002. }
  47003. ctx.propsDestructureDecl = declId;
  47004. const registerBinding = (key, local, defaultValue) => {
  47005. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  47006. if (local !== key) {
  47007. ctx.bindingMetadata[local] = "props-aliased";
  47008. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  47009. }
  47010. };
  47011. for (const prop of declId.properties) {
  47012. if (prop.type === "ObjectProperty") {
  47013. const propKey = resolveObjectKey(prop.key, prop.computed);
  47014. if (!propKey) {
  47015. ctx.error(
  47016. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  47017. prop.key
  47018. );
  47019. }
  47020. if (prop.value.type === "AssignmentPattern") {
  47021. const { left, right } = prop.value;
  47022. if (left.type !== "Identifier") {
  47023. ctx.error(
  47024. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  47025. left
  47026. );
  47027. }
  47028. registerBinding(propKey, left.name, right);
  47029. } else if (prop.value.type === "Identifier") {
  47030. registerBinding(propKey, prop.value.name);
  47031. } else {
  47032. ctx.error(
  47033. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  47034. prop.value
  47035. );
  47036. }
  47037. } else {
  47038. ctx.propsDestructureRestId = prop.argument.name;
  47039. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  47040. }
  47041. }
  47042. }
  47043. function transformDestructuredProps(ctx, vueImportAliases) {
  47044. if (ctx.options.propsDestructure === false) {
  47045. return;
  47046. }
  47047. const rootScope = /* @__PURE__ */ Object.create(null);
  47048. const scopeStack = [rootScope];
  47049. let currentScope = rootScope;
  47050. const excludedIds = /* @__PURE__ */ new WeakSet();
  47051. const parentStack = [];
  47052. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  47053. for (const key in ctx.propsDestructuredBindings) {
  47054. const { local } = ctx.propsDestructuredBindings[key];
  47055. rootScope[local] = true;
  47056. propsLocalToPublicMap[local] = key;
  47057. }
  47058. function pushScope() {
  47059. scopeStack.push(currentScope = Object.create(currentScope));
  47060. }
  47061. function popScope() {
  47062. scopeStack.pop();
  47063. currentScope = scopeStack[scopeStack.length - 1] || null;
  47064. }
  47065. function registerLocalBinding(id) {
  47066. excludedIds.add(id);
  47067. if (currentScope) {
  47068. currentScope[id.name] = false;
  47069. } else {
  47070. ctx.error(
  47071. "registerBinding called without active scope, something is wrong.",
  47072. id
  47073. );
  47074. }
  47075. }
  47076. function walkScope(node, isRoot = false) {
  47077. for (const stmt of node.body) {
  47078. if (stmt.type === "VariableDeclaration") {
  47079. walkVariableDeclaration(stmt, isRoot);
  47080. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  47081. if (stmt.declare || !stmt.id) continue;
  47082. registerLocalBinding(stmt.id);
  47083. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  47084. walkVariableDeclaration(stmt.declaration, isRoot);
  47085. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  47086. walkVariableDeclaration(stmt.body, isRoot);
  47087. }
  47088. }
  47089. }
  47090. function walkVariableDeclaration(stmt, isRoot = false) {
  47091. if (stmt.declare) {
  47092. return;
  47093. }
  47094. for (const decl of stmt.declarations) {
  47095. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  47096. for (const id of extractIdentifiers$1(decl.id)) {
  47097. if (isDefineProps) {
  47098. excludedIds.add(id);
  47099. } else {
  47100. registerLocalBinding(id);
  47101. }
  47102. }
  47103. }
  47104. }
  47105. function rewriteId(id, parent, parentStack2) {
  47106. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  47107. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  47108. }
  47109. if (isStaticProperty(parent) && parent.shorthand) {
  47110. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  47111. ctx.s.appendLeft(
  47112. id.end + ctx.startOffset,
  47113. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  47114. );
  47115. }
  47116. } else {
  47117. ctx.s.overwrite(
  47118. id.start + ctx.startOffset,
  47119. id.end + ctx.startOffset,
  47120. genPropsAccessExp(propsLocalToPublicMap[id.name])
  47121. );
  47122. }
  47123. }
  47124. function checkUsage(node, method, alias = method) {
  47125. if (isCallOf(node, alias)) {
  47126. const arg = unwrapTSNode(node.arguments[0]);
  47127. if (arg.type === "Identifier" && currentScope[arg.name]) {
  47128. ctx.error(
  47129. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  47130. arg
  47131. );
  47132. }
  47133. }
  47134. }
  47135. const ast = ctx.scriptSetupAst;
  47136. walkScope(ast, true);
  47137. walk$2(ast, {
  47138. enter(node, parent) {
  47139. parent && parentStack.push(parent);
  47140. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  47141. return this.skip();
  47142. }
  47143. checkUsage(node, "watch", vueImportAliases.watch);
  47144. checkUsage(node, "toRef", vueImportAliases.toRef);
  47145. if (isFunctionType(node)) {
  47146. pushScope();
  47147. walkFunctionParams(node, registerLocalBinding);
  47148. if (node.body.type === "BlockStatement") {
  47149. walkScope(node.body);
  47150. }
  47151. return;
  47152. }
  47153. if (node.type === "CatchClause") {
  47154. pushScope();
  47155. if (node.param && node.param.type === "Identifier") {
  47156. registerLocalBinding(node.param);
  47157. }
  47158. walkScope(node.body);
  47159. return;
  47160. }
  47161. if (node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47162. pushScope();
  47163. const varDecl = node.type === "ForStatement" ? node.init : node.left;
  47164. if (varDecl && varDecl.type === "VariableDeclaration") {
  47165. walkVariableDeclaration(varDecl);
  47166. }
  47167. if (node.body.type === "BlockStatement") {
  47168. walkScope(node.body);
  47169. }
  47170. return;
  47171. }
  47172. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  47173. pushScope();
  47174. walkScope(node);
  47175. return;
  47176. }
  47177. if (node.type === "Identifier") {
  47178. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  47179. if (currentScope[node.name]) {
  47180. rewriteId(node, parent, parentStack);
  47181. }
  47182. }
  47183. }
  47184. },
  47185. leave(node, parent) {
  47186. parent && parentStack.pop();
  47187. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node) || node.type === "CatchClause" || node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
  47188. popScope();
  47189. }
  47190. }
  47191. });
  47192. }
  47193. const DEFINE_EMITS = "defineEmits";
  47194. function processDefineEmits(ctx, node, declId) {
  47195. if (!isCallOf(node, DEFINE_EMITS)) {
  47196. return false;
  47197. }
  47198. if (ctx.hasDefineEmitCall) {
  47199. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  47200. }
  47201. ctx.hasDefineEmitCall = true;
  47202. ctx.emitsRuntimeDecl = node.arguments[0];
  47203. if (node.typeParameters) {
  47204. if (ctx.emitsRuntimeDecl) {
  47205. ctx.error(
  47206. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  47207. node
  47208. );
  47209. }
  47210. ctx.emitsTypeDecl = node.typeParameters.params[0];
  47211. }
  47212. ctx.emitDecl = declId;
  47213. return true;
  47214. }
  47215. function genRuntimeEmits(ctx) {
  47216. let emitsDecl = "";
  47217. if (ctx.emitsRuntimeDecl) {
  47218. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  47219. } else if (ctx.emitsTypeDecl) {
  47220. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  47221. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  47222. }
  47223. if (ctx.hasDefineModelCall) {
  47224. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  47225. emitsDecl = emitsDecl ? `/*@__PURE__*/${ctx.helper(
  47226. "mergeModels"
  47227. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  47228. }
  47229. return emitsDecl;
  47230. }
  47231. function extractRuntimeEmits(ctx) {
  47232. const emits = /* @__PURE__ */ new Set();
  47233. const node = ctx.emitsTypeDecl;
  47234. if (node.type === "TSFunctionType") {
  47235. extractEventNames(ctx, node.parameters[0], emits);
  47236. return emits;
  47237. }
  47238. const { props, calls } = resolveTypeElements(ctx, node);
  47239. let hasProperty = false;
  47240. for (const key in props) {
  47241. emits.add(key);
  47242. hasProperty = true;
  47243. }
  47244. if (calls) {
  47245. if (hasProperty) {
  47246. ctx.error(
  47247. `defineEmits() type cannot mixed call signature and property syntax.`,
  47248. node
  47249. );
  47250. }
  47251. for (const call of calls) {
  47252. extractEventNames(ctx, call.parameters[0], emits);
  47253. }
  47254. }
  47255. return emits;
  47256. }
  47257. function extractEventNames(ctx, eventName, emits) {
  47258. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  47259. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  47260. for (const type of types) {
  47261. if (type.type === "TSLiteralType") {
  47262. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  47263. emits.add(String(type.literal.value));
  47264. }
  47265. }
  47266. }
  47267. }
  47268. }
  47269. const DEFINE_EXPOSE = "defineExpose";
  47270. function processDefineExpose(ctx, node) {
  47271. if (isCallOf(node, DEFINE_EXPOSE)) {
  47272. if (ctx.hasDefineExposeCall) {
  47273. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  47274. }
  47275. ctx.hasDefineExposeCall = true;
  47276. return true;
  47277. }
  47278. return false;
  47279. }
  47280. const DEFINE_SLOTS = "defineSlots";
  47281. function processDefineSlots(ctx, node, declId) {
  47282. if (!isCallOf(node, DEFINE_SLOTS)) {
  47283. return false;
  47284. }
  47285. if (ctx.hasDefineSlotsCall) {
  47286. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  47287. }
  47288. ctx.hasDefineSlotsCall = true;
  47289. if (node.arguments.length > 0) {
  47290. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  47291. }
  47292. if (declId) {
  47293. ctx.s.overwrite(
  47294. ctx.startOffset + node.start,
  47295. ctx.startOffset + node.end,
  47296. `${ctx.helper("useSlots")}()`
  47297. );
  47298. }
  47299. return true;
  47300. }
  47301. const DEFINE_OPTIONS = "defineOptions";
  47302. function processDefineOptions(ctx, node) {
  47303. if (!isCallOf(node, DEFINE_OPTIONS)) {
  47304. return false;
  47305. }
  47306. if (ctx.hasDefineOptionsCall) {
  47307. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  47308. }
  47309. if (node.typeParameters) {
  47310. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  47311. }
  47312. if (!node.arguments[0]) return true;
  47313. ctx.hasDefineOptionsCall = true;
  47314. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  47315. let propsOption = void 0;
  47316. let emitsOption = void 0;
  47317. let exposeOption = void 0;
  47318. let slotsOption = void 0;
  47319. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  47320. for (const prop of ctx.optionsRuntimeDecl.properties) {
  47321. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  47322. switch (prop.key.name) {
  47323. case "props":
  47324. propsOption = prop;
  47325. break;
  47326. case "emits":
  47327. emitsOption = prop;
  47328. break;
  47329. case "expose":
  47330. exposeOption = prop;
  47331. break;
  47332. case "slots":
  47333. slotsOption = prop;
  47334. break;
  47335. }
  47336. }
  47337. }
  47338. }
  47339. if (propsOption) {
  47340. ctx.error(
  47341. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  47342. propsOption
  47343. );
  47344. }
  47345. if (emitsOption) {
  47346. ctx.error(
  47347. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  47348. emitsOption
  47349. );
  47350. }
  47351. if (exposeOption) {
  47352. ctx.error(
  47353. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  47354. exposeOption
  47355. );
  47356. }
  47357. if (slotsOption) {
  47358. ctx.error(
  47359. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  47360. slotsOption
  47361. );
  47362. }
  47363. return true;
  47364. }
  47365. function processAwait(ctx, node, needSemi, isStatement) {
  47366. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  47367. const startOffset = ctx.startOffset;
  47368. const argumentStr = ctx.descriptor.source.slice(
  47369. argumentStart + startOffset,
  47370. node.argument.end + startOffset
  47371. );
  47372. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  47373. ctx.s.overwrite(
  47374. node.start + startOffset,
  47375. argumentStart + startOffset,
  47376. `${needSemi ? `;` : ``}(
  47377. ([__temp,__restore] = ${ctx.helper(
  47378. `withAsyncContext`
  47379. )}(${containsNestedAwait ? `async ` : ``}() => `
  47380. );
  47381. ctx.s.appendLeft(
  47382. node.end + startOffset,
  47383. `)),
  47384. ${isStatement ? `` : `__temp = `}await __temp,
  47385. __restore()${isStatement ? `` : `,
  47386. __temp`}
  47387. )`
  47388. );
  47389. }
  47390. var __defProp$1 = Object.defineProperty;
  47391. var __defProps = Object.defineProperties;
  47392. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  47393. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  47394. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  47395. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  47396. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  47397. var __spreadValues$1 = (a, b) => {
  47398. for (var prop in b || (b = {}))
  47399. if (__hasOwnProp$1.call(b, prop))
  47400. __defNormalProp$1(a, prop, b[prop]);
  47401. if (__getOwnPropSymbols$1)
  47402. for (var prop of __getOwnPropSymbols$1(b)) {
  47403. if (__propIsEnum$1.call(b, prop))
  47404. __defNormalProp$1(a, prop, b[prop]);
  47405. }
  47406. return a;
  47407. };
  47408. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  47409. const MACROS = [
  47410. DEFINE_PROPS,
  47411. DEFINE_EMITS,
  47412. DEFINE_EXPOSE,
  47413. DEFINE_OPTIONS,
  47414. DEFINE_SLOTS,
  47415. DEFINE_MODEL,
  47416. WITH_DEFAULTS
  47417. ];
  47418. function compileScript(sfc, options) {
  47419. var _a, _b, _c;
  47420. if (!options.id) {
  47421. warnOnce$1(
  47422. `compileScript now requires passing the \`id\` option.
  47423. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  47424. );
  47425. }
  47426. const { script, scriptSetup, source, filename } = sfc;
  47427. const hoistStatic = options.hoistStatic !== false && !script;
  47428. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  47429. const scriptLang = script && script.lang;
  47430. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  47431. const isJSOrTS = isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang);
  47432. if (script && scriptSetup && scriptLang !== scriptSetupLang) {
  47433. throw new Error(
  47434. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  47435. );
  47436. }
  47437. if (!scriptSetup) {
  47438. if (!script) {
  47439. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  47440. }
  47441. if (script.lang && !isJSOrTS) {
  47442. return script;
  47443. }
  47444. const ctx2 = new ScriptCompileContext(sfc, options);
  47445. return processNormalScript(ctx2, scopeId);
  47446. }
  47447. if (scriptSetupLang && !isJSOrTS) {
  47448. return scriptSetup;
  47449. }
  47450. const ctx = new ScriptCompileContext(sfc, options);
  47451. const scriptBindings = /* @__PURE__ */ Object.create(null);
  47452. const setupBindings = /* @__PURE__ */ Object.create(null);
  47453. let defaultExport;
  47454. let hasAwait = false;
  47455. let hasInlinedSsrRenderFn = false;
  47456. const startOffset = ctx.startOffset;
  47457. const endOffset = ctx.endOffset;
  47458. const scriptStartOffset = script && script.loc.start.offset;
  47459. const scriptEndOffset = script && script.loc.end.offset;
  47460. function hoistNode(node) {
  47461. const start = node.start + startOffset;
  47462. let end = node.end + startOffset;
  47463. if (node.trailingComments && node.trailingComments.length > 0) {
  47464. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  47465. end = lastCommentNode.end + startOffset;
  47466. }
  47467. while (end <= source.length) {
  47468. if (!/\s/.test(source.charAt(end))) {
  47469. break;
  47470. }
  47471. end++;
  47472. }
  47473. ctx.s.move(start, end, 0);
  47474. }
  47475. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  47476. let isUsedInTemplate = needTemplateUsageCheck;
  47477. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  47478. isUsedInTemplate = isImportUsed(local, sfc);
  47479. }
  47480. ctx.userImports[local] = {
  47481. isType,
  47482. imported,
  47483. local,
  47484. source: source2,
  47485. isFromSetup,
  47486. isUsedInTemplate
  47487. };
  47488. }
  47489. function checkInvalidScopeReference(node, method) {
  47490. if (!node) return;
  47491. walkIdentifiers(node, (id) => {
  47492. const binding = setupBindings[id.name];
  47493. if (binding && binding !== "literal-const") {
  47494. ctx.error(
  47495. `\`${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.`,
  47496. id
  47497. );
  47498. }
  47499. });
  47500. }
  47501. const scriptAst = ctx.scriptAst;
  47502. const scriptSetupAst = ctx.scriptSetupAst;
  47503. if (scriptAst) {
  47504. for (const node of scriptAst.body) {
  47505. if (node.type === "ImportDeclaration") {
  47506. for (const specifier of node.specifiers) {
  47507. const imported = getImportedName(specifier);
  47508. registerUserImport(
  47509. node.source.value,
  47510. specifier.local.name,
  47511. imported,
  47512. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47513. false,
  47514. !options.inlineTemplate
  47515. );
  47516. }
  47517. }
  47518. }
  47519. }
  47520. for (const node of scriptSetupAst.body) {
  47521. if (node.type === "ImportDeclaration") {
  47522. hoistNode(node);
  47523. let removed = 0;
  47524. const removeSpecifier = (i) => {
  47525. const removeLeft = i > removed;
  47526. removed++;
  47527. const current = node.specifiers[i];
  47528. const next = node.specifiers[i + 1];
  47529. ctx.s.remove(
  47530. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  47531. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  47532. );
  47533. };
  47534. for (let i = 0; i < node.specifiers.length; i++) {
  47535. const specifier = node.specifiers[i];
  47536. const local = specifier.local.name;
  47537. const imported = getImportedName(specifier);
  47538. const source2 = node.source.value;
  47539. const existing = ctx.userImports[local];
  47540. if (source2 === "vue" && MACROS.includes(imported)) {
  47541. if (local === imported) {
  47542. warnOnce$1(
  47543. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  47544. );
  47545. } else {
  47546. ctx.error(
  47547. `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
  47548. specifier
  47549. );
  47550. }
  47551. removeSpecifier(i);
  47552. } else if (existing) {
  47553. if (existing.source === source2 && existing.imported === imported) {
  47554. removeSpecifier(i);
  47555. } else {
  47556. ctx.error(
  47557. `different imports aliased to same local name.`,
  47558. specifier
  47559. );
  47560. }
  47561. } else {
  47562. registerUserImport(
  47563. source2,
  47564. local,
  47565. imported,
  47566. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47567. true,
  47568. !options.inlineTemplate
  47569. );
  47570. }
  47571. }
  47572. if (node.specifiers.length && removed === node.specifiers.length) {
  47573. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47574. }
  47575. }
  47576. }
  47577. const vueImportAliases = {};
  47578. for (const key in ctx.userImports) {
  47579. const { source: source2, imported, local } = ctx.userImports[key];
  47580. if (source2 === "vue") vueImportAliases[imported] = local;
  47581. }
  47582. if (script && scriptAst) {
  47583. for (const node of scriptAst.body) {
  47584. if (node.type === "ExportDefaultDeclaration") {
  47585. defaultExport = node;
  47586. let optionProperties;
  47587. if (defaultExport.declaration.type === "ObjectExpression") {
  47588. optionProperties = defaultExport.declaration.properties;
  47589. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  47590. optionProperties = defaultExport.declaration.arguments[0].properties;
  47591. }
  47592. if (optionProperties) {
  47593. for (const p of optionProperties) {
  47594. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  47595. ctx.hasDefaultExportName = true;
  47596. }
  47597. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  47598. ctx.hasDefaultExportRender = true;
  47599. }
  47600. }
  47601. }
  47602. const start = node.start + scriptStartOffset;
  47603. const end = node.declaration.start + scriptStartOffset;
  47604. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  47605. } else if (node.type === "ExportNamedDeclaration") {
  47606. const defaultSpecifier = node.specifiers.find(
  47607. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  47608. );
  47609. if (defaultSpecifier) {
  47610. defaultExport = node;
  47611. if (node.specifiers.length > 1) {
  47612. ctx.s.remove(
  47613. defaultSpecifier.start + scriptStartOffset,
  47614. defaultSpecifier.end + scriptStartOffset
  47615. );
  47616. } else {
  47617. ctx.s.remove(
  47618. node.start + scriptStartOffset,
  47619. node.end + scriptStartOffset
  47620. );
  47621. }
  47622. if (node.source) {
  47623. ctx.s.prepend(
  47624. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  47625. `
  47626. );
  47627. } else {
  47628. ctx.s.appendLeft(
  47629. scriptEndOffset,
  47630. `
  47631. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  47632. `
  47633. );
  47634. }
  47635. }
  47636. if (node.declaration) {
  47637. walkDeclaration(
  47638. "script",
  47639. node.declaration,
  47640. scriptBindings,
  47641. vueImportAliases,
  47642. hoistStatic
  47643. );
  47644. }
  47645. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47646. walkDeclaration(
  47647. "script",
  47648. node,
  47649. scriptBindings,
  47650. vueImportAliases,
  47651. hoistStatic
  47652. );
  47653. }
  47654. }
  47655. if (scriptStartOffset > startOffset) {
  47656. if (!/\n$/.test(script.content.trim())) {
  47657. ctx.s.appendLeft(scriptEndOffset, `
  47658. `);
  47659. }
  47660. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  47661. }
  47662. }
  47663. for (const node of scriptSetupAst.body) {
  47664. if (node.type === "ExpressionStatement") {
  47665. const expr = unwrapTSNode(node.expression);
  47666. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  47667. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47668. } else if (processDefineExpose(ctx, expr)) {
  47669. const callee = expr.callee;
  47670. ctx.s.overwrite(
  47671. callee.start + startOffset,
  47672. callee.end + startOffset,
  47673. "__expose"
  47674. );
  47675. } else {
  47676. processDefineModel(ctx, expr);
  47677. }
  47678. }
  47679. if (node.type === "VariableDeclaration" && !node.declare) {
  47680. const total = node.declarations.length;
  47681. let left = total;
  47682. let lastNonRemoved;
  47683. for (let i = 0; i < total; i++) {
  47684. const decl = node.declarations[i];
  47685. const init = decl.init && unwrapTSNode(decl.init);
  47686. if (init) {
  47687. if (processDefineOptions(ctx, init)) {
  47688. ctx.error(
  47689. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  47690. node
  47691. );
  47692. }
  47693. const isDefineProps = processDefineProps(ctx, init, decl.id);
  47694. if (ctx.propsDestructureRestId) {
  47695. setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
  47696. }
  47697. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  47698. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  47699. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  47700. if (left === 1) {
  47701. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47702. } else {
  47703. let start = decl.start + startOffset;
  47704. let end = decl.end + startOffset;
  47705. if (i === total - 1) {
  47706. start = node.declarations[lastNonRemoved].end + startOffset;
  47707. } else {
  47708. end = node.declarations[i + 1].start + startOffset;
  47709. }
  47710. ctx.s.remove(start, end);
  47711. left--;
  47712. }
  47713. } else if (isDefineEmits) {
  47714. ctx.s.overwrite(
  47715. startOffset + init.start,
  47716. startOffset + init.end,
  47717. "__emit"
  47718. );
  47719. } else {
  47720. lastNonRemoved = i;
  47721. }
  47722. }
  47723. }
  47724. }
  47725. let isAllLiteral = false;
  47726. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47727. isAllLiteral = walkDeclaration(
  47728. "scriptSetup",
  47729. node,
  47730. setupBindings,
  47731. vueImportAliases,
  47732. hoistStatic,
  47733. !!ctx.propsDestructureDecl
  47734. );
  47735. }
  47736. if (hoistStatic && isAllLiteral) {
  47737. hoistNode(node);
  47738. }
  47739. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  47740. const scope = [scriptSetupAst.body];
  47741. walk$2(node, {
  47742. enter(child, parent) {
  47743. if (isFunctionType(child)) {
  47744. this.skip();
  47745. }
  47746. if (child.type === "BlockStatement") {
  47747. scope.push(child.body);
  47748. }
  47749. if (child.type === "AwaitExpression") {
  47750. hasAwait = true;
  47751. const currentScope = scope[scope.length - 1];
  47752. const needsSemi = currentScope.some((n, i) => {
  47753. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47754. });
  47755. processAwait(
  47756. ctx,
  47757. child,
  47758. needsSemi,
  47759. parent.type === "ExpressionStatement"
  47760. );
  47761. }
  47762. },
  47763. exit(node2) {
  47764. if (node2.type === "BlockStatement") scope.pop();
  47765. }
  47766. });
  47767. }
  47768. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47769. ctx.error(
  47770. `<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.`,
  47771. node
  47772. );
  47773. }
  47774. if (ctx.isTS) {
  47775. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47776. if (node.type !== "TSEnumDeclaration") {
  47777. hoistNode(node);
  47778. }
  47779. }
  47780. }
  47781. }
  47782. if (ctx.propsDestructureDecl) {
  47783. transformDestructuredProps(ctx, vueImportAliases);
  47784. }
  47785. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47786. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47787. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47788. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47789. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47790. for (const { runtimeOptionNodes } of Object.values(ctx.modelDecls)) {
  47791. for (const node of runtimeOptionNodes) {
  47792. checkInvalidScopeReference(node, DEFINE_MODEL);
  47793. }
  47794. }
  47795. if (script) {
  47796. if (startOffset < scriptStartOffset) {
  47797. ctx.s.remove(0, startOffset);
  47798. ctx.s.remove(endOffset, scriptStartOffset);
  47799. ctx.s.remove(scriptEndOffset, source.length);
  47800. } else {
  47801. ctx.s.remove(0, scriptStartOffset);
  47802. ctx.s.remove(scriptEndOffset, startOffset);
  47803. ctx.s.remove(endOffset, source.length);
  47804. }
  47805. } else {
  47806. ctx.s.remove(0, startOffset);
  47807. ctx.s.remove(endOffset, source.length);
  47808. }
  47809. if (scriptAst) {
  47810. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47811. }
  47812. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47813. ctx.userImports
  47814. )) {
  47815. if (isType) continue;
  47816. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47817. }
  47818. for (const key in scriptBindings) {
  47819. ctx.bindingMetadata[key] = scriptBindings[key];
  47820. }
  47821. for (const key in setupBindings) {
  47822. ctx.bindingMetadata[key] = setupBindings[key];
  47823. }
  47824. if (sfc.template && !sfc.template.src && sfc.template.ast) {
  47825. const vModelIds = resolveTemplateVModelIdentifiers(sfc);
  47826. if (vModelIds.size) {
  47827. const toDemote = /* @__PURE__ */ new Set();
  47828. for (const id of vModelIds) {
  47829. if (setupBindings[id] === "setup-reactive-const") {
  47830. toDemote.add(id);
  47831. }
  47832. }
  47833. if (toDemote.size) {
  47834. for (const node of scriptSetupAst.body) {
  47835. if (node.type === "VariableDeclaration" && node.kind === "const" && !node.declare) {
  47836. const demotedInDecl = [];
  47837. for (const decl of node.declarations) {
  47838. if (decl.id.type === "Identifier" && toDemote.has(decl.id.name)) {
  47839. demotedInDecl.push(decl.id.name);
  47840. }
  47841. }
  47842. if (demotedInDecl.length) {
  47843. ctx.s.overwrite(
  47844. node.start + startOffset,
  47845. node.start + startOffset + "const".length,
  47846. "let"
  47847. );
  47848. for (const id of demotedInDecl) {
  47849. setupBindings[id] = "setup-let";
  47850. ctx.bindingMetadata[id] = "setup-let";
  47851. warnOnce$1(
  47852. `\`v-model\` cannot update a \`const\` reactive binding \`${id}\`. The compiler has transformed it to \`let\` to make the update work.`
  47853. );
  47854. }
  47855. }
  47856. }
  47857. }
  47858. }
  47859. }
  47860. }
  47861. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47862. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47863. ctx.helperImports.add(CSS_VARS_HELPER);
  47864. ctx.helperImports.add("unref");
  47865. ctx.s.prependLeft(
  47866. startOffset,
  47867. `
  47868. ${genCssVarsCode(
  47869. sfc.cssVars,
  47870. ctx.bindingMetadata,
  47871. scopeId,
  47872. !!options.isProd
  47873. )}
  47874. `
  47875. );
  47876. }
  47877. let args = `__props`;
  47878. if (ctx.propsTypeDecl) {
  47879. args += `: any`;
  47880. }
  47881. if (ctx.propsDecl) {
  47882. if (ctx.propsDestructureRestId) {
  47883. ctx.s.overwrite(
  47884. startOffset + ctx.propsCall.start,
  47885. startOffset + ctx.propsCall.end,
  47886. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47887. Object.keys(ctx.propsDestructuredBindings)
  47888. )})`
  47889. );
  47890. ctx.s.overwrite(
  47891. startOffset + ctx.propsDestructureDecl.start,
  47892. startOffset + ctx.propsDestructureDecl.end,
  47893. ctx.propsDestructureRestId
  47894. );
  47895. } else if (!ctx.propsDestructureDecl) {
  47896. ctx.s.overwrite(
  47897. startOffset + ctx.propsCall.start,
  47898. startOffset + ctx.propsCall.end,
  47899. "__props"
  47900. );
  47901. }
  47902. }
  47903. if (hasAwait) {
  47904. const any = ctx.isTS ? `: any` : ``;
  47905. ctx.s.prependLeft(startOffset, `
  47906. let __temp${any}, __restore${any}
  47907. `);
  47908. }
  47909. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47910. if (ctx.emitDecl) {
  47911. destructureElements.push(`emit: __emit`);
  47912. }
  47913. if (destructureElements.length) {
  47914. args += `, { ${destructureElements.join(", ")} }`;
  47915. }
  47916. let templateMap;
  47917. let returned;
  47918. const propsDecl = genRuntimeProps(ctx);
  47919. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47920. const allBindings = __spreadValues$1(__spreadValues$1({}, scriptBindings), setupBindings);
  47921. for (const key in ctx.userImports) {
  47922. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47923. allBindings[key] = true;
  47924. }
  47925. }
  47926. returned = `{ `;
  47927. for (const key in allBindings) {
  47928. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47929. returned += `get ${key}() { return ${key} }, `;
  47930. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47931. const setArg = key === "v" ? `_v` : `v`;
  47932. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47933. } else {
  47934. returned += `${key}, `;
  47935. }
  47936. }
  47937. returned = returned.replace(/, $/, "") + ` }`;
  47938. } else {
  47939. if (sfc.template && !sfc.template.src) {
  47940. if (options.templateOptions && options.templateOptions.ssr) {
  47941. hasInlinedSsrRenderFn = true;
  47942. }
  47943. const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
  47944. filename,
  47945. ast: sfc.template.ast,
  47946. source: sfc.template.content,
  47947. inMap: sfc.template.map
  47948. }, options.templateOptions), {
  47949. id: scopeId,
  47950. scoped: sfc.styles.some((s) => s.scoped),
  47951. isProd: options.isProd,
  47952. ssrCssVars: sfc.cssVars,
  47953. compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47954. inline: true,
  47955. isTS: ctx.isTS,
  47956. bindingMetadata: ctx.bindingMetadata
  47957. })
  47958. }));
  47959. templateMap = map2;
  47960. if (tips.length) {
  47961. tips.forEach(warnOnce$1);
  47962. }
  47963. const err = errors[0];
  47964. if (typeof err === "string") {
  47965. throw new Error(err);
  47966. } else if (err) {
  47967. if (err.loc) {
  47968. err.message += `
  47969. ` + sfc.filename + "\n" + generateCodeFrame(
  47970. source,
  47971. err.loc.start.offset,
  47972. err.loc.end.offset
  47973. ) + `
  47974. `;
  47975. }
  47976. throw err;
  47977. }
  47978. if (preamble) {
  47979. ctx.s.prepend(preamble);
  47980. }
  47981. if (ast && ast.helpers.has(UNREF)) {
  47982. ctx.helperImports.delete("unref");
  47983. }
  47984. returned = code;
  47985. } else {
  47986. returned = `() => {}`;
  47987. }
  47988. }
  47989. if (!options.inlineTemplate && true) {
  47990. ctx.s.appendRight(
  47991. endOffset,
  47992. `
  47993. const __returned__ = ${returned}
  47994. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47995. return __returned__
  47996. }
  47997. `
  47998. );
  47999. } else {
  48000. ctx.s.appendRight(endOffset, `
  48001. return ${returned}
  48002. }
  48003. `);
  48004. }
  48005. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  48006. let runtimeOptions = ``;
  48007. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  48008. const match = filename.match(/([^/\\]+)\.\w+$/);
  48009. if (match) {
  48010. runtimeOptions += `
  48011. __name: '${match[1]}',`;
  48012. }
  48013. }
  48014. if (hasInlinedSsrRenderFn) {
  48015. runtimeOptions += `
  48016. __ssrInlineRender: true,`;
  48017. }
  48018. if (propsDecl) runtimeOptions += `
  48019. props: ${propsDecl},`;
  48020. const emitsDecl = genRuntimeEmits(ctx);
  48021. if (emitsDecl) runtimeOptions += `
  48022. emits: ${emitsDecl},`;
  48023. let definedOptions = "";
  48024. if (ctx.optionsRuntimeDecl) {
  48025. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  48026. }
  48027. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  48028. `;
  48029. if (ctx.isTS) {
  48030. const def = (defaultExport ? `
  48031. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  48032. ...${definedOptions},` : "");
  48033. ctx.s.prependLeft(
  48034. startOffset,
  48035. `
  48036. ${genDefaultAs} /*@__PURE__*/${ctx.helper(
  48037. `defineComponent`
  48038. )}({${def}${runtimeOptions}
  48039. ${hasAwait ? `async ` : ``}setup(${args}) {
  48040. ${exposeCall}`
  48041. );
  48042. ctx.s.appendRight(endOffset, `})`);
  48043. } else {
  48044. if (defaultExport || definedOptions) {
  48045. ctx.s.prependLeft(
  48046. startOffset,
  48047. `
  48048. ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  48049. ${hasAwait ? `async ` : ``}setup(${args}) {
  48050. ${exposeCall}`
  48051. );
  48052. ctx.s.appendRight(endOffset, `})`);
  48053. } else {
  48054. ctx.s.prependLeft(
  48055. startOffset,
  48056. `
  48057. ${genDefaultAs} {${runtimeOptions}
  48058. ${hasAwait ? `async ` : ``}setup(${args}) {
  48059. ${exposeCall}`
  48060. );
  48061. ctx.s.appendRight(endOffset, `}`);
  48062. }
  48063. }
  48064. if (ctx.helperImports.size > 0) {
  48065. const runtimeModuleName = (_c = (_b = options.templateOptions) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.runtimeModuleName;
  48066. const importSrc = runtimeModuleName ? JSON.stringify(runtimeModuleName) : `'vue'`;
  48067. ctx.s.prepend(
  48068. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from ${importSrc}
  48069. `
  48070. );
  48071. }
  48072. const content = ctx.s.toString();
  48073. let map = options.sourceMap !== false ? ctx.s.generateMap({
  48074. source: filename,
  48075. hires: true,
  48076. includeContent: true
  48077. }) : void 0;
  48078. if (templateMap && map) {
  48079. const offset = content.indexOf(returned);
  48080. const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
  48081. map = mergeSourceMaps(map, templateMap, templateLineOffset);
  48082. }
  48083. return __spreadProps(__spreadValues$1({}, scriptSetup), {
  48084. bindings: ctx.bindingMetadata,
  48085. imports: ctx.userImports,
  48086. content,
  48087. map,
  48088. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  48089. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  48090. deps: ctx.deps ? [...ctx.deps] : void 0
  48091. });
  48092. }
  48093. function registerBinding(bindings, node, type) {
  48094. bindings[node.name] = type;
  48095. }
  48096. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
  48097. let isAllLiteral = false;
  48098. if (node.type === "VariableDeclaration") {
  48099. const isConst = node.kind === "const";
  48100. isAllLiteral = isConst && node.declarations.every(
  48101. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  48102. );
  48103. for (const { id, init: _init } of node.declarations) {
  48104. const init = _init && unwrapTSNode(_init);
  48105. const isConstMacroCall = isConst && isCallOf(
  48106. init,
  48107. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
  48108. );
  48109. if (id.type === "Identifier") {
  48110. let bindingType;
  48111. const userReactiveBinding = userImportAliases["reactive"];
  48112. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  48113. bindingType = "literal-const";
  48114. } else if (isCallOf(init, userReactiveBinding)) {
  48115. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  48116. } else if (
  48117. // if a declaration is a const literal, we can mark it so that
  48118. // the generated render fn code doesn't need to unref() it
  48119. isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
  48120. ) {
  48121. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  48122. } else if (isConst) {
  48123. if (isCallOf(
  48124. init,
  48125. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
  48126. )) {
  48127. bindingType = "setup-ref";
  48128. } else {
  48129. bindingType = "setup-maybe-ref";
  48130. }
  48131. } else {
  48132. bindingType = "setup-let";
  48133. }
  48134. registerBinding(bindings, id, bindingType);
  48135. } else {
  48136. if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
  48137. continue;
  48138. }
  48139. if (id.type === "ObjectPattern") {
  48140. walkObjectPattern(id, bindings, isConst, isConstMacroCall);
  48141. } else if (id.type === "ArrayPattern") {
  48142. walkArrayPattern(id, bindings, isConst, isConstMacroCall);
  48143. }
  48144. }
  48145. }
  48146. } else if (node.type === "TSEnumDeclaration") {
  48147. isAllLiteral = node.members.every(
  48148. (member) => !member.initializer || isStaticNode(member.initializer)
  48149. );
  48150. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  48151. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  48152. bindings[node.id.name] = "setup-const";
  48153. }
  48154. return isAllLiteral;
  48155. }
  48156. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  48157. for (const p of node.properties) {
  48158. if (p.type === "ObjectProperty") {
  48159. if (p.key.type === "Identifier" && p.key === p.value) {
  48160. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48161. registerBinding(bindings, p.key, type);
  48162. } else {
  48163. walkPattern(p.value, bindings, isConst, isDefineCall);
  48164. }
  48165. } else {
  48166. const type = isConst ? "setup-const" : "setup-let";
  48167. registerBinding(bindings, p.argument, type);
  48168. }
  48169. }
  48170. }
  48171. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  48172. for (const e of node.elements) {
  48173. e && walkPattern(e, bindings, isConst, isDefineCall);
  48174. }
  48175. }
  48176. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  48177. if (node.type === "Identifier") {
  48178. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48179. registerBinding(bindings, node, type);
  48180. } else if (node.type === "RestElement") {
  48181. const type = isConst ? "setup-const" : "setup-let";
  48182. registerBinding(bindings, node.argument, type);
  48183. } else if (node.type === "ObjectPattern") {
  48184. walkObjectPattern(node, bindings, isConst);
  48185. } else if (node.type === "ArrayPattern") {
  48186. walkArrayPattern(node, bindings, isConst);
  48187. } else if (node.type === "AssignmentPattern") {
  48188. if (node.left.type === "Identifier") {
  48189. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  48190. registerBinding(bindings, node.left, type);
  48191. } else {
  48192. walkPattern(node.left, bindings, isConst);
  48193. }
  48194. }
  48195. }
  48196. function canNeverBeRef(node, userReactiveImport) {
  48197. if (isCallOf(node, userReactiveImport)) {
  48198. return true;
  48199. }
  48200. switch (node.type) {
  48201. case "UnaryExpression":
  48202. case "BinaryExpression":
  48203. case "ArrayExpression":
  48204. case "ObjectExpression":
  48205. case "FunctionExpression":
  48206. case "ArrowFunctionExpression":
  48207. case "UpdateExpression":
  48208. case "ClassExpression":
  48209. case "TaggedTemplateExpression":
  48210. return true;
  48211. case "SequenceExpression":
  48212. return canNeverBeRef(
  48213. node.expressions[node.expressions.length - 1],
  48214. userReactiveImport
  48215. );
  48216. default:
  48217. if (isLiteralNode(node)) {
  48218. return true;
  48219. }
  48220. return false;
  48221. }
  48222. }
  48223. function isStaticNode(node) {
  48224. node = unwrapTSNode(node);
  48225. switch (node.type) {
  48226. case "UnaryExpression":
  48227. return isStaticNode(node.argument);
  48228. case "LogicalExpression":
  48229. // 1 > 2
  48230. case "BinaryExpression":
  48231. return isStaticNode(node.left) && isStaticNode(node.right);
  48232. case "ConditionalExpression": {
  48233. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  48234. }
  48235. case "SequenceExpression":
  48236. // (1, 2)
  48237. case "TemplateLiteral":
  48238. return node.expressions.every((expr) => isStaticNode(expr));
  48239. case "ParenthesizedExpression":
  48240. return isStaticNode(node.expression);
  48241. case "StringLiteral":
  48242. case "NumericLiteral":
  48243. case "BooleanLiteral":
  48244. case "NullLiteral":
  48245. case "BigIntLiteral":
  48246. return true;
  48247. }
  48248. return false;
  48249. }
  48250. function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
  48251. const generator = new sourceMapExports.SourceMapGenerator();
  48252. const addMapping = (map, lineOffset = 0) => {
  48253. const consumer = new sourceMapExports.SourceMapConsumer(map);
  48254. consumer.sources.forEach((sourceFile) => {
  48255. generator._sources.add(sourceFile);
  48256. const sourceContent = consumer.sourceContentFor(sourceFile);
  48257. if (sourceContent != null) {
  48258. generator.setSourceContent(sourceFile, sourceContent);
  48259. }
  48260. });
  48261. consumer.eachMapping((m) => {
  48262. if (m.originalLine == null) return;
  48263. generator.addMapping({
  48264. generated: {
  48265. line: m.generatedLine + lineOffset,
  48266. column: m.generatedColumn
  48267. },
  48268. original: {
  48269. line: m.originalLine,
  48270. column: m.originalColumn
  48271. },
  48272. source: m.source,
  48273. name: m.name
  48274. });
  48275. });
  48276. };
  48277. addMapping(scriptMap);
  48278. addMapping(templateMap, templateLineOffset);
  48279. generator._sourceRoot = scriptMap.sourceRoot;
  48280. generator._file = scriptMap.file;
  48281. return generator.toJSON();
  48282. }
  48283. var __defProp = Object.defineProperty;
  48284. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  48285. var __hasOwnProp = Object.prototype.hasOwnProperty;
  48286. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  48287. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  48288. var __spreadValues = (a, b) => {
  48289. for (var prop in b || (b = {}))
  48290. if (__hasOwnProp.call(b, prop))
  48291. __defNormalProp(a, prop, b[prop]);
  48292. if (__getOwnPropSymbols)
  48293. for (var prop of __getOwnPropSymbols(b)) {
  48294. if (__propIsEnum.call(b, prop))
  48295. __defNormalProp(a, prop, b[prop]);
  48296. }
  48297. return a;
  48298. };
  48299. const version = "3.5.33";
  48300. const parseCache = parseCache$1;
  48301. const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
  48302. const walk = walk$2;
  48303. const shouldTransformRef = () => false;
  48304. var parse$4 = libExports.parse;
  48305. 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 };