compiler-sfc.esm-browser.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480
  1. /**
  2. * @vue/compiler-sfc v3.5.19
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. /*! #__NO_SIDE_EFFECTS__ */
  7. // @__NO_SIDE_EFFECTS__
  8. function makeMap(str) {
  9. const map = /* @__PURE__ */ Object.create(null);
  10. for (const key of str.split(",")) map[key] = 1;
  11. return (val) => val in map;
  12. }
  13. const EMPTY_OBJ = Object.freeze({}) ;
  14. const NOOP = () => {
  15. };
  16. const NO = () => false;
  17. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  18. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  19. const extend = Object.assign;
  20. const hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  21. const hasOwn = (val, key) => hasOwnProperty$3.call(val, key);
  22. const isArray$3 = Array.isArray;
  23. const isMap = (val) => toTypeString(val) === "[object Map]";
  24. const isSet = (val) => toTypeString(val) === "[object Set]";
  25. const isFunction$1 = (val) => typeof val === "function";
  26. const isString$1 = (val) => typeof val === "string";
  27. const isSymbol$1 = (val) => typeof val === "symbol";
  28. const isObject$2 = (val) => val !== null && typeof val === "object";
  29. const objectToString$1 = Object.prototype.toString;
  30. const toTypeString = (value) => objectToString$1.call(value);
  31. const isPlainObject = (val) => toTypeString(val) === "[object Object]";
  32. const isReservedProp = /* @__PURE__ */ makeMap(
  33. // the leading comma is intentional so empty string "" is also included
  34. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  35. );
  36. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  37. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  38. );
  39. const cacheStringFunction = (fn) => {
  40. const cache = /* @__PURE__ */ Object.create(null);
  41. return ((str) => {
  42. const hit = cache[str];
  43. return hit || (cache[str] = fn(str));
  44. });
  45. };
  46. const camelizeRE = /-(\w)/g;
  47. const camelize = cacheStringFunction(
  48. (str) => {
  49. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  50. }
  51. );
  52. const hyphenateRE = /\B([A-Z])/g;
  53. const hyphenate = cacheStringFunction(
  54. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  55. );
  56. const capitalize = cacheStringFunction((str) => {
  57. return str.charAt(0).toUpperCase() + str.slice(1);
  58. });
  59. const toHandlerKey = cacheStringFunction(
  60. (str) => {
  61. const s = str ? `on${capitalize(str)}` : ``;
  62. return s;
  63. }
  64. );
  65. const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
  66. function genPropsAccessExp(name) {
  67. return identRE.test(name) ? `__props.${name}` : `__props[${JSON.stringify(name)}]`;
  68. }
  69. function genCacheKey(source, options) {
  70. return source + JSON.stringify(
  71. options,
  72. (_, val) => typeof val === "function" ? val.toString() : val
  73. );
  74. }
  75. const PatchFlagNames = {
  76. [1]: `TEXT`,
  77. [2]: `CLASS`,
  78. [4]: `STYLE`,
  79. [8]: `PROPS`,
  80. [16]: `FULL_PROPS`,
  81. [32]: `NEED_HYDRATION`,
  82. [64]: `STABLE_FRAGMENT`,
  83. [128]: `KEYED_FRAGMENT`,
  84. [256]: `UNKEYED_FRAGMENT`,
  85. [512]: `NEED_PATCH`,
  86. [1024]: `DYNAMIC_SLOTS`,
  87. [2048]: `DEV_ROOT_FRAGMENT`,
  88. [-1]: `CACHED`,
  89. [-2]: `BAIL`
  90. };
  91. const slotFlagsText = {
  92. [1]: "STABLE",
  93. [2]: "DYNAMIC",
  94. [3]: "FORWARDED"
  95. };
  96. 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";
  97. const isGloballyAllowed = /* @__PURE__ */ makeMap(GLOBALS_ALLOWED);
  98. const range = 2;
  99. function generateCodeFrame(source, start = 0, end = source.length) {
  100. start = Math.max(0, Math.min(start, source.length));
  101. end = Math.max(0, Math.min(end, source.length));
  102. if (start > end) return "";
  103. let lines = source.split(/(\r?\n)/);
  104. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  105. lines = lines.filter((_, idx) => idx % 2 === 0);
  106. let count = 0;
  107. const res = [];
  108. for (let i = 0; i < lines.length; i++) {
  109. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  110. if (count >= start) {
  111. for (let j = i - range; j <= i + range || end > count; j++) {
  112. if (j < 0 || j >= lines.length) continue;
  113. const line = j + 1;
  114. res.push(
  115. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  116. );
  117. const lineLength = lines[j].length;
  118. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  119. if (j === i) {
  120. const pad = start - (count - (lineLength + newLineSeqLength));
  121. const length = Math.max(
  122. 1,
  123. end > count ? lineLength - pad : end - start
  124. );
  125. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  126. } else if (j > i) {
  127. if (end > count) {
  128. const length = Math.max(Math.min(end - count, lineLength), 1);
  129. res.push(` | ` + "^".repeat(length));
  130. }
  131. count += lineLength + newLineSeqLength;
  132. }
  133. }
  134. break;
  135. }
  136. }
  137. return res.join("\n");
  138. }
  139. function normalizeStyle(value) {
  140. if (isArray$3(value)) {
  141. const res = {};
  142. for (let i = 0; i < value.length; i++) {
  143. const item = value[i];
  144. const normalized = isString$1(item) ? parseStringStyle(item) : normalizeStyle(item);
  145. if (normalized) {
  146. for (const key in normalized) {
  147. res[key] = normalized[key];
  148. }
  149. }
  150. }
  151. return res;
  152. } else if (isString$1(value) || isObject$2(value)) {
  153. return value;
  154. }
  155. }
  156. const listDelimiterRE = /;(?![^(]*\))/g;
  157. const propertyDelimiterRE = /:([^]+)/;
  158. const styleCommentRE = /\/\*[^]*?\*\//g;
  159. function parseStringStyle(cssText) {
  160. const ret = {};
  161. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  162. if (item) {
  163. const tmp = item.split(propertyDelimiterRE);
  164. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  165. }
  166. });
  167. return ret;
  168. }
  169. function stringifyStyle(styles) {
  170. if (!styles) return "";
  171. if (isString$1(styles)) return styles;
  172. let ret = "";
  173. for (const key in styles) {
  174. const value = styles[key];
  175. if (isString$1(value) || typeof value === "number") {
  176. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  177. ret += `${normalizedKey}:${value};`;
  178. }
  179. }
  180. return ret;
  181. }
  182. function normalizeClass(value) {
  183. let res = "";
  184. if (isString$1(value)) {
  185. res = value;
  186. } else if (isArray$3(value)) {
  187. for (let i = 0; i < value.length; i++) {
  188. const normalized = normalizeClass(value[i]);
  189. if (normalized) {
  190. res += normalized + " ";
  191. }
  192. }
  193. } else if (isObject$2(value)) {
  194. for (const name in value) {
  195. if (value[name]) {
  196. res += name + " ";
  197. }
  198. }
  199. }
  200. return res.trim();
  201. }
  202. 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";
  203. 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";
  204. 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";
  205. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  206. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  207. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  208. const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
  209. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  210. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  211. const isBooleanAttr = /* @__PURE__ */ makeMap(
  212. specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
  213. );
  214. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  215. const attrValidationCache = {};
  216. function isSSRSafeAttrName(name) {
  217. if (attrValidationCache.hasOwnProperty(name)) {
  218. return attrValidationCache[name];
  219. }
  220. const isUnsafe = unsafeAttrCharRE.test(name);
  221. if (isUnsafe) {
  222. console.error(`unsafe attribute name: ${name}`);
  223. }
  224. return attrValidationCache[name] = !isUnsafe;
  225. }
  226. const propsToAttrMap = {
  227. acceptCharset: "accept-charset",
  228. className: "class",
  229. htmlFor: "for",
  230. httpEquiv: "http-equiv"
  231. };
  232. const isKnownHtmlAttr = /* @__PURE__ */ makeMap(
  233. `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`
  234. );
  235. const isKnownSvgAttr = /* @__PURE__ */ makeMap(
  236. `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`
  237. );
  238. const isKnownMathMLAttr = /* @__PURE__ */ makeMap(
  239. `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`
  240. );
  241. const escapeRE = /["'&<>]/;
  242. function escapeHtml(string) {
  243. const str = "" + string;
  244. const match = escapeRE.exec(str);
  245. if (!match) {
  246. return str;
  247. }
  248. let html = "";
  249. let escaped;
  250. let index;
  251. let lastIndex = 0;
  252. for (index = match.index; index < str.length; index++) {
  253. switch (str.charCodeAt(index)) {
  254. case 34:
  255. escaped = "&quot;";
  256. break;
  257. case 38:
  258. escaped = "&amp;";
  259. break;
  260. case 39:
  261. escaped = "&#39;";
  262. break;
  263. case 60:
  264. escaped = "&lt;";
  265. break;
  266. case 62:
  267. escaped = "&gt;";
  268. break;
  269. default:
  270. continue;
  271. }
  272. if (lastIndex !== index) {
  273. html += str.slice(lastIndex, index);
  274. }
  275. lastIndex = index + 1;
  276. html += escaped;
  277. }
  278. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  279. }
  280. const cssVarNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g;
  281. function getEscapedCssVarName(key, doubleEscape) {
  282. return key.replace(
  283. cssVarNameEscapeSymbolsRE,
  284. (s) => doubleEscape ? s === '"' ? '\\\\\\"' : `\\\\${s}` : `\\${s}`
  285. );
  286. }
  287. const isRef = (val) => {
  288. return !!(val && val["__v_isRef"] === true);
  289. };
  290. const toDisplayString = (val) => {
  291. 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);
  292. };
  293. const replacer = (_key, val) => {
  294. if (isRef(val)) {
  295. return replacer(_key, val.value);
  296. } else if (isMap(val)) {
  297. return {
  298. [`Map(${val.size})`]: [...val.entries()].reduce(
  299. (entries, [key, val2], i) => {
  300. entries[stringifySymbol(key, i) + " =>"] = val2;
  301. return entries;
  302. },
  303. {}
  304. )
  305. };
  306. } else if (isSet(val)) {
  307. return {
  308. [`Set(${val.size})`]: [...val.values()].map((v) => stringifySymbol(v))
  309. };
  310. } else if (isSymbol$1(val)) {
  311. return stringifySymbol(val);
  312. } else if (isObject$2(val) && !isArray$3(val) && !isPlainObject(val)) {
  313. return String(val);
  314. }
  315. return val;
  316. };
  317. const stringifySymbol = (v, i = "") => {
  318. var _a;
  319. return (
  320. // Symbol.description in es2019+ so we need to cast here to pass
  321. // the lib: es2016 check
  322. isSymbol$1(v) ? `Symbol(${(_a = v.description) != null ? _a : i})` : v
  323. );
  324. };
  325. const FRAGMENT = Symbol(`Fragment` );
  326. const TELEPORT = Symbol(`Teleport` );
  327. const SUSPENSE = Symbol(`Suspense` );
  328. const KEEP_ALIVE = Symbol(`KeepAlive` );
  329. const BASE_TRANSITION = Symbol(
  330. `BaseTransition`
  331. );
  332. const OPEN_BLOCK = Symbol(`openBlock` );
  333. const CREATE_BLOCK = Symbol(`createBlock` );
  334. const CREATE_ELEMENT_BLOCK = Symbol(
  335. `createElementBlock`
  336. );
  337. const CREATE_VNODE = Symbol(`createVNode` );
  338. const CREATE_ELEMENT_VNODE = Symbol(
  339. `createElementVNode`
  340. );
  341. const CREATE_COMMENT = Symbol(
  342. `createCommentVNode`
  343. );
  344. const CREATE_TEXT = Symbol(
  345. `createTextVNode`
  346. );
  347. const CREATE_STATIC = Symbol(
  348. `createStaticVNode`
  349. );
  350. const RESOLVE_COMPONENT = Symbol(
  351. `resolveComponent`
  352. );
  353. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  354. `resolveDynamicComponent`
  355. );
  356. const RESOLVE_DIRECTIVE = Symbol(
  357. `resolveDirective`
  358. );
  359. const RESOLVE_FILTER = Symbol(
  360. `resolveFilter`
  361. );
  362. const WITH_DIRECTIVES = Symbol(
  363. `withDirectives`
  364. );
  365. const RENDER_LIST = Symbol(`renderList` );
  366. const RENDER_SLOT = Symbol(`renderSlot` );
  367. const CREATE_SLOTS = Symbol(`createSlots` );
  368. const TO_DISPLAY_STRING = Symbol(
  369. `toDisplayString`
  370. );
  371. const MERGE_PROPS = Symbol(`mergeProps` );
  372. const NORMALIZE_CLASS = Symbol(
  373. `normalizeClass`
  374. );
  375. const NORMALIZE_STYLE = Symbol(
  376. `normalizeStyle`
  377. );
  378. const NORMALIZE_PROPS = Symbol(
  379. `normalizeProps`
  380. );
  381. const GUARD_REACTIVE_PROPS = Symbol(
  382. `guardReactiveProps`
  383. );
  384. const TO_HANDLERS = Symbol(`toHandlers` );
  385. const CAMELIZE = Symbol(`camelize` );
  386. const CAPITALIZE = Symbol(`capitalize` );
  387. const TO_HANDLER_KEY = Symbol(
  388. `toHandlerKey`
  389. );
  390. const SET_BLOCK_TRACKING = Symbol(
  391. `setBlockTracking`
  392. );
  393. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  394. const POP_SCOPE_ID = Symbol(`popScopeId` );
  395. const WITH_CTX = Symbol(`withCtx` );
  396. const UNREF = Symbol(`unref` );
  397. const IS_REF = Symbol(`isRef` );
  398. const WITH_MEMO = Symbol(`withMemo` );
  399. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  400. const helperNameMap = {
  401. [FRAGMENT]: `Fragment`,
  402. [TELEPORT]: `Teleport`,
  403. [SUSPENSE]: `Suspense`,
  404. [KEEP_ALIVE]: `KeepAlive`,
  405. [BASE_TRANSITION]: `BaseTransition`,
  406. [OPEN_BLOCK]: `openBlock`,
  407. [CREATE_BLOCK]: `createBlock`,
  408. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  409. [CREATE_VNODE]: `createVNode`,
  410. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  411. [CREATE_COMMENT]: `createCommentVNode`,
  412. [CREATE_TEXT]: `createTextVNode`,
  413. [CREATE_STATIC]: `createStaticVNode`,
  414. [RESOLVE_COMPONENT]: `resolveComponent`,
  415. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  416. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  417. [RESOLVE_FILTER]: `resolveFilter`,
  418. [WITH_DIRECTIVES]: `withDirectives`,
  419. [RENDER_LIST]: `renderList`,
  420. [RENDER_SLOT]: `renderSlot`,
  421. [CREATE_SLOTS]: `createSlots`,
  422. [TO_DISPLAY_STRING]: `toDisplayString`,
  423. [MERGE_PROPS]: `mergeProps`,
  424. [NORMALIZE_CLASS]: `normalizeClass`,
  425. [NORMALIZE_STYLE]: `normalizeStyle`,
  426. [NORMALIZE_PROPS]: `normalizeProps`,
  427. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  428. [TO_HANDLERS]: `toHandlers`,
  429. [CAMELIZE]: `camelize`,
  430. [CAPITALIZE]: `capitalize`,
  431. [TO_HANDLER_KEY]: `toHandlerKey`,
  432. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  433. [PUSH_SCOPE_ID]: `pushScopeId`,
  434. [POP_SCOPE_ID]: `popScopeId`,
  435. [WITH_CTX]: `withCtx`,
  436. [UNREF]: `unref`,
  437. [IS_REF]: `isRef`,
  438. [WITH_MEMO]: `withMemo`,
  439. [IS_MEMO_SAME]: `isMemoSame`
  440. };
  441. function registerRuntimeHelpers(helpers) {
  442. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  443. helperNameMap[s] = helpers[s];
  444. });
  445. }
  446. const Namespaces = {
  447. "HTML": 0,
  448. "0": "HTML",
  449. "SVG": 1,
  450. "1": "SVG",
  451. "MATH_ML": 2,
  452. "2": "MATH_ML"
  453. };
  454. const NodeTypes = {
  455. "ROOT": 0,
  456. "0": "ROOT",
  457. "ELEMENT": 1,
  458. "1": "ELEMENT",
  459. "TEXT": 2,
  460. "2": "TEXT",
  461. "COMMENT": 3,
  462. "3": "COMMENT",
  463. "SIMPLE_EXPRESSION": 4,
  464. "4": "SIMPLE_EXPRESSION",
  465. "INTERPOLATION": 5,
  466. "5": "INTERPOLATION",
  467. "ATTRIBUTE": 6,
  468. "6": "ATTRIBUTE",
  469. "DIRECTIVE": 7,
  470. "7": "DIRECTIVE",
  471. "COMPOUND_EXPRESSION": 8,
  472. "8": "COMPOUND_EXPRESSION",
  473. "IF": 9,
  474. "9": "IF",
  475. "IF_BRANCH": 10,
  476. "10": "IF_BRANCH",
  477. "FOR": 11,
  478. "11": "FOR",
  479. "TEXT_CALL": 12,
  480. "12": "TEXT_CALL",
  481. "VNODE_CALL": 13,
  482. "13": "VNODE_CALL",
  483. "JS_CALL_EXPRESSION": 14,
  484. "14": "JS_CALL_EXPRESSION",
  485. "JS_OBJECT_EXPRESSION": 15,
  486. "15": "JS_OBJECT_EXPRESSION",
  487. "JS_PROPERTY": 16,
  488. "16": "JS_PROPERTY",
  489. "JS_ARRAY_EXPRESSION": 17,
  490. "17": "JS_ARRAY_EXPRESSION",
  491. "JS_FUNCTION_EXPRESSION": 18,
  492. "18": "JS_FUNCTION_EXPRESSION",
  493. "JS_CONDITIONAL_EXPRESSION": 19,
  494. "19": "JS_CONDITIONAL_EXPRESSION",
  495. "JS_CACHE_EXPRESSION": 20,
  496. "20": "JS_CACHE_EXPRESSION",
  497. "JS_BLOCK_STATEMENT": 21,
  498. "21": "JS_BLOCK_STATEMENT",
  499. "JS_TEMPLATE_LITERAL": 22,
  500. "22": "JS_TEMPLATE_LITERAL",
  501. "JS_IF_STATEMENT": 23,
  502. "23": "JS_IF_STATEMENT",
  503. "JS_ASSIGNMENT_EXPRESSION": 24,
  504. "24": "JS_ASSIGNMENT_EXPRESSION",
  505. "JS_SEQUENCE_EXPRESSION": 25,
  506. "25": "JS_SEQUENCE_EXPRESSION",
  507. "JS_RETURN_STATEMENT": 26,
  508. "26": "JS_RETURN_STATEMENT"
  509. };
  510. const ElementTypes = {
  511. "ELEMENT": 0,
  512. "0": "ELEMENT",
  513. "COMPONENT": 1,
  514. "1": "COMPONENT",
  515. "SLOT": 2,
  516. "2": "SLOT",
  517. "TEMPLATE": 3,
  518. "3": "TEMPLATE"
  519. };
  520. const ConstantTypes = {
  521. "NOT_CONSTANT": 0,
  522. "0": "NOT_CONSTANT",
  523. "CAN_SKIP_PATCH": 1,
  524. "1": "CAN_SKIP_PATCH",
  525. "CAN_CACHE": 2,
  526. "2": "CAN_CACHE",
  527. "CAN_STRINGIFY": 3,
  528. "3": "CAN_STRINGIFY"
  529. };
  530. const locStub = {
  531. start: { line: 1, column: 1, offset: 0 },
  532. end: { line: 1, column: 1, offset: 0 },
  533. source: ""
  534. };
  535. function createRoot(children, source = "") {
  536. return {
  537. type: 0,
  538. source,
  539. children,
  540. helpers: /* @__PURE__ */ new Set(),
  541. components: [],
  542. directives: [],
  543. hoists: [],
  544. imports: [],
  545. cached: [],
  546. temps: 0,
  547. codegenNode: void 0,
  548. loc: locStub
  549. };
  550. }
  551. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  552. if (context) {
  553. if (isBlock) {
  554. context.helper(OPEN_BLOCK);
  555. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  556. } else {
  557. context.helper(getVNodeHelper(context.inSSR, isComponent));
  558. }
  559. if (directives) {
  560. context.helper(WITH_DIRECTIVES);
  561. }
  562. }
  563. return {
  564. type: 13,
  565. tag,
  566. props,
  567. children,
  568. patchFlag,
  569. dynamicProps,
  570. directives,
  571. isBlock,
  572. disableTracking,
  573. isComponent,
  574. loc
  575. };
  576. }
  577. function createArrayExpression(elements, loc = locStub) {
  578. return {
  579. type: 17,
  580. loc,
  581. elements
  582. };
  583. }
  584. function createObjectExpression(properties, loc = locStub) {
  585. return {
  586. type: 15,
  587. loc,
  588. properties
  589. };
  590. }
  591. function createObjectProperty(key, value) {
  592. return {
  593. type: 16,
  594. loc: locStub,
  595. key: isString$1(key) ? createSimpleExpression(key, true) : key,
  596. value
  597. };
  598. }
  599. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  600. return {
  601. type: 4,
  602. loc,
  603. content,
  604. isStatic,
  605. constType: isStatic ? 3 : constType
  606. };
  607. }
  608. function createInterpolation(content, loc) {
  609. return {
  610. type: 5,
  611. loc,
  612. content: isString$1(content) ? createSimpleExpression(content, false, loc) : content
  613. };
  614. }
  615. function createCompoundExpression(children, loc = locStub) {
  616. return {
  617. type: 8,
  618. loc,
  619. children
  620. };
  621. }
  622. function createCallExpression(callee, args = [], loc = locStub) {
  623. return {
  624. type: 14,
  625. loc,
  626. callee,
  627. arguments: args
  628. };
  629. }
  630. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  631. return {
  632. type: 18,
  633. params,
  634. returns,
  635. newline,
  636. isSlot,
  637. loc
  638. };
  639. }
  640. function createConditionalExpression(test, consequent, alternate, newline = true) {
  641. return {
  642. type: 19,
  643. test,
  644. consequent,
  645. alternate,
  646. newline,
  647. loc: locStub
  648. };
  649. }
  650. function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
  651. return {
  652. type: 20,
  653. index,
  654. value,
  655. needPauseTracking,
  656. inVOnce,
  657. needArraySpread: false,
  658. loc: locStub
  659. };
  660. }
  661. function createBlockStatement(body) {
  662. return {
  663. type: 21,
  664. body,
  665. loc: locStub
  666. };
  667. }
  668. function createTemplateLiteral(elements) {
  669. return {
  670. type: 22,
  671. elements,
  672. loc: locStub
  673. };
  674. }
  675. function createIfStatement(test, consequent, alternate) {
  676. return {
  677. type: 23,
  678. test,
  679. consequent,
  680. alternate,
  681. loc: locStub
  682. };
  683. }
  684. function createAssignmentExpression(left, right) {
  685. return {
  686. type: 24,
  687. left,
  688. right,
  689. loc: locStub
  690. };
  691. }
  692. function createSequenceExpression(expressions) {
  693. return {
  694. type: 25,
  695. expressions,
  696. loc: locStub
  697. };
  698. }
  699. function createReturnStatement(returns) {
  700. return {
  701. type: 26,
  702. returns,
  703. loc: locStub
  704. };
  705. }
  706. function getVNodeHelper(ssr, isComponent) {
  707. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  708. }
  709. function getVNodeBlockHelper(ssr, isComponent) {
  710. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  711. }
  712. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  713. if (!node.isBlock) {
  714. node.isBlock = true;
  715. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  716. helper(OPEN_BLOCK);
  717. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  718. }
  719. }
  720. // Generated using scripts/write-decode-map.ts
  721. var htmlDecodeTree = new Uint16Array(
  722. // prettier-ignore
  723. "\u1d41<\xd5\u0131\u028a\u049d\u057b\u05d0\u0675\u06de\u07a2\u07d6\u080f\u0a4a\u0a91\u0da1\u0e6d\u0f09\u0f26\u10ca\u1228\u12e1\u1415\u149d\u14c3\u14df\u1525\0\0\0\0\0\0\u156b\u16cd\u198d\u1c12\u1ddd\u1f7e\u2060\u21b0\u228d\u23c0\u23fb\u2442\u2824\u2912\u2d08\u2e48\u2fce\u3016\u32ba\u3639\u37ac\u38fe\u3a28\u3a71\u3ae0\u3b2e\u0800EMabcfglmnoprstu\\bfms\x7f\x84\x8b\x90\x95\x98\xa6\xb3\xb9\xc8\xcflig\u803b\xc6\u40c6P\u803b&\u4026cute\u803b\xc1\u40c1reve;\u4102\u0100iyx}rc\u803b\xc2\u40c2;\u4410r;\uc000\ud835\udd04rave\u803b\xc0\u40c0pha;\u4391acr;\u4100d;\u6a53\u0100gp\x9d\xa1on;\u4104f;\uc000\ud835\udd38plyFunction;\u6061ing\u803b\xc5\u40c5\u0100cs\xbe\xc3r;\uc000\ud835\udc9cign;\u6254ilde\u803b\xc3\u40c3ml\u803b\xc4\u40c4\u0400aceforsu\xe5\xfb\xfe\u0117\u011c\u0122\u0127\u012a\u0100cr\xea\xf2kslash;\u6216\u0176\xf6\xf8;\u6ae7ed;\u6306y;\u4411\u0180crt\u0105\u010b\u0114ause;\u6235noullis;\u612ca;\u4392r;\uc000\ud835\udd05pf;\uc000\ud835\udd39eve;\u42d8c\xf2\u0113mpeq;\u624e\u0700HOacdefhilorsu\u014d\u0151\u0156\u0180\u019e\u01a2\u01b5\u01b7\u01ba\u01dc\u0215\u0273\u0278\u027ecy;\u4427PY\u803b\xa9\u40a9\u0180cpy\u015d\u0162\u017aute;\u4106\u0100;i\u0167\u0168\u62d2talDifferentialD;\u6145leys;\u612d\u0200aeio\u0189\u018e\u0194\u0198ron;\u410cdil\u803b\xc7\u40c7rc;\u4108nint;\u6230ot;\u410a\u0100dn\u01a7\u01adilla;\u40b8terDot;\u40b7\xf2\u017fi;\u43a7rcle\u0200DMPT\u01c7\u01cb\u01d1\u01d6ot;\u6299inus;\u6296lus;\u6295imes;\u6297o\u0100cs\u01e2\u01f8kwiseContourIntegral;\u6232eCurly\u0100DQ\u0203\u020foubleQuote;\u601duote;\u6019\u0200lnpu\u021e\u0228\u0247\u0255on\u0100;e\u0225\u0226\u6237;\u6a74\u0180git\u022f\u0236\u023aruent;\u6261nt;\u622fourIntegral;\u622e\u0100fr\u024c\u024e;\u6102oduct;\u6210nterClockwiseContourIntegral;\u6233oss;\u6a2fcr;\uc000\ud835\udc9ep\u0100;C\u0284\u0285\u62d3ap;\u624d\u0580DJSZacefios\u02a0\u02ac\u02b0\u02b4\u02b8\u02cb\u02d7\u02e1\u02e6\u0333\u048d\u0100;o\u0179\u02a5trahd;\u6911cy;\u4402cy;\u4405cy;\u440f\u0180grs\u02bf\u02c4\u02c7ger;\u6021r;\u61a1hv;\u6ae4\u0100ay\u02d0\u02d5ron;\u410e;\u4414l\u0100;t\u02dd\u02de\u6207a;\u4394r;\uc000\ud835\udd07\u0100af\u02eb\u0327\u0100cm\u02f0\u0322ritical\u0200ADGT\u0300\u0306\u0316\u031ccute;\u40b4o\u0174\u030b\u030d;\u42d9bleAcute;\u42ddrave;\u4060ilde;\u42dcond;\u62c4ferentialD;\u6146\u0470\u033d\0\0\0\u0342\u0354\0\u0405f;\uc000\ud835\udd3b\u0180;DE\u0348\u0349\u034d\u40a8ot;\u60dcqual;\u6250ble\u0300CDLRUV\u0363\u0372\u0382\u03cf\u03e2\u03f8ontourIntegra\xec\u0239o\u0274\u0379\0\0\u037b\xbb\u0349nArrow;\u61d3\u0100eo\u0387\u03a4ft\u0180ART\u0390\u0396\u03a1rrow;\u61d0ightArrow;\u61d4e\xe5\u02cang\u0100LR\u03ab\u03c4eft\u0100AR\u03b3\u03b9rrow;\u67f8ightArrow;\u67faightArrow;\u67f9ight\u0100AT\u03d8\u03derrow;\u61d2ee;\u62a8p\u0241\u03e9\0\0\u03efrrow;\u61d1ownArrow;\u61d5erticalBar;\u6225n\u0300ABLRTa\u0412\u042a\u0430\u045e\u047f\u037crrow\u0180;BU\u041d\u041e\u0422\u6193ar;\u6913pArrow;\u61f5reve;\u4311eft\u02d2\u043a\0\u0446\0\u0450ightVector;\u6950eeVector;\u695eector\u0100;B\u0459\u045a\u61bdar;\u6956ight\u01d4\u0467\0\u0471eeVector;\u695fector\u0100;B\u047a\u047b\u61c1ar;\u6957ee\u0100;A\u0486\u0487\u62a4rrow;\u61a7\u0100ct\u0492\u0497r;\uc000\ud835\udc9frok;\u4110\u0800NTacdfglmopqstux\u04bd\u04c0\u04c4\u04cb\u04de\u04e2\u04e7\u04ee\u04f5\u0521\u052f\u0536\u0552\u055d\u0560\u0565G;\u414aH\u803b\xd0\u40d0cute\u803b\xc9\u40c9\u0180aiy\u04d2\u04d7\u04dcron;\u411arc\u803b\xca\u40ca;\u442dot;\u4116r;\uc000\ud835\udd08rave\u803b\xc8\u40c8ement;\u6208\u0100ap\u04fa\u04fecr;\u4112ty\u0253\u0506\0\0\u0512mallSquare;\u65fberySmallSquare;\u65ab\u0100gp\u0526\u052aon;\u4118f;\uc000\ud835\udd3csilon;\u4395u\u0100ai\u053c\u0549l\u0100;T\u0542\u0543\u6a75ilde;\u6242librium;\u61cc\u0100ci\u0557\u055ar;\u6130m;\u6a73a;\u4397ml\u803b\xcb\u40cb\u0100ip\u056a\u056fsts;\u6203onentialE;\u6147\u0280cfios\u0585\u0588\u058d\u05b2\u05ccy;\u4424r;\uc000\ud835\udd09lled\u0253\u0597\0\0\u05a3mallSquare;\u65fcerySmallSquare;\u65aa\u0370\u05ba\0\u05bf\0\0\u05c4f;\uc000\ud835\udd3dAll;\u6200riertrf;\u6131c\xf2\u05cb\u0600JTabcdfgorst\u05e8\u05ec\u05ef\u05fa\u0600\u0612\u0616\u061b\u061d\u0623\u066c\u0672cy;\u4403\u803b>\u403emma\u0100;d\u05f7\u05f8\u4393;\u43dcreve;\u411e\u0180eiy\u0607\u060c\u0610dil;\u4122rc;\u411c;\u4413ot;\u4120r;\uc000\ud835\udd0a;\u62d9pf;\uc000\ud835\udd3eeater\u0300EFGLST\u0635\u0644\u064e\u0656\u065b\u0666qual\u0100;L\u063e\u063f\u6265ess;\u62dbullEqual;\u6267reater;\u6aa2ess;\u6277lantEqual;\u6a7eilde;\u6273cr;\uc000\ud835\udca2;\u626b\u0400Aacfiosu\u0685\u068b\u0696\u069b\u069e\u06aa\u06be\u06caRDcy;\u442a\u0100ct\u0690\u0694ek;\u42c7;\u405eirc;\u4124r;\u610clbertSpace;\u610b\u01f0\u06af\0\u06b2f;\u610dizontalLine;\u6500\u0100ct\u06c3\u06c5\xf2\u06a9rok;\u4126mp\u0144\u06d0\u06d8ownHum\xf0\u012fqual;\u624f\u0700EJOacdfgmnostu\u06fa\u06fe\u0703\u0707\u070e\u071a\u071e\u0721\u0728\u0744\u0778\u078b\u078f\u0795cy;\u4415lig;\u4132cy;\u4401cute\u803b\xcd\u40cd\u0100iy\u0713\u0718rc\u803b\xce\u40ce;\u4418ot;\u4130r;\u6111rave\u803b\xcc\u40cc\u0180;ap\u0720\u072f\u073f\u0100cg\u0734\u0737r;\u412ainaryI;\u6148lie\xf3\u03dd\u01f4\u0749\0\u0762\u0100;e\u074d\u074e\u622c\u0100gr\u0753\u0758ral;\u622bsection;\u62c2isible\u0100CT\u076c\u0772omma;\u6063imes;\u6062\u0180gpt\u077f\u0783\u0788on;\u412ef;\uc000\ud835\udd40a;\u4399cr;\u6110ilde;\u4128\u01eb\u079a\0\u079ecy;\u4406l\u803b\xcf\u40cf\u0280cfosu\u07ac\u07b7\u07bc\u07c2\u07d0\u0100iy\u07b1\u07b5rc;\u4134;\u4419r;\uc000\ud835\udd0dpf;\uc000\ud835\udd41\u01e3\u07c7\0\u07ccr;\uc000\ud835\udca5rcy;\u4408kcy;\u4404\u0380HJacfos\u07e4\u07e8\u07ec\u07f1\u07fd\u0802\u0808cy;\u4425cy;\u440cppa;\u439a\u0100ey\u07f6\u07fbdil;\u4136;\u441ar;\uc000\ud835\udd0epf;\uc000\ud835\udd42cr;\uc000\ud835\udca6\u0580JTaceflmost\u0825\u0829\u082c\u0850\u0863\u09b3\u09b8\u09c7\u09cd\u0a37\u0a47cy;\u4409\u803b<\u403c\u0280cmnpr\u0837\u083c\u0841\u0844\u084dute;\u4139bda;\u439bg;\u67ealacetrf;\u6112r;\u619e\u0180aey\u0857\u085c\u0861ron;\u413ddil;\u413b;\u441b\u0100fs\u0868\u0970t\u0500ACDFRTUVar\u087e\u08a9\u08b1\u08e0\u08e6\u08fc\u092f\u095b\u0390\u096a\u0100nr\u0883\u088fgleBracket;\u67e8row\u0180;BR\u0899\u089a\u089e\u6190ar;\u61e4ightArrow;\u61c6eiling;\u6308o\u01f5\u08b7\0\u08c3bleBracket;\u67e6n\u01d4\u08c8\0\u08d2eeVector;\u6961ector\u0100;B\u08db\u08dc\u61c3ar;\u6959loor;\u630aight\u0100AV\u08ef\u08f5rrow;\u6194ector;\u694e\u0100er\u0901\u0917e\u0180;AV\u0909\u090a\u0910\u62a3rrow;\u61a4ector;\u695aiangle\u0180;BE\u0924\u0925\u0929\u62b2ar;\u69cfqual;\u62b4p\u0180DTV\u0937\u0942\u094cownVector;\u6951eeVector;\u6960ector\u0100;B\u0956\u0957\u61bfar;\u6958ector\u0100;B\u0965\u0966\u61bcar;\u6952ight\xe1\u039cs\u0300EFGLST\u097e\u098b\u0995\u099d\u09a2\u09adqualGreater;\u62daullEqual;\u6266reater;\u6276ess;\u6aa1lantEqual;\u6a7dilde;\u6272r;\uc000\ud835\udd0f\u0100;e\u09bd\u09be\u62d8ftarrow;\u61daidot;\u413f\u0180npw\u09d4\u0a16\u0a1bg\u0200LRlr\u09de\u09f7\u0a02\u0a10eft\u0100AR\u09e6\u09ecrrow;\u67f5ightArrow;\u67f7ightArrow;\u67f6eft\u0100ar\u03b3\u0a0aight\xe1\u03bfight\xe1\u03caf;\uc000\ud835\udd43er\u0100LR\u0a22\u0a2ceftArrow;\u6199ightArrow;\u6198\u0180cht\u0a3e\u0a40\u0a42\xf2\u084c;\u61b0rok;\u4141;\u626a\u0400acefiosu\u0a5a\u0a5d\u0a60\u0a77\u0a7c\u0a85\u0a8b\u0a8ep;\u6905y;\u441c\u0100dl\u0a65\u0a6fiumSpace;\u605flintrf;\u6133r;\uc000\ud835\udd10nusPlus;\u6213pf;\uc000\ud835\udd44c\xf2\u0a76;\u439c\u0480Jacefostu\u0aa3\u0aa7\u0aad\u0ac0\u0b14\u0b19\u0d91\u0d97\u0d9ecy;\u440acute;\u4143\u0180aey\u0ab4\u0ab9\u0aberon;\u4147dil;\u4145;\u441d\u0180gsw\u0ac7\u0af0\u0b0eative\u0180MTV\u0ad3\u0adf\u0ae8ediumSpace;\u600bhi\u0100cn\u0ae6\u0ad8\xeb\u0ad9eryThi\xee\u0ad9ted\u0100GL\u0af8\u0b06reaterGreate\xf2\u0673essLes\xf3\u0a48Line;\u400ar;\uc000\ud835\udd11\u0200Bnpt\u0b22\u0b28\u0b37\u0b3areak;\u6060BreakingSpace;\u40a0f;\u6115\u0680;CDEGHLNPRSTV\u0b55\u0b56\u0b6a\u0b7c\u0ba1\u0beb\u0c04\u0c5e\u0c84\u0ca6\u0cd8\u0d61\u0d85\u6aec\u0100ou\u0b5b\u0b64ngruent;\u6262pCap;\u626doubleVerticalBar;\u6226\u0180lqx\u0b83\u0b8a\u0b9bement;\u6209ual\u0100;T\u0b92\u0b93\u6260ilde;\uc000\u2242\u0338ists;\u6204reater\u0380;EFGLST\u0bb6\u0bb7\u0bbd\u0bc9\u0bd3\u0bd8\u0be5\u626fqual;\u6271ullEqual;\uc000\u2267\u0338reater;\uc000\u226b\u0338ess;\u6279lantEqual;\uc000\u2a7e\u0338ilde;\u6275ump\u0144\u0bf2\u0bfdownHump;\uc000\u224e\u0338qual;\uc000\u224f\u0338e\u0100fs\u0c0a\u0c27tTriangle\u0180;BE\u0c1a\u0c1b\u0c21\u62eaar;\uc000\u29cf\u0338qual;\u62ecs\u0300;EGLST\u0c35\u0c36\u0c3c\u0c44\u0c4b\u0c58\u626equal;\u6270reater;\u6278ess;\uc000\u226a\u0338lantEqual;\uc000\u2a7d\u0338ilde;\u6274ested\u0100GL\u0c68\u0c79reaterGreater;\uc000\u2aa2\u0338essLess;\uc000\u2aa1\u0338recedes\u0180;ES\u0c92\u0c93\u0c9b\u6280qual;\uc000\u2aaf\u0338lantEqual;\u62e0\u0100ei\u0cab\u0cb9verseElement;\u620cghtTriangle\u0180;BE\u0ccb\u0ccc\u0cd2\u62ebar;\uc000\u29d0\u0338qual;\u62ed\u0100qu\u0cdd\u0d0cuareSu\u0100bp\u0ce8\u0cf9set\u0100;E\u0cf0\u0cf3\uc000\u228f\u0338qual;\u62e2erset\u0100;E\u0d03\u0d06\uc000\u2290\u0338qual;\u62e3\u0180bcp\u0d13\u0d24\u0d4eset\u0100;E\u0d1b\u0d1e\uc000\u2282\u20d2qual;\u6288ceeds\u0200;EST\u0d32\u0d33\u0d3b\u0d46\u6281qual;\uc000\u2ab0\u0338lantEqual;\u62e1ilde;\uc000\u227f\u0338erset\u0100;E\u0d58\u0d5b\uc000\u2283\u20d2qual;\u6289ilde\u0200;EFT\u0d6e\u0d6f\u0d75\u0d7f\u6241qual;\u6244ullEqual;\u6247ilde;\u6249erticalBar;\u6224cr;\uc000\ud835\udca9ilde\u803b\xd1\u40d1;\u439d\u0700Eacdfgmoprstuv\u0dbd\u0dc2\u0dc9\u0dd5\u0ddb\u0de0\u0de7\u0dfc\u0e02\u0e20\u0e22\u0e32\u0e3f\u0e44lig;\u4152cute\u803b\xd3\u40d3\u0100iy\u0dce\u0dd3rc\u803b\xd4\u40d4;\u441eblac;\u4150r;\uc000\ud835\udd12rave\u803b\xd2\u40d2\u0180aei\u0dee\u0df2\u0df6cr;\u414cga;\u43a9cron;\u439fpf;\uc000\ud835\udd46enCurly\u0100DQ\u0e0e\u0e1aoubleQuote;\u601cuote;\u6018;\u6a54\u0100cl\u0e27\u0e2cr;\uc000\ud835\udcaaash\u803b\xd8\u40d8i\u016c\u0e37\u0e3cde\u803b\xd5\u40d5es;\u6a37ml\u803b\xd6\u40d6er\u0100BP\u0e4b\u0e60\u0100ar\u0e50\u0e53r;\u603eac\u0100ek\u0e5a\u0e5c;\u63deet;\u63b4arenthesis;\u63dc\u0480acfhilors\u0e7f\u0e87\u0e8a\u0e8f\u0e92\u0e94\u0e9d\u0eb0\u0efcrtialD;\u6202y;\u441fr;\uc000\ud835\udd13i;\u43a6;\u43a0usMinus;\u40b1\u0100ip\u0ea2\u0eadncareplan\xe5\u069df;\u6119\u0200;eio\u0eb9\u0eba\u0ee0\u0ee4\u6abbcedes\u0200;EST\u0ec8\u0ec9\u0ecf\u0eda\u627aqual;\u6aaflantEqual;\u627cilde;\u627eme;\u6033\u0100dp\u0ee9\u0eeeuct;\u620fortion\u0100;a\u0225\u0ef9l;\u621d\u0100ci\u0f01\u0f06r;\uc000\ud835\udcab;\u43a8\u0200Ufos\u0f11\u0f16\u0f1b\u0f1fOT\u803b\"\u4022r;\uc000\ud835\udd14pf;\u611acr;\uc000\ud835\udcac\u0600BEacefhiorsu\u0f3e\u0f43\u0f47\u0f60\u0f73\u0fa7\u0faa\u0fad\u1096\u10a9\u10b4\u10bearr;\u6910G\u803b\xae\u40ae\u0180cnr\u0f4e\u0f53\u0f56ute;\u4154g;\u67ebr\u0100;t\u0f5c\u0f5d\u61a0l;\u6916\u0180aey\u0f67\u0f6c\u0f71ron;\u4158dil;\u4156;\u4420\u0100;v\u0f78\u0f79\u611cerse\u0100EU\u0f82\u0f99\u0100lq\u0f87\u0f8eement;\u620builibrium;\u61cbpEquilibrium;\u696fr\xbb\u0f79o;\u43a1ght\u0400ACDFTUVa\u0fc1\u0feb\u0ff3\u1022\u1028\u105b\u1087\u03d8\u0100nr\u0fc6\u0fd2gleBracket;\u67e9row\u0180;BL\u0fdc\u0fdd\u0fe1\u6192ar;\u61e5eftArrow;\u61c4eiling;\u6309o\u01f5\u0ff9\0\u1005bleBracket;\u67e7n\u01d4\u100a\0\u1014eeVector;\u695dector\u0100;B\u101d\u101e\u61c2ar;\u6955loor;\u630b\u0100er\u102d\u1043e\u0180;AV\u1035\u1036\u103c\u62a2rrow;\u61a6ector;\u695biangle\u0180;BE\u1050\u1051\u1055\u62b3ar;\u69d0qual;\u62b5p\u0180DTV\u1063\u106e\u1078ownVector;\u694feeVector;\u695cector\u0100;B\u1082\u1083\u61bear;\u6954ector\u0100;B\u1091\u1092\u61c0ar;\u6953\u0100pu\u109b\u109ef;\u611dndImplies;\u6970ightarrow;\u61db\u0100ch\u10b9\u10bcr;\u611b;\u61b1leDelayed;\u69f4\u0680HOacfhimoqstu\u10e4\u10f1\u10f7\u10fd\u1119\u111e\u1151\u1156\u1161\u1167\u11b5\u11bb\u11bf\u0100Cc\u10e9\u10eeHcy;\u4429y;\u4428FTcy;\u442ccute;\u415a\u0280;aeiy\u1108\u1109\u110e\u1113\u1117\u6abcron;\u4160dil;\u415erc;\u415c;\u4421r;\uc000\ud835\udd16ort\u0200DLRU\u112a\u1134\u113e\u1149ownArrow\xbb\u041eeftArrow\xbb\u089aightArrow\xbb\u0fddpArrow;\u6191gma;\u43a3allCircle;\u6218pf;\uc000\ud835\udd4a\u0272\u116d\0\0\u1170t;\u621aare\u0200;ISU\u117b\u117c\u1189\u11af\u65a1ntersection;\u6293u\u0100bp\u118f\u119eset\u0100;E\u1197\u1198\u628fqual;\u6291erset\u0100;E\u11a8\u11a9\u6290qual;\u6292nion;\u6294cr;\uc000\ud835\udcaear;\u62c6\u0200bcmp\u11c8\u11db\u1209\u120b\u0100;s\u11cd\u11ce\u62d0et\u0100;E\u11cd\u11d5qual;\u6286\u0100ch\u11e0\u1205eeds\u0200;EST\u11ed\u11ee\u11f4\u11ff\u627bqual;\u6ab0lantEqual;\u627dilde;\u627fTh\xe1\u0f8c;\u6211\u0180;es\u1212\u1213\u1223\u62d1rset\u0100;E\u121c\u121d\u6283qual;\u6287et\xbb\u1213\u0580HRSacfhiors\u123e\u1244\u1249\u1255\u125e\u1271\u1276\u129f\u12c2\u12c8\u12d1ORN\u803b\xde\u40deADE;\u6122\u0100Hc\u124e\u1252cy;\u440by;\u4426\u0100bu\u125a\u125c;\u4009;\u43a4\u0180aey\u1265\u126a\u126fron;\u4164dil;\u4162;\u4422r;\uc000\ud835\udd17\u0100ei\u127b\u1289\u01f2\u1280\0\u1287efore;\u6234a;\u4398\u0100cn\u128e\u1298kSpace;\uc000\u205f\u200aSpace;\u6009lde\u0200;EFT\u12ab\u12ac\u12b2\u12bc\u623cqual;\u6243ullEqual;\u6245ilde;\u6248pf;\uc000\ud835\udd4bipleDot;\u60db\u0100ct\u12d6\u12dbr;\uc000\ud835\udcafrok;\u4166\u0ae1\u12f7\u130e\u131a\u1326\0\u132c\u1331\0\0\0\0\0\u1338\u133d\u1377\u1385\0\u13ff\u1404\u140a\u1410\u0100cr\u12fb\u1301ute\u803b\xda\u40dar\u0100;o\u1307\u1308\u619fcir;\u6949r\u01e3\u1313\0\u1316y;\u440eve;\u416c\u0100iy\u131e\u1323rc\u803b\xdb\u40db;\u4423blac;\u4170r;\uc000\ud835\udd18rave\u803b\xd9\u40d9acr;\u416a\u0100di\u1341\u1369er\u0100BP\u1348\u135d\u0100ar\u134d\u1350r;\u405fac\u0100ek\u1357\u1359;\u63dfet;\u63b5arenthesis;\u63ddon\u0100;P\u1370\u1371\u62c3lus;\u628e\u0100gp\u137b\u137fon;\u4172f;\uc000\ud835\udd4c\u0400ADETadps\u1395\u13ae\u13b8\u13c4\u03e8\u13d2\u13d7\u13f3rrow\u0180;BD\u1150\u13a0\u13a4ar;\u6912ownArrow;\u61c5ownArrow;\u6195quilibrium;\u696eee\u0100;A\u13cb\u13cc\u62a5rrow;\u61a5own\xe1\u03f3er\u0100LR\u13de\u13e8eftArrow;\u6196ightArrow;\u6197i\u0100;l\u13f9\u13fa\u43d2on;\u43a5ing;\u416ecr;\uc000\ud835\udcb0ilde;\u4168ml\u803b\xdc\u40dc\u0480Dbcdefosv\u1427\u142c\u1430\u1433\u143e\u1485\u148a\u1490\u1496ash;\u62abar;\u6aeby;\u4412ash\u0100;l\u143b\u143c\u62a9;\u6ae6\u0100er\u1443\u1445;\u62c1\u0180bty\u144c\u1450\u147aar;\u6016\u0100;i\u144f\u1455cal\u0200BLST\u1461\u1465\u146a\u1474ar;\u6223ine;\u407ceparator;\u6758ilde;\u6240ThinSpace;\u600ar;\uc000\ud835\udd19pf;\uc000\ud835\udd4dcr;\uc000\ud835\udcb1dash;\u62aa\u0280cefos\u14a7\u14ac\u14b1\u14b6\u14bcirc;\u4174dge;\u62c0r;\uc000\ud835\udd1apf;\uc000\ud835\udd4ecr;\uc000\ud835\udcb2\u0200fios\u14cb\u14d0\u14d2\u14d8r;\uc000\ud835\udd1b;\u439epf;\uc000\ud835\udd4fcr;\uc000\ud835\udcb3\u0480AIUacfosu\u14f1\u14f5\u14f9\u14fd\u1504\u150f\u1514\u151a\u1520cy;\u442fcy;\u4407cy;\u442ecute\u803b\xdd\u40dd\u0100iy\u1509\u150drc;\u4176;\u442br;\uc000\ud835\udd1cpf;\uc000\ud835\udd50cr;\uc000\ud835\udcb4ml;\u4178\u0400Hacdefos\u1535\u1539\u153f\u154b\u154f\u155d\u1560\u1564cy;\u4416cute;\u4179\u0100ay\u1544\u1549ron;\u417d;\u4417ot;\u417b\u01f2\u1554\0\u155boWidt\xe8\u0ad9a;\u4396r;\u6128pf;\u6124cr;\uc000\ud835\udcb5\u0be1\u1583\u158a\u1590\0\u15b0\u15b6\u15bf\0\0\0\0\u15c6\u15db\u15eb\u165f\u166d\0\u1695\u169b\u16b2\u16b9\0\u16becute\u803b\xe1\u40e1reve;\u4103\u0300;Ediuy\u159c\u159d\u15a1\u15a3\u15a8\u15ad\u623e;\uc000\u223e\u0333;\u623frc\u803b\xe2\u40e2te\u80bb\xb4\u0306;\u4430lig\u803b\xe6\u40e6\u0100;r\xb2\u15ba;\uc000\ud835\udd1erave\u803b\xe0\u40e0\u0100ep\u15ca\u15d6\u0100fp\u15cf\u15d4sym;\u6135\xe8\u15d3ha;\u43b1\u0100ap\u15dfc\u0100cl\u15e4\u15e7r;\u4101g;\u6a3f\u0264\u15f0\0\0\u160a\u0280;adsv\u15fa\u15fb\u15ff\u1601\u1607\u6227nd;\u6a55;\u6a5clope;\u6a58;\u6a5a\u0380;elmrsz\u1618\u1619\u161b\u161e\u163f\u164f\u1659\u6220;\u69a4e\xbb\u1619sd\u0100;a\u1625\u1626\u6221\u0461\u1630\u1632\u1634\u1636\u1638\u163a\u163c\u163e;\u69a8;\u69a9;\u69aa;\u69ab;\u69ac;\u69ad;\u69ae;\u69aft\u0100;v\u1645\u1646\u621fb\u0100;d\u164c\u164d\u62be;\u699d\u0100pt\u1654\u1657h;\u6222\xbb\xb9arr;\u637c\u0100gp\u1663\u1667on;\u4105f;\uc000\ud835\udd52\u0380;Eaeiop\u12c1\u167b\u167d\u1682\u1684\u1687\u168a;\u6a70cir;\u6a6f;\u624ad;\u624bs;\u4027rox\u0100;e\u12c1\u1692\xf1\u1683ing\u803b\xe5\u40e5\u0180cty\u16a1\u16a6\u16a8r;\uc000\ud835\udcb6;\u402amp\u0100;e\u12c1\u16af\xf1\u0288ilde\u803b\xe3\u40e3ml\u803b\xe4\u40e4\u0100ci\u16c2\u16c8onin\xf4\u0272nt;\u6a11\u0800Nabcdefiklnoprsu\u16ed\u16f1\u1730\u173c\u1743\u1748\u1778\u177d\u17e0\u17e6\u1839\u1850\u170d\u193d\u1948\u1970ot;\u6aed\u0100cr\u16f6\u171ek\u0200ceps\u1700\u1705\u170d\u1713ong;\u624cpsilon;\u43f6rime;\u6035im\u0100;e\u171a\u171b\u623dq;\u62cd\u0176\u1722\u1726ee;\u62bded\u0100;g\u172c\u172d\u6305e\xbb\u172drk\u0100;t\u135c\u1737brk;\u63b6\u0100oy\u1701\u1741;\u4431quo;\u601e\u0280cmprt\u1753\u175b\u1761\u1764\u1768aus\u0100;e\u010a\u0109ptyv;\u69b0s\xe9\u170cno\xf5\u0113\u0180ahw\u176f\u1771\u1773;\u43b2;\u6136een;\u626cr;\uc000\ud835\udd1fg\u0380costuvw\u178d\u179d\u17b3\u17c1\u17d5\u17db\u17de\u0180aiu\u1794\u1796\u179a\xf0\u0760rc;\u65efp\xbb\u1371\u0180dpt\u17a4\u17a8\u17adot;\u6a00lus;\u6a01imes;\u6a02\u0271\u17b9\0\0\u17becup;\u6a06ar;\u6605riangle\u0100du\u17cd\u17d2own;\u65bdp;\u65b3plus;\u6a04e\xe5\u1444\xe5\u14adarow;\u690d\u0180ako\u17ed\u1826\u1835\u0100cn\u17f2\u1823k\u0180lst\u17fa\u05ab\u1802ozenge;\u69ebriangle\u0200;dlr\u1812\u1813\u1818\u181d\u65b4own;\u65beeft;\u65c2ight;\u65b8k;\u6423\u01b1\u182b\0\u1833\u01b2\u182f\0\u1831;\u6592;\u65914;\u6593ck;\u6588\u0100eo\u183e\u184d\u0100;q\u1843\u1846\uc000=\u20e5uiv;\uc000\u2261\u20e5t;\u6310\u0200ptwx\u1859\u185e\u1867\u186cf;\uc000\ud835\udd53\u0100;t\u13cb\u1863om\xbb\u13cctie;\u62c8\u0600DHUVbdhmptuv\u1885\u1896\u18aa\u18bb\u18d7\u18db\u18ec\u18ff\u1905\u190a\u1910\u1921\u0200LRlr\u188e\u1890\u1892\u1894;\u6557;\u6554;\u6556;\u6553\u0280;DUdu\u18a1\u18a2\u18a4\u18a6\u18a8\u6550;\u6566;\u6569;\u6564;\u6567\u0200LRlr\u18b3\u18b5\u18b7\u18b9;\u655d;\u655a;\u655c;\u6559\u0380;HLRhlr\u18ca\u18cb\u18cd\u18cf\u18d1\u18d3\u18d5\u6551;\u656c;\u6563;\u6560;\u656b;\u6562;\u655fox;\u69c9\u0200LRlr\u18e4\u18e6\u18e8\u18ea;\u6555;\u6552;\u6510;\u650c\u0280;DUdu\u06bd\u18f7\u18f9\u18fb\u18fd;\u6565;\u6568;\u652c;\u6534inus;\u629flus;\u629eimes;\u62a0\u0200LRlr\u1919\u191b\u191d\u191f;\u655b;\u6558;\u6518;\u6514\u0380;HLRhlr\u1930\u1931\u1933\u1935\u1937\u1939\u193b\u6502;\u656a;\u6561;\u655e;\u653c;\u6524;\u651c\u0100ev\u0123\u1942bar\u803b\xa6\u40a6\u0200ceio\u1951\u1956\u195a\u1960r;\uc000\ud835\udcb7mi;\u604fm\u0100;e\u171a\u171cl\u0180;bh\u1968\u1969\u196b\u405c;\u69c5sub;\u67c8\u016c\u1974\u197el\u0100;e\u1979\u197a\u6022t\xbb\u197ap\u0180;Ee\u012f\u1985\u1987;\u6aae\u0100;q\u06dc\u06db\u0ce1\u19a7\0\u19e8\u1a11\u1a15\u1a32\0\u1a37\u1a50\0\0\u1ab4\0\0\u1ac1\0\0\u1b21\u1b2e\u1b4d\u1b52\0\u1bfd\0\u1c0c\u0180cpr\u19ad\u19b2\u19ddute;\u4107\u0300;abcds\u19bf\u19c0\u19c4\u19ca\u19d5\u19d9\u6229nd;\u6a44rcup;\u6a49\u0100au\u19cf\u19d2p;\u6a4bp;\u6a47ot;\u6a40;\uc000\u2229\ufe00\u0100eo\u19e2\u19e5t;\u6041\xee\u0693\u0200aeiu\u19f0\u19fb\u1a01\u1a05\u01f0\u19f5\0\u19f8s;\u6a4don;\u410ddil\u803b\xe7\u40e7rc;\u4109ps\u0100;s\u1a0c\u1a0d\u6a4cm;\u6a50ot;\u410b\u0180dmn\u1a1b\u1a20\u1a26il\u80bb\xb8\u01adptyv;\u69b2t\u8100\xa2;e\u1a2d\u1a2e\u40a2r\xe4\u01b2r;\uc000\ud835\udd20\u0180cei\u1a3d\u1a40\u1a4dy;\u4447ck\u0100;m\u1a47\u1a48\u6713ark\xbb\u1a48;\u43c7r\u0380;Ecefms\u1a5f\u1a60\u1a62\u1a6b\u1aa4\u1aaa\u1aae\u65cb;\u69c3\u0180;el\u1a69\u1a6a\u1a6d\u42c6q;\u6257e\u0261\u1a74\0\0\u1a88rrow\u0100lr\u1a7c\u1a81eft;\u61baight;\u61bb\u0280RSacd\u1a92\u1a94\u1a96\u1a9a\u1a9f\xbb\u0f47;\u64c8st;\u629birc;\u629aash;\u629dnint;\u6a10id;\u6aefcir;\u69c2ubs\u0100;u\u1abb\u1abc\u6663it\xbb\u1abc\u02ec\u1ac7\u1ad4\u1afa\0\u1b0aon\u0100;e\u1acd\u1ace\u403a\u0100;q\xc7\xc6\u026d\u1ad9\0\0\u1ae2a\u0100;t\u1ade\u1adf\u402c;\u4040\u0180;fl\u1ae8\u1ae9\u1aeb\u6201\xee\u1160e\u0100mx\u1af1\u1af6ent\xbb\u1ae9e\xf3\u024d\u01e7\u1afe\0\u1b07\u0100;d\u12bb\u1b02ot;\u6a6dn\xf4\u0246\u0180fry\u1b10\u1b14\u1b17;\uc000\ud835\udd54o\xe4\u0254\u8100\xa9;s\u0155\u1b1dr;\u6117\u0100ao\u1b25\u1b29rr;\u61b5ss;\u6717\u0100cu\u1b32\u1b37r;\uc000\ud835\udcb8\u0100bp\u1b3c\u1b44\u0100;e\u1b41\u1b42\u6acf;\u6ad1\u0100;e\u1b49\u1b4a\u6ad0;\u6ad2dot;\u62ef\u0380delprvw\u1b60\u1b6c\u1b77\u1b82\u1bac\u1bd4\u1bf9arr\u0100lr\u1b68\u1b6a;\u6938;\u6935\u0270\u1b72\0\0\u1b75r;\u62dec;\u62dfarr\u0100;p\u1b7f\u1b80\u61b6;\u693d\u0300;bcdos\u1b8f\u1b90\u1b96\u1ba1\u1ba5\u1ba8\u622arcap;\u6a48\u0100au\u1b9b\u1b9ep;\u6a46p;\u6a4aot;\u628dr;\u6a45;\uc000\u222a\ufe00\u0200alrv\u1bb5\u1bbf\u1bde\u1be3rr\u0100;m\u1bbc\u1bbd\u61b7;\u693cy\u0180evw\u1bc7\u1bd4\u1bd8q\u0270\u1bce\0\0\u1bd2re\xe3\u1b73u\xe3\u1b75ee;\u62ceedge;\u62cfen\u803b\xa4\u40a4earrow\u0100lr\u1bee\u1bf3eft\xbb\u1b80ight\xbb\u1bbde\xe4\u1bdd\u0100ci\u1c01\u1c07onin\xf4\u01f7nt;\u6231lcty;\u632d\u0980AHabcdefhijlorstuwz\u1c38\u1c3b\u1c3f\u1c5d\u1c69\u1c75\u1c8a\u1c9e\u1cac\u1cb7\u1cfb\u1cff\u1d0d\u1d7b\u1d91\u1dab\u1dbb\u1dc6\u1dcdr\xf2\u0381ar;\u6965\u0200glrs\u1c48\u1c4d\u1c52\u1c54ger;\u6020eth;\u6138\xf2\u1133h\u0100;v\u1c5a\u1c5b\u6010\xbb\u090a\u016b\u1c61\u1c67arow;\u690fa\xe3\u0315\u0100ay\u1c6e\u1c73ron;\u410f;\u4434\u0180;ao\u0332\u1c7c\u1c84\u0100gr\u02bf\u1c81r;\u61catseq;\u6a77\u0180glm\u1c91\u1c94\u1c98\u803b\xb0\u40b0ta;\u43b4ptyv;\u69b1\u0100ir\u1ca3\u1ca8sht;\u697f;\uc000\ud835\udd21ar\u0100lr\u1cb3\u1cb5\xbb\u08dc\xbb\u101e\u0280aegsv\u1cc2\u0378\u1cd6\u1cdc\u1ce0m\u0180;os\u0326\u1cca\u1cd4nd\u0100;s\u0326\u1cd1uit;\u6666amma;\u43ddin;\u62f2\u0180;io\u1ce7\u1ce8\u1cf8\u40f7de\u8100\xf7;o\u1ce7\u1cf0ntimes;\u62c7n\xf8\u1cf7cy;\u4452c\u026f\u1d06\0\0\u1d0arn;\u631eop;\u630d\u0280lptuw\u1d18\u1d1d\u1d22\u1d49\u1d55lar;\u4024f;\uc000\ud835\udd55\u0280;emps\u030b\u1d2d\u1d37\u1d3d\u1d42q\u0100;d\u0352\u1d33ot;\u6251inus;\u6238lus;\u6214quare;\u62a1blebarwedg\xe5\xfan\u0180adh\u112e\u1d5d\u1d67ownarrow\xf3\u1c83arpoon\u0100lr\u1d72\u1d76ef\xf4\u1cb4igh\xf4\u1cb6\u0162\u1d7f\u1d85karo\xf7\u0f42\u026f\u1d8a\0\0\u1d8ern;\u631fop;\u630c\u0180cot\u1d98\u1da3\u1da6\u0100ry\u1d9d\u1da1;\uc000\ud835\udcb9;\u4455l;\u69f6rok;\u4111\u0100dr\u1db0\u1db4ot;\u62f1i\u0100;f\u1dba\u1816\u65bf\u0100ah\u1dc0\u1dc3r\xf2\u0429a\xf2\u0fa6angle;\u69a6\u0100ci\u1dd2\u1dd5y;\u445fgrarr;\u67ff\u0900Dacdefglmnopqrstux\u1e01\u1e09\u1e19\u1e38\u0578\u1e3c\u1e49\u1e61\u1e7e\u1ea5\u1eaf\u1ebd\u1ee1\u1f2a\u1f37\u1f44\u1f4e\u1f5a\u0100Do\u1e06\u1d34o\xf4\u1c89\u0100cs\u1e0e\u1e14ute\u803b\xe9\u40e9ter;\u6a6e\u0200aioy\u1e22\u1e27\u1e31\u1e36ron;\u411br\u0100;c\u1e2d\u1e2e\u6256\u803b\xea\u40ealon;\u6255;\u444dot;\u4117\u0100Dr\u1e41\u1e45ot;\u6252;\uc000\ud835\udd22\u0180;rs\u1e50\u1e51\u1e57\u6a9aave\u803b\xe8\u40e8\u0100;d\u1e5c\u1e5d\u6a96ot;\u6a98\u0200;ils\u1e6a\u1e6b\u1e72\u1e74\u6a99nters;\u63e7;\u6113\u0100;d\u1e79\u1e7a\u6a95ot;\u6a97\u0180aps\u1e85\u1e89\u1e97cr;\u4113ty\u0180;sv\u1e92\u1e93\u1e95\u6205et\xbb\u1e93p\u01001;\u1e9d\u1ea4\u0133\u1ea1\u1ea3;\u6004;\u6005\u6003\u0100gs\u1eaa\u1eac;\u414bp;\u6002\u0100gp\u1eb4\u1eb8on;\u4119f;\uc000\ud835\udd56\u0180als\u1ec4\u1ece\u1ed2r\u0100;s\u1eca\u1ecb\u62d5l;\u69e3us;\u6a71i\u0180;lv\u1eda\u1edb\u1edf\u43b5on\xbb\u1edb;\u43f5\u0200csuv\u1eea\u1ef3\u1f0b\u1f23\u0100io\u1eef\u1e31rc\xbb\u1e2e\u0269\u1ef9\0\0\u1efb\xed\u0548ant\u0100gl\u1f02\u1f06tr\xbb\u1e5dess\xbb\u1e7a\u0180aei\u1f12\u1f16\u1f1als;\u403dst;\u625fv\u0100;D\u0235\u1f20D;\u6a78parsl;\u69e5\u0100Da\u1f2f\u1f33ot;\u6253rr;\u6971\u0180cdi\u1f3e\u1f41\u1ef8r;\u612fo\xf4\u0352\u0100ah\u1f49\u1f4b;\u43b7\u803b\xf0\u40f0\u0100mr\u1f53\u1f57l\u803b\xeb\u40ebo;\u60ac\u0180cip\u1f61\u1f64\u1f67l;\u4021s\xf4\u056e\u0100eo\u1f6c\u1f74ctatio\xee\u0559nential\xe5\u0579\u09e1\u1f92\0\u1f9e\0\u1fa1\u1fa7\0\0\u1fc6\u1fcc\0\u1fd3\0\u1fe6\u1fea\u2000\0\u2008\u205allingdotse\xf1\u1e44y;\u4444male;\u6640\u0180ilr\u1fad\u1fb3\u1fc1lig;\u8000\ufb03\u0269\u1fb9\0\0\u1fbdg;\u8000\ufb00ig;\u8000\ufb04;\uc000\ud835\udd23lig;\u8000\ufb01lig;\uc000fj\u0180alt\u1fd9\u1fdc\u1fe1t;\u666dig;\u8000\ufb02ns;\u65b1of;\u4192\u01f0\u1fee\0\u1ff3f;\uc000\ud835\udd57\u0100ak\u05bf\u1ff7\u0100;v\u1ffc\u1ffd\u62d4;\u6ad9artint;\u6a0d\u0100ao\u200c\u2055\u0100cs\u2011\u2052\u03b1\u201a\u2030\u2038\u2045\u2048\0\u2050\u03b2\u2022\u2025\u2027\u202a\u202c\0\u202e\u803b\xbd\u40bd;\u6153\u803b\xbc\u40bc;\u6155;\u6159;\u615b\u01b3\u2034\0\u2036;\u6154;\u6156\u02b4\u203e\u2041\0\0\u2043\u803b\xbe\u40be;\u6157;\u615c5;\u6158\u01b6\u204c\0\u204e;\u615a;\u615d8;\u615el;\u6044wn;\u6322cr;\uc000\ud835\udcbb\u0880Eabcdefgijlnorstv\u2082\u2089\u209f\u20a5\u20b0\u20b4\u20f0\u20f5\u20fa\u20ff\u2103\u2112\u2138\u0317\u213e\u2152\u219e\u0100;l\u064d\u2087;\u6a8c\u0180cmp\u2090\u2095\u209dute;\u41f5ma\u0100;d\u209c\u1cda\u43b3;\u6a86reve;\u411f\u0100iy\u20aa\u20aerc;\u411d;\u4433ot;\u4121\u0200;lqs\u063e\u0642\u20bd\u20c9\u0180;qs\u063e\u064c\u20c4lan\xf4\u0665\u0200;cdl\u0665\u20d2\u20d5\u20e5c;\u6aa9ot\u0100;o\u20dc\u20dd\u6a80\u0100;l\u20e2\u20e3\u6a82;\u6a84\u0100;e\u20ea\u20ed\uc000\u22db\ufe00s;\u6a94r;\uc000\ud835\udd24\u0100;g\u0673\u061bmel;\u6137cy;\u4453\u0200;Eaj\u065a\u210c\u210e\u2110;\u6a92;\u6aa5;\u6aa4\u0200Eaes\u211b\u211d\u2129\u2134;\u6269p\u0100;p\u2123\u2124\u6a8arox\xbb\u2124\u0100;q\u212e\u212f\u6a88\u0100;q\u212e\u211bim;\u62e7pf;\uc000\ud835\udd58\u0100ci\u2143\u2146r;\u610am\u0180;el\u066b\u214e\u2150;\u6a8e;\u6a90\u8300>;cdlqr\u05ee\u2160\u216a\u216e\u2173\u2179\u0100ci\u2165\u2167;\u6aa7r;\u6a7aot;\u62d7Par;\u6995uest;\u6a7c\u0280adels\u2184\u216a\u2190\u0656\u219b\u01f0\u2189\0\u218epro\xf8\u209er;\u6978q\u0100lq\u063f\u2196les\xf3\u2088i\xed\u066b\u0100en\u21a3\u21adrtneqq;\uc000\u2269\ufe00\xc5\u21aa\u0500Aabcefkosy\u21c4\u21c7\u21f1\u21f5\u21fa\u2218\u221d\u222f\u2268\u227dr\xf2\u03a0\u0200ilmr\u21d0\u21d4\u21d7\u21dbrs\xf0\u1484f\xbb\u2024il\xf4\u06a9\u0100dr\u21e0\u21e4cy;\u444a\u0180;cw\u08f4\u21eb\u21efir;\u6948;\u61adar;\u610firc;\u4125\u0180alr\u2201\u220e\u2213rts\u0100;u\u2209\u220a\u6665it\xbb\u220alip;\u6026con;\u62b9r;\uc000\ud835\udd25s\u0100ew\u2223\u2229arow;\u6925arow;\u6926\u0280amopr\u223a\u223e\u2243\u225e\u2263rr;\u61fftht;\u623bk\u0100lr\u2249\u2253eftarrow;\u61a9ightarrow;\u61aaf;\uc000\ud835\udd59bar;\u6015\u0180clt\u226f\u2274\u2278r;\uc000\ud835\udcbdas\xe8\u21f4rok;\u4127\u0100bp\u2282\u2287ull;\u6043hen\xbb\u1c5b\u0ae1\u22a3\0\u22aa\0\u22b8\u22c5\u22ce\0\u22d5\u22f3\0\0\u22f8\u2322\u2367\u2362\u237f\0\u2386\u23aa\u23b4cute\u803b\xed\u40ed\u0180;iy\u0771\u22b0\u22b5rc\u803b\xee\u40ee;\u4438\u0100cx\u22bc\u22bfy;\u4435cl\u803b\xa1\u40a1\u0100fr\u039f\u22c9;\uc000\ud835\udd26rave\u803b\xec\u40ec\u0200;ino\u073e\u22dd\u22e9\u22ee\u0100in\u22e2\u22e6nt;\u6a0ct;\u622dfin;\u69dcta;\u6129lig;\u4133\u0180aop\u22fe\u231a\u231d\u0180cgt\u2305\u2308\u2317r;\u412b\u0180elp\u071f\u230f\u2313in\xe5\u078ear\xf4\u0720h;\u4131f;\u62b7ed;\u41b5\u0280;cfot\u04f4\u232c\u2331\u233d\u2341are;\u6105in\u0100;t\u2338\u2339\u621eie;\u69dddo\xf4\u2319\u0280;celp\u0757\u234c\u2350\u235b\u2361al;\u62ba\u0100gr\u2355\u2359er\xf3\u1563\xe3\u234darhk;\u6a17rod;\u6a3c\u0200cgpt\u236f\u2372\u2376\u237by;\u4451on;\u412ff;\uc000\ud835\udd5aa;\u43b9uest\u803b\xbf\u40bf\u0100ci\u238a\u238fr;\uc000\ud835\udcben\u0280;Edsv\u04f4\u239b\u239d\u23a1\u04f3;\u62f9ot;\u62f5\u0100;v\u23a6\u23a7\u62f4;\u62f3\u0100;i\u0777\u23aelde;\u4129\u01eb\u23b8\0\u23bccy;\u4456l\u803b\xef\u40ef\u0300cfmosu\u23cc\u23d7\u23dc\u23e1\u23e7\u23f5\u0100iy\u23d1\u23d5rc;\u4135;\u4439r;\uc000\ud835\udd27ath;\u4237pf;\uc000\ud835\udd5b\u01e3\u23ec\0\u23f1r;\uc000\ud835\udcbfrcy;\u4458kcy;\u4454\u0400acfghjos\u240b\u2416\u2422\u2427\u242d\u2431\u2435\u243bppa\u0100;v\u2413\u2414\u43ba;\u43f0\u0100ey\u241b\u2420dil;\u4137;\u443ar;\uc000\ud835\udd28reen;\u4138cy;\u4445cy;\u445cpf;\uc000\ud835\udd5ccr;\uc000\ud835\udcc0\u0b80ABEHabcdefghjlmnoprstuv\u2470\u2481\u2486\u248d\u2491\u250e\u253d\u255a\u2580\u264e\u265e\u2665\u2679\u267d\u269a\u26b2\u26d8\u275d\u2768\u278b\u27c0\u2801\u2812\u0180art\u2477\u247a\u247cr\xf2\u09c6\xf2\u0395ail;\u691barr;\u690e\u0100;g\u0994\u248b;\u6a8bar;\u6962\u0963\u24a5\0\u24aa\0\u24b1\0\0\0\0\0\u24b5\u24ba\0\u24c6\u24c8\u24cd\0\u24f9ute;\u413amptyv;\u69b4ra\xee\u084cbda;\u43bbg\u0180;dl\u088e\u24c1\u24c3;\u6991\xe5\u088e;\u6a85uo\u803b\xab\u40abr\u0400;bfhlpst\u0899\u24de\u24e6\u24e9\u24eb\u24ee\u24f1\u24f5\u0100;f\u089d\u24e3s;\u691fs;\u691d\xeb\u2252p;\u61abl;\u6939im;\u6973l;\u61a2\u0180;ae\u24ff\u2500\u2504\u6aabil;\u6919\u0100;s\u2509\u250a\u6aad;\uc000\u2aad\ufe00\u0180abr\u2515\u2519\u251drr;\u690crk;\u6772\u0100ak\u2522\u252cc\u0100ek\u2528\u252a;\u407b;\u405b\u0100es\u2531\u2533;\u698bl\u0100du\u2539\u253b;\u698f;\u698d\u0200aeuy\u2546\u254b\u2556\u2558ron;\u413e\u0100di\u2550\u2554il;\u413c\xec\u08b0\xe2\u2529;\u443b\u0200cqrs\u2563\u2566\u256d\u257da;\u6936uo\u0100;r\u0e19\u1746\u0100du\u2572\u2577har;\u6967shar;\u694bh;\u61b2\u0280;fgqs\u258b\u258c\u0989\u25f3\u25ff\u6264t\u0280ahlrt\u2598\u25a4\u25b7\u25c2\u25e8rrow\u0100;t\u0899\u25a1a\xe9\u24f6arpoon\u0100du\u25af\u25b4own\xbb\u045ap\xbb\u0966eftarrows;\u61c7ight\u0180ahs\u25cd\u25d6\u25derrow\u0100;s\u08f4\u08a7arpoon\xf3\u0f98quigarro\xf7\u21f0hreetimes;\u62cb\u0180;qs\u258b\u0993\u25falan\xf4\u09ac\u0280;cdgs\u09ac\u260a\u260d\u261d\u2628c;\u6aa8ot\u0100;o\u2614\u2615\u6a7f\u0100;r\u261a\u261b\u6a81;\u6a83\u0100;e\u2622\u2625\uc000\u22da\ufe00s;\u6a93\u0280adegs\u2633\u2639\u263d\u2649\u264bppro\xf8\u24c6ot;\u62d6q\u0100gq\u2643\u2645\xf4\u0989gt\xf2\u248c\xf4\u099bi\xed\u09b2\u0180ilr\u2655\u08e1\u265asht;\u697c;\uc000\ud835\udd29\u0100;E\u099c\u2663;\u6a91\u0161\u2669\u2676r\u0100du\u25b2\u266e\u0100;l\u0965\u2673;\u696alk;\u6584cy;\u4459\u0280;acht\u0a48\u2688\u268b\u2691\u2696r\xf2\u25c1orne\xf2\u1d08ard;\u696bri;\u65fa\u0100io\u269f\u26a4dot;\u4140ust\u0100;a\u26ac\u26ad\u63b0che\xbb\u26ad\u0200Eaes\u26bb\u26bd\u26c9\u26d4;\u6268p\u0100;p\u26c3\u26c4\u6a89rox\xbb\u26c4\u0100;q\u26ce\u26cf\u6a87\u0100;q\u26ce\u26bbim;\u62e6\u0400abnoptwz\u26e9\u26f4\u26f7\u271a\u272f\u2741\u2747\u2750\u0100nr\u26ee\u26f1g;\u67ecr;\u61fdr\xeb\u08c1g\u0180lmr\u26ff\u270d\u2714eft\u0100ar\u09e6\u2707ight\xe1\u09f2apsto;\u67fcight\xe1\u09fdparrow\u0100lr\u2725\u2729ef\xf4\u24edight;\u61ac\u0180afl\u2736\u2739\u273dr;\u6985;\uc000\ud835\udd5dus;\u6a2dimes;\u6a34\u0161\u274b\u274fst;\u6217\xe1\u134e\u0180;ef\u2757\u2758\u1800\u65cange\xbb\u2758ar\u0100;l\u2764\u2765\u4028t;\u6993\u0280achmt\u2773\u2776\u277c\u2785\u2787r\xf2\u08a8orne\xf2\u1d8car\u0100;d\u0f98\u2783;\u696d;\u600eri;\u62bf\u0300achiqt\u2798\u279d\u0a40\u27a2\u27ae\u27bbquo;\u6039r;\uc000\ud835\udcc1m\u0180;eg\u09b2\u27aa\u27ac;\u6a8d;\u6a8f\u0100bu\u252a\u27b3o\u0100;r\u0e1f\u27b9;\u601arok;\u4142\u8400<;cdhilqr\u082b\u27d2\u2639\u27dc\u27e0\u27e5\u27ea\u27f0\u0100ci\u27d7\u27d9;\u6aa6r;\u6a79re\xe5\u25f2mes;\u62c9arr;\u6976uest;\u6a7b\u0100Pi\u27f5\u27f9ar;\u6996\u0180;ef\u2800\u092d\u181b\u65c3r\u0100du\u2807\u280dshar;\u694ahar;\u6966\u0100en\u2817\u2821rtneqq;\uc000\u2268\ufe00\xc5\u281e\u0700Dacdefhilnopsu\u2840\u2845\u2882\u288e\u2893\u28a0\u28a5\u28a8\u28da\u28e2\u28e4\u0a83\u28f3\u2902Dot;\u623a\u0200clpr\u284e\u2852\u2863\u287dr\u803b\xaf\u40af\u0100et\u2857\u2859;\u6642\u0100;e\u285e\u285f\u6720se\xbb\u285f\u0100;s\u103b\u2868to\u0200;dlu\u103b\u2873\u2877\u287bow\xee\u048cef\xf4\u090f\xf0\u13d1ker;\u65ae\u0100oy\u2887\u288cmma;\u6a29;\u443cash;\u6014asuredangle\xbb\u1626r;\uc000\ud835\udd2ao;\u6127\u0180cdn\u28af\u28b4\u28c9ro\u803b\xb5\u40b5\u0200;acd\u1464\u28bd\u28c0\u28c4s\xf4\u16a7ir;\u6af0ot\u80bb\xb7\u01b5us\u0180;bd\u28d2\u1903\u28d3\u6212\u0100;u\u1d3c\u28d8;\u6a2a\u0163\u28de\u28e1p;\u6adb\xf2\u2212\xf0\u0a81\u0100dp\u28e9\u28eeels;\u62a7f;\uc000\ud835\udd5e\u0100ct\u28f8\u28fdr;\uc000\ud835\udcc2pos\xbb\u159d\u0180;lm\u2909\u290a\u290d\u43bctimap;\u62b8\u0c00GLRVabcdefghijlmoprstuvw\u2942\u2953\u297e\u2989\u2998\u29da\u29e9\u2a15\u2a1a\u2a58\u2a5d\u2a83\u2a95\u2aa4\u2aa8\u2b04\u2b07\u2b44\u2b7f\u2bae\u2c34\u2c67\u2c7c\u2ce9\u0100gt\u2947\u294b;\uc000\u22d9\u0338\u0100;v\u2950\u0bcf\uc000\u226b\u20d2\u0180elt\u295a\u2972\u2976ft\u0100ar\u2961\u2967rrow;\u61cdightarrow;\u61ce;\uc000\u22d8\u0338\u0100;v\u297b\u0c47\uc000\u226a\u20d2ightarrow;\u61cf\u0100Dd\u298e\u2993ash;\u62afash;\u62ae\u0280bcnpt\u29a3\u29a7\u29ac\u29b1\u29ccla\xbb\u02deute;\u4144g;\uc000\u2220\u20d2\u0280;Eiop\u0d84\u29bc\u29c0\u29c5\u29c8;\uc000\u2a70\u0338d;\uc000\u224b\u0338s;\u4149ro\xf8\u0d84ur\u0100;a\u29d3\u29d4\u666el\u0100;s\u29d3\u0b38\u01f3\u29df\0\u29e3p\u80bb\xa0\u0b37mp\u0100;e\u0bf9\u0c00\u0280aeouy\u29f4\u29fe\u2a03\u2a10\u2a13\u01f0\u29f9\0\u29fb;\u6a43on;\u4148dil;\u4146ng\u0100;d\u0d7e\u2a0aot;\uc000\u2a6d\u0338p;\u6a42;\u443dash;\u6013\u0380;Aadqsx\u0b92\u2a29\u2a2d\u2a3b\u2a41\u2a45\u2a50rr;\u61d7r\u0100hr\u2a33\u2a36k;\u6924\u0100;o\u13f2\u13f0ot;\uc000\u2250\u0338ui\xf6\u0b63\u0100ei\u2a4a\u2a4ear;\u6928\xed\u0b98ist\u0100;s\u0ba0\u0b9fr;\uc000\ud835\udd2b\u0200Eest\u0bc5\u2a66\u2a79\u2a7c\u0180;qs\u0bbc\u2a6d\u0be1\u0180;qs\u0bbc\u0bc5\u2a74lan\xf4\u0be2i\xed\u0bea\u0100;r\u0bb6\u2a81\xbb\u0bb7\u0180Aap\u2a8a\u2a8d\u2a91r\xf2\u2971rr;\u61aear;\u6af2\u0180;sv\u0f8d\u2a9c\u0f8c\u0100;d\u2aa1\u2aa2\u62fc;\u62facy;\u445a\u0380AEadest\u2ab7\u2aba\u2abe\u2ac2\u2ac5\u2af6\u2af9r\xf2\u2966;\uc000\u2266\u0338rr;\u619ar;\u6025\u0200;fqs\u0c3b\u2ace\u2ae3\u2aeft\u0100ar\u2ad4\u2ad9rro\xf7\u2ac1ightarro\xf7\u2a90\u0180;qs\u0c3b\u2aba\u2aealan\xf4\u0c55\u0100;s\u0c55\u2af4\xbb\u0c36i\xed\u0c5d\u0100;r\u0c35\u2afei\u0100;e\u0c1a\u0c25i\xe4\u0d90\u0100pt\u2b0c\u2b11f;\uc000\ud835\udd5f\u8180\xac;in\u2b19\u2b1a\u2b36\u40acn\u0200;Edv\u0b89\u2b24\u2b28\u2b2e;\uc000\u22f9\u0338ot;\uc000\u22f5\u0338\u01e1\u0b89\u2b33\u2b35;\u62f7;\u62f6i\u0100;v\u0cb8\u2b3c\u01e1\u0cb8\u2b41\u2b43;\u62fe;\u62fd\u0180aor\u2b4b\u2b63\u2b69r\u0200;ast\u0b7b\u2b55\u2b5a\u2b5flle\xec\u0b7bl;\uc000\u2afd\u20e5;\uc000\u2202\u0338lint;\u6a14\u0180;ce\u0c92\u2b70\u2b73u\xe5\u0ca5\u0100;c\u0c98\u2b78\u0100;e\u0c92\u2b7d\xf1\u0c98\u0200Aait\u2b88\u2b8b\u2b9d\u2ba7r\xf2\u2988rr\u0180;cw\u2b94\u2b95\u2b99\u619b;\uc000\u2933\u0338;\uc000\u219d\u0338ghtarrow\xbb\u2b95ri\u0100;e\u0ccb\u0cd6\u0380chimpqu\u2bbd\u2bcd\u2bd9\u2b04\u0b78\u2be4\u2bef\u0200;cer\u0d32\u2bc6\u0d37\u2bc9u\xe5\u0d45;\uc000\ud835\udcc3ort\u026d\u2b05\0\0\u2bd6ar\xe1\u2b56m\u0100;e\u0d6e\u2bdf\u0100;q\u0d74\u0d73su\u0100bp\u2beb\u2bed\xe5\u0cf8\xe5\u0d0b\u0180bcp\u2bf6\u2c11\u2c19\u0200;Ees\u2bff\u2c00\u0d22\u2c04\u6284;\uc000\u2ac5\u0338et\u0100;e\u0d1b\u2c0bq\u0100;q\u0d23\u2c00c\u0100;e\u0d32\u2c17\xf1\u0d38\u0200;Ees\u2c22\u2c23\u0d5f\u2c27\u6285;\uc000\u2ac6\u0338et\u0100;e\u0d58\u2c2eq\u0100;q\u0d60\u2c23\u0200gilr\u2c3d\u2c3f\u2c45\u2c47\xec\u0bd7lde\u803b\xf1\u40f1\xe7\u0c43iangle\u0100lr\u2c52\u2c5ceft\u0100;e\u0c1a\u2c5a\xf1\u0c26ight\u0100;e\u0ccb\u2c65\xf1\u0cd7\u0100;m\u2c6c\u2c6d\u43bd\u0180;es\u2c74\u2c75\u2c79\u4023ro;\u6116p;\u6007\u0480DHadgilrs\u2c8f\u2c94\u2c99\u2c9e\u2ca3\u2cb0\u2cb6\u2cd3\u2ce3ash;\u62adarr;\u6904p;\uc000\u224d\u20d2ash;\u62ac\u0100et\u2ca8\u2cac;\uc000\u2265\u20d2;\uc000>\u20d2nfin;\u69de\u0180Aet\u2cbd\u2cc1\u2cc5rr;\u6902;\uc000\u2264\u20d2\u0100;r\u2cca\u2ccd\uc000<\u20d2ie;\uc000\u22b4\u20d2\u0100At\u2cd8\u2cdcrr;\u6903rie;\uc000\u22b5\u20d2im;\uc000\u223c\u20d2\u0180Aan\u2cf0\u2cf4\u2d02rr;\u61d6r\u0100hr\u2cfa\u2cfdk;\u6923\u0100;o\u13e7\u13e5ear;\u6927\u1253\u1a95\0\0\0\0\0\0\0\0\0\0\0\0\0\u2d2d\0\u2d38\u2d48\u2d60\u2d65\u2d72\u2d84\u1b07\0\0\u2d8d\u2dab\0\u2dc8\u2dce\0\u2ddc\u2e19\u2e2b\u2e3e\u2e43\u0100cs\u2d31\u1a97ute\u803b\xf3\u40f3\u0100iy\u2d3c\u2d45r\u0100;c\u1a9e\u2d42\u803b\xf4\u40f4;\u443e\u0280abios\u1aa0\u2d52\u2d57\u01c8\u2d5alac;\u4151v;\u6a38old;\u69bclig;\u4153\u0100cr\u2d69\u2d6dir;\u69bf;\uc000\ud835\udd2c\u036f\u2d79\0\0\u2d7c\0\u2d82n;\u42dbave\u803b\xf2\u40f2;\u69c1\u0100bm\u2d88\u0df4ar;\u69b5\u0200acit\u2d95\u2d98\u2da5\u2da8r\xf2\u1a80\u0100ir\u2d9d\u2da0r;\u69beoss;\u69bbn\xe5\u0e52;\u69c0\u0180aei\u2db1\u2db5\u2db9cr;\u414dga;\u43c9\u0180cdn\u2dc0\u2dc5\u01cdron;\u43bf;\u69b6pf;\uc000\ud835\udd60\u0180ael\u2dd4\u2dd7\u01d2r;\u69b7rp;\u69b9\u0380;adiosv\u2dea\u2deb\u2dee\u2e08\u2e0d\u2e10\u2e16\u6228r\xf2\u1a86\u0200;efm\u2df7\u2df8\u2e02\u2e05\u6a5dr\u0100;o\u2dfe\u2dff\u6134f\xbb\u2dff\u803b\xaa\u40aa\u803b\xba\u40bagof;\u62b6r;\u6a56lope;\u6a57;\u6a5b\u0180clo\u2e1f\u2e21\u2e27\xf2\u2e01ash\u803b\xf8\u40f8l;\u6298i\u016c\u2e2f\u2e34de\u803b\xf5\u40f5es\u0100;a\u01db\u2e3as;\u6a36ml\u803b\xf6\u40f6bar;\u633d\u0ae1\u2e5e\0\u2e7d\0\u2e80\u2e9d\0\u2ea2\u2eb9\0\0\u2ecb\u0e9c\0\u2f13\0\0\u2f2b\u2fbc\0\u2fc8r\u0200;ast\u0403\u2e67\u2e72\u0e85\u8100\xb6;l\u2e6d\u2e6e\u40b6le\xec\u0403\u0269\u2e78\0\0\u2e7bm;\u6af3;\u6afdy;\u443fr\u0280cimpt\u2e8b\u2e8f\u2e93\u1865\u2e97nt;\u4025od;\u402eil;\u6030enk;\u6031r;\uc000\ud835\udd2d\u0180imo\u2ea8\u2eb0\u2eb4\u0100;v\u2ead\u2eae\u43c6;\u43d5ma\xf4\u0a76ne;\u660e\u0180;tv\u2ebf\u2ec0\u2ec8\u43c0chfork\xbb\u1ffd;\u43d6\u0100au\u2ecf\u2edfn\u0100ck\u2ed5\u2eddk\u0100;h\u21f4\u2edb;\u610e\xf6\u21f4s\u0480;abcdemst\u2ef3\u2ef4\u1908\u2ef9\u2efd\u2f04\u2f06\u2f0a\u2f0e\u402bcir;\u6a23ir;\u6a22\u0100ou\u1d40\u2f02;\u6a25;\u6a72n\u80bb\xb1\u0e9dim;\u6a26wo;\u6a27\u0180ipu\u2f19\u2f20\u2f25ntint;\u6a15f;\uc000\ud835\udd61nd\u803b\xa3\u40a3\u0500;Eaceinosu\u0ec8\u2f3f\u2f41\u2f44\u2f47\u2f81\u2f89\u2f92\u2f7e\u2fb6;\u6ab3p;\u6ab7u\xe5\u0ed9\u0100;c\u0ece\u2f4c\u0300;acens\u0ec8\u2f59\u2f5f\u2f66\u2f68\u2f7eppro\xf8\u2f43urlye\xf1\u0ed9\xf1\u0ece\u0180aes\u2f6f\u2f76\u2f7approx;\u6ab9qq;\u6ab5im;\u62e8i\xed\u0edfme\u0100;s\u2f88\u0eae\u6032\u0180Eas\u2f78\u2f90\u2f7a\xf0\u2f75\u0180dfp\u0eec\u2f99\u2faf\u0180als\u2fa0\u2fa5\u2faalar;\u632eine;\u6312urf;\u6313\u0100;t\u0efb\u2fb4\xef\u0efbrel;\u62b0\u0100ci\u2fc0\u2fc5r;\uc000\ud835\udcc5;\u43c8ncsp;\u6008\u0300fiopsu\u2fda\u22e2\u2fdf\u2fe5\u2feb\u2ff1r;\uc000\ud835\udd2epf;\uc000\ud835\udd62rime;\u6057cr;\uc000\ud835\udcc6\u0180aeo\u2ff8\u3009\u3013t\u0100ei\u2ffe\u3005rnion\xf3\u06b0nt;\u6a16st\u0100;e\u3010\u3011\u403f\xf1\u1f19\xf4\u0f14\u0a80ABHabcdefhilmnoprstux\u3040\u3051\u3055\u3059\u30e0\u310e\u312b\u3147\u3162\u3172\u318e\u3206\u3215\u3224\u3229\u3258\u326e\u3272\u3290\u32b0\u32b7\u0180art\u3047\u304a\u304cr\xf2\u10b3\xf2\u03ddail;\u691car\xf2\u1c65ar;\u6964\u0380cdenqrt\u3068\u3075\u3078\u307f\u308f\u3094\u30cc\u0100eu\u306d\u3071;\uc000\u223d\u0331te;\u4155i\xe3\u116emptyv;\u69b3g\u0200;del\u0fd1\u3089\u308b\u308d;\u6992;\u69a5\xe5\u0fd1uo\u803b\xbb\u40bbr\u0580;abcfhlpstw\u0fdc\u30ac\u30af\u30b7\u30b9\u30bc\u30be\u30c0\u30c3\u30c7\u30cap;\u6975\u0100;f\u0fe0\u30b4s;\u6920;\u6933s;\u691e\xeb\u225d\xf0\u272el;\u6945im;\u6974l;\u61a3;\u619d\u0100ai\u30d1\u30d5il;\u691ao\u0100;n\u30db\u30dc\u6236al\xf3\u0f1e\u0180abr\u30e7\u30ea\u30eer\xf2\u17e5rk;\u6773\u0100ak\u30f3\u30fdc\u0100ek\u30f9\u30fb;\u407d;\u405d\u0100es\u3102\u3104;\u698cl\u0100du\u310a\u310c;\u698e;\u6990\u0200aeuy\u3117\u311c\u3127\u3129ron;\u4159\u0100di\u3121\u3125il;\u4157\xec\u0ff2\xe2\u30fa;\u4440\u0200clqs\u3134\u3137\u313d\u3144a;\u6937dhar;\u6969uo\u0100;r\u020e\u020dh;\u61b3\u0180acg\u314e\u315f\u0f44l\u0200;ips\u0f78\u3158\u315b\u109cn\xe5\u10bbar\xf4\u0fa9t;\u65ad\u0180ilr\u3169\u1023\u316esht;\u697d;\uc000\ud835\udd2f\u0100ao\u3177\u3186r\u0100du\u317d\u317f\xbb\u047b\u0100;l\u1091\u3184;\u696c\u0100;v\u318b\u318c\u43c1;\u43f1\u0180gns\u3195\u31f9\u31fcht\u0300ahlrst\u31a4\u31b0\u31c2\u31d8\u31e4\u31eerrow\u0100;t\u0fdc\u31ada\xe9\u30c8arpoon\u0100du\u31bb\u31bfow\xee\u317ep\xbb\u1092eft\u0100ah\u31ca\u31d0rrow\xf3\u0feaarpoon\xf3\u0551ightarrows;\u61c9quigarro\xf7\u30cbhreetimes;\u62ccg;\u42daingdotse\xf1\u1f32\u0180ahm\u320d\u3210\u3213r\xf2\u0feaa\xf2\u0551;\u600foust\u0100;a\u321e\u321f\u63b1che\xbb\u321fmid;\u6aee\u0200abpt\u3232\u323d\u3240\u3252\u0100nr\u3237\u323ag;\u67edr;\u61fer\xeb\u1003\u0180afl\u3247\u324a\u324er;\u6986;\uc000\ud835\udd63us;\u6a2eimes;\u6a35\u0100ap\u325d\u3267r\u0100;g\u3263\u3264\u4029t;\u6994olint;\u6a12ar\xf2\u31e3\u0200achq\u327b\u3280\u10bc\u3285quo;\u603ar;\uc000\ud835\udcc7\u0100bu\u30fb\u328ao\u0100;r\u0214\u0213\u0180hir\u3297\u329b\u32a0re\xe5\u31f8mes;\u62cai\u0200;efl\u32aa\u1059\u1821\u32ab\u65b9tri;\u69celuhar;\u6968;\u611e\u0d61\u32d5\u32db\u32df\u332c\u3338\u3371\0\u337a\u33a4\0\0\u33ec\u33f0\0\u3428\u3448\u345a\u34ad\u34b1\u34ca\u34f1\0\u3616\0\0\u3633cute;\u415bqu\xef\u27ba\u0500;Eaceinpsy\u11ed\u32f3\u32f5\u32ff\u3302\u330b\u330f\u331f\u3326\u3329;\u6ab4\u01f0\u32fa\0\u32fc;\u6ab8on;\u4161u\xe5\u11fe\u0100;d\u11f3\u3307il;\u415frc;\u415d\u0180Eas\u3316\u3318\u331b;\u6ab6p;\u6abaim;\u62e9olint;\u6a13i\xed\u1204;\u4441ot\u0180;be\u3334\u1d47\u3335\u62c5;\u6a66\u0380Aacmstx\u3346\u334a\u3357\u335b\u335e\u3363\u336drr;\u61d8r\u0100hr\u3350\u3352\xeb\u2228\u0100;o\u0a36\u0a34t\u803b\xa7\u40a7i;\u403bwar;\u6929m\u0100in\u3369\xf0nu\xf3\xf1t;\u6736r\u0100;o\u3376\u2055\uc000\ud835\udd30\u0200acoy\u3382\u3386\u3391\u33a0rp;\u666f\u0100hy\u338b\u338fcy;\u4449;\u4448rt\u026d\u3399\0\0\u339ci\xe4\u1464ara\xec\u2e6f\u803b\xad\u40ad\u0100gm\u33a8\u33b4ma\u0180;fv\u33b1\u33b2\u33b2\u43c3;\u43c2\u0400;deglnpr\u12ab\u33c5\u33c9\u33ce\u33d6\u33de\u33e1\u33e6ot;\u6a6a\u0100;q\u12b1\u12b0\u0100;E\u33d3\u33d4\u6a9e;\u6aa0\u0100;E\u33db\u33dc\u6a9d;\u6a9fe;\u6246lus;\u6a24arr;\u6972ar\xf2\u113d\u0200aeit\u33f8\u3408\u340f\u3417\u0100ls\u33fd\u3404lsetm\xe9\u336ahp;\u6a33parsl;\u69e4\u0100dl\u1463\u3414e;\u6323\u0100;e\u341c\u341d\u6aaa\u0100;s\u3422\u3423\u6aac;\uc000\u2aac\ufe00\u0180flp\u342e\u3433\u3442tcy;\u444c\u0100;b\u3438\u3439\u402f\u0100;a\u343e\u343f\u69c4r;\u633ff;\uc000\ud835\udd64a\u0100dr\u344d\u0402es\u0100;u\u3454\u3455\u6660it\xbb\u3455\u0180csu\u3460\u3479\u349f\u0100au\u3465\u346fp\u0100;s\u1188\u346b;\uc000\u2293\ufe00p\u0100;s\u11b4\u3475;\uc000\u2294\ufe00u\u0100bp\u347f\u348f\u0180;es\u1197\u119c\u3486et\u0100;e\u1197\u348d\xf1\u119d\u0180;es\u11a8\u11ad\u3496et\u0100;e\u11a8\u349d\xf1\u11ae\u0180;af\u117b\u34a6\u05b0r\u0165\u34ab\u05b1\xbb\u117car\xf2\u1148\u0200cemt\u34b9\u34be\u34c2\u34c5r;\uc000\ud835\udcc8tm\xee\xf1i\xec\u3415ar\xe6\u11be\u0100ar\u34ce\u34d5r\u0100;f\u34d4\u17bf\u6606\u0100an\u34da\u34edight\u0100ep\u34e3\u34eapsilo\xee\u1ee0h\xe9\u2eafs\xbb\u2852\u0280bcmnp\u34fb\u355e\u1209\u358b\u358e\u0480;Edemnprs\u350e\u350f\u3511\u3515\u351e\u3523\u352c\u3531\u3536\u6282;\u6ac5ot;\u6abd\u0100;d\u11da\u351aot;\u6ac3ult;\u6ac1\u0100Ee\u3528\u352a;\u6acb;\u628alus;\u6abfarr;\u6979\u0180eiu\u353d\u3552\u3555t\u0180;en\u350e\u3545\u354bq\u0100;q\u11da\u350feq\u0100;q\u352b\u3528m;\u6ac7\u0100bp\u355a\u355c;\u6ad5;\u6ad3c\u0300;acens\u11ed\u356c\u3572\u3579\u357b\u3326ppro\xf8\u32faurlye\xf1\u11fe\xf1\u11f3\u0180aes\u3582\u3588\u331bppro\xf8\u331aq\xf1\u3317g;\u666a\u0680123;Edehlmnps\u35a9\u35ac\u35af\u121c\u35b2\u35b4\u35c0\u35c9\u35d5\u35da\u35df\u35e8\u35ed\u803b\xb9\u40b9\u803b\xb2\u40b2\u803b\xb3\u40b3;\u6ac6\u0100os\u35b9\u35bct;\u6abeub;\u6ad8\u0100;d\u1222\u35c5ot;\u6ac4s\u0100ou\u35cf\u35d2l;\u67c9b;\u6ad7arr;\u697bult;\u6ac2\u0100Ee\u35e4\u35e6;\u6acc;\u628blus;\u6ac0\u0180eiu\u35f4\u3609\u360ct\u0180;en\u121c\u35fc\u3602q\u0100;q\u1222\u35b2eq\u0100;q\u35e7\u35e4m;\u6ac8\u0100bp\u3611\u3613;\u6ad4;\u6ad6\u0180Aan\u361c\u3620\u362drr;\u61d9r\u0100hr\u3626\u3628\xeb\u222e\u0100;o\u0a2b\u0a29war;\u692alig\u803b\xdf\u40df\u0be1\u3651\u365d\u3660\u12ce\u3673\u3679\0\u367e\u36c2\0\0\0\0\0\u36db\u3703\0\u3709\u376c\0\0\0\u3787\u0272\u3656\0\0\u365bget;\u6316;\u43c4r\xeb\u0e5f\u0180aey\u3666\u366b\u3670ron;\u4165dil;\u4163;\u4442lrec;\u6315r;\uc000\ud835\udd31\u0200eiko\u3686\u369d\u36b5\u36bc\u01f2\u368b\0\u3691e\u01004f\u1284\u1281a\u0180;sv\u3698\u3699\u369b\u43b8ym;\u43d1\u0100cn\u36a2\u36b2k\u0100as\u36a8\u36aeppro\xf8\u12c1im\xbb\u12acs\xf0\u129e\u0100as\u36ba\u36ae\xf0\u12c1rn\u803b\xfe\u40fe\u01ec\u031f\u36c6\u22e7es\u8180\xd7;bd\u36cf\u36d0\u36d8\u40d7\u0100;a\u190f\u36d5r;\u6a31;\u6a30\u0180eps\u36e1\u36e3\u3700\xe1\u2a4d\u0200;bcf\u0486\u36ec\u36f0\u36f4ot;\u6336ir;\u6af1\u0100;o\u36f9\u36fc\uc000\ud835\udd65rk;\u6ada\xe1\u3362rime;\u6034\u0180aip\u370f\u3712\u3764d\xe5\u1248\u0380adempst\u3721\u374d\u3740\u3751\u3757\u375c\u375fngle\u0280;dlqr\u3730\u3731\u3736\u3740\u3742\u65b5own\xbb\u1dbbeft\u0100;e\u2800\u373e\xf1\u092e;\u625cight\u0100;e\u32aa\u374b\xf1\u105aot;\u65ecinus;\u6a3alus;\u6a39b;\u69cdime;\u6a3bezium;\u63e2\u0180cht\u3772\u377d\u3781\u0100ry\u3777\u377b;\uc000\ud835\udcc9;\u4446cy;\u445brok;\u4167\u0100io\u378b\u378ex\xf4\u1777head\u0100lr\u3797\u37a0eftarro\xf7\u084fightarrow\xbb\u0f5d\u0900AHabcdfghlmoprstuw\u37d0\u37d3\u37d7\u37e4\u37f0\u37fc\u380e\u381c\u3823\u3834\u3851\u385d\u386b\u38a9\u38cc\u38d2\u38ea\u38f6r\xf2\u03edar;\u6963\u0100cr\u37dc\u37e2ute\u803b\xfa\u40fa\xf2\u1150r\u01e3\u37ea\0\u37edy;\u445eve;\u416d\u0100iy\u37f5\u37farc\u803b\xfb\u40fb;\u4443\u0180abh\u3803\u3806\u380br\xf2\u13adlac;\u4171a\xf2\u13c3\u0100ir\u3813\u3818sht;\u697e;\uc000\ud835\udd32rave\u803b\xf9\u40f9\u0161\u3827\u3831r\u0100lr\u382c\u382e\xbb\u0957\xbb\u1083lk;\u6580\u0100ct\u3839\u384d\u026f\u383f\0\0\u384arn\u0100;e\u3845\u3846\u631cr\xbb\u3846op;\u630fri;\u65f8\u0100al\u3856\u385acr;\u416b\u80bb\xa8\u0349\u0100gp\u3862\u3866on;\u4173f;\uc000\ud835\udd66\u0300adhlsu\u114b\u3878\u387d\u1372\u3891\u38a0own\xe1\u13b3arpoon\u0100lr\u3888\u388cef\xf4\u382digh\xf4\u382fi\u0180;hl\u3899\u389a\u389c\u43c5\xbb\u13faon\xbb\u389aparrows;\u61c8\u0180cit\u38b0\u38c4\u38c8\u026f\u38b6\0\0\u38c1rn\u0100;e\u38bc\u38bd\u631dr\xbb\u38bdop;\u630eng;\u416fri;\u65f9cr;\uc000\ud835\udcca\u0180dir\u38d9\u38dd\u38e2ot;\u62f0lde;\u4169i\u0100;f\u3730\u38e8\xbb\u1813\u0100am\u38ef\u38f2r\xf2\u38a8l\u803b\xfc\u40fcangle;\u69a7\u0780ABDacdeflnoprsz\u391c\u391f\u3929\u392d\u39b5\u39b8\u39bd\u39df\u39e4\u39e8\u39f3\u39f9\u39fd\u3a01\u3a20r\xf2\u03f7ar\u0100;v\u3926\u3927\u6ae8;\u6ae9as\xe8\u03e1\u0100nr\u3932\u3937grt;\u699c\u0380eknprst\u34e3\u3946\u394b\u3952\u395d\u3964\u3996app\xe1\u2415othin\xe7\u1e96\u0180hir\u34eb\u2ec8\u3959op\xf4\u2fb5\u0100;h\u13b7\u3962\xef\u318d\u0100iu\u3969\u396dgm\xe1\u33b3\u0100bp\u3972\u3984setneq\u0100;q\u397d\u3980\uc000\u228a\ufe00;\uc000\u2acb\ufe00setneq\u0100;q\u398f\u3992\uc000\u228b\ufe00;\uc000\u2acc\ufe00\u0100hr\u399b\u399fet\xe1\u369ciangle\u0100lr\u39aa\u39afeft\xbb\u0925ight\xbb\u1051y;\u4432ash\xbb\u1036\u0180elr\u39c4\u39d2\u39d7\u0180;be\u2dea\u39cb\u39cfar;\u62bbq;\u625alip;\u62ee\u0100bt\u39dc\u1468a\xf2\u1469r;\uc000\ud835\udd33tr\xe9\u39aesu\u0100bp\u39ef\u39f1\xbb\u0d1c\xbb\u0d59pf;\uc000\ud835\udd67ro\xf0\u0efbtr\xe9\u39b4\u0100cu\u3a06\u3a0br;\uc000\ud835\udccb\u0100bp\u3a10\u3a18n\u0100Ee\u3980\u3a16\xbb\u397en\u0100Ee\u3992\u3a1e\xbb\u3990igzag;\u699a\u0380cefoprs\u3a36\u3a3b\u3a56\u3a5b\u3a54\u3a61\u3a6airc;\u4175\u0100di\u3a40\u3a51\u0100bg\u3a45\u3a49ar;\u6a5fe\u0100;q\u15fa\u3a4f;\u6259erp;\u6118r;\uc000\ud835\udd34pf;\uc000\ud835\udd68\u0100;e\u1479\u3a66at\xe8\u1479cr;\uc000\ud835\udccc\u0ae3\u178e\u3a87\0\u3a8b\0\u3a90\u3a9b\0\0\u3a9d\u3aa8\u3aab\u3aaf\0\0\u3ac3\u3ace\0\u3ad8\u17dc\u17dftr\xe9\u17d1r;\uc000\ud835\udd35\u0100Aa\u3a94\u3a97r\xf2\u03c3r\xf2\u09f6;\u43be\u0100Aa\u3aa1\u3aa4r\xf2\u03b8r\xf2\u09eba\xf0\u2713is;\u62fb\u0180dpt\u17a4\u3ab5\u3abe\u0100fl\u3aba\u17a9;\uc000\ud835\udd69im\xe5\u17b2\u0100Aa\u3ac7\u3acar\xf2\u03cer\xf2\u0a01\u0100cq\u3ad2\u17b8r;\uc000\ud835\udccd\u0100pt\u17d6\u3adcr\xe9\u17d4\u0400acefiosu\u3af0\u3afd\u3b08\u3b0c\u3b11\u3b15\u3b1b\u3b21c\u0100uy\u3af6\u3afbte\u803b\xfd\u40fd;\u444f\u0100iy\u3b02\u3b06rc;\u4177;\u444bn\u803b\xa5\u40a5r;\uc000\ud835\udd36cy;\u4457pf;\uc000\ud835\udd6acr;\uc000\ud835\udcce\u0100cm\u3b26\u3b29y;\u444el\u803b\xff\u40ff\u0500acdefhiosw\u3b42\u3b48\u3b54\u3b58\u3b64\u3b69\u3b6d\u3b74\u3b7a\u3b80cute;\u417a\u0100ay\u3b4d\u3b52ron;\u417e;\u4437ot;\u417c\u0100et\u3b5d\u3b61tr\xe6\u155fa;\u43b6r;\uc000\ud835\udd37cy;\u4436grarr;\u61ddpf;\uc000\ud835\udd6bcr;\uc000\ud835\udccf\u0100jn\u3b85\u3b87;\u600dj;\u600c"
  724. .split("")
  725. .map((c) => c.charCodeAt(0)));
  726. // Generated using scripts/write-decode-map.ts
  727. var xmlDecodeTree = new Uint16Array(
  728. // prettier-ignore
  729. "\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022"
  730. .split("")
  731. .map((c) => c.charCodeAt(0)));
  732. // Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
  733. var _a$1;
  734. const decodeMap = new Map([
  735. [0, 65533],
  736. // C1 Unicode control character reference replacements
  737. [128, 8364],
  738. [130, 8218],
  739. [131, 402],
  740. [132, 8222],
  741. [133, 8230],
  742. [134, 8224],
  743. [135, 8225],
  744. [136, 710],
  745. [137, 8240],
  746. [138, 352],
  747. [139, 8249],
  748. [140, 338],
  749. [142, 381],
  750. [145, 8216],
  751. [146, 8217],
  752. [147, 8220],
  753. [148, 8221],
  754. [149, 8226],
  755. [150, 8211],
  756. [151, 8212],
  757. [152, 732],
  758. [153, 8482],
  759. [154, 353],
  760. [155, 8250],
  761. [156, 339],
  762. [158, 382],
  763. [159, 376],
  764. ]);
  765. /**
  766. * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
  767. */
  768. const fromCodePoint =
  769. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
  770. (_a$1 = String.fromCodePoint) !== null && _a$1 !== void 0 ? _a$1 : function (codePoint) {
  771. let output = "";
  772. if (codePoint > 0xffff) {
  773. codePoint -= 0x10000;
  774. output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
  775. codePoint = 0xdc00 | (codePoint & 0x3ff);
  776. }
  777. output += String.fromCharCode(codePoint);
  778. return output;
  779. };
  780. /**
  781. * Replace the given code point with a replacement character if it is a
  782. * surrogate or is outside the valid range. Otherwise return the code
  783. * point unchanged.
  784. */
  785. function replaceCodePoint(codePoint) {
  786. var _a;
  787. if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
  788. return 0xfffd;
  789. }
  790. return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
  791. }
  792. var CharCodes;
  793. (function (CharCodes) {
  794. CharCodes[CharCodes["NUM"] = 35] = "NUM";
  795. CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
  796. CharCodes[CharCodes["EQUALS"] = 61] = "EQUALS";
  797. CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
  798. CharCodes[CharCodes["NINE"] = 57] = "NINE";
  799. CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
  800. CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
  801. CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
  802. CharCodes[CharCodes["LOWER_Z"] = 122] = "LOWER_Z";
  803. CharCodes[CharCodes["UPPER_A"] = 65] = "UPPER_A";
  804. CharCodes[CharCodes["UPPER_F"] = 70] = "UPPER_F";
  805. CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z";
  806. })(CharCodes || (CharCodes = {}));
  807. /** Bit that needs to be set to convert an upper case ASCII character to lower case */
  808. const TO_LOWER_BIT = 0b100000;
  809. var BinTrieFlags;
  810. (function (BinTrieFlags) {
  811. BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
  812. BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
  813. BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
  814. })(BinTrieFlags || (BinTrieFlags = {}));
  815. function isNumber$1(code) {
  816. return code >= CharCodes.ZERO && code <= CharCodes.NINE;
  817. }
  818. function isHexadecimalCharacter(code) {
  819. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||
  820. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F));
  821. }
  822. function isAsciiAlphaNumeric(code) {
  823. return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||
  824. (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||
  825. isNumber$1(code));
  826. }
  827. /**
  828. * Checks if the given character is a valid end character for an entity in an attribute.
  829. *
  830. * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.
  831. * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state
  832. */
  833. function isEntityInAttributeInvalidEnd(code) {
  834. return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);
  835. }
  836. var EntityDecoderState;
  837. (function (EntityDecoderState) {
  838. EntityDecoderState[EntityDecoderState["EntityStart"] = 0] = "EntityStart";
  839. EntityDecoderState[EntityDecoderState["NumericStart"] = 1] = "NumericStart";
  840. EntityDecoderState[EntityDecoderState["NumericDecimal"] = 2] = "NumericDecimal";
  841. EntityDecoderState[EntityDecoderState["NumericHex"] = 3] = "NumericHex";
  842. EntityDecoderState[EntityDecoderState["NamedEntity"] = 4] = "NamedEntity";
  843. })(EntityDecoderState || (EntityDecoderState = {}));
  844. var DecodingMode;
  845. (function (DecodingMode) {
  846. /** Entities in text nodes that can end with any character. */
  847. DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
  848. /** Only allow entities terminated with a semicolon. */
  849. DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
  850. /** Entities in attributes have limitations on ending characters. */
  851. DecodingMode[DecodingMode["Attribute"] = 2] = "Attribute";
  852. })(DecodingMode || (DecodingMode = {}));
  853. /**
  854. * Token decoder with support of writing partial entities.
  855. */
  856. class EntityDecoder {
  857. constructor(
  858. /** The tree used to decode entities. */
  859. decodeTree,
  860. /**
  861. * The function that is called when a codepoint is decoded.
  862. *
  863. * For multi-byte named entities, this will be called multiple times,
  864. * with the second codepoint, and the same `consumed` value.
  865. *
  866. * @param codepoint The decoded codepoint.
  867. * @param consumed The number of bytes consumed by the decoder.
  868. */
  869. emitCodePoint,
  870. /** An object that is used to produce errors. */
  871. errors) {
  872. this.decodeTree = decodeTree;
  873. this.emitCodePoint = emitCodePoint;
  874. this.errors = errors;
  875. /** The current state of the decoder. */
  876. this.state = EntityDecoderState.EntityStart;
  877. /** Characters that were consumed while parsing an entity. */
  878. this.consumed = 1;
  879. /**
  880. * The result of the entity.
  881. *
  882. * Either the result index of a numeric entity, or the codepoint of a
  883. * numeric entity.
  884. */
  885. this.result = 0;
  886. /** The current index in the decode tree. */
  887. this.treeIndex = 0;
  888. /** The number of characters that were consumed in excess. */
  889. this.excess = 1;
  890. /** The mode in which the decoder is operating. */
  891. this.decodeMode = DecodingMode.Strict;
  892. }
  893. /** Resets the instance to make it reusable. */
  894. startEntity(decodeMode) {
  895. this.decodeMode = decodeMode;
  896. this.state = EntityDecoderState.EntityStart;
  897. this.result = 0;
  898. this.treeIndex = 0;
  899. this.excess = 1;
  900. this.consumed = 1;
  901. }
  902. /**
  903. * Write an entity to the decoder. This can be called multiple times with partial entities.
  904. * If the entity is incomplete, the decoder will return -1.
  905. *
  906. * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
  907. * entity is incomplete, and resume when the next string is written.
  908. *
  909. * @param string The string containing the entity (or a continuation of the entity).
  910. * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
  911. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  912. */
  913. write(str, offset) {
  914. switch (this.state) {
  915. case EntityDecoderState.EntityStart: {
  916. if (str.charCodeAt(offset) === CharCodes.NUM) {
  917. this.state = EntityDecoderState.NumericStart;
  918. this.consumed += 1;
  919. return this.stateNumericStart(str, offset + 1);
  920. }
  921. this.state = EntityDecoderState.NamedEntity;
  922. return this.stateNamedEntity(str, offset);
  923. }
  924. case EntityDecoderState.NumericStart: {
  925. return this.stateNumericStart(str, offset);
  926. }
  927. case EntityDecoderState.NumericDecimal: {
  928. return this.stateNumericDecimal(str, offset);
  929. }
  930. case EntityDecoderState.NumericHex: {
  931. return this.stateNumericHex(str, offset);
  932. }
  933. case EntityDecoderState.NamedEntity: {
  934. return this.stateNamedEntity(str, offset);
  935. }
  936. }
  937. }
  938. /**
  939. * Switches between the numeric decimal and hexadecimal states.
  940. *
  941. * Equivalent to the `Numeric character reference state` in the HTML spec.
  942. *
  943. * @param str The string containing the entity (or a continuation of the entity).
  944. * @param offset The current offset.
  945. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  946. */
  947. stateNumericStart(str, offset) {
  948. if (offset >= str.length) {
  949. return -1;
  950. }
  951. if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
  952. this.state = EntityDecoderState.NumericHex;
  953. this.consumed += 1;
  954. return this.stateNumericHex(str, offset + 1);
  955. }
  956. this.state = EntityDecoderState.NumericDecimal;
  957. return this.stateNumericDecimal(str, offset);
  958. }
  959. addToNumericResult(str, start, end, base) {
  960. if (start !== end) {
  961. const digitCount = end - start;
  962. this.result =
  963. this.result * Math.pow(base, digitCount) +
  964. parseInt(str.substr(start, digitCount), base);
  965. this.consumed += digitCount;
  966. }
  967. }
  968. /**
  969. * Parses a hexadecimal numeric entity.
  970. *
  971. * Equivalent to the `Hexademical character reference state` in the HTML spec.
  972. *
  973. * @param str The string containing the entity (or a continuation of the entity).
  974. * @param offset The current offset.
  975. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  976. */
  977. stateNumericHex(str, offset) {
  978. const startIdx = offset;
  979. while (offset < str.length) {
  980. const char = str.charCodeAt(offset);
  981. if (isNumber$1(char) || isHexadecimalCharacter(char)) {
  982. offset += 1;
  983. }
  984. else {
  985. this.addToNumericResult(str, startIdx, offset, 16);
  986. return this.emitNumericEntity(char, 3);
  987. }
  988. }
  989. this.addToNumericResult(str, startIdx, offset, 16);
  990. return -1;
  991. }
  992. /**
  993. * Parses a decimal numeric entity.
  994. *
  995. * Equivalent to the `Decimal character reference state` in the HTML spec.
  996. *
  997. * @param str The string containing the entity (or a continuation of the entity).
  998. * @param offset The current offset.
  999. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  1000. */
  1001. stateNumericDecimal(str, offset) {
  1002. const startIdx = offset;
  1003. while (offset < str.length) {
  1004. const char = str.charCodeAt(offset);
  1005. if (isNumber$1(char)) {
  1006. offset += 1;
  1007. }
  1008. else {
  1009. this.addToNumericResult(str, startIdx, offset, 10);
  1010. return this.emitNumericEntity(char, 2);
  1011. }
  1012. }
  1013. this.addToNumericResult(str, startIdx, offset, 10);
  1014. return -1;
  1015. }
  1016. /**
  1017. * Validate and emit a numeric entity.
  1018. *
  1019. * Implements the logic from the `Hexademical character reference start
  1020. * state` and `Numeric character reference end state` in the HTML spec.
  1021. *
  1022. * @param lastCp The last code point of the entity. Used to see if the
  1023. * entity was terminated with a semicolon.
  1024. * @param expectedLength The minimum number of characters that should be
  1025. * consumed. Used to validate that at least one digit
  1026. * was consumed.
  1027. * @returns The number of characters that were consumed.
  1028. */
  1029. emitNumericEntity(lastCp, expectedLength) {
  1030. var _a;
  1031. // Ensure we consumed at least one digit.
  1032. if (this.consumed <= expectedLength) {
  1033. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  1034. return 0;
  1035. }
  1036. // Figure out if this is a legit end of the entity
  1037. if (lastCp === CharCodes.SEMI) {
  1038. this.consumed += 1;
  1039. }
  1040. else if (this.decodeMode === DecodingMode.Strict) {
  1041. return 0;
  1042. }
  1043. this.emitCodePoint(replaceCodePoint(this.result), this.consumed);
  1044. if (this.errors) {
  1045. if (lastCp !== CharCodes.SEMI) {
  1046. this.errors.missingSemicolonAfterCharacterReference();
  1047. }
  1048. this.errors.validateNumericCharacterReference(this.result);
  1049. }
  1050. return this.consumed;
  1051. }
  1052. /**
  1053. * Parses a named entity.
  1054. *
  1055. * Equivalent to the `Named character reference state` in the HTML spec.
  1056. *
  1057. * @param str The string containing the entity (or a continuation of the entity).
  1058. * @param offset The current offset.
  1059. * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
  1060. */
  1061. stateNamedEntity(str, offset) {
  1062. const { decodeTree } = this;
  1063. let current = decodeTree[this.treeIndex];
  1064. // The mask is the number of bytes of the value, including the current byte.
  1065. let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  1066. for (; offset < str.length; offset++, this.excess++) {
  1067. const char = str.charCodeAt(offset);
  1068. this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);
  1069. if (this.treeIndex < 0) {
  1070. return this.result === 0 ||
  1071. // If we are parsing an attribute
  1072. (this.decodeMode === DecodingMode.Attribute &&
  1073. // We shouldn't have consumed any characters after the entity,
  1074. (valueLength === 0 ||
  1075. // And there should be no invalid characters.
  1076. isEntityInAttributeInvalidEnd(char)))
  1077. ? 0
  1078. : this.emitNotTerminatedNamedEntity();
  1079. }
  1080. current = decodeTree[this.treeIndex];
  1081. valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
  1082. // If the branch is a value, store it and continue
  1083. if (valueLength !== 0) {
  1084. // If the entity is terminated by a semicolon, we are done.
  1085. if (char === CharCodes.SEMI) {
  1086. return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);
  1087. }
  1088. // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.
  1089. if (this.decodeMode !== DecodingMode.Strict) {
  1090. this.result = this.treeIndex;
  1091. this.consumed += this.excess;
  1092. this.excess = 0;
  1093. }
  1094. }
  1095. }
  1096. return -1;
  1097. }
  1098. /**
  1099. * Emit a named entity that was not terminated with a semicolon.
  1100. *
  1101. * @returns The number of characters consumed.
  1102. */
  1103. emitNotTerminatedNamedEntity() {
  1104. var _a;
  1105. const { result, decodeTree } = this;
  1106. const valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14;
  1107. this.emitNamedEntityData(result, valueLength, this.consumed);
  1108. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference();
  1109. return this.consumed;
  1110. }
  1111. /**
  1112. * Emit a named entity.
  1113. *
  1114. * @param result The index of the entity in the decode tree.
  1115. * @param valueLength The number of bytes in the entity.
  1116. * @param consumed The number of characters consumed.
  1117. *
  1118. * @returns The number of characters consumed.
  1119. */
  1120. emitNamedEntityData(result, valueLength, consumed) {
  1121. const { decodeTree } = this;
  1122. this.emitCodePoint(valueLength === 1
  1123. ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH
  1124. : decodeTree[result + 1], consumed);
  1125. if (valueLength === 3) {
  1126. // For multi-byte values, we need to emit the second byte.
  1127. this.emitCodePoint(decodeTree[result + 2], consumed);
  1128. }
  1129. return consumed;
  1130. }
  1131. /**
  1132. * Signal to the parser that the end of the input was reached.
  1133. *
  1134. * Remaining data will be emitted and relevant errors will be produced.
  1135. *
  1136. * @returns The number of characters consumed.
  1137. */
  1138. end() {
  1139. var _a;
  1140. switch (this.state) {
  1141. case EntityDecoderState.NamedEntity: {
  1142. // Emit a named entity if we have one.
  1143. return this.result !== 0 &&
  1144. (this.decodeMode !== DecodingMode.Attribute ||
  1145. this.result === this.treeIndex)
  1146. ? this.emitNotTerminatedNamedEntity()
  1147. : 0;
  1148. }
  1149. // Otherwise, emit a numeric entity if we have one.
  1150. case EntityDecoderState.NumericDecimal: {
  1151. return this.emitNumericEntity(0, 2);
  1152. }
  1153. case EntityDecoderState.NumericHex: {
  1154. return this.emitNumericEntity(0, 3);
  1155. }
  1156. case EntityDecoderState.NumericStart: {
  1157. (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);
  1158. return 0;
  1159. }
  1160. case EntityDecoderState.EntityStart: {
  1161. // Return 0 if we have no entity.
  1162. return 0;
  1163. }
  1164. }
  1165. }
  1166. }
  1167. /**
  1168. * Creates a function that decodes entities in a string.
  1169. *
  1170. * @param decodeTree The decode tree.
  1171. * @returns A function that decodes entities in a string.
  1172. */
  1173. function getDecoder(decodeTree) {
  1174. let ret = "";
  1175. const decoder = new EntityDecoder(decodeTree, (str) => (ret += fromCodePoint(str)));
  1176. return function decodeWithTrie(str, decodeMode) {
  1177. let lastIndex = 0;
  1178. let offset = 0;
  1179. while ((offset = str.indexOf("&", offset)) >= 0) {
  1180. ret += str.slice(lastIndex, offset);
  1181. decoder.startEntity(decodeMode);
  1182. const len = decoder.write(str,
  1183. // Skip the "&"
  1184. offset + 1);
  1185. if (len < 0) {
  1186. lastIndex = offset + decoder.end();
  1187. break;
  1188. }
  1189. lastIndex = offset + len;
  1190. // If `len` is 0, skip the current `&` and continue.
  1191. offset = len === 0 ? lastIndex + 1 : lastIndex;
  1192. }
  1193. const result = ret + str.slice(lastIndex);
  1194. // Make sure we don't keep a reference to the final string.
  1195. ret = "";
  1196. return result;
  1197. };
  1198. }
  1199. /**
  1200. * Determines the branch of the current node that is taken given the current
  1201. * character. This function is used to traverse the trie.
  1202. *
  1203. * @param decodeTree The trie.
  1204. * @param current The current node.
  1205. * @param nodeIdx The index right after the current node and its value.
  1206. * @param char The current character.
  1207. * @returns The index of the next node, or -1 if no branch is taken.
  1208. */
  1209. function determineBranch(decodeTree, current, nodeIdx, char) {
  1210. const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
  1211. const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
  1212. // Case 1: Single branch encoded in jump offset
  1213. if (branchCount === 0) {
  1214. return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
  1215. }
  1216. // Case 2: Multiple branches encoded in jump table
  1217. if (jumpOffset) {
  1218. const value = char - jumpOffset;
  1219. return value < 0 || value >= branchCount
  1220. ? -1
  1221. : decodeTree[nodeIdx + value] - 1;
  1222. }
  1223. // Case 3: Multiple branches encoded in dictionary
  1224. // Binary search for the character.
  1225. let lo = nodeIdx;
  1226. let hi = lo + branchCount - 1;
  1227. while (lo <= hi) {
  1228. const mid = (lo + hi) >>> 1;
  1229. const midVal = decodeTree[mid];
  1230. if (midVal < char) {
  1231. lo = mid + 1;
  1232. }
  1233. else if (midVal > char) {
  1234. hi = mid - 1;
  1235. }
  1236. else {
  1237. return decodeTree[mid + branchCount];
  1238. }
  1239. }
  1240. return -1;
  1241. }
  1242. const htmlDecoder = getDecoder(htmlDecodeTree);
  1243. getDecoder(xmlDecodeTree);
  1244. /**
  1245. * Decodes an HTML string.
  1246. *
  1247. * @param str The string to decode.
  1248. * @param mode The decoding mode.
  1249. * @returns The decoded string.
  1250. */
  1251. function decodeHTML(str, mode = DecodingMode.Legacy) {
  1252. return htmlDecoder(str, mode);
  1253. }
  1254. const defaultDelimitersOpen = new Uint8Array([123, 123]);
  1255. const defaultDelimitersClose = new Uint8Array([125, 125]);
  1256. function isTagStartChar(c) {
  1257. return c >= 97 && c <= 122 || c >= 65 && c <= 90;
  1258. }
  1259. function isWhitespace(c) {
  1260. return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
  1261. }
  1262. function isEndOfTagSection(c) {
  1263. return c === 47 || c === 62 || isWhitespace(c);
  1264. }
  1265. function toCharCodes(str) {
  1266. const ret = new Uint8Array(str.length);
  1267. for (let i = 0; i < str.length; i++) {
  1268. ret[i] = str.charCodeAt(i);
  1269. }
  1270. return ret;
  1271. }
  1272. const Sequences = {
  1273. Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
  1274. // CDATA[
  1275. CdataEnd: new Uint8Array([93, 93, 62]),
  1276. // ]]>
  1277. CommentEnd: new Uint8Array([45, 45, 62]),
  1278. // `-->`
  1279. ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
  1280. // `<\/script`
  1281. StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
  1282. // `</style`
  1283. TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
  1284. // `</title`
  1285. TextareaEnd: new Uint8Array([
  1286. 60,
  1287. 47,
  1288. 116,
  1289. 101,
  1290. 120,
  1291. 116,
  1292. 97,
  1293. 114,
  1294. 101,
  1295. 97
  1296. ])
  1297. // `</textarea
  1298. };
  1299. class Tokenizer {
  1300. constructor(stack, cbs) {
  1301. this.stack = stack;
  1302. this.cbs = cbs;
  1303. /** The current state the tokenizer is in. */
  1304. this.state = 1;
  1305. /** The read buffer. */
  1306. this.buffer = "";
  1307. /** The beginning of the section that is currently being read. */
  1308. this.sectionStart = 0;
  1309. /** The index within the buffer that we are currently looking at. */
  1310. this.index = 0;
  1311. /** The start of the last entity. */
  1312. this.entityStart = 0;
  1313. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  1314. this.baseState = 1;
  1315. /** For special parsing behavior inside of script and style tags. */
  1316. this.inRCDATA = false;
  1317. /** For disabling RCDATA tags handling */
  1318. this.inXML = false;
  1319. /** For disabling interpolation parsing in v-pre */
  1320. this.inVPre = false;
  1321. /** Record newline positions for fast line / column calculation */
  1322. this.newlines = [];
  1323. this.mode = 0;
  1324. this.delimiterOpen = defaultDelimitersOpen;
  1325. this.delimiterClose = defaultDelimitersClose;
  1326. this.delimiterIndex = -1;
  1327. this.currentSequence = void 0;
  1328. this.sequenceIndex = 0;
  1329. {
  1330. this.entityDecoder = new EntityDecoder(
  1331. htmlDecodeTree,
  1332. (cp, consumed) => this.emitCodePoint(cp, consumed)
  1333. );
  1334. }
  1335. }
  1336. get inSFCRoot() {
  1337. return this.mode === 2 && this.stack.length === 0;
  1338. }
  1339. reset() {
  1340. this.state = 1;
  1341. this.mode = 0;
  1342. this.buffer = "";
  1343. this.sectionStart = 0;
  1344. this.index = 0;
  1345. this.baseState = 1;
  1346. this.inRCDATA = false;
  1347. this.currentSequence = void 0;
  1348. this.newlines.length = 0;
  1349. this.delimiterOpen = defaultDelimitersOpen;
  1350. this.delimiterClose = defaultDelimitersClose;
  1351. }
  1352. /**
  1353. * Generate Position object with line / column information using recorded
  1354. * newline positions. We know the index is always going to be an already
  1355. * processed index, so all the newlines up to this index should have been
  1356. * recorded.
  1357. */
  1358. getPos(index) {
  1359. let line = 1;
  1360. let column = index + 1;
  1361. for (let i = this.newlines.length - 1; i >= 0; i--) {
  1362. const newlineIndex = this.newlines[i];
  1363. if (index > newlineIndex) {
  1364. line = i + 2;
  1365. column = index - newlineIndex;
  1366. break;
  1367. }
  1368. }
  1369. return {
  1370. column,
  1371. line,
  1372. offset: index
  1373. };
  1374. }
  1375. peek() {
  1376. return this.buffer.charCodeAt(this.index + 1);
  1377. }
  1378. stateText(c) {
  1379. if (c === 60) {
  1380. if (this.index > this.sectionStart) {
  1381. this.cbs.ontext(this.sectionStart, this.index);
  1382. }
  1383. this.state = 5;
  1384. this.sectionStart = this.index;
  1385. } else if (c === 38) {
  1386. this.startEntity();
  1387. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  1388. this.state = 2;
  1389. this.delimiterIndex = 0;
  1390. this.stateInterpolationOpen(c);
  1391. }
  1392. }
  1393. stateInterpolationOpen(c) {
  1394. if (c === this.delimiterOpen[this.delimiterIndex]) {
  1395. if (this.delimiterIndex === this.delimiterOpen.length - 1) {
  1396. const start = this.index + 1 - this.delimiterOpen.length;
  1397. if (start > this.sectionStart) {
  1398. this.cbs.ontext(this.sectionStart, start);
  1399. }
  1400. this.state = 3;
  1401. this.sectionStart = start;
  1402. } else {
  1403. this.delimiterIndex++;
  1404. }
  1405. } else if (this.inRCDATA) {
  1406. this.state = 32;
  1407. this.stateInRCDATA(c);
  1408. } else {
  1409. this.state = 1;
  1410. this.stateText(c);
  1411. }
  1412. }
  1413. stateInterpolation(c) {
  1414. if (c === this.delimiterClose[0]) {
  1415. this.state = 4;
  1416. this.delimiterIndex = 0;
  1417. this.stateInterpolationClose(c);
  1418. }
  1419. }
  1420. stateInterpolationClose(c) {
  1421. if (c === this.delimiterClose[this.delimiterIndex]) {
  1422. if (this.delimiterIndex === this.delimiterClose.length - 1) {
  1423. this.cbs.oninterpolation(this.sectionStart, this.index + 1);
  1424. if (this.inRCDATA) {
  1425. this.state = 32;
  1426. } else {
  1427. this.state = 1;
  1428. }
  1429. this.sectionStart = this.index + 1;
  1430. } else {
  1431. this.delimiterIndex++;
  1432. }
  1433. } else {
  1434. this.state = 3;
  1435. this.stateInterpolation(c);
  1436. }
  1437. }
  1438. stateSpecialStartSequence(c) {
  1439. const isEnd = this.sequenceIndex === this.currentSequence.length;
  1440. const isMatch = isEnd ? (
  1441. // If we are at the end of the sequence, make sure the tag name has ended
  1442. isEndOfTagSection(c)
  1443. ) : (
  1444. // Otherwise, do a case-insensitive comparison
  1445. (c | 32) === this.currentSequence[this.sequenceIndex]
  1446. );
  1447. if (!isMatch) {
  1448. this.inRCDATA = false;
  1449. } else if (!isEnd) {
  1450. this.sequenceIndex++;
  1451. return;
  1452. }
  1453. this.sequenceIndex = 0;
  1454. this.state = 6;
  1455. this.stateInTagName(c);
  1456. }
  1457. /** Look for an end tag. For <title> and <textarea>, also decode entities. */
  1458. stateInRCDATA(c) {
  1459. if (this.sequenceIndex === this.currentSequence.length) {
  1460. if (c === 62 || isWhitespace(c)) {
  1461. const endOfText = this.index - this.currentSequence.length;
  1462. if (this.sectionStart < endOfText) {
  1463. const actualIndex = this.index;
  1464. this.index = endOfText;
  1465. this.cbs.ontext(this.sectionStart, endOfText);
  1466. this.index = actualIndex;
  1467. }
  1468. this.sectionStart = endOfText + 2;
  1469. this.stateInClosingTagName(c);
  1470. this.inRCDATA = false;
  1471. return;
  1472. }
  1473. this.sequenceIndex = 0;
  1474. }
  1475. if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
  1476. this.sequenceIndex += 1;
  1477. } else if (this.sequenceIndex === 0) {
  1478. if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
  1479. if (c === 38) {
  1480. this.startEntity();
  1481. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  1482. this.state = 2;
  1483. this.delimiterIndex = 0;
  1484. this.stateInterpolationOpen(c);
  1485. }
  1486. } else if (this.fastForwardTo(60)) {
  1487. this.sequenceIndex = 1;
  1488. }
  1489. } else {
  1490. this.sequenceIndex = Number(c === 60);
  1491. }
  1492. }
  1493. stateCDATASequence(c) {
  1494. if (c === Sequences.Cdata[this.sequenceIndex]) {
  1495. if (++this.sequenceIndex === Sequences.Cdata.length) {
  1496. this.state = 28;
  1497. this.currentSequence = Sequences.CdataEnd;
  1498. this.sequenceIndex = 0;
  1499. this.sectionStart = this.index + 1;
  1500. }
  1501. } else {
  1502. this.sequenceIndex = 0;
  1503. this.state = 23;
  1504. this.stateInDeclaration(c);
  1505. }
  1506. }
  1507. /**
  1508. * When we wait for one specific character, we can speed things up
  1509. * by skipping through the buffer until we find it.
  1510. *
  1511. * @returns Whether the character was found.
  1512. */
  1513. fastForwardTo(c) {
  1514. while (++this.index < this.buffer.length) {
  1515. const cc = this.buffer.charCodeAt(this.index);
  1516. if (cc === 10) {
  1517. this.newlines.push(this.index);
  1518. }
  1519. if (cc === c) {
  1520. return true;
  1521. }
  1522. }
  1523. this.index = this.buffer.length - 1;
  1524. return false;
  1525. }
  1526. /**
  1527. * Comments and CDATA end with `-->` and `]]>`.
  1528. *
  1529. * Their common qualities are:
  1530. * - Their end sequences have a distinct character they start with.
  1531. * - That character is then repeated, so we have to check multiple repeats.
  1532. * - All characters but the start character of the sequence can be skipped.
  1533. */
  1534. stateInCommentLike(c) {
  1535. if (c === this.currentSequence[this.sequenceIndex]) {
  1536. if (++this.sequenceIndex === this.currentSequence.length) {
  1537. if (this.currentSequence === Sequences.CdataEnd) {
  1538. this.cbs.oncdata(this.sectionStart, this.index - 2);
  1539. } else {
  1540. this.cbs.oncomment(this.sectionStart, this.index - 2);
  1541. }
  1542. this.sequenceIndex = 0;
  1543. this.sectionStart = this.index + 1;
  1544. this.state = 1;
  1545. }
  1546. } else if (this.sequenceIndex === 0) {
  1547. if (this.fastForwardTo(this.currentSequence[0])) {
  1548. this.sequenceIndex = 1;
  1549. }
  1550. } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
  1551. this.sequenceIndex = 0;
  1552. }
  1553. }
  1554. startSpecial(sequence, offset) {
  1555. this.enterRCDATA(sequence, offset);
  1556. this.state = 31;
  1557. }
  1558. enterRCDATA(sequence, offset) {
  1559. this.inRCDATA = true;
  1560. this.currentSequence = sequence;
  1561. this.sequenceIndex = offset;
  1562. }
  1563. stateBeforeTagName(c) {
  1564. if (c === 33) {
  1565. this.state = 22;
  1566. this.sectionStart = this.index + 1;
  1567. } else if (c === 63) {
  1568. this.state = 24;
  1569. this.sectionStart = this.index + 1;
  1570. } else if (isTagStartChar(c)) {
  1571. this.sectionStart = this.index;
  1572. if (this.mode === 0) {
  1573. this.state = 6;
  1574. } else if (this.inSFCRoot) {
  1575. this.state = 34;
  1576. } else if (!this.inXML) {
  1577. if (c === 116) {
  1578. this.state = 30;
  1579. } else {
  1580. this.state = c === 115 ? 29 : 6;
  1581. }
  1582. } else {
  1583. this.state = 6;
  1584. }
  1585. } else if (c === 47) {
  1586. this.state = 8;
  1587. } else {
  1588. this.state = 1;
  1589. this.stateText(c);
  1590. }
  1591. }
  1592. stateInTagName(c) {
  1593. if (isEndOfTagSection(c)) {
  1594. this.handleTagName(c);
  1595. }
  1596. }
  1597. stateInSFCRootTagName(c) {
  1598. if (isEndOfTagSection(c)) {
  1599. const tag = this.buffer.slice(this.sectionStart, this.index);
  1600. if (tag !== "template") {
  1601. this.enterRCDATA(toCharCodes(`</` + tag), 0);
  1602. }
  1603. this.handleTagName(c);
  1604. }
  1605. }
  1606. handleTagName(c) {
  1607. this.cbs.onopentagname(this.sectionStart, this.index);
  1608. this.sectionStart = -1;
  1609. this.state = 11;
  1610. this.stateBeforeAttrName(c);
  1611. }
  1612. stateBeforeClosingTagName(c) {
  1613. if (isWhitespace(c)) ; else if (c === 62) {
  1614. {
  1615. this.cbs.onerr(14, this.index);
  1616. }
  1617. this.state = 1;
  1618. this.sectionStart = this.index + 1;
  1619. } else {
  1620. this.state = isTagStartChar(c) ? 9 : 27;
  1621. this.sectionStart = this.index;
  1622. }
  1623. }
  1624. stateInClosingTagName(c) {
  1625. if (c === 62 || isWhitespace(c)) {
  1626. this.cbs.onclosetag(this.sectionStart, this.index);
  1627. this.sectionStart = -1;
  1628. this.state = 10;
  1629. this.stateAfterClosingTagName(c);
  1630. }
  1631. }
  1632. stateAfterClosingTagName(c) {
  1633. if (c === 62) {
  1634. this.state = 1;
  1635. this.sectionStart = this.index + 1;
  1636. }
  1637. }
  1638. stateBeforeAttrName(c) {
  1639. if (c === 62) {
  1640. this.cbs.onopentagend(this.index);
  1641. if (this.inRCDATA) {
  1642. this.state = 32;
  1643. } else {
  1644. this.state = 1;
  1645. }
  1646. this.sectionStart = this.index + 1;
  1647. } else if (c === 47) {
  1648. this.state = 7;
  1649. if (this.peek() !== 62) {
  1650. this.cbs.onerr(22, this.index);
  1651. }
  1652. } else if (c === 60 && this.peek() === 47) {
  1653. this.cbs.onopentagend(this.index);
  1654. this.state = 5;
  1655. this.sectionStart = this.index;
  1656. } else if (!isWhitespace(c)) {
  1657. if (c === 61) {
  1658. this.cbs.onerr(
  1659. 19,
  1660. this.index
  1661. );
  1662. }
  1663. this.handleAttrStart(c);
  1664. }
  1665. }
  1666. handleAttrStart(c) {
  1667. if (c === 118 && this.peek() === 45) {
  1668. this.state = 13;
  1669. this.sectionStart = this.index;
  1670. } else if (c === 46 || c === 58 || c === 64 || c === 35) {
  1671. this.cbs.ondirname(this.index, this.index + 1);
  1672. this.state = 14;
  1673. this.sectionStart = this.index + 1;
  1674. } else {
  1675. this.state = 12;
  1676. this.sectionStart = this.index;
  1677. }
  1678. }
  1679. stateInSelfClosingTag(c) {
  1680. if (c === 62) {
  1681. this.cbs.onselfclosingtag(this.index);
  1682. this.state = 1;
  1683. this.sectionStart = this.index + 1;
  1684. this.inRCDATA = false;
  1685. } else if (!isWhitespace(c)) {
  1686. this.state = 11;
  1687. this.stateBeforeAttrName(c);
  1688. }
  1689. }
  1690. stateInAttrName(c) {
  1691. if (c === 61 || isEndOfTagSection(c)) {
  1692. this.cbs.onattribname(this.sectionStart, this.index);
  1693. this.handleAttrNameEnd(c);
  1694. } else if (c === 34 || c === 39 || c === 60) {
  1695. this.cbs.onerr(
  1696. 17,
  1697. this.index
  1698. );
  1699. }
  1700. }
  1701. stateInDirName(c) {
  1702. if (c === 61 || isEndOfTagSection(c)) {
  1703. this.cbs.ondirname(this.sectionStart, this.index);
  1704. this.handleAttrNameEnd(c);
  1705. } else if (c === 58) {
  1706. this.cbs.ondirname(this.sectionStart, this.index);
  1707. this.state = 14;
  1708. this.sectionStart = this.index + 1;
  1709. } else if (c === 46) {
  1710. this.cbs.ondirname(this.sectionStart, this.index);
  1711. this.state = 16;
  1712. this.sectionStart = this.index + 1;
  1713. }
  1714. }
  1715. stateInDirArg(c) {
  1716. if (c === 61 || isEndOfTagSection(c)) {
  1717. this.cbs.ondirarg(this.sectionStart, this.index);
  1718. this.handleAttrNameEnd(c);
  1719. } else if (c === 91) {
  1720. this.state = 15;
  1721. } else if (c === 46) {
  1722. this.cbs.ondirarg(this.sectionStart, this.index);
  1723. this.state = 16;
  1724. this.sectionStart = this.index + 1;
  1725. }
  1726. }
  1727. stateInDynamicDirArg(c) {
  1728. if (c === 93) {
  1729. this.state = 14;
  1730. } else if (c === 61 || isEndOfTagSection(c)) {
  1731. this.cbs.ondirarg(this.sectionStart, this.index + 1);
  1732. this.handleAttrNameEnd(c);
  1733. {
  1734. this.cbs.onerr(
  1735. 27,
  1736. this.index
  1737. );
  1738. }
  1739. }
  1740. }
  1741. stateInDirModifier(c) {
  1742. if (c === 61 || isEndOfTagSection(c)) {
  1743. this.cbs.ondirmodifier(this.sectionStart, this.index);
  1744. this.handleAttrNameEnd(c);
  1745. } else if (c === 46) {
  1746. this.cbs.ondirmodifier(this.sectionStart, this.index);
  1747. this.sectionStart = this.index + 1;
  1748. }
  1749. }
  1750. handleAttrNameEnd(c) {
  1751. this.sectionStart = this.index;
  1752. this.state = 17;
  1753. this.cbs.onattribnameend(this.index);
  1754. this.stateAfterAttrName(c);
  1755. }
  1756. stateAfterAttrName(c) {
  1757. if (c === 61) {
  1758. this.state = 18;
  1759. } else if (c === 47 || c === 62) {
  1760. this.cbs.onattribend(0, this.sectionStart);
  1761. this.sectionStart = -1;
  1762. this.state = 11;
  1763. this.stateBeforeAttrName(c);
  1764. } else if (!isWhitespace(c)) {
  1765. this.cbs.onattribend(0, this.sectionStart);
  1766. this.handleAttrStart(c);
  1767. }
  1768. }
  1769. stateBeforeAttrValue(c) {
  1770. if (c === 34) {
  1771. this.state = 19;
  1772. this.sectionStart = this.index + 1;
  1773. } else if (c === 39) {
  1774. this.state = 20;
  1775. this.sectionStart = this.index + 1;
  1776. } else if (!isWhitespace(c)) {
  1777. this.sectionStart = this.index;
  1778. this.state = 21;
  1779. this.stateInAttrValueNoQuotes(c);
  1780. }
  1781. }
  1782. handleInAttrValue(c, quote) {
  1783. if (c === quote || false) {
  1784. this.cbs.onattribdata(this.sectionStart, this.index);
  1785. this.sectionStart = -1;
  1786. this.cbs.onattribend(
  1787. quote === 34 ? 3 : 2,
  1788. this.index + 1
  1789. );
  1790. this.state = 11;
  1791. } else if (c === 38) {
  1792. this.startEntity();
  1793. }
  1794. }
  1795. stateInAttrValueDoubleQuotes(c) {
  1796. this.handleInAttrValue(c, 34);
  1797. }
  1798. stateInAttrValueSingleQuotes(c) {
  1799. this.handleInAttrValue(c, 39);
  1800. }
  1801. stateInAttrValueNoQuotes(c) {
  1802. if (isWhitespace(c) || c === 62) {
  1803. this.cbs.onattribdata(this.sectionStart, this.index);
  1804. this.sectionStart = -1;
  1805. this.cbs.onattribend(1, this.index);
  1806. this.state = 11;
  1807. this.stateBeforeAttrName(c);
  1808. } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
  1809. this.cbs.onerr(
  1810. 18,
  1811. this.index
  1812. );
  1813. } else if (c === 38) {
  1814. this.startEntity();
  1815. }
  1816. }
  1817. stateBeforeDeclaration(c) {
  1818. if (c === 91) {
  1819. this.state = 26;
  1820. this.sequenceIndex = 0;
  1821. } else {
  1822. this.state = c === 45 ? 25 : 23;
  1823. }
  1824. }
  1825. stateInDeclaration(c) {
  1826. if (c === 62 || this.fastForwardTo(62)) {
  1827. this.state = 1;
  1828. this.sectionStart = this.index + 1;
  1829. }
  1830. }
  1831. stateInProcessingInstruction(c) {
  1832. if (c === 62 || this.fastForwardTo(62)) {
  1833. this.cbs.onprocessinginstruction(this.sectionStart, this.index);
  1834. this.state = 1;
  1835. this.sectionStart = this.index + 1;
  1836. }
  1837. }
  1838. stateBeforeComment(c) {
  1839. if (c === 45) {
  1840. this.state = 28;
  1841. this.currentSequence = Sequences.CommentEnd;
  1842. this.sequenceIndex = 2;
  1843. this.sectionStart = this.index + 1;
  1844. } else {
  1845. this.state = 23;
  1846. }
  1847. }
  1848. stateInSpecialComment(c) {
  1849. if (c === 62 || this.fastForwardTo(62)) {
  1850. this.cbs.oncomment(this.sectionStart, this.index);
  1851. this.state = 1;
  1852. this.sectionStart = this.index + 1;
  1853. }
  1854. }
  1855. stateBeforeSpecialS(c) {
  1856. if (c === Sequences.ScriptEnd[3]) {
  1857. this.startSpecial(Sequences.ScriptEnd, 4);
  1858. } else if (c === Sequences.StyleEnd[3]) {
  1859. this.startSpecial(Sequences.StyleEnd, 4);
  1860. } else {
  1861. this.state = 6;
  1862. this.stateInTagName(c);
  1863. }
  1864. }
  1865. stateBeforeSpecialT(c) {
  1866. if (c === Sequences.TitleEnd[3]) {
  1867. this.startSpecial(Sequences.TitleEnd, 4);
  1868. } else if (c === Sequences.TextareaEnd[3]) {
  1869. this.startSpecial(Sequences.TextareaEnd, 4);
  1870. } else {
  1871. this.state = 6;
  1872. this.stateInTagName(c);
  1873. }
  1874. }
  1875. startEntity() {
  1876. {
  1877. this.baseState = this.state;
  1878. this.state = 33;
  1879. this.entityStart = this.index;
  1880. this.entityDecoder.startEntity(
  1881. this.baseState === 1 || this.baseState === 32 ? DecodingMode.Legacy : DecodingMode.Attribute
  1882. );
  1883. }
  1884. }
  1885. stateInEntity() {
  1886. {
  1887. const length = this.entityDecoder.write(this.buffer, this.index);
  1888. if (length >= 0) {
  1889. this.state = this.baseState;
  1890. if (length === 0) {
  1891. this.index = this.entityStart;
  1892. }
  1893. } else {
  1894. this.index = this.buffer.length - 1;
  1895. }
  1896. }
  1897. }
  1898. /**
  1899. * Iterates through the buffer, calling the function corresponding to the current state.
  1900. *
  1901. * States that are more likely to be hit are higher up, as a performance improvement.
  1902. */
  1903. parse(input) {
  1904. this.buffer = input;
  1905. while (this.index < this.buffer.length) {
  1906. const c = this.buffer.charCodeAt(this.index);
  1907. if (c === 10 && this.state !== 33) {
  1908. this.newlines.push(this.index);
  1909. }
  1910. switch (this.state) {
  1911. case 1: {
  1912. this.stateText(c);
  1913. break;
  1914. }
  1915. case 2: {
  1916. this.stateInterpolationOpen(c);
  1917. break;
  1918. }
  1919. case 3: {
  1920. this.stateInterpolation(c);
  1921. break;
  1922. }
  1923. case 4: {
  1924. this.stateInterpolationClose(c);
  1925. break;
  1926. }
  1927. case 31: {
  1928. this.stateSpecialStartSequence(c);
  1929. break;
  1930. }
  1931. case 32: {
  1932. this.stateInRCDATA(c);
  1933. break;
  1934. }
  1935. case 26: {
  1936. this.stateCDATASequence(c);
  1937. break;
  1938. }
  1939. case 19: {
  1940. this.stateInAttrValueDoubleQuotes(c);
  1941. break;
  1942. }
  1943. case 12: {
  1944. this.stateInAttrName(c);
  1945. break;
  1946. }
  1947. case 13: {
  1948. this.stateInDirName(c);
  1949. break;
  1950. }
  1951. case 14: {
  1952. this.stateInDirArg(c);
  1953. break;
  1954. }
  1955. case 15: {
  1956. this.stateInDynamicDirArg(c);
  1957. break;
  1958. }
  1959. case 16: {
  1960. this.stateInDirModifier(c);
  1961. break;
  1962. }
  1963. case 28: {
  1964. this.stateInCommentLike(c);
  1965. break;
  1966. }
  1967. case 27: {
  1968. this.stateInSpecialComment(c);
  1969. break;
  1970. }
  1971. case 11: {
  1972. this.stateBeforeAttrName(c);
  1973. break;
  1974. }
  1975. case 6: {
  1976. this.stateInTagName(c);
  1977. break;
  1978. }
  1979. case 34: {
  1980. this.stateInSFCRootTagName(c);
  1981. break;
  1982. }
  1983. case 9: {
  1984. this.stateInClosingTagName(c);
  1985. break;
  1986. }
  1987. case 5: {
  1988. this.stateBeforeTagName(c);
  1989. break;
  1990. }
  1991. case 17: {
  1992. this.stateAfterAttrName(c);
  1993. break;
  1994. }
  1995. case 20: {
  1996. this.stateInAttrValueSingleQuotes(c);
  1997. break;
  1998. }
  1999. case 18: {
  2000. this.stateBeforeAttrValue(c);
  2001. break;
  2002. }
  2003. case 8: {
  2004. this.stateBeforeClosingTagName(c);
  2005. break;
  2006. }
  2007. case 10: {
  2008. this.stateAfterClosingTagName(c);
  2009. break;
  2010. }
  2011. case 29: {
  2012. this.stateBeforeSpecialS(c);
  2013. break;
  2014. }
  2015. case 30: {
  2016. this.stateBeforeSpecialT(c);
  2017. break;
  2018. }
  2019. case 21: {
  2020. this.stateInAttrValueNoQuotes(c);
  2021. break;
  2022. }
  2023. case 7: {
  2024. this.stateInSelfClosingTag(c);
  2025. break;
  2026. }
  2027. case 23: {
  2028. this.stateInDeclaration(c);
  2029. break;
  2030. }
  2031. case 22: {
  2032. this.stateBeforeDeclaration(c);
  2033. break;
  2034. }
  2035. case 25: {
  2036. this.stateBeforeComment(c);
  2037. break;
  2038. }
  2039. case 24: {
  2040. this.stateInProcessingInstruction(c);
  2041. break;
  2042. }
  2043. case 33: {
  2044. this.stateInEntity();
  2045. break;
  2046. }
  2047. }
  2048. this.index++;
  2049. }
  2050. this.cleanup();
  2051. this.finish();
  2052. }
  2053. /**
  2054. * Remove data that has already been consumed from the buffer.
  2055. */
  2056. cleanup() {
  2057. if (this.sectionStart !== this.index) {
  2058. if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
  2059. this.cbs.ontext(this.sectionStart, this.index);
  2060. this.sectionStart = this.index;
  2061. } else if (this.state === 19 || this.state === 20 || this.state === 21) {
  2062. this.cbs.onattribdata(this.sectionStart, this.index);
  2063. this.sectionStart = this.index;
  2064. }
  2065. }
  2066. }
  2067. finish() {
  2068. if (this.state === 33) {
  2069. this.entityDecoder.end();
  2070. this.state = this.baseState;
  2071. }
  2072. this.handleTrailingData();
  2073. this.cbs.onend();
  2074. }
  2075. /** Handle any trailing data. */
  2076. handleTrailingData() {
  2077. const endIndex = this.buffer.length;
  2078. if (this.sectionStart >= endIndex) {
  2079. return;
  2080. }
  2081. if (this.state === 28) {
  2082. if (this.currentSequence === Sequences.CdataEnd) {
  2083. this.cbs.oncdata(this.sectionStart, endIndex);
  2084. } else {
  2085. this.cbs.oncomment(this.sectionStart, endIndex);
  2086. }
  2087. } 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 {
  2088. this.cbs.ontext(this.sectionStart, endIndex);
  2089. }
  2090. }
  2091. emitCodePoint(cp, consumed) {
  2092. {
  2093. if (this.baseState !== 1 && this.baseState !== 32) {
  2094. if (this.sectionStart < this.entityStart) {
  2095. this.cbs.onattribdata(this.sectionStart, this.entityStart);
  2096. }
  2097. this.sectionStart = this.entityStart + consumed;
  2098. this.index = this.sectionStart - 1;
  2099. this.cbs.onattribentity(
  2100. fromCodePoint(cp),
  2101. this.entityStart,
  2102. this.sectionStart
  2103. );
  2104. } else {
  2105. if (this.sectionStart < this.entityStart) {
  2106. this.cbs.ontext(this.sectionStart, this.entityStart);
  2107. }
  2108. this.sectionStart = this.entityStart + consumed;
  2109. this.index = this.sectionStart - 1;
  2110. this.cbs.ontextentity(
  2111. fromCodePoint(cp),
  2112. this.entityStart,
  2113. this.sectionStart
  2114. );
  2115. }
  2116. }
  2117. }
  2118. }
  2119. const CompilerDeprecationTypes = {
  2120. "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
  2121. "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
  2122. "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
  2123. "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
  2124. "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2125. "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
  2126. "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
  2127. "COMPILER_FILTERS": "COMPILER_FILTERS"
  2128. };
  2129. const deprecationData = {
  2130. ["COMPILER_IS_ON_ELEMENT"]: {
  2131. 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:".`,
  2132. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  2133. },
  2134. ["COMPILER_V_BIND_SYNC"]: {
  2135. 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}\`.`,
  2136. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  2137. },
  2138. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  2139. 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.`,
  2140. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  2141. },
  2142. ["COMPILER_V_ON_NATIVE"]: {
  2143. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  2144. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  2145. },
  2146. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  2147. 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.`,
  2148. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  2149. },
  2150. ["COMPILER_NATIVE_TEMPLATE"]: {
  2151. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  2152. },
  2153. ["COMPILER_INLINE_TEMPLATE"]: {
  2154. message: `"inline-template" has been removed in Vue 3.`,
  2155. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  2156. },
  2157. ["COMPILER_FILTERS"]: {
  2158. 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.`,
  2159. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  2160. }
  2161. };
  2162. function getCompatValue(key, { compatConfig }) {
  2163. const value = compatConfig && compatConfig[key];
  2164. if (key === "MODE") {
  2165. return value || 3;
  2166. } else {
  2167. return value;
  2168. }
  2169. }
  2170. function isCompatEnabled(key, context) {
  2171. const mode = getCompatValue("MODE", context);
  2172. const value = getCompatValue(key, context);
  2173. return mode === 3 ? value === true : value !== false;
  2174. }
  2175. function checkCompatEnabled(key, context, loc, ...args) {
  2176. const enabled = isCompatEnabled(key, context);
  2177. if (enabled) {
  2178. warnDeprecation(key, context, loc, ...args);
  2179. }
  2180. return enabled;
  2181. }
  2182. function warnDeprecation(key, context, loc, ...args) {
  2183. const val = getCompatValue(key, context);
  2184. if (val === "suppress-warning") {
  2185. return;
  2186. }
  2187. const { message, link } = deprecationData[key];
  2188. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  2189. Details: ${link}` : ``}`;
  2190. const err = new SyntaxError(msg);
  2191. err.code = key;
  2192. if (loc) err.loc = loc;
  2193. context.onWarn(err);
  2194. }
  2195. function defaultOnError(error) {
  2196. throw error;
  2197. }
  2198. function defaultOnWarn(msg) {
  2199. console.warn(`[Vue warn] ${msg.message}`);
  2200. }
  2201. function createCompilerError(code, loc, messages, additionalMessage) {
  2202. const msg = (messages || errorMessages$1)[code] + (additionalMessage || ``) ;
  2203. const error = new SyntaxError(String(msg));
  2204. error.code = code;
  2205. error.loc = loc;
  2206. return error;
  2207. }
  2208. const ErrorCodes = {
  2209. "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
  2210. "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
  2211. "CDATA_IN_HTML_CONTENT": 1,
  2212. "1": "CDATA_IN_HTML_CONTENT",
  2213. "DUPLICATE_ATTRIBUTE": 2,
  2214. "2": "DUPLICATE_ATTRIBUTE",
  2215. "END_TAG_WITH_ATTRIBUTES": 3,
  2216. "3": "END_TAG_WITH_ATTRIBUTES",
  2217. "END_TAG_WITH_TRAILING_SOLIDUS": 4,
  2218. "4": "END_TAG_WITH_TRAILING_SOLIDUS",
  2219. "EOF_BEFORE_TAG_NAME": 5,
  2220. "5": "EOF_BEFORE_TAG_NAME",
  2221. "EOF_IN_CDATA": 6,
  2222. "6": "EOF_IN_CDATA",
  2223. "EOF_IN_COMMENT": 7,
  2224. "7": "EOF_IN_COMMENT",
  2225. "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
  2226. "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
  2227. "EOF_IN_TAG": 9,
  2228. "9": "EOF_IN_TAG",
  2229. "INCORRECTLY_CLOSED_COMMENT": 10,
  2230. "10": "INCORRECTLY_CLOSED_COMMENT",
  2231. "INCORRECTLY_OPENED_COMMENT": 11,
  2232. "11": "INCORRECTLY_OPENED_COMMENT",
  2233. "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
  2234. "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
  2235. "MISSING_ATTRIBUTE_VALUE": 13,
  2236. "13": "MISSING_ATTRIBUTE_VALUE",
  2237. "MISSING_END_TAG_NAME": 14,
  2238. "14": "MISSING_END_TAG_NAME",
  2239. "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
  2240. "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
  2241. "NESTED_COMMENT": 16,
  2242. "16": "NESTED_COMMENT",
  2243. "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
  2244. "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
  2245. "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
  2246. "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
  2247. "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
  2248. "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
  2249. "UNEXPECTED_NULL_CHARACTER": 20,
  2250. "20": "UNEXPECTED_NULL_CHARACTER",
  2251. "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
  2252. "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
  2253. "UNEXPECTED_SOLIDUS_IN_TAG": 22,
  2254. "22": "UNEXPECTED_SOLIDUS_IN_TAG",
  2255. "X_INVALID_END_TAG": 23,
  2256. "23": "X_INVALID_END_TAG",
  2257. "X_MISSING_END_TAG": 24,
  2258. "24": "X_MISSING_END_TAG",
  2259. "X_MISSING_INTERPOLATION_END": 25,
  2260. "25": "X_MISSING_INTERPOLATION_END",
  2261. "X_MISSING_DIRECTIVE_NAME": 26,
  2262. "26": "X_MISSING_DIRECTIVE_NAME",
  2263. "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
  2264. "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
  2265. "X_V_IF_NO_EXPRESSION": 28,
  2266. "28": "X_V_IF_NO_EXPRESSION",
  2267. "X_V_IF_SAME_KEY": 29,
  2268. "29": "X_V_IF_SAME_KEY",
  2269. "X_V_ELSE_NO_ADJACENT_IF": 30,
  2270. "30": "X_V_ELSE_NO_ADJACENT_IF",
  2271. "X_V_FOR_NO_EXPRESSION": 31,
  2272. "31": "X_V_FOR_NO_EXPRESSION",
  2273. "X_V_FOR_MALFORMED_EXPRESSION": 32,
  2274. "32": "X_V_FOR_MALFORMED_EXPRESSION",
  2275. "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
  2276. "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
  2277. "X_V_BIND_NO_EXPRESSION": 34,
  2278. "34": "X_V_BIND_NO_EXPRESSION",
  2279. "X_V_ON_NO_EXPRESSION": 35,
  2280. "35": "X_V_ON_NO_EXPRESSION",
  2281. "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
  2282. "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
  2283. "X_V_SLOT_MIXED_SLOT_USAGE": 37,
  2284. "37": "X_V_SLOT_MIXED_SLOT_USAGE",
  2285. "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
  2286. "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
  2287. "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
  2288. "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
  2289. "X_V_SLOT_MISPLACED": 40,
  2290. "40": "X_V_SLOT_MISPLACED",
  2291. "X_V_MODEL_NO_EXPRESSION": 41,
  2292. "41": "X_V_MODEL_NO_EXPRESSION",
  2293. "X_V_MODEL_MALFORMED_EXPRESSION": 42,
  2294. "42": "X_V_MODEL_MALFORMED_EXPRESSION",
  2295. "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
  2296. "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
  2297. "X_V_MODEL_ON_PROPS": 44,
  2298. "44": "X_V_MODEL_ON_PROPS",
  2299. "X_INVALID_EXPRESSION": 45,
  2300. "45": "X_INVALID_EXPRESSION",
  2301. "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
  2302. "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
  2303. "X_PREFIX_ID_NOT_SUPPORTED": 47,
  2304. "47": "X_PREFIX_ID_NOT_SUPPORTED",
  2305. "X_MODULE_MODE_NOT_SUPPORTED": 48,
  2306. "48": "X_MODULE_MODE_NOT_SUPPORTED",
  2307. "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
  2308. "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
  2309. "X_SCOPE_ID_NOT_SUPPORTED": 50,
  2310. "50": "X_SCOPE_ID_NOT_SUPPORTED",
  2311. "X_VNODE_HOOKS": 51,
  2312. "51": "X_VNODE_HOOKS",
  2313. "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
  2314. "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
  2315. "__EXTEND_POINT__": 53,
  2316. "53": "__EXTEND_POINT__"
  2317. };
  2318. const errorMessages$1 = {
  2319. // parse errors
  2320. [0]: "Illegal comment.",
  2321. [1]: "CDATA section is allowed only in XML context.",
  2322. [2]: "Duplicate attribute.",
  2323. [3]: "End tag cannot have attributes.",
  2324. [4]: "Illegal '/' in tags.",
  2325. [5]: "Unexpected EOF in tag.",
  2326. [6]: "Unexpected EOF in CDATA section.",
  2327. [7]: "Unexpected EOF in comment.",
  2328. [8]: "Unexpected EOF in script.",
  2329. [9]: "Unexpected EOF in tag.",
  2330. [10]: "Incorrectly closed comment.",
  2331. [11]: "Incorrectly opened comment.",
  2332. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  2333. [13]: "Attribute value was expected.",
  2334. [14]: "End tag name was expected.",
  2335. [15]: "Whitespace was expected.",
  2336. [16]: "Unexpected '<!--' in comment.",
  2337. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  2338. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  2339. [19]: "Attribute name cannot start with '='.",
  2340. [21]: "'<?' is allowed only in XML context.",
  2341. [20]: `Unexpected null character.`,
  2342. [22]: "Illegal '/' in tags.",
  2343. // Vue-specific parse errors
  2344. [23]: "Invalid end tag.",
  2345. [24]: "Element is missing end tag.",
  2346. [25]: "Interpolation end sign was not found.",
  2347. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  2348. [26]: "Legal directive name was expected.",
  2349. // transform errors
  2350. [28]: `v-if/v-else-if is missing expression.`,
  2351. [29]: `v-if/else branches must use unique keys.`,
  2352. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  2353. [31]: `v-for is missing expression.`,
  2354. [32]: `v-for has invalid expression.`,
  2355. [33]: `<template v-for> key should be placed on the <template> tag.`,
  2356. [34]: `v-bind is missing expression.`,
  2357. [52]: `v-bind with same-name shorthand only allows static argument.`,
  2358. [35]: `v-on is missing expression.`,
  2359. [36]: `Unexpected custom directive on <slot> outlet.`,
  2360. [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.`,
  2361. [38]: `Duplicate slot names found. `,
  2362. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  2363. [40]: `v-slot can only be used on components or <template> tags.`,
  2364. [41]: `v-model is missing expression.`,
  2365. [42]: `v-model value must be a valid JavaScript member expression.`,
  2366. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  2367. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  2368. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  2369. [45]: `Error parsing JavaScript expression: `,
  2370. [46]: `<KeepAlive> expects exactly one child component.`,
  2371. [51]: `@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.`,
  2372. // generic errors
  2373. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  2374. [48]: `ES module mode is not supported in this build of compiler.`,
  2375. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  2376. [50]: `"scopeId" option is only supported in module mode.`,
  2377. // just to fulfill types
  2378. [53]: ``
  2379. };
  2380. function getDefaultExportFromCjs (x) {
  2381. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  2382. }
  2383. function getAugmentedNamespace(n) {
  2384. if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
  2385. var f = n.default;
  2386. if (typeof f == "function") {
  2387. var a = function a () {
  2388. var isInstance = false;
  2389. try {
  2390. isInstance = this instanceof a;
  2391. } catch {}
  2392. if (isInstance) {
  2393. return Reflect.construct(f, arguments, this.constructor);
  2394. }
  2395. return f.apply(this, arguments);
  2396. };
  2397. a.prototype = f.prototype;
  2398. } else a = {};
  2399. Object.defineProperty(a, '__esModule', {value: true});
  2400. Object.keys(n).forEach(function (k) {
  2401. var d = Object.getOwnPropertyDescriptor(n, k);
  2402. Object.defineProperty(a, k, d.get ? d : {
  2403. enumerable: true,
  2404. get: function () {
  2405. return n[k];
  2406. }
  2407. });
  2408. });
  2409. return a;
  2410. }
  2411. var lib = {};
  2412. var hasRequiredLib;
  2413. function requireLib () {
  2414. if (hasRequiredLib) return lib;
  2415. hasRequiredLib = 1;
  2416. Object.defineProperty(lib, '__esModule', {
  2417. value: true
  2418. });
  2419. function _objectWithoutPropertiesLoose(r, e) {
  2420. if (null == r) return {};
  2421. var t = {};
  2422. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  2423. if (-1 !== e.indexOf(n)) continue;
  2424. t[n] = r[n];
  2425. }
  2426. return t;
  2427. }
  2428. class Position {
  2429. constructor(line, col, index) {
  2430. this.line = void 0;
  2431. this.column = void 0;
  2432. this.index = void 0;
  2433. this.line = line;
  2434. this.column = col;
  2435. this.index = index;
  2436. }
  2437. }
  2438. class SourceLocation {
  2439. constructor(start, end) {
  2440. this.start = void 0;
  2441. this.end = void 0;
  2442. this.filename = void 0;
  2443. this.identifierName = void 0;
  2444. this.start = start;
  2445. this.end = end;
  2446. }
  2447. }
  2448. function createPositionWithColumnOffset(position, columnOffset) {
  2449. const {
  2450. line,
  2451. column,
  2452. index
  2453. } = position;
  2454. return new Position(line, column + columnOffset, index + columnOffset);
  2455. }
  2456. const code = "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED";
  2457. var ModuleErrors = {
  2458. ImportMetaOutsideModule: {
  2459. message: `import.meta may appear only with 'sourceType: "module"'`,
  2460. code
  2461. },
  2462. ImportOutsideModule: {
  2463. message: `'import' and 'export' may appear only with 'sourceType: "module"'`,
  2464. code
  2465. }
  2466. };
  2467. const NodeDescriptions = {
  2468. ArrayPattern: "array destructuring pattern",
  2469. AssignmentExpression: "assignment expression",
  2470. AssignmentPattern: "assignment expression",
  2471. ArrowFunctionExpression: "arrow function expression",
  2472. ConditionalExpression: "conditional expression",
  2473. CatchClause: "catch clause",
  2474. ForOfStatement: "for-of statement",
  2475. ForInStatement: "for-in statement",
  2476. ForStatement: "for-loop",
  2477. FormalParameters: "function parameter list",
  2478. Identifier: "identifier",
  2479. ImportSpecifier: "import specifier",
  2480. ImportDefaultSpecifier: "import default specifier",
  2481. ImportNamespaceSpecifier: "import namespace specifier",
  2482. ObjectPattern: "object destructuring pattern",
  2483. ParenthesizedExpression: "parenthesized expression",
  2484. RestElement: "rest element",
  2485. UpdateExpression: {
  2486. true: "prefix operation",
  2487. false: "postfix operation"
  2488. },
  2489. VariableDeclarator: "variable declaration",
  2490. YieldExpression: "yield expression"
  2491. };
  2492. const toNodeDescription = node => node.type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[`${node.prefix}`] : NodeDescriptions[node.type];
  2493. var StandardErrors = {
  2494. AccessorIsGenerator: ({
  2495. kind
  2496. }) => `A ${kind}ter cannot be a generator.`,
  2497. ArgumentsInClass: "'arguments' is only allowed in functions and class methods.",
  2498. AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.",
  2499. AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.",
  2500. AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.",
  2501. AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.",
  2502. AwaitUsingNotInAsyncContext: "'await using' is only allowed within async functions and at the top levels of modules.",
  2503. AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.",
  2504. BadGetterArity: "A 'get' accessor must not have any formal parameters.",
  2505. BadSetterArity: "A 'set' accessor must have exactly one formal parameter.",
  2506. BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.",
  2507. ConstructorClassField: "Classes may not have a field named 'constructor'.",
  2508. ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.",
  2509. ConstructorIsAccessor: "Class constructor may not be an accessor.",
  2510. ConstructorIsAsync: "Constructor can't be an async function.",
  2511. ConstructorIsGenerator: "Constructor can't be a generator.",
  2512. DeclarationMissingInitializer: ({
  2513. kind
  2514. }) => `Missing initializer in ${kind} declaration.`,
  2515. DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.",
  2516. DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.",
  2517. DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.",
  2518. DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?",
  2519. DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.",
  2520. DecoratorSemicolon: "Decorators must not be followed by a semicolon.",
  2521. DecoratorStaticBlock: "Decorators can't be used with a static block.",
  2522. DeferImportRequiresNamespace: 'Only `import defer * as x from "./module"` is valid.',
  2523. DeletePrivateField: "Deleting a private field is not allowed.",
  2524. DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.",
  2525. DuplicateConstructor: "Duplicate constructor in the same class.",
  2526. DuplicateDefaultExport: "Only one default export allowed per module.",
  2527. DuplicateExport: ({
  2528. exportName
  2529. }) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`,
  2530. DuplicateProto: "Redefinition of __proto__ property.",
  2531. DuplicateRegExpFlags: "Duplicate regular expression flag.",
  2532. ElementAfterRest: "Rest element must be last element.",
  2533. EscapedCharNotAnIdentifier: "Invalid Unicode escape.",
  2534. ExportBindingIsString: ({
  2535. localName,
  2536. exportName
  2537. }) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`,
  2538. ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.",
  2539. ForInOfLoopInitializer: ({
  2540. type
  2541. }) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`,
  2542. ForInUsing: "For-in loop may not start with 'using' declaration.",
  2543. ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.",
  2544. ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.",
  2545. GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.",
  2546. IllegalBreakContinue: ({
  2547. type
  2548. }) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`,
  2549. IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.",
  2550. IllegalReturn: "'return' outside of function.",
  2551. 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.",
  2552. ImportBindingIsString: ({
  2553. importName
  2554. }) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`,
  2555. ImportCallArity: `\`import()\` requires exactly one or two arguments.`,
  2556. ImportCallNotNewExpression: "Cannot use new with import(...).",
  2557. ImportCallSpreadArgument: "`...` is not allowed in `import()`.",
  2558. ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.",
  2559. ImportReflectionHasAssertion: "`import module x` cannot have assertions.",
  2560. ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.',
  2561. IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.",
  2562. InvalidBigIntLiteral: "Invalid BigIntLiteral.",
  2563. InvalidCodePoint: "Code point out of bounds.",
  2564. InvalidCoverDiscardElement: "'void' must be followed by an expression when not used in a binding position.",
  2565. InvalidCoverInitializedName: "Invalid shorthand property initializer.",
  2566. InvalidDecimal: "Invalid decimal.",
  2567. InvalidDigit: ({
  2568. radix
  2569. }) => `Expected number in radix ${radix}.`,
  2570. InvalidEscapeSequence: "Bad character escape sequence.",
  2571. InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.",
  2572. InvalidEscapedReservedWord: ({
  2573. reservedWord
  2574. }) => `Escape sequence in keyword ${reservedWord}.`,
  2575. InvalidIdentifier: ({
  2576. identifierName
  2577. }) => `Invalid identifier ${identifierName}.`,
  2578. InvalidLhs: ({
  2579. ancestor
  2580. }) => `Invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  2581. InvalidLhsBinding: ({
  2582. ancestor
  2583. }) => `Binding invalid left-hand side in ${toNodeDescription(ancestor)}.`,
  2584. InvalidLhsOptionalChaining: ({
  2585. ancestor
  2586. }) => `Invalid optional chaining in the left-hand side of ${toNodeDescription(ancestor)}.`,
  2587. InvalidNumber: "Invalid number.",
  2588. InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.",
  2589. InvalidOrUnexpectedToken: ({
  2590. unexpected
  2591. }) => `Unexpected character '${unexpected}'.`,
  2592. InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.",
  2593. InvalidPrivateFieldResolution: ({
  2594. identifierName
  2595. }) => `Private name #${identifierName} is not defined.`,
  2596. InvalidPropertyBindingPattern: "Binding member expression.",
  2597. InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.",
  2598. InvalidRestAssignmentPattern: "Invalid rest operator's argument.",
  2599. LabelRedeclaration: ({
  2600. labelName
  2601. }) => `Label '${labelName}' is already declared.`,
  2602. LetInLexicalBinding: "'let' is disallowed as a lexically bound name.",
  2603. LineTerminatorBeforeArrow: "No line break is allowed before '=>'.",
  2604. MalformedRegExpFlags: "Invalid regular expression flag.",
  2605. MissingClassName: "A class name is required.",
  2606. MissingEqInAssignment: "Only '=' operator can be used for specifying default value.",
  2607. MissingSemicolon: "Missing semicolon.",
  2608. MissingPlugin: ({
  2609. missingPlugin
  2610. }) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  2611. MissingOneOfPlugins: ({
  2612. missingPlugin
  2613. }) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`,
  2614. MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.",
  2615. MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.",
  2616. ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.",
  2617. ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.",
  2618. ModuleAttributesWithDuplicateKeys: ({
  2619. key
  2620. }) => `Duplicate key "${key}" is not allowed in module attributes.`,
  2621. ModuleExportNameHasLoneSurrogate: ({
  2622. surrogateCharCode
  2623. }) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`,
  2624. ModuleExportUndefined: ({
  2625. localName
  2626. }) => `Export '${localName}' is not defined.`,
  2627. MultipleDefaultsInSwitch: "Multiple default clauses.",
  2628. NewlineAfterThrow: "Illegal newline after throw.",
  2629. NoCatchOrFinally: "Missing catch or finally clause.",
  2630. NumberIdentifier: "Identifier directly after number.",
  2631. NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.",
  2632. ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.",
  2633. OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.",
  2634. OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.",
  2635. OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.",
  2636. ParamDupe: "Argument name clash.",
  2637. PatternHasAccessor: "Object pattern can't contain getter or setter.",
  2638. PatternHasMethod: "Object pattern can't contain methods.",
  2639. PrivateInExpectedIn: ({
  2640. identifierName
  2641. }) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`,
  2642. PrivateNameRedeclaration: ({
  2643. identifierName
  2644. }) => `Duplicate private name #${identifierName}.`,
  2645. RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  2646. RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  2647. RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  2648. RecordNoProto: "'__proto__' is not allowed in Record expressions.",
  2649. RestTrailingComma: "Unexpected trailing comma after rest element.",
  2650. SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.",
  2651. 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.",
  2652. SourcePhaseImportRequiresDefault: 'Only `import source x from "./module"` is valid.',
  2653. StaticPrototype: "Classes may not have static property named prototype.",
  2654. 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?",
  2655. SuperPrivateField: "Private fields can't be accessed on super.",
  2656. TrailingDecorator: "Decorators must be attached to a class element.",
  2657. TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  2658. TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.",
  2659. TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.",
  2660. UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.",
  2661. UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.',
  2662. UnexpectedDigitAfterHash: "Unexpected digit after hash token.",
  2663. UnexpectedImportExport: "'import' and 'export' may only appear at the top level.",
  2664. UnexpectedKeyword: ({
  2665. keyword
  2666. }) => `Unexpected keyword '${keyword}'.`,
  2667. UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.",
  2668. UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.",
  2669. UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.",
  2670. UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.",
  2671. UnexpectedPrivateField: "Unexpected private name.",
  2672. UnexpectedReservedWord: ({
  2673. reservedWord
  2674. }) => `Unexpected reserved word '${reservedWord}'.`,
  2675. UnexpectedSuper: "'super' is only allowed in object methods and classes.",
  2676. UnexpectedToken: ({
  2677. expected,
  2678. unexpected
  2679. }) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`,
  2680. UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
  2681. UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement.",
  2682. UnexpectedVoidPattern: "Unexpected void binding.",
  2683. UnsupportedBind: "Binding should be performed on object property.",
  2684. UnsupportedDecoratorExport: "A decorated export must export a class declaration.",
  2685. UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.",
  2686. UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.",
  2687. UnsupportedMetaProperty: ({
  2688. target,
  2689. onlyValidPropertyName
  2690. }) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`,
  2691. UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.",
  2692. UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.",
  2693. UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).",
  2694. UnterminatedComment: "Unterminated comment.",
  2695. UnterminatedRegExp: "Unterminated regular expression.",
  2696. UnterminatedString: "Unterminated string constant.",
  2697. UnterminatedTemplate: "Unterminated template.",
  2698. UsingDeclarationExport: "Using declaration cannot be exported.",
  2699. UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.",
  2700. VarRedeclaration: ({
  2701. identifierName
  2702. }) => `Identifier '${identifierName}' has already been declared.`,
  2703. VoidPatternCatchClauseParam: "A void binding can not be the catch clause parameter. Use `try { ... } catch { ... }` if you want to discard the caught error.",
  2704. VoidPatternInitializer: "A void binding may not have an initializer.",
  2705. YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.",
  2706. YieldInParameter: "Yield expression is not allowed in formal parameters.",
  2707. YieldNotInGeneratorFunction: "'yield' is only allowed within generator functions.",
  2708. ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0."
  2709. };
  2710. var StrictModeErrors = {
  2711. StrictDelete: "Deleting local variable in strict mode.",
  2712. StrictEvalArguments: ({
  2713. referenceName
  2714. }) => `Assigning to '${referenceName}' in strict mode.`,
  2715. StrictEvalArgumentsBinding: ({
  2716. bindingName
  2717. }) => `Binding '${bindingName}' in strict mode.`,
  2718. StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.",
  2719. StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.",
  2720. StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.",
  2721. StrictWith: "'with' in strict mode."
  2722. };
  2723. var ParseExpressionErrors = {
  2724. ParseExpressionEmptyInput: "Unexpected parseExpression() input: The input is empty or contains only comments.",
  2725. ParseExpressionExpectsEOF: ({
  2726. unexpected
  2727. }) => `Unexpected parseExpression() input: The input should contain exactly one expression, but the first expression is followed by the unexpected character \`${String.fromCodePoint(unexpected)}\`.`
  2728. };
  2729. const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]);
  2730. var PipelineOperatorErrors = Object.assign({
  2731. PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",
  2732. PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
  2733. PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.",
  2734. PipeTopicUnconfiguredToken: ({
  2735. token
  2736. }) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`,
  2737. PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",
  2738. PipeUnparenthesizedBody: ({
  2739. type
  2740. }) => `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({
  2741. type
  2742. })}; please wrap it in parentheses.`
  2743. }, {
  2744. PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
  2745. PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.",
  2746. PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.",
  2747. PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.",
  2748. PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.",
  2749. PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.'
  2750. });
  2751. const _excluded = ["message"];
  2752. function defineHidden(obj, key, value) {
  2753. Object.defineProperty(obj, key, {
  2754. enumerable: false,
  2755. configurable: true,
  2756. value
  2757. });
  2758. }
  2759. function toParseErrorConstructor({
  2760. toMessage,
  2761. code,
  2762. reasonCode,
  2763. syntaxPlugin
  2764. }) {
  2765. const hasMissingPlugin = reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins";
  2766. {
  2767. const oldReasonCodes = {
  2768. AccessorCannotDeclareThisParameter: "AccesorCannotDeclareThisParameter",
  2769. AccessorCannotHaveTypeParameters: "AccesorCannotHaveTypeParameters",
  2770. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference",
  2771. SetAccessorCannotHaveOptionalParameter: "SetAccesorCannotHaveOptionalParameter",
  2772. SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
  2773. SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType"
  2774. };
  2775. if (oldReasonCodes[reasonCode]) {
  2776. reasonCode = oldReasonCodes[reasonCode];
  2777. }
  2778. }
  2779. return function constructor(loc, details) {
  2780. const error = new SyntaxError();
  2781. error.code = code;
  2782. error.reasonCode = reasonCode;
  2783. error.loc = loc;
  2784. error.pos = loc.index;
  2785. error.syntaxPlugin = syntaxPlugin;
  2786. if (hasMissingPlugin) {
  2787. error.missingPlugin = details.missingPlugin;
  2788. }
  2789. defineHidden(error, "clone", function clone(overrides = {}) {
  2790. var _overrides$loc;
  2791. const {
  2792. line,
  2793. column,
  2794. index
  2795. } = (_overrides$loc = overrides.loc) != null ? _overrides$loc : loc;
  2796. return constructor(new Position(line, column, index), Object.assign({}, details, overrides.details));
  2797. });
  2798. defineHidden(error, "details", details);
  2799. Object.defineProperty(error, "message", {
  2800. configurable: true,
  2801. get() {
  2802. const message = `${toMessage(details)} (${loc.line}:${loc.column})`;
  2803. this.message = message;
  2804. return message;
  2805. },
  2806. set(value) {
  2807. Object.defineProperty(this, "message", {
  2808. value,
  2809. writable: true
  2810. });
  2811. }
  2812. });
  2813. return error;
  2814. };
  2815. }
  2816. function ParseErrorEnum(argument, syntaxPlugin) {
  2817. if (Array.isArray(argument)) {
  2818. return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]);
  2819. }
  2820. const ParseErrorConstructors = {};
  2821. for (const reasonCode of Object.keys(argument)) {
  2822. const template = argument[reasonCode];
  2823. const _ref = typeof template === "string" ? {
  2824. message: () => template
  2825. } : typeof template === "function" ? {
  2826. message: template
  2827. } : template,
  2828. {
  2829. message
  2830. } = _ref,
  2831. rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  2832. const toMessage = typeof message === "string" ? () => message : message;
  2833. ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({
  2834. code: "BABEL_PARSER_SYNTAX_ERROR",
  2835. reasonCode,
  2836. toMessage
  2837. }, syntaxPlugin ? {
  2838. syntaxPlugin
  2839. } : {}, rest));
  2840. }
  2841. return ParseErrorConstructors;
  2842. }
  2843. const Errors = Object.assign({}, ParseErrorEnum(ModuleErrors), ParseErrorEnum(StandardErrors), ParseErrorEnum(StrictModeErrors), ParseErrorEnum(ParseExpressionErrors), ParseErrorEnum`pipelineOperator`(PipelineOperatorErrors));
  2844. function createDefaultOptions() {
  2845. return {
  2846. sourceType: "script",
  2847. sourceFilename: undefined,
  2848. startIndex: 0,
  2849. startColumn: 0,
  2850. startLine: 1,
  2851. allowAwaitOutsideFunction: false,
  2852. allowReturnOutsideFunction: false,
  2853. allowNewTargetOutsideFunction: false,
  2854. allowImportExportEverywhere: false,
  2855. allowSuperOutsideMethod: false,
  2856. allowUndeclaredExports: false,
  2857. allowYieldOutsideFunction: false,
  2858. plugins: [],
  2859. strictMode: null,
  2860. ranges: false,
  2861. tokens: false,
  2862. createImportExpressions: false,
  2863. createParenthesizedExpressions: false,
  2864. errorRecovery: false,
  2865. attachComment: true,
  2866. annexB: true
  2867. };
  2868. }
  2869. function getOptions(opts) {
  2870. const options = createDefaultOptions();
  2871. if (opts == null) {
  2872. return options;
  2873. }
  2874. if (opts.annexB != null && opts.annexB !== false) {
  2875. throw new Error("The `annexB` option can only be set to `false`.");
  2876. }
  2877. for (const key of Object.keys(options)) {
  2878. if (opts[key] != null) options[key] = opts[key];
  2879. }
  2880. if (options.startLine === 1) {
  2881. if (opts.startIndex == null && options.startColumn > 0) {
  2882. options.startIndex = options.startColumn;
  2883. } else if (opts.startColumn == null && options.startIndex > 0) {
  2884. options.startColumn = options.startIndex;
  2885. }
  2886. } else if (opts.startColumn == null || opts.startIndex == null) {
  2887. if (opts.startIndex != null) {
  2888. throw new Error("With a `startLine > 1` you must also specify `startIndex` and `startColumn`.");
  2889. }
  2890. }
  2891. if (options.sourceType === "commonjs") {
  2892. if (opts.allowAwaitOutsideFunction != null) {
  2893. throw new Error("The `allowAwaitOutsideFunction` option cannot be used with `sourceType: 'commonjs'`.");
  2894. }
  2895. if (opts.allowReturnOutsideFunction != null) {
  2896. throw new Error("`sourceType: 'commonjs'` implies `allowReturnOutsideFunction: true`, please remove the `allowReturnOutsideFunction` option or use `sourceType: 'script'`.");
  2897. }
  2898. if (opts.allowNewTargetOutsideFunction != null) {
  2899. throw new Error("`sourceType: 'commonjs'` implies `allowNewTargetOutsideFunction: true`, please remove the `allowNewTargetOutsideFunction` option or use `sourceType: 'script'`.");
  2900. }
  2901. }
  2902. return options;
  2903. }
  2904. const {
  2905. defineProperty
  2906. } = Object;
  2907. const toUnenumerable = (object, key) => {
  2908. if (object) {
  2909. defineProperty(object, key, {
  2910. enumerable: false,
  2911. value: object[key]
  2912. });
  2913. }
  2914. };
  2915. function toESTreeLocation(node) {
  2916. toUnenumerable(node.loc.start, "index");
  2917. toUnenumerable(node.loc.end, "index");
  2918. return node;
  2919. }
  2920. var estree = superClass => class ESTreeParserMixin extends superClass {
  2921. parse() {
  2922. const file = toESTreeLocation(super.parse());
  2923. if (this.optionFlags & 256) {
  2924. file.tokens = file.tokens.map(toESTreeLocation);
  2925. }
  2926. return file;
  2927. }
  2928. parseRegExpLiteral({
  2929. pattern,
  2930. flags
  2931. }) {
  2932. let regex = null;
  2933. try {
  2934. regex = new RegExp(pattern, flags);
  2935. } catch (_) {}
  2936. const node = this.estreeParseLiteral(regex);
  2937. node.regex = {
  2938. pattern,
  2939. flags
  2940. };
  2941. return node;
  2942. }
  2943. parseBigIntLiteral(value) {
  2944. let bigInt;
  2945. try {
  2946. bigInt = BigInt(value);
  2947. } catch (_unused) {
  2948. bigInt = null;
  2949. }
  2950. const node = this.estreeParseLiteral(bigInt);
  2951. node.bigint = String(node.value || value);
  2952. return node;
  2953. }
  2954. parseDecimalLiteral(value) {
  2955. const decimal = null;
  2956. const node = this.estreeParseLiteral(decimal);
  2957. node.decimal = String(node.value || value);
  2958. return node;
  2959. }
  2960. estreeParseLiteral(value) {
  2961. return this.parseLiteral(value, "Literal");
  2962. }
  2963. parseStringLiteral(value) {
  2964. return this.estreeParseLiteral(value);
  2965. }
  2966. parseNumericLiteral(value) {
  2967. return this.estreeParseLiteral(value);
  2968. }
  2969. parseNullLiteral() {
  2970. return this.estreeParseLiteral(null);
  2971. }
  2972. parseBooleanLiteral(value) {
  2973. return this.estreeParseLiteral(value);
  2974. }
  2975. estreeParseChainExpression(node, endLoc) {
  2976. const chain = this.startNodeAtNode(node);
  2977. chain.expression = node;
  2978. return this.finishNodeAt(chain, "ChainExpression", endLoc);
  2979. }
  2980. directiveToStmt(directive) {
  2981. const expression = directive.value;
  2982. delete directive.value;
  2983. this.castNodeTo(expression, "Literal");
  2984. expression.raw = expression.extra.raw;
  2985. expression.value = expression.extra.expressionValue;
  2986. const stmt = this.castNodeTo(directive, "ExpressionStatement");
  2987. stmt.expression = expression;
  2988. stmt.directive = expression.extra.rawValue;
  2989. delete expression.extra;
  2990. return stmt;
  2991. }
  2992. fillOptionalPropertiesForTSESLint(node) {}
  2993. cloneEstreeStringLiteral(node) {
  2994. const {
  2995. start,
  2996. end,
  2997. loc,
  2998. range,
  2999. raw,
  3000. value
  3001. } = node;
  3002. const cloned = Object.create(node.constructor.prototype);
  3003. cloned.type = "Literal";
  3004. cloned.start = start;
  3005. cloned.end = end;
  3006. cloned.loc = loc;
  3007. cloned.range = range;
  3008. cloned.raw = raw;
  3009. cloned.value = value;
  3010. return cloned;
  3011. }
  3012. initFunction(node, isAsync) {
  3013. super.initFunction(node, isAsync);
  3014. node.expression = false;
  3015. }
  3016. checkDeclaration(node) {
  3017. if (node != null && this.isObjectProperty(node)) {
  3018. this.checkDeclaration(node.value);
  3019. } else {
  3020. super.checkDeclaration(node);
  3021. }
  3022. }
  3023. getObjectOrClassMethodParams(method) {
  3024. return method.value.params;
  3025. }
  3026. isValidDirective(stmt) {
  3027. var _stmt$expression$extr;
  3028. return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized);
  3029. }
  3030. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  3031. super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
  3032. const directiveStatements = node.directives.map(d => this.directiveToStmt(d));
  3033. node.body = directiveStatements.concat(node.body);
  3034. delete node.directives;
  3035. }
  3036. parsePrivateName() {
  3037. const node = super.parsePrivateName();
  3038. {
  3039. if (!this.getPluginOption("estree", "classFeatures")) {
  3040. return node;
  3041. }
  3042. }
  3043. return this.convertPrivateNameToPrivateIdentifier(node);
  3044. }
  3045. convertPrivateNameToPrivateIdentifier(node) {
  3046. const name = super.getPrivateNameSV(node);
  3047. node = node;
  3048. delete node.id;
  3049. node.name = name;
  3050. return this.castNodeTo(node, "PrivateIdentifier");
  3051. }
  3052. isPrivateName(node) {
  3053. {
  3054. if (!this.getPluginOption("estree", "classFeatures")) {
  3055. return super.isPrivateName(node);
  3056. }
  3057. }
  3058. return node.type === "PrivateIdentifier";
  3059. }
  3060. getPrivateNameSV(node) {
  3061. {
  3062. if (!this.getPluginOption("estree", "classFeatures")) {
  3063. return super.getPrivateNameSV(node);
  3064. }
  3065. }
  3066. return node.name;
  3067. }
  3068. parseLiteral(value, type) {
  3069. const node = super.parseLiteral(value, type);
  3070. node.raw = node.extra.raw;
  3071. delete node.extra;
  3072. return node;
  3073. }
  3074. parseFunctionBody(node, allowExpression, isMethod = false) {
  3075. super.parseFunctionBody(node, allowExpression, isMethod);
  3076. node.expression = node.body.type !== "BlockStatement";
  3077. }
  3078. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  3079. let funcNode = this.startNode();
  3080. funcNode.kind = node.kind;
  3081. funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  3082. delete funcNode.kind;
  3083. const {
  3084. typeParameters
  3085. } = node;
  3086. if (typeParameters) {
  3087. delete node.typeParameters;
  3088. funcNode.typeParameters = typeParameters;
  3089. this.resetStartLocationFromNode(funcNode, typeParameters);
  3090. }
  3091. const valueNode = this.castNodeTo(funcNode, "FunctionExpression");
  3092. node.value = valueNode;
  3093. if (type === "ClassPrivateMethod") {
  3094. node.computed = false;
  3095. }
  3096. if (type === "ObjectMethod") {
  3097. if (node.kind === "method") {
  3098. node.kind = "init";
  3099. }
  3100. node.shorthand = false;
  3101. return this.finishNode(node, "Property");
  3102. } else {
  3103. return this.finishNode(node, "MethodDefinition");
  3104. }
  3105. }
  3106. nameIsConstructor(key) {
  3107. if (key.type === "Literal") return key.value === "constructor";
  3108. return super.nameIsConstructor(key);
  3109. }
  3110. parseClassProperty(...args) {
  3111. const propertyNode = super.parseClassProperty(...args);
  3112. {
  3113. if (!this.getPluginOption("estree", "classFeatures")) {
  3114. return propertyNode;
  3115. }
  3116. }
  3117. {
  3118. this.castNodeTo(propertyNode, "PropertyDefinition");
  3119. }
  3120. return propertyNode;
  3121. }
  3122. parseClassPrivateProperty(...args) {
  3123. const propertyNode = super.parseClassPrivateProperty(...args);
  3124. {
  3125. if (!this.getPluginOption("estree", "classFeatures")) {
  3126. return propertyNode;
  3127. }
  3128. }
  3129. {
  3130. this.castNodeTo(propertyNode, "PropertyDefinition");
  3131. }
  3132. propertyNode.computed = false;
  3133. return propertyNode;
  3134. }
  3135. parseClassAccessorProperty(node) {
  3136. const accessorPropertyNode = super.parseClassAccessorProperty(node);
  3137. {
  3138. if (!this.getPluginOption("estree", "classFeatures")) {
  3139. return accessorPropertyNode;
  3140. }
  3141. }
  3142. if (accessorPropertyNode.abstract && this.hasPlugin("typescript")) {
  3143. delete accessorPropertyNode.abstract;
  3144. this.castNodeTo(accessorPropertyNode, "TSAbstractAccessorProperty");
  3145. } else {
  3146. this.castNodeTo(accessorPropertyNode, "AccessorProperty");
  3147. }
  3148. return accessorPropertyNode;
  3149. }
  3150. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  3151. const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  3152. if (node) {
  3153. node.kind = "init";
  3154. this.castNodeTo(node, "Property");
  3155. }
  3156. return node;
  3157. }
  3158. finishObjectProperty(node) {
  3159. node.kind = "init";
  3160. return this.finishNode(node, "Property");
  3161. }
  3162. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  3163. return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  3164. }
  3165. isAssignable(node, isBinding) {
  3166. if (node != null && this.isObjectProperty(node)) {
  3167. return this.isAssignable(node.value, isBinding);
  3168. }
  3169. return super.isAssignable(node, isBinding);
  3170. }
  3171. toAssignable(node, isLHS = false) {
  3172. if (node != null && this.isObjectProperty(node)) {
  3173. const {
  3174. key,
  3175. value
  3176. } = node;
  3177. if (this.isPrivateName(key)) {
  3178. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  3179. }
  3180. this.toAssignable(value, isLHS);
  3181. } else {
  3182. super.toAssignable(node, isLHS);
  3183. }
  3184. }
  3185. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  3186. if (prop.type === "Property" && (prop.kind === "get" || prop.kind === "set")) {
  3187. this.raise(Errors.PatternHasAccessor, prop.key);
  3188. } else if (prop.type === "Property" && prop.method) {
  3189. this.raise(Errors.PatternHasMethod, prop.key);
  3190. } else {
  3191. super.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  3192. }
  3193. }
  3194. finishCallExpression(unfinished, optional) {
  3195. const node = super.finishCallExpression(unfinished, optional);
  3196. if (node.callee.type === "Import") {
  3197. var _ref;
  3198. this.castNodeTo(node, "ImportExpression");
  3199. node.source = node.arguments[0];
  3200. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  3201. {
  3202. var _ref2;
  3203. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  3204. }
  3205. delete node.arguments;
  3206. delete node.callee;
  3207. } else if (node.type === "OptionalCallExpression") {
  3208. this.castNodeTo(node, "CallExpression");
  3209. } else {
  3210. node.optional = false;
  3211. }
  3212. return node;
  3213. }
  3214. toReferencedArguments(node) {
  3215. if (node.type === "ImportExpression") {
  3216. return;
  3217. }
  3218. super.toReferencedArguments(node);
  3219. }
  3220. parseExport(unfinished, decorators) {
  3221. const exportStartLoc = this.state.lastTokStartLoc;
  3222. const node = super.parseExport(unfinished, decorators);
  3223. switch (node.type) {
  3224. case "ExportAllDeclaration":
  3225. node.exported = null;
  3226. break;
  3227. case "ExportNamedDeclaration":
  3228. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  3229. this.castNodeTo(node, "ExportAllDeclaration");
  3230. node.exported = node.specifiers[0].exported;
  3231. delete node.specifiers;
  3232. }
  3233. case "ExportDefaultDeclaration":
  3234. {
  3235. var _declaration$decorato;
  3236. const {
  3237. declaration
  3238. } = node;
  3239. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  3240. this.resetStartLocation(node, exportStartLoc);
  3241. }
  3242. }
  3243. break;
  3244. }
  3245. return node;
  3246. }
  3247. stopParseSubscript(base, state) {
  3248. const node = super.stopParseSubscript(base, state);
  3249. if (state.optionalChainMember) {
  3250. return this.estreeParseChainExpression(node, base.loc.end);
  3251. }
  3252. return node;
  3253. }
  3254. parseMember(base, startLoc, state, computed, optional) {
  3255. const node = super.parseMember(base, startLoc, state, computed, optional);
  3256. if (node.type === "OptionalMemberExpression") {
  3257. this.castNodeTo(node, "MemberExpression");
  3258. } else {
  3259. node.optional = false;
  3260. }
  3261. return node;
  3262. }
  3263. isOptionalMemberExpression(node) {
  3264. if (node.type === "ChainExpression") {
  3265. return node.expression.type === "MemberExpression";
  3266. }
  3267. return super.isOptionalMemberExpression(node);
  3268. }
  3269. hasPropertyAsPrivateName(node) {
  3270. if (node.type === "ChainExpression") {
  3271. node = node.expression;
  3272. }
  3273. return super.hasPropertyAsPrivateName(node);
  3274. }
  3275. isObjectProperty(node) {
  3276. return node.type === "Property" && node.kind === "init" && !node.method;
  3277. }
  3278. isObjectMethod(node) {
  3279. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  3280. }
  3281. castNodeTo(node, type) {
  3282. const result = super.castNodeTo(node, type);
  3283. this.fillOptionalPropertiesForTSESLint(result);
  3284. return result;
  3285. }
  3286. cloneIdentifier(node) {
  3287. const cloned = super.cloneIdentifier(node);
  3288. this.fillOptionalPropertiesForTSESLint(cloned);
  3289. return cloned;
  3290. }
  3291. cloneStringLiteral(node) {
  3292. if (node.type === "Literal") {
  3293. return this.cloneEstreeStringLiteral(node);
  3294. }
  3295. return super.cloneStringLiteral(node);
  3296. }
  3297. finishNodeAt(node, type, endLoc) {
  3298. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  3299. }
  3300. finishNode(node, type) {
  3301. const result = super.finishNode(node, type);
  3302. this.fillOptionalPropertiesForTSESLint(result);
  3303. return result;
  3304. }
  3305. resetStartLocation(node, startLoc) {
  3306. super.resetStartLocation(node, startLoc);
  3307. toESTreeLocation(node);
  3308. }
  3309. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3310. super.resetEndLocation(node, endLoc);
  3311. toESTreeLocation(node);
  3312. }
  3313. };
  3314. class TokContext {
  3315. constructor(token, preserveSpace) {
  3316. this.token = void 0;
  3317. this.preserveSpace = void 0;
  3318. this.token = token;
  3319. this.preserveSpace = !!preserveSpace;
  3320. }
  3321. }
  3322. const types = {
  3323. brace: new TokContext("{"),
  3324. j_oTag: new TokContext("<tag"),
  3325. j_cTag: new TokContext("</tag"),
  3326. j_expr: new TokContext("<tag>...</tag>", true)
  3327. };
  3328. {
  3329. types.template = new TokContext("`", true);
  3330. }
  3331. const beforeExpr = true;
  3332. const startsExpr = true;
  3333. const isLoop = true;
  3334. const isAssign = true;
  3335. const prefix = true;
  3336. const postfix = true;
  3337. class ExportedTokenType {
  3338. constructor(label, conf = {}) {
  3339. this.label = void 0;
  3340. this.keyword = void 0;
  3341. this.beforeExpr = void 0;
  3342. this.startsExpr = void 0;
  3343. this.rightAssociative = void 0;
  3344. this.isLoop = void 0;
  3345. this.isAssign = void 0;
  3346. this.prefix = void 0;
  3347. this.postfix = void 0;
  3348. this.binop = void 0;
  3349. this.label = label;
  3350. this.keyword = conf.keyword;
  3351. this.beforeExpr = !!conf.beforeExpr;
  3352. this.startsExpr = !!conf.startsExpr;
  3353. this.rightAssociative = !!conf.rightAssociative;
  3354. this.isLoop = !!conf.isLoop;
  3355. this.isAssign = !!conf.isAssign;
  3356. this.prefix = !!conf.prefix;
  3357. this.postfix = !!conf.postfix;
  3358. this.binop = conf.binop != null ? conf.binop : null;
  3359. {
  3360. this.updateContext = null;
  3361. }
  3362. }
  3363. }
  3364. const keywords$1 = new Map();
  3365. function createKeyword(name, options = {}) {
  3366. options.keyword = name;
  3367. const token = createToken(name, options);
  3368. keywords$1.set(name, token);
  3369. return token;
  3370. }
  3371. function createBinop(name, binop) {
  3372. return createToken(name, {
  3373. beforeExpr,
  3374. binop
  3375. });
  3376. }
  3377. let tokenTypeCounter = -1;
  3378. const tokenTypes = [];
  3379. const tokenLabels = [];
  3380. const tokenBinops = [];
  3381. const tokenBeforeExprs = [];
  3382. const tokenStartsExprs = [];
  3383. const tokenPrefixes = [];
  3384. function createToken(name, options = {}) {
  3385. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  3386. ++tokenTypeCounter;
  3387. tokenLabels.push(name);
  3388. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  3389. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  3390. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  3391. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  3392. tokenTypes.push(new ExportedTokenType(name, options));
  3393. return tokenTypeCounter;
  3394. }
  3395. function createKeywordLike(name, options = {}) {
  3396. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  3397. ++tokenTypeCounter;
  3398. keywords$1.set(name, tokenTypeCounter);
  3399. tokenLabels.push(name);
  3400. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  3401. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  3402. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  3403. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  3404. tokenTypes.push(new ExportedTokenType("name", options));
  3405. return tokenTypeCounter;
  3406. }
  3407. const tt = {
  3408. bracketL: createToken("[", {
  3409. beforeExpr,
  3410. startsExpr
  3411. }),
  3412. bracketHashL: createToken("#[", {
  3413. beforeExpr,
  3414. startsExpr
  3415. }),
  3416. bracketBarL: createToken("[|", {
  3417. beforeExpr,
  3418. startsExpr
  3419. }),
  3420. bracketR: createToken("]"),
  3421. bracketBarR: createToken("|]"),
  3422. braceL: createToken("{", {
  3423. beforeExpr,
  3424. startsExpr
  3425. }),
  3426. braceBarL: createToken("{|", {
  3427. beforeExpr,
  3428. startsExpr
  3429. }),
  3430. braceHashL: createToken("#{", {
  3431. beforeExpr,
  3432. startsExpr
  3433. }),
  3434. braceR: createToken("}"),
  3435. braceBarR: createToken("|}"),
  3436. parenL: createToken("(", {
  3437. beforeExpr,
  3438. startsExpr
  3439. }),
  3440. parenR: createToken(")"),
  3441. comma: createToken(",", {
  3442. beforeExpr
  3443. }),
  3444. semi: createToken(";", {
  3445. beforeExpr
  3446. }),
  3447. colon: createToken(":", {
  3448. beforeExpr
  3449. }),
  3450. doubleColon: createToken("::", {
  3451. beforeExpr
  3452. }),
  3453. dot: createToken("."),
  3454. question: createToken("?", {
  3455. beforeExpr
  3456. }),
  3457. questionDot: createToken("?."),
  3458. arrow: createToken("=>", {
  3459. beforeExpr
  3460. }),
  3461. template: createToken("template"),
  3462. ellipsis: createToken("...", {
  3463. beforeExpr
  3464. }),
  3465. backQuote: createToken("`", {
  3466. startsExpr
  3467. }),
  3468. dollarBraceL: createToken("${", {
  3469. beforeExpr,
  3470. startsExpr
  3471. }),
  3472. templateTail: createToken("...`", {
  3473. startsExpr
  3474. }),
  3475. templateNonTail: createToken("...${", {
  3476. beforeExpr,
  3477. startsExpr
  3478. }),
  3479. at: createToken("@"),
  3480. hash: createToken("#", {
  3481. startsExpr
  3482. }),
  3483. interpreterDirective: createToken("#!..."),
  3484. eq: createToken("=", {
  3485. beforeExpr,
  3486. isAssign
  3487. }),
  3488. assign: createToken("_=", {
  3489. beforeExpr,
  3490. isAssign
  3491. }),
  3492. slashAssign: createToken("_=", {
  3493. beforeExpr,
  3494. isAssign
  3495. }),
  3496. xorAssign: createToken("_=", {
  3497. beforeExpr,
  3498. isAssign
  3499. }),
  3500. moduloAssign: createToken("_=", {
  3501. beforeExpr,
  3502. isAssign
  3503. }),
  3504. incDec: createToken("++/--", {
  3505. prefix,
  3506. postfix,
  3507. startsExpr
  3508. }),
  3509. bang: createToken("!", {
  3510. beforeExpr,
  3511. prefix,
  3512. startsExpr
  3513. }),
  3514. tilde: createToken("~", {
  3515. beforeExpr,
  3516. prefix,
  3517. startsExpr
  3518. }),
  3519. doubleCaret: createToken("^^", {
  3520. startsExpr
  3521. }),
  3522. doubleAt: createToken("@@", {
  3523. startsExpr
  3524. }),
  3525. pipeline: createBinop("|>", 0),
  3526. nullishCoalescing: createBinop("??", 1),
  3527. logicalOR: createBinop("||", 1),
  3528. logicalAND: createBinop("&&", 2),
  3529. bitwiseOR: createBinop("|", 3),
  3530. bitwiseXOR: createBinop("^", 4),
  3531. bitwiseAND: createBinop("&", 5),
  3532. equality: createBinop("==/!=/===/!==", 6),
  3533. lt: createBinop("</>/<=/>=", 7),
  3534. gt: createBinop("</>/<=/>=", 7),
  3535. relational: createBinop("</>/<=/>=", 7),
  3536. bitShift: createBinop("<</>>/>>>", 8),
  3537. bitShiftL: createBinop("<</>>/>>>", 8),
  3538. bitShiftR: createBinop("<</>>/>>>", 8),
  3539. plusMin: createToken("+/-", {
  3540. beforeExpr,
  3541. binop: 9,
  3542. prefix,
  3543. startsExpr
  3544. }),
  3545. modulo: createToken("%", {
  3546. binop: 10,
  3547. startsExpr
  3548. }),
  3549. star: createToken("*", {
  3550. binop: 10
  3551. }),
  3552. slash: createBinop("/", 10),
  3553. exponent: createToken("**", {
  3554. beforeExpr,
  3555. binop: 11,
  3556. rightAssociative: true
  3557. }),
  3558. _in: createKeyword("in", {
  3559. beforeExpr,
  3560. binop: 7
  3561. }),
  3562. _instanceof: createKeyword("instanceof", {
  3563. beforeExpr,
  3564. binop: 7
  3565. }),
  3566. _break: createKeyword("break"),
  3567. _case: createKeyword("case", {
  3568. beforeExpr
  3569. }),
  3570. _catch: createKeyword("catch"),
  3571. _continue: createKeyword("continue"),
  3572. _debugger: createKeyword("debugger"),
  3573. _default: createKeyword("default", {
  3574. beforeExpr
  3575. }),
  3576. _else: createKeyword("else", {
  3577. beforeExpr
  3578. }),
  3579. _finally: createKeyword("finally"),
  3580. _function: createKeyword("function", {
  3581. startsExpr
  3582. }),
  3583. _if: createKeyword("if"),
  3584. _return: createKeyword("return", {
  3585. beforeExpr
  3586. }),
  3587. _switch: createKeyword("switch"),
  3588. _throw: createKeyword("throw", {
  3589. beforeExpr,
  3590. prefix,
  3591. startsExpr
  3592. }),
  3593. _try: createKeyword("try"),
  3594. _var: createKeyword("var"),
  3595. _const: createKeyword("const"),
  3596. _with: createKeyword("with"),
  3597. _new: createKeyword("new", {
  3598. beforeExpr,
  3599. startsExpr
  3600. }),
  3601. _this: createKeyword("this", {
  3602. startsExpr
  3603. }),
  3604. _super: createKeyword("super", {
  3605. startsExpr
  3606. }),
  3607. _class: createKeyword("class", {
  3608. startsExpr
  3609. }),
  3610. _extends: createKeyword("extends", {
  3611. beforeExpr
  3612. }),
  3613. _export: createKeyword("export"),
  3614. _import: createKeyword("import", {
  3615. startsExpr
  3616. }),
  3617. _null: createKeyword("null", {
  3618. startsExpr
  3619. }),
  3620. _true: createKeyword("true", {
  3621. startsExpr
  3622. }),
  3623. _false: createKeyword("false", {
  3624. startsExpr
  3625. }),
  3626. _typeof: createKeyword("typeof", {
  3627. beforeExpr,
  3628. prefix,
  3629. startsExpr
  3630. }),
  3631. _void: createKeyword("void", {
  3632. beforeExpr,
  3633. prefix,
  3634. startsExpr
  3635. }),
  3636. _delete: createKeyword("delete", {
  3637. beforeExpr,
  3638. prefix,
  3639. startsExpr
  3640. }),
  3641. _do: createKeyword("do", {
  3642. isLoop,
  3643. beforeExpr
  3644. }),
  3645. _for: createKeyword("for", {
  3646. isLoop
  3647. }),
  3648. _while: createKeyword("while", {
  3649. isLoop
  3650. }),
  3651. _as: createKeywordLike("as", {
  3652. startsExpr
  3653. }),
  3654. _assert: createKeywordLike("assert", {
  3655. startsExpr
  3656. }),
  3657. _async: createKeywordLike("async", {
  3658. startsExpr
  3659. }),
  3660. _await: createKeywordLike("await", {
  3661. startsExpr
  3662. }),
  3663. _defer: createKeywordLike("defer", {
  3664. startsExpr
  3665. }),
  3666. _from: createKeywordLike("from", {
  3667. startsExpr
  3668. }),
  3669. _get: createKeywordLike("get", {
  3670. startsExpr
  3671. }),
  3672. _let: createKeywordLike("let", {
  3673. startsExpr
  3674. }),
  3675. _meta: createKeywordLike("meta", {
  3676. startsExpr
  3677. }),
  3678. _of: createKeywordLike("of", {
  3679. startsExpr
  3680. }),
  3681. _sent: createKeywordLike("sent", {
  3682. startsExpr
  3683. }),
  3684. _set: createKeywordLike("set", {
  3685. startsExpr
  3686. }),
  3687. _source: createKeywordLike("source", {
  3688. startsExpr
  3689. }),
  3690. _static: createKeywordLike("static", {
  3691. startsExpr
  3692. }),
  3693. _using: createKeywordLike("using", {
  3694. startsExpr
  3695. }),
  3696. _yield: createKeywordLike("yield", {
  3697. startsExpr
  3698. }),
  3699. _asserts: createKeywordLike("asserts", {
  3700. startsExpr
  3701. }),
  3702. _checks: createKeywordLike("checks", {
  3703. startsExpr
  3704. }),
  3705. _exports: createKeywordLike("exports", {
  3706. startsExpr
  3707. }),
  3708. _global: createKeywordLike("global", {
  3709. startsExpr
  3710. }),
  3711. _implements: createKeywordLike("implements", {
  3712. startsExpr
  3713. }),
  3714. _intrinsic: createKeywordLike("intrinsic", {
  3715. startsExpr
  3716. }),
  3717. _infer: createKeywordLike("infer", {
  3718. startsExpr
  3719. }),
  3720. _is: createKeywordLike("is", {
  3721. startsExpr
  3722. }),
  3723. _mixins: createKeywordLike("mixins", {
  3724. startsExpr
  3725. }),
  3726. _proto: createKeywordLike("proto", {
  3727. startsExpr
  3728. }),
  3729. _require: createKeywordLike("require", {
  3730. startsExpr
  3731. }),
  3732. _satisfies: createKeywordLike("satisfies", {
  3733. startsExpr
  3734. }),
  3735. _keyof: createKeywordLike("keyof", {
  3736. startsExpr
  3737. }),
  3738. _readonly: createKeywordLike("readonly", {
  3739. startsExpr
  3740. }),
  3741. _unique: createKeywordLike("unique", {
  3742. startsExpr
  3743. }),
  3744. _abstract: createKeywordLike("abstract", {
  3745. startsExpr
  3746. }),
  3747. _declare: createKeywordLike("declare", {
  3748. startsExpr
  3749. }),
  3750. _enum: createKeywordLike("enum", {
  3751. startsExpr
  3752. }),
  3753. _module: createKeywordLike("module", {
  3754. startsExpr
  3755. }),
  3756. _namespace: createKeywordLike("namespace", {
  3757. startsExpr
  3758. }),
  3759. _interface: createKeywordLike("interface", {
  3760. startsExpr
  3761. }),
  3762. _type: createKeywordLike("type", {
  3763. startsExpr
  3764. }),
  3765. _opaque: createKeywordLike("opaque", {
  3766. startsExpr
  3767. }),
  3768. name: createToken("name", {
  3769. startsExpr
  3770. }),
  3771. placeholder: createToken("%%", {
  3772. startsExpr
  3773. }),
  3774. string: createToken("string", {
  3775. startsExpr
  3776. }),
  3777. num: createToken("num", {
  3778. startsExpr
  3779. }),
  3780. bigint: createToken("bigint", {
  3781. startsExpr
  3782. }),
  3783. decimal: createToken("decimal", {
  3784. startsExpr
  3785. }),
  3786. regexp: createToken("regexp", {
  3787. startsExpr
  3788. }),
  3789. privateName: createToken("#name", {
  3790. startsExpr
  3791. }),
  3792. eof: createToken("eof"),
  3793. jsxName: createToken("jsxName"),
  3794. jsxText: createToken("jsxText", {
  3795. beforeExpr
  3796. }),
  3797. jsxTagStart: createToken("jsxTagStart", {
  3798. startsExpr
  3799. }),
  3800. jsxTagEnd: createToken("jsxTagEnd")
  3801. };
  3802. function tokenIsIdentifier(token) {
  3803. return token >= 93 && token <= 133;
  3804. }
  3805. function tokenKeywordOrIdentifierIsKeyword(token) {
  3806. return token <= 92;
  3807. }
  3808. function tokenIsKeywordOrIdentifier(token) {
  3809. return token >= 58 && token <= 133;
  3810. }
  3811. function tokenIsLiteralPropertyName(token) {
  3812. return token >= 58 && token <= 137;
  3813. }
  3814. function tokenComesBeforeExpression(token) {
  3815. return tokenBeforeExprs[token];
  3816. }
  3817. function tokenCanStartExpression(token) {
  3818. return tokenStartsExprs[token];
  3819. }
  3820. function tokenIsAssignment(token) {
  3821. return token >= 29 && token <= 33;
  3822. }
  3823. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  3824. return token >= 129 && token <= 131;
  3825. }
  3826. function tokenIsLoop(token) {
  3827. return token >= 90 && token <= 92;
  3828. }
  3829. function tokenIsKeyword(token) {
  3830. return token >= 58 && token <= 92;
  3831. }
  3832. function tokenIsOperator(token) {
  3833. return token >= 39 && token <= 59;
  3834. }
  3835. function tokenIsPostfix(token) {
  3836. return token === 34;
  3837. }
  3838. function tokenIsPrefix(token) {
  3839. return tokenPrefixes[token];
  3840. }
  3841. function tokenIsTSTypeOperator(token) {
  3842. return token >= 121 && token <= 123;
  3843. }
  3844. function tokenIsTSDeclarationStart(token) {
  3845. return token >= 124 && token <= 130;
  3846. }
  3847. function tokenLabelName(token) {
  3848. return tokenLabels[token];
  3849. }
  3850. function tokenOperatorPrecedence(token) {
  3851. return tokenBinops[token];
  3852. }
  3853. function tokenIsRightAssociative(token) {
  3854. return token === 57;
  3855. }
  3856. function tokenIsTemplate(token) {
  3857. return token >= 24 && token <= 25;
  3858. }
  3859. function getExportedToken(token) {
  3860. return tokenTypes[token];
  3861. }
  3862. {
  3863. tokenTypes[8].updateContext = context => {
  3864. context.pop();
  3865. };
  3866. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  3867. context.push(types.brace);
  3868. };
  3869. tokenTypes[22].updateContext = context => {
  3870. if (context[context.length - 1] === types.template) {
  3871. context.pop();
  3872. } else {
  3873. context.push(types.template);
  3874. }
  3875. };
  3876. tokenTypes[143].updateContext = context => {
  3877. context.push(types.j_expr, types.j_oTag);
  3878. };
  3879. }
  3880. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\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-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  3881. 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-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\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";
  3882. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  3883. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  3884. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  3885. 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, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 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, 328, 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, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
  3886. 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, 80, 3, 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, 343, 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, 330, 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, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  3887. function isInAstralSet(code, set) {
  3888. let pos = 0x10000;
  3889. for (let i = 0, length = set.length; i < length; i += 2) {
  3890. pos += set[i];
  3891. if (pos > code) return false;
  3892. pos += set[i + 1];
  3893. if (pos >= code) return true;
  3894. }
  3895. return false;
  3896. }
  3897. function isIdentifierStart(code) {
  3898. if (code < 65) return code === 36;
  3899. if (code <= 90) return true;
  3900. if (code < 97) return code === 95;
  3901. if (code <= 122) return true;
  3902. if (code <= 0xffff) {
  3903. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  3904. }
  3905. return isInAstralSet(code, astralIdentifierStartCodes);
  3906. }
  3907. function isIdentifierChar(code) {
  3908. if (code < 48) return code === 36;
  3909. if (code < 58) return true;
  3910. if (code < 65) return false;
  3911. if (code <= 90) return true;
  3912. if (code < 97) return code === 95;
  3913. if (code <= 122) return true;
  3914. if (code <= 0xffff) {
  3915. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  3916. }
  3917. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  3918. }
  3919. const reservedWords = {
  3920. 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"],
  3921. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  3922. strictBind: ["eval", "arguments"]
  3923. };
  3924. const keywords = new Set(reservedWords.keyword);
  3925. const reservedWordsStrictSet = new Set(reservedWords.strict);
  3926. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  3927. function isReservedWord(word, inModule) {
  3928. return inModule && word === "await" || word === "enum";
  3929. }
  3930. function isStrictReservedWord(word, inModule) {
  3931. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  3932. }
  3933. function isStrictBindOnlyReservedWord(word) {
  3934. return reservedWordsStrictBindSet.has(word);
  3935. }
  3936. function isStrictBindReservedWord(word, inModule) {
  3937. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  3938. }
  3939. function isKeyword(word) {
  3940. return keywords.has(word);
  3941. }
  3942. function isIteratorStart(current, next, next2) {
  3943. return current === 64 && next === 64 && isIdentifierStart(next2);
  3944. }
  3945. 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"]);
  3946. function canBeReservedWord(word) {
  3947. return reservedWordLikeSet.has(word);
  3948. }
  3949. class Scope {
  3950. constructor(flags) {
  3951. this.flags = 0;
  3952. this.names = new Map();
  3953. this.firstLexicalName = "";
  3954. this.flags = flags;
  3955. }
  3956. }
  3957. class ScopeHandler {
  3958. constructor(parser, inModule) {
  3959. this.parser = void 0;
  3960. this.scopeStack = [];
  3961. this.inModule = void 0;
  3962. this.undefinedExports = new Map();
  3963. this.parser = parser;
  3964. this.inModule = inModule;
  3965. }
  3966. get inTopLevel() {
  3967. return (this.currentScope().flags & 1) > 0;
  3968. }
  3969. get inFunction() {
  3970. return (this.currentVarScopeFlags() & 2) > 0;
  3971. }
  3972. get allowSuper() {
  3973. return (this.currentThisScopeFlags() & 16) > 0;
  3974. }
  3975. get allowDirectSuper() {
  3976. return (this.currentThisScopeFlags() & 32) > 0;
  3977. }
  3978. get allowNewTarget() {
  3979. return (this.currentThisScopeFlags() & 512) > 0;
  3980. }
  3981. get inClass() {
  3982. return (this.currentThisScopeFlags() & 64) > 0;
  3983. }
  3984. get inClassAndNotInNonArrowFunction() {
  3985. const flags = this.currentThisScopeFlags();
  3986. return (flags & 64) > 0 && (flags & 2) === 0;
  3987. }
  3988. get inStaticBlock() {
  3989. for (let i = this.scopeStack.length - 1;; i--) {
  3990. const {
  3991. flags
  3992. } = this.scopeStack[i];
  3993. if (flags & 128) {
  3994. return true;
  3995. }
  3996. if (flags & (1667 | 64)) {
  3997. return false;
  3998. }
  3999. }
  4000. }
  4001. get inNonArrowFunction() {
  4002. return (this.currentThisScopeFlags() & 2) > 0;
  4003. }
  4004. get inBareCaseStatement() {
  4005. return (this.currentScope().flags & 256) > 0;
  4006. }
  4007. get treatFunctionsAsVar() {
  4008. return this.treatFunctionsAsVarInScope(this.currentScope());
  4009. }
  4010. createScope(flags) {
  4011. return new Scope(flags);
  4012. }
  4013. enter(flags) {
  4014. this.scopeStack.push(this.createScope(flags));
  4015. }
  4016. exit() {
  4017. const scope = this.scopeStack.pop();
  4018. return scope.flags;
  4019. }
  4020. treatFunctionsAsVarInScope(scope) {
  4021. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  4022. }
  4023. declareName(name, bindingType, loc) {
  4024. let scope = this.currentScope();
  4025. if (bindingType & 8 || bindingType & 16) {
  4026. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4027. let type = scope.names.get(name) || 0;
  4028. if (bindingType & 16) {
  4029. type = type | 4;
  4030. } else {
  4031. if (!scope.firstLexicalName) {
  4032. scope.firstLexicalName = name;
  4033. }
  4034. type = type | 2;
  4035. }
  4036. scope.names.set(name, type);
  4037. if (bindingType & 8) {
  4038. this.maybeExportDefined(scope, name);
  4039. }
  4040. } else if (bindingType & 4) {
  4041. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  4042. scope = this.scopeStack[i];
  4043. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4044. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  4045. this.maybeExportDefined(scope, name);
  4046. if (scope.flags & 1667) break;
  4047. }
  4048. }
  4049. if (this.parser.inModule && scope.flags & 1) {
  4050. this.undefinedExports.delete(name);
  4051. }
  4052. }
  4053. maybeExportDefined(scope, name) {
  4054. if (this.parser.inModule && scope.flags & 1) {
  4055. this.undefinedExports.delete(name);
  4056. }
  4057. }
  4058. checkRedeclarationInScope(scope, name, bindingType, loc) {
  4059. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  4060. this.parser.raise(Errors.VarRedeclaration, loc, {
  4061. identifierName: name
  4062. });
  4063. }
  4064. }
  4065. isRedeclaredInScope(scope, name, bindingType) {
  4066. if (!(bindingType & 1)) return false;
  4067. if (bindingType & 8) {
  4068. return scope.names.has(name);
  4069. }
  4070. const type = scope.names.get(name);
  4071. if (bindingType & 16) {
  4072. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  4073. }
  4074. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  4075. }
  4076. checkLocalExport(id) {
  4077. const {
  4078. name
  4079. } = id;
  4080. const topLevelScope = this.scopeStack[0];
  4081. if (!topLevelScope.names.has(name)) {
  4082. this.undefinedExports.set(name, id.loc.start);
  4083. }
  4084. }
  4085. currentScope() {
  4086. return this.scopeStack[this.scopeStack.length - 1];
  4087. }
  4088. currentVarScopeFlags() {
  4089. for (let i = this.scopeStack.length - 1;; i--) {
  4090. const {
  4091. flags
  4092. } = this.scopeStack[i];
  4093. if (flags & 1667) {
  4094. return flags;
  4095. }
  4096. }
  4097. }
  4098. currentThisScopeFlags() {
  4099. for (let i = this.scopeStack.length - 1;; i--) {
  4100. const {
  4101. flags
  4102. } = this.scopeStack[i];
  4103. if (flags & (1667 | 64) && !(flags & 4)) {
  4104. return flags;
  4105. }
  4106. }
  4107. }
  4108. }
  4109. class FlowScope extends Scope {
  4110. constructor(...args) {
  4111. super(...args);
  4112. this.declareFunctions = new Set();
  4113. }
  4114. }
  4115. class FlowScopeHandler extends ScopeHandler {
  4116. createScope(flags) {
  4117. return new FlowScope(flags);
  4118. }
  4119. declareName(name, bindingType, loc) {
  4120. const scope = this.currentScope();
  4121. if (bindingType & 2048) {
  4122. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4123. this.maybeExportDefined(scope, name);
  4124. scope.declareFunctions.add(name);
  4125. return;
  4126. }
  4127. super.declareName(name, bindingType, loc);
  4128. }
  4129. isRedeclaredInScope(scope, name, bindingType) {
  4130. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  4131. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  4132. const type = scope.names.get(name);
  4133. return (type & 4) > 0 || (type & 2) > 0;
  4134. }
  4135. return false;
  4136. }
  4137. checkLocalExport(id) {
  4138. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  4139. super.checkLocalExport(id);
  4140. }
  4141. }
  4142. }
  4143. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  4144. const FlowErrors = ParseErrorEnum`flow`({
  4145. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  4146. 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.",
  4147. AssignReservedType: ({
  4148. reservedType
  4149. }) => `Cannot overwrite reserved type ${reservedType}.`,
  4150. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  4151. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  4152. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  4153. EnumBooleanMemberNotInitialized: ({
  4154. memberName,
  4155. enumName
  4156. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  4157. EnumDuplicateMemberName: ({
  4158. memberName,
  4159. enumName
  4160. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  4161. EnumInconsistentMemberValues: ({
  4162. enumName
  4163. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  4164. EnumInvalidExplicitType: ({
  4165. invalidEnumType,
  4166. enumName
  4167. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4168. EnumInvalidExplicitTypeUnknownSupplied: ({
  4169. enumName
  4170. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4171. EnumInvalidMemberInitializerPrimaryType: ({
  4172. enumName,
  4173. memberName,
  4174. explicitType
  4175. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  4176. EnumInvalidMemberInitializerSymbolType: ({
  4177. enumName,
  4178. memberName
  4179. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  4180. EnumInvalidMemberInitializerUnknownType: ({
  4181. enumName,
  4182. memberName
  4183. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  4184. EnumInvalidMemberName: ({
  4185. enumName,
  4186. memberName,
  4187. suggestion
  4188. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  4189. EnumNumberMemberNotInitialized: ({
  4190. enumName,
  4191. memberName
  4192. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  4193. EnumStringMemberInconsistentlyInitialized: ({
  4194. enumName
  4195. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  4196. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  4197. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  4198. 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.",
  4199. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  4200. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  4201. InexactVariance: "Explicit inexact syntax cannot have variance.",
  4202. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  4203. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  4204. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  4205. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  4206. PatternIsOptional: Object.assign({
  4207. message: "A binding pattern parameter cannot be optional in an implementation signature."
  4208. }, {
  4209. reasonCode: "OptionalBindingPattern"
  4210. }),
  4211. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  4212. SpreadVariance: "Spread properties cannot have variance.",
  4213. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  4214. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  4215. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  4216. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  4217. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  4218. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  4219. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  4220. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  4221. UnexpectedReservedType: ({
  4222. reservedType
  4223. }) => `Unexpected reserved type ${reservedType}.`,
  4224. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4225. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4226. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4227. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4228. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4229. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4230. UnsupportedDeclareExportKind: ({
  4231. unsupportedExportKind,
  4232. suggestion
  4233. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4234. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4235. UnterminatedFlowComment: "Unterminated flow-comment."
  4236. });
  4237. function isEsModuleType(bodyElement) {
  4238. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4239. }
  4240. function hasTypeImportKind(node) {
  4241. return node.importKind === "type" || node.importKind === "typeof";
  4242. }
  4243. const exportSuggestions = {
  4244. const: "declare export var",
  4245. let: "declare export var",
  4246. type: "export type",
  4247. interface: "export interface"
  4248. };
  4249. function partition(list, test) {
  4250. const list1 = [];
  4251. const list2 = [];
  4252. for (let i = 0; i < list.length; i++) {
  4253. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4254. }
  4255. return [list1, list2];
  4256. }
  4257. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4258. var flow = superClass => class FlowParserMixin extends superClass {
  4259. constructor(...args) {
  4260. super(...args);
  4261. this.flowPragma = undefined;
  4262. }
  4263. getScopeHandler() {
  4264. return FlowScopeHandler;
  4265. }
  4266. shouldParseTypes() {
  4267. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4268. }
  4269. finishToken(type, val) {
  4270. if (type !== 134 && type !== 13 && type !== 28) {
  4271. if (this.flowPragma === undefined) {
  4272. this.flowPragma = null;
  4273. }
  4274. }
  4275. super.finishToken(type, val);
  4276. }
  4277. addComment(comment) {
  4278. if (this.flowPragma === undefined) {
  4279. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4280. if (!matches) ;else if (matches[1] === "flow") {
  4281. this.flowPragma = "flow";
  4282. } else if (matches[1] === "noflow") {
  4283. this.flowPragma = "noflow";
  4284. } else {
  4285. throw new Error("Unexpected flow pragma");
  4286. }
  4287. }
  4288. super.addComment(comment);
  4289. }
  4290. flowParseTypeInitialiser(tok) {
  4291. const oldInType = this.state.inType;
  4292. this.state.inType = true;
  4293. this.expect(tok || 14);
  4294. const type = this.flowParseType();
  4295. this.state.inType = oldInType;
  4296. return type;
  4297. }
  4298. flowParsePredicate() {
  4299. const node = this.startNode();
  4300. const moduloLoc = this.state.startLoc;
  4301. this.next();
  4302. this.expectContextual(110);
  4303. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4304. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4305. }
  4306. if (this.eat(10)) {
  4307. node.value = super.parseExpression();
  4308. this.expect(11);
  4309. return this.finishNode(node, "DeclaredPredicate");
  4310. } else {
  4311. return this.finishNode(node, "InferredPredicate");
  4312. }
  4313. }
  4314. flowParseTypeAndPredicateInitialiser() {
  4315. const oldInType = this.state.inType;
  4316. this.state.inType = true;
  4317. this.expect(14);
  4318. let type = null;
  4319. let predicate = null;
  4320. if (this.match(54)) {
  4321. this.state.inType = oldInType;
  4322. predicate = this.flowParsePredicate();
  4323. } else {
  4324. type = this.flowParseType();
  4325. this.state.inType = oldInType;
  4326. if (this.match(54)) {
  4327. predicate = this.flowParsePredicate();
  4328. }
  4329. }
  4330. return [type, predicate];
  4331. }
  4332. flowParseDeclareClass(node) {
  4333. this.next();
  4334. this.flowParseInterfaceish(node, true);
  4335. return this.finishNode(node, "DeclareClass");
  4336. }
  4337. flowParseDeclareFunction(node) {
  4338. this.next();
  4339. const id = node.id = this.parseIdentifier();
  4340. const typeNode = this.startNode();
  4341. const typeContainer = this.startNode();
  4342. if (this.match(47)) {
  4343. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4344. } else {
  4345. typeNode.typeParameters = null;
  4346. }
  4347. this.expect(10);
  4348. const tmp = this.flowParseFunctionTypeParams();
  4349. typeNode.params = tmp.params;
  4350. typeNode.rest = tmp.rest;
  4351. typeNode.this = tmp._this;
  4352. this.expect(11);
  4353. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4354. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4355. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4356. this.resetEndLocation(id);
  4357. this.semicolon();
  4358. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4359. return this.finishNode(node, "DeclareFunction");
  4360. }
  4361. flowParseDeclare(node, insideModule) {
  4362. if (this.match(80)) {
  4363. return this.flowParseDeclareClass(node);
  4364. } else if (this.match(68)) {
  4365. return this.flowParseDeclareFunction(node);
  4366. } else if (this.match(74)) {
  4367. return this.flowParseDeclareVariable(node);
  4368. } else if (this.eatContextual(127)) {
  4369. if (this.match(16)) {
  4370. return this.flowParseDeclareModuleExports(node);
  4371. } else {
  4372. if (insideModule) {
  4373. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4374. }
  4375. return this.flowParseDeclareModule(node);
  4376. }
  4377. } else if (this.isContextual(130)) {
  4378. return this.flowParseDeclareTypeAlias(node);
  4379. } else if (this.isContextual(131)) {
  4380. return this.flowParseDeclareOpaqueType(node);
  4381. } else if (this.isContextual(129)) {
  4382. return this.flowParseDeclareInterface(node);
  4383. } else if (this.match(82)) {
  4384. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4385. } else {
  4386. this.unexpected();
  4387. }
  4388. }
  4389. flowParseDeclareVariable(node) {
  4390. this.next();
  4391. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4392. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4393. this.semicolon();
  4394. return this.finishNode(node, "DeclareVariable");
  4395. }
  4396. flowParseDeclareModule(node) {
  4397. this.scope.enter(0);
  4398. if (this.match(134)) {
  4399. node.id = super.parseExprAtom();
  4400. } else {
  4401. node.id = this.parseIdentifier();
  4402. }
  4403. const bodyNode = node.body = this.startNode();
  4404. const body = bodyNode.body = [];
  4405. this.expect(5);
  4406. while (!this.match(8)) {
  4407. let bodyNode = this.startNode();
  4408. if (this.match(83)) {
  4409. this.next();
  4410. if (!this.isContextual(130) && !this.match(87)) {
  4411. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4412. }
  4413. super.parseImport(bodyNode);
  4414. } else {
  4415. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4416. bodyNode = this.flowParseDeclare(bodyNode, true);
  4417. }
  4418. body.push(bodyNode);
  4419. }
  4420. this.scope.exit();
  4421. this.expect(8);
  4422. this.finishNode(bodyNode, "BlockStatement");
  4423. let kind = null;
  4424. let hasModuleExport = false;
  4425. body.forEach(bodyElement => {
  4426. if (isEsModuleType(bodyElement)) {
  4427. if (kind === "CommonJS") {
  4428. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4429. }
  4430. kind = "ES";
  4431. } else if (bodyElement.type === "DeclareModuleExports") {
  4432. if (hasModuleExport) {
  4433. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4434. }
  4435. if (kind === "ES") {
  4436. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4437. }
  4438. kind = "CommonJS";
  4439. hasModuleExport = true;
  4440. }
  4441. });
  4442. node.kind = kind || "CommonJS";
  4443. return this.finishNode(node, "DeclareModule");
  4444. }
  4445. flowParseDeclareExportDeclaration(node, insideModule) {
  4446. this.expect(82);
  4447. if (this.eat(65)) {
  4448. if (this.match(68) || this.match(80)) {
  4449. node.declaration = this.flowParseDeclare(this.startNode());
  4450. } else {
  4451. node.declaration = this.flowParseType();
  4452. this.semicolon();
  4453. }
  4454. node.default = true;
  4455. return this.finishNode(node, "DeclareExportDeclaration");
  4456. } else {
  4457. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4458. const label = this.state.value;
  4459. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4460. unsupportedExportKind: label,
  4461. suggestion: exportSuggestions[label]
  4462. });
  4463. }
  4464. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4465. node.declaration = this.flowParseDeclare(this.startNode());
  4466. node.default = false;
  4467. return this.finishNode(node, "DeclareExportDeclaration");
  4468. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4469. node = this.parseExport(node, null);
  4470. if (node.type === "ExportNamedDeclaration") {
  4471. node.default = false;
  4472. delete node.exportKind;
  4473. return this.castNodeTo(node, "DeclareExportDeclaration");
  4474. } else {
  4475. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  4476. }
  4477. }
  4478. }
  4479. this.unexpected();
  4480. }
  4481. flowParseDeclareModuleExports(node) {
  4482. this.next();
  4483. this.expectContextual(111);
  4484. node.typeAnnotation = this.flowParseTypeAnnotation();
  4485. this.semicolon();
  4486. return this.finishNode(node, "DeclareModuleExports");
  4487. }
  4488. flowParseDeclareTypeAlias(node) {
  4489. this.next();
  4490. const finished = this.flowParseTypeAlias(node);
  4491. this.castNodeTo(finished, "DeclareTypeAlias");
  4492. return finished;
  4493. }
  4494. flowParseDeclareOpaqueType(node) {
  4495. this.next();
  4496. const finished = this.flowParseOpaqueType(node, true);
  4497. this.castNodeTo(finished, "DeclareOpaqueType");
  4498. return finished;
  4499. }
  4500. flowParseDeclareInterface(node) {
  4501. this.next();
  4502. this.flowParseInterfaceish(node, false);
  4503. return this.finishNode(node, "DeclareInterface");
  4504. }
  4505. flowParseInterfaceish(node, isClass) {
  4506. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4507. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4508. if (this.match(47)) {
  4509. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4510. } else {
  4511. node.typeParameters = null;
  4512. }
  4513. node.extends = [];
  4514. if (this.eat(81)) {
  4515. do {
  4516. node.extends.push(this.flowParseInterfaceExtends());
  4517. } while (!isClass && this.eat(12));
  4518. }
  4519. if (isClass) {
  4520. node.implements = [];
  4521. node.mixins = [];
  4522. if (this.eatContextual(117)) {
  4523. do {
  4524. node.mixins.push(this.flowParseInterfaceExtends());
  4525. } while (this.eat(12));
  4526. }
  4527. if (this.eatContextual(113)) {
  4528. do {
  4529. node.implements.push(this.flowParseInterfaceExtends());
  4530. } while (this.eat(12));
  4531. }
  4532. }
  4533. node.body = this.flowParseObjectType({
  4534. allowStatic: isClass,
  4535. allowExact: false,
  4536. allowSpread: false,
  4537. allowProto: isClass,
  4538. allowInexact: false
  4539. });
  4540. }
  4541. flowParseInterfaceExtends() {
  4542. const node = this.startNode();
  4543. node.id = this.flowParseQualifiedTypeIdentifier();
  4544. if (this.match(47)) {
  4545. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4546. } else {
  4547. node.typeParameters = null;
  4548. }
  4549. return this.finishNode(node, "InterfaceExtends");
  4550. }
  4551. flowParseInterface(node) {
  4552. this.flowParseInterfaceish(node, false);
  4553. return this.finishNode(node, "InterfaceDeclaration");
  4554. }
  4555. checkNotUnderscore(word) {
  4556. if (word === "_") {
  4557. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4558. }
  4559. }
  4560. checkReservedType(word, startLoc, declaration) {
  4561. if (!reservedTypes.has(word)) return;
  4562. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4563. reservedType: word
  4564. });
  4565. }
  4566. flowParseRestrictedIdentifier(liberal, declaration) {
  4567. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4568. return this.parseIdentifier(liberal);
  4569. }
  4570. flowParseTypeAlias(node) {
  4571. node.id = this.flowParseRestrictedIdentifier(false, true);
  4572. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4573. if (this.match(47)) {
  4574. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4575. } else {
  4576. node.typeParameters = null;
  4577. }
  4578. node.right = this.flowParseTypeInitialiser(29);
  4579. this.semicolon();
  4580. return this.finishNode(node, "TypeAlias");
  4581. }
  4582. flowParseOpaqueType(node, declare) {
  4583. this.expectContextual(130);
  4584. node.id = this.flowParseRestrictedIdentifier(true, true);
  4585. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4586. if (this.match(47)) {
  4587. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4588. } else {
  4589. node.typeParameters = null;
  4590. }
  4591. node.supertype = null;
  4592. if (this.match(14)) {
  4593. node.supertype = this.flowParseTypeInitialiser(14);
  4594. }
  4595. node.impltype = null;
  4596. if (!declare) {
  4597. node.impltype = this.flowParseTypeInitialiser(29);
  4598. }
  4599. this.semicolon();
  4600. return this.finishNode(node, "OpaqueType");
  4601. }
  4602. flowParseTypeParameter(requireDefault = false) {
  4603. const nodeStartLoc = this.state.startLoc;
  4604. const node = this.startNode();
  4605. const variance = this.flowParseVariance();
  4606. const ident = this.flowParseTypeAnnotatableIdentifier();
  4607. node.name = ident.name;
  4608. node.variance = variance;
  4609. node.bound = ident.typeAnnotation;
  4610. if (this.match(29)) {
  4611. this.eat(29);
  4612. node.default = this.flowParseType();
  4613. } else {
  4614. if (requireDefault) {
  4615. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4616. }
  4617. }
  4618. return this.finishNode(node, "TypeParameter");
  4619. }
  4620. flowParseTypeParameterDeclaration() {
  4621. const oldInType = this.state.inType;
  4622. const node = this.startNode();
  4623. node.params = [];
  4624. this.state.inType = true;
  4625. if (this.match(47) || this.match(143)) {
  4626. this.next();
  4627. } else {
  4628. this.unexpected();
  4629. }
  4630. let defaultRequired = false;
  4631. do {
  4632. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4633. node.params.push(typeParameter);
  4634. if (typeParameter.default) {
  4635. defaultRequired = true;
  4636. }
  4637. if (!this.match(48)) {
  4638. this.expect(12);
  4639. }
  4640. } while (!this.match(48));
  4641. this.expect(48);
  4642. this.state.inType = oldInType;
  4643. return this.finishNode(node, "TypeParameterDeclaration");
  4644. }
  4645. flowInTopLevelContext(cb) {
  4646. if (this.curContext() !== types.brace) {
  4647. const oldContext = this.state.context;
  4648. this.state.context = [oldContext[0]];
  4649. try {
  4650. return cb();
  4651. } finally {
  4652. this.state.context = oldContext;
  4653. }
  4654. } else {
  4655. return cb();
  4656. }
  4657. }
  4658. flowParseTypeParameterInstantiationInExpression() {
  4659. if (this.reScan_lt() !== 47) return;
  4660. return this.flowParseTypeParameterInstantiation();
  4661. }
  4662. flowParseTypeParameterInstantiation() {
  4663. const node = this.startNode();
  4664. const oldInType = this.state.inType;
  4665. this.state.inType = true;
  4666. node.params = [];
  4667. this.flowInTopLevelContext(() => {
  4668. this.expect(47);
  4669. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4670. this.state.noAnonFunctionType = false;
  4671. while (!this.match(48)) {
  4672. node.params.push(this.flowParseType());
  4673. if (!this.match(48)) {
  4674. this.expect(12);
  4675. }
  4676. }
  4677. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4678. });
  4679. this.state.inType = oldInType;
  4680. if (!this.state.inType && this.curContext() === types.brace) {
  4681. this.reScan_lt_gt();
  4682. }
  4683. this.expect(48);
  4684. return this.finishNode(node, "TypeParameterInstantiation");
  4685. }
  4686. flowParseTypeParameterInstantiationCallOrNew() {
  4687. if (this.reScan_lt() !== 47) return;
  4688. const node = this.startNode();
  4689. const oldInType = this.state.inType;
  4690. node.params = [];
  4691. this.state.inType = true;
  4692. this.expect(47);
  4693. while (!this.match(48)) {
  4694. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4695. if (!this.match(48)) {
  4696. this.expect(12);
  4697. }
  4698. }
  4699. this.expect(48);
  4700. this.state.inType = oldInType;
  4701. return this.finishNode(node, "TypeParameterInstantiation");
  4702. }
  4703. flowParseInterfaceType() {
  4704. const node = this.startNode();
  4705. this.expectContextual(129);
  4706. node.extends = [];
  4707. if (this.eat(81)) {
  4708. do {
  4709. node.extends.push(this.flowParseInterfaceExtends());
  4710. } while (this.eat(12));
  4711. }
  4712. node.body = this.flowParseObjectType({
  4713. allowStatic: false,
  4714. allowExact: false,
  4715. allowSpread: false,
  4716. allowProto: false,
  4717. allowInexact: false
  4718. });
  4719. return this.finishNode(node, "InterfaceTypeAnnotation");
  4720. }
  4721. flowParseObjectPropertyKey() {
  4722. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  4723. }
  4724. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4725. node.static = isStatic;
  4726. if (this.lookahead().type === 14) {
  4727. node.id = this.flowParseObjectPropertyKey();
  4728. node.key = this.flowParseTypeInitialiser();
  4729. } else {
  4730. node.id = null;
  4731. node.key = this.flowParseType();
  4732. }
  4733. this.expect(3);
  4734. node.value = this.flowParseTypeInitialiser();
  4735. node.variance = variance;
  4736. return this.finishNode(node, "ObjectTypeIndexer");
  4737. }
  4738. flowParseObjectTypeInternalSlot(node, isStatic) {
  4739. node.static = isStatic;
  4740. node.id = this.flowParseObjectPropertyKey();
  4741. this.expect(3);
  4742. this.expect(3);
  4743. if (this.match(47) || this.match(10)) {
  4744. node.method = true;
  4745. node.optional = false;
  4746. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4747. } else {
  4748. node.method = false;
  4749. if (this.eat(17)) {
  4750. node.optional = true;
  4751. }
  4752. node.value = this.flowParseTypeInitialiser();
  4753. }
  4754. return this.finishNode(node, "ObjectTypeInternalSlot");
  4755. }
  4756. flowParseObjectTypeMethodish(node) {
  4757. node.params = [];
  4758. node.rest = null;
  4759. node.typeParameters = null;
  4760. node.this = null;
  4761. if (this.match(47)) {
  4762. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4763. }
  4764. this.expect(10);
  4765. if (this.match(78)) {
  4766. node.this = this.flowParseFunctionTypeParam(true);
  4767. node.this.name = null;
  4768. if (!this.match(11)) {
  4769. this.expect(12);
  4770. }
  4771. }
  4772. while (!this.match(11) && !this.match(21)) {
  4773. node.params.push(this.flowParseFunctionTypeParam(false));
  4774. if (!this.match(11)) {
  4775. this.expect(12);
  4776. }
  4777. }
  4778. if (this.eat(21)) {
  4779. node.rest = this.flowParseFunctionTypeParam(false);
  4780. }
  4781. this.expect(11);
  4782. node.returnType = this.flowParseTypeInitialiser();
  4783. return this.finishNode(node, "FunctionTypeAnnotation");
  4784. }
  4785. flowParseObjectTypeCallProperty(node, isStatic) {
  4786. const valueNode = this.startNode();
  4787. node.static = isStatic;
  4788. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4789. return this.finishNode(node, "ObjectTypeCallProperty");
  4790. }
  4791. flowParseObjectType({
  4792. allowStatic,
  4793. allowExact,
  4794. allowSpread,
  4795. allowProto,
  4796. allowInexact
  4797. }) {
  4798. const oldInType = this.state.inType;
  4799. this.state.inType = true;
  4800. const nodeStart = this.startNode();
  4801. nodeStart.callProperties = [];
  4802. nodeStart.properties = [];
  4803. nodeStart.indexers = [];
  4804. nodeStart.internalSlots = [];
  4805. let endDelim;
  4806. let exact;
  4807. let inexact = false;
  4808. if (allowExact && this.match(6)) {
  4809. this.expect(6);
  4810. endDelim = 9;
  4811. exact = true;
  4812. } else {
  4813. this.expect(5);
  4814. endDelim = 8;
  4815. exact = false;
  4816. }
  4817. nodeStart.exact = exact;
  4818. while (!this.match(endDelim)) {
  4819. let isStatic = false;
  4820. let protoStartLoc = null;
  4821. let inexactStartLoc = null;
  4822. const node = this.startNode();
  4823. if (allowProto && this.isContextual(118)) {
  4824. const lookahead = this.lookahead();
  4825. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4826. this.next();
  4827. protoStartLoc = this.state.startLoc;
  4828. allowStatic = false;
  4829. }
  4830. }
  4831. if (allowStatic && this.isContextual(106)) {
  4832. const lookahead = this.lookahead();
  4833. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4834. this.next();
  4835. isStatic = true;
  4836. }
  4837. }
  4838. const variance = this.flowParseVariance();
  4839. if (this.eat(0)) {
  4840. if (protoStartLoc != null) {
  4841. this.unexpected(protoStartLoc);
  4842. }
  4843. if (this.eat(0)) {
  4844. if (variance) {
  4845. this.unexpected(variance.loc.start);
  4846. }
  4847. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4848. } else {
  4849. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4850. }
  4851. } else if (this.match(10) || this.match(47)) {
  4852. if (protoStartLoc != null) {
  4853. this.unexpected(protoStartLoc);
  4854. }
  4855. if (variance) {
  4856. this.unexpected(variance.loc.start);
  4857. }
  4858. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4859. } else {
  4860. let kind = "init";
  4861. if (this.isContextual(99) || this.isContextual(104)) {
  4862. const lookahead = this.lookahead();
  4863. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4864. kind = this.state.value;
  4865. this.next();
  4866. }
  4867. }
  4868. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4869. if (propOrInexact === null) {
  4870. inexact = true;
  4871. inexactStartLoc = this.state.lastTokStartLoc;
  4872. } else {
  4873. nodeStart.properties.push(propOrInexact);
  4874. }
  4875. }
  4876. this.flowObjectTypeSemicolon();
  4877. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4878. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4879. }
  4880. }
  4881. this.expect(endDelim);
  4882. if (allowSpread) {
  4883. nodeStart.inexact = inexact;
  4884. }
  4885. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4886. this.state.inType = oldInType;
  4887. return out;
  4888. }
  4889. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4890. if (this.eat(21)) {
  4891. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4892. if (isInexactToken) {
  4893. if (!allowSpread) {
  4894. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4895. } else if (!allowInexact) {
  4896. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4897. }
  4898. if (variance) {
  4899. this.raise(FlowErrors.InexactVariance, variance);
  4900. }
  4901. return null;
  4902. }
  4903. if (!allowSpread) {
  4904. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4905. }
  4906. if (protoStartLoc != null) {
  4907. this.unexpected(protoStartLoc);
  4908. }
  4909. if (variance) {
  4910. this.raise(FlowErrors.SpreadVariance, variance);
  4911. }
  4912. node.argument = this.flowParseType();
  4913. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4914. } else {
  4915. node.key = this.flowParseObjectPropertyKey();
  4916. node.static = isStatic;
  4917. node.proto = protoStartLoc != null;
  4918. node.kind = kind;
  4919. let optional = false;
  4920. if (this.match(47) || this.match(10)) {
  4921. node.method = true;
  4922. if (protoStartLoc != null) {
  4923. this.unexpected(protoStartLoc);
  4924. }
  4925. if (variance) {
  4926. this.unexpected(variance.loc.start);
  4927. }
  4928. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4929. if (kind === "get" || kind === "set") {
  4930. this.flowCheckGetterSetterParams(node);
  4931. }
  4932. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4933. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4934. }
  4935. } else {
  4936. if (kind !== "init") this.unexpected();
  4937. node.method = false;
  4938. if (this.eat(17)) {
  4939. optional = true;
  4940. }
  4941. node.value = this.flowParseTypeInitialiser();
  4942. node.variance = variance;
  4943. }
  4944. node.optional = optional;
  4945. return this.finishNode(node, "ObjectTypeProperty");
  4946. }
  4947. }
  4948. flowCheckGetterSetterParams(property) {
  4949. const paramCount = property.kind === "get" ? 0 : 1;
  4950. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4951. if (property.value.this) {
  4952. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4953. }
  4954. if (length !== paramCount) {
  4955. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4956. }
  4957. if (property.kind === "set" && property.value.rest) {
  4958. this.raise(Errors.BadSetterRestParameter, property);
  4959. }
  4960. }
  4961. flowObjectTypeSemicolon() {
  4962. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4963. this.unexpected();
  4964. }
  4965. }
  4966. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4967. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  4968. let node = id || this.flowParseRestrictedIdentifier(true);
  4969. while (this.eat(16)) {
  4970. const node2 = this.startNodeAt(startLoc);
  4971. node2.qualification = node;
  4972. node2.id = this.flowParseRestrictedIdentifier(true);
  4973. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4974. }
  4975. return node;
  4976. }
  4977. flowParseGenericType(startLoc, id) {
  4978. const node = this.startNodeAt(startLoc);
  4979. node.typeParameters = null;
  4980. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4981. if (this.match(47)) {
  4982. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4983. }
  4984. return this.finishNode(node, "GenericTypeAnnotation");
  4985. }
  4986. flowParseTypeofType() {
  4987. const node = this.startNode();
  4988. this.expect(87);
  4989. node.argument = this.flowParsePrimaryType();
  4990. return this.finishNode(node, "TypeofTypeAnnotation");
  4991. }
  4992. flowParseTupleType() {
  4993. const node = this.startNode();
  4994. node.types = [];
  4995. this.expect(0);
  4996. while (this.state.pos < this.length && !this.match(3)) {
  4997. node.types.push(this.flowParseType());
  4998. if (this.match(3)) break;
  4999. this.expect(12);
  5000. }
  5001. this.expect(3);
  5002. return this.finishNode(node, "TupleTypeAnnotation");
  5003. }
  5004. flowParseFunctionTypeParam(first) {
  5005. let name = null;
  5006. let optional = false;
  5007. let typeAnnotation = null;
  5008. const node = this.startNode();
  5009. const lh = this.lookahead();
  5010. const isThis = this.state.type === 78;
  5011. if (lh.type === 14 || lh.type === 17) {
  5012. if (isThis && !first) {
  5013. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  5014. }
  5015. name = this.parseIdentifier(isThis);
  5016. if (this.eat(17)) {
  5017. optional = true;
  5018. if (isThis) {
  5019. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  5020. }
  5021. }
  5022. typeAnnotation = this.flowParseTypeInitialiser();
  5023. } else {
  5024. typeAnnotation = this.flowParseType();
  5025. }
  5026. node.name = name;
  5027. node.optional = optional;
  5028. node.typeAnnotation = typeAnnotation;
  5029. return this.finishNode(node, "FunctionTypeParam");
  5030. }
  5031. reinterpretTypeAsFunctionTypeParam(type) {
  5032. const node = this.startNodeAt(type.loc.start);
  5033. node.name = null;
  5034. node.optional = false;
  5035. node.typeAnnotation = type;
  5036. return this.finishNode(node, "FunctionTypeParam");
  5037. }
  5038. flowParseFunctionTypeParams(params = []) {
  5039. let rest = null;
  5040. let _this = null;
  5041. if (this.match(78)) {
  5042. _this = this.flowParseFunctionTypeParam(true);
  5043. _this.name = null;
  5044. if (!this.match(11)) {
  5045. this.expect(12);
  5046. }
  5047. }
  5048. while (!this.match(11) && !this.match(21)) {
  5049. params.push(this.flowParseFunctionTypeParam(false));
  5050. if (!this.match(11)) {
  5051. this.expect(12);
  5052. }
  5053. }
  5054. if (this.eat(21)) {
  5055. rest = this.flowParseFunctionTypeParam(false);
  5056. }
  5057. return {
  5058. params,
  5059. rest,
  5060. _this
  5061. };
  5062. }
  5063. flowIdentToTypeAnnotation(startLoc, node, id) {
  5064. switch (id.name) {
  5065. case "any":
  5066. return this.finishNode(node, "AnyTypeAnnotation");
  5067. case "bool":
  5068. case "boolean":
  5069. return this.finishNode(node, "BooleanTypeAnnotation");
  5070. case "mixed":
  5071. return this.finishNode(node, "MixedTypeAnnotation");
  5072. case "empty":
  5073. return this.finishNode(node, "EmptyTypeAnnotation");
  5074. case "number":
  5075. return this.finishNode(node, "NumberTypeAnnotation");
  5076. case "string":
  5077. return this.finishNode(node, "StringTypeAnnotation");
  5078. case "symbol":
  5079. return this.finishNode(node, "SymbolTypeAnnotation");
  5080. default:
  5081. this.checkNotUnderscore(id.name);
  5082. return this.flowParseGenericType(startLoc, id);
  5083. }
  5084. }
  5085. flowParsePrimaryType() {
  5086. const startLoc = this.state.startLoc;
  5087. const node = this.startNode();
  5088. let tmp;
  5089. let type;
  5090. let isGroupedType = false;
  5091. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5092. switch (this.state.type) {
  5093. case 5:
  5094. return this.flowParseObjectType({
  5095. allowStatic: false,
  5096. allowExact: false,
  5097. allowSpread: true,
  5098. allowProto: false,
  5099. allowInexact: true
  5100. });
  5101. case 6:
  5102. return this.flowParseObjectType({
  5103. allowStatic: false,
  5104. allowExact: true,
  5105. allowSpread: true,
  5106. allowProto: false,
  5107. allowInexact: false
  5108. });
  5109. case 0:
  5110. this.state.noAnonFunctionType = false;
  5111. type = this.flowParseTupleType();
  5112. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5113. return type;
  5114. case 47:
  5115. {
  5116. const node = this.startNode();
  5117. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5118. this.expect(10);
  5119. tmp = this.flowParseFunctionTypeParams();
  5120. node.params = tmp.params;
  5121. node.rest = tmp.rest;
  5122. node.this = tmp._this;
  5123. this.expect(11);
  5124. this.expect(19);
  5125. node.returnType = this.flowParseType();
  5126. return this.finishNode(node, "FunctionTypeAnnotation");
  5127. }
  5128. case 10:
  5129. {
  5130. const node = this.startNode();
  5131. this.next();
  5132. if (!this.match(11) && !this.match(21)) {
  5133. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  5134. const token = this.lookahead().type;
  5135. isGroupedType = token !== 17 && token !== 14;
  5136. } else {
  5137. isGroupedType = true;
  5138. }
  5139. }
  5140. if (isGroupedType) {
  5141. this.state.noAnonFunctionType = false;
  5142. type = this.flowParseType();
  5143. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5144. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  5145. this.expect(11);
  5146. return type;
  5147. } else {
  5148. this.eat(12);
  5149. }
  5150. }
  5151. if (type) {
  5152. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  5153. } else {
  5154. tmp = this.flowParseFunctionTypeParams();
  5155. }
  5156. node.params = tmp.params;
  5157. node.rest = tmp.rest;
  5158. node.this = tmp._this;
  5159. this.expect(11);
  5160. this.expect(19);
  5161. node.returnType = this.flowParseType();
  5162. node.typeParameters = null;
  5163. return this.finishNode(node, "FunctionTypeAnnotation");
  5164. }
  5165. case 134:
  5166. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  5167. case 85:
  5168. case 86:
  5169. node.value = this.match(85);
  5170. this.next();
  5171. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  5172. case 53:
  5173. if (this.state.value === "-") {
  5174. this.next();
  5175. if (this.match(135)) {
  5176. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  5177. }
  5178. if (this.match(136)) {
  5179. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  5180. }
  5181. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  5182. }
  5183. this.unexpected();
  5184. return;
  5185. case 135:
  5186. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  5187. case 136:
  5188. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  5189. case 88:
  5190. this.next();
  5191. return this.finishNode(node, "VoidTypeAnnotation");
  5192. case 84:
  5193. this.next();
  5194. return this.finishNode(node, "NullLiteralTypeAnnotation");
  5195. case 78:
  5196. this.next();
  5197. return this.finishNode(node, "ThisTypeAnnotation");
  5198. case 55:
  5199. this.next();
  5200. return this.finishNode(node, "ExistsTypeAnnotation");
  5201. case 87:
  5202. return this.flowParseTypeofType();
  5203. default:
  5204. if (tokenIsKeyword(this.state.type)) {
  5205. const label = tokenLabelName(this.state.type);
  5206. this.next();
  5207. return super.createIdentifier(node, label);
  5208. } else if (tokenIsIdentifier(this.state.type)) {
  5209. if (this.isContextual(129)) {
  5210. return this.flowParseInterfaceType();
  5211. }
  5212. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  5213. }
  5214. }
  5215. this.unexpected();
  5216. }
  5217. flowParsePostfixType() {
  5218. const startLoc = this.state.startLoc;
  5219. let type = this.flowParsePrimaryType();
  5220. let seenOptionalIndexedAccess = false;
  5221. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  5222. const node = this.startNodeAt(startLoc);
  5223. const optional = this.eat(18);
  5224. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5225. this.expect(0);
  5226. if (!optional && this.match(3)) {
  5227. node.elementType = type;
  5228. this.next();
  5229. type = this.finishNode(node, "ArrayTypeAnnotation");
  5230. } else {
  5231. node.objectType = type;
  5232. node.indexType = this.flowParseType();
  5233. this.expect(3);
  5234. if (seenOptionalIndexedAccess) {
  5235. node.optional = optional;
  5236. type = this.finishNode(node, "OptionalIndexedAccessType");
  5237. } else {
  5238. type = this.finishNode(node, "IndexedAccessType");
  5239. }
  5240. }
  5241. }
  5242. return type;
  5243. }
  5244. flowParsePrefixType() {
  5245. const node = this.startNode();
  5246. if (this.eat(17)) {
  5247. node.typeAnnotation = this.flowParsePrefixType();
  5248. return this.finishNode(node, "NullableTypeAnnotation");
  5249. } else {
  5250. return this.flowParsePostfixType();
  5251. }
  5252. }
  5253. flowParseAnonFunctionWithoutParens() {
  5254. const param = this.flowParsePrefixType();
  5255. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5256. const node = this.startNodeAt(param.loc.start);
  5257. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5258. node.rest = null;
  5259. node.this = null;
  5260. node.returnType = this.flowParseType();
  5261. node.typeParameters = null;
  5262. return this.finishNode(node, "FunctionTypeAnnotation");
  5263. }
  5264. return param;
  5265. }
  5266. flowParseIntersectionType() {
  5267. const node = this.startNode();
  5268. this.eat(45);
  5269. const type = this.flowParseAnonFunctionWithoutParens();
  5270. node.types = [type];
  5271. while (this.eat(45)) {
  5272. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5273. }
  5274. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5275. }
  5276. flowParseUnionType() {
  5277. const node = this.startNode();
  5278. this.eat(43);
  5279. const type = this.flowParseIntersectionType();
  5280. node.types = [type];
  5281. while (this.eat(43)) {
  5282. node.types.push(this.flowParseIntersectionType());
  5283. }
  5284. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5285. }
  5286. flowParseType() {
  5287. const oldInType = this.state.inType;
  5288. this.state.inType = true;
  5289. const type = this.flowParseUnionType();
  5290. this.state.inType = oldInType;
  5291. return type;
  5292. }
  5293. flowParseTypeOrImplicitInstantiation() {
  5294. if (this.state.type === 132 && this.state.value === "_") {
  5295. const startLoc = this.state.startLoc;
  5296. const node = this.parseIdentifier();
  5297. return this.flowParseGenericType(startLoc, node);
  5298. } else {
  5299. return this.flowParseType();
  5300. }
  5301. }
  5302. flowParseTypeAnnotation() {
  5303. const node = this.startNode();
  5304. node.typeAnnotation = this.flowParseTypeInitialiser();
  5305. return this.finishNode(node, "TypeAnnotation");
  5306. }
  5307. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5308. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5309. if (this.match(14)) {
  5310. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5311. this.resetEndLocation(ident);
  5312. }
  5313. return ident;
  5314. }
  5315. typeCastToParameter(node) {
  5316. node.expression.typeAnnotation = node.typeAnnotation;
  5317. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5318. return node.expression;
  5319. }
  5320. flowParseVariance() {
  5321. let variance = null;
  5322. if (this.match(53)) {
  5323. variance = this.startNode();
  5324. if (this.state.value === "+") {
  5325. variance.kind = "plus";
  5326. } else {
  5327. variance.kind = "minus";
  5328. }
  5329. this.next();
  5330. return this.finishNode(variance, "Variance");
  5331. }
  5332. return variance;
  5333. }
  5334. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5335. if (allowExpressionBody) {
  5336. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5337. return;
  5338. }
  5339. super.parseFunctionBody(node, false, isMethod);
  5340. }
  5341. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5342. if (this.match(14)) {
  5343. const typeNode = this.startNode();
  5344. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5345. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5346. }
  5347. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5348. }
  5349. parseStatementLike(flags) {
  5350. if (this.state.strict && this.isContextual(129)) {
  5351. const lookahead = this.lookahead();
  5352. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5353. const node = this.startNode();
  5354. this.next();
  5355. return this.flowParseInterface(node);
  5356. }
  5357. } else if (this.isContextual(126)) {
  5358. const node = this.startNode();
  5359. this.next();
  5360. return this.flowParseEnumDeclaration(node);
  5361. }
  5362. const stmt = super.parseStatementLike(flags);
  5363. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5364. this.flowPragma = null;
  5365. }
  5366. return stmt;
  5367. }
  5368. parseExpressionStatement(node, expr, decorators) {
  5369. if (expr.type === "Identifier") {
  5370. if (expr.name === "declare") {
  5371. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5372. return this.flowParseDeclare(node);
  5373. }
  5374. } else if (tokenIsIdentifier(this.state.type)) {
  5375. if (expr.name === "interface") {
  5376. return this.flowParseInterface(node);
  5377. } else if (expr.name === "type") {
  5378. return this.flowParseTypeAlias(node);
  5379. } else if (expr.name === "opaque") {
  5380. return this.flowParseOpaqueType(node, false);
  5381. }
  5382. }
  5383. }
  5384. return super.parseExpressionStatement(node, expr, decorators);
  5385. }
  5386. shouldParseExportDeclaration() {
  5387. const {
  5388. type
  5389. } = this.state;
  5390. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5391. return !this.state.containsEsc;
  5392. }
  5393. return super.shouldParseExportDeclaration();
  5394. }
  5395. isExportDefaultSpecifier() {
  5396. const {
  5397. type
  5398. } = this.state;
  5399. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5400. return this.state.containsEsc;
  5401. }
  5402. return super.isExportDefaultSpecifier();
  5403. }
  5404. parseExportDefaultExpression() {
  5405. if (this.isContextual(126)) {
  5406. const node = this.startNode();
  5407. this.next();
  5408. return this.flowParseEnumDeclaration(node);
  5409. }
  5410. return super.parseExportDefaultExpression();
  5411. }
  5412. parseConditional(expr, startLoc, refExpressionErrors) {
  5413. if (!this.match(17)) return expr;
  5414. if (this.state.maybeInArrowParameters) {
  5415. const nextCh = this.lookaheadCharCode();
  5416. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5417. this.setOptionalParametersError(refExpressionErrors);
  5418. return expr;
  5419. }
  5420. }
  5421. this.expect(17);
  5422. const state = this.state.clone();
  5423. const originalNoArrowAt = this.state.noArrowAt;
  5424. const node = this.startNodeAt(startLoc);
  5425. let {
  5426. consequent,
  5427. failed
  5428. } = this.tryParseConditionalConsequent();
  5429. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5430. if (failed || invalid.length > 0) {
  5431. const noArrowAt = [...originalNoArrowAt];
  5432. if (invalid.length > 0) {
  5433. this.state = state;
  5434. this.state.noArrowAt = noArrowAt;
  5435. for (let i = 0; i < invalid.length; i++) {
  5436. noArrowAt.push(invalid[i].start);
  5437. }
  5438. ({
  5439. consequent,
  5440. failed
  5441. } = this.tryParseConditionalConsequent());
  5442. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5443. }
  5444. if (failed && valid.length > 1) {
  5445. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5446. }
  5447. if (failed && valid.length === 1) {
  5448. this.state = state;
  5449. noArrowAt.push(valid[0].start);
  5450. this.state.noArrowAt = noArrowAt;
  5451. ({
  5452. consequent,
  5453. failed
  5454. } = this.tryParseConditionalConsequent());
  5455. }
  5456. }
  5457. this.getArrowLikeExpressions(consequent, true);
  5458. this.state.noArrowAt = originalNoArrowAt;
  5459. this.expect(14);
  5460. node.test = expr;
  5461. node.consequent = consequent;
  5462. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5463. return this.finishNode(node, "ConditionalExpression");
  5464. }
  5465. tryParseConditionalConsequent() {
  5466. this.state.noArrowParamsConversionAt.push(this.state.start);
  5467. const consequent = this.parseMaybeAssignAllowIn();
  5468. const failed = !this.match(14);
  5469. this.state.noArrowParamsConversionAt.pop();
  5470. return {
  5471. consequent,
  5472. failed
  5473. };
  5474. }
  5475. getArrowLikeExpressions(node, disallowInvalid) {
  5476. const stack = [node];
  5477. const arrows = [];
  5478. while (stack.length !== 0) {
  5479. const node = stack.pop();
  5480. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5481. if (node.typeParameters || !node.returnType) {
  5482. this.finishArrowValidation(node);
  5483. } else {
  5484. arrows.push(node);
  5485. }
  5486. stack.push(node.body);
  5487. } else if (node.type === "ConditionalExpression") {
  5488. stack.push(node.consequent);
  5489. stack.push(node.alternate);
  5490. }
  5491. }
  5492. if (disallowInvalid) {
  5493. arrows.forEach(node => this.finishArrowValidation(node));
  5494. return [arrows, []];
  5495. }
  5496. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5497. }
  5498. finishArrowValidation(node) {
  5499. var _node$extra;
  5500. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5501. this.scope.enter(514 | 4);
  5502. super.checkParams(node, false, true);
  5503. this.scope.exit();
  5504. }
  5505. forwardNoArrowParamsConversionAt(node, parse) {
  5506. let result;
  5507. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5508. this.state.noArrowParamsConversionAt.push(this.state.start);
  5509. result = parse();
  5510. this.state.noArrowParamsConversionAt.pop();
  5511. } else {
  5512. result = parse();
  5513. }
  5514. return result;
  5515. }
  5516. parseParenItem(node, startLoc) {
  5517. const newNode = super.parseParenItem(node, startLoc);
  5518. if (this.eat(17)) {
  5519. newNode.optional = true;
  5520. this.resetEndLocation(node);
  5521. }
  5522. if (this.match(14)) {
  5523. const typeCastNode = this.startNodeAt(startLoc);
  5524. typeCastNode.expression = newNode;
  5525. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5526. return this.finishNode(typeCastNode, "TypeCastExpression");
  5527. }
  5528. return newNode;
  5529. }
  5530. assertModuleNodeAllowed(node) {
  5531. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5532. return;
  5533. }
  5534. super.assertModuleNodeAllowed(node);
  5535. }
  5536. parseExportDeclaration(node) {
  5537. if (this.isContextual(130)) {
  5538. node.exportKind = "type";
  5539. const declarationNode = this.startNode();
  5540. this.next();
  5541. if (this.match(5)) {
  5542. node.specifiers = this.parseExportSpecifiers(true);
  5543. super.parseExportFrom(node);
  5544. return null;
  5545. } else {
  5546. return this.flowParseTypeAlias(declarationNode);
  5547. }
  5548. } else if (this.isContextual(131)) {
  5549. node.exportKind = "type";
  5550. const declarationNode = this.startNode();
  5551. this.next();
  5552. return this.flowParseOpaqueType(declarationNode, false);
  5553. } else if (this.isContextual(129)) {
  5554. node.exportKind = "type";
  5555. const declarationNode = this.startNode();
  5556. this.next();
  5557. return this.flowParseInterface(declarationNode);
  5558. } else if (this.isContextual(126)) {
  5559. node.exportKind = "value";
  5560. const declarationNode = this.startNode();
  5561. this.next();
  5562. return this.flowParseEnumDeclaration(declarationNode);
  5563. } else {
  5564. return super.parseExportDeclaration(node);
  5565. }
  5566. }
  5567. eatExportStar(node) {
  5568. if (super.eatExportStar(node)) return true;
  5569. if (this.isContextual(130) && this.lookahead().type === 55) {
  5570. node.exportKind = "type";
  5571. this.next();
  5572. this.next();
  5573. return true;
  5574. }
  5575. return false;
  5576. }
  5577. maybeParseExportNamespaceSpecifier(node) {
  5578. const {
  5579. startLoc
  5580. } = this.state;
  5581. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5582. if (hasNamespace && node.exportKind === "type") {
  5583. this.unexpected(startLoc);
  5584. }
  5585. return hasNamespace;
  5586. }
  5587. parseClassId(node, isStatement, optionalId) {
  5588. super.parseClassId(node, isStatement, optionalId);
  5589. if (this.match(47)) {
  5590. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5591. }
  5592. }
  5593. parseClassMember(classBody, member, state) {
  5594. const {
  5595. startLoc
  5596. } = this.state;
  5597. if (this.isContextual(125)) {
  5598. if (super.parseClassMemberFromModifier(classBody, member)) {
  5599. return;
  5600. }
  5601. member.declare = true;
  5602. }
  5603. super.parseClassMember(classBody, member, state);
  5604. if (member.declare) {
  5605. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5606. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5607. } else if (member.value) {
  5608. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5609. }
  5610. }
  5611. }
  5612. isIterator(word) {
  5613. return word === "iterator" || word === "asyncIterator";
  5614. }
  5615. readIterator() {
  5616. const word = super.readWord1();
  5617. const fullWord = "@@" + word;
  5618. if (!this.isIterator(word) || !this.state.inType) {
  5619. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5620. identifierName: fullWord
  5621. });
  5622. }
  5623. this.finishToken(132, fullWord);
  5624. }
  5625. getTokenFromCode(code) {
  5626. const next = this.input.charCodeAt(this.state.pos + 1);
  5627. if (code === 123 && next === 124) {
  5628. this.finishOp(6, 2);
  5629. } else if (this.state.inType && (code === 62 || code === 60)) {
  5630. this.finishOp(code === 62 ? 48 : 47, 1);
  5631. } else if (this.state.inType && code === 63) {
  5632. if (next === 46) {
  5633. this.finishOp(18, 2);
  5634. } else {
  5635. this.finishOp(17, 1);
  5636. }
  5637. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5638. this.state.pos += 2;
  5639. this.readIterator();
  5640. } else {
  5641. super.getTokenFromCode(code);
  5642. }
  5643. }
  5644. isAssignable(node, isBinding) {
  5645. if (node.type === "TypeCastExpression") {
  5646. return this.isAssignable(node.expression, isBinding);
  5647. } else {
  5648. return super.isAssignable(node, isBinding);
  5649. }
  5650. }
  5651. toAssignable(node, isLHS = false) {
  5652. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5653. node.left = this.typeCastToParameter(node.left);
  5654. }
  5655. super.toAssignable(node, isLHS);
  5656. }
  5657. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5658. for (let i = 0; i < exprList.length; i++) {
  5659. const expr = exprList[i];
  5660. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5661. exprList[i] = this.typeCastToParameter(expr);
  5662. }
  5663. }
  5664. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5665. }
  5666. toReferencedList(exprList, isParenthesizedExpr) {
  5667. for (let i = 0; i < exprList.length; i++) {
  5668. var _expr$extra;
  5669. const expr = exprList[i];
  5670. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5671. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5672. }
  5673. }
  5674. return exprList;
  5675. }
  5676. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5677. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5678. if (canBePattern && !this.state.maybeInArrowParameters) {
  5679. this.toReferencedList(node.elements);
  5680. }
  5681. return node;
  5682. }
  5683. isValidLVal(type, isParenthesized, binding) {
  5684. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5685. }
  5686. parseClassProperty(node) {
  5687. if (this.match(14)) {
  5688. node.typeAnnotation = this.flowParseTypeAnnotation();
  5689. }
  5690. return super.parseClassProperty(node);
  5691. }
  5692. parseClassPrivateProperty(node) {
  5693. if (this.match(14)) {
  5694. node.typeAnnotation = this.flowParseTypeAnnotation();
  5695. }
  5696. return super.parseClassPrivateProperty(node);
  5697. }
  5698. isClassMethod() {
  5699. return this.match(47) || super.isClassMethod();
  5700. }
  5701. isClassProperty() {
  5702. return this.match(14) || super.isClassProperty();
  5703. }
  5704. isNonstaticConstructor(method) {
  5705. return !this.match(14) && super.isNonstaticConstructor(method);
  5706. }
  5707. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5708. if (method.variance) {
  5709. this.unexpected(method.variance.loc.start);
  5710. }
  5711. delete method.variance;
  5712. if (this.match(47)) {
  5713. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5714. }
  5715. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5716. if (method.params && isConstructor) {
  5717. const params = method.params;
  5718. if (params.length > 0 && this.isThisParam(params[0])) {
  5719. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5720. }
  5721. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5722. const params = method.value.params;
  5723. if (params.length > 0 && this.isThisParam(params[0])) {
  5724. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5725. }
  5726. }
  5727. }
  5728. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5729. if (method.variance) {
  5730. this.unexpected(method.variance.loc.start);
  5731. }
  5732. delete method.variance;
  5733. if (this.match(47)) {
  5734. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5735. }
  5736. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5737. }
  5738. parseClassSuper(node) {
  5739. super.parseClassSuper(node);
  5740. if (node.superClass && (this.match(47) || this.match(51))) {
  5741. {
  5742. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  5743. }
  5744. }
  5745. if (this.isContextual(113)) {
  5746. this.next();
  5747. const implemented = node.implements = [];
  5748. do {
  5749. const node = this.startNode();
  5750. node.id = this.flowParseRestrictedIdentifier(true);
  5751. if (this.match(47)) {
  5752. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5753. } else {
  5754. node.typeParameters = null;
  5755. }
  5756. implemented.push(this.finishNode(node, "ClassImplements"));
  5757. } while (this.eat(12));
  5758. }
  5759. }
  5760. checkGetterSetterParams(method) {
  5761. super.checkGetterSetterParams(method);
  5762. const params = this.getObjectOrClassMethodParams(method);
  5763. if (params.length > 0) {
  5764. const param = params[0];
  5765. if (this.isThisParam(param) && method.kind === "get") {
  5766. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5767. } else if (this.isThisParam(param)) {
  5768. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5769. }
  5770. }
  5771. }
  5772. parsePropertyNamePrefixOperator(node) {
  5773. node.variance = this.flowParseVariance();
  5774. }
  5775. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5776. if (prop.variance) {
  5777. this.unexpected(prop.variance.loc.start);
  5778. }
  5779. delete prop.variance;
  5780. let typeParameters;
  5781. if (this.match(47) && !isAccessor) {
  5782. typeParameters = this.flowParseTypeParameterDeclaration();
  5783. if (!this.match(10)) this.unexpected();
  5784. }
  5785. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5786. if (typeParameters) {
  5787. (result.value || result).typeParameters = typeParameters;
  5788. }
  5789. return result;
  5790. }
  5791. parseFunctionParamType(param) {
  5792. if (this.eat(17)) {
  5793. if (param.type !== "Identifier") {
  5794. this.raise(FlowErrors.PatternIsOptional, param);
  5795. }
  5796. if (this.isThisParam(param)) {
  5797. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5798. }
  5799. param.optional = true;
  5800. }
  5801. if (this.match(14)) {
  5802. param.typeAnnotation = this.flowParseTypeAnnotation();
  5803. } else if (this.isThisParam(param)) {
  5804. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5805. }
  5806. if (this.match(29) && this.isThisParam(param)) {
  5807. this.raise(FlowErrors.ThisParamNoDefault, param);
  5808. }
  5809. this.resetEndLocation(param);
  5810. return param;
  5811. }
  5812. parseMaybeDefault(startLoc, left) {
  5813. const node = super.parseMaybeDefault(startLoc, left);
  5814. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5815. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5816. }
  5817. return node;
  5818. }
  5819. checkImportReflection(node) {
  5820. super.checkImportReflection(node);
  5821. if (node.module && node.importKind !== "value") {
  5822. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5823. }
  5824. }
  5825. parseImportSpecifierLocal(node, specifier, type) {
  5826. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5827. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5828. }
  5829. isPotentialImportPhase(isExport) {
  5830. if (super.isPotentialImportPhase(isExport)) return true;
  5831. if (this.isContextual(130)) {
  5832. if (!isExport) return true;
  5833. const ch = this.lookaheadCharCode();
  5834. return ch === 123 || ch === 42;
  5835. }
  5836. return !isExport && this.isContextual(87);
  5837. }
  5838. applyImportPhase(node, isExport, phase, loc) {
  5839. super.applyImportPhase(node, isExport, phase, loc);
  5840. if (isExport) {
  5841. if (!phase && this.match(65)) {
  5842. return;
  5843. }
  5844. node.exportKind = phase === "type" ? phase : "value";
  5845. } else {
  5846. if (phase === "type" && this.match(55)) this.unexpected();
  5847. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5848. }
  5849. }
  5850. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5851. const firstIdent = specifier.imported;
  5852. let specifierTypeKind = null;
  5853. if (firstIdent.type === "Identifier") {
  5854. if (firstIdent.name === "type") {
  5855. specifierTypeKind = "type";
  5856. } else if (firstIdent.name === "typeof") {
  5857. specifierTypeKind = "typeof";
  5858. }
  5859. }
  5860. let isBinding = false;
  5861. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5862. const as_ident = this.parseIdentifier(true);
  5863. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5864. specifier.imported = as_ident;
  5865. specifier.importKind = specifierTypeKind;
  5866. specifier.local = this.cloneIdentifier(as_ident);
  5867. } else {
  5868. specifier.imported = firstIdent;
  5869. specifier.importKind = null;
  5870. specifier.local = this.parseIdentifier();
  5871. }
  5872. } else {
  5873. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5874. specifier.imported = this.parseIdentifier(true);
  5875. specifier.importKind = specifierTypeKind;
  5876. } else {
  5877. if (importedIsString) {
  5878. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5879. importName: firstIdent.value
  5880. });
  5881. }
  5882. specifier.imported = firstIdent;
  5883. specifier.importKind = null;
  5884. }
  5885. if (this.eatContextual(93)) {
  5886. specifier.local = this.parseIdentifier();
  5887. } else {
  5888. isBinding = true;
  5889. specifier.local = this.cloneIdentifier(specifier.imported);
  5890. }
  5891. }
  5892. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5893. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5894. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5895. }
  5896. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5897. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5898. }
  5899. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5900. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5901. }
  5902. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5903. }
  5904. parseBindingAtom() {
  5905. switch (this.state.type) {
  5906. case 78:
  5907. return this.parseIdentifier(true);
  5908. default:
  5909. return super.parseBindingAtom();
  5910. }
  5911. }
  5912. parseFunctionParams(node, isConstructor) {
  5913. const kind = node.kind;
  5914. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5915. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5916. }
  5917. super.parseFunctionParams(node, isConstructor);
  5918. }
  5919. parseVarId(decl, kind) {
  5920. super.parseVarId(decl, kind);
  5921. if (this.match(14)) {
  5922. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5923. this.resetEndLocation(decl.id);
  5924. }
  5925. }
  5926. parseAsyncArrowFromCallExpression(node, call) {
  5927. if (this.match(14)) {
  5928. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5929. this.state.noAnonFunctionType = true;
  5930. node.returnType = this.flowParseTypeAnnotation();
  5931. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5932. }
  5933. return super.parseAsyncArrowFromCallExpression(node, call);
  5934. }
  5935. shouldParseAsyncArrow() {
  5936. return this.match(14) || super.shouldParseAsyncArrow();
  5937. }
  5938. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5939. var _jsx;
  5940. let state = null;
  5941. let jsx;
  5942. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  5943. state = this.state.clone();
  5944. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5945. if (!jsx.error) return jsx.node;
  5946. const {
  5947. context
  5948. } = this.state;
  5949. const currentContext = context[context.length - 1];
  5950. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5951. context.pop();
  5952. }
  5953. }
  5954. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5955. var _jsx2, _jsx3;
  5956. state = state || this.state.clone();
  5957. let typeParameters;
  5958. const arrow = this.tryParse(abort => {
  5959. var _arrowExpression$extr;
  5960. typeParameters = this.flowParseTypeParameterDeclaration();
  5961. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5962. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5963. this.resetStartLocationFromNode(result, typeParameters);
  5964. return result;
  5965. });
  5966. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5967. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5968. if (expr.type !== "ArrowFunctionExpression") abort();
  5969. expr.typeParameters = typeParameters;
  5970. this.resetStartLocationFromNode(expr, typeParameters);
  5971. return arrowExpression;
  5972. }, state);
  5973. let arrowExpression = null;
  5974. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5975. if (!arrow.error && !arrow.aborted) {
  5976. if (arrow.node.async) {
  5977. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5978. }
  5979. return arrow.node;
  5980. }
  5981. arrowExpression = arrow.node;
  5982. }
  5983. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5984. this.state = jsx.failState;
  5985. return jsx.node;
  5986. }
  5987. if (arrowExpression) {
  5988. this.state = arrow.failState;
  5989. return arrowExpression;
  5990. }
  5991. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5992. if (arrow.thrown) throw arrow.error;
  5993. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5994. }
  5995. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5996. }
  5997. parseArrow(node) {
  5998. if (this.match(14)) {
  5999. const result = this.tryParse(() => {
  6000. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  6001. this.state.noAnonFunctionType = true;
  6002. const typeNode = this.startNode();
  6003. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6004. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6005. if (this.canInsertSemicolon()) this.unexpected();
  6006. if (!this.match(19)) this.unexpected();
  6007. return typeNode;
  6008. });
  6009. if (result.thrown) return null;
  6010. if (result.error) this.state = result.failState;
  6011. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  6012. }
  6013. return super.parseArrow(node);
  6014. }
  6015. shouldParseArrow(params) {
  6016. return this.match(14) || super.shouldParseArrow(params);
  6017. }
  6018. setArrowFunctionParameters(node, params) {
  6019. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  6020. node.params = params;
  6021. } else {
  6022. super.setArrowFunctionParameters(node, params);
  6023. }
  6024. }
  6025. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  6026. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  6027. return;
  6028. }
  6029. for (let i = 0; i < node.params.length; i++) {
  6030. if (this.isThisParam(node.params[i]) && i > 0) {
  6031. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  6032. }
  6033. }
  6034. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  6035. }
  6036. parseParenAndDistinguishExpression(canBeArrow) {
  6037. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  6038. }
  6039. parseSubscripts(base, startLoc, noCalls) {
  6040. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  6041. this.next();
  6042. const node = this.startNodeAt(startLoc);
  6043. node.callee = base;
  6044. node.arguments = super.parseCallExpressionArguments();
  6045. base = this.finishNode(node, "CallExpression");
  6046. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  6047. const state = this.state.clone();
  6048. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  6049. if (!arrow.error && !arrow.aborted) return arrow.node;
  6050. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  6051. if (result.node && !result.error) return result.node;
  6052. if (arrow.node) {
  6053. this.state = arrow.failState;
  6054. return arrow.node;
  6055. }
  6056. if (result.node) {
  6057. this.state = result.failState;
  6058. return result.node;
  6059. }
  6060. throw arrow.error || result.error;
  6061. }
  6062. return super.parseSubscripts(base, startLoc, noCalls);
  6063. }
  6064. parseSubscript(base, startLoc, noCalls, subscriptState) {
  6065. if (this.match(18) && this.isLookaheadToken_lt()) {
  6066. subscriptState.optionalChainMember = true;
  6067. if (noCalls) {
  6068. subscriptState.stop = true;
  6069. return base;
  6070. }
  6071. this.next();
  6072. const node = this.startNodeAt(startLoc);
  6073. node.callee = base;
  6074. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6075. this.expect(10);
  6076. node.arguments = this.parseCallExpressionArguments();
  6077. node.optional = true;
  6078. return this.finishCallExpression(node, true);
  6079. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  6080. const node = this.startNodeAt(startLoc);
  6081. node.callee = base;
  6082. const result = this.tryParse(() => {
  6083. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  6084. this.expect(10);
  6085. node.arguments = super.parseCallExpressionArguments();
  6086. if (subscriptState.optionalChainMember) {
  6087. node.optional = false;
  6088. }
  6089. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  6090. });
  6091. if (result.node) {
  6092. if (result.error) this.state = result.failState;
  6093. return result.node;
  6094. }
  6095. }
  6096. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  6097. }
  6098. parseNewCallee(node) {
  6099. super.parseNewCallee(node);
  6100. let targs = null;
  6101. if (this.shouldParseTypes() && this.match(47)) {
  6102. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  6103. }
  6104. node.typeArguments = targs;
  6105. }
  6106. parseAsyncArrowWithTypeParameters(startLoc) {
  6107. const node = this.startNodeAt(startLoc);
  6108. this.parseFunctionParams(node, false);
  6109. if (!this.parseArrow(node)) return;
  6110. return super.parseArrowExpression(node, undefined, true);
  6111. }
  6112. readToken_mult_modulo(code) {
  6113. const next = this.input.charCodeAt(this.state.pos + 1);
  6114. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  6115. this.state.hasFlowComment = false;
  6116. this.state.pos += 2;
  6117. this.nextToken();
  6118. return;
  6119. }
  6120. super.readToken_mult_modulo(code);
  6121. }
  6122. readToken_pipe_amp(code) {
  6123. const next = this.input.charCodeAt(this.state.pos + 1);
  6124. if (code === 124 && next === 125) {
  6125. this.finishOp(9, 2);
  6126. return;
  6127. }
  6128. super.readToken_pipe_amp(code);
  6129. }
  6130. parseTopLevel(file, program) {
  6131. const fileNode = super.parseTopLevel(file, program);
  6132. if (this.state.hasFlowComment) {
  6133. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  6134. }
  6135. return fileNode;
  6136. }
  6137. skipBlockComment() {
  6138. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  6139. if (this.state.hasFlowComment) {
  6140. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  6141. }
  6142. this.hasFlowCommentCompletion();
  6143. const commentSkip = this.skipFlowComment();
  6144. if (commentSkip) {
  6145. this.state.pos += commentSkip;
  6146. this.state.hasFlowComment = true;
  6147. }
  6148. return;
  6149. }
  6150. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  6151. }
  6152. skipFlowComment() {
  6153. const {
  6154. pos
  6155. } = this.state;
  6156. let shiftToFirstNonWhiteSpace = 2;
  6157. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  6158. shiftToFirstNonWhiteSpace++;
  6159. }
  6160. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6161. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6162. if (ch2 === 58 && ch3 === 58) {
  6163. return shiftToFirstNonWhiteSpace + 2;
  6164. }
  6165. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6166. return shiftToFirstNonWhiteSpace + 12;
  6167. }
  6168. if (ch2 === 58 && ch3 !== 58) {
  6169. return shiftToFirstNonWhiteSpace;
  6170. }
  6171. return false;
  6172. }
  6173. hasFlowCommentCompletion() {
  6174. const end = this.input.indexOf("*/", this.state.pos);
  6175. if (end === -1) {
  6176. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  6177. }
  6178. }
  6179. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6180. enumName,
  6181. memberName
  6182. }) {
  6183. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  6184. memberName,
  6185. enumName
  6186. });
  6187. }
  6188. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6189. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  6190. }
  6191. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  6192. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  6193. }
  6194. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  6195. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  6196. }
  6197. flowEnumMemberInit() {
  6198. const startLoc = this.state.startLoc;
  6199. const endOfInit = () => this.match(12) || this.match(8);
  6200. switch (this.state.type) {
  6201. case 135:
  6202. {
  6203. const literal = this.parseNumericLiteral(this.state.value);
  6204. if (endOfInit()) {
  6205. return {
  6206. type: "number",
  6207. loc: literal.loc.start,
  6208. value: literal
  6209. };
  6210. }
  6211. return {
  6212. type: "invalid",
  6213. loc: startLoc
  6214. };
  6215. }
  6216. case 134:
  6217. {
  6218. const literal = this.parseStringLiteral(this.state.value);
  6219. if (endOfInit()) {
  6220. return {
  6221. type: "string",
  6222. loc: literal.loc.start,
  6223. value: literal
  6224. };
  6225. }
  6226. return {
  6227. type: "invalid",
  6228. loc: startLoc
  6229. };
  6230. }
  6231. case 85:
  6232. case 86:
  6233. {
  6234. const literal = this.parseBooleanLiteral(this.match(85));
  6235. if (endOfInit()) {
  6236. return {
  6237. type: "boolean",
  6238. loc: literal.loc.start,
  6239. value: literal
  6240. };
  6241. }
  6242. return {
  6243. type: "invalid",
  6244. loc: startLoc
  6245. };
  6246. }
  6247. default:
  6248. return {
  6249. type: "invalid",
  6250. loc: startLoc
  6251. };
  6252. }
  6253. }
  6254. flowEnumMemberRaw() {
  6255. const loc = this.state.startLoc;
  6256. const id = this.parseIdentifier(true);
  6257. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6258. type: "none",
  6259. loc
  6260. };
  6261. return {
  6262. id,
  6263. init
  6264. };
  6265. }
  6266. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6267. const {
  6268. explicitType
  6269. } = context;
  6270. if (explicitType === null) {
  6271. return;
  6272. }
  6273. if (explicitType !== expectedType) {
  6274. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6275. }
  6276. }
  6277. flowEnumMembers({
  6278. enumName,
  6279. explicitType
  6280. }) {
  6281. const seenNames = new Set();
  6282. const members = {
  6283. booleanMembers: [],
  6284. numberMembers: [],
  6285. stringMembers: [],
  6286. defaultedMembers: []
  6287. };
  6288. let hasUnknownMembers = false;
  6289. while (!this.match(8)) {
  6290. if (this.eat(21)) {
  6291. hasUnknownMembers = true;
  6292. break;
  6293. }
  6294. const memberNode = this.startNode();
  6295. const {
  6296. id,
  6297. init
  6298. } = this.flowEnumMemberRaw();
  6299. const memberName = id.name;
  6300. if (memberName === "") {
  6301. continue;
  6302. }
  6303. if (/^[a-z]/.test(memberName)) {
  6304. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  6305. memberName,
  6306. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6307. enumName
  6308. });
  6309. }
  6310. if (seenNames.has(memberName)) {
  6311. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6312. memberName,
  6313. enumName
  6314. });
  6315. }
  6316. seenNames.add(memberName);
  6317. const context = {
  6318. enumName,
  6319. explicitType,
  6320. memberName
  6321. };
  6322. memberNode.id = id;
  6323. switch (init.type) {
  6324. case "boolean":
  6325. {
  6326. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6327. memberNode.init = init.value;
  6328. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6329. break;
  6330. }
  6331. case "number":
  6332. {
  6333. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6334. memberNode.init = init.value;
  6335. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6336. break;
  6337. }
  6338. case "string":
  6339. {
  6340. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6341. memberNode.init = init.value;
  6342. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6343. break;
  6344. }
  6345. case "invalid":
  6346. {
  6347. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6348. }
  6349. case "none":
  6350. {
  6351. switch (explicitType) {
  6352. case "boolean":
  6353. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6354. break;
  6355. case "number":
  6356. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6357. break;
  6358. default:
  6359. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6360. }
  6361. }
  6362. }
  6363. if (!this.match(8)) {
  6364. this.expect(12);
  6365. }
  6366. }
  6367. return {
  6368. members,
  6369. hasUnknownMembers
  6370. };
  6371. }
  6372. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6373. enumName
  6374. }) {
  6375. if (initializedMembers.length === 0) {
  6376. return defaultedMembers;
  6377. } else if (defaultedMembers.length === 0) {
  6378. return initializedMembers;
  6379. } else if (defaultedMembers.length > initializedMembers.length) {
  6380. for (const member of initializedMembers) {
  6381. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6382. enumName
  6383. });
  6384. }
  6385. return defaultedMembers;
  6386. } else {
  6387. for (const member of defaultedMembers) {
  6388. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6389. enumName
  6390. });
  6391. }
  6392. return initializedMembers;
  6393. }
  6394. }
  6395. flowEnumParseExplicitType({
  6396. enumName
  6397. }) {
  6398. if (!this.eatContextual(102)) return null;
  6399. if (!tokenIsIdentifier(this.state.type)) {
  6400. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6401. enumName
  6402. });
  6403. }
  6404. const {
  6405. value
  6406. } = this.state;
  6407. this.next();
  6408. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6409. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6410. enumName,
  6411. invalidEnumType: value
  6412. });
  6413. }
  6414. return value;
  6415. }
  6416. flowEnumBody(node, id) {
  6417. const enumName = id.name;
  6418. const nameLoc = id.loc.start;
  6419. const explicitType = this.flowEnumParseExplicitType({
  6420. enumName
  6421. });
  6422. this.expect(5);
  6423. const {
  6424. members,
  6425. hasUnknownMembers
  6426. } = this.flowEnumMembers({
  6427. enumName,
  6428. explicitType
  6429. });
  6430. node.hasUnknownMembers = hasUnknownMembers;
  6431. switch (explicitType) {
  6432. case "boolean":
  6433. node.explicitType = true;
  6434. node.members = members.booleanMembers;
  6435. this.expect(8);
  6436. return this.finishNode(node, "EnumBooleanBody");
  6437. case "number":
  6438. node.explicitType = true;
  6439. node.members = members.numberMembers;
  6440. this.expect(8);
  6441. return this.finishNode(node, "EnumNumberBody");
  6442. case "string":
  6443. node.explicitType = true;
  6444. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6445. enumName
  6446. });
  6447. this.expect(8);
  6448. return this.finishNode(node, "EnumStringBody");
  6449. case "symbol":
  6450. node.members = members.defaultedMembers;
  6451. this.expect(8);
  6452. return this.finishNode(node, "EnumSymbolBody");
  6453. default:
  6454. {
  6455. const empty = () => {
  6456. node.members = [];
  6457. this.expect(8);
  6458. return this.finishNode(node, "EnumStringBody");
  6459. };
  6460. node.explicitType = false;
  6461. const boolsLen = members.booleanMembers.length;
  6462. const numsLen = members.numberMembers.length;
  6463. const strsLen = members.stringMembers.length;
  6464. const defaultedLen = members.defaultedMembers.length;
  6465. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6466. return empty();
  6467. } else if (!boolsLen && !numsLen) {
  6468. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6469. enumName
  6470. });
  6471. this.expect(8);
  6472. return this.finishNode(node, "EnumStringBody");
  6473. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6474. for (const member of members.defaultedMembers) {
  6475. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6476. enumName,
  6477. memberName: member.id.name
  6478. });
  6479. }
  6480. node.members = members.booleanMembers;
  6481. this.expect(8);
  6482. return this.finishNode(node, "EnumBooleanBody");
  6483. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6484. for (const member of members.defaultedMembers) {
  6485. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6486. enumName,
  6487. memberName: member.id.name
  6488. });
  6489. }
  6490. node.members = members.numberMembers;
  6491. this.expect(8);
  6492. return this.finishNode(node, "EnumNumberBody");
  6493. } else {
  6494. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6495. enumName
  6496. });
  6497. return empty();
  6498. }
  6499. }
  6500. }
  6501. }
  6502. flowParseEnumDeclaration(node) {
  6503. const id = this.parseIdentifier();
  6504. node.id = id;
  6505. node.body = this.flowEnumBody(this.startNode(), id);
  6506. return this.finishNode(node, "EnumDeclaration");
  6507. }
  6508. jsxParseOpeningElementAfterName(node) {
  6509. if (this.shouldParseTypes()) {
  6510. if (this.match(47) || this.match(51)) {
  6511. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6512. }
  6513. }
  6514. return super.jsxParseOpeningElementAfterName(node);
  6515. }
  6516. isLookaheadToken_lt() {
  6517. const next = this.nextTokenStart();
  6518. if (this.input.charCodeAt(next) === 60) {
  6519. const afterNext = this.input.charCodeAt(next + 1);
  6520. return afterNext !== 60 && afterNext !== 61;
  6521. }
  6522. return false;
  6523. }
  6524. reScan_lt_gt() {
  6525. const {
  6526. type
  6527. } = this.state;
  6528. if (type === 47) {
  6529. this.state.pos -= 1;
  6530. this.readToken_lt();
  6531. } else if (type === 48) {
  6532. this.state.pos -= 1;
  6533. this.readToken_gt();
  6534. }
  6535. }
  6536. reScan_lt() {
  6537. const {
  6538. type
  6539. } = this.state;
  6540. if (type === 51) {
  6541. this.state.pos -= 2;
  6542. this.finishOp(47, 1);
  6543. return 47;
  6544. }
  6545. return type;
  6546. }
  6547. maybeUnwrapTypeCastExpression(node) {
  6548. return node.type === "TypeCastExpression" ? node.expression : node;
  6549. }
  6550. };
  6551. const entities = {
  6552. __proto__: null,
  6553. quot: "\u0022",
  6554. amp: "&",
  6555. apos: "\u0027",
  6556. lt: "<",
  6557. gt: ">",
  6558. nbsp: "\u00A0",
  6559. iexcl: "\u00A1",
  6560. cent: "\u00A2",
  6561. pound: "\u00A3",
  6562. curren: "\u00A4",
  6563. yen: "\u00A5",
  6564. brvbar: "\u00A6",
  6565. sect: "\u00A7",
  6566. uml: "\u00A8",
  6567. copy: "\u00A9",
  6568. ordf: "\u00AA",
  6569. laquo: "\u00AB",
  6570. not: "\u00AC",
  6571. shy: "\u00AD",
  6572. reg: "\u00AE",
  6573. macr: "\u00AF",
  6574. deg: "\u00B0",
  6575. plusmn: "\u00B1",
  6576. sup2: "\u00B2",
  6577. sup3: "\u00B3",
  6578. acute: "\u00B4",
  6579. micro: "\u00B5",
  6580. para: "\u00B6",
  6581. middot: "\u00B7",
  6582. cedil: "\u00B8",
  6583. sup1: "\u00B9",
  6584. ordm: "\u00BA",
  6585. raquo: "\u00BB",
  6586. frac14: "\u00BC",
  6587. frac12: "\u00BD",
  6588. frac34: "\u00BE",
  6589. iquest: "\u00BF",
  6590. Agrave: "\u00C0",
  6591. Aacute: "\u00C1",
  6592. Acirc: "\u00C2",
  6593. Atilde: "\u00C3",
  6594. Auml: "\u00C4",
  6595. Aring: "\u00C5",
  6596. AElig: "\u00C6",
  6597. Ccedil: "\u00C7",
  6598. Egrave: "\u00C8",
  6599. Eacute: "\u00C9",
  6600. Ecirc: "\u00CA",
  6601. Euml: "\u00CB",
  6602. Igrave: "\u00CC",
  6603. Iacute: "\u00CD",
  6604. Icirc: "\u00CE",
  6605. Iuml: "\u00CF",
  6606. ETH: "\u00D0",
  6607. Ntilde: "\u00D1",
  6608. Ograve: "\u00D2",
  6609. Oacute: "\u00D3",
  6610. Ocirc: "\u00D4",
  6611. Otilde: "\u00D5",
  6612. Ouml: "\u00D6",
  6613. times: "\u00D7",
  6614. Oslash: "\u00D8",
  6615. Ugrave: "\u00D9",
  6616. Uacute: "\u00DA",
  6617. Ucirc: "\u00DB",
  6618. Uuml: "\u00DC",
  6619. Yacute: "\u00DD",
  6620. THORN: "\u00DE",
  6621. szlig: "\u00DF",
  6622. agrave: "\u00E0",
  6623. aacute: "\u00E1",
  6624. acirc: "\u00E2",
  6625. atilde: "\u00E3",
  6626. auml: "\u00E4",
  6627. aring: "\u00E5",
  6628. aelig: "\u00E6",
  6629. ccedil: "\u00E7",
  6630. egrave: "\u00E8",
  6631. eacute: "\u00E9",
  6632. ecirc: "\u00EA",
  6633. euml: "\u00EB",
  6634. igrave: "\u00EC",
  6635. iacute: "\u00ED",
  6636. icirc: "\u00EE",
  6637. iuml: "\u00EF",
  6638. eth: "\u00F0",
  6639. ntilde: "\u00F1",
  6640. ograve: "\u00F2",
  6641. oacute: "\u00F3",
  6642. ocirc: "\u00F4",
  6643. otilde: "\u00F5",
  6644. ouml: "\u00F6",
  6645. divide: "\u00F7",
  6646. oslash: "\u00F8",
  6647. ugrave: "\u00F9",
  6648. uacute: "\u00FA",
  6649. ucirc: "\u00FB",
  6650. uuml: "\u00FC",
  6651. yacute: "\u00FD",
  6652. thorn: "\u00FE",
  6653. yuml: "\u00FF",
  6654. OElig: "\u0152",
  6655. oelig: "\u0153",
  6656. Scaron: "\u0160",
  6657. scaron: "\u0161",
  6658. Yuml: "\u0178",
  6659. fnof: "\u0192",
  6660. circ: "\u02C6",
  6661. tilde: "\u02DC",
  6662. Alpha: "\u0391",
  6663. Beta: "\u0392",
  6664. Gamma: "\u0393",
  6665. Delta: "\u0394",
  6666. Epsilon: "\u0395",
  6667. Zeta: "\u0396",
  6668. Eta: "\u0397",
  6669. Theta: "\u0398",
  6670. Iota: "\u0399",
  6671. Kappa: "\u039A",
  6672. Lambda: "\u039B",
  6673. Mu: "\u039C",
  6674. Nu: "\u039D",
  6675. Xi: "\u039E",
  6676. Omicron: "\u039F",
  6677. Pi: "\u03A0",
  6678. Rho: "\u03A1",
  6679. Sigma: "\u03A3",
  6680. Tau: "\u03A4",
  6681. Upsilon: "\u03A5",
  6682. Phi: "\u03A6",
  6683. Chi: "\u03A7",
  6684. Psi: "\u03A8",
  6685. Omega: "\u03A9",
  6686. alpha: "\u03B1",
  6687. beta: "\u03B2",
  6688. gamma: "\u03B3",
  6689. delta: "\u03B4",
  6690. epsilon: "\u03B5",
  6691. zeta: "\u03B6",
  6692. eta: "\u03B7",
  6693. theta: "\u03B8",
  6694. iota: "\u03B9",
  6695. kappa: "\u03BA",
  6696. lambda: "\u03BB",
  6697. mu: "\u03BC",
  6698. nu: "\u03BD",
  6699. xi: "\u03BE",
  6700. omicron: "\u03BF",
  6701. pi: "\u03C0",
  6702. rho: "\u03C1",
  6703. sigmaf: "\u03C2",
  6704. sigma: "\u03C3",
  6705. tau: "\u03C4",
  6706. upsilon: "\u03C5",
  6707. phi: "\u03C6",
  6708. chi: "\u03C7",
  6709. psi: "\u03C8",
  6710. omega: "\u03C9",
  6711. thetasym: "\u03D1",
  6712. upsih: "\u03D2",
  6713. piv: "\u03D6",
  6714. ensp: "\u2002",
  6715. emsp: "\u2003",
  6716. thinsp: "\u2009",
  6717. zwnj: "\u200C",
  6718. zwj: "\u200D",
  6719. lrm: "\u200E",
  6720. rlm: "\u200F",
  6721. ndash: "\u2013",
  6722. mdash: "\u2014",
  6723. lsquo: "\u2018",
  6724. rsquo: "\u2019",
  6725. sbquo: "\u201A",
  6726. ldquo: "\u201C",
  6727. rdquo: "\u201D",
  6728. bdquo: "\u201E",
  6729. dagger: "\u2020",
  6730. Dagger: "\u2021",
  6731. bull: "\u2022",
  6732. hellip: "\u2026",
  6733. permil: "\u2030",
  6734. prime: "\u2032",
  6735. Prime: "\u2033",
  6736. lsaquo: "\u2039",
  6737. rsaquo: "\u203A",
  6738. oline: "\u203E",
  6739. frasl: "\u2044",
  6740. euro: "\u20AC",
  6741. image: "\u2111",
  6742. weierp: "\u2118",
  6743. real: "\u211C",
  6744. trade: "\u2122",
  6745. alefsym: "\u2135",
  6746. larr: "\u2190",
  6747. uarr: "\u2191",
  6748. rarr: "\u2192",
  6749. darr: "\u2193",
  6750. harr: "\u2194",
  6751. crarr: "\u21B5",
  6752. lArr: "\u21D0",
  6753. uArr: "\u21D1",
  6754. rArr: "\u21D2",
  6755. dArr: "\u21D3",
  6756. hArr: "\u21D4",
  6757. forall: "\u2200",
  6758. part: "\u2202",
  6759. exist: "\u2203",
  6760. empty: "\u2205",
  6761. nabla: "\u2207",
  6762. isin: "\u2208",
  6763. notin: "\u2209",
  6764. ni: "\u220B",
  6765. prod: "\u220F",
  6766. sum: "\u2211",
  6767. minus: "\u2212",
  6768. lowast: "\u2217",
  6769. radic: "\u221A",
  6770. prop: "\u221D",
  6771. infin: "\u221E",
  6772. ang: "\u2220",
  6773. and: "\u2227",
  6774. or: "\u2228",
  6775. cap: "\u2229",
  6776. cup: "\u222A",
  6777. int: "\u222B",
  6778. there4: "\u2234",
  6779. sim: "\u223C",
  6780. cong: "\u2245",
  6781. asymp: "\u2248",
  6782. ne: "\u2260",
  6783. equiv: "\u2261",
  6784. le: "\u2264",
  6785. ge: "\u2265",
  6786. sub: "\u2282",
  6787. sup: "\u2283",
  6788. nsub: "\u2284",
  6789. sube: "\u2286",
  6790. supe: "\u2287",
  6791. oplus: "\u2295",
  6792. otimes: "\u2297",
  6793. perp: "\u22A5",
  6794. sdot: "\u22C5",
  6795. lceil: "\u2308",
  6796. rceil: "\u2309",
  6797. lfloor: "\u230A",
  6798. rfloor: "\u230B",
  6799. lang: "\u2329",
  6800. rang: "\u232A",
  6801. loz: "\u25CA",
  6802. spades: "\u2660",
  6803. clubs: "\u2663",
  6804. hearts: "\u2665",
  6805. diams: "\u2666"
  6806. };
  6807. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  6808. const lineBreakG = new RegExp(lineBreak.source, "g");
  6809. function isNewLine(code) {
  6810. switch (code) {
  6811. case 10:
  6812. case 13:
  6813. case 8232:
  6814. case 8233:
  6815. return true;
  6816. default:
  6817. return false;
  6818. }
  6819. }
  6820. function hasNewLine(input, start, end) {
  6821. for (let i = start; i < end; i++) {
  6822. if (isNewLine(input.charCodeAt(i))) {
  6823. return true;
  6824. }
  6825. }
  6826. return false;
  6827. }
  6828. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  6829. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  6830. function isWhitespace(code) {
  6831. switch (code) {
  6832. case 0x0009:
  6833. case 0x000b:
  6834. case 0x000c:
  6835. case 32:
  6836. case 160:
  6837. case 5760:
  6838. case 0x2000:
  6839. case 0x2001:
  6840. case 0x2002:
  6841. case 0x2003:
  6842. case 0x2004:
  6843. case 0x2005:
  6844. case 0x2006:
  6845. case 0x2007:
  6846. case 0x2008:
  6847. case 0x2009:
  6848. case 0x200a:
  6849. case 0x202f:
  6850. case 0x205f:
  6851. case 0x3000:
  6852. case 0xfeff:
  6853. return true;
  6854. default:
  6855. return false;
  6856. }
  6857. }
  6858. const JsxErrors = ParseErrorEnum`jsx`({
  6859. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6860. MissingClosingTagElement: ({
  6861. openingTagName
  6862. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6863. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6864. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6865. UnexpectedToken: ({
  6866. unexpected,
  6867. HTMLEntity
  6868. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6869. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6870. UnterminatedJsxContent: "Unterminated JSX contents.",
  6871. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6872. });
  6873. function isFragment(object) {
  6874. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6875. }
  6876. function getQualifiedJSXName(object) {
  6877. if (object.type === "JSXIdentifier") {
  6878. return object.name;
  6879. }
  6880. if (object.type === "JSXNamespacedName") {
  6881. return object.namespace.name + ":" + object.name.name;
  6882. }
  6883. if (object.type === "JSXMemberExpression") {
  6884. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6885. }
  6886. throw new Error("Node had unexpected type: " + object.type);
  6887. }
  6888. var jsx = superClass => class JSXParserMixin extends superClass {
  6889. jsxReadToken() {
  6890. let out = "";
  6891. let chunkStart = this.state.pos;
  6892. for (;;) {
  6893. if (this.state.pos >= this.length) {
  6894. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6895. }
  6896. const ch = this.input.charCodeAt(this.state.pos);
  6897. switch (ch) {
  6898. case 60:
  6899. case 123:
  6900. if (this.state.pos === this.state.start) {
  6901. if (ch === 60 && this.state.canStartJSXElement) {
  6902. ++this.state.pos;
  6903. this.finishToken(143);
  6904. } else {
  6905. super.getTokenFromCode(ch);
  6906. }
  6907. return;
  6908. }
  6909. out += this.input.slice(chunkStart, this.state.pos);
  6910. this.finishToken(142, out);
  6911. return;
  6912. case 38:
  6913. out += this.input.slice(chunkStart, this.state.pos);
  6914. out += this.jsxReadEntity();
  6915. chunkStart = this.state.pos;
  6916. break;
  6917. case 62:
  6918. case 125:
  6919. default:
  6920. if (isNewLine(ch)) {
  6921. out += this.input.slice(chunkStart, this.state.pos);
  6922. out += this.jsxReadNewLine(true);
  6923. chunkStart = this.state.pos;
  6924. } else {
  6925. ++this.state.pos;
  6926. }
  6927. }
  6928. }
  6929. }
  6930. jsxReadNewLine(normalizeCRLF) {
  6931. const ch = this.input.charCodeAt(this.state.pos);
  6932. let out;
  6933. ++this.state.pos;
  6934. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6935. ++this.state.pos;
  6936. out = normalizeCRLF ? "\n" : "\r\n";
  6937. } else {
  6938. out = String.fromCharCode(ch);
  6939. }
  6940. ++this.state.curLine;
  6941. this.state.lineStart = this.state.pos;
  6942. return out;
  6943. }
  6944. jsxReadString(quote) {
  6945. let out = "";
  6946. let chunkStart = ++this.state.pos;
  6947. for (;;) {
  6948. if (this.state.pos >= this.length) {
  6949. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6950. }
  6951. const ch = this.input.charCodeAt(this.state.pos);
  6952. if (ch === quote) break;
  6953. if (ch === 38) {
  6954. out += this.input.slice(chunkStart, this.state.pos);
  6955. out += this.jsxReadEntity();
  6956. chunkStart = this.state.pos;
  6957. } else if (isNewLine(ch)) {
  6958. out += this.input.slice(chunkStart, this.state.pos);
  6959. out += this.jsxReadNewLine(false);
  6960. chunkStart = this.state.pos;
  6961. } else {
  6962. ++this.state.pos;
  6963. }
  6964. }
  6965. out += this.input.slice(chunkStart, this.state.pos++);
  6966. this.finishToken(134, out);
  6967. }
  6968. jsxReadEntity() {
  6969. const startPos = ++this.state.pos;
  6970. if (this.codePointAtPos(this.state.pos) === 35) {
  6971. ++this.state.pos;
  6972. let radix = 10;
  6973. if (this.codePointAtPos(this.state.pos) === 120) {
  6974. radix = 16;
  6975. ++this.state.pos;
  6976. }
  6977. const codePoint = this.readInt(radix, undefined, false, "bail");
  6978. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6979. ++this.state.pos;
  6980. return String.fromCodePoint(codePoint);
  6981. }
  6982. } else {
  6983. let count = 0;
  6984. let semi = false;
  6985. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6986. ++this.state.pos;
  6987. }
  6988. if (semi) {
  6989. const desc = this.input.slice(startPos, this.state.pos);
  6990. const entity = entities[desc];
  6991. ++this.state.pos;
  6992. if (entity) {
  6993. return entity;
  6994. }
  6995. }
  6996. }
  6997. this.state.pos = startPos;
  6998. return "&";
  6999. }
  7000. jsxReadWord() {
  7001. let ch;
  7002. const start = this.state.pos;
  7003. do {
  7004. ch = this.input.charCodeAt(++this.state.pos);
  7005. } while (isIdentifierChar(ch) || ch === 45);
  7006. this.finishToken(141, this.input.slice(start, this.state.pos));
  7007. }
  7008. jsxParseIdentifier() {
  7009. const node = this.startNode();
  7010. if (this.match(141)) {
  7011. node.name = this.state.value;
  7012. } else if (tokenIsKeyword(this.state.type)) {
  7013. node.name = tokenLabelName(this.state.type);
  7014. } else {
  7015. this.unexpected();
  7016. }
  7017. this.next();
  7018. return this.finishNode(node, "JSXIdentifier");
  7019. }
  7020. jsxParseNamespacedName() {
  7021. const startLoc = this.state.startLoc;
  7022. const name = this.jsxParseIdentifier();
  7023. if (!this.eat(14)) return name;
  7024. const node = this.startNodeAt(startLoc);
  7025. node.namespace = name;
  7026. node.name = this.jsxParseIdentifier();
  7027. return this.finishNode(node, "JSXNamespacedName");
  7028. }
  7029. jsxParseElementName() {
  7030. const startLoc = this.state.startLoc;
  7031. let node = this.jsxParseNamespacedName();
  7032. if (node.type === "JSXNamespacedName") {
  7033. return node;
  7034. }
  7035. while (this.eat(16)) {
  7036. const newNode = this.startNodeAt(startLoc);
  7037. newNode.object = node;
  7038. newNode.property = this.jsxParseIdentifier();
  7039. node = this.finishNode(newNode, "JSXMemberExpression");
  7040. }
  7041. return node;
  7042. }
  7043. jsxParseAttributeValue() {
  7044. let node;
  7045. switch (this.state.type) {
  7046. case 5:
  7047. node = this.startNode();
  7048. this.setContext(types.brace);
  7049. this.next();
  7050. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  7051. if (node.expression.type === "JSXEmptyExpression") {
  7052. this.raise(JsxErrors.AttributeIsEmpty, node);
  7053. }
  7054. return node;
  7055. case 143:
  7056. case 134:
  7057. return this.parseExprAtom();
  7058. default:
  7059. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  7060. }
  7061. }
  7062. jsxParseEmptyExpression() {
  7063. const node = this.startNodeAt(this.state.lastTokEndLoc);
  7064. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  7065. }
  7066. jsxParseSpreadChild(node) {
  7067. this.next();
  7068. node.expression = this.parseExpression();
  7069. this.setContext(types.j_expr);
  7070. this.state.canStartJSXElement = true;
  7071. this.expect(8);
  7072. return this.finishNode(node, "JSXSpreadChild");
  7073. }
  7074. jsxParseExpressionContainer(node, previousContext) {
  7075. if (this.match(8)) {
  7076. node.expression = this.jsxParseEmptyExpression();
  7077. } else {
  7078. const expression = this.parseExpression();
  7079. node.expression = expression;
  7080. }
  7081. this.setContext(previousContext);
  7082. this.state.canStartJSXElement = true;
  7083. this.expect(8);
  7084. return this.finishNode(node, "JSXExpressionContainer");
  7085. }
  7086. jsxParseAttribute() {
  7087. const node = this.startNode();
  7088. if (this.match(5)) {
  7089. this.setContext(types.brace);
  7090. this.next();
  7091. this.expect(21);
  7092. node.argument = this.parseMaybeAssignAllowIn();
  7093. this.setContext(types.j_oTag);
  7094. this.state.canStartJSXElement = true;
  7095. this.expect(8);
  7096. return this.finishNode(node, "JSXSpreadAttribute");
  7097. }
  7098. node.name = this.jsxParseNamespacedName();
  7099. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  7100. return this.finishNode(node, "JSXAttribute");
  7101. }
  7102. jsxParseOpeningElementAt(startLoc) {
  7103. const node = this.startNodeAt(startLoc);
  7104. if (this.eat(144)) {
  7105. return this.finishNode(node, "JSXOpeningFragment");
  7106. }
  7107. node.name = this.jsxParseElementName();
  7108. return this.jsxParseOpeningElementAfterName(node);
  7109. }
  7110. jsxParseOpeningElementAfterName(node) {
  7111. const attributes = [];
  7112. while (!this.match(56) && !this.match(144)) {
  7113. attributes.push(this.jsxParseAttribute());
  7114. }
  7115. node.attributes = attributes;
  7116. node.selfClosing = this.eat(56);
  7117. this.expect(144);
  7118. return this.finishNode(node, "JSXOpeningElement");
  7119. }
  7120. jsxParseClosingElementAt(startLoc) {
  7121. const node = this.startNodeAt(startLoc);
  7122. if (this.eat(144)) {
  7123. return this.finishNode(node, "JSXClosingFragment");
  7124. }
  7125. node.name = this.jsxParseElementName();
  7126. this.expect(144);
  7127. return this.finishNode(node, "JSXClosingElement");
  7128. }
  7129. jsxParseElementAt(startLoc) {
  7130. const node = this.startNodeAt(startLoc);
  7131. const children = [];
  7132. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  7133. let closingElement = null;
  7134. if (!openingElement.selfClosing) {
  7135. contents: for (;;) {
  7136. switch (this.state.type) {
  7137. case 143:
  7138. startLoc = this.state.startLoc;
  7139. this.next();
  7140. if (this.eat(56)) {
  7141. closingElement = this.jsxParseClosingElementAt(startLoc);
  7142. break contents;
  7143. }
  7144. children.push(this.jsxParseElementAt(startLoc));
  7145. break;
  7146. case 142:
  7147. children.push(this.parseLiteral(this.state.value, "JSXText"));
  7148. break;
  7149. case 5:
  7150. {
  7151. const node = this.startNode();
  7152. this.setContext(types.brace);
  7153. this.next();
  7154. if (this.match(21)) {
  7155. children.push(this.jsxParseSpreadChild(node));
  7156. } else {
  7157. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  7158. }
  7159. break;
  7160. }
  7161. default:
  7162. this.unexpected();
  7163. }
  7164. }
  7165. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  7166. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  7167. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  7168. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  7169. openingTagName: getQualifiedJSXName(openingElement.name)
  7170. });
  7171. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  7172. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  7173. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  7174. openingTagName: getQualifiedJSXName(openingElement.name)
  7175. });
  7176. }
  7177. }
  7178. }
  7179. if (isFragment(openingElement)) {
  7180. node.openingFragment = openingElement;
  7181. node.closingFragment = closingElement;
  7182. } else {
  7183. node.openingElement = openingElement;
  7184. node.closingElement = closingElement;
  7185. }
  7186. node.children = children;
  7187. if (this.match(47)) {
  7188. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  7189. }
  7190. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  7191. }
  7192. jsxParseElement() {
  7193. const startLoc = this.state.startLoc;
  7194. this.next();
  7195. return this.jsxParseElementAt(startLoc);
  7196. }
  7197. setContext(newContext) {
  7198. const {
  7199. context
  7200. } = this.state;
  7201. context[context.length - 1] = newContext;
  7202. }
  7203. parseExprAtom(refExpressionErrors) {
  7204. if (this.match(143)) {
  7205. return this.jsxParseElement();
  7206. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7207. this.replaceToken(143);
  7208. return this.jsxParseElement();
  7209. } else {
  7210. return super.parseExprAtom(refExpressionErrors);
  7211. }
  7212. }
  7213. skipSpace() {
  7214. const curContext = this.curContext();
  7215. if (!curContext.preserveSpace) super.skipSpace();
  7216. }
  7217. getTokenFromCode(code) {
  7218. const context = this.curContext();
  7219. if (context === types.j_expr) {
  7220. this.jsxReadToken();
  7221. return;
  7222. }
  7223. if (context === types.j_oTag || context === types.j_cTag) {
  7224. if (isIdentifierStart(code)) {
  7225. this.jsxReadWord();
  7226. return;
  7227. }
  7228. if (code === 62) {
  7229. ++this.state.pos;
  7230. this.finishToken(144);
  7231. return;
  7232. }
  7233. if ((code === 34 || code === 39) && context === types.j_oTag) {
  7234. this.jsxReadString(code);
  7235. return;
  7236. }
  7237. }
  7238. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7239. ++this.state.pos;
  7240. this.finishToken(143);
  7241. return;
  7242. }
  7243. super.getTokenFromCode(code);
  7244. }
  7245. updateContext(prevType) {
  7246. const {
  7247. context,
  7248. type
  7249. } = this.state;
  7250. if (type === 56 && prevType === 143) {
  7251. context.splice(-2, 2, types.j_cTag);
  7252. this.state.canStartJSXElement = false;
  7253. } else if (type === 143) {
  7254. context.push(types.j_oTag);
  7255. } else if (type === 144) {
  7256. const out = context[context.length - 1];
  7257. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  7258. context.pop();
  7259. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  7260. } else {
  7261. this.setContext(types.j_expr);
  7262. this.state.canStartJSXElement = true;
  7263. }
  7264. } else {
  7265. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7266. }
  7267. }
  7268. };
  7269. class TypeScriptScope extends Scope {
  7270. constructor(...args) {
  7271. super(...args);
  7272. this.tsNames = new Map();
  7273. }
  7274. }
  7275. class TypeScriptScopeHandler extends ScopeHandler {
  7276. constructor(...args) {
  7277. super(...args);
  7278. this.importsStack = [];
  7279. }
  7280. createScope(flags) {
  7281. this.importsStack.push(new Set());
  7282. return new TypeScriptScope(flags);
  7283. }
  7284. enter(flags) {
  7285. if (flags === 1024) {
  7286. this.importsStack.push(new Set());
  7287. }
  7288. super.enter(flags);
  7289. }
  7290. exit() {
  7291. const flags = super.exit();
  7292. if (flags === 1024) {
  7293. this.importsStack.pop();
  7294. }
  7295. return flags;
  7296. }
  7297. hasImport(name, allowShadow) {
  7298. const len = this.importsStack.length;
  7299. if (this.importsStack[len - 1].has(name)) {
  7300. return true;
  7301. }
  7302. if (!allowShadow && len > 1) {
  7303. for (let i = 0; i < len - 1; i++) {
  7304. if (this.importsStack[i].has(name)) return true;
  7305. }
  7306. }
  7307. return false;
  7308. }
  7309. declareName(name, bindingType, loc) {
  7310. if (bindingType & 4096) {
  7311. if (this.hasImport(name, true)) {
  7312. this.parser.raise(Errors.VarRedeclaration, loc, {
  7313. identifierName: name
  7314. });
  7315. }
  7316. this.importsStack[this.importsStack.length - 1].add(name);
  7317. return;
  7318. }
  7319. const scope = this.currentScope();
  7320. let type = scope.tsNames.get(name) || 0;
  7321. if (bindingType & 1024) {
  7322. this.maybeExportDefined(scope, name);
  7323. scope.tsNames.set(name, type | 16);
  7324. return;
  7325. }
  7326. super.declareName(name, bindingType, loc);
  7327. if (bindingType & 2) {
  7328. if (!(bindingType & 1)) {
  7329. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7330. this.maybeExportDefined(scope, name);
  7331. }
  7332. type = type | 1;
  7333. }
  7334. if (bindingType & 256) {
  7335. type = type | 2;
  7336. }
  7337. if (bindingType & 512) {
  7338. type = type | 4;
  7339. }
  7340. if (bindingType & 128) {
  7341. type = type | 8;
  7342. }
  7343. if (type) scope.tsNames.set(name, type);
  7344. }
  7345. isRedeclaredInScope(scope, name, bindingType) {
  7346. const type = scope.tsNames.get(name);
  7347. if ((type & 2) > 0) {
  7348. if (bindingType & 256) {
  7349. const isConst = !!(bindingType & 512);
  7350. const wasConst = (type & 4) > 0;
  7351. return isConst !== wasConst;
  7352. }
  7353. return true;
  7354. }
  7355. if (bindingType & 128 && (type & 8) > 0) {
  7356. if (scope.names.get(name) & 2) {
  7357. return !!(bindingType & 1);
  7358. } else {
  7359. return false;
  7360. }
  7361. }
  7362. if (bindingType & 2 && (type & 1) > 0) {
  7363. return true;
  7364. }
  7365. return super.isRedeclaredInScope(scope, name, bindingType);
  7366. }
  7367. checkLocalExport(id) {
  7368. const {
  7369. name
  7370. } = id;
  7371. if (this.hasImport(name)) return;
  7372. const len = this.scopeStack.length;
  7373. for (let i = len - 1; i >= 0; i--) {
  7374. const scope = this.scopeStack[i];
  7375. const type = scope.tsNames.get(name);
  7376. if ((type & 1) > 0 || (type & 16) > 0) {
  7377. return;
  7378. }
  7379. }
  7380. super.checkLocalExport(id);
  7381. }
  7382. }
  7383. class ProductionParameterHandler {
  7384. constructor() {
  7385. this.stacks = [];
  7386. }
  7387. enter(flags) {
  7388. this.stacks.push(flags);
  7389. }
  7390. exit() {
  7391. this.stacks.pop();
  7392. }
  7393. currentFlags() {
  7394. return this.stacks[this.stacks.length - 1];
  7395. }
  7396. get hasAwait() {
  7397. return (this.currentFlags() & 2) > 0;
  7398. }
  7399. get hasYield() {
  7400. return (this.currentFlags() & 1) > 0;
  7401. }
  7402. get hasReturn() {
  7403. return (this.currentFlags() & 4) > 0;
  7404. }
  7405. get hasIn() {
  7406. return (this.currentFlags() & 8) > 0;
  7407. }
  7408. }
  7409. function functionFlags(isAsync, isGenerator) {
  7410. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  7411. }
  7412. class BaseParser {
  7413. constructor() {
  7414. this.sawUnambiguousESM = false;
  7415. this.ambiguousScriptDifferentAst = false;
  7416. }
  7417. sourceToOffsetPos(sourcePos) {
  7418. return sourcePos + this.startIndex;
  7419. }
  7420. offsetToSourcePos(offsetPos) {
  7421. return offsetPos - this.startIndex;
  7422. }
  7423. hasPlugin(pluginConfig) {
  7424. if (typeof pluginConfig === "string") {
  7425. return this.plugins.has(pluginConfig);
  7426. } else {
  7427. const [pluginName, pluginOptions] = pluginConfig;
  7428. if (!this.hasPlugin(pluginName)) {
  7429. return false;
  7430. }
  7431. const actualOptions = this.plugins.get(pluginName);
  7432. for (const key of Object.keys(pluginOptions)) {
  7433. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  7434. return false;
  7435. }
  7436. }
  7437. return true;
  7438. }
  7439. }
  7440. getPluginOption(plugin, name) {
  7441. var _this$plugins$get;
  7442. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  7443. }
  7444. }
  7445. function setTrailingComments(node, comments) {
  7446. if (node.trailingComments === undefined) {
  7447. node.trailingComments = comments;
  7448. } else {
  7449. node.trailingComments.unshift(...comments);
  7450. }
  7451. }
  7452. function setLeadingComments(node, comments) {
  7453. if (node.leadingComments === undefined) {
  7454. node.leadingComments = comments;
  7455. } else {
  7456. node.leadingComments.unshift(...comments);
  7457. }
  7458. }
  7459. function setInnerComments(node, comments) {
  7460. if (node.innerComments === undefined) {
  7461. node.innerComments = comments;
  7462. } else {
  7463. node.innerComments.unshift(...comments);
  7464. }
  7465. }
  7466. function adjustInnerComments(node, elements, commentWS) {
  7467. let lastElement = null;
  7468. let i = elements.length;
  7469. while (lastElement === null && i > 0) {
  7470. lastElement = elements[--i];
  7471. }
  7472. if (lastElement === null || lastElement.start > commentWS.start) {
  7473. setInnerComments(node, commentWS.comments);
  7474. } else {
  7475. setTrailingComments(lastElement, commentWS.comments);
  7476. }
  7477. }
  7478. class CommentsParser extends BaseParser {
  7479. addComment(comment) {
  7480. if (this.filename) comment.loc.filename = this.filename;
  7481. const {
  7482. commentsLen
  7483. } = this.state;
  7484. if (this.comments.length !== commentsLen) {
  7485. this.comments.length = commentsLen;
  7486. }
  7487. this.comments.push(comment);
  7488. this.state.commentsLen++;
  7489. }
  7490. processComment(node) {
  7491. const {
  7492. commentStack
  7493. } = this.state;
  7494. const commentStackLength = commentStack.length;
  7495. if (commentStackLength === 0) return;
  7496. let i = commentStackLength - 1;
  7497. const lastCommentWS = commentStack[i];
  7498. if (lastCommentWS.start === node.end) {
  7499. lastCommentWS.leadingNode = node;
  7500. i--;
  7501. }
  7502. const {
  7503. start: nodeStart
  7504. } = node;
  7505. for (; i >= 0; i--) {
  7506. const commentWS = commentStack[i];
  7507. const commentEnd = commentWS.end;
  7508. if (commentEnd > nodeStart) {
  7509. commentWS.containingNode = node;
  7510. this.finalizeComment(commentWS);
  7511. commentStack.splice(i, 1);
  7512. } else {
  7513. if (commentEnd === nodeStart) {
  7514. commentWS.trailingNode = node;
  7515. }
  7516. break;
  7517. }
  7518. }
  7519. }
  7520. finalizeComment(commentWS) {
  7521. var _node$options;
  7522. const {
  7523. comments
  7524. } = commentWS;
  7525. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  7526. if (commentWS.leadingNode !== null) {
  7527. setTrailingComments(commentWS.leadingNode, comments);
  7528. }
  7529. if (commentWS.trailingNode !== null) {
  7530. setLeadingComments(commentWS.trailingNode, comments);
  7531. }
  7532. } else {
  7533. const {
  7534. containingNode: node,
  7535. start: commentStart
  7536. } = commentWS;
  7537. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  7538. switch (node.type) {
  7539. case "ObjectExpression":
  7540. case "ObjectPattern":
  7541. case "RecordExpression":
  7542. adjustInnerComments(node, node.properties, commentWS);
  7543. break;
  7544. case "CallExpression":
  7545. case "OptionalCallExpression":
  7546. adjustInnerComments(node, node.arguments, commentWS);
  7547. break;
  7548. case "ImportExpression":
  7549. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  7550. break;
  7551. case "FunctionDeclaration":
  7552. case "FunctionExpression":
  7553. case "ArrowFunctionExpression":
  7554. case "ObjectMethod":
  7555. case "ClassMethod":
  7556. case "ClassPrivateMethod":
  7557. adjustInnerComments(node, node.params, commentWS);
  7558. break;
  7559. case "ArrayExpression":
  7560. case "ArrayPattern":
  7561. case "TupleExpression":
  7562. adjustInnerComments(node, node.elements, commentWS);
  7563. break;
  7564. case "ExportNamedDeclaration":
  7565. case "ImportDeclaration":
  7566. adjustInnerComments(node, node.specifiers, commentWS);
  7567. break;
  7568. case "TSEnumDeclaration":
  7569. {
  7570. adjustInnerComments(node, node.members, commentWS);
  7571. }
  7572. break;
  7573. case "TSEnumBody":
  7574. adjustInnerComments(node, node.members, commentWS);
  7575. break;
  7576. default:
  7577. {
  7578. setInnerComments(node, comments);
  7579. }
  7580. }
  7581. } else {
  7582. setInnerComments(node, comments);
  7583. }
  7584. }
  7585. }
  7586. finalizeRemainingComments() {
  7587. const {
  7588. commentStack
  7589. } = this.state;
  7590. for (let i = commentStack.length - 1; i >= 0; i--) {
  7591. this.finalizeComment(commentStack[i]);
  7592. }
  7593. this.state.commentStack = [];
  7594. }
  7595. resetPreviousNodeTrailingComments(node) {
  7596. const {
  7597. commentStack
  7598. } = this.state;
  7599. const {
  7600. length
  7601. } = commentStack;
  7602. if (length === 0) return;
  7603. const commentWS = commentStack[length - 1];
  7604. if (commentWS.leadingNode === node) {
  7605. commentWS.leadingNode = null;
  7606. }
  7607. }
  7608. takeSurroundingComments(node, start, end) {
  7609. const {
  7610. commentStack
  7611. } = this.state;
  7612. const commentStackLength = commentStack.length;
  7613. if (commentStackLength === 0) return;
  7614. let i = commentStackLength - 1;
  7615. for (; i >= 0; i--) {
  7616. const commentWS = commentStack[i];
  7617. const commentEnd = commentWS.end;
  7618. const commentStart = commentWS.start;
  7619. if (commentStart === end) {
  7620. commentWS.leadingNode = node;
  7621. } else if (commentEnd === start) {
  7622. commentWS.trailingNode = node;
  7623. } else if (commentEnd < start) {
  7624. break;
  7625. }
  7626. }
  7627. }
  7628. }
  7629. class State {
  7630. constructor() {
  7631. this.flags = 1024;
  7632. this.startIndex = void 0;
  7633. this.curLine = void 0;
  7634. this.lineStart = void 0;
  7635. this.startLoc = void 0;
  7636. this.endLoc = void 0;
  7637. this.errors = [];
  7638. this.potentialArrowAt = -1;
  7639. this.noArrowAt = [];
  7640. this.noArrowParamsConversionAt = [];
  7641. this.topicContext = {
  7642. maxNumOfResolvableTopics: 0,
  7643. maxTopicIndex: null
  7644. };
  7645. this.labels = [];
  7646. this.commentsLen = 0;
  7647. this.commentStack = [];
  7648. this.pos = 0;
  7649. this.type = 140;
  7650. this.value = null;
  7651. this.start = 0;
  7652. this.end = 0;
  7653. this.lastTokEndLoc = null;
  7654. this.lastTokStartLoc = null;
  7655. this.context = [types.brace];
  7656. this.firstInvalidTemplateEscapePos = null;
  7657. this.strictErrors = new Map();
  7658. this.tokensLength = 0;
  7659. }
  7660. get strict() {
  7661. return (this.flags & 1) > 0;
  7662. }
  7663. set strict(v) {
  7664. if (v) this.flags |= 1;else this.flags &= -2;
  7665. }
  7666. init({
  7667. strictMode,
  7668. sourceType,
  7669. startIndex,
  7670. startLine,
  7671. startColumn
  7672. }) {
  7673. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  7674. this.startIndex = startIndex;
  7675. this.curLine = startLine;
  7676. this.lineStart = -startColumn;
  7677. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  7678. }
  7679. get maybeInArrowParameters() {
  7680. return (this.flags & 2) > 0;
  7681. }
  7682. set maybeInArrowParameters(v) {
  7683. if (v) this.flags |= 2;else this.flags &= -3;
  7684. }
  7685. get inType() {
  7686. return (this.flags & 4) > 0;
  7687. }
  7688. set inType(v) {
  7689. if (v) this.flags |= 4;else this.flags &= -5;
  7690. }
  7691. get noAnonFunctionType() {
  7692. return (this.flags & 8) > 0;
  7693. }
  7694. set noAnonFunctionType(v) {
  7695. if (v) this.flags |= 8;else this.flags &= -9;
  7696. }
  7697. get hasFlowComment() {
  7698. return (this.flags & 16) > 0;
  7699. }
  7700. set hasFlowComment(v) {
  7701. if (v) this.flags |= 16;else this.flags &= -17;
  7702. }
  7703. get isAmbientContext() {
  7704. return (this.flags & 32) > 0;
  7705. }
  7706. set isAmbientContext(v) {
  7707. if (v) this.flags |= 32;else this.flags &= -33;
  7708. }
  7709. get inAbstractClass() {
  7710. return (this.flags & 64) > 0;
  7711. }
  7712. set inAbstractClass(v) {
  7713. if (v) this.flags |= 64;else this.flags &= -65;
  7714. }
  7715. get inDisallowConditionalTypesContext() {
  7716. return (this.flags & 128) > 0;
  7717. }
  7718. set inDisallowConditionalTypesContext(v) {
  7719. if (v) this.flags |= 128;else this.flags &= -129;
  7720. }
  7721. get soloAwait() {
  7722. return (this.flags & 256) > 0;
  7723. }
  7724. set soloAwait(v) {
  7725. if (v) this.flags |= 256;else this.flags &= -257;
  7726. }
  7727. get inFSharpPipelineDirectBody() {
  7728. return (this.flags & 512) > 0;
  7729. }
  7730. set inFSharpPipelineDirectBody(v) {
  7731. if (v) this.flags |= 512;else this.flags &= -513;
  7732. }
  7733. get canStartJSXElement() {
  7734. return (this.flags & 1024) > 0;
  7735. }
  7736. set canStartJSXElement(v) {
  7737. if (v) this.flags |= 1024;else this.flags &= -1025;
  7738. }
  7739. get containsEsc() {
  7740. return (this.flags & 2048) > 0;
  7741. }
  7742. set containsEsc(v) {
  7743. if (v) this.flags |= 2048;else this.flags &= -2049;
  7744. }
  7745. get hasTopLevelAwait() {
  7746. return (this.flags & 4096) > 0;
  7747. }
  7748. set hasTopLevelAwait(v) {
  7749. if (v) this.flags |= 4096;else this.flags &= -4097;
  7750. }
  7751. curPosition() {
  7752. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  7753. }
  7754. clone() {
  7755. const state = new State();
  7756. state.flags = this.flags;
  7757. state.startIndex = this.startIndex;
  7758. state.curLine = this.curLine;
  7759. state.lineStart = this.lineStart;
  7760. state.startLoc = this.startLoc;
  7761. state.endLoc = this.endLoc;
  7762. state.errors = this.errors.slice();
  7763. state.potentialArrowAt = this.potentialArrowAt;
  7764. state.noArrowAt = this.noArrowAt.slice();
  7765. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  7766. state.topicContext = this.topicContext;
  7767. state.labels = this.labels.slice();
  7768. state.commentsLen = this.commentsLen;
  7769. state.commentStack = this.commentStack.slice();
  7770. state.pos = this.pos;
  7771. state.type = this.type;
  7772. state.value = this.value;
  7773. state.start = this.start;
  7774. state.end = this.end;
  7775. state.lastTokEndLoc = this.lastTokEndLoc;
  7776. state.lastTokStartLoc = this.lastTokStartLoc;
  7777. state.context = this.context.slice();
  7778. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  7779. state.strictErrors = this.strictErrors;
  7780. state.tokensLength = this.tokensLength;
  7781. return state;
  7782. }
  7783. }
  7784. var _isDigit = function isDigit(code) {
  7785. return code >= 48 && code <= 57;
  7786. };
  7787. const forbiddenNumericSeparatorSiblings = {
  7788. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  7789. hex: new Set([46, 88, 95, 120])
  7790. };
  7791. const isAllowedNumericSeparatorSibling = {
  7792. bin: ch => ch === 48 || ch === 49,
  7793. oct: ch => ch >= 48 && ch <= 55,
  7794. dec: ch => ch >= 48 && ch <= 57,
  7795. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  7796. };
  7797. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  7798. const initialPos = pos;
  7799. const initialLineStart = lineStart;
  7800. const initialCurLine = curLine;
  7801. let out = "";
  7802. let firstInvalidLoc = null;
  7803. let chunkStart = pos;
  7804. const {
  7805. length
  7806. } = input;
  7807. for (;;) {
  7808. if (pos >= length) {
  7809. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  7810. out += input.slice(chunkStart, pos);
  7811. break;
  7812. }
  7813. const ch = input.charCodeAt(pos);
  7814. if (isStringEnd(type, ch, input, pos)) {
  7815. out += input.slice(chunkStart, pos);
  7816. break;
  7817. }
  7818. if (ch === 92) {
  7819. out += input.slice(chunkStart, pos);
  7820. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  7821. if (res.ch === null && !firstInvalidLoc) {
  7822. firstInvalidLoc = {
  7823. pos,
  7824. lineStart,
  7825. curLine
  7826. };
  7827. } else {
  7828. out += res.ch;
  7829. }
  7830. ({
  7831. pos,
  7832. lineStart,
  7833. curLine
  7834. } = res);
  7835. chunkStart = pos;
  7836. } else if (ch === 8232 || ch === 8233) {
  7837. ++pos;
  7838. ++curLine;
  7839. lineStart = pos;
  7840. } else if (ch === 10 || ch === 13) {
  7841. if (type === "template") {
  7842. out += input.slice(chunkStart, pos) + "\n";
  7843. ++pos;
  7844. if (ch === 13 && input.charCodeAt(pos) === 10) {
  7845. ++pos;
  7846. }
  7847. ++curLine;
  7848. chunkStart = lineStart = pos;
  7849. } else {
  7850. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  7851. }
  7852. } else {
  7853. ++pos;
  7854. }
  7855. }
  7856. return {
  7857. pos,
  7858. str: out,
  7859. firstInvalidLoc,
  7860. lineStart,
  7861. curLine,
  7862. containsInvalid: !!firstInvalidLoc
  7863. };
  7864. }
  7865. function isStringEnd(type, ch, input, pos) {
  7866. if (type === "template") {
  7867. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  7868. }
  7869. return ch === (type === "double" ? 34 : 39);
  7870. }
  7871. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  7872. const throwOnInvalid = !inTemplate;
  7873. pos++;
  7874. const res = ch => ({
  7875. pos,
  7876. ch,
  7877. lineStart,
  7878. curLine
  7879. });
  7880. const ch = input.charCodeAt(pos++);
  7881. switch (ch) {
  7882. case 110:
  7883. return res("\n");
  7884. case 114:
  7885. return res("\r");
  7886. case 120:
  7887. {
  7888. let code;
  7889. ({
  7890. code,
  7891. pos
  7892. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  7893. return res(code === null ? null : String.fromCharCode(code));
  7894. }
  7895. case 117:
  7896. {
  7897. let code;
  7898. ({
  7899. code,
  7900. pos
  7901. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  7902. return res(code === null ? null : String.fromCodePoint(code));
  7903. }
  7904. case 116:
  7905. return res("\t");
  7906. case 98:
  7907. return res("\b");
  7908. case 118:
  7909. return res("\u000b");
  7910. case 102:
  7911. return res("\f");
  7912. case 13:
  7913. if (input.charCodeAt(pos) === 10) {
  7914. ++pos;
  7915. }
  7916. case 10:
  7917. lineStart = pos;
  7918. ++curLine;
  7919. case 8232:
  7920. case 8233:
  7921. return res("");
  7922. case 56:
  7923. case 57:
  7924. if (inTemplate) {
  7925. return res(null);
  7926. } else {
  7927. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  7928. }
  7929. default:
  7930. if (ch >= 48 && ch <= 55) {
  7931. const startPos = pos - 1;
  7932. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  7933. let octalStr = match[0];
  7934. let octal = parseInt(octalStr, 8);
  7935. if (octal > 255) {
  7936. octalStr = octalStr.slice(0, -1);
  7937. octal = parseInt(octalStr, 8);
  7938. }
  7939. pos += octalStr.length - 1;
  7940. const next = input.charCodeAt(pos);
  7941. if (octalStr !== "0" || next === 56 || next === 57) {
  7942. if (inTemplate) {
  7943. return res(null);
  7944. } else {
  7945. errors.strictNumericEscape(startPos, lineStart, curLine);
  7946. }
  7947. }
  7948. return res(String.fromCharCode(octal));
  7949. }
  7950. return res(String.fromCharCode(ch));
  7951. }
  7952. }
  7953. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  7954. const initialPos = pos;
  7955. let n;
  7956. ({
  7957. n,
  7958. pos
  7959. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  7960. if (n === null) {
  7961. if (throwOnInvalid) {
  7962. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  7963. } else {
  7964. pos = initialPos - 1;
  7965. }
  7966. }
  7967. return {
  7968. code: n,
  7969. pos
  7970. };
  7971. }
  7972. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  7973. const start = pos;
  7974. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  7975. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  7976. let invalid = false;
  7977. let total = 0;
  7978. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  7979. const code = input.charCodeAt(pos);
  7980. let val;
  7981. if (code === 95 && allowNumSeparator !== "bail") {
  7982. const prev = input.charCodeAt(pos - 1);
  7983. const next = input.charCodeAt(pos + 1);
  7984. if (!allowNumSeparator) {
  7985. if (bailOnError) return {
  7986. n: null,
  7987. pos
  7988. };
  7989. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  7990. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  7991. if (bailOnError) return {
  7992. n: null,
  7993. pos
  7994. };
  7995. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  7996. }
  7997. ++pos;
  7998. continue;
  7999. }
  8000. if (code >= 97) {
  8001. val = code - 97 + 10;
  8002. } else if (code >= 65) {
  8003. val = code - 65 + 10;
  8004. } else if (_isDigit(code)) {
  8005. val = code - 48;
  8006. } else {
  8007. val = Infinity;
  8008. }
  8009. if (val >= radix) {
  8010. if (val <= 9 && bailOnError) {
  8011. return {
  8012. n: null,
  8013. pos
  8014. };
  8015. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  8016. val = 0;
  8017. } else if (forceLen) {
  8018. val = 0;
  8019. invalid = true;
  8020. } else {
  8021. break;
  8022. }
  8023. }
  8024. ++pos;
  8025. total = total * radix + val;
  8026. }
  8027. if (pos === start || len != null && pos - start !== len || invalid) {
  8028. return {
  8029. n: null,
  8030. pos
  8031. };
  8032. }
  8033. return {
  8034. n: total,
  8035. pos
  8036. };
  8037. }
  8038. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  8039. const ch = input.charCodeAt(pos);
  8040. let code;
  8041. if (ch === 123) {
  8042. ++pos;
  8043. ({
  8044. code,
  8045. pos
  8046. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  8047. ++pos;
  8048. if (code !== null && code > 0x10ffff) {
  8049. if (throwOnInvalid) {
  8050. errors.invalidCodePoint(pos, lineStart, curLine);
  8051. } else {
  8052. return {
  8053. code: null,
  8054. pos
  8055. };
  8056. }
  8057. }
  8058. } else {
  8059. ({
  8060. code,
  8061. pos
  8062. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  8063. }
  8064. return {
  8065. code,
  8066. pos
  8067. };
  8068. }
  8069. function buildPosition(pos, lineStart, curLine) {
  8070. return new Position(curLine, pos - lineStart, pos);
  8071. }
  8072. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  8073. class Token {
  8074. constructor(state) {
  8075. const startIndex = state.startIndex || 0;
  8076. this.type = state.type;
  8077. this.value = state.value;
  8078. this.start = startIndex + state.start;
  8079. this.end = startIndex + state.end;
  8080. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  8081. }
  8082. }
  8083. class Tokenizer extends CommentsParser {
  8084. constructor(options, input) {
  8085. super();
  8086. this.isLookahead = void 0;
  8087. this.tokens = [];
  8088. this.errorHandlers_readInt = {
  8089. invalidDigit: (pos, lineStart, curLine, radix) => {
  8090. if (!(this.optionFlags & 2048)) return false;
  8091. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  8092. radix
  8093. });
  8094. return true;
  8095. },
  8096. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  8097. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  8098. };
  8099. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  8100. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  8101. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  8102. });
  8103. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  8104. strictNumericEscape: (pos, lineStart, curLine) => {
  8105. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  8106. },
  8107. unterminated: (pos, lineStart, curLine) => {
  8108. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  8109. }
  8110. });
  8111. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  8112. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  8113. unterminated: (pos, lineStart, curLine) => {
  8114. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  8115. }
  8116. });
  8117. this.state = new State();
  8118. this.state.init(options);
  8119. this.input = input;
  8120. this.length = input.length;
  8121. this.comments = [];
  8122. this.isLookahead = false;
  8123. }
  8124. pushToken(token) {
  8125. this.tokens.length = this.state.tokensLength;
  8126. this.tokens.push(token);
  8127. ++this.state.tokensLength;
  8128. }
  8129. next() {
  8130. this.checkKeywordEscapes();
  8131. if (this.optionFlags & 256) {
  8132. this.pushToken(new Token(this.state));
  8133. }
  8134. this.state.lastTokEndLoc = this.state.endLoc;
  8135. this.state.lastTokStartLoc = this.state.startLoc;
  8136. this.nextToken();
  8137. }
  8138. eat(type) {
  8139. if (this.match(type)) {
  8140. this.next();
  8141. return true;
  8142. } else {
  8143. return false;
  8144. }
  8145. }
  8146. match(type) {
  8147. return this.state.type === type;
  8148. }
  8149. createLookaheadState(state) {
  8150. return {
  8151. pos: state.pos,
  8152. value: null,
  8153. type: state.type,
  8154. start: state.start,
  8155. end: state.end,
  8156. context: [this.curContext()],
  8157. inType: state.inType,
  8158. startLoc: state.startLoc,
  8159. lastTokEndLoc: state.lastTokEndLoc,
  8160. curLine: state.curLine,
  8161. lineStart: state.lineStart,
  8162. curPosition: state.curPosition
  8163. };
  8164. }
  8165. lookahead() {
  8166. const old = this.state;
  8167. this.state = this.createLookaheadState(old);
  8168. this.isLookahead = true;
  8169. this.nextToken();
  8170. this.isLookahead = false;
  8171. const curr = this.state;
  8172. this.state = old;
  8173. return curr;
  8174. }
  8175. nextTokenStart() {
  8176. return this.nextTokenStartSince(this.state.pos);
  8177. }
  8178. nextTokenStartSince(pos) {
  8179. skipWhiteSpace.lastIndex = pos;
  8180. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  8181. }
  8182. lookaheadCharCode() {
  8183. return this.lookaheadCharCodeSince(this.state.pos);
  8184. }
  8185. lookaheadCharCodeSince(pos) {
  8186. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  8187. }
  8188. nextTokenInLineStart() {
  8189. return this.nextTokenInLineStartSince(this.state.pos);
  8190. }
  8191. nextTokenInLineStartSince(pos) {
  8192. skipWhiteSpaceInLine.lastIndex = pos;
  8193. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  8194. }
  8195. lookaheadInLineCharCode() {
  8196. return this.input.charCodeAt(this.nextTokenInLineStart());
  8197. }
  8198. codePointAtPos(pos) {
  8199. let cp = this.input.charCodeAt(pos);
  8200. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  8201. const trail = this.input.charCodeAt(pos);
  8202. if ((trail & 0xfc00) === 0xdc00) {
  8203. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  8204. }
  8205. }
  8206. return cp;
  8207. }
  8208. setStrict(strict) {
  8209. this.state.strict = strict;
  8210. if (strict) {
  8211. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  8212. this.state.strictErrors.clear();
  8213. }
  8214. }
  8215. curContext() {
  8216. return this.state.context[this.state.context.length - 1];
  8217. }
  8218. nextToken() {
  8219. this.skipSpace();
  8220. this.state.start = this.state.pos;
  8221. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  8222. if (this.state.pos >= this.length) {
  8223. this.finishToken(140);
  8224. return;
  8225. }
  8226. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  8227. }
  8228. skipBlockComment(commentEnd) {
  8229. let startLoc;
  8230. if (!this.isLookahead) startLoc = this.state.curPosition();
  8231. const start = this.state.pos;
  8232. const end = this.input.indexOf(commentEnd, start + 2);
  8233. if (end === -1) {
  8234. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  8235. }
  8236. this.state.pos = end + commentEnd.length;
  8237. lineBreakG.lastIndex = start + 2;
  8238. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  8239. ++this.state.curLine;
  8240. this.state.lineStart = lineBreakG.lastIndex;
  8241. }
  8242. if (this.isLookahead) return;
  8243. const comment = {
  8244. type: "CommentBlock",
  8245. value: this.input.slice(start + 2, end),
  8246. start: this.sourceToOffsetPos(start),
  8247. end: this.sourceToOffsetPos(end + commentEnd.length),
  8248. loc: new SourceLocation(startLoc, this.state.curPosition())
  8249. };
  8250. if (this.optionFlags & 256) this.pushToken(comment);
  8251. return comment;
  8252. }
  8253. skipLineComment(startSkip) {
  8254. const start = this.state.pos;
  8255. let startLoc;
  8256. if (!this.isLookahead) startLoc = this.state.curPosition();
  8257. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  8258. if (this.state.pos < this.length) {
  8259. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  8260. ch = this.input.charCodeAt(this.state.pos);
  8261. }
  8262. }
  8263. if (this.isLookahead) return;
  8264. const end = this.state.pos;
  8265. const value = this.input.slice(start + startSkip, end);
  8266. const comment = {
  8267. type: "CommentLine",
  8268. value,
  8269. start: this.sourceToOffsetPos(start),
  8270. end: this.sourceToOffsetPos(end),
  8271. loc: new SourceLocation(startLoc, this.state.curPosition())
  8272. };
  8273. if (this.optionFlags & 256) this.pushToken(comment);
  8274. return comment;
  8275. }
  8276. skipSpace() {
  8277. const spaceStart = this.state.pos;
  8278. const comments = this.optionFlags & 4096 ? [] : null;
  8279. loop: while (this.state.pos < this.length) {
  8280. const ch = this.input.charCodeAt(this.state.pos);
  8281. switch (ch) {
  8282. case 32:
  8283. case 160:
  8284. case 9:
  8285. ++this.state.pos;
  8286. break;
  8287. case 13:
  8288. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  8289. ++this.state.pos;
  8290. }
  8291. case 10:
  8292. case 8232:
  8293. case 8233:
  8294. ++this.state.pos;
  8295. ++this.state.curLine;
  8296. this.state.lineStart = this.state.pos;
  8297. break;
  8298. case 47:
  8299. switch (this.input.charCodeAt(this.state.pos + 1)) {
  8300. case 42:
  8301. {
  8302. const comment = this.skipBlockComment("*/");
  8303. if (comment !== undefined) {
  8304. this.addComment(comment);
  8305. comments == null || comments.push(comment);
  8306. }
  8307. break;
  8308. }
  8309. case 47:
  8310. {
  8311. const comment = this.skipLineComment(2);
  8312. if (comment !== undefined) {
  8313. this.addComment(comment);
  8314. comments == null || comments.push(comment);
  8315. }
  8316. break;
  8317. }
  8318. default:
  8319. break loop;
  8320. }
  8321. break;
  8322. default:
  8323. if (isWhitespace(ch)) {
  8324. ++this.state.pos;
  8325. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  8326. const pos = this.state.pos;
  8327. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  8328. const comment = this.skipLineComment(3);
  8329. if (comment !== undefined) {
  8330. this.addComment(comment);
  8331. comments == null || comments.push(comment);
  8332. }
  8333. } else {
  8334. break loop;
  8335. }
  8336. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  8337. const pos = this.state.pos;
  8338. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  8339. const comment = this.skipLineComment(4);
  8340. if (comment !== undefined) {
  8341. this.addComment(comment);
  8342. comments == null || comments.push(comment);
  8343. }
  8344. } else {
  8345. break loop;
  8346. }
  8347. } else {
  8348. break loop;
  8349. }
  8350. }
  8351. }
  8352. if ((comments == null ? void 0 : comments.length) > 0) {
  8353. const end = this.state.pos;
  8354. const commentWhitespace = {
  8355. start: this.sourceToOffsetPos(spaceStart),
  8356. end: this.sourceToOffsetPos(end),
  8357. comments,
  8358. leadingNode: null,
  8359. trailingNode: null,
  8360. containingNode: null
  8361. };
  8362. this.state.commentStack.push(commentWhitespace);
  8363. }
  8364. }
  8365. finishToken(type, val) {
  8366. this.state.end = this.state.pos;
  8367. this.state.endLoc = this.state.curPosition();
  8368. const prevType = this.state.type;
  8369. this.state.type = type;
  8370. this.state.value = val;
  8371. if (!this.isLookahead) {
  8372. this.updateContext(prevType);
  8373. }
  8374. }
  8375. replaceToken(type) {
  8376. this.state.type = type;
  8377. this.updateContext();
  8378. }
  8379. readToken_numberSign() {
  8380. if (this.state.pos === 0 && this.readToken_interpreter()) {
  8381. return;
  8382. }
  8383. const nextPos = this.state.pos + 1;
  8384. const next = this.codePointAtPos(nextPos);
  8385. if (next >= 48 && next <= 57) {
  8386. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  8387. }
  8388. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  8389. this.expectPlugin("recordAndTuple");
  8390. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  8391. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  8392. }
  8393. this.state.pos += 2;
  8394. if (next === 123) {
  8395. this.finishToken(7);
  8396. } else {
  8397. this.finishToken(1);
  8398. }
  8399. } else if (isIdentifierStart(next)) {
  8400. ++this.state.pos;
  8401. this.finishToken(139, this.readWord1(next));
  8402. } else if (next === 92) {
  8403. ++this.state.pos;
  8404. this.finishToken(139, this.readWord1());
  8405. } else {
  8406. this.finishOp(27, 1);
  8407. }
  8408. }
  8409. readToken_dot() {
  8410. const next = this.input.charCodeAt(this.state.pos + 1);
  8411. if (next >= 48 && next <= 57) {
  8412. this.readNumber(true);
  8413. return;
  8414. }
  8415. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  8416. this.state.pos += 3;
  8417. this.finishToken(21);
  8418. } else {
  8419. ++this.state.pos;
  8420. this.finishToken(16);
  8421. }
  8422. }
  8423. readToken_slash() {
  8424. const next = this.input.charCodeAt(this.state.pos + 1);
  8425. if (next === 61) {
  8426. this.finishOp(31, 2);
  8427. } else {
  8428. this.finishOp(56, 1);
  8429. }
  8430. }
  8431. readToken_interpreter() {
  8432. if (this.state.pos !== 0 || this.length < 2) return false;
  8433. let ch = this.input.charCodeAt(this.state.pos + 1);
  8434. if (ch !== 33) return false;
  8435. const start = this.state.pos;
  8436. this.state.pos += 1;
  8437. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  8438. ch = this.input.charCodeAt(this.state.pos);
  8439. }
  8440. const value = this.input.slice(start + 2, this.state.pos);
  8441. this.finishToken(28, value);
  8442. return true;
  8443. }
  8444. readToken_mult_modulo(code) {
  8445. let type = code === 42 ? 55 : 54;
  8446. let width = 1;
  8447. let next = this.input.charCodeAt(this.state.pos + 1);
  8448. if (code === 42 && next === 42) {
  8449. width++;
  8450. next = this.input.charCodeAt(this.state.pos + 2);
  8451. type = 57;
  8452. }
  8453. if (next === 61 && !this.state.inType) {
  8454. width++;
  8455. type = code === 37 ? 33 : 30;
  8456. }
  8457. this.finishOp(type, width);
  8458. }
  8459. readToken_pipe_amp(code) {
  8460. const next = this.input.charCodeAt(this.state.pos + 1);
  8461. if (next === code) {
  8462. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  8463. this.finishOp(30, 3);
  8464. } else {
  8465. this.finishOp(code === 124 ? 41 : 42, 2);
  8466. }
  8467. return;
  8468. }
  8469. if (code === 124) {
  8470. if (next === 62) {
  8471. this.finishOp(39, 2);
  8472. return;
  8473. }
  8474. if (this.hasPlugin("recordAndTuple") && next === 125) {
  8475. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8476. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  8477. }
  8478. this.state.pos += 2;
  8479. this.finishToken(9);
  8480. return;
  8481. }
  8482. if (this.hasPlugin("recordAndTuple") && next === 93) {
  8483. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8484. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  8485. }
  8486. this.state.pos += 2;
  8487. this.finishToken(4);
  8488. return;
  8489. }
  8490. }
  8491. if (next === 61) {
  8492. this.finishOp(30, 2);
  8493. return;
  8494. }
  8495. this.finishOp(code === 124 ? 43 : 45, 1);
  8496. }
  8497. readToken_caret() {
  8498. const next = this.input.charCodeAt(this.state.pos + 1);
  8499. if (next === 61 && !this.state.inType) {
  8500. this.finishOp(32, 2);
  8501. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  8502. proposal: "hack",
  8503. topicToken: "^^"
  8504. }])) {
  8505. this.finishOp(37, 2);
  8506. const lookaheadCh = this.input.codePointAt(this.state.pos);
  8507. if (lookaheadCh === 94) {
  8508. this.unexpected();
  8509. }
  8510. } else {
  8511. this.finishOp(44, 1);
  8512. }
  8513. }
  8514. readToken_atSign() {
  8515. const next = this.input.charCodeAt(this.state.pos + 1);
  8516. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  8517. proposal: "hack",
  8518. topicToken: "@@"
  8519. }])) {
  8520. this.finishOp(38, 2);
  8521. } else {
  8522. this.finishOp(26, 1);
  8523. }
  8524. }
  8525. readToken_plus_min(code) {
  8526. const next = this.input.charCodeAt(this.state.pos + 1);
  8527. if (next === code) {
  8528. this.finishOp(34, 2);
  8529. return;
  8530. }
  8531. if (next === 61) {
  8532. this.finishOp(30, 2);
  8533. } else {
  8534. this.finishOp(53, 1);
  8535. }
  8536. }
  8537. readToken_lt() {
  8538. const {
  8539. pos
  8540. } = this.state;
  8541. const next = this.input.charCodeAt(pos + 1);
  8542. if (next === 60) {
  8543. if (this.input.charCodeAt(pos + 2) === 61) {
  8544. this.finishOp(30, 3);
  8545. return;
  8546. }
  8547. this.finishOp(51, 2);
  8548. return;
  8549. }
  8550. if (next === 61) {
  8551. this.finishOp(49, 2);
  8552. return;
  8553. }
  8554. this.finishOp(47, 1);
  8555. }
  8556. readToken_gt() {
  8557. const {
  8558. pos
  8559. } = this.state;
  8560. const next = this.input.charCodeAt(pos + 1);
  8561. if (next === 62) {
  8562. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  8563. if (this.input.charCodeAt(pos + size) === 61) {
  8564. this.finishOp(30, size + 1);
  8565. return;
  8566. }
  8567. this.finishOp(52, size);
  8568. return;
  8569. }
  8570. if (next === 61) {
  8571. this.finishOp(49, 2);
  8572. return;
  8573. }
  8574. this.finishOp(48, 1);
  8575. }
  8576. readToken_eq_excl(code) {
  8577. const next = this.input.charCodeAt(this.state.pos + 1);
  8578. if (next === 61) {
  8579. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  8580. return;
  8581. }
  8582. if (code === 61 && next === 62) {
  8583. this.state.pos += 2;
  8584. this.finishToken(19);
  8585. return;
  8586. }
  8587. this.finishOp(code === 61 ? 29 : 35, 1);
  8588. }
  8589. readToken_question() {
  8590. const next = this.input.charCodeAt(this.state.pos + 1);
  8591. const next2 = this.input.charCodeAt(this.state.pos + 2);
  8592. if (next === 63) {
  8593. if (next2 === 61) {
  8594. this.finishOp(30, 3);
  8595. } else {
  8596. this.finishOp(40, 2);
  8597. }
  8598. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  8599. this.state.pos += 2;
  8600. this.finishToken(18);
  8601. } else {
  8602. ++this.state.pos;
  8603. this.finishToken(17);
  8604. }
  8605. }
  8606. getTokenFromCode(code) {
  8607. switch (code) {
  8608. case 46:
  8609. this.readToken_dot();
  8610. return;
  8611. case 40:
  8612. ++this.state.pos;
  8613. this.finishToken(10);
  8614. return;
  8615. case 41:
  8616. ++this.state.pos;
  8617. this.finishToken(11);
  8618. return;
  8619. case 59:
  8620. ++this.state.pos;
  8621. this.finishToken(13);
  8622. return;
  8623. case 44:
  8624. ++this.state.pos;
  8625. this.finishToken(12);
  8626. return;
  8627. case 91:
  8628. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  8629. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8630. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  8631. }
  8632. this.state.pos += 2;
  8633. this.finishToken(2);
  8634. } else {
  8635. ++this.state.pos;
  8636. this.finishToken(0);
  8637. }
  8638. return;
  8639. case 93:
  8640. ++this.state.pos;
  8641. this.finishToken(3);
  8642. return;
  8643. case 123:
  8644. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  8645. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8646. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  8647. }
  8648. this.state.pos += 2;
  8649. this.finishToken(6);
  8650. } else {
  8651. ++this.state.pos;
  8652. this.finishToken(5);
  8653. }
  8654. return;
  8655. case 125:
  8656. ++this.state.pos;
  8657. this.finishToken(8);
  8658. return;
  8659. case 58:
  8660. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  8661. this.finishOp(15, 2);
  8662. } else {
  8663. ++this.state.pos;
  8664. this.finishToken(14);
  8665. }
  8666. return;
  8667. case 63:
  8668. this.readToken_question();
  8669. return;
  8670. case 96:
  8671. this.readTemplateToken();
  8672. return;
  8673. case 48:
  8674. {
  8675. const next = this.input.charCodeAt(this.state.pos + 1);
  8676. if (next === 120 || next === 88) {
  8677. this.readRadixNumber(16);
  8678. return;
  8679. }
  8680. if (next === 111 || next === 79) {
  8681. this.readRadixNumber(8);
  8682. return;
  8683. }
  8684. if (next === 98 || next === 66) {
  8685. this.readRadixNumber(2);
  8686. return;
  8687. }
  8688. }
  8689. case 49:
  8690. case 50:
  8691. case 51:
  8692. case 52:
  8693. case 53:
  8694. case 54:
  8695. case 55:
  8696. case 56:
  8697. case 57:
  8698. this.readNumber(false);
  8699. return;
  8700. case 34:
  8701. case 39:
  8702. this.readString(code);
  8703. return;
  8704. case 47:
  8705. this.readToken_slash();
  8706. return;
  8707. case 37:
  8708. case 42:
  8709. this.readToken_mult_modulo(code);
  8710. return;
  8711. case 124:
  8712. case 38:
  8713. this.readToken_pipe_amp(code);
  8714. return;
  8715. case 94:
  8716. this.readToken_caret();
  8717. return;
  8718. case 43:
  8719. case 45:
  8720. this.readToken_plus_min(code);
  8721. return;
  8722. case 60:
  8723. this.readToken_lt();
  8724. return;
  8725. case 62:
  8726. this.readToken_gt();
  8727. return;
  8728. case 61:
  8729. case 33:
  8730. this.readToken_eq_excl(code);
  8731. return;
  8732. case 126:
  8733. this.finishOp(36, 1);
  8734. return;
  8735. case 64:
  8736. this.readToken_atSign();
  8737. return;
  8738. case 35:
  8739. this.readToken_numberSign();
  8740. return;
  8741. case 92:
  8742. this.readWord();
  8743. return;
  8744. default:
  8745. if (isIdentifierStart(code)) {
  8746. this.readWord(code);
  8747. return;
  8748. }
  8749. }
  8750. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  8751. unexpected: String.fromCodePoint(code)
  8752. });
  8753. }
  8754. finishOp(type, size) {
  8755. const str = this.input.slice(this.state.pos, this.state.pos + size);
  8756. this.state.pos += size;
  8757. this.finishToken(type, str);
  8758. }
  8759. readRegexp() {
  8760. const startLoc = this.state.startLoc;
  8761. const start = this.state.start + 1;
  8762. let escaped, inClass;
  8763. let {
  8764. pos
  8765. } = this.state;
  8766. for (;; ++pos) {
  8767. if (pos >= this.length) {
  8768. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  8769. }
  8770. const ch = this.input.charCodeAt(pos);
  8771. if (isNewLine(ch)) {
  8772. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  8773. }
  8774. if (escaped) {
  8775. escaped = false;
  8776. } else {
  8777. if (ch === 91) {
  8778. inClass = true;
  8779. } else if (ch === 93 && inClass) {
  8780. inClass = false;
  8781. } else if (ch === 47 && !inClass) {
  8782. break;
  8783. }
  8784. escaped = ch === 92;
  8785. }
  8786. }
  8787. const content = this.input.slice(start, pos);
  8788. ++pos;
  8789. let mods = "";
  8790. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  8791. while (pos < this.length) {
  8792. const cp = this.codePointAtPos(pos);
  8793. const char = String.fromCharCode(cp);
  8794. if (VALID_REGEX_FLAGS.has(cp)) {
  8795. if (cp === 118) {
  8796. if (mods.includes("u")) {
  8797. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  8798. }
  8799. } else if (cp === 117) {
  8800. if (mods.includes("v")) {
  8801. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  8802. }
  8803. }
  8804. if (mods.includes(char)) {
  8805. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  8806. }
  8807. } else if (isIdentifierChar(cp) || cp === 92) {
  8808. this.raise(Errors.MalformedRegExpFlags, nextPos());
  8809. } else {
  8810. break;
  8811. }
  8812. ++pos;
  8813. mods += char;
  8814. }
  8815. this.state.pos = pos;
  8816. this.finishToken(138, {
  8817. pattern: content,
  8818. flags: mods
  8819. });
  8820. }
  8821. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  8822. const {
  8823. n,
  8824. pos
  8825. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  8826. this.state.pos = pos;
  8827. return n;
  8828. }
  8829. readRadixNumber(radix) {
  8830. const start = this.state.pos;
  8831. const startLoc = this.state.curPosition();
  8832. let isBigInt = false;
  8833. this.state.pos += 2;
  8834. const val = this.readInt(radix);
  8835. if (val == null) {
  8836. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  8837. radix
  8838. });
  8839. }
  8840. const next = this.input.charCodeAt(this.state.pos);
  8841. if (next === 110) {
  8842. ++this.state.pos;
  8843. isBigInt = true;
  8844. } else if (next === 109) {
  8845. throw this.raise(Errors.InvalidDecimal, startLoc);
  8846. }
  8847. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  8848. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  8849. }
  8850. if (isBigInt) {
  8851. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  8852. this.finishToken(136, str);
  8853. return;
  8854. }
  8855. this.finishToken(135, val);
  8856. }
  8857. readNumber(startsWithDot) {
  8858. const start = this.state.pos;
  8859. const startLoc = this.state.curPosition();
  8860. let isFloat = false;
  8861. let isBigInt = false;
  8862. let hasExponent = false;
  8863. let isOctal = false;
  8864. if (!startsWithDot && this.readInt(10) === null) {
  8865. this.raise(Errors.InvalidNumber, this.state.curPosition());
  8866. }
  8867. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  8868. if (hasLeadingZero) {
  8869. const integer = this.input.slice(start, this.state.pos);
  8870. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  8871. if (!this.state.strict) {
  8872. const underscorePos = integer.indexOf("_");
  8873. if (underscorePos > 0) {
  8874. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  8875. }
  8876. }
  8877. isOctal = hasLeadingZero && !/[89]/.test(integer);
  8878. }
  8879. let next = this.input.charCodeAt(this.state.pos);
  8880. if (next === 46 && !isOctal) {
  8881. ++this.state.pos;
  8882. this.readInt(10);
  8883. isFloat = true;
  8884. next = this.input.charCodeAt(this.state.pos);
  8885. }
  8886. if ((next === 69 || next === 101) && !isOctal) {
  8887. next = this.input.charCodeAt(++this.state.pos);
  8888. if (next === 43 || next === 45) {
  8889. ++this.state.pos;
  8890. }
  8891. if (this.readInt(10) === null) {
  8892. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  8893. }
  8894. isFloat = true;
  8895. hasExponent = true;
  8896. next = this.input.charCodeAt(this.state.pos);
  8897. }
  8898. if (next === 110) {
  8899. if (isFloat || hasLeadingZero) {
  8900. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  8901. }
  8902. ++this.state.pos;
  8903. isBigInt = true;
  8904. }
  8905. if (next === 109) {
  8906. this.expectPlugin("decimal", this.state.curPosition());
  8907. if (hasExponent || hasLeadingZero) {
  8908. this.raise(Errors.InvalidDecimal, startLoc);
  8909. }
  8910. ++this.state.pos;
  8911. var isDecimal = true;
  8912. }
  8913. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  8914. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  8915. }
  8916. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  8917. if (isBigInt) {
  8918. this.finishToken(136, str);
  8919. return;
  8920. }
  8921. if (isDecimal) {
  8922. this.finishToken(137, str);
  8923. return;
  8924. }
  8925. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  8926. this.finishToken(135, val);
  8927. }
  8928. readCodePoint(throwOnInvalid) {
  8929. const {
  8930. code,
  8931. pos
  8932. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  8933. this.state.pos = pos;
  8934. return code;
  8935. }
  8936. readString(quote) {
  8937. const {
  8938. str,
  8939. pos,
  8940. curLine,
  8941. lineStart
  8942. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  8943. this.state.pos = pos + 1;
  8944. this.state.lineStart = lineStart;
  8945. this.state.curLine = curLine;
  8946. this.finishToken(134, str);
  8947. }
  8948. readTemplateContinuation() {
  8949. if (!this.match(8)) {
  8950. this.unexpected(null, 8);
  8951. }
  8952. this.state.pos--;
  8953. this.readTemplateToken();
  8954. }
  8955. readTemplateToken() {
  8956. const opening = this.input[this.state.pos];
  8957. const {
  8958. str,
  8959. firstInvalidLoc,
  8960. pos,
  8961. curLine,
  8962. lineStart
  8963. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  8964. this.state.pos = pos + 1;
  8965. this.state.lineStart = lineStart;
  8966. this.state.curLine = curLine;
  8967. if (firstInvalidLoc) {
  8968. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  8969. }
  8970. if (this.input.codePointAt(pos) === 96) {
  8971. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  8972. } else {
  8973. this.state.pos++;
  8974. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  8975. }
  8976. }
  8977. recordStrictModeErrors(toParseError, at) {
  8978. const index = at.index;
  8979. if (this.state.strict && !this.state.strictErrors.has(index)) {
  8980. this.raise(toParseError, at);
  8981. } else {
  8982. this.state.strictErrors.set(index, [toParseError, at]);
  8983. }
  8984. }
  8985. readWord1(firstCode) {
  8986. this.state.containsEsc = false;
  8987. let word = "";
  8988. const start = this.state.pos;
  8989. let chunkStart = this.state.pos;
  8990. if (firstCode !== undefined) {
  8991. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  8992. }
  8993. while (this.state.pos < this.length) {
  8994. const ch = this.codePointAtPos(this.state.pos);
  8995. if (isIdentifierChar(ch)) {
  8996. this.state.pos += ch <= 0xffff ? 1 : 2;
  8997. } else if (ch === 92) {
  8998. this.state.containsEsc = true;
  8999. word += this.input.slice(chunkStart, this.state.pos);
  9000. const escStart = this.state.curPosition();
  9001. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  9002. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  9003. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  9004. chunkStart = this.state.pos - 1;
  9005. continue;
  9006. }
  9007. ++this.state.pos;
  9008. const esc = this.readCodePoint(true);
  9009. if (esc !== null) {
  9010. if (!identifierCheck(esc)) {
  9011. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  9012. }
  9013. word += String.fromCodePoint(esc);
  9014. }
  9015. chunkStart = this.state.pos;
  9016. } else {
  9017. break;
  9018. }
  9019. }
  9020. return word + this.input.slice(chunkStart, this.state.pos);
  9021. }
  9022. readWord(firstCode) {
  9023. const word = this.readWord1(firstCode);
  9024. const type = keywords$1.get(word);
  9025. if (type !== undefined) {
  9026. this.finishToken(type, tokenLabelName(type));
  9027. } else {
  9028. this.finishToken(132, word);
  9029. }
  9030. }
  9031. checkKeywordEscapes() {
  9032. const {
  9033. type
  9034. } = this.state;
  9035. if (tokenIsKeyword(type) && this.state.containsEsc) {
  9036. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  9037. reservedWord: tokenLabelName(type)
  9038. });
  9039. }
  9040. }
  9041. raise(toParseError, at, details = {}) {
  9042. const loc = at instanceof Position ? at : at.loc.start;
  9043. const error = toParseError(loc, details);
  9044. if (!(this.optionFlags & 2048)) throw error;
  9045. if (!this.isLookahead) this.state.errors.push(error);
  9046. return error;
  9047. }
  9048. raiseOverwrite(toParseError, at, details = {}) {
  9049. const loc = at instanceof Position ? at : at.loc.start;
  9050. const pos = loc.index;
  9051. const errors = this.state.errors;
  9052. for (let i = errors.length - 1; i >= 0; i--) {
  9053. const error = errors[i];
  9054. if (error.loc.index === pos) {
  9055. return errors[i] = toParseError(loc, details);
  9056. }
  9057. if (error.loc.index < pos) break;
  9058. }
  9059. return this.raise(toParseError, at, details);
  9060. }
  9061. updateContext(prevType) {}
  9062. unexpected(loc, type) {
  9063. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  9064. expected: type ? tokenLabelName(type) : null
  9065. });
  9066. }
  9067. expectPlugin(pluginName, loc) {
  9068. if (this.hasPlugin(pluginName)) {
  9069. return true;
  9070. }
  9071. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  9072. missingPlugin: [pluginName]
  9073. });
  9074. }
  9075. expectOnePlugin(pluginNames) {
  9076. if (!pluginNames.some(name => this.hasPlugin(name))) {
  9077. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  9078. missingPlugin: pluginNames
  9079. });
  9080. }
  9081. }
  9082. errorBuilder(error) {
  9083. return (pos, lineStart, curLine) => {
  9084. this.raise(error, buildPosition(pos, lineStart, curLine));
  9085. };
  9086. }
  9087. }
  9088. class ClassScope {
  9089. constructor() {
  9090. this.privateNames = new Set();
  9091. this.loneAccessors = new Map();
  9092. this.undefinedPrivateNames = new Map();
  9093. }
  9094. }
  9095. class ClassScopeHandler {
  9096. constructor(parser) {
  9097. this.parser = void 0;
  9098. this.stack = [];
  9099. this.undefinedPrivateNames = new Map();
  9100. this.parser = parser;
  9101. }
  9102. current() {
  9103. return this.stack[this.stack.length - 1];
  9104. }
  9105. enter() {
  9106. this.stack.push(new ClassScope());
  9107. }
  9108. exit() {
  9109. const oldClassScope = this.stack.pop();
  9110. const current = this.current();
  9111. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  9112. if (current) {
  9113. if (!current.undefinedPrivateNames.has(name)) {
  9114. current.undefinedPrivateNames.set(name, loc);
  9115. }
  9116. } else {
  9117. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  9118. identifierName: name
  9119. });
  9120. }
  9121. }
  9122. }
  9123. declarePrivateName(name, elementType, loc) {
  9124. const {
  9125. privateNames,
  9126. loneAccessors,
  9127. undefinedPrivateNames
  9128. } = this.current();
  9129. let redefined = privateNames.has(name);
  9130. if (elementType & 3) {
  9131. const accessor = redefined && loneAccessors.get(name);
  9132. if (accessor) {
  9133. const oldStatic = accessor & 4;
  9134. const newStatic = elementType & 4;
  9135. const oldKind = accessor & 3;
  9136. const newKind = elementType & 3;
  9137. redefined = oldKind === newKind || oldStatic !== newStatic;
  9138. if (!redefined) loneAccessors.delete(name);
  9139. } else if (!redefined) {
  9140. loneAccessors.set(name, elementType);
  9141. }
  9142. }
  9143. if (redefined) {
  9144. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  9145. identifierName: name
  9146. });
  9147. }
  9148. privateNames.add(name);
  9149. undefinedPrivateNames.delete(name);
  9150. }
  9151. usePrivateName(name, loc) {
  9152. let classScope;
  9153. for (classScope of this.stack) {
  9154. if (classScope.privateNames.has(name)) return;
  9155. }
  9156. if (classScope) {
  9157. classScope.undefinedPrivateNames.set(name, loc);
  9158. } else {
  9159. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  9160. identifierName: name
  9161. });
  9162. }
  9163. }
  9164. }
  9165. class ExpressionScope {
  9166. constructor(type = 0) {
  9167. this.type = type;
  9168. }
  9169. canBeArrowParameterDeclaration() {
  9170. return this.type === 2 || this.type === 1;
  9171. }
  9172. isCertainlyParameterDeclaration() {
  9173. return this.type === 3;
  9174. }
  9175. }
  9176. class ArrowHeadParsingScope extends ExpressionScope {
  9177. constructor(type) {
  9178. super(type);
  9179. this.declarationErrors = new Map();
  9180. }
  9181. recordDeclarationError(ParsingErrorClass, at) {
  9182. const index = at.index;
  9183. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  9184. }
  9185. clearDeclarationError(index) {
  9186. this.declarationErrors.delete(index);
  9187. }
  9188. iterateErrors(iterator) {
  9189. this.declarationErrors.forEach(iterator);
  9190. }
  9191. }
  9192. class ExpressionScopeHandler {
  9193. constructor(parser) {
  9194. this.parser = void 0;
  9195. this.stack = [new ExpressionScope()];
  9196. this.parser = parser;
  9197. }
  9198. enter(scope) {
  9199. this.stack.push(scope);
  9200. }
  9201. exit() {
  9202. this.stack.pop();
  9203. }
  9204. recordParameterInitializerError(toParseError, node) {
  9205. const origin = node.loc.start;
  9206. const {
  9207. stack
  9208. } = this;
  9209. let i = stack.length - 1;
  9210. let scope = stack[i];
  9211. while (!scope.isCertainlyParameterDeclaration()) {
  9212. if (scope.canBeArrowParameterDeclaration()) {
  9213. scope.recordDeclarationError(toParseError, origin);
  9214. } else {
  9215. return;
  9216. }
  9217. scope = stack[--i];
  9218. }
  9219. this.parser.raise(toParseError, origin);
  9220. }
  9221. recordArrowParameterBindingError(error, node) {
  9222. const {
  9223. stack
  9224. } = this;
  9225. const scope = stack[stack.length - 1];
  9226. const origin = node.loc.start;
  9227. if (scope.isCertainlyParameterDeclaration()) {
  9228. this.parser.raise(error, origin);
  9229. } else if (scope.canBeArrowParameterDeclaration()) {
  9230. scope.recordDeclarationError(error, origin);
  9231. } else {
  9232. return;
  9233. }
  9234. }
  9235. recordAsyncArrowParametersError(at) {
  9236. const {
  9237. stack
  9238. } = this;
  9239. let i = stack.length - 1;
  9240. let scope = stack[i];
  9241. while (scope.canBeArrowParameterDeclaration()) {
  9242. if (scope.type === 2) {
  9243. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  9244. }
  9245. scope = stack[--i];
  9246. }
  9247. }
  9248. validateAsPattern() {
  9249. const {
  9250. stack
  9251. } = this;
  9252. const currentScope = stack[stack.length - 1];
  9253. if (!currentScope.canBeArrowParameterDeclaration()) return;
  9254. currentScope.iterateErrors(([toParseError, loc]) => {
  9255. this.parser.raise(toParseError, loc);
  9256. let i = stack.length - 2;
  9257. let scope = stack[i];
  9258. while (scope.canBeArrowParameterDeclaration()) {
  9259. scope.clearDeclarationError(loc.index);
  9260. scope = stack[--i];
  9261. }
  9262. });
  9263. }
  9264. }
  9265. function newParameterDeclarationScope() {
  9266. return new ExpressionScope(3);
  9267. }
  9268. function newArrowHeadScope() {
  9269. return new ArrowHeadParsingScope(1);
  9270. }
  9271. function newAsyncArrowScope() {
  9272. return new ArrowHeadParsingScope(2);
  9273. }
  9274. function newExpressionScope() {
  9275. return new ExpressionScope();
  9276. }
  9277. class UtilParser extends Tokenizer {
  9278. addExtra(node, key, value, enumerable = true) {
  9279. if (!node) return;
  9280. let {
  9281. extra
  9282. } = node;
  9283. if (extra == null) {
  9284. extra = {};
  9285. node.extra = extra;
  9286. }
  9287. if (enumerable) {
  9288. extra[key] = value;
  9289. } else {
  9290. Object.defineProperty(extra, key, {
  9291. enumerable,
  9292. value
  9293. });
  9294. }
  9295. }
  9296. isContextual(token) {
  9297. return this.state.type === token && !this.state.containsEsc;
  9298. }
  9299. isUnparsedContextual(nameStart, name) {
  9300. if (this.input.startsWith(name, nameStart)) {
  9301. const nextCh = this.input.charCodeAt(nameStart + name.length);
  9302. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  9303. }
  9304. return false;
  9305. }
  9306. isLookaheadContextual(name) {
  9307. const next = this.nextTokenStart();
  9308. return this.isUnparsedContextual(next, name);
  9309. }
  9310. eatContextual(token) {
  9311. if (this.isContextual(token)) {
  9312. this.next();
  9313. return true;
  9314. }
  9315. return false;
  9316. }
  9317. expectContextual(token, toParseError) {
  9318. if (!this.eatContextual(token)) {
  9319. if (toParseError != null) {
  9320. throw this.raise(toParseError, this.state.startLoc);
  9321. }
  9322. this.unexpected(null, token);
  9323. }
  9324. }
  9325. canInsertSemicolon() {
  9326. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  9327. }
  9328. hasPrecedingLineBreak() {
  9329. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  9330. }
  9331. hasFollowingLineBreak() {
  9332. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  9333. }
  9334. isLineTerminator() {
  9335. return this.eat(13) || this.canInsertSemicolon();
  9336. }
  9337. semicolon(allowAsi = true) {
  9338. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  9339. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  9340. }
  9341. expect(type, loc) {
  9342. if (!this.eat(type)) {
  9343. this.unexpected(loc, type);
  9344. }
  9345. }
  9346. tryParse(fn, oldState = this.state.clone()) {
  9347. const abortSignal = {
  9348. node: null
  9349. };
  9350. try {
  9351. const node = fn((node = null) => {
  9352. abortSignal.node = node;
  9353. throw abortSignal;
  9354. });
  9355. if (this.state.errors.length > oldState.errors.length) {
  9356. const failState = this.state;
  9357. this.state = oldState;
  9358. this.state.tokensLength = failState.tokensLength;
  9359. return {
  9360. node,
  9361. error: failState.errors[oldState.errors.length],
  9362. thrown: false,
  9363. aborted: false,
  9364. failState
  9365. };
  9366. }
  9367. return {
  9368. node,
  9369. error: null,
  9370. thrown: false,
  9371. aborted: false,
  9372. failState: null
  9373. };
  9374. } catch (error) {
  9375. const failState = this.state;
  9376. this.state = oldState;
  9377. if (error instanceof SyntaxError) {
  9378. return {
  9379. node: null,
  9380. error,
  9381. thrown: true,
  9382. aborted: false,
  9383. failState
  9384. };
  9385. }
  9386. if (error === abortSignal) {
  9387. return {
  9388. node: abortSignal.node,
  9389. error: null,
  9390. thrown: false,
  9391. aborted: true,
  9392. failState
  9393. };
  9394. }
  9395. throw error;
  9396. }
  9397. }
  9398. checkExpressionErrors(refExpressionErrors, andThrow) {
  9399. if (!refExpressionErrors) return false;
  9400. const {
  9401. shorthandAssignLoc,
  9402. doubleProtoLoc,
  9403. privateKeyLoc,
  9404. optionalParametersLoc,
  9405. voidPatternLoc
  9406. } = refExpressionErrors;
  9407. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  9408. if (!andThrow) {
  9409. return hasErrors;
  9410. }
  9411. if (shorthandAssignLoc != null) {
  9412. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  9413. }
  9414. if (doubleProtoLoc != null) {
  9415. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  9416. }
  9417. if (privateKeyLoc != null) {
  9418. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  9419. }
  9420. if (optionalParametersLoc != null) {
  9421. this.unexpected(optionalParametersLoc);
  9422. }
  9423. if (voidPatternLoc != null) {
  9424. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  9425. }
  9426. }
  9427. isLiteralPropertyName() {
  9428. return tokenIsLiteralPropertyName(this.state.type);
  9429. }
  9430. isPrivateName(node) {
  9431. return node.type === "PrivateName";
  9432. }
  9433. getPrivateNameSV(node) {
  9434. return node.id.name;
  9435. }
  9436. hasPropertyAsPrivateName(node) {
  9437. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  9438. }
  9439. isObjectProperty(node) {
  9440. return node.type === "ObjectProperty";
  9441. }
  9442. isObjectMethod(node) {
  9443. return node.type === "ObjectMethod";
  9444. }
  9445. initializeScopes(inModule = this.options.sourceType === "module") {
  9446. const oldLabels = this.state.labels;
  9447. this.state.labels = [];
  9448. const oldExportedIdentifiers = this.exportedIdentifiers;
  9449. this.exportedIdentifiers = new Set();
  9450. const oldInModule = this.inModule;
  9451. this.inModule = inModule;
  9452. const oldScope = this.scope;
  9453. const ScopeHandler = this.getScopeHandler();
  9454. this.scope = new ScopeHandler(this, inModule);
  9455. const oldProdParam = this.prodParam;
  9456. this.prodParam = new ProductionParameterHandler();
  9457. const oldClassScope = this.classScope;
  9458. this.classScope = new ClassScopeHandler(this);
  9459. const oldExpressionScope = this.expressionScope;
  9460. this.expressionScope = new ExpressionScopeHandler(this);
  9461. return () => {
  9462. this.state.labels = oldLabels;
  9463. this.exportedIdentifiers = oldExportedIdentifiers;
  9464. this.inModule = oldInModule;
  9465. this.scope = oldScope;
  9466. this.prodParam = oldProdParam;
  9467. this.classScope = oldClassScope;
  9468. this.expressionScope = oldExpressionScope;
  9469. };
  9470. }
  9471. enterInitialScopes() {
  9472. let paramFlags = 0;
  9473. if (this.inModule || this.optionFlags & 1) {
  9474. paramFlags |= 2;
  9475. }
  9476. if (this.optionFlags & 32) {
  9477. paramFlags |= 1;
  9478. }
  9479. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  9480. if (isCommonJS || this.optionFlags & 2) {
  9481. paramFlags |= 4;
  9482. }
  9483. this.prodParam.enter(paramFlags);
  9484. let scopeFlags = isCommonJS ? 514 : 1;
  9485. if (this.optionFlags & 4) {
  9486. scopeFlags |= 512;
  9487. }
  9488. this.scope.enter(scopeFlags);
  9489. }
  9490. checkDestructuringPrivate(refExpressionErrors) {
  9491. const {
  9492. privateKeyLoc
  9493. } = refExpressionErrors;
  9494. if (privateKeyLoc !== null) {
  9495. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  9496. }
  9497. }
  9498. }
  9499. class ExpressionErrors {
  9500. constructor() {
  9501. this.shorthandAssignLoc = null;
  9502. this.doubleProtoLoc = null;
  9503. this.privateKeyLoc = null;
  9504. this.optionalParametersLoc = null;
  9505. this.voidPatternLoc = null;
  9506. }
  9507. }
  9508. class Node {
  9509. constructor(parser, pos, loc) {
  9510. this.type = "";
  9511. this.start = pos;
  9512. this.end = 0;
  9513. this.loc = new SourceLocation(loc);
  9514. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  9515. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  9516. }
  9517. }
  9518. const NodePrototype = Node.prototype;
  9519. {
  9520. NodePrototype.__clone = function () {
  9521. const newNode = new Node(undefined, this.start, this.loc.start);
  9522. const keys = Object.keys(this);
  9523. for (let i = 0, length = keys.length; i < length; i++) {
  9524. const key = keys[i];
  9525. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  9526. newNode[key] = this[key];
  9527. }
  9528. }
  9529. return newNode;
  9530. };
  9531. }
  9532. class NodeUtils extends UtilParser {
  9533. startNode() {
  9534. const loc = this.state.startLoc;
  9535. return new Node(this, loc.index, loc);
  9536. }
  9537. startNodeAt(loc) {
  9538. return new Node(this, loc.index, loc);
  9539. }
  9540. startNodeAtNode(type) {
  9541. return this.startNodeAt(type.loc.start);
  9542. }
  9543. finishNode(node, type) {
  9544. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  9545. }
  9546. finishNodeAt(node, type, endLoc) {
  9547. node.type = type;
  9548. node.end = endLoc.index;
  9549. node.loc.end = endLoc;
  9550. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  9551. if (this.optionFlags & 4096) {
  9552. this.processComment(node);
  9553. }
  9554. return node;
  9555. }
  9556. resetStartLocation(node, startLoc) {
  9557. node.start = startLoc.index;
  9558. node.loc.start = startLoc;
  9559. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  9560. }
  9561. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  9562. node.end = endLoc.index;
  9563. node.loc.end = endLoc;
  9564. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  9565. }
  9566. resetStartLocationFromNode(node, locationNode) {
  9567. this.resetStartLocation(node, locationNode.loc.start);
  9568. }
  9569. castNodeTo(node, type) {
  9570. node.type = type;
  9571. return node;
  9572. }
  9573. cloneIdentifier(node) {
  9574. const {
  9575. type,
  9576. start,
  9577. end,
  9578. loc,
  9579. range,
  9580. name
  9581. } = node;
  9582. const cloned = Object.create(NodePrototype);
  9583. cloned.type = type;
  9584. cloned.start = start;
  9585. cloned.end = end;
  9586. cloned.loc = loc;
  9587. cloned.range = range;
  9588. cloned.name = name;
  9589. if (node.extra) cloned.extra = node.extra;
  9590. return cloned;
  9591. }
  9592. cloneStringLiteral(node) {
  9593. const {
  9594. type,
  9595. start,
  9596. end,
  9597. loc,
  9598. range,
  9599. extra
  9600. } = node;
  9601. const cloned = Object.create(NodePrototype);
  9602. cloned.type = type;
  9603. cloned.start = start;
  9604. cloned.end = end;
  9605. cloned.loc = loc;
  9606. cloned.range = range;
  9607. cloned.extra = extra;
  9608. cloned.value = node.value;
  9609. return cloned;
  9610. }
  9611. }
  9612. const unwrapParenthesizedExpression = node => {
  9613. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  9614. };
  9615. class LValParser extends NodeUtils {
  9616. toAssignable(node, isLHS = false) {
  9617. var _node$extra, _node$extra3;
  9618. let parenthesized = undefined;
  9619. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  9620. parenthesized = unwrapParenthesizedExpression(node);
  9621. if (isLHS) {
  9622. if (parenthesized.type === "Identifier") {
  9623. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  9624. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  9625. this.raise(Errors.InvalidParenthesizedAssignment, node);
  9626. }
  9627. } else {
  9628. this.raise(Errors.InvalidParenthesizedAssignment, node);
  9629. }
  9630. }
  9631. switch (node.type) {
  9632. case "Identifier":
  9633. case "ObjectPattern":
  9634. case "ArrayPattern":
  9635. case "AssignmentPattern":
  9636. case "RestElement":
  9637. case "VoidPattern":
  9638. break;
  9639. case "ObjectExpression":
  9640. this.castNodeTo(node, "ObjectPattern");
  9641. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  9642. var _node$extra2;
  9643. const prop = node.properties[i];
  9644. const isLast = i === last;
  9645. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  9646. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  9647. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  9648. }
  9649. }
  9650. break;
  9651. case "ObjectProperty":
  9652. {
  9653. const {
  9654. key,
  9655. value
  9656. } = node;
  9657. if (this.isPrivateName(key)) {
  9658. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  9659. }
  9660. this.toAssignable(value, isLHS);
  9661. break;
  9662. }
  9663. case "SpreadElement":
  9664. {
  9665. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  9666. }
  9667. case "ArrayExpression":
  9668. this.castNodeTo(node, "ArrayPattern");
  9669. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  9670. break;
  9671. case "AssignmentExpression":
  9672. if (node.operator !== "=") {
  9673. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  9674. }
  9675. this.castNodeTo(node, "AssignmentPattern");
  9676. delete node.operator;
  9677. if (node.left.type === "VoidPattern") {
  9678. this.raise(Errors.VoidPatternInitializer, node.left);
  9679. }
  9680. this.toAssignable(node.left, isLHS);
  9681. break;
  9682. case "ParenthesizedExpression":
  9683. this.toAssignable(parenthesized, isLHS);
  9684. break;
  9685. }
  9686. }
  9687. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  9688. if (prop.type === "ObjectMethod") {
  9689. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  9690. } else if (prop.type === "SpreadElement") {
  9691. this.castNodeTo(prop, "RestElement");
  9692. const arg = prop.argument;
  9693. this.checkToRestConversion(arg, false);
  9694. this.toAssignable(arg, isLHS);
  9695. if (!isLast) {
  9696. this.raise(Errors.RestTrailingComma, prop);
  9697. }
  9698. } else {
  9699. this.toAssignable(prop, isLHS);
  9700. }
  9701. }
  9702. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9703. const end = exprList.length - 1;
  9704. for (let i = 0; i <= end; i++) {
  9705. const elt = exprList[i];
  9706. if (!elt) continue;
  9707. this.toAssignableListItem(exprList, i, isLHS);
  9708. if (elt.type === "RestElement") {
  9709. if (i < end) {
  9710. this.raise(Errors.RestTrailingComma, elt);
  9711. } else if (trailingCommaLoc) {
  9712. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  9713. }
  9714. }
  9715. }
  9716. }
  9717. toAssignableListItem(exprList, index, isLHS) {
  9718. const node = exprList[index];
  9719. if (node.type === "SpreadElement") {
  9720. this.castNodeTo(node, "RestElement");
  9721. const arg = node.argument;
  9722. this.checkToRestConversion(arg, true);
  9723. this.toAssignable(arg, isLHS);
  9724. } else {
  9725. this.toAssignable(node, isLHS);
  9726. }
  9727. }
  9728. isAssignable(node, isBinding) {
  9729. switch (node.type) {
  9730. case "Identifier":
  9731. case "ObjectPattern":
  9732. case "ArrayPattern":
  9733. case "AssignmentPattern":
  9734. case "RestElement":
  9735. case "VoidPattern":
  9736. return true;
  9737. case "ObjectExpression":
  9738. {
  9739. const last = node.properties.length - 1;
  9740. return node.properties.every((prop, i) => {
  9741. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  9742. });
  9743. }
  9744. case "ObjectProperty":
  9745. return this.isAssignable(node.value);
  9746. case "SpreadElement":
  9747. return this.isAssignable(node.argument);
  9748. case "ArrayExpression":
  9749. return node.elements.every(element => element === null || this.isAssignable(element));
  9750. case "AssignmentExpression":
  9751. return node.operator === "=";
  9752. case "ParenthesizedExpression":
  9753. return this.isAssignable(node.expression);
  9754. case "MemberExpression":
  9755. case "OptionalMemberExpression":
  9756. return !isBinding;
  9757. default:
  9758. return false;
  9759. }
  9760. }
  9761. toReferencedList(exprList, isParenthesizedExpr) {
  9762. return exprList;
  9763. }
  9764. toReferencedListDeep(exprList, isParenthesizedExpr) {
  9765. this.toReferencedList(exprList, isParenthesizedExpr);
  9766. for (const expr of exprList) {
  9767. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  9768. this.toReferencedListDeep(expr.elements);
  9769. }
  9770. }
  9771. }
  9772. parseSpread(refExpressionErrors) {
  9773. const node = this.startNode();
  9774. this.next();
  9775. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  9776. return this.finishNode(node, "SpreadElement");
  9777. }
  9778. parseRestBinding() {
  9779. const node = this.startNode();
  9780. this.next();
  9781. const argument = this.parseBindingAtom();
  9782. if (argument.type === "VoidPattern") {
  9783. this.raise(Errors.UnexpectedVoidPattern, argument);
  9784. }
  9785. node.argument = argument;
  9786. return this.finishNode(node, "RestElement");
  9787. }
  9788. parseBindingAtom() {
  9789. switch (this.state.type) {
  9790. case 0:
  9791. {
  9792. const node = this.startNode();
  9793. this.next();
  9794. node.elements = this.parseBindingList(3, 93, 1);
  9795. return this.finishNode(node, "ArrayPattern");
  9796. }
  9797. case 5:
  9798. return this.parseObjectLike(8, true);
  9799. case 88:
  9800. return this.parseVoidPattern(null);
  9801. }
  9802. return this.parseIdentifier();
  9803. }
  9804. parseBindingList(close, closeCharCode, flags) {
  9805. const allowEmpty = flags & 1;
  9806. const elts = [];
  9807. let first = true;
  9808. while (!this.eat(close)) {
  9809. if (first) {
  9810. first = false;
  9811. } else {
  9812. this.expect(12);
  9813. }
  9814. if (allowEmpty && this.match(12)) {
  9815. elts.push(null);
  9816. } else if (this.eat(close)) {
  9817. break;
  9818. } else if (this.match(21)) {
  9819. let rest = this.parseRestBinding();
  9820. if (this.hasPlugin("flow") || flags & 2) {
  9821. rest = this.parseFunctionParamType(rest);
  9822. }
  9823. elts.push(rest);
  9824. if (!this.checkCommaAfterRest(closeCharCode)) {
  9825. this.expect(close);
  9826. break;
  9827. }
  9828. } else {
  9829. const decorators = [];
  9830. if (flags & 2) {
  9831. if (this.match(26) && this.hasPlugin("decorators")) {
  9832. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  9833. }
  9834. while (this.match(26)) {
  9835. decorators.push(this.parseDecorator());
  9836. }
  9837. }
  9838. elts.push(this.parseBindingElement(flags, decorators));
  9839. }
  9840. }
  9841. return elts;
  9842. }
  9843. parseBindingRestProperty(prop) {
  9844. this.next();
  9845. if (this.hasPlugin("discardBinding") && this.match(88)) {
  9846. prop.argument = this.parseVoidPattern(null);
  9847. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  9848. } else {
  9849. prop.argument = this.parseIdentifier();
  9850. }
  9851. this.checkCommaAfterRest(125);
  9852. return this.finishNode(prop, "RestElement");
  9853. }
  9854. parseBindingProperty() {
  9855. const {
  9856. type,
  9857. startLoc
  9858. } = this.state;
  9859. if (type === 21) {
  9860. return this.parseBindingRestProperty(this.startNode());
  9861. }
  9862. const prop = this.startNode();
  9863. if (type === 139) {
  9864. this.expectPlugin("destructuringPrivate", startLoc);
  9865. this.classScope.usePrivateName(this.state.value, startLoc);
  9866. prop.key = this.parsePrivateName();
  9867. } else {
  9868. this.parsePropertyName(prop);
  9869. }
  9870. prop.method = false;
  9871. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  9872. }
  9873. parseBindingElement(flags, decorators) {
  9874. const left = this.parseMaybeDefault();
  9875. if (this.hasPlugin("flow") || flags & 2) {
  9876. this.parseFunctionParamType(left);
  9877. }
  9878. if (decorators.length) {
  9879. left.decorators = decorators;
  9880. this.resetStartLocationFromNode(left, decorators[0]);
  9881. }
  9882. const elt = this.parseMaybeDefault(left.loc.start, left);
  9883. return elt;
  9884. }
  9885. parseFunctionParamType(param) {
  9886. return param;
  9887. }
  9888. parseMaybeDefault(startLoc, left) {
  9889. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  9890. left = left != null ? left : this.parseBindingAtom();
  9891. if (!this.eat(29)) return left;
  9892. const node = this.startNodeAt(startLoc);
  9893. if (left.type === "VoidPattern") {
  9894. this.raise(Errors.VoidPatternInitializer, left);
  9895. }
  9896. node.left = left;
  9897. node.right = this.parseMaybeAssignAllowIn();
  9898. return this.finishNode(node, "AssignmentPattern");
  9899. }
  9900. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9901. switch (type) {
  9902. case "AssignmentPattern":
  9903. return "left";
  9904. case "RestElement":
  9905. return "argument";
  9906. case "ObjectProperty":
  9907. return "value";
  9908. case "ParenthesizedExpression":
  9909. return "expression";
  9910. case "ArrayPattern":
  9911. return "elements";
  9912. case "ObjectPattern":
  9913. return "properties";
  9914. case "VoidPattern":
  9915. return true;
  9916. }
  9917. return false;
  9918. }
  9919. isOptionalMemberExpression(expression) {
  9920. return expression.type === "OptionalMemberExpression";
  9921. }
  9922. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  9923. var _expression$extra;
  9924. const type = expression.type;
  9925. if (this.isObjectMethod(expression)) return;
  9926. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  9927. if (isOptionalMemberExpression || type === "MemberExpression") {
  9928. if (isOptionalMemberExpression) {
  9929. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  9930. if (ancestor.type !== "AssignmentExpression") {
  9931. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  9932. ancestor
  9933. });
  9934. }
  9935. }
  9936. if (binding !== 64) {
  9937. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  9938. }
  9939. return;
  9940. }
  9941. if (type === "Identifier") {
  9942. this.checkIdentifier(expression, binding, strictModeChanged);
  9943. const {
  9944. name
  9945. } = expression;
  9946. if (checkClashes) {
  9947. if (checkClashes.has(name)) {
  9948. this.raise(Errors.ParamDupe, expression);
  9949. } else {
  9950. checkClashes.add(name);
  9951. }
  9952. }
  9953. return;
  9954. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  9955. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  9956. }
  9957. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  9958. if (validity === true) return;
  9959. if (validity === false) {
  9960. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  9961. this.raise(ParseErrorClass, expression, {
  9962. ancestor
  9963. });
  9964. return;
  9965. }
  9966. let key, isParenthesizedExpression;
  9967. if (typeof validity === "string") {
  9968. key = validity;
  9969. isParenthesizedExpression = type === "ParenthesizedExpression";
  9970. } else {
  9971. [key, isParenthesizedExpression] = validity;
  9972. }
  9973. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  9974. type
  9975. } : ancestor;
  9976. const val = expression[key];
  9977. if (Array.isArray(val)) {
  9978. for (const child of val) {
  9979. if (child) {
  9980. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  9981. }
  9982. }
  9983. } else if (val) {
  9984. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  9985. }
  9986. }
  9987. checkIdentifier(at, bindingType, strictModeChanged = false) {
  9988. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  9989. if (bindingType === 64) {
  9990. this.raise(Errors.StrictEvalArguments, at, {
  9991. referenceName: at.name
  9992. });
  9993. } else {
  9994. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  9995. bindingName: at.name
  9996. });
  9997. }
  9998. }
  9999. if (bindingType & 8192 && at.name === "let") {
  10000. this.raise(Errors.LetInLexicalBinding, at);
  10001. }
  10002. if (!(bindingType & 64)) {
  10003. this.declareNameFromIdentifier(at, bindingType);
  10004. }
  10005. }
  10006. declareNameFromIdentifier(identifier, binding) {
  10007. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  10008. }
  10009. checkToRestConversion(node, allowPattern) {
  10010. switch (node.type) {
  10011. case "ParenthesizedExpression":
  10012. this.checkToRestConversion(node.expression, allowPattern);
  10013. break;
  10014. case "Identifier":
  10015. case "MemberExpression":
  10016. break;
  10017. case "ArrayExpression":
  10018. case "ObjectExpression":
  10019. if (allowPattern) break;
  10020. default:
  10021. this.raise(Errors.InvalidRestAssignmentPattern, node);
  10022. }
  10023. }
  10024. checkCommaAfterRest(close) {
  10025. if (!this.match(12)) {
  10026. return false;
  10027. }
  10028. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  10029. return true;
  10030. }
  10031. }
  10032. function nonNull(x) {
  10033. if (x == null) {
  10034. throw new Error(`Unexpected ${x} value.`);
  10035. }
  10036. return x;
  10037. }
  10038. function assert(x) {
  10039. if (!x) {
  10040. throw new Error("Assert fail");
  10041. }
  10042. }
  10043. const TSErrors = ParseErrorEnum`typescript`({
  10044. AbstractMethodHasImplementation: ({
  10045. methodName
  10046. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  10047. AbstractPropertyHasInitializer: ({
  10048. propertyName
  10049. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  10050. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  10051. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  10052. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  10053. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  10054. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  10055. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  10056. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  10057. DeclareAccessor: ({
  10058. kind
  10059. }) => `'declare' is not allowed in ${kind}ters.`,
  10060. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  10061. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  10062. DuplicateAccessibilityModifier: ({
  10063. modifier
  10064. }) => `Accessibility modifier already seen: '${modifier}'.`,
  10065. DuplicateModifier: ({
  10066. modifier
  10067. }) => `Duplicate modifier: '${modifier}'.`,
  10068. EmptyHeritageClauseType: ({
  10069. token
  10070. }) => `'${token}' list cannot be empty.`,
  10071. EmptyTypeArguments: "Type argument list cannot be empty.",
  10072. EmptyTypeParameters: "Type parameter list cannot be empty.",
  10073. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  10074. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  10075. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  10076. IncompatibleModifiers: ({
  10077. modifiers
  10078. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  10079. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  10080. IndexSignatureHasAccessibility: ({
  10081. modifier
  10082. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  10083. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  10084. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  10085. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  10086. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  10087. InvalidHeritageClauseType: ({
  10088. token
  10089. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  10090. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  10091. InvalidModifierOnTypeMember: ({
  10092. modifier
  10093. }) => `'${modifier}' modifier cannot appear on a type member.`,
  10094. InvalidModifierOnTypeParameter: ({
  10095. modifier
  10096. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  10097. InvalidModifierOnTypeParameterPositions: ({
  10098. modifier
  10099. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  10100. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  10101. InvalidModifiersOrder: ({
  10102. orderedModifiers
  10103. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  10104. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  10105. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  10106. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  10107. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  10108. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  10109. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  10110. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  10111. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  10112. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  10113. PrivateElementHasAccessibility: ({
  10114. modifier
  10115. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  10116. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  10117. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  10118. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  10119. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  10120. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  10121. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  10122. SingleTypeParameterWithoutTrailingComma: ({
  10123. typeParameterName
  10124. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  10125. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  10126. 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?`).",
  10127. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  10128. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  10129. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  10130. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  10131. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  10132. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  10133. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  10134. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  10135. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  10136. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  10137. UnsupportedSignatureParameterKind: ({
  10138. type
  10139. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  10140. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  10141. });
  10142. function keywordTypeFromName(value) {
  10143. switch (value) {
  10144. case "any":
  10145. return "TSAnyKeyword";
  10146. case "boolean":
  10147. return "TSBooleanKeyword";
  10148. case "bigint":
  10149. return "TSBigIntKeyword";
  10150. case "never":
  10151. return "TSNeverKeyword";
  10152. case "number":
  10153. return "TSNumberKeyword";
  10154. case "object":
  10155. return "TSObjectKeyword";
  10156. case "string":
  10157. return "TSStringKeyword";
  10158. case "symbol":
  10159. return "TSSymbolKeyword";
  10160. case "undefined":
  10161. return "TSUndefinedKeyword";
  10162. case "unknown":
  10163. return "TSUnknownKeyword";
  10164. default:
  10165. return undefined;
  10166. }
  10167. }
  10168. function tsIsAccessModifier(modifier) {
  10169. return modifier === "private" || modifier === "public" || modifier === "protected";
  10170. }
  10171. function tsIsVarianceAnnotations(modifier) {
  10172. return modifier === "in" || modifier === "out";
  10173. }
  10174. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  10175. constructor(...args) {
  10176. super(...args);
  10177. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  10178. allowedModifiers: ["in", "out"],
  10179. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  10180. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  10181. });
  10182. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  10183. allowedModifiers: ["const"],
  10184. disallowedModifiers: ["in", "out"],
  10185. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  10186. });
  10187. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  10188. allowedModifiers: ["in", "out", "const"],
  10189. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  10190. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  10191. });
  10192. }
  10193. getScopeHandler() {
  10194. return TypeScriptScopeHandler;
  10195. }
  10196. tsIsIdentifier() {
  10197. return tokenIsIdentifier(this.state.type);
  10198. }
  10199. tsTokenCanFollowModifier() {
  10200. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  10201. }
  10202. tsNextTokenOnSameLineAndCanFollowModifier() {
  10203. this.next();
  10204. if (this.hasPrecedingLineBreak()) {
  10205. return false;
  10206. }
  10207. return this.tsTokenCanFollowModifier();
  10208. }
  10209. tsNextTokenCanFollowModifier() {
  10210. if (this.match(106)) {
  10211. this.next();
  10212. return this.tsTokenCanFollowModifier();
  10213. }
  10214. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  10215. }
  10216. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  10217. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  10218. return undefined;
  10219. }
  10220. const modifier = this.state.value;
  10221. if (allowedModifiers.includes(modifier)) {
  10222. if (hasSeenStaticModifier && this.match(106)) {
  10223. return undefined;
  10224. }
  10225. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  10226. return undefined;
  10227. }
  10228. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  10229. return modifier;
  10230. }
  10231. }
  10232. return undefined;
  10233. }
  10234. tsParseModifiers({
  10235. allowedModifiers,
  10236. disallowedModifiers,
  10237. stopOnStartOfClassStaticBlock,
  10238. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  10239. }, modified) {
  10240. const enforceOrder = (loc, modifier, before, after) => {
  10241. if (modifier === before && modified[after]) {
  10242. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  10243. orderedModifiers: [before, after]
  10244. });
  10245. }
  10246. };
  10247. const incompatible = (loc, modifier, mod1, mod2) => {
  10248. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  10249. this.raise(TSErrors.IncompatibleModifiers, loc, {
  10250. modifiers: [mod1, mod2]
  10251. });
  10252. }
  10253. };
  10254. for (;;) {
  10255. const {
  10256. startLoc
  10257. } = this.state;
  10258. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  10259. if (!modifier) break;
  10260. if (tsIsAccessModifier(modifier)) {
  10261. if (modified.accessibility) {
  10262. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  10263. modifier
  10264. });
  10265. } else {
  10266. enforceOrder(startLoc, modifier, modifier, "override");
  10267. enforceOrder(startLoc, modifier, modifier, "static");
  10268. enforceOrder(startLoc, modifier, modifier, "readonly");
  10269. modified.accessibility = modifier;
  10270. }
  10271. } else if (tsIsVarianceAnnotations(modifier)) {
  10272. if (modified[modifier]) {
  10273. this.raise(TSErrors.DuplicateModifier, startLoc, {
  10274. modifier
  10275. });
  10276. }
  10277. modified[modifier] = true;
  10278. enforceOrder(startLoc, modifier, "in", "out");
  10279. } else {
  10280. if (hasOwnProperty.call(modified, modifier)) {
  10281. this.raise(TSErrors.DuplicateModifier, startLoc, {
  10282. modifier
  10283. });
  10284. } else {
  10285. enforceOrder(startLoc, modifier, "static", "readonly");
  10286. enforceOrder(startLoc, modifier, "static", "override");
  10287. enforceOrder(startLoc, modifier, "override", "readonly");
  10288. enforceOrder(startLoc, modifier, "abstract", "override");
  10289. incompatible(startLoc, modifier, "declare", "override");
  10290. incompatible(startLoc, modifier, "static", "abstract");
  10291. }
  10292. modified[modifier] = true;
  10293. }
  10294. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  10295. this.raise(errorTemplate, startLoc, {
  10296. modifier
  10297. });
  10298. }
  10299. }
  10300. }
  10301. tsIsListTerminator(kind) {
  10302. switch (kind) {
  10303. case "EnumMembers":
  10304. case "TypeMembers":
  10305. return this.match(8);
  10306. case "HeritageClauseElement":
  10307. return this.match(5);
  10308. case "TupleElementTypes":
  10309. return this.match(3);
  10310. case "TypeParametersOrArguments":
  10311. return this.match(48);
  10312. }
  10313. }
  10314. tsParseList(kind, parseElement) {
  10315. const result = [];
  10316. while (!this.tsIsListTerminator(kind)) {
  10317. result.push(parseElement());
  10318. }
  10319. return result;
  10320. }
  10321. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  10322. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  10323. }
  10324. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  10325. const result = [];
  10326. let trailingCommaPos = -1;
  10327. for (;;) {
  10328. if (this.tsIsListTerminator(kind)) {
  10329. break;
  10330. }
  10331. trailingCommaPos = -1;
  10332. const element = parseElement();
  10333. if (element == null) {
  10334. return undefined;
  10335. }
  10336. result.push(element);
  10337. if (this.eat(12)) {
  10338. trailingCommaPos = this.state.lastTokStartLoc.index;
  10339. continue;
  10340. }
  10341. if (this.tsIsListTerminator(kind)) {
  10342. break;
  10343. }
  10344. if (expectSuccess) {
  10345. this.expect(12);
  10346. }
  10347. return undefined;
  10348. }
  10349. if (refTrailingCommaPos) {
  10350. refTrailingCommaPos.value = trailingCommaPos;
  10351. }
  10352. return result;
  10353. }
  10354. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  10355. if (!skipFirstToken) {
  10356. if (bracket) {
  10357. this.expect(0);
  10358. } else {
  10359. this.expect(47);
  10360. }
  10361. }
  10362. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  10363. if (bracket) {
  10364. this.expect(3);
  10365. } else {
  10366. this.expect(48);
  10367. }
  10368. return result;
  10369. }
  10370. tsParseImportType() {
  10371. const node = this.startNode();
  10372. this.expect(83);
  10373. this.expect(10);
  10374. if (!this.match(134)) {
  10375. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  10376. {
  10377. node.argument = super.parseExprAtom();
  10378. }
  10379. } else {
  10380. {
  10381. node.argument = this.parseStringLiteral(this.state.value);
  10382. }
  10383. }
  10384. if (this.eat(12)) {
  10385. node.options = this.tsParseImportTypeOptions();
  10386. } else {
  10387. node.options = null;
  10388. }
  10389. this.expect(11);
  10390. if (this.eat(16)) {
  10391. node.qualifier = this.tsParseEntityName(1 | 2);
  10392. }
  10393. if (this.match(47)) {
  10394. {
  10395. node.typeParameters = this.tsParseTypeArguments();
  10396. }
  10397. }
  10398. return this.finishNode(node, "TSImportType");
  10399. }
  10400. tsParseImportTypeOptions() {
  10401. const node = this.startNode();
  10402. this.expect(5);
  10403. const withProperty = this.startNode();
  10404. if (this.isContextual(76)) {
  10405. withProperty.method = false;
  10406. withProperty.key = this.parseIdentifier(true);
  10407. withProperty.computed = false;
  10408. withProperty.shorthand = false;
  10409. } else {
  10410. this.unexpected(null, 76);
  10411. }
  10412. this.expect(14);
  10413. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  10414. node.properties = [this.finishObjectProperty(withProperty)];
  10415. this.eat(12);
  10416. this.expect(8);
  10417. return this.finishNode(node, "ObjectExpression");
  10418. }
  10419. tsParseImportTypeWithPropertyValue() {
  10420. const node = this.startNode();
  10421. const properties = [];
  10422. this.expect(5);
  10423. while (!this.match(8)) {
  10424. const type = this.state.type;
  10425. if (tokenIsIdentifier(type) || type === 134) {
  10426. properties.push(super.parsePropertyDefinition(null));
  10427. } else {
  10428. this.unexpected();
  10429. }
  10430. this.eat(12);
  10431. }
  10432. node.properties = properties;
  10433. this.next();
  10434. return this.finishNode(node, "ObjectExpression");
  10435. }
  10436. tsParseEntityName(flags) {
  10437. let entity;
  10438. if (flags & 1 && this.match(78)) {
  10439. if (flags & 2) {
  10440. entity = this.parseIdentifier(true);
  10441. } else {
  10442. const node = this.startNode();
  10443. this.next();
  10444. entity = this.finishNode(node, "ThisExpression");
  10445. }
  10446. } else {
  10447. entity = this.parseIdentifier(!!(flags & 1));
  10448. }
  10449. while (this.eat(16)) {
  10450. const node = this.startNodeAtNode(entity);
  10451. node.left = entity;
  10452. node.right = this.parseIdentifier(!!(flags & 1));
  10453. entity = this.finishNode(node, "TSQualifiedName");
  10454. }
  10455. return entity;
  10456. }
  10457. tsParseTypeReference() {
  10458. const node = this.startNode();
  10459. node.typeName = this.tsParseEntityName(1);
  10460. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  10461. {
  10462. node.typeParameters = this.tsParseTypeArguments();
  10463. }
  10464. }
  10465. return this.finishNode(node, "TSTypeReference");
  10466. }
  10467. tsParseThisTypePredicate(lhs) {
  10468. this.next();
  10469. const node = this.startNodeAtNode(lhs);
  10470. node.parameterName = lhs;
  10471. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  10472. node.asserts = false;
  10473. return this.finishNode(node, "TSTypePredicate");
  10474. }
  10475. tsParseThisTypeNode() {
  10476. const node = this.startNode();
  10477. this.next();
  10478. return this.finishNode(node, "TSThisType");
  10479. }
  10480. tsParseTypeQuery() {
  10481. const node = this.startNode();
  10482. this.expect(87);
  10483. if (this.match(83)) {
  10484. node.exprName = this.tsParseImportType();
  10485. } else {
  10486. {
  10487. node.exprName = this.tsParseEntityName(1 | 2);
  10488. }
  10489. }
  10490. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  10491. {
  10492. node.typeParameters = this.tsParseTypeArguments();
  10493. }
  10494. }
  10495. return this.finishNode(node, "TSTypeQuery");
  10496. }
  10497. tsParseTypeParameter(parseModifiers) {
  10498. const node = this.startNode();
  10499. parseModifiers(node);
  10500. node.name = this.tsParseTypeParameterName();
  10501. node.constraint = this.tsEatThenParseType(81);
  10502. node.default = this.tsEatThenParseType(29);
  10503. return this.finishNode(node, "TSTypeParameter");
  10504. }
  10505. tsTryParseTypeParameters(parseModifiers) {
  10506. if (this.match(47)) {
  10507. return this.tsParseTypeParameters(parseModifiers);
  10508. }
  10509. }
  10510. tsParseTypeParameters(parseModifiers) {
  10511. const node = this.startNode();
  10512. if (this.match(47) || this.match(143)) {
  10513. this.next();
  10514. } else {
  10515. this.unexpected();
  10516. }
  10517. const refTrailingCommaPos = {
  10518. value: -1
  10519. };
  10520. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  10521. if (node.params.length === 0) {
  10522. this.raise(TSErrors.EmptyTypeParameters, node);
  10523. }
  10524. if (refTrailingCommaPos.value !== -1) {
  10525. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  10526. }
  10527. return this.finishNode(node, "TSTypeParameterDeclaration");
  10528. }
  10529. tsFillSignature(returnToken, signature) {
  10530. const returnTokenRequired = returnToken === 19;
  10531. const paramsKey = "parameters";
  10532. const returnTypeKey = "typeAnnotation";
  10533. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10534. this.expect(10);
  10535. signature[paramsKey] = this.tsParseBindingListForSignature();
  10536. if (returnTokenRequired) {
  10537. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  10538. } else if (this.match(returnToken)) {
  10539. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  10540. }
  10541. }
  10542. tsParseBindingListForSignature() {
  10543. const list = super.parseBindingList(11, 41, 2);
  10544. for (const pattern of list) {
  10545. const {
  10546. type
  10547. } = pattern;
  10548. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  10549. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  10550. type
  10551. });
  10552. }
  10553. }
  10554. return list;
  10555. }
  10556. tsParseTypeMemberSemicolon() {
  10557. if (!this.eat(12) && !this.isLineTerminator()) {
  10558. this.expect(13);
  10559. }
  10560. }
  10561. tsParseSignatureMember(kind, node) {
  10562. this.tsFillSignature(14, node);
  10563. this.tsParseTypeMemberSemicolon();
  10564. return this.finishNode(node, kind);
  10565. }
  10566. tsIsUnambiguouslyIndexSignature() {
  10567. this.next();
  10568. if (tokenIsIdentifier(this.state.type)) {
  10569. this.next();
  10570. return this.match(14);
  10571. }
  10572. return false;
  10573. }
  10574. tsTryParseIndexSignature(node) {
  10575. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  10576. return;
  10577. }
  10578. this.expect(0);
  10579. const id = this.parseIdentifier();
  10580. id.typeAnnotation = this.tsParseTypeAnnotation();
  10581. this.resetEndLocation(id);
  10582. this.expect(3);
  10583. node.parameters = [id];
  10584. const type = this.tsTryParseTypeAnnotation();
  10585. if (type) node.typeAnnotation = type;
  10586. this.tsParseTypeMemberSemicolon();
  10587. return this.finishNode(node, "TSIndexSignature");
  10588. }
  10589. tsParsePropertyOrMethodSignature(node, readonly) {
  10590. if (this.eat(17)) node.optional = true;
  10591. if (this.match(10) || this.match(47)) {
  10592. if (readonly) {
  10593. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  10594. }
  10595. const method = node;
  10596. if (method.kind && this.match(47)) {
  10597. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  10598. }
  10599. this.tsFillSignature(14, method);
  10600. this.tsParseTypeMemberSemicolon();
  10601. const paramsKey = "parameters";
  10602. const returnTypeKey = "typeAnnotation";
  10603. if (method.kind === "get") {
  10604. if (method[paramsKey].length > 0) {
  10605. this.raise(Errors.BadGetterArity, this.state.curPosition());
  10606. if (this.isThisParam(method[paramsKey][0])) {
  10607. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  10608. }
  10609. }
  10610. } else if (method.kind === "set") {
  10611. if (method[paramsKey].length !== 1) {
  10612. this.raise(Errors.BadSetterArity, this.state.curPosition());
  10613. } else {
  10614. const firstParameter = method[paramsKey][0];
  10615. if (this.isThisParam(firstParameter)) {
  10616. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  10617. }
  10618. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  10619. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  10620. }
  10621. if (firstParameter.type === "RestElement") {
  10622. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  10623. }
  10624. }
  10625. if (method[returnTypeKey]) {
  10626. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  10627. }
  10628. } else {
  10629. method.kind = "method";
  10630. }
  10631. return this.finishNode(method, "TSMethodSignature");
  10632. } else {
  10633. const property = node;
  10634. if (readonly) property.readonly = true;
  10635. const type = this.tsTryParseTypeAnnotation();
  10636. if (type) property.typeAnnotation = type;
  10637. this.tsParseTypeMemberSemicolon();
  10638. return this.finishNode(property, "TSPropertySignature");
  10639. }
  10640. }
  10641. tsParseTypeMember() {
  10642. const node = this.startNode();
  10643. if (this.match(10) || this.match(47)) {
  10644. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  10645. }
  10646. if (this.match(77)) {
  10647. const id = this.startNode();
  10648. this.next();
  10649. if (this.match(10) || this.match(47)) {
  10650. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  10651. } else {
  10652. node.key = this.createIdentifier(id, "new");
  10653. return this.tsParsePropertyOrMethodSignature(node, false);
  10654. }
  10655. }
  10656. this.tsParseModifiers({
  10657. allowedModifiers: ["readonly"],
  10658. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  10659. }, node);
  10660. const idx = this.tsTryParseIndexSignature(node);
  10661. if (idx) {
  10662. return idx;
  10663. }
  10664. super.parsePropertyName(node);
  10665. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  10666. node.kind = node.key.name;
  10667. super.parsePropertyName(node);
  10668. if (!this.match(10) && !this.match(47)) {
  10669. this.unexpected(null, 10);
  10670. }
  10671. }
  10672. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  10673. }
  10674. tsParseTypeLiteral() {
  10675. const node = this.startNode();
  10676. node.members = this.tsParseObjectTypeMembers();
  10677. return this.finishNode(node, "TSTypeLiteral");
  10678. }
  10679. tsParseObjectTypeMembers() {
  10680. this.expect(5);
  10681. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  10682. this.expect(8);
  10683. return members;
  10684. }
  10685. tsIsStartOfMappedType() {
  10686. this.next();
  10687. if (this.eat(53)) {
  10688. return this.isContextual(122);
  10689. }
  10690. if (this.isContextual(122)) {
  10691. this.next();
  10692. }
  10693. if (!this.match(0)) {
  10694. return false;
  10695. }
  10696. this.next();
  10697. if (!this.tsIsIdentifier()) {
  10698. return false;
  10699. }
  10700. this.next();
  10701. return this.match(58);
  10702. }
  10703. tsParseMappedType() {
  10704. const node = this.startNode();
  10705. this.expect(5);
  10706. if (this.match(53)) {
  10707. node.readonly = this.state.value;
  10708. this.next();
  10709. this.expectContextual(122);
  10710. } else if (this.eatContextual(122)) {
  10711. node.readonly = true;
  10712. }
  10713. this.expect(0);
  10714. {
  10715. const typeParameter = this.startNode();
  10716. typeParameter.name = this.tsParseTypeParameterName();
  10717. typeParameter.constraint = this.tsExpectThenParseType(58);
  10718. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  10719. }
  10720. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  10721. this.expect(3);
  10722. if (this.match(53)) {
  10723. node.optional = this.state.value;
  10724. this.next();
  10725. this.expect(17);
  10726. } else if (this.eat(17)) {
  10727. node.optional = true;
  10728. }
  10729. node.typeAnnotation = this.tsTryParseType();
  10730. this.semicolon();
  10731. this.expect(8);
  10732. return this.finishNode(node, "TSMappedType");
  10733. }
  10734. tsParseTupleType() {
  10735. const node = this.startNode();
  10736. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  10737. let seenOptionalElement = false;
  10738. node.elementTypes.forEach(elementNode => {
  10739. const {
  10740. type
  10741. } = elementNode;
  10742. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  10743. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  10744. }
  10745. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  10746. });
  10747. return this.finishNode(node, "TSTupleType");
  10748. }
  10749. tsParseTupleElementType() {
  10750. const restStartLoc = this.state.startLoc;
  10751. const rest = this.eat(21);
  10752. const {
  10753. startLoc
  10754. } = this.state;
  10755. let labeled;
  10756. let label;
  10757. let optional;
  10758. let type;
  10759. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  10760. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  10761. if (chAfterWord === 58) {
  10762. labeled = true;
  10763. optional = false;
  10764. label = this.parseIdentifier(true);
  10765. this.expect(14);
  10766. type = this.tsParseType();
  10767. } else if (chAfterWord === 63) {
  10768. optional = true;
  10769. const wordName = this.state.value;
  10770. const typeOrLabel = this.tsParseNonArrayType();
  10771. if (this.lookaheadCharCode() === 58) {
  10772. labeled = true;
  10773. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  10774. this.expect(17);
  10775. this.expect(14);
  10776. type = this.tsParseType();
  10777. } else {
  10778. labeled = false;
  10779. type = typeOrLabel;
  10780. this.expect(17);
  10781. }
  10782. } else {
  10783. type = this.tsParseType();
  10784. optional = this.eat(17);
  10785. labeled = this.eat(14);
  10786. }
  10787. if (labeled) {
  10788. let labeledNode;
  10789. if (label) {
  10790. labeledNode = this.startNodeAt(startLoc);
  10791. labeledNode.optional = optional;
  10792. labeledNode.label = label;
  10793. labeledNode.elementType = type;
  10794. if (this.eat(17)) {
  10795. labeledNode.optional = true;
  10796. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  10797. }
  10798. } else {
  10799. labeledNode = this.startNodeAt(startLoc);
  10800. labeledNode.optional = optional;
  10801. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  10802. labeledNode.label = type;
  10803. labeledNode.elementType = this.tsParseType();
  10804. }
  10805. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  10806. } else if (optional) {
  10807. const optionalTypeNode = this.startNodeAt(startLoc);
  10808. optionalTypeNode.typeAnnotation = type;
  10809. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  10810. }
  10811. if (rest) {
  10812. const restNode = this.startNodeAt(restStartLoc);
  10813. restNode.typeAnnotation = type;
  10814. type = this.finishNode(restNode, "TSRestType");
  10815. }
  10816. return type;
  10817. }
  10818. tsParseParenthesizedType() {
  10819. const node = this.startNode();
  10820. this.expect(10);
  10821. node.typeAnnotation = this.tsParseType();
  10822. this.expect(11);
  10823. return this.finishNode(node, "TSParenthesizedType");
  10824. }
  10825. tsParseFunctionOrConstructorType(type, abstract) {
  10826. const node = this.startNode();
  10827. if (type === "TSConstructorType") {
  10828. node.abstract = !!abstract;
  10829. if (abstract) this.next();
  10830. this.next();
  10831. }
  10832. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  10833. return this.finishNode(node, type);
  10834. }
  10835. tsParseLiteralTypeNode() {
  10836. const node = this.startNode();
  10837. switch (this.state.type) {
  10838. case 135:
  10839. case 136:
  10840. case 134:
  10841. case 85:
  10842. case 86:
  10843. node.literal = super.parseExprAtom();
  10844. break;
  10845. default:
  10846. this.unexpected();
  10847. }
  10848. return this.finishNode(node, "TSLiteralType");
  10849. }
  10850. tsParseTemplateLiteralType() {
  10851. {
  10852. const node = this.startNode();
  10853. node.literal = super.parseTemplate(false);
  10854. return this.finishNode(node, "TSLiteralType");
  10855. }
  10856. }
  10857. parseTemplateSubstitution() {
  10858. if (this.state.inType) return this.tsParseType();
  10859. return super.parseTemplateSubstitution();
  10860. }
  10861. tsParseThisTypeOrThisTypePredicate() {
  10862. const thisKeyword = this.tsParseThisTypeNode();
  10863. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  10864. return this.tsParseThisTypePredicate(thisKeyword);
  10865. } else {
  10866. return thisKeyword;
  10867. }
  10868. }
  10869. tsParseNonArrayType() {
  10870. switch (this.state.type) {
  10871. case 134:
  10872. case 135:
  10873. case 136:
  10874. case 85:
  10875. case 86:
  10876. return this.tsParseLiteralTypeNode();
  10877. case 53:
  10878. if (this.state.value === "-") {
  10879. const node = this.startNode();
  10880. const nextToken = this.lookahead();
  10881. if (nextToken.type !== 135 && nextToken.type !== 136) {
  10882. this.unexpected();
  10883. }
  10884. node.literal = this.parseMaybeUnary();
  10885. return this.finishNode(node, "TSLiteralType");
  10886. }
  10887. break;
  10888. case 78:
  10889. return this.tsParseThisTypeOrThisTypePredicate();
  10890. case 87:
  10891. return this.tsParseTypeQuery();
  10892. case 83:
  10893. return this.tsParseImportType();
  10894. case 5:
  10895. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  10896. case 0:
  10897. return this.tsParseTupleType();
  10898. case 10:
  10899. return this.tsParseParenthesizedType();
  10900. case 25:
  10901. case 24:
  10902. return this.tsParseTemplateLiteralType();
  10903. default:
  10904. {
  10905. const {
  10906. type
  10907. } = this.state;
  10908. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  10909. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  10910. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  10911. const node = this.startNode();
  10912. this.next();
  10913. return this.finishNode(node, nodeType);
  10914. }
  10915. return this.tsParseTypeReference();
  10916. }
  10917. }
  10918. }
  10919. this.unexpected();
  10920. }
  10921. tsParseArrayTypeOrHigher() {
  10922. const {
  10923. startLoc
  10924. } = this.state;
  10925. let type = this.tsParseNonArrayType();
  10926. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  10927. if (this.match(3)) {
  10928. const node = this.startNodeAt(startLoc);
  10929. node.elementType = type;
  10930. this.expect(3);
  10931. type = this.finishNode(node, "TSArrayType");
  10932. } else {
  10933. const node = this.startNodeAt(startLoc);
  10934. node.objectType = type;
  10935. node.indexType = this.tsParseType();
  10936. this.expect(3);
  10937. type = this.finishNode(node, "TSIndexedAccessType");
  10938. }
  10939. }
  10940. return type;
  10941. }
  10942. tsParseTypeOperator() {
  10943. const node = this.startNode();
  10944. const operator = this.state.value;
  10945. this.next();
  10946. node.operator = operator;
  10947. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  10948. if (operator === "readonly") {
  10949. this.tsCheckTypeAnnotationForReadOnly(node);
  10950. }
  10951. return this.finishNode(node, "TSTypeOperator");
  10952. }
  10953. tsCheckTypeAnnotationForReadOnly(node) {
  10954. switch (node.typeAnnotation.type) {
  10955. case "TSTupleType":
  10956. case "TSArrayType":
  10957. return;
  10958. default:
  10959. this.raise(TSErrors.UnexpectedReadonly, node);
  10960. }
  10961. }
  10962. tsParseInferType() {
  10963. const node = this.startNode();
  10964. this.expectContextual(115);
  10965. const typeParameter = this.startNode();
  10966. typeParameter.name = this.tsParseTypeParameterName();
  10967. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  10968. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  10969. return this.finishNode(node, "TSInferType");
  10970. }
  10971. tsParseConstraintForInferType() {
  10972. if (this.eat(81)) {
  10973. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  10974. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  10975. return constraint;
  10976. }
  10977. }
  10978. }
  10979. tsParseTypeOperatorOrHigher() {
  10980. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  10981. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  10982. }
  10983. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  10984. const node = this.startNode();
  10985. const hasLeadingOperator = this.eat(operator);
  10986. const types = [];
  10987. do {
  10988. types.push(parseConstituentType());
  10989. } while (this.eat(operator));
  10990. if (types.length === 1 && !hasLeadingOperator) {
  10991. return types[0];
  10992. }
  10993. node.types = types;
  10994. return this.finishNode(node, kind);
  10995. }
  10996. tsParseIntersectionTypeOrHigher() {
  10997. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  10998. }
  10999. tsParseUnionTypeOrHigher() {
  11000. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  11001. }
  11002. tsIsStartOfFunctionType() {
  11003. if (this.match(47)) {
  11004. return true;
  11005. }
  11006. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  11007. }
  11008. tsSkipParameterStart() {
  11009. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  11010. this.next();
  11011. return true;
  11012. }
  11013. if (this.match(5)) {
  11014. const {
  11015. errors
  11016. } = this.state;
  11017. const previousErrorCount = errors.length;
  11018. try {
  11019. this.parseObjectLike(8, true);
  11020. return errors.length === previousErrorCount;
  11021. } catch (_unused) {
  11022. return false;
  11023. }
  11024. }
  11025. if (this.match(0)) {
  11026. this.next();
  11027. const {
  11028. errors
  11029. } = this.state;
  11030. const previousErrorCount = errors.length;
  11031. try {
  11032. super.parseBindingList(3, 93, 1);
  11033. return errors.length === previousErrorCount;
  11034. } catch (_unused2) {
  11035. return false;
  11036. }
  11037. }
  11038. return false;
  11039. }
  11040. tsIsUnambiguouslyStartOfFunctionType() {
  11041. this.next();
  11042. if (this.match(11) || this.match(21)) {
  11043. return true;
  11044. }
  11045. if (this.tsSkipParameterStart()) {
  11046. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  11047. return true;
  11048. }
  11049. if (this.match(11)) {
  11050. this.next();
  11051. if (this.match(19)) {
  11052. return true;
  11053. }
  11054. }
  11055. }
  11056. return false;
  11057. }
  11058. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  11059. return this.tsInType(() => {
  11060. const t = this.startNode();
  11061. this.expect(returnToken);
  11062. const node = this.startNode();
  11063. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  11064. if (asserts && this.match(78)) {
  11065. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  11066. if (thisTypePredicate.type === "TSThisType") {
  11067. node.parameterName = thisTypePredicate;
  11068. node.asserts = true;
  11069. node.typeAnnotation = null;
  11070. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  11071. } else {
  11072. this.resetStartLocationFromNode(thisTypePredicate, node);
  11073. thisTypePredicate.asserts = true;
  11074. }
  11075. t.typeAnnotation = thisTypePredicate;
  11076. return this.finishNode(t, "TSTypeAnnotation");
  11077. }
  11078. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  11079. if (!typePredicateVariable) {
  11080. if (!asserts) {
  11081. return this.tsParseTypeAnnotation(false, t);
  11082. }
  11083. node.parameterName = this.parseIdentifier();
  11084. node.asserts = asserts;
  11085. node.typeAnnotation = null;
  11086. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  11087. return this.finishNode(t, "TSTypeAnnotation");
  11088. }
  11089. const type = this.tsParseTypeAnnotation(false);
  11090. node.parameterName = typePredicateVariable;
  11091. node.typeAnnotation = type;
  11092. node.asserts = asserts;
  11093. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  11094. return this.finishNode(t, "TSTypeAnnotation");
  11095. });
  11096. }
  11097. tsTryParseTypeOrTypePredicateAnnotation() {
  11098. if (this.match(14)) {
  11099. return this.tsParseTypeOrTypePredicateAnnotation(14);
  11100. }
  11101. }
  11102. tsTryParseTypeAnnotation() {
  11103. if (this.match(14)) {
  11104. return this.tsParseTypeAnnotation();
  11105. }
  11106. }
  11107. tsTryParseType() {
  11108. return this.tsEatThenParseType(14);
  11109. }
  11110. tsParseTypePredicatePrefix() {
  11111. const id = this.parseIdentifier();
  11112. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  11113. this.next();
  11114. return id;
  11115. }
  11116. }
  11117. tsParseTypePredicateAsserts() {
  11118. if (this.state.type !== 109) {
  11119. return false;
  11120. }
  11121. const containsEsc = this.state.containsEsc;
  11122. this.next();
  11123. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  11124. return false;
  11125. }
  11126. if (containsEsc) {
  11127. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  11128. reservedWord: "asserts"
  11129. });
  11130. }
  11131. return true;
  11132. }
  11133. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  11134. this.tsInType(() => {
  11135. if (eatColon) this.expect(14);
  11136. t.typeAnnotation = this.tsParseType();
  11137. });
  11138. return this.finishNode(t, "TSTypeAnnotation");
  11139. }
  11140. tsParseType() {
  11141. assert(this.state.inType);
  11142. const type = this.tsParseNonConditionalType();
  11143. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  11144. return type;
  11145. }
  11146. const node = this.startNodeAtNode(type);
  11147. node.checkType = type;
  11148. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  11149. this.expect(17);
  11150. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  11151. this.expect(14);
  11152. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  11153. return this.finishNode(node, "TSConditionalType");
  11154. }
  11155. isAbstractConstructorSignature() {
  11156. return this.isContextual(124) && this.isLookaheadContextual("new");
  11157. }
  11158. tsParseNonConditionalType() {
  11159. if (this.tsIsStartOfFunctionType()) {
  11160. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  11161. }
  11162. if (this.match(77)) {
  11163. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  11164. } else if (this.isAbstractConstructorSignature()) {
  11165. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  11166. }
  11167. return this.tsParseUnionTypeOrHigher();
  11168. }
  11169. tsParseTypeAssertion() {
  11170. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  11171. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  11172. }
  11173. const node = this.startNode();
  11174. node.typeAnnotation = this.tsInType(() => {
  11175. this.next();
  11176. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  11177. });
  11178. this.expect(48);
  11179. node.expression = this.parseMaybeUnary();
  11180. return this.finishNode(node, "TSTypeAssertion");
  11181. }
  11182. tsParseHeritageClause(token) {
  11183. const originalStartLoc = this.state.startLoc;
  11184. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  11185. {
  11186. const node = this.startNode();
  11187. node.expression = this.tsParseEntityName(1 | 2);
  11188. if (this.match(47)) {
  11189. node.typeParameters = this.tsParseTypeArguments();
  11190. }
  11191. return this.finishNode(node, "TSExpressionWithTypeArguments");
  11192. }
  11193. });
  11194. if (!delimitedList.length) {
  11195. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  11196. token
  11197. });
  11198. }
  11199. return delimitedList;
  11200. }
  11201. tsParseInterfaceDeclaration(node, properties = {}) {
  11202. if (this.hasFollowingLineBreak()) return null;
  11203. this.expectContextual(129);
  11204. if (properties.declare) node.declare = true;
  11205. if (tokenIsIdentifier(this.state.type)) {
  11206. node.id = this.parseIdentifier();
  11207. this.checkIdentifier(node.id, 130);
  11208. } else {
  11209. node.id = null;
  11210. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  11211. }
  11212. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  11213. if (this.eat(81)) {
  11214. node.extends = this.tsParseHeritageClause("extends");
  11215. }
  11216. const body = this.startNode();
  11217. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  11218. node.body = this.finishNode(body, "TSInterfaceBody");
  11219. return this.finishNode(node, "TSInterfaceDeclaration");
  11220. }
  11221. tsParseTypeAliasDeclaration(node) {
  11222. node.id = this.parseIdentifier();
  11223. this.checkIdentifier(node.id, 2);
  11224. node.typeAnnotation = this.tsInType(() => {
  11225. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  11226. this.expect(29);
  11227. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  11228. const node = this.startNode();
  11229. this.next();
  11230. return this.finishNode(node, "TSIntrinsicKeyword");
  11231. }
  11232. return this.tsParseType();
  11233. });
  11234. this.semicolon();
  11235. return this.finishNode(node, "TSTypeAliasDeclaration");
  11236. }
  11237. tsInTopLevelContext(cb) {
  11238. if (this.curContext() !== types.brace) {
  11239. const oldContext = this.state.context;
  11240. this.state.context = [oldContext[0]];
  11241. try {
  11242. return cb();
  11243. } finally {
  11244. this.state.context = oldContext;
  11245. }
  11246. } else {
  11247. return cb();
  11248. }
  11249. }
  11250. tsInType(cb) {
  11251. const oldInType = this.state.inType;
  11252. this.state.inType = true;
  11253. try {
  11254. return cb();
  11255. } finally {
  11256. this.state.inType = oldInType;
  11257. }
  11258. }
  11259. tsInDisallowConditionalTypesContext(cb) {
  11260. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  11261. this.state.inDisallowConditionalTypesContext = true;
  11262. try {
  11263. return cb();
  11264. } finally {
  11265. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  11266. }
  11267. }
  11268. tsInAllowConditionalTypesContext(cb) {
  11269. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  11270. this.state.inDisallowConditionalTypesContext = false;
  11271. try {
  11272. return cb();
  11273. } finally {
  11274. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  11275. }
  11276. }
  11277. tsEatThenParseType(token) {
  11278. if (this.match(token)) {
  11279. return this.tsNextThenParseType();
  11280. }
  11281. }
  11282. tsExpectThenParseType(token) {
  11283. return this.tsInType(() => {
  11284. this.expect(token);
  11285. return this.tsParseType();
  11286. });
  11287. }
  11288. tsNextThenParseType() {
  11289. return this.tsInType(() => {
  11290. this.next();
  11291. return this.tsParseType();
  11292. });
  11293. }
  11294. tsParseEnumMember() {
  11295. const node = this.startNode();
  11296. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  11297. if (this.eat(29)) {
  11298. node.initializer = super.parseMaybeAssignAllowIn();
  11299. }
  11300. return this.finishNode(node, "TSEnumMember");
  11301. }
  11302. tsParseEnumDeclaration(node, properties = {}) {
  11303. if (properties.const) node.const = true;
  11304. if (properties.declare) node.declare = true;
  11305. this.expectContextual(126);
  11306. node.id = this.parseIdentifier();
  11307. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  11308. {
  11309. this.expect(5);
  11310. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  11311. this.expect(8);
  11312. }
  11313. return this.finishNode(node, "TSEnumDeclaration");
  11314. }
  11315. tsParseEnumBody() {
  11316. const node = this.startNode();
  11317. this.expect(5);
  11318. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  11319. this.expect(8);
  11320. return this.finishNode(node, "TSEnumBody");
  11321. }
  11322. tsParseModuleBlock() {
  11323. const node = this.startNode();
  11324. this.scope.enter(0);
  11325. this.expect(5);
  11326. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  11327. this.scope.exit();
  11328. return this.finishNode(node, "TSModuleBlock");
  11329. }
  11330. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  11331. node.id = this.parseIdentifier();
  11332. if (!nested) {
  11333. this.checkIdentifier(node.id, 1024);
  11334. }
  11335. if (this.eat(16)) {
  11336. const inner = this.startNode();
  11337. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  11338. node.body = inner;
  11339. } else {
  11340. this.scope.enter(1024);
  11341. this.prodParam.enter(0);
  11342. node.body = this.tsParseModuleBlock();
  11343. this.prodParam.exit();
  11344. this.scope.exit();
  11345. }
  11346. return this.finishNode(node, "TSModuleDeclaration");
  11347. }
  11348. tsParseAmbientExternalModuleDeclaration(node) {
  11349. if (this.isContextual(112)) {
  11350. node.kind = "global";
  11351. {
  11352. node.global = true;
  11353. }
  11354. node.id = this.parseIdentifier();
  11355. } else if (this.match(134)) {
  11356. node.kind = "module";
  11357. node.id = super.parseStringLiteral(this.state.value);
  11358. } else {
  11359. this.unexpected();
  11360. }
  11361. if (this.match(5)) {
  11362. this.scope.enter(1024);
  11363. this.prodParam.enter(0);
  11364. node.body = this.tsParseModuleBlock();
  11365. this.prodParam.exit();
  11366. this.scope.exit();
  11367. } else {
  11368. this.semicolon();
  11369. }
  11370. return this.finishNode(node, "TSModuleDeclaration");
  11371. }
  11372. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  11373. {
  11374. node.isExport = isExport || false;
  11375. }
  11376. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  11377. this.checkIdentifier(node.id, 4096);
  11378. this.expect(29);
  11379. const moduleReference = this.tsParseModuleReference();
  11380. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  11381. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  11382. }
  11383. node.moduleReference = moduleReference;
  11384. this.semicolon();
  11385. return this.finishNode(node, "TSImportEqualsDeclaration");
  11386. }
  11387. tsIsExternalModuleReference() {
  11388. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  11389. }
  11390. tsParseModuleReference() {
  11391. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  11392. }
  11393. tsParseExternalModuleReference() {
  11394. const node = this.startNode();
  11395. this.expectContextual(119);
  11396. this.expect(10);
  11397. if (!this.match(134)) {
  11398. this.unexpected();
  11399. }
  11400. node.expression = super.parseExprAtom();
  11401. this.expect(11);
  11402. this.sawUnambiguousESM = true;
  11403. return this.finishNode(node, "TSExternalModuleReference");
  11404. }
  11405. tsLookAhead(f) {
  11406. const state = this.state.clone();
  11407. const res = f();
  11408. this.state = state;
  11409. return res;
  11410. }
  11411. tsTryParseAndCatch(f) {
  11412. const result = this.tryParse(abort => f() || abort());
  11413. if (result.aborted || !result.node) return;
  11414. if (result.error) this.state = result.failState;
  11415. return result.node;
  11416. }
  11417. tsTryParse(f) {
  11418. const state = this.state.clone();
  11419. const result = f();
  11420. if (result !== undefined && result !== false) {
  11421. return result;
  11422. }
  11423. this.state = state;
  11424. }
  11425. tsTryParseDeclare(node) {
  11426. if (this.isLineTerminator()) {
  11427. return;
  11428. }
  11429. const startType = this.state.type;
  11430. return this.tsInAmbientContext(() => {
  11431. switch (startType) {
  11432. case 68:
  11433. node.declare = true;
  11434. return super.parseFunctionStatement(node, false, false);
  11435. case 80:
  11436. node.declare = true;
  11437. return this.parseClass(node, true, false);
  11438. case 126:
  11439. return this.tsParseEnumDeclaration(node, {
  11440. declare: true
  11441. });
  11442. case 112:
  11443. return this.tsParseAmbientExternalModuleDeclaration(node);
  11444. case 100:
  11445. if (this.state.containsEsc) {
  11446. return;
  11447. }
  11448. case 75:
  11449. case 74:
  11450. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  11451. node.declare = true;
  11452. return this.parseVarStatement(node, this.state.value, true);
  11453. }
  11454. this.expect(75);
  11455. return this.tsParseEnumDeclaration(node, {
  11456. const: true,
  11457. declare: true
  11458. });
  11459. case 107:
  11460. if (this.isUsing()) {
  11461. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  11462. node.declare = true;
  11463. return this.parseVarStatement(node, "using", true);
  11464. }
  11465. break;
  11466. case 96:
  11467. if (this.isAwaitUsing()) {
  11468. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  11469. node.declare = true;
  11470. this.next();
  11471. return this.parseVarStatement(node, "await using", true);
  11472. }
  11473. break;
  11474. case 129:
  11475. {
  11476. const result = this.tsParseInterfaceDeclaration(node, {
  11477. declare: true
  11478. });
  11479. if (result) return result;
  11480. }
  11481. default:
  11482. if (tokenIsIdentifier(startType)) {
  11483. return this.tsParseDeclaration(node, this.state.value, true, null);
  11484. }
  11485. }
  11486. });
  11487. }
  11488. tsTryParseExportDeclaration() {
  11489. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  11490. }
  11491. tsParseExpressionStatement(node, expr, decorators) {
  11492. switch (expr.name) {
  11493. case "declare":
  11494. {
  11495. const declaration = this.tsTryParseDeclare(node);
  11496. if (declaration) {
  11497. declaration.declare = true;
  11498. }
  11499. return declaration;
  11500. }
  11501. case "global":
  11502. if (this.match(5)) {
  11503. this.scope.enter(1024);
  11504. this.prodParam.enter(0);
  11505. const mod = node;
  11506. mod.kind = "global";
  11507. {
  11508. node.global = true;
  11509. }
  11510. mod.id = expr;
  11511. mod.body = this.tsParseModuleBlock();
  11512. this.scope.exit();
  11513. this.prodParam.exit();
  11514. return this.finishNode(mod, "TSModuleDeclaration");
  11515. }
  11516. break;
  11517. default:
  11518. return this.tsParseDeclaration(node, expr.name, false, decorators);
  11519. }
  11520. }
  11521. tsParseDeclaration(node, value, next, decorators) {
  11522. switch (value) {
  11523. case "abstract":
  11524. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  11525. return this.tsParseAbstractDeclaration(node, decorators);
  11526. }
  11527. break;
  11528. case "module":
  11529. if (this.tsCheckLineTerminator(next)) {
  11530. if (this.match(134)) {
  11531. return this.tsParseAmbientExternalModuleDeclaration(node);
  11532. } else if (tokenIsIdentifier(this.state.type)) {
  11533. node.kind = "module";
  11534. return this.tsParseModuleOrNamespaceDeclaration(node);
  11535. }
  11536. }
  11537. break;
  11538. case "namespace":
  11539. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  11540. node.kind = "namespace";
  11541. return this.tsParseModuleOrNamespaceDeclaration(node);
  11542. }
  11543. break;
  11544. case "type":
  11545. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  11546. return this.tsParseTypeAliasDeclaration(node);
  11547. }
  11548. break;
  11549. }
  11550. }
  11551. tsCheckLineTerminator(next) {
  11552. if (next) {
  11553. if (this.hasFollowingLineBreak()) return false;
  11554. this.next();
  11555. return true;
  11556. }
  11557. return !this.isLineTerminator();
  11558. }
  11559. tsTryParseGenericAsyncArrowFunction(startLoc) {
  11560. if (!this.match(47)) return;
  11561. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11562. this.state.maybeInArrowParameters = true;
  11563. const res = this.tsTryParseAndCatch(() => {
  11564. const node = this.startNodeAt(startLoc);
  11565. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  11566. super.parseFunctionParams(node);
  11567. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  11568. this.expect(19);
  11569. return node;
  11570. });
  11571. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11572. if (!res) return;
  11573. return super.parseArrowExpression(res, null, true);
  11574. }
  11575. tsParseTypeArgumentsInExpression() {
  11576. if (this.reScan_lt() !== 47) return;
  11577. return this.tsParseTypeArguments();
  11578. }
  11579. tsParseTypeArguments() {
  11580. const node = this.startNode();
  11581. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  11582. this.expect(47);
  11583. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  11584. }));
  11585. if (node.params.length === 0) {
  11586. this.raise(TSErrors.EmptyTypeArguments, node);
  11587. } else if (!this.state.inType && this.curContext() === types.brace) {
  11588. this.reScan_lt_gt();
  11589. }
  11590. this.expect(48);
  11591. return this.finishNode(node, "TSTypeParameterInstantiation");
  11592. }
  11593. tsIsDeclarationStart() {
  11594. return tokenIsTSDeclarationStart(this.state.type);
  11595. }
  11596. isExportDefaultSpecifier() {
  11597. if (this.tsIsDeclarationStart()) return false;
  11598. return super.isExportDefaultSpecifier();
  11599. }
  11600. parseBindingElement(flags, decorators) {
  11601. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  11602. const modified = {};
  11603. this.tsParseModifiers({
  11604. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  11605. }, modified);
  11606. const accessibility = modified.accessibility;
  11607. const override = modified.override;
  11608. const readonly = modified.readonly;
  11609. if (!(flags & 4) && (accessibility || readonly || override)) {
  11610. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  11611. }
  11612. const left = this.parseMaybeDefault();
  11613. if (flags & 2) {
  11614. this.parseFunctionParamType(left);
  11615. }
  11616. const elt = this.parseMaybeDefault(left.loc.start, left);
  11617. if (accessibility || readonly || override) {
  11618. const pp = this.startNodeAt(startLoc);
  11619. if (decorators.length) {
  11620. pp.decorators = decorators;
  11621. }
  11622. if (accessibility) pp.accessibility = accessibility;
  11623. if (readonly) pp.readonly = readonly;
  11624. if (override) pp.override = override;
  11625. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  11626. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  11627. }
  11628. pp.parameter = elt;
  11629. return this.finishNode(pp, "TSParameterProperty");
  11630. }
  11631. if (decorators.length) {
  11632. left.decorators = decorators;
  11633. }
  11634. return elt;
  11635. }
  11636. isSimpleParameter(node) {
  11637. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  11638. }
  11639. tsDisallowOptionalPattern(node) {
  11640. for (const param of node.params) {
  11641. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  11642. this.raise(TSErrors.PatternIsOptional, param);
  11643. }
  11644. }
  11645. }
  11646. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11647. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11648. this.tsDisallowOptionalPattern(node);
  11649. }
  11650. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11651. if (this.match(14)) {
  11652. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  11653. }
  11654. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  11655. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  11656. return this.finishNode(node, bodilessType);
  11657. }
  11658. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  11659. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  11660. if (node.declare) {
  11661. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  11662. }
  11663. }
  11664. this.tsDisallowOptionalPattern(node);
  11665. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  11666. }
  11667. registerFunctionStatementId(node) {
  11668. if (!node.body && node.id) {
  11669. this.checkIdentifier(node.id, 1024);
  11670. } else {
  11671. super.registerFunctionStatementId(node);
  11672. }
  11673. }
  11674. tsCheckForInvalidTypeCasts(items) {
  11675. items.forEach(node => {
  11676. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  11677. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  11678. }
  11679. });
  11680. }
  11681. toReferencedList(exprList, isInParens) {
  11682. this.tsCheckForInvalidTypeCasts(exprList);
  11683. return exprList;
  11684. }
  11685. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11686. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  11687. if (node.type === "ArrayExpression") {
  11688. this.tsCheckForInvalidTypeCasts(node.elements);
  11689. }
  11690. return node;
  11691. }
  11692. parseSubscript(base, startLoc, noCalls, state) {
  11693. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  11694. this.state.canStartJSXElement = false;
  11695. this.next();
  11696. const nonNullExpression = this.startNodeAt(startLoc);
  11697. nonNullExpression.expression = base;
  11698. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  11699. }
  11700. let isOptionalCall = false;
  11701. if (this.match(18) && this.lookaheadCharCode() === 60) {
  11702. if (noCalls) {
  11703. state.stop = true;
  11704. return base;
  11705. }
  11706. state.optionalChainMember = isOptionalCall = true;
  11707. this.next();
  11708. }
  11709. if (this.match(47) || this.match(51)) {
  11710. let missingParenErrorLoc;
  11711. const result = this.tsTryParseAndCatch(() => {
  11712. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  11713. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  11714. if (asyncArrowFn) {
  11715. state.stop = true;
  11716. return asyncArrowFn;
  11717. }
  11718. }
  11719. const typeArguments = this.tsParseTypeArgumentsInExpression();
  11720. if (!typeArguments) return;
  11721. if (isOptionalCall && !this.match(10)) {
  11722. missingParenErrorLoc = this.state.curPosition();
  11723. return;
  11724. }
  11725. if (tokenIsTemplate(this.state.type)) {
  11726. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  11727. {
  11728. result.typeParameters = typeArguments;
  11729. }
  11730. return result;
  11731. }
  11732. if (!noCalls && this.eat(10)) {
  11733. const node = this.startNodeAt(startLoc);
  11734. node.callee = base;
  11735. node.arguments = this.parseCallExpressionArguments();
  11736. this.tsCheckForInvalidTypeCasts(node.arguments);
  11737. {
  11738. node.typeParameters = typeArguments;
  11739. }
  11740. if (state.optionalChainMember) {
  11741. node.optional = isOptionalCall;
  11742. }
  11743. return this.finishCallExpression(node, state.optionalChainMember);
  11744. }
  11745. const tokenType = this.state.type;
  11746. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  11747. return;
  11748. }
  11749. const node = this.startNodeAt(startLoc);
  11750. node.expression = base;
  11751. {
  11752. node.typeParameters = typeArguments;
  11753. }
  11754. return this.finishNode(node, "TSInstantiationExpression");
  11755. });
  11756. if (missingParenErrorLoc) {
  11757. this.unexpected(missingParenErrorLoc, 10);
  11758. }
  11759. if (result) {
  11760. if (result.type === "TSInstantiationExpression") {
  11761. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  11762. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  11763. }
  11764. if (!this.match(16) && !this.match(18)) {
  11765. result.expression = super.stopParseSubscript(base, state);
  11766. }
  11767. }
  11768. return result;
  11769. }
  11770. }
  11771. return super.parseSubscript(base, startLoc, noCalls, state);
  11772. }
  11773. parseNewCallee(node) {
  11774. var _callee$extra;
  11775. super.parseNewCallee(node);
  11776. const {
  11777. callee
  11778. } = node;
  11779. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  11780. {
  11781. node.typeParameters = callee.typeParameters;
  11782. }
  11783. node.callee = callee.expression;
  11784. }
  11785. }
  11786. parseExprOp(left, leftStartLoc, minPrec) {
  11787. let isSatisfies;
  11788. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  11789. const node = this.startNodeAt(leftStartLoc);
  11790. node.expression = left;
  11791. node.typeAnnotation = this.tsInType(() => {
  11792. this.next();
  11793. if (this.match(75)) {
  11794. if (isSatisfies) {
  11795. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  11796. keyword: "const"
  11797. });
  11798. }
  11799. return this.tsParseTypeReference();
  11800. }
  11801. return this.tsParseType();
  11802. });
  11803. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  11804. this.reScan_lt_gt();
  11805. return this.parseExprOp(node, leftStartLoc, minPrec);
  11806. }
  11807. return super.parseExprOp(left, leftStartLoc, minPrec);
  11808. }
  11809. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11810. if (!this.state.isAmbientContext) {
  11811. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  11812. }
  11813. }
  11814. checkImportReflection(node) {
  11815. super.checkImportReflection(node);
  11816. if (node.module && node.importKind !== "value") {
  11817. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  11818. }
  11819. }
  11820. checkDuplicateExports() {}
  11821. isPotentialImportPhase(isExport) {
  11822. if (super.isPotentialImportPhase(isExport)) return true;
  11823. if (this.isContextual(130)) {
  11824. const ch = this.lookaheadCharCode();
  11825. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  11826. }
  11827. return !isExport && this.isContextual(87);
  11828. }
  11829. applyImportPhase(node, isExport, phase, loc) {
  11830. super.applyImportPhase(node, isExport, phase, loc);
  11831. if (isExport) {
  11832. node.exportKind = phase === "type" ? "type" : "value";
  11833. } else {
  11834. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  11835. }
  11836. }
  11837. parseImport(node) {
  11838. if (this.match(134)) {
  11839. node.importKind = "value";
  11840. return super.parseImport(node);
  11841. }
  11842. let importNode;
  11843. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  11844. node.importKind = "value";
  11845. return this.tsParseImportEqualsDeclaration(node);
  11846. } else if (this.isContextual(130)) {
  11847. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  11848. if (this.lookaheadCharCode() === 61) {
  11849. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  11850. } else {
  11851. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  11852. }
  11853. } else {
  11854. importNode = super.parseImport(node);
  11855. }
  11856. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  11857. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  11858. }
  11859. return importNode;
  11860. }
  11861. parseExport(node, decorators) {
  11862. if (this.match(83)) {
  11863. const nodeImportEquals = node;
  11864. this.next();
  11865. let maybeDefaultIdentifier = null;
  11866. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  11867. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  11868. } else {
  11869. nodeImportEquals.importKind = "value";
  11870. }
  11871. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  11872. {
  11873. return declaration;
  11874. }
  11875. } else if (this.eat(29)) {
  11876. const assign = node;
  11877. assign.expression = super.parseExpression();
  11878. this.semicolon();
  11879. this.sawUnambiguousESM = true;
  11880. return this.finishNode(assign, "TSExportAssignment");
  11881. } else if (this.eatContextual(93)) {
  11882. const decl = node;
  11883. this.expectContextual(128);
  11884. decl.id = this.parseIdentifier();
  11885. this.semicolon();
  11886. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  11887. } else {
  11888. return super.parseExport(node, decorators);
  11889. }
  11890. }
  11891. isAbstractClass() {
  11892. return this.isContextual(124) && this.isLookaheadContextual("class");
  11893. }
  11894. parseExportDefaultExpression() {
  11895. if (this.isAbstractClass()) {
  11896. const cls = this.startNode();
  11897. this.next();
  11898. cls.abstract = true;
  11899. return this.parseClass(cls, true, true);
  11900. }
  11901. if (this.match(129)) {
  11902. const result = this.tsParseInterfaceDeclaration(this.startNode());
  11903. if (result) return result;
  11904. }
  11905. return super.parseExportDefaultExpression();
  11906. }
  11907. parseVarStatement(node, kind, allowMissingInitializer = false) {
  11908. const {
  11909. isAmbientContext
  11910. } = this.state;
  11911. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  11912. if (!isAmbientContext) return declaration;
  11913. if (!node.declare && (kind === "using" || kind === "await using")) {
  11914. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  11915. return declaration;
  11916. }
  11917. for (const {
  11918. id,
  11919. init
  11920. } of declaration.declarations) {
  11921. if (!init) continue;
  11922. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  11923. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  11924. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  11925. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  11926. }
  11927. }
  11928. return declaration;
  11929. }
  11930. parseStatementContent(flags, decorators) {
  11931. if (this.match(75) && this.isLookaheadContextual("enum")) {
  11932. const node = this.startNode();
  11933. this.expect(75);
  11934. return this.tsParseEnumDeclaration(node, {
  11935. const: true
  11936. });
  11937. }
  11938. if (this.isContextual(126)) {
  11939. return this.tsParseEnumDeclaration(this.startNode());
  11940. }
  11941. if (this.isContextual(129)) {
  11942. const result = this.tsParseInterfaceDeclaration(this.startNode());
  11943. if (result) return result;
  11944. }
  11945. return super.parseStatementContent(flags, decorators);
  11946. }
  11947. parseAccessModifier() {
  11948. return this.tsParseModifier(["public", "protected", "private"]);
  11949. }
  11950. tsHasSomeModifiers(member, modifiers) {
  11951. return modifiers.some(modifier => {
  11952. if (tsIsAccessModifier(modifier)) {
  11953. return member.accessibility === modifier;
  11954. }
  11955. return !!member[modifier];
  11956. });
  11957. }
  11958. tsIsStartOfStaticBlocks() {
  11959. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  11960. }
  11961. parseClassMember(classBody, member, state) {
  11962. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  11963. this.tsParseModifiers({
  11964. allowedModifiers: modifiers,
  11965. disallowedModifiers: ["in", "out"],
  11966. stopOnStartOfClassStaticBlock: true,
  11967. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  11968. }, member);
  11969. const callParseClassMemberWithIsStatic = () => {
  11970. if (this.tsIsStartOfStaticBlocks()) {
  11971. this.next();
  11972. this.next();
  11973. if (this.tsHasSomeModifiers(member, modifiers)) {
  11974. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  11975. }
  11976. super.parseClassStaticBlock(classBody, member);
  11977. } else {
  11978. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  11979. }
  11980. };
  11981. if (member.declare) {
  11982. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  11983. } else {
  11984. callParseClassMemberWithIsStatic();
  11985. }
  11986. }
  11987. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  11988. const idx = this.tsTryParseIndexSignature(member);
  11989. if (idx) {
  11990. classBody.body.push(idx);
  11991. if (member.abstract) {
  11992. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  11993. }
  11994. if (member.accessibility) {
  11995. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  11996. modifier: member.accessibility
  11997. });
  11998. }
  11999. if (member.declare) {
  12000. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  12001. }
  12002. if (member.override) {
  12003. this.raise(TSErrors.IndexSignatureHasOverride, member);
  12004. }
  12005. return;
  12006. }
  12007. if (!this.state.inAbstractClass && member.abstract) {
  12008. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  12009. }
  12010. if (member.override) {
  12011. if (!state.hadSuperClass) {
  12012. this.raise(TSErrors.OverrideNotInSubClass, member);
  12013. }
  12014. }
  12015. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  12016. }
  12017. parsePostMemberNameModifiers(methodOrProp) {
  12018. const optional = this.eat(17);
  12019. if (optional) methodOrProp.optional = true;
  12020. if (methodOrProp.readonly && this.match(10)) {
  12021. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  12022. }
  12023. if (methodOrProp.declare && this.match(10)) {
  12024. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  12025. }
  12026. }
  12027. parseExpressionStatement(node, expr, decorators) {
  12028. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  12029. return decl || super.parseExpressionStatement(node, expr, decorators);
  12030. }
  12031. shouldParseExportDeclaration() {
  12032. if (this.tsIsDeclarationStart()) return true;
  12033. return super.shouldParseExportDeclaration();
  12034. }
  12035. parseConditional(expr, startLoc, refExpressionErrors) {
  12036. if (!this.match(17)) return expr;
  12037. if (this.state.maybeInArrowParameters) {
  12038. const nextCh = this.lookaheadCharCode();
  12039. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  12040. this.setOptionalParametersError(refExpressionErrors);
  12041. return expr;
  12042. }
  12043. }
  12044. return super.parseConditional(expr, startLoc, refExpressionErrors);
  12045. }
  12046. parseParenItem(node, startLoc) {
  12047. const newNode = super.parseParenItem(node, startLoc);
  12048. if (this.eat(17)) {
  12049. newNode.optional = true;
  12050. this.resetEndLocation(node);
  12051. }
  12052. if (this.match(14)) {
  12053. const typeCastNode = this.startNodeAt(startLoc);
  12054. typeCastNode.expression = node;
  12055. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  12056. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  12057. }
  12058. return node;
  12059. }
  12060. parseExportDeclaration(node) {
  12061. if (!this.state.isAmbientContext && this.isContextual(125)) {
  12062. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  12063. }
  12064. const startLoc = this.state.startLoc;
  12065. const isDeclare = this.eatContextual(125);
  12066. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  12067. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  12068. }
  12069. const isIdentifier = tokenIsIdentifier(this.state.type);
  12070. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  12071. if (!declaration) return null;
  12072. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  12073. node.exportKind = "type";
  12074. }
  12075. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  12076. this.resetStartLocation(declaration, startLoc);
  12077. declaration.declare = true;
  12078. }
  12079. return declaration;
  12080. }
  12081. parseClassId(node, isStatement, optionalId, bindingType) {
  12082. if ((!isStatement || optionalId) && this.isContextual(113)) {
  12083. return;
  12084. }
  12085. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  12086. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  12087. if (typeParameters) node.typeParameters = typeParameters;
  12088. }
  12089. parseClassPropertyAnnotation(node) {
  12090. if (!node.optional) {
  12091. if (this.eat(35)) {
  12092. node.definite = true;
  12093. } else if (this.eat(17)) {
  12094. node.optional = true;
  12095. }
  12096. }
  12097. const type = this.tsTryParseTypeAnnotation();
  12098. if (type) node.typeAnnotation = type;
  12099. }
  12100. parseClassProperty(node) {
  12101. this.parseClassPropertyAnnotation(node);
  12102. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  12103. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  12104. }
  12105. if (node.abstract && this.match(29)) {
  12106. const {
  12107. key
  12108. } = node;
  12109. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  12110. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  12111. });
  12112. }
  12113. return super.parseClassProperty(node);
  12114. }
  12115. parseClassPrivateProperty(node) {
  12116. if (node.abstract) {
  12117. this.raise(TSErrors.PrivateElementHasAbstract, node);
  12118. }
  12119. if (node.accessibility) {
  12120. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  12121. modifier: node.accessibility
  12122. });
  12123. }
  12124. this.parseClassPropertyAnnotation(node);
  12125. return super.parseClassPrivateProperty(node);
  12126. }
  12127. parseClassAccessorProperty(node) {
  12128. this.parseClassPropertyAnnotation(node);
  12129. if (node.optional) {
  12130. this.raise(TSErrors.AccessorCannotBeOptional, node);
  12131. }
  12132. return super.parseClassAccessorProperty(node);
  12133. }
  12134. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  12135. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12136. if (typeParameters && isConstructor) {
  12137. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  12138. }
  12139. const {
  12140. declare = false,
  12141. kind
  12142. } = method;
  12143. if (declare && (kind === "get" || kind === "set")) {
  12144. this.raise(TSErrors.DeclareAccessor, method, {
  12145. kind
  12146. });
  12147. }
  12148. if (typeParameters) method.typeParameters = typeParameters;
  12149. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  12150. }
  12151. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  12152. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12153. if (typeParameters) method.typeParameters = typeParameters;
  12154. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  12155. }
  12156. declareClassPrivateMethodInScope(node, kind) {
  12157. if (node.type === "TSDeclareMethod") return;
  12158. if (node.type === "MethodDefinition" && node.value.body == null) {
  12159. return;
  12160. }
  12161. super.declareClassPrivateMethodInScope(node, kind);
  12162. }
  12163. parseClassSuper(node) {
  12164. super.parseClassSuper(node);
  12165. if (node.superClass && (this.match(47) || this.match(51))) {
  12166. {
  12167. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  12168. }
  12169. }
  12170. if (this.eatContextual(113)) {
  12171. node.implements = this.tsParseHeritageClause("implements");
  12172. }
  12173. }
  12174. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12175. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12176. if (typeParameters) prop.typeParameters = typeParameters;
  12177. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  12178. }
  12179. parseFunctionParams(node, isConstructor) {
  12180. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12181. if (typeParameters) node.typeParameters = typeParameters;
  12182. super.parseFunctionParams(node, isConstructor);
  12183. }
  12184. parseVarId(decl, kind) {
  12185. super.parseVarId(decl, kind);
  12186. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  12187. decl.definite = true;
  12188. }
  12189. const type = this.tsTryParseTypeAnnotation();
  12190. if (type) {
  12191. decl.id.typeAnnotation = type;
  12192. this.resetEndLocation(decl.id);
  12193. }
  12194. }
  12195. parseAsyncArrowFromCallExpression(node, call) {
  12196. if (this.match(14)) {
  12197. node.returnType = this.tsParseTypeAnnotation();
  12198. }
  12199. return super.parseAsyncArrowFromCallExpression(node, call);
  12200. }
  12201. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  12202. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  12203. let state;
  12204. let jsx;
  12205. let typeCast;
  12206. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  12207. state = this.state.clone();
  12208. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  12209. if (!jsx.error) return jsx.node;
  12210. const {
  12211. context
  12212. } = this.state;
  12213. const currentContext = context[context.length - 1];
  12214. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  12215. context.pop();
  12216. }
  12217. }
  12218. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  12219. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  12220. }
  12221. if (!state || state === this.state) state = this.state.clone();
  12222. let typeParameters;
  12223. const arrow = this.tryParse(abort => {
  12224. var _expr$extra, _typeParameters;
  12225. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  12226. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  12227. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  12228. abort();
  12229. }
  12230. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  12231. this.resetStartLocationFromNode(expr, typeParameters);
  12232. }
  12233. expr.typeParameters = typeParameters;
  12234. return expr;
  12235. }, state);
  12236. if (!arrow.error && !arrow.aborted) {
  12237. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  12238. return arrow.node;
  12239. }
  12240. if (!jsx) {
  12241. assert(!this.hasPlugin("jsx"));
  12242. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  12243. if (!typeCast.error) return typeCast.node;
  12244. }
  12245. if ((_jsx2 = jsx) != null && _jsx2.node) {
  12246. this.state = jsx.failState;
  12247. return jsx.node;
  12248. }
  12249. if (arrow.node) {
  12250. this.state = arrow.failState;
  12251. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  12252. return arrow.node;
  12253. }
  12254. if ((_typeCast = typeCast) != null && _typeCast.node) {
  12255. this.state = typeCast.failState;
  12256. return typeCast.node;
  12257. }
  12258. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  12259. }
  12260. reportReservedArrowTypeParam(node) {
  12261. var _node$extra2;
  12262. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  12263. this.raise(TSErrors.ReservedArrowTypeParam, node);
  12264. }
  12265. }
  12266. parseMaybeUnary(refExpressionErrors, sawUnary) {
  12267. if (!this.hasPlugin("jsx") && this.match(47)) {
  12268. return this.tsParseTypeAssertion();
  12269. }
  12270. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  12271. }
  12272. parseArrow(node) {
  12273. if (this.match(14)) {
  12274. const result = this.tryParse(abort => {
  12275. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  12276. if (this.canInsertSemicolon() || !this.match(19)) abort();
  12277. return returnType;
  12278. });
  12279. if (result.aborted) return;
  12280. if (!result.thrown) {
  12281. if (result.error) this.state = result.failState;
  12282. node.returnType = result.node;
  12283. }
  12284. }
  12285. return super.parseArrow(node);
  12286. }
  12287. parseFunctionParamType(param) {
  12288. if (this.eat(17)) {
  12289. param.optional = true;
  12290. }
  12291. const type = this.tsTryParseTypeAnnotation();
  12292. if (type) param.typeAnnotation = type;
  12293. this.resetEndLocation(param);
  12294. return param;
  12295. }
  12296. isAssignable(node, isBinding) {
  12297. switch (node.type) {
  12298. case "TSTypeCastExpression":
  12299. return this.isAssignable(node.expression, isBinding);
  12300. case "TSParameterProperty":
  12301. return true;
  12302. default:
  12303. return super.isAssignable(node, isBinding);
  12304. }
  12305. }
  12306. toAssignable(node, isLHS = false) {
  12307. switch (node.type) {
  12308. case "ParenthesizedExpression":
  12309. this.toAssignableParenthesizedExpression(node, isLHS);
  12310. break;
  12311. case "TSAsExpression":
  12312. case "TSSatisfiesExpression":
  12313. case "TSNonNullExpression":
  12314. case "TSTypeAssertion":
  12315. if (isLHS) {
  12316. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  12317. } else {
  12318. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  12319. }
  12320. this.toAssignable(node.expression, isLHS);
  12321. break;
  12322. case "AssignmentExpression":
  12323. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  12324. node.left = this.typeCastToParameter(node.left);
  12325. }
  12326. default:
  12327. super.toAssignable(node, isLHS);
  12328. }
  12329. }
  12330. toAssignableParenthesizedExpression(node, isLHS) {
  12331. switch (node.expression.type) {
  12332. case "TSAsExpression":
  12333. case "TSSatisfiesExpression":
  12334. case "TSNonNullExpression":
  12335. case "TSTypeAssertion":
  12336. case "ParenthesizedExpression":
  12337. this.toAssignable(node.expression, isLHS);
  12338. break;
  12339. default:
  12340. super.toAssignable(node, isLHS);
  12341. }
  12342. }
  12343. checkToRestConversion(node, allowPattern) {
  12344. switch (node.type) {
  12345. case "TSAsExpression":
  12346. case "TSSatisfiesExpression":
  12347. case "TSTypeAssertion":
  12348. case "TSNonNullExpression":
  12349. this.checkToRestConversion(node.expression, false);
  12350. break;
  12351. default:
  12352. super.checkToRestConversion(node, allowPattern);
  12353. }
  12354. }
  12355. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  12356. switch (type) {
  12357. case "TSTypeCastExpression":
  12358. return true;
  12359. case "TSParameterProperty":
  12360. return "parameter";
  12361. case "TSNonNullExpression":
  12362. return "expression";
  12363. case "TSAsExpression":
  12364. case "TSSatisfiesExpression":
  12365. case "TSTypeAssertion":
  12366. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  12367. default:
  12368. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  12369. }
  12370. }
  12371. parseBindingAtom() {
  12372. if (this.state.type === 78) {
  12373. return this.parseIdentifier(true);
  12374. }
  12375. return super.parseBindingAtom();
  12376. }
  12377. parseMaybeDecoratorArguments(expr, startLoc) {
  12378. if (this.match(47) || this.match(51)) {
  12379. const typeArguments = this.tsParseTypeArgumentsInExpression();
  12380. if (this.match(10)) {
  12381. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  12382. {
  12383. call.typeParameters = typeArguments;
  12384. }
  12385. return call;
  12386. }
  12387. this.unexpected(null, 10);
  12388. }
  12389. return super.parseMaybeDecoratorArguments(expr, startLoc);
  12390. }
  12391. checkCommaAfterRest(close) {
  12392. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  12393. this.next();
  12394. return false;
  12395. }
  12396. return super.checkCommaAfterRest(close);
  12397. }
  12398. isClassMethod() {
  12399. return this.match(47) || super.isClassMethod();
  12400. }
  12401. isClassProperty() {
  12402. return this.match(35) || this.match(14) || super.isClassProperty();
  12403. }
  12404. parseMaybeDefault(startLoc, left) {
  12405. const node = super.parseMaybeDefault(startLoc, left);
  12406. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  12407. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  12408. }
  12409. return node;
  12410. }
  12411. getTokenFromCode(code) {
  12412. if (this.state.inType) {
  12413. if (code === 62) {
  12414. this.finishOp(48, 1);
  12415. return;
  12416. }
  12417. if (code === 60) {
  12418. this.finishOp(47, 1);
  12419. return;
  12420. }
  12421. }
  12422. super.getTokenFromCode(code);
  12423. }
  12424. reScan_lt_gt() {
  12425. const {
  12426. type
  12427. } = this.state;
  12428. if (type === 47) {
  12429. this.state.pos -= 1;
  12430. this.readToken_lt();
  12431. } else if (type === 48) {
  12432. this.state.pos -= 1;
  12433. this.readToken_gt();
  12434. }
  12435. }
  12436. reScan_lt() {
  12437. const {
  12438. type
  12439. } = this.state;
  12440. if (type === 51) {
  12441. this.state.pos -= 2;
  12442. this.finishOp(47, 1);
  12443. return 47;
  12444. }
  12445. return type;
  12446. }
  12447. toAssignableListItem(exprList, index, isLHS) {
  12448. const node = exprList[index];
  12449. if (node.type === "TSTypeCastExpression") {
  12450. exprList[index] = this.typeCastToParameter(node);
  12451. }
  12452. super.toAssignableListItem(exprList, index, isLHS);
  12453. }
  12454. typeCastToParameter(node) {
  12455. node.expression.typeAnnotation = node.typeAnnotation;
  12456. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  12457. return node.expression;
  12458. }
  12459. shouldParseArrow(params) {
  12460. if (this.match(14)) {
  12461. return params.every(expr => this.isAssignable(expr, true));
  12462. }
  12463. return super.shouldParseArrow(params);
  12464. }
  12465. shouldParseAsyncArrow() {
  12466. return this.match(14) || super.shouldParseAsyncArrow();
  12467. }
  12468. canHaveLeadingDecorator() {
  12469. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  12470. }
  12471. jsxParseOpeningElementAfterName(node) {
  12472. if (this.match(47) || this.match(51)) {
  12473. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  12474. if (typeArguments) {
  12475. {
  12476. node.typeParameters = typeArguments;
  12477. }
  12478. }
  12479. }
  12480. return super.jsxParseOpeningElementAfterName(node);
  12481. }
  12482. getGetterSetterExpectedParamCount(method) {
  12483. const baseCount = super.getGetterSetterExpectedParamCount(method);
  12484. const params = this.getObjectOrClassMethodParams(method);
  12485. const firstParam = params[0];
  12486. const hasContextParam = firstParam && this.isThisParam(firstParam);
  12487. return hasContextParam ? baseCount + 1 : baseCount;
  12488. }
  12489. parseCatchClauseParam() {
  12490. const param = super.parseCatchClauseParam();
  12491. const type = this.tsTryParseTypeAnnotation();
  12492. if (type) {
  12493. param.typeAnnotation = type;
  12494. this.resetEndLocation(param);
  12495. }
  12496. return param;
  12497. }
  12498. tsInAmbientContext(cb) {
  12499. const {
  12500. isAmbientContext: oldIsAmbientContext,
  12501. strict: oldStrict
  12502. } = this.state;
  12503. this.state.isAmbientContext = true;
  12504. this.state.strict = false;
  12505. try {
  12506. return cb();
  12507. } finally {
  12508. this.state.isAmbientContext = oldIsAmbientContext;
  12509. this.state.strict = oldStrict;
  12510. }
  12511. }
  12512. parseClass(node, isStatement, optionalId) {
  12513. const oldInAbstractClass = this.state.inAbstractClass;
  12514. this.state.inAbstractClass = !!node.abstract;
  12515. try {
  12516. return super.parseClass(node, isStatement, optionalId);
  12517. } finally {
  12518. this.state.inAbstractClass = oldInAbstractClass;
  12519. }
  12520. }
  12521. tsParseAbstractDeclaration(node, decorators) {
  12522. if (this.match(80)) {
  12523. node.abstract = true;
  12524. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  12525. } else if (this.isContextual(129)) {
  12526. if (!this.hasFollowingLineBreak()) {
  12527. node.abstract = true;
  12528. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  12529. return this.tsParseInterfaceDeclaration(node);
  12530. }
  12531. } else {
  12532. this.unexpected(null, 80);
  12533. }
  12534. }
  12535. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  12536. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  12537. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  12538. const hasEstreePlugin = this.hasPlugin("estree");
  12539. const methodFn = hasEstreePlugin ? method.value : method;
  12540. if (methodFn.body) {
  12541. const {
  12542. key
  12543. } = method;
  12544. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  12545. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  12546. });
  12547. }
  12548. }
  12549. return method;
  12550. }
  12551. tsParseTypeParameterName() {
  12552. const typeName = this.parseIdentifier();
  12553. return typeName.name;
  12554. }
  12555. shouldParseAsAmbientContext() {
  12556. return !!this.getPluginOption("typescript", "dts");
  12557. }
  12558. parse() {
  12559. if (this.shouldParseAsAmbientContext()) {
  12560. this.state.isAmbientContext = true;
  12561. }
  12562. return super.parse();
  12563. }
  12564. getExpression() {
  12565. if (this.shouldParseAsAmbientContext()) {
  12566. this.state.isAmbientContext = true;
  12567. }
  12568. return super.getExpression();
  12569. }
  12570. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  12571. if (!isString && isMaybeTypeOnly) {
  12572. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  12573. return this.finishNode(node, "ExportSpecifier");
  12574. }
  12575. node.exportKind = "value";
  12576. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  12577. }
  12578. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  12579. if (!importedIsString && isMaybeTypeOnly) {
  12580. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  12581. return this.finishNode(specifier, "ImportSpecifier");
  12582. }
  12583. specifier.importKind = "value";
  12584. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  12585. }
  12586. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  12587. const leftOfAsKey = isImport ? "imported" : "local";
  12588. const rightOfAsKey = isImport ? "local" : "exported";
  12589. let leftOfAs = node[leftOfAsKey];
  12590. let rightOfAs;
  12591. let hasTypeSpecifier = false;
  12592. let canParseAsKeyword = true;
  12593. const loc = leftOfAs.loc.start;
  12594. if (this.isContextual(93)) {
  12595. const firstAs = this.parseIdentifier();
  12596. if (this.isContextual(93)) {
  12597. const secondAs = this.parseIdentifier();
  12598. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12599. hasTypeSpecifier = true;
  12600. leftOfAs = firstAs;
  12601. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12602. canParseAsKeyword = false;
  12603. } else {
  12604. rightOfAs = secondAs;
  12605. canParseAsKeyword = false;
  12606. }
  12607. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12608. canParseAsKeyword = false;
  12609. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12610. } else {
  12611. hasTypeSpecifier = true;
  12612. leftOfAs = firstAs;
  12613. }
  12614. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12615. hasTypeSpecifier = true;
  12616. if (isImport) {
  12617. leftOfAs = this.parseIdentifier(true);
  12618. if (!this.isContextual(93)) {
  12619. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  12620. }
  12621. } else {
  12622. leftOfAs = this.parseModuleExportName();
  12623. }
  12624. }
  12625. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  12626. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  12627. }
  12628. node[leftOfAsKey] = leftOfAs;
  12629. node[rightOfAsKey] = rightOfAs;
  12630. const kindKey = isImport ? "importKind" : "exportKind";
  12631. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  12632. if (canParseAsKeyword && this.eatContextual(93)) {
  12633. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12634. }
  12635. if (!node[rightOfAsKey]) {
  12636. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  12637. }
  12638. if (isImport) {
  12639. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  12640. }
  12641. }
  12642. fillOptionalPropertiesForTSESLint(node) {
  12643. 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$declare7, _node$global, _node$const2, _node$in, _node$out;
  12644. switch (node.type) {
  12645. case "ExpressionStatement":
  12646. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  12647. return;
  12648. case "RestElement":
  12649. node.value = undefined;
  12650. case "Identifier":
  12651. case "ArrayPattern":
  12652. case "AssignmentPattern":
  12653. case "ObjectPattern":
  12654. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  12655. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  12656. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  12657. return;
  12658. case "TSParameterProperty":
  12659. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  12660. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  12661. (_node$override = node.override) != null ? _node$override : node.override = false;
  12662. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  12663. (_node$static = node.static) != null ? _node$static : node.static = false;
  12664. return;
  12665. case "TSEmptyBodyFunctionExpression":
  12666. node.body = null;
  12667. case "TSDeclareFunction":
  12668. case "FunctionDeclaration":
  12669. case "FunctionExpression":
  12670. case "ClassMethod":
  12671. case "ClassPrivateMethod":
  12672. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  12673. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  12674. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  12675. return;
  12676. case "Property":
  12677. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  12678. return;
  12679. case "TSMethodSignature":
  12680. case "TSPropertySignature":
  12681. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  12682. case "TSIndexSignature":
  12683. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  12684. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  12685. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  12686. return;
  12687. case "TSAbstractPropertyDefinition":
  12688. case "PropertyDefinition":
  12689. case "TSAbstractAccessorProperty":
  12690. case "AccessorProperty":
  12691. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  12692. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  12693. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  12694. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  12695. case "TSAbstractMethodDefinition":
  12696. case "MethodDefinition":
  12697. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  12698. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  12699. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  12700. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  12701. return;
  12702. case "ClassExpression":
  12703. (_node$id = node.id) != null ? _node$id : node.id = null;
  12704. case "ClassDeclaration":
  12705. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  12706. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  12707. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  12708. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  12709. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  12710. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  12711. return;
  12712. case "TSTypeAliasDeclaration":
  12713. case "VariableDeclaration":
  12714. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  12715. return;
  12716. case "VariableDeclarator":
  12717. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  12718. return;
  12719. case "TSEnumDeclaration":
  12720. (_node$const = node.const) != null ? _node$const : node.const = false;
  12721. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  12722. return;
  12723. case "TSEnumMember":
  12724. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  12725. return;
  12726. case "TSImportType":
  12727. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  12728. (_node$options = node.options) != null ? _node$options : node.options = null;
  12729. return;
  12730. case "TSInterfaceDeclaration":
  12731. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  12732. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  12733. return;
  12734. case "TSModuleDeclaration":
  12735. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  12736. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  12737. return;
  12738. case "TSTypeParameter":
  12739. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  12740. (_node$in = node.in) != null ? _node$in : node.in = false;
  12741. (_node$out = node.out) != null ? _node$out : node.out = false;
  12742. return;
  12743. }
  12744. }
  12745. };
  12746. function isPossiblyLiteralEnum(expression) {
  12747. if (expression.type !== "MemberExpression") return false;
  12748. const {
  12749. computed,
  12750. property
  12751. } = expression;
  12752. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  12753. return false;
  12754. }
  12755. return isUncomputedMemberExpressionChain(expression.object);
  12756. }
  12757. function isValidAmbientConstInitializer(expression, estree) {
  12758. var _expression$extra;
  12759. const {
  12760. type
  12761. } = expression;
  12762. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  12763. return false;
  12764. }
  12765. if (estree) {
  12766. if (type === "Literal") {
  12767. const {
  12768. value
  12769. } = expression;
  12770. if (typeof value === "string" || typeof value === "boolean") {
  12771. return true;
  12772. }
  12773. }
  12774. } else {
  12775. if (type === "StringLiteral" || type === "BooleanLiteral") {
  12776. return true;
  12777. }
  12778. }
  12779. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  12780. return true;
  12781. }
  12782. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  12783. return true;
  12784. }
  12785. if (isPossiblyLiteralEnum(expression)) {
  12786. return true;
  12787. }
  12788. return false;
  12789. }
  12790. function isNumber(expression, estree) {
  12791. if (estree) {
  12792. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  12793. }
  12794. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  12795. }
  12796. function isNegativeNumber(expression, estree) {
  12797. if (expression.type === "UnaryExpression") {
  12798. const {
  12799. operator,
  12800. argument
  12801. } = expression;
  12802. if (operator === "-" && isNumber(argument, estree)) {
  12803. return true;
  12804. }
  12805. }
  12806. return false;
  12807. }
  12808. function isUncomputedMemberExpressionChain(expression) {
  12809. if (expression.type === "Identifier") return true;
  12810. if (expression.type !== "MemberExpression" || expression.computed) {
  12811. return false;
  12812. }
  12813. return isUncomputedMemberExpressionChain(expression.object);
  12814. }
  12815. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  12816. ClassNameIsRequired: "A class name is required.",
  12817. UnexpectedSpace: "Unexpected space in placeholder."
  12818. });
  12819. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  12820. parsePlaceholder(expectedNode) {
  12821. if (this.match(133)) {
  12822. const node = this.startNode();
  12823. this.next();
  12824. this.assertNoSpace();
  12825. node.name = super.parseIdentifier(true);
  12826. this.assertNoSpace();
  12827. this.expect(133);
  12828. return this.finishPlaceholder(node, expectedNode);
  12829. }
  12830. }
  12831. finishPlaceholder(node, expectedNode) {
  12832. let placeholder = node;
  12833. if (!placeholder.expectedNode || !placeholder.type) {
  12834. placeholder = this.finishNode(placeholder, "Placeholder");
  12835. }
  12836. placeholder.expectedNode = expectedNode;
  12837. return placeholder;
  12838. }
  12839. getTokenFromCode(code) {
  12840. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  12841. this.finishOp(133, 2);
  12842. } else {
  12843. super.getTokenFromCode(code);
  12844. }
  12845. }
  12846. parseExprAtom(refExpressionErrors) {
  12847. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  12848. }
  12849. parseIdentifier(liberal) {
  12850. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  12851. }
  12852. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12853. if (word !== undefined) {
  12854. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  12855. }
  12856. }
  12857. cloneIdentifier(node) {
  12858. const cloned = super.cloneIdentifier(node);
  12859. if (cloned.type === "Placeholder") {
  12860. cloned.expectedNode = node.expectedNode;
  12861. }
  12862. return cloned;
  12863. }
  12864. cloneStringLiteral(node) {
  12865. if (node.type === "Placeholder") {
  12866. return this.cloneIdentifier(node);
  12867. }
  12868. return super.cloneStringLiteral(node);
  12869. }
  12870. parseBindingAtom() {
  12871. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  12872. }
  12873. isValidLVal(type, isParenthesized, binding) {
  12874. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  12875. }
  12876. toAssignable(node, isLHS) {
  12877. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  12878. node.expectedNode = "Pattern";
  12879. } else {
  12880. super.toAssignable(node, isLHS);
  12881. }
  12882. }
  12883. chStartsBindingIdentifier(ch, pos) {
  12884. if (super.chStartsBindingIdentifier(ch, pos)) {
  12885. return true;
  12886. }
  12887. const next = this.nextTokenStart();
  12888. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  12889. return true;
  12890. }
  12891. return false;
  12892. }
  12893. verifyBreakContinue(node, isBreak) {
  12894. if (node.label && node.label.type === "Placeholder") return;
  12895. super.verifyBreakContinue(node, isBreak);
  12896. }
  12897. parseExpressionStatement(node, expr) {
  12898. var _expr$extra;
  12899. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  12900. return super.parseExpressionStatement(node, expr);
  12901. }
  12902. if (this.match(14)) {
  12903. const stmt = node;
  12904. stmt.label = this.finishPlaceholder(expr, "Identifier");
  12905. this.next();
  12906. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12907. return this.finishNode(stmt, "LabeledStatement");
  12908. }
  12909. this.semicolon();
  12910. const stmtPlaceholder = node;
  12911. stmtPlaceholder.name = expr.name;
  12912. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  12913. }
  12914. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  12915. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  12916. }
  12917. parseFunctionId(requireId) {
  12918. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  12919. }
  12920. parseClass(node, isStatement, optionalId) {
  12921. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  12922. this.next();
  12923. const oldStrict = this.state.strict;
  12924. const placeholder = this.parsePlaceholder("Identifier");
  12925. if (placeholder) {
  12926. if (this.match(81) || this.match(133) || this.match(5)) {
  12927. node.id = placeholder;
  12928. } else if (optionalId || !isStatement) {
  12929. node.id = null;
  12930. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  12931. return this.finishNode(node, type);
  12932. } else {
  12933. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  12934. }
  12935. } else {
  12936. this.parseClassId(node, isStatement, optionalId);
  12937. }
  12938. super.parseClassSuper(node);
  12939. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  12940. return this.finishNode(node, type);
  12941. }
  12942. parseExport(node, decorators) {
  12943. const placeholder = this.parsePlaceholder("Identifier");
  12944. if (!placeholder) return super.parseExport(node, decorators);
  12945. const node2 = node;
  12946. if (!this.isContextual(98) && !this.match(12)) {
  12947. node2.specifiers = [];
  12948. node2.source = null;
  12949. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  12950. return this.finishNode(node2, "ExportNamedDeclaration");
  12951. }
  12952. this.expectPlugin("exportDefaultFrom");
  12953. const specifier = this.startNode();
  12954. specifier.exported = placeholder;
  12955. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  12956. return super.parseExport(node2, decorators);
  12957. }
  12958. isExportDefaultSpecifier() {
  12959. if (this.match(65)) {
  12960. const next = this.nextTokenStart();
  12961. if (this.isUnparsedContextual(next, "from")) {
  12962. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  12963. return true;
  12964. }
  12965. }
  12966. }
  12967. return super.isExportDefaultSpecifier();
  12968. }
  12969. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  12970. var _specifiers;
  12971. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  12972. return true;
  12973. }
  12974. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  12975. }
  12976. checkExport(node) {
  12977. const {
  12978. specifiers
  12979. } = node;
  12980. if (specifiers != null && specifiers.length) {
  12981. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  12982. }
  12983. super.checkExport(node);
  12984. node.specifiers = specifiers;
  12985. }
  12986. parseImport(node) {
  12987. const placeholder = this.parsePlaceholder("Identifier");
  12988. if (!placeholder) return super.parseImport(node);
  12989. node.specifiers = [];
  12990. if (!this.isContextual(98) && !this.match(12)) {
  12991. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  12992. this.semicolon();
  12993. return this.finishNode(node, "ImportDeclaration");
  12994. }
  12995. const specifier = this.startNodeAtNode(placeholder);
  12996. specifier.local = placeholder;
  12997. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  12998. if (this.eat(12)) {
  12999. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  13000. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  13001. }
  13002. this.expectContextual(98);
  13003. node.source = this.parseImportSource();
  13004. this.semicolon();
  13005. return this.finishNode(node, "ImportDeclaration");
  13006. }
  13007. parseImportSource() {
  13008. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  13009. }
  13010. assertNoSpace() {
  13011. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  13012. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  13013. }
  13014. }
  13015. };
  13016. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  13017. parseV8Intrinsic() {
  13018. if (this.match(54)) {
  13019. const v8IntrinsicStartLoc = this.state.startLoc;
  13020. const node = this.startNode();
  13021. this.next();
  13022. if (tokenIsIdentifier(this.state.type)) {
  13023. const name = this.parseIdentifierName();
  13024. const identifier = this.createIdentifier(node, name);
  13025. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  13026. if (this.match(10)) {
  13027. return identifier;
  13028. }
  13029. }
  13030. this.unexpected(v8IntrinsicStartLoc);
  13031. }
  13032. }
  13033. parseExprAtom(refExpressionErrors) {
  13034. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  13035. }
  13036. };
  13037. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  13038. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  13039. function validatePlugins(pluginsMap) {
  13040. if (pluginsMap.has("decorators")) {
  13041. if (pluginsMap.has("decorators-legacy")) {
  13042. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  13043. }
  13044. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  13045. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  13046. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  13047. }
  13048. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  13049. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  13050. throw new Error("'allowCallParenthesized' must be a boolean.");
  13051. }
  13052. }
  13053. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  13054. throw new Error("Cannot combine flow and typescript plugins.");
  13055. }
  13056. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  13057. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  13058. }
  13059. if (pluginsMap.has("pipelineOperator")) {
  13060. var _pluginsMap$get2;
  13061. const proposal = pluginsMap.get("pipelineOperator").proposal;
  13062. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  13063. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  13064. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  13065. }
  13066. if (proposal === "hack") {
  13067. if (pluginsMap.has("placeholders")) {
  13068. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  13069. }
  13070. if (pluginsMap.has("v8intrinsic")) {
  13071. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  13072. }
  13073. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  13074. if (!TOPIC_TOKENS.includes(topicToken)) {
  13075. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  13076. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  13077. }
  13078. {
  13079. var _pluginsMap$get;
  13080. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  13081. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  13082. }
  13083. }
  13084. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  13085. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  13086. }
  13087. }
  13088. if (pluginsMap.has("moduleAttributes")) {
  13089. {
  13090. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  13091. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  13092. }
  13093. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  13094. if (moduleAttributesVersionPluginOption !== "may-2020") {
  13095. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  13096. }
  13097. }
  13098. }
  13099. if (pluginsMap.has("importAssertions")) {
  13100. if (pluginsMap.has("deprecatedImportAssert")) {
  13101. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  13102. }
  13103. }
  13104. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  13105. {
  13106. pluginsMap.set("deprecatedImportAssert", {});
  13107. }
  13108. }
  13109. if (pluginsMap.has("recordAndTuple")) {
  13110. {
  13111. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  13112. if (syntaxType != null) {
  13113. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  13114. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  13115. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  13116. }
  13117. }
  13118. }
  13119. }
  13120. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  13121. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  13122. error.missingPlugins = "doExpressions";
  13123. throw error;
  13124. }
  13125. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  13126. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  13127. }
  13128. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  13129. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  13130. }
  13131. }
  13132. const mixinPlugins = {
  13133. estree,
  13134. jsx,
  13135. flow,
  13136. typescript,
  13137. v8intrinsic,
  13138. placeholders
  13139. };
  13140. const mixinPluginNames = Object.keys(mixinPlugins);
  13141. class ExpressionParser extends LValParser {
  13142. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  13143. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  13144. return sawProto;
  13145. }
  13146. const key = prop.key;
  13147. const name = key.type === "Identifier" ? key.name : key.value;
  13148. if (name === "__proto__") {
  13149. if (isRecord) {
  13150. this.raise(Errors.RecordNoProto, key);
  13151. return true;
  13152. }
  13153. if (sawProto) {
  13154. if (refExpressionErrors) {
  13155. if (refExpressionErrors.doubleProtoLoc === null) {
  13156. refExpressionErrors.doubleProtoLoc = key.loc.start;
  13157. }
  13158. } else {
  13159. this.raise(Errors.DuplicateProto, key);
  13160. }
  13161. }
  13162. return true;
  13163. }
  13164. return sawProto;
  13165. }
  13166. shouldExitDescending(expr, potentialArrowAt) {
  13167. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  13168. }
  13169. getExpression() {
  13170. this.enterInitialScopes();
  13171. this.nextToken();
  13172. if (this.match(140)) {
  13173. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  13174. }
  13175. const expr = this.parseExpression();
  13176. if (!this.match(140)) {
  13177. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  13178. unexpected: this.input.codePointAt(this.state.start)
  13179. });
  13180. }
  13181. this.finalizeRemainingComments();
  13182. expr.comments = this.comments;
  13183. expr.errors = this.state.errors;
  13184. if (this.optionFlags & 256) {
  13185. expr.tokens = this.tokens;
  13186. }
  13187. return expr;
  13188. }
  13189. parseExpression(disallowIn, refExpressionErrors) {
  13190. if (disallowIn) {
  13191. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  13192. }
  13193. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  13194. }
  13195. parseExpressionBase(refExpressionErrors) {
  13196. const startLoc = this.state.startLoc;
  13197. const expr = this.parseMaybeAssign(refExpressionErrors);
  13198. if (this.match(12)) {
  13199. const node = this.startNodeAt(startLoc);
  13200. node.expressions = [expr];
  13201. while (this.eat(12)) {
  13202. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  13203. }
  13204. this.toReferencedList(node.expressions);
  13205. return this.finishNode(node, "SequenceExpression");
  13206. }
  13207. return expr;
  13208. }
  13209. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  13210. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  13211. }
  13212. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  13213. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  13214. }
  13215. setOptionalParametersError(refExpressionErrors) {
  13216. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  13217. }
  13218. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  13219. const startLoc = this.state.startLoc;
  13220. const isYield = this.isContextual(108);
  13221. if (isYield) {
  13222. if (this.prodParam.hasYield) {
  13223. this.next();
  13224. let left = this.parseYield(startLoc);
  13225. if (afterLeftParse) {
  13226. left = afterLeftParse.call(this, left, startLoc);
  13227. }
  13228. return left;
  13229. }
  13230. }
  13231. let ownExpressionErrors;
  13232. if (refExpressionErrors) {
  13233. ownExpressionErrors = false;
  13234. } else {
  13235. refExpressionErrors = new ExpressionErrors();
  13236. ownExpressionErrors = true;
  13237. }
  13238. const {
  13239. type
  13240. } = this.state;
  13241. if (type === 10 || tokenIsIdentifier(type)) {
  13242. this.state.potentialArrowAt = this.state.start;
  13243. }
  13244. let left = this.parseMaybeConditional(refExpressionErrors);
  13245. if (afterLeftParse) {
  13246. left = afterLeftParse.call(this, left, startLoc);
  13247. }
  13248. if (tokenIsAssignment(this.state.type)) {
  13249. const node = this.startNodeAt(startLoc);
  13250. const operator = this.state.value;
  13251. node.operator = operator;
  13252. if (this.match(29)) {
  13253. this.toAssignable(left, true);
  13254. node.left = left;
  13255. const startIndex = startLoc.index;
  13256. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  13257. refExpressionErrors.doubleProtoLoc = null;
  13258. }
  13259. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  13260. refExpressionErrors.shorthandAssignLoc = null;
  13261. }
  13262. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  13263. this.checkDestructuringPrivate(refExpressionErrors);
  13264. refExpressionErrors.privateKeyLoc = null;
  13265. }
  13266. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  13267. refExpressionErrors.voidPatternLoc = null;
  13268. }
  13269. } else {
  13270. node.left = left;
  13271. }
  13272. this.next();
  13273. node.right = this.parseMaybeAssign();
  13274. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  13275. return node;
  13276. } else if (ownExpressionErrors) {
  13277. this.checkExpressionErrors(refExpressionErrors, true);
  13278. }
  13279. if (isYield) {
  13280. const {
  13281. type
  13282. } = this.state;
  13283. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  13284. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  13285. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  13286. return this.parseYield(startLoc);
  13287. }
  13288. }
  13289. return left;
  13290. }
  13291. parseMaybeConditional(refExpressionErrors) {
  13292. const startLoc = this.state.startLoc;
  13293. const potentialArrowAt = this.state.potentialArrowAt;
  13294. const expr = this.parseExprOps(refExpressionErrors);
  13295. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13296. return expr;
  13297. }
  13298. return this.parseConditional(expr, startLoc, refExpressionErrors);
  13299. }
  13300. parseConditional(expr, startLoc, refExpressionErrors) {
  13301. if (this.eat(17)) {
  13302. const node = this.startNodeAt(startLoc);
  13303. node.test = expr;
  13304. node.consequent = this.parseMaybeAssignAllowIn();
  13305. this.expect(14);
  13306. node.alternate = this.parseMaybeAssign();
  13307. return this.finishNode(node, "ConditionalExpression");
  13308. }
  13309. return expr;
  13310. }
  13311. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  13312. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  13313. }
  13314. parseExprOps(refExpressionErrors) {
  13315. const startLoc = this.state.startLoc;
  13316. const potentialArrowAt = this.state.potentialArrowAt;
  13317. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  13318. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13319. return expr;
  13320. }
  13321. return this.parseExprOp(expr, startLoc, -1);
  13322. }
  13323. parseExprOp(left, leftStartLoc, minPrec) {
  13324. if (this.isPrivateName(left)) {
  13325. const value = this.getPrivateNameSV(left);
  13326. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  13327. this.raise(Errors.PrivateInExpectedIn, left, {
  13328. identifierName: value
  13329. });
  13330. }
  13331. this.classScope.usePrivateName(value, left.loc.start);
  13332. }
  13333. const op = this.state.type;
  13334. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  13335. let prec = tokenOperatorPrecedence(op);
  13336. if (prec > minPrec) {
  13337. if (op === 39) {
  13338. this.expectPlugin("pipelineOperator");
  13339. if (this.state.inFSharpPipelineDirectBody) {
  13340. return left;
  13341. }
  13342. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  13343. }
  13344. const node = this.startNodeAt(leftStartLoc);
  13345. node.left = left;
  13346. node.operator = this.state.value;
  13347. const logical = op === 41 || op === 42;
  13348. const coalesce = op === 40;
  13349. if (coalesce) {
  13350. prec = tokenOperatorPrecedence(42);
  13351. }
  13352. this.next();
  13353. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  13354. proposal: "minimal"
  13355. }])) {
  13356. if (this.state.type === 96 && this.prodParam.hasAwait) {
  13357. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  13358. }
  13359. }
  13360. node.right = this.parseExprOpRightExpr(op, prec);
  13361. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  13362. const nextOp = this.state.type;
  13363. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  13364. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  13365. }
  13366. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  13367. }
  13368. }
  13369. return left;
  13370. }
  13371. parseExprOpRightExpr(op, prec) {
  13372. const startLoc = this.state.startLoc;
  13373. switch (op) {
  13374. case 39:
  13375. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  13376. case "hack":
  13377. return this.withTopicBindingContext(() => {
  13378. return this.parseHackPipeBody();
  13379. });
  13380. case "fsharp":
  13381. return this.withSoloAwaitPermittingContext(() => {
  13382. return this.parseFSharpPipelineBody(prec);
  13383. });
  13384. }
  13385. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  13386. return this.withTopicBindingContext(() => {
  13387. if (this.prodParam.hasYield && this.isContextual(108)) {
  13388. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  13389. }
  13390. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  13391. });
  13392. }
  13393. default:
  13394. return this.parseExprOpBaseRightExpr(op, prec);
  13395. }
  13396. }
  13397. parseExprOpBaseRightExpr(op, prec) {
  13398. const startLoc = this.state.startLoc;
  13399. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  13400. }
  13401. parseHackPipeBody() {
  13402. var _body$extra;
  13403. const {
  13404. startLoc
  13405. } = this.state;
  13406. const body = this.parseMaybeAssign();
  13407. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  13408. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  13409. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  13410. type: body.type
  13411. });
  13412. }
  13413. if (!this.topicReferenceWasUsedInCurrentContext()) {
  13414. this.raise(Errors.PipeTopicUnused, startLoc);
  13415. }
  13416. return body;
  13417. }
  13418. checkExponentialAfterUnary(node) {
  13419. if (this.match(57)) {
  13420. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  13421. }
  13422. }
  13423. parseMaybeUnary(refExpressionErrors, sawUnary) {
  13424. const startLoc = this.state.startLoc;
  13425. const isAwait = this.isContextual(96);
  13426. if (isAwait && this.recordAwaitIfAllowed()) {
  13427. this.next();
  13428. const expr = this.parseAwait(startLoc);
  13429. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  13430. return expr;
  13431. }
  13432. const update = this.match(34);
  13433. const node = this.startNode();
  13434. if (tokenIsPrefix(this.state.type)) {
  13435. node.operator = this.state.value;
  13436. node.prefix = true;
  13437. if (this.match(72)) {
  13438. this.expectPlugin("throwExpressions");
  13439. }
  13440. const isDelete = this.match(89);
  13441. this.next();
  13442. node.argument = this.parseMaybeUnary(null, true);
  13443. this.checkExpressionErrors(refExpressionErrors, true);
  13444. if (this.state.strict && isDelete) {
  13445. const arg = node.argument;
  13446. if (arg.type === "Identifier") {
  13447. this.raise(Errors.StrictDelete, node);
  13448. } else if (this.hasPropertyAsPrivateName(arg)) {
  13449. this.raise(Errors.DeletePrivateField, node);
  13450. }
  13451. }
  13452. if (!update) {
  13453. if (!sawUnary) {
  13454. this.checkExponentialAfterUnary(node);
  13455. }
  13456. return this.finishNode(node, "UnaryExpression");
  13457. }
  13458. }
  13459. const expr = this.parseUpdate(node, update, refExpressionErrors);
  13460. if (isAwait) {
  13461. const {
  13462. type
  13463. } = this.state;
  13464. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  13465. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  13466. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  13467. return this.parseAwait(startLoc);
  13468. }
  13469. }
  13470. return expr;
  13471. }
  13472. parseUpdate(node, update, refExpressionErrors) {
  13473. if (update) {
  13474. const updateExpressionNode = node;
  13475. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  13476. return node;
  13477. }
  13478. const startLoc = this.state.startLoc;
  13479. let expr = this.parseExprSubscripts(refExpressionErrors);
  13480. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  13481. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  13482. const node = this.startNodeAt(startLoc);
  13483. node.operator = this.state.value;
  13484. node.prefix = false;
  13485. node.argument = expr;
  13486. this.next();
  13487. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  13488. }
  13489. return expr;
  13490. }
  13491. parseExprSubscripts(refExpressionErrors) {
  13492. const startLoc = this.state.startLoc;
  13493. const potentialArrowAt = this.state.potentialArrowAt;
  13494. const expr = this.parseExprAtom(refExpressionErrors);
  13495. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13496. return expr;
  13497. }
  13498. return this.parseSubscripts(expr, startLoc);
  13499. }
  13500. parseSubscripts(base, startLoc, noCalls) {
  13501. const state = {
  13502. optionalChainMember: false,
  13503. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  13504. stop: false
  13505. };
  13506. do {
  13507. base = this.parseSubscript(base, startLoc, noCalls, state);
  13508. state.maybeAsyncArrow = false;
  13509. } while (!state.stop);
  13510. return base;
  13511. }
  13512. parseSubscript(base, startLoc, noCalls, state) {
  13513. const {
  13514. type
  13515. } = this.state;
  13516. if (!noCalls && type === 15) {
  13517. return this.parseBind(base, startLoc, noCalls, state);
  13518. } else if (tokenIsTemplate(type)) {
  13519. return this.parseTaggedTemplateExpression(base, startLoc, state);
  13520. }
  13521. let optional = false;
  13522. if (type === 18) {
  13523. if (noCalls) {
  13524. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  13525. if (this.lookaheadCharCode() === 40) {
  13526. return this.stopParseSubscript(base, state);
  13527. }
  13528. }
  13529. state.optionalChainMember = optional = true;
  13530. this.next();
  13531. }
  13532. if (!noCalls && this.match(10)) {
  13533. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  13534. } else {
  13535. const computed = this.eat(0);
  13536. if (computed || optional || this.eat(16)) {
  13537. return this.parseMember(base, startLoc, state, computed, optional);
  13538. } else {
  13539. return this.stopParseSubscript(base, state);
  13540. }
  13541. }
  13542. }
  13543. stopParseSubscript(base, state) {
  13544. state.stop = true;
  13545. return base;
  13546. }
  13547. parseMember(base, startLoc, state, computed, optional) {
  13548. const node = this.startNodeAt(startLoc);
  13549. node.object = base;
  13550. node.computed = computed;
  13551. if (computed) {
  13552. node.property = this.parseExpression();
  13553. this.expect(3);
  13554. } else if (this.match(139)) {
  13555. if (base.type === "Super") {
  13556. this.raise(Errors.SuperPrivateField, startLoc);
  13557. }
  13558. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13559. node.property = this.parsePrivateName();
  13560. } else {
  13561. node.property = this.parseIdentifier(true);
  13562. }
  13563. if (state.optionalChainMember) {
  13564. node.optional = optional;
  13565. return this.finishNode(node, "OptionalMemberExpression");
  13566. } else {
  13567. return this.finishNode(node, "MemberExpression");
  13568. }
  13569. }
  13570. parseBind(base, startLoc, noCalls, state) {
  13571. const node = this.startNodeAt(startLoc);
  13572. node.object = base;
  13573. this.next();
  13574. node.callee = this.parseNoCallExpr();
  13575. state.stop = true;
  13576. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  13577. }
  13578. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  13579. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13580. let refExpressionErrors = null;
  13581. this.state.maybeInArrowParameters = true;
  13582. this.next();
  13583. const node = this.startNodeAt(startLoc);
  13584. node.callee = base;
  13585. const {
  13586. maybeAsyncArrow,
  13587. optionalChainMember
  13588. } = state;
  13589. if (maybeAsyncArrow) {
  13590. this.expressionScope.enter(newAsyncArrowScope());
  13591. refExpressionErrors = new ExpressionErrors();
  13592. }
  13593. if (optionalChainMember) {
  13594. node.optional = optional;
  13595. }
  13596. if (optional) {
  13597. node.arguments = this.parseCallExpressionArguments();
  13598. } else {
  13599. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  13600. }
  13601. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  13602. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  13603. state.stop = true;
  13604. this.checkDestructuringPrivate(refExpressionErrors);
  13605. this.expressionScope.validateAsPattern();
  13606. this.expressionScope.exit();
  13607. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  13608. } else {
  13609. if (maybeAsyncArrow) {
  13610. this.checkExpressionErrors(refExpressionErrors, true);
  13611. this.expressionScope.exit();
  13612. }
  13613. this.toReferencedArguments(finishedNode);
  13614. }
  13615. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13616. return finishedNode;
  13617. }
  13618. toReferencedArguments(node, isParenthesizedExpr) {
  13619. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  13620. }
  13621. parseTaggedTemplateExpression(base, startLoc, state) {
  13622. const node = this.startNodeAt(startLoc);
  13623. node.tag = base;
  13624. node.quasi = this.parseTemplate(true);
  13625. if (state.optionalChainMember) {
  13626. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  13627. }
  13628. return this.finishNode(node, "TaggedTemplateExpression");
  13629. }
  13630. atPossibleAsyncArrow(base) {
  13631. 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;
  13632. }
  13633. finishCallExpression(node, optional) {
  13634. if (node.callee.type === "Import") {
  13635. if (node.arguments.length === 0 || node.arguments.length > 2) {
  13636. this.raise(Errors.ImportCallArity, node);
  13637. } else {
  13638. for (const arg of node.arguments) {
  13639. if (arg.type === "SpreadElement") {
  13640. this.raise(Errors.ImportCallSpreadArgument, arg);
  13641. }
  13642. }
  13643. }
  13644. }
  13645. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  13646. }
  13647. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  13648. const elts = [];
  13649. let first = true;
  13650. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  13651. this.state.inFSharpPipelineDirectBody = false;
  13652. while (!this.eat(11)) {
  13653. if (first) {
  13654. first = false;
  13655. } else {
  13656. this.expect(12);
  13657. if (this.match(11)) {
  13658. if (nodeForExtra) {
  13659. this.addTrailingCommaExtraToNode(nodeForExtra);
  13660. }
  13661. this.next();
  13662. break;
  13663. }
  13664. }
  13665. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  13666. }
  13667. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  13668. return elts;
  13669. }
  13670. shouldParseAsyncArrow() {
  13671. return this.match(19) && !this.canInsertSemicolon();
  13672. }
  13673. parseAsyncArrowFromCallExpression(node, call) {
  13674. var _call$extra;
  13675. this.resetPreviousNodeTrailingComments(call);
  13676. this.expect(19);
  13677. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  13678. if (call.innerComments) {
  13679. setInnerComments(node, call.innerComments);
  13680. }
  13681. if (call.callee.trailingComments) {
  13682. setInnerComments(node, call.callee.trailingComments);
  13683. }
  13684. return node;
  13685. }
  13686. parseNoCallExpr() {
  13687. const startLoc = this.state.startLoc;
  13688. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  13689. }
  13690. parseExprAtom(refExpressionErrors) {
  13691. let node;
  13692. let decorators = null;
  13693. const {
  13694. type
  13695. } = this.state;
  13696. switch (type) {
  13697. case 79:
  13698. return this.parseSuper();
  13699. case 83:
  13700. node = this.startNode();
  13701. this.next();
  13702. if (this.match(16)) {
  13703. return this.parseImportMetaPropertyOrPhaseCall(node);
  13704. }
  13705. if (this.match(10)) {
  13706. if (this.optionFlags & 512) {
  13707. return this.parseImportCall(node);
  13708. } else {
  13709. return this.finishNode(node, "Import");
  13710. }
  13711. } else {
  13712. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  13713. return this.finishNode(node, "Import");
  13714. }
  13715. case 78:
  13716. node = this.startNode();
  13717. this.next();
  13718. return this.finishNode(node, "ThisExpression");
  13719. case 90:
  13720. {
  13721. return this.parseDo(this.startNode(), false);
  13722. }
  13723. case 56:
  13724. case 31:
  13725. {
  13726. this.readRegexp();
  13727. return this.parseRegExpLiteral(this.state.value);
  13728. }
  13729. case 135:
  13730. return this.parseNumericLiteral(this.state.value);
  13731. case 136:
  13732. return this.parseBigIntLiteral(this.state.value);
  13733. case 134:
  13734. return this.parseStringLiteral(this.state.value);
  13735. case 84:
  13736. return this.parseNullLiteral();
  13737. case 85:
  13738. return this.parseBooleanLiteral(true);
  13739. case 86:
  13740. return this.parseBooleanLiteral(false);
  13741. case 10:
  13742. {
  13743. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  13744. return this.parseParenAndDistinguishExpression(canBeArrow);
  13745. }
  13746. case 0:
  13747. {
  13748. return this.parseArrayLike(3, true, false, refExpressionErrors);
  13749. }
  13750. case 5:
  13751. {
  13752. return this.parseObjectLike(8, false, false, refExpressionErrors);
  13753. }
  13754. case 68:
  13755. return this.parseFunctionOrFunctionSent();
  13756. case 26:
  13757. decorators = this.parseDecorators();
  13758. case 80:
  13759. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  13760. case 77:
  13761. return this.parseNewOrNewTarget();
  13762. case 25:
  13763. case 24:
  13764. return this.parseTemplate(false);
  13765. case 15:
  13766. {
  13767. node = this.startNode();
  13768. this.next();
  13769. node.object = null;
  13770. const callee = node.callee = this.parseNoCallExpr();
  13771. if (callee.type === "MemberExpression") {
  13772. return this.finishNode(node, "BindExpression");
  13773. } else {
  13774. throw this.raise(Errors.UnsupportedBind, callee);
  13775. }
  13776. }
  13777. case 139:
  13778. {
  13779. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  13780. identifierName: this.state.value
  13781. });
  13782. return this.parsePrivateName();
  13783. }
  13784. case 33:
  13785. {
  13786. return this.parseTopicReferenceThenEqualsSign(54, "%");
  13787. }
  13788. case 32:
  13789. {
  13790. return this.parseTopicReferenceThenEqualsSign(44, "^");
  13791. }
  13792. case 37:
  13793. case 38:
  13794. {
  13795. return this.parseTopicReference("hack");
  13796. }
  13797. case 44:
  13798. case 54:
  13799. case 27:
  13800. {
  13801. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  13802. if (pipeProposal) {
  13803. return this.parseTopicReference(pipeProposal);
  13804. }
  13805. this.unexpected();
  13806. break;
  13807. }
  13808. case 47:
  13809. {
  13810. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  13811. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  13812. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  13813. } else {
  13814. this.unexpected();
  13815. }
  13816. break;
  13817. }
  13818. default:
  13819. {
  13820. if (type === 137) {
  13821. return this.parseDecimalLiteral(this.state.value);
  13822. } else if (type === 2 || type === 1) {
  13823. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  13824. } else if (type === 6 || type === 7) {
  13825. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  13826. }
  13827. }
  13828. if (tokenIsIdentifier(type)) {
  13829. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  13830. return this.parseModuleExpression();
  13831. }
  13832. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  13833. const containsEsc = this.state.containsEsc;
  13834. const id = this.parseIdentifier();
  13835. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  13836. const {
  13837. type
  13838. } = this.state;
  13839. if (type === 68) {
  13840. this.resetPreviousNodeTrailingComments(id);
  13841. this.next();
  13842. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  13843. } else if (tokenIsIdentifier(type)) {
  13844. if (this.lookaheadCharCode() === 61) {
  13845. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  13846. } else {
  13847. return id;
  13848. }
  13849. } else if (type === 90) {
  13850. this.resetPreviousNodeTrailingComments(id);
  13851. return this.parseDo(this.startNodeAtNode(id), true);
  13852. }
  13853. }
  13854. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  13855. this.next();
  13856. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  13857. }
  13858. return id;
  13859. } else {
  13860. this.unexpected();
  13861. }
  13862. }
  13863. }
  13864. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  13865. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  13866. if (pipeProposal) {
  13867. this.state.type = topicTokenType;
  13868. this.state.value = topicTokenValue;
  13869. this.state.pos--;
  13870. this.state.end--;
  13871. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  13872. return this.parseTopicReference(pipeProposal);
  13873. } else {
  13874. this.unexpected();
  13875. }
  13876. }
  13877. parseTopicReference(pipeProposal) {
  13878. const node = this.startNode();
  13879. const startLoc = this.state.startLoc;
  13880. const tokenType = this.state.type;
  13881. this.next();
  13882. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  13883. }
  13884. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  13885. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  13886. if (pipeProposal === "hack") {
  13887. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  13888. this.raise(Errors.PipeTopicUnbound, startLoc);
  13889. }
  13890. this.registerTopicReference();
  13891. return this.finishNode(node, "TopicReference");
  13892. } else {
  13893. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  13894. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  13895. }
  13896. this.registerTopicReference();
  13897. return this.finishNode(node, "PipelinePrimaryTopicReference");
  13898. }
  13899. } else {
  13900. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  13901. token: tokenLabelName(tokenType)
  13902. });
  13903. }
  13904. }
  13905. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  13906. switch (pipeProposal) {
  13907. case "hack":
  13908. {
  13909. return this.hasPlugin(["pipelineOperator", {
  13910. topicToken: tokenLabelName(tokenType)
  13911. }]);
  13912. }
  13913. case "smart":
  13914. return tokenType === 27;
  13915. default:
  13916. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  13917. }
  13918. }
  13919. parseAsyncArrowUnaryFunction(node) {
  13920. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  13921. const params = [this.parseIdentifier()];
  13922. this.prodParam.exit();
  13923. if (this.hasPrecedingLineBreak()) {
  13924. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  13925. }
  13926. this.expect(19);
  13927. return this.parseArrowExpression(node, params, true);
  13928. }
  13929. parseDo(node, isAsync) {
  13930. this.expectPlugin("doExpressions");
  13931. if (isAsync) {
  13932. this.expectPlugin("asyncDoExpressions");
  13933. }
  13934. node.async = isAsync;
  13935. this.next();
  13936. const oldLabels = this.state.labels;
  13937. this.state.labels = [];
  13938. if (isAsync) {
  13939. this.prodParam.enter(2);
  13940. node.body = this.parseBlock();
  13941. this.prodParam.exit();
  13942. } else {
  13943. node.body = this.parseBlock();
  13944. }
  13945. this.state.labels = oldLabels;
  13946. return this.finishNode(node, "DoExpression");
  13947. }
  13948. parseSuper() {
  13949. const node = this.startNode();
  13950. this.next();
  13951. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  13952. this.raise(Errors.SuperNotAllowed, node);
  13953. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  13954. this.raise(Errors.UnexpectedSuper, node);
  13955. }
  13956. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  13957. this.raise(Errors.UnsupportedSuper, node);
  13958. }
  13959. return this.finishNode(node, "Super");
  13960. }
  13961. parsePrivateName() {
  13962. const node = this.startNode();
  13963. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  13964. const name = this.state.value;
  13965. this.next();
  13966. node.id = this.createIdentifier(id, name);
  13967. return this.finishNode(node, "PrivateName");
  13968. }
  13969. parseFunctionOrFunctionSent() {
  13970. const node = this.startNode();
  13971. this.next();
  13972. if (this.prodParam.hasYield && this.match(16)) {
  13973. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  13974. this.next();
  13975. if (this.match(103)) {
  13976. this.expectPlugin("functionSent");
  13977. } else if (!this.hasPlugin("functionSent")) {
  13978. this.unexpected();
  13979. }
  13980. return this.parseMetaProperty(node, meta, "sent");
  13981. }
  13982. return this.parseFunction(node);
  13983. }
  13984. parseMetaProperty(node, meta, propertyName) {
  13985. node.meta = meta;
  13986. const containsEsc = this.state.containsEsc;
  13987. node.property = this.parseIdentifier(true);
  13988. if (node.property.name !== propertyName || containsEsc) {
  13989. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  13990. target: meta.name,
  13991. onlyValidPropertyName: propertyName
  13992. });
  13993. }
  13994. return this.finishNode(node, "MetaProperty");
  13995. }
  13996. parseImportMetaPropertyOrPhaseCall(node) {
  13997. this.next();
  13998. if (this.isContextual(105) || this.isContextual(97)) {
  13999. const isSource = this.isContextual(105);
  14000. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  14001. this.next();
  14002. node.phase = isSource ? "source" : "defer";
  14003. return this.parseImportCall(node);
  14004. } else {
  14005. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  14006. if (this.isContextual(101)) {
  14007. if (!this.inModule) {
  14008. this.raise(Errors.ImportMetaOutsideModule, id);
  14009. }
  14010. this.sawUnambiguousESM = true;
  14011. }
  14012. return this.parseMetaProperty(node, id, "meta");
  14013. }
  14014. }
  14015. parseLiteralAtNode(value, type, node) {
  14016. this.addExtra(node, "rawValue", value);
  14017. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  14018. node.value = value;
  14019. this.next();
  14020. return this.finishNode(node, type);
  14021. }
  14022. parseLiteral(value, type) {
  14023. const node = this.startNode();
  14024. return this.parseLiteralAtNode(value, type, node);
  14025. }
  14026. parseStringLiteral(value) {
  14027. return this.parseLiteral(value, "StringLiteral");
  14028. }
  14029. parseNumericLiteral(value) {
  14030. return this.parseLiteral(value, "NumericLiteral");
  14031. }
  14032. parseBigIntLiteral(value) {
  14033. {
  14034. return this.parseLiteral(value, "BigIntLiteral");
  14035. }
  14036. }
  14037. parseDecimalLiteral(value) {
  14038. return this.parseLiteral(value, "DecimalLiteral");
  14039. }
  14040. parseRegExpLiteral(value) {
  14041. const node = this.startNode();
  14042. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  14043. node.pattern = value.pattern;
  14044. node.flags = value.flags;
  14045. this.next();
  14046. return this.finishNode(node, "RegExpLiteral");
  14047. }
  14048. parseBooleanLiteral(value) {
  14049. const node = this.startNode();
  14050. node.value = value;
  14051. this.next();
  14052. return this.finishNode(node, "BooleanLiteral");
  14053. }
  14054. parseNullLiteral() {
  14055. const node = this.startNode();
  14056. this.next();
  14057. return this.finishNode(node, "NullLiteral");
  14058. }
  14059. parseParenAndDistinguishExpression(canBeArrow) {
  14060. const startLoc = this.state.startLoc;
  14061. let val;
  14062. this.next();
  14063. this.expressionScope.enter(newArrowHeadScope());
  14064. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  14065. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14066. this.state.maybeInArrowParameters = true;
  14067. this.state.inFSharpPipelineDirectBody = false;
  14068. const innerStartLoc = this.state.startLoc;
  14069. const exprList = [];
  14070. const refExpressionErrors = new ExpressionErrors();
  14071. let first = true;
  14072. let spreadStartLoc;
  14073. let optionalCommaStartLoc;
  14074. while (!this.match(11)) {
  14075. if (first) {
  14076. first = false;
  14077. } else {
  14078. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  14079. if (this.match(11)) {
  14080. optionalCommaStartLoc = this.state.startLoc;
  14081. break;
  14082. }
  14083. }
  14084. if (this.match(21)) {
  14085. const spreadNodeStartLoc = this.state.startLoc;
  14086. spreadStartLoc = this.state.startLoc;
  14087. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  14088. if (!this.checkCommaAfterRest(41)) {
  14089. break;
  14090. }
  14091. } else {
  14092. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  14093. }
  14094. }
  14095. const innerEndLoc = this.state.lastTokEndLoc;
  14096. this.expect(11);
  14097. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  14098. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14099. let arrowNode = this.startNodeAt(startLoc);
  14100. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  14101. this.checkDestructuringPrivate(refExpressionErrors);
  14102. this.expressionScope.validateAsPattern();
  14103. this.expressionScope.exit();
  14104. this.parseArrowExpression(arrowNode, exprList, false);
  14105. return arrowNode;
  14106. }
  14107. this.expressionScope.exit();
  14108. if (!exprList.length) {
  14109. this.unexpected(this.state.lastTokStartLoc);
  14110. }
  14111. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  14112. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  14113. this.checkExpressionErrors(refExpressionErrors, true);
  14114. this.toReferencedListDeep(exprList, true);
  14115. if (exprList.length > 1) {
  14116. val = this.startNodeAt(innerStartLoc);
  14117. val.expressions = exprList;
  14118. this.finishNode(val, "SequenceExpression");
  14119. this.resetEndLocation(val, innerEndLoc);
  14120. } else {
  14121. val = exprList[0];
  14122. }
  14123. return this.wrapParenthesis(startLoc, val);
  14124. }
  14125. wrapParenthesis(startLoc, expression) {
  14126. if (!(this.optionFlags & 1024)) {
  14127. this.addExtra(expression, "parenthesized", true);
  14128. this.addExtra(expression, "parenStart", startLoc.index);
  14129. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  14130. return expression;
  14131. }
  14132. const parenExpression = this.startNodeAt(startLoc);
  14133. parenExpression.expression = expression;
  14134. return this.finishNode(parenExpression, "ParenthesizedExpression");
  14135. }
  14136. shouldParseArrow(params) {
  14137. return !this.canInsertSemicolon();
  14138. }
  14139. parseArrow(node) {
  14140. if (this.eat(19)) {
  14141. return node;
  14142. }
  14143. }
  14144. parseParenItem(node, startLoc) {
  14145. return node;
  14146. }
  14147. parseNewOrNewTarget() {
  14148. const node = this.startNode();
  14149. this.next();
  14150. if (this.match(16)) {
  14151. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  14152. this.next();
  14153. const metaProp = this.parseMetaProperty(node, meta, "target");
  14154. if (!this.scope.allowNewTarget) {
  14155. this.raise(Errors.UnexpectedNewTarget, metaProp);
  14156. }
  14157. return metaProp;
  14158. }
  14159. return this.parseNew(node);
  14160. }
  14161. parseNew(node) {
  14162. this.parseNewCallee(node);
  14163. if (this.eat(10)) {
  14164. const args = this.parseExprList(11);
  14165. this.toReferencedList(args);
  14166. node.arguments = args;
  14167. } else {
  14168. node.arguments = [];
  14169. }
  14170. return this.finishNode(node, "NewExpression");
  14171. }
  14172. parseNewCallee(node) {
  14173. const isImport = this.match(83);
  14174. const callee = this.parseNoCallExpr();
  14175. node.callee = callee;
  14176. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  14177. this.raise(Errors.ImportCallNotNewExpression, callee);
  14178. }
  14179. }
  14180. parseTemplateElement(isTagged) {
  14181. const {
  14182. start,
  14183. startLoc,
  14184. end,
  14185. value
  14186. } = this.state;
  14187. const elemStart = start + 1;
  14188. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  14189. if (value === null) {
  14190. if (!isTagged) {
  14191. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  14192. }
  14193. }
  14194. const isTail = this.match(24);
  14195. const endOffset = isTail ? -1 : -2;
  14196. const elemEnd = end + endOffset;
  14197. elem.value = {
  14198. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  14199. cooked: value === null ? null : value.slice(1, endOffset)
  14200. };
  14201. elem.tail = isTail;
  14202. this.next();
  14203. const finishedNode = this.finishNode(elem, "TemplateElement");
  14204. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  14205. return finishedNode;
  14206. }
  14207. parseTemplate(isTagged) {
  14208. const node = this.startNode();
  14209. let curElt = this.parseTemplateElement(isTagged);
  14210. const quasis = [curElt];
  14211. const substitutions = [];
  14212. while (!curElt.tail) {
  14213. substitutions.push(this.parseTemplateSubstitution());
  14214. this.readTemplateContinuation();
  14215. quasis.push(curElt = this.parseTemplateElement(isTagged));
  14216. }
  14217. node.expressions = substitutions;
  14218. node.quasis = quasis;
  14219. return this.finishNode(node, "TemplateLiteral");
  14220. }
  14221. parseTemplateSubstitution() {
  14222. return this.parseExpression();
  14223. }
  14224. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  14225. if (isRecord) {
  14226. this.expectPlugin("recordAndTuple");
  14227. }
  14228. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14229. this.state.inFSharpPipelineDirectBody = false;
  14230. let sawProto = false;
  14231. let first = true;
  14232. const node = this.startNode();
  14233. node.properties = [];
  14234. this.next();
  14235. while (!this.match(close)) {
  14236. if (first) {
  14237. first = false;
  14238. } else {
  14239. this.expect(12);
  14240. if (this.match(close)) {
  14241. this.addTrailingCommaExtraToNode(node);
  14242. break;
  14243. }
  14244. }
  14245. let prop;
  14246. if (isPattern) {
  14247. prop = this.parseBindingProperty();
  14248. } else {
  14249. prop = this.parsePropertyDefinition(refExpressionErrors);
  14250. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  14251. }
  14252. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  14253. this.raise(Errors.InvalidRecordProperty, prop);
  14254. }
  14255. {
  14256. if (prop.shorthand) {
  14257. this.addExtra(prop, "shorthand", true);
  14258. }
  14259. }
  14260. node.properties.push(prop);
  14261. }
  14262. this.next();
  14263. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14264. let type = "ObjectExpression";
  14265. if (isPattern) {
  14266. type = "ObjectPattern";
  14267. } else if (isRecord) {
  14268. type = "RecordExpression";
  14269. }
  14270. return this.finishNode(node, type);
  14271. }
  14272. addTrailingCommaExtraToNode(node) {
  14273. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  14274. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  14275. }
  14276. maybeAsyncOrAccessorProp(prop) {
  14277. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  14278. }
  14279. parsePropertyDefinition(refExpressionErrors) {
  14280. let decorators = [];
  14281. if (this.match(26)) {
  14282. if (this.hasPlugin("decorators")) {
  14283. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  14284. }
  14285. while (this.match(26)) {
  14286. decorators.push(this.parseDecorator());
  14287. }
  14288. }
  14289. const prop = this.startNode();
  14290. let isAsync = false;
  14291. let isAccessor = false;
  14292. let startLoc;
  14293. if (this.match(21)) {
  14294. if (decorators.length) this.unexpected();
  14295. return this.parseSpread();
  14296. }
  14297. if (decorators.length) {
  14298. prop.decorators = decorators;
  14299. decorators = [];
  14300. }
  14301. prop.method = false;
  14302. if (refExpressionErrors) {
  14303. startLoc = this.state.startLoc;
  14304. }
  14305. let isGenerator = this.eat(55);
  14306. this.parsePropertyNamePrefixOperator(prop);
  14307. const containsEsc = this.state.containsEsc;
  14308. this.parsePropertyName(prop, refExpressionErrors);
  14309. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  14310. const {
  14311. key
  14312. } = prop;
  14313. const keyName = key.name;
  14314. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  14315. isAsync = true;
  14316. this.resetPreviousNodeTrailingComments(key);
  14317. isGenerator = this.eat(55);
  14318. this.parsePropertyName(prop);
  14319. }
  14320. if (keyName === "get" || keyName === "set") {
  14321. isAccessor = true;
  14322. this.resetPreviousNodeTrailingComments(key);
  14323. prop.kind = keyName;
  14324. if (this.match(55)) {
  14325. isGenerator = true;
  14326. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  14327. kind: keyName
  14328. });
  14329. this.next();
  14330. }
  14331. this.parsePropertyName(prop);
  14332. }
  14333. }
  14334. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  14335. }
  14336. getGetterSetterExpectedParamCount(method) {
  14337. return method.kind === "get" ? 0 : 1;
  14338. }
  14339. getObjectOrClassMethodParams(method) {
  14340. return method.params;
  14341. }
  14342. checkGetterSetterParams(method) {
  14343. var _params;
  14344. const paramCount = this.getGetterSetterExpectedParamCount(method);
  14345. const params = this.getObjectOrClassMethodParams(method);
  14346. if (params.length !== paramCount) {
  14347. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  14348. }
  14349. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  14350. this.raise(Errors.BadSetterRestParameter, method);
  14351. }
  14352. }
  14353. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  14354. if (isAccessor) {
  14355. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  14356. this.checkGetterSetterParams(finishedProp);
  14357. return finishedProp;
  14358. }
  14359. if (isAsync || isGenerator || this.match(10)) {
  14360. if (isPattern) this.unexpected();
  14361. prop.kind = "method";
  14362. prop.method = true;
  14363. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  14364. }
  14365. }
  14366. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  14367. prop.shorthand = false;
  14368. if (this.eat(14)) {
  14369. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  14370. return this.finishObjectProperty(prop);
  14371. }
  14372. if (!prop.computed && prop.key.type === "Identifier") {
  14373. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  14374. if (isPattern) {
  14375. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  14376. } else if (this.match(29)) {
  14377. const shorthandAssignLoc = this.state.startLoc;
  14378. if (refExpressionErrors != null) {
  14379. if (refExpressionErrors.shorthandAssignLoc === null) {
  14380. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  14381. }
  14382. } else {
  14383. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  14384. }
  14385. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  14386. } else {
  14387. prop.value = this.cloneIdentifier(prop.key);
  14388. }
  14389. prop.shorthand = true;
  14390. return this.finishObjectProperty(prop);
  14391. }
  14392. }
  14393. finishObjectProperty(node) {
  14394. return this.finishNode(node, "ObjectProperty");
  14395. }
  14396. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  14397. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  14398. if (!node) this.unexpected();
  14399. return node;
  14400. }
  14401. parsePropertyName(prop, refExpressionErrors) {
  14402. if (this.eat(0)) {
  14403. prop.computed = true;
  14404. prop.key = this.parseMaybeAssignAllowIn();
  14405. this.expect(3);
  14406. } else {
  14407. const {
  14408. type,
  14409. value
  14410. } = this.state;
  14411. let key;
  14412. if (tokenIsKeywordOrIdentifier(type)) {
  14413. key = this.parseIdentifier(true);
  14414. } else {
  14415. switch (type) {
  14416. case 135:
  14417. key = this.parseNumericLiteral(value);
  14418. break;
  14419. case 134:
  14420. key = this.parseStringLiteral(value);
  14421. break;
  14422. case 136:
  14423. key = this.parseBigIntLiteral(value);
  14424. break;
  14425. case 139:
  14426. {
  14427. const privateKeyLoc = this.state.startLoc;
  14428. if (refExpressionErrors != null) {
  14429. if (refExpressionErrors.privateKeyLoc === null) {
  14430. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  14431. }
  14432. } else {
  14433. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  14434. }
  14435. key = this.parsePrivateName();
  14436. break;
  14437. }
  14438. default:
  14439. if (type === 137) {
  14440. key = this.parseDecimalLiteral(value);
  14441. break;
  14442. }
  14443. this.unexpected();
  14444. }
  14445. }
  14446. prop.key = key;
  14447. if (type !== 139) {
  14448. prop.computed = false;
  14449. }
  14450. }
  14451. }
  14452. initFunction(node, isAsync) {
  14453. node.id = null;
  14454. node.generator = false;
  14455. node.async = isAsync;
  14456. }
  14457. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  14458. this.initFunction(node, isAsync);
  14459. node.generator = isGenerator;
  14460. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  14461. this.prodParam.enter(functionFlags(isAsync, node.generator));
  14462. this.parseFunctionParams(node, isConstructor);
  14463. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  14464. this.prodParam.exit();
  14465. this.scope.exit();
  14466. return finishedNode;
  14467. }
  14468. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  14469. if (isTuple) {
  14470. this.expectPlugin("recordAndTuple");
  14471. }
  14472. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14473. this.state.inFSharpPipelineDirectBody = false;
  14474. const node = this.startNode();
  14475. this.next();
  14476. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  14477. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14478. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  14479. }
  14480. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  14481. this.scope.enter(514 | 4);
  14482. let flags = functionFlags(isAsync, false);
  14483. if (!this.match(5) && this.prodParam.hasIn) {
  14484. flags |= 8;
  14485. }
  14486. this.prodParam.enter(flags);
  14487. this.initFunction(node, isAsync);
  14488. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  14489. if (params) {
  14490. this.state.maybeInArrowParameters = true;
  14491. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  14492. }
  14493. this.state.maybeInArrowParameters = false;
  14494. this.parseFunctionBody(node, true);
  14495. this.prodParam.exit();
  14496. this.scope.exit();
  14497. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  14498. return this.finishNode(node, "ArrowFunctionExpression");
  14499. }
  14500. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  14501. this.toAssignableList(params, trailingCommaLoc, false);
  14502. node.params = params;
  14503. }
  14504. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  14505. this.parseFunctionBody(node, false, isMethod);
  14506. return this.finishNode(node, type);
  14507. }
  14508. parseFunctionBody(node, allowExpression, isMethod = false) {
  14509. const isExpression = allowExpression && !this.match(5);
  14510. this.expressionScope.enter(newExpressionScope());
  14511. if (isExpression) {
  14512. node.body = this.parseMaybeAssign();
  14513. this.checkParams(node, false, allowExpression, false);
  14514. } else {
  14515. const oldStrict = this.state.strict;
  14516. const oldLabels = this.state.labels;
  14517. this.state.labels = [];
  14518. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  14519. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  14520. const nonSimple = !this.isSimpleParamList(node.params);
  14521. if (hasStrictModeDirective && nonSimple) {
  14522. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  14523. }
  14524. const strictModeChanged = !oldStrict && this.state.strict;
  14525. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  14526. if (this.state.strict && node.id) {
  14527. this.checkIdentifier(node.id, 65, strictModeChanged);
  14528. }
  14529. });
  14530. this.prodParam.exit();
  14531. this.state.labels = oldLabels;
  14532. }
  14533. this.expressionScope.exit();
  14534. }
  14535. isSimpleParameter(node) {
  14536. return node.type === "Identifier";
  14537. }
  14538. isSimpleParamList(params) {
  14539. for (let i = 0, len = params.length; i < len; i++) {
  14540. if (!this.isSimpleParameter(params[i])) return false;
  14541. }
  14542. return true;
  14543. }
  14544. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  14545. const checkClashes = !allowDuplicates && new Set();
  14546. const formalParameters = {
  14547. type: "FormalParameters"
  14548. };
  14549. for (const param of node.params) {
  14550. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  14551. }
  14552. }
  14553. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  14554. const elts = [];
  14555. let first = true;
  14556. while (!this.eat(close)) {
  14557. if (first) {
  14558. first = false;
  14559. } else {
  14560. this.expect(12);
  14561. if (this.match(close)) {
  14562. if (nodeForExtra) {
  14563. this.addTrailingCommaExtraToNode(nodeForExtra);
  14564. }
  14565. this.next();
  14566. break;
  14567. }
  14568. }
  14569. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  14570. }
  14571. return elts;
  14572. }
  14573. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  14574. let elt;
  14575. if (this.match(12)) {
  14576. if (!allowEmpty) {
  14577. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  14578. unexpected: ","
  14579. });
  14580. }
  14581. elt = null;
  14582. } else if (this.match(21)) {
  14583. const spreadNodeStartLoc = this.state.startLoc;
  14584. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  14585. } else if (this.match(17)) {
  14586. this.expectPlugin("partialApplication");
  14587. if (!allowPlaceholder) {
  14588. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  14589. }
  14590. const node = this.startNode();
  14591. this.next();
  14592. elt = this.finishNode(node, "ArgumentPlaceholder");
  14593. } else {
  14594. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  14595. }
  14596. return elt;
  14597. }
  14598. parseIdentifier(liberal) {
  14599. const node = this.startNode();
  14600. const name = this.parseIdentifierName(liberal);
  14601. return this.createIdentifier(node, name);
  14602. }
  14603. createIdentifier(node, name) {
  14604. node.name = name;
  14605. node.loc.identifierName = name;
  14606. return this.finishNode(node, "Identifier");
  14607. }
  14608. createIdentifierAt(node, name, endLoc) {
  14609. node.name = name;
  14610. node.loc.identifierName = name;
  14611. return this.finishNodeAt(node, "Identifier", endLoc);
  14612. }
  14613. parseIdentifierName(liberal) {
  14614. let name;
  14615. const {
  14616. startLoc,
  14617. type
  14618. } = this.state;
  14619. if (tokenIsKeywordOrIdentifier(type)) {
  14620. name = this.state.value;
  14621. } else {
  14622. this.unexpected();
  14623. }
  14624. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  14625. if (liberal) {
  14626. if (tokenIsKeyword) {
  14627. this.replaceToken(132);
  14628. }
  14629. } else {
  14630. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  14631. }
  14632. this.next();
  14633. return name;
  14634. }
  14635. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  14636. if (word.length > 10) {
  14637. return;
  14638. }
  14639. if (!canBeReservedWord(word)) {
  14640. return;
  14641. }
  14642. if (checkKeywords && isKeyword(word)) {
  14643. this.raise(Errors.UnexpectedKeyword, startLoc, {
  14644. keyword: word
  14645. });
  14646. return;
  14647. }
  14648. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  14649. if (reservedTest(word, this.inModule)) {
  14650. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  14651. reservedWord: word
  14652. });
  14653. return;
  14654. } else if (word === "yield") {
  14655. if (this.prodParam.hasYield) {
  14656. this.raise(Errors.YieldBindingIdentifier, startLoc);
  14657. return;
  14658. }
  14659. } else if (word === "await") {
  14660. if (this.prodParam.hasAwait) {
  14661. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  14662. return;
  14663. }
  14664. if (this.scope.inStaticBlock) {
  14665. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  14666. return;
  14667. }
  14668. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  14669. } else if (word === "arguments") {
  14670. if (this.scope.inClassAndNotInNonArrowFunction) {
  14671. this.raise(Errors.ArgumentsInClass, startLoc);
  14672. return;
  14673. }
  14674. }
  14675. }
  14676. recordAwaitIfAllowed() {
  14677. const isAwaitAllowed = this.prodParam.hasAwait;
  14678. if (isAwaitAllowed && !this.scope.inFunction) {
  14679. this.state.hasTopLevelAwait = true;
  14680. }
  14681. return isAwaitAllowed;
  14682. }
  14683. parseAwait(startLoc) {
  14684. const node = this.startNodeAt(startLoc);
  14685. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  14686. if (this.eat(55)) {
  14687. this.raise(Errors.ObsoleteAwaitStar, node);
  14688. }
  14689. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  14690. if (this.isAmbiguousPrefixOrIdentifier()) {
  14691. this.ambiguousScriptDifferentAst = true;
  14692. } else {
  14693. this.sawUnambiguousESM = true;
  14694. }
  14695. }
  14696. if (!this.state.soloAwait) {
  14697. node.argument = this.parseMaybeUnary(null, true);
  14698. }
  14699. return this.finishNode(node, "AwaitExpression");
  14700. }
  14701. isAmbiguousPrefixOrIdentifier() {
  14702. if (this.hasPrecedingLineBreak()) return true;
  14703. const {
  14704. type
  14705. } = this.state;
  14706. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  14707. }
  14708. parseYield(startLoc) {
  14709. const node = this.startNodeAt(startLoc);
  14710. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  14711. let delegating = false;
  14712. let argument = null;
  14713. if (!this.hasPrecedingLineBreak()) {
  14714. delegating = this.eat(55);
  14715. switch (this.state.type) {
  14716. case 13:
  14717. case 140:
  14718. case 8:
  14719. case 11:
  14720. case 3:
  14721. case 9:
  14722. case 14:
  14723. case 12:
  14724. if (!delegating) break;
  14725. default:
  14726. argument = this.parseMaybeAssign();
  14727. }
  14728. }
  14729. node.delegate = delegating;
  14730. node.argument = argument;
  14731. return this.finishNode(node, "YieldExpression");
  14732. }
  14733. parseImportCall(node) {
  14734. this.next();
  14735. node.source = this.parseMaybeAssignAllowIn();
  14736. node.options = null;
  14737. if (this.eat(12)) {
  14738. if (!this.match(11)) {
  14739. node.options = this.parseMaybeAssignAllowIn();
  14740. if (this.eat(12)) {
  14741. this.addTrailingCommaExtraToNode(node.options);
  14742. if (!this.match(11)) {
  14743. do {
  14744. this.parseMaybeAssignAllowIn();
  14745. } while (this.eat(12) && !this.match(11));
  14746. this.raise(Errors.ImportCallArity, node);
  14747. }
  14748. }
  14749. } else {
  14750. this.addTrailingCommaExtraToNode(node.source);
  14751. }
  14752. }
  14753. this.expect(11);
  14754. return this.finishNode(node, "ImportExpression");
  14755. }
  14756. checkPipelineAtInfixOperator(left, leftStartLoc) {
  14757. if (this.hasPlugin(["pipelineOperator", {
  14758. proposal: "smart"
  14759. }])) {
  14760. if (left.type === "SequenceExpression") {
  14761. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  14762. }
  14763. }
  14764. }
  14765. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  14766. if (this.isSimpleReference(childExpr)) {
  14767. const bodyNode = this.startNodeAt(startLoc);
  14768. bodyNode.callee = childExpr;
  14769. return this.finishNode(bodyNode, "PipelineBareFunction");
  14770. } else {
  14771. const bodyNode = this.startNodeAt(startLoc);
  14772. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  14773. bodyNode.expression = childExpr;
  14774. return this.finishNode(bodyNode, "PipelineTopicExpression");
  14775. }
  14776. }
  14777. isSimpleReference(expression) {
  14778. switch (expression.type) {
  14779. case "MemberExpression":
  14780. return !expression.computed && this.isSimpleReference(expression.object);
  14781. case "Identifier":
  14782. return true;
  14783. default:
  14784. return false;
  14785. }
  14786. }
  14787. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  14788. if (this.match(19)) {
  14789. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  14790. }
  14791. if (!this.topicReferenceWasUsedInCurrentContext()) {
  14792. this.raise(Errors.PipelineTopicUnused, startLoc);
  14793. }
  14794. }
  14795. withTopicBindingContext(callback) {
  14796. const outerContextTopicState = this.state.topicContext;
  14797. this.state.topicContext = {
  14798. maxNumOfResolvableTopics: 1,
  14799. maxTopicIndex: null
  14800. };
  14801. try {
  14802. return callback();
  14803. } finally {
  14804. this.state.topicContext = outerContextTopicState;
  14805. }
  14806. }
  14807. withSmartMixTopicForbiddingContext(callback) {
  14808. if (this.hasPlugin(["pipelineOperator", {
  14809. proposal: "smart"
  14810. }])) {
  14811. const outerContextTopicState = this.state.topicContext;
  14812. this.state.topicContext = {
  14813. maxNumOfResolvableTopics: 0,
  14814. maxTopicIndex: null
  14815. };
  14816. try {
  14817. return callback();
  14818. } finally {
  14819. this.state.topicContext = outerContextTopicState;
  14820. }
  14821. } else {
  14822. return callback();
  14823. }
  14824. }
  14825. withSoloAwaitPermittingContext(callback) {
  14826. const outerContextSoloAwaitState = this.state.soloAwait;
  14827. this.state.soloAwait = true;
  14828. try {
  14829. return callback();
  14830. } finally {
  14831. this.state.soloAwait = outerContextSoloAwaitState;
  14832. }
  14833. }
  14834. allowInAnd(callback) {
  14835. const flags = this.prodParam.currentFlags();
  14836. const prodParamToSet = 8 & ~flags;
  14837. if (prodParamToSet) {
  14838. this.prodParam.enter(flags | 8);
  14839. try {
  14840. return callback();
  14841. } finally {
  14842. this.prodParam.exit();
  14843. }
  14844. }
  14845. return callback();
  14846. }
  14847. disallowInAnd(callback) {
  14848. const flags = this.prodParam.currentFlags();
  14849. const prodParamToClear = 8 & flags;
  14850. if (prodParamToClear) {
  14851. this.prodParam.enter(flags & -9);
  14852. try {
  14853. return callback();
  14854. } finally {
  14855. this.prodParam.exit();
  14856. }
  14857. }
  14858. return callback();
  14859. }
  14860. registerTopicReference() {
  14861. this.state.topicContext.maxTopicIndex = 0;
  14862. }
  14863. topicReferenceIsAllowedInCurrentContext() {
  14864. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  14865. }
  14866. topicReferenceWasUsedInCurrentContext() {
  14867. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  14868. }
  14869. parseFSharpPipelineBody(prec) {
  14870. const startLoc = this.state.startLoc;
  14871. this.state.potentialArrowAt = this.state.start;
  14872. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14873. this.state.inFSharpPipelineDirectBody = true;
  14874. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  14875. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14876. return ret;
  14877. }
  14878. parseModuleExpression() {
  14879. this.expectPlugin("moduleBlocks");
  14880. const node = this.startNode();
  14881. this.next();
  14882. if (!this.match(5)) {
  14883. this.unexpected(null, 5);
  14884. }
  14885. const program = this.startNodeAt(this.state.endLoc);
  14886. this.next();
  14887. const revertScopes = this.initializeScopes(true);
  14888. this.enterInitialScopes();
  14889. try {
  14890. node.body = this.parseProgram(program, 8, "module");
  14891. } finally {
  14892. revertScopes();
  14893. }
  14894. return this.finishNode(node, "ModuleExpression");
  14895. }
  14896. parseVoidPattern(refExpressionErrors) {
  14897. this.expectPlugin("discardBinding");
  14898. const node = this.startNode();
  14899. if (refExpressionErrors != null) {
  14900. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  14901. }
  14902. this.next();
  14903. return this.finishNode(node, "VoidPattern");
  14904. }
  14905. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  14906. if (refExpressionErrors != null && this.match(88)) {
  14907. const nextCode = this.lookaheadCharCode();
  14908. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  14909. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  14910. }
  14911. }
  14912. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  14913. }
  14914. parsePropertyNamePrefixOperator(prop) {}
  14915. }
  14916. const loopLabel = {
  14917. kind: 1
  14918. },
  14919. switchLabel = {
  14920. kind: 2
  14921. };
  14922. const loneSurrogate = /[\uD800-\uDFFF]/u;
  14923. const keywordRelationalOperator = /in(?:stanceof)?/y;
  14924. function babel7CompatTokens(tokens, input, startIndex) {
  14925. for (let i = 0; i < tokens.length; i++) {
  14926. const token = tokens[i];
  14927. const {
  14928. type
  14929. } = token;
  14930. if (typeof type === "number") {
  14931. {
  14932. if (type === 139) {
  14933. const {
  14934. loc,
  14935. start,
  14936. value,
  14937. end
  14938. } = token;
  14939. const hashEndPos = start + 1;
  14940. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  14941. tokens.splice(i, 1, new Token({
  14942. type: getExportedToken(27),
  14943. value: "#",
  14944. start: start,
  14945. end: hashEndPos,
  14946. startLoc: loc.start,
  14947. endLoc: hashEndLoc
  14948. }), new Token({
  14949. type: getExportedToken(132),
  14950. value: value,
  14951. start: hashEndPos,
  14952. end: end,
  14953. startLoc: hashEndLoc,
  14954. endLoc: loc.end
  14955. }));
  14956. i++;
  14957. continue;
  14958. }
  14959. if (tokenIsTemplate(type)) {
  14960. const {
  14961. loc,
  14962. start,
  14963. value,
  14964. end
  14965. } = token;
  14966. const backquoteEnd = start + 1;
  14967. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  14968. let startToken;
  14969. if (input.charCodeAt(start - startIndex) === 96) {
  14970. startToken = new Token({
  14971. type: getExportedToken(22),
  14972. value: "`",
  14973. start: start,
  14974. end: backquoteEnd,
  14975. startLoc: loc.start,
  14976. endLoc: backquoteEndLoc
  14977. });
  14978. } else {
  14979. startToken = new Token({
  14980. type: getExportedToken(8),
  14981. value: "}",
  14982. start: start,
  14983. end: backquoteEnd,
  14984. startLoc: loc.start,
  14985. endLoc: backquoteEndLoc
  14986. });
  14987. }
  14988. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  14989. if (type === 24) {
  14990. templateElementEnd = end - 1;
  14991. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  14992. templateValue = value === null ? null : value.slice(1, -1);
  14993. endToken = new Token({
  14994. type: getExportedToken(22),
  14995. value: "`",
  14996. start: templateElementEnd,
  14997. end: end,
  14998. startLoc: templateElementEndLoc,
  14999. endLoc: loc.end
  15000. });
  15001. } else {
  15002. templateElementEnd = end - 2;
  15003. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  15004. templateValue = value === null ? null : value.slice(1, -2);
  15005. endToken = new Token({
  15006. type: getExportedToken(23),
  15007. value: "${",
  15008. start: templateElementEnd,
  15009. end: end,
  15010. startLoc: templateElementEndLoc,
  15011. endLoc: loc.end
  15012. });
  15013. }
  15014. tokens.splice(i, 1, startToken, new Token({
  15015. type: getExportedToken(20),
  15016. value: templateValue,
  15017. start: backquoteEnd,
  15018. end: templateElementEnd,
  15019. startLoc: backquoteEndLoc,
  15020. endLoc: templateElementEndLoc
  15021. }), endToken);
  15022. i += 2;
  15023. continue;
  15024. }
  15025. }
  15026. token.type = getExportedToken(type);
  15027. }
  15028. }
  15029. return tokens;
  15030. }
  15031. class StatementParser extends ExpressionParser {
  15032. parseTopLevel(file, program) {
  15033. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  15034. file.comments = this.comments;
  15035. if (this.optionFlags & 256) {
  15036. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  15037. }
  15038. return this.finishNode(file, "File");
  15039. }
  15040. parseProgram(program, end, sourceType) {
  15041. program.sourceType = sourceType;
  15042. program.interpreter = this.parseInterpreterDirective();
  15043. this.parseBlockBody(program, true, true, end);
  15044. if (this.inModule) {
  15045. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  15046. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  15047. this.raise(Errors.ModuleExportUndefined, at, {
  15048. localName
  15049. });
  15050. }
  15051. }
  15052. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  15053. }
  15054. let finishedProgram;
  15055. if (end === 140) {
  15056. finishedProgram = this.finishNode(program, "Program");
  15057. } else {
  15058. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  15059. }
  15060. return finishedProgram;
  15061. }
  15062. stmtToDirective(stmt) {
  15063. const directive = this.castNodeTo(stmt, "Directive");
  15064. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  15065. const expressionValue = directiveLiteral.value;
  15066. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  15067. const val = directiveLiteral.value = raw.slice(1, -1);
  15068. this.addExtra(directiveLiteral, "raw", raw);
  15069. this.addExtra(directiveLiteral, "rawValue", val);
  15070. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  15071. directive.value = directiveLiteral;
  15072. delete stmt.expression;
  15073. return directive;
  15074. }
  15075. parseInterpreterDirective() {
  15076. if (!this.match(28)) {
  15077. return null;
  15078. }
  15079. const node = this.startNode();
  15080. node.value = this.state.value;
  15081. this.next();
  15082. return this.finishNode(node, "InterpreterDirective");
  15083. }
  15084. isLet() {
  15085. if (!this.isContextual(100)) {
  15086. return false;
  15087. }
  15088. return this.hasFollowingBindingAtom();
  15089. }
  15090. isUsing() {
  15091. if (!this.isContextual(107)) {
  15092. return false;
  15093. }
  15094. const next = this.nextTokenInLineStart();
  15095. const nextCh = this.codePointAtPos(next);
  15096. return this.chStartsBindingIdentifier(nextCh, next);
  15097. }
  15098. isForUsing() {
  15099. if (!this.isContextual(107)) {
  15100. return false;
  15101. }
  15102. const next = this.nextTokenInLineStart();
  15103. const nextCh = this.codePointAtPos(next);
  15104. if (this.isUnparsedContextual(next, "of")) {
  15105. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  15106. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  15107. return false;
  15108. }
  15109. }
  15110. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  15111. return true;
  15112. }
  15113. return false;
  15114. }
  15115. isAwaitUsing() {
  15116. if (!this.isContextual(96)) {
  15117. return false;
  15118. }
  15119. let next = this.nextTokenInLineStart();
  15120. if (this.isUnparsedContextual(next, "using")) {
  15121. next = this.nextTokenInLineStartSince(next + 5);
  15122. const nextCh = this.codePointAtPos(next);
  15123. if (this.chStartsBindingIdentifier(nextCh, next)) {
  15124. return true;
  15125. }
  15126. }
  15127. return false;
  15128. }
  15129. chStartsBindingIdentifier(ch, pos) {
  15130. if (isIdentifierStart(ch)) {
  15131. keywordRelationalOperator.lastIndex = pos;
  15132. if (keywordRelationalOperator.test(this.input)) {
  15133. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  15134. if (!isIdentifierChar(endCh) && endCh !== 92) {
  15135. return false;
  15136. }
  15137. }
  15138. return true;
  15139. } else if (ch === 92) {
  15140. return true;
  15141. } else {
  15142. return false;
  15143. }
  15144. }
  15145. chStartsBindingPattern(ch) {
  15146. return ch === 91 || ch === 123;
  15147. }
  15148. hasFollowingBindingAtom() {
  15149. const next = this.nextTokenStart();
  15150. const nextCh = this.codePointAtPos(next);
  15151. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  15152. }
  15153. hasInLineFollowingBindingIdentifierOrBrace() {
  15154. const next = this.nextTokenInLineStart();
  15155. const nextCh = this.codePointAtPos(next);
  15156. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  15157. }
  15158. allowsUsing() {
  15159. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  15160. }
  15161. parseModuleItem() {
  15162. return this.parseStatementLike(1 | 2 | 4 | 8);
  15163. }
  15164. parseStatementListItem() {
  15165. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  15166. }
  15167. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  15168. let flags = 0;
  15169. if (this.options.annexB && !this.state.strict) {
  15170. flags |= 4;
  15171. if (allowLabeledFunction) {
  15172. flags |= 8;
  15173. }
  15174. }
  15175. return this.parseStatementLike(flags);
  15176. }
  15177. parseStatement() {
  15178. return this.parseStatementLike(0);
  15179. }
  15180. parseStatementLike(flags) {
  15181. let decorators = null;
  15182. if (this.match(26)) {
  15183. decorators = this.parseDecorators(true);
  15184. }
  15185. return this.parseStatementContent(flags, decorators);
  15186. }
  15187. parseStatementContent(flags, decorators) {
  15188. const startType = this.state.type;
  15189. const node = this.startNode();
  15190. const allowDeclaration = !!(flags & 2);
  15191. const allowFunctionDeclaration = !!(flags & 4);
  15192. const topLevel = flags & 1;
  15193. switch (startType) {
  15194. case 60:
  15195. return this.parseBreakContinueStatement(node, true);
  15196. case 63:
  15197. return this.parseBreakContinueStatement(node, false);
  15198. case 64:
  15199. return this.parseDebuggerStatement(node);
  15200. case 90:
  15201. return this.parseDoWhileStatement(node);
  15202. case 91:
  15203. return this.parseForStatement(node);
  15204. case 68:
  15205. if (this.lookaheadCharCode() === 46) break;
  15206. if (!allowFunctionDeclaration) {
  15207. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  15208. }
  15209. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  15210. case 80:
  15211. if (!allowDeclaration) this.unexpected();
  15212. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  15213. case 69:
  15214. return this.parseIfStatement(node);
  15215. case 70:
  15216. return this.parseReturnStatement(node);
  15217. case 71:
  15218. return this.parseSwitchStatement(node);
  15219. case 72:
  15220. return this.parseThrowStatement(node);
  15221. case 73:
  15222. return this.parseTryStatement(node);
  15223. case 96:
  15224. if (this.isAwaitUsing()) {
  15225. if (!this.allowsUsing()) {
  15226. this.raise(Errors.UnexpectedUsingDeclaration, node);
  15227. } else if (!allowDeclaration) {
  15228. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  15229. } else if (!this.recordAwaitIfAllowed()) {
  15230. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  15231. }
  15232. this.next();
  15233. return this.parseVarStatement(node, "await using");
  15234. }
  15235. break;
  15236. case 107:
  15237. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  15238. break;
  15239. }
  15240. if (!this.allowsUsing()) {
  15241. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  15242. } else if (!allowDeclaration) {
  15243. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  15244. }
  15245. return this.parseVarStatement(node, "using");
  15246. case 100:
  15247. {
  15248. if (this.state.containsEsc) {
  15249. break;
  15250. }
  15251. const next = this.nextTokenStart();
  15252. const nextCh = this.codePointAtPos(next);
  15253. if (nextCh !== 91) {
  15254. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  15255. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  15256. break;
  15257. }
  15258. }
  15259. }
  15260. case 75:
  15261. {
  15262. if (!allowDeclaration) {
  15263. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  15264. }
  15265. }
  15266. case 74:
  15267. {
  15268. const kind = this.state.value;
  15269. return this.parseVarStatement(node, kind);
  15270. }
  15271. case 92:
  15272. return this.parseWhileStatement(node);
  15273. case 76:
  15274. return this.parseWithStatement(node);
  15275. case 5:
  15276. return this.parseBlock();
  15277. case 13:
  15278. return this.parseEmptyStatement(node);
  15279. case 83:
  15280. {
  15281. const nextTokenCharCode = this.lookaheadCharCode();
  15282. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  15283. break;
  15284. }
  15285. }
  15286. case 82:
  15287. {
  15288. if (!(this.optionFlags & 8) && !topLevel) {
  15289. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  15290. }
  15291. this.next();
  15292. let result;
  15293. if (startType === 83) {
  15294. result = this.parseImport(node);
  15295. } else {
  15296. result = this.parseExport(node, decorators);
  15297. }
  15298. this.assertModuleNodeAllowed(result);
  15299. return result;
  15300. }
  15301. default:
  15302. {
  15303. if (this.isAsyncFunction()) {
  15304. if (!allowDeclaration) {
  15305. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  15306. }
  15307. this.next();
  15308. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  15309. }
  15310. }
  15311. }
  15312. const maybeName = this.state.value;
  15313. const expr = this.parseExpression();
  15314. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  15315. return this.parseLabeledStatement(node, maybeName, expr, flags);
  15316. } else {
  15317. return this.parseExpressionStatement(node, expr, decorators);
  15318. }
  15319. }
  15320. assertModuleNodeAllowed(node) {
  15321. if (!(this.optionFlags & 8) && !this.inModule) {
  15322. this.raise(Errors.ImportOutsideModule, node);
  15323. }
  15324. }
  15325. decoratorsEnabledBeforeExport() {
  15326. if (this.hasPlugin("decorators-legacy")) return true;
  15327. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  15328. }
  15329. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  15330. if (maybeDecorators) {
  15331. var _classNode$decorators;
  15332. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  15333. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  15334. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  15335. }
  15336. classNode.decorators.unshift(...maybeDecorators);
  15337. } else {
  15338. classNode.decorators = maybeDecorators;
  15339. }
  15340. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  15341. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  15342. }
  15343. return classNode;
  15344. }
  15345. canHaveLeadingDecorator() {
  15346. return this.match(80);
  15347. }
  15348. parseDecorators(allowExport) {
  15349. const decorators = [];
  15350. do {
  15351. decorators.push(this.parseDecorator());
  15352. } while (this.match(26));
  15353. if (this.match(82)) {
  15354. if (!allowExport) {
  15355. this.unexpected();
  15356. }
  15357. if (!this.decoratorsEnabledBeforeExport()) {
  15358. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  15359. }
  15360. } else if (!this.canHaveLeadingDecorator()) {
  15361. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  15362. }
  15363. return decorators;
  15364. }
  15365. parseDecorator() {
  15366. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  15367. const node = this.startNode();
  15368. this.next();
  15369. if (this.hasPlugin("decorators")) {
  15370. const startLoc = this.state.startLoc;
  15371. let expr;
  15372. if (this.match(10)) {
  15373. const startLoc = this.state.startLoc;
  15374. this.next();
  15375. expr = this.parseExpression();
  15376. this.expect(11);
  15377. expr = this.wrapParenthesis(startLoc, expr);
  15378. const paramsStartLoc = this.state.startLoc;
  15379. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  15380. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  15381. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  15382. }
  15383. } else {
  15384. expr = this.parseIdentifier(false);
  15385. while (this.eat(16)) {
  15386. const node = this.startNodeAt(startLoc);
  15387. node.object = expr;
  15388. if (this.match(139)) {
  15389. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  15390. node.property = this.parsePrivateName();
  15391. } else {
  15392. node.property = this.parseIdentifier(true);
  15393. }
  15394. node.computed = false;
  15395. expr = this.finishNode(node, "MemberExpression");
  15396. }
  15397. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  15398. }
  15399. } else {
  15400. node.expression = this.parseExprSubscripts();
  15401. }
  15402. return this.finishNode(node, "Decorator");
  15403. }
  15404. parseMaybeDecoratorArguments(expr, startLoc) {
  15405. if (this.eat(10)) {
  15406. const node = this.startNodeAt(startLoc);
  15407. node.callee = expr;
  15408. node.arguments = this.parseCallExpressionArguments();
  15409. this.toReferencedList(node.arguments);
  15410. return this.finishNode(node, "CallExpression");
  15411. }
  15412. return expr;
  15413. }
  15414. parseBreakContinueStatement(node, isBreak) {
  15415. this.next();
  15416. if (this.isLineTerminator()) {
  15417. node.label = null;
  15418. } else {
  15419. node.label = this.parseIdentifier();
  15420. this.semicolon();
  15421. }
  15422. this.verifyBreakContinue(node, isBreak);
  15423. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  15424. }
  15425. verifyBreakContinue(node, isBreak) {
  15426. let i;
  15427. for (i = 0; i < this.state.labels.length; ++i) {
  15428. const lab = this.state.labels[i];
  15429. if (node.label == null || lab.name === node.label.name) {
  15430. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  15431. break;
  15432. }
  15433. if (node.label && isBreak) break;
  15434. }
  15435. }
  15436. if (i === this.state.labels.length) {
  15437. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  15438. this.raise(Errors.IllegalBreakContinue, node, {
  15439. type
  15440. });
  15441. }
  15442. }
  15443. parseDebuggerStatement(node) {
  15444. this.next();
  15445. this.semicolon();
  15446. return this.finishNode(node, "DebuggerStatement");
  15447. }
  15448. parseHeaderExpression() {
  15449. this.expect(10);
  15450. const val = this.parseExpression();
  15451. this.expect(11);
  15452. return val;
  15453. }
  15454. parseDoWhileStatement(node) {
  15455. this.next();
  15456. this.state.labels.push(loopLabel);
  15457. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15458. this.state.labels.pop();
  15459. this.expect(92);
  15460. node.test = this.parseHeaderExpression();
  15461. this.eat(13);
  15462. return this.finishNode(node, "DoWhileStatement");
  15463. }
  15464. parseForStatement(node) {
  15465. this.next();
  15466. this.state.labels.push(loopLabel);
  15467. let awaitAt = null;
  15468. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  15469. awaitAt = this.state.startLoc;
  15470. this.next();
  15471. }
  15472. this.scope.enter(0);
  15473. this.expect(10);
  15474. if (this.match(13)) {
  15475. if (awaitAt !== null) {
  15476. this.unexpected(awaitAt);
  15477. }
  15478. return this.parseFor(node, null);
  15479. }
  15480. const startsWithLet = this.isContextual(100);
  15481. {
  15482. const startsWithAwaitUsing = this.isAwaitUsing();
  15483. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  15484. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  15485. if (this.match(74) || this.match(75) || isLetOrUsing) {
  15486. const initNode = this.startNode();
  15487. let kind;
  15488. if (startsWithAwaitUsing) {
  15489. kind = "await using";
  15490. if (!this.recordAwaitIfAllowed()) {
  15491. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  15492. }
  15493. this.next();
  15494. } else {
  15495. kind = this.state.value;
  15496. }
  15497. this.next();
  15498. this.parseVar(initNode, true, kind);
  15499. const init = this.finishNode(initNode, "VariableDeclaration");
  15500. const isForIn = this.match(58);
  15501. if (isForIn && starsWithUsingDeclaration) {
  15502. this.raise(Errors.ForInUsing, init);
  15503. }
  15504. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  15505. return this.parseForIn(node, init, awaitAt);
  15506. }
  15507. if (awaitAt !== null) {
  15508. this.unexpected(awaitAt);
  15509. }
  15510. return this.parseFor(node, init);
  15511. }
  15512. }
  15513. const startsWithAsync = this.isContextual(95);
  15514. const refExpressionErrors = new ExpressionErrors();
  15515. const init = this.parseExpression(true, refExpressionErrors);
  15516. const isForOf = this.isContextual(102);
  15517. if (isForOf) {
  15518. if (startsWithLet) {
  15519. this.raise(Errors.ForOfLet, init);
  15520. }
  15521. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  15522. this.raise(Errors.ForOfAsync, init);
  15523. }
  15524. }
  15525. if (isForOf || this.match(58)) {
  15526. this.checkDestructuringPrivate(refExpressionErrors);
  15527. this.toAssignable(init, true);
  15528. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  15529. this.checkLVal(init, {
  15530. type
  15531. });
  15532. return this.parseForIn(node, init, awaitAt);
  15533. } else {
  15534. this.checkExpressionErrors(refExpressionErrors, true);
  15535. }
  15536. if (awaitAt !== null) {
  15537. this.unexpected(awaitAt);
  15538. }
  15539. return this.parseFor(node, init);
  15540. }
  15541. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  15542. this.next();
  15543. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  15544. }
  15545. parseIfStatement(node) {
  15546. this.next();
  15547. node.test = this.parseHeaderExpression();
  15548. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  15549. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  15550. return this.finishNode(node, "IfStatement");
  15551. }
  15552. parseReturnStatement(node) {
  15553. if (!this.prodParam.hasReturn) {
  15554. this.raise(Errors.IllegalReturn, this.state.startLoc);
  15555. }
  15556. this.next();
  15557. if (this.isLineTerminator()) {
  15558. node.argument = null;
  15559. } else {
  15560. node.argument = this.parseExpression();
  15561. this.semicolon();
  15562. }
  15563. return this.finishNode(node, "ReturnStatement");
  15564. }
  15565. parseSwitchStatement(node) {
  15566. this.next();
  15567. node.discriminant = this.parseHeaderExpression();
  15568. const cases = node.cases = [];
  15569. this.expect(5);
  15570. this.state.labels.push(switchLabel);
  15571. this.scope.enter(256);
  15572. let cur;
  15573. for (let sawDefault; !this.match(8);) {
  15574. if (this.match(61) || this.match(65)) {
  15575. const isCase = this.match(61);
  15576. if (cur) this.finishNode(cur, "SwitchCase");
  15577. cases.push(cur = this.startNode());
  15578. cur.consequent = [];
  15579. this.next();
  15580. if (isCase) {
  15581. cur.test = this.parseExpression();
  15582. } else {
  15583. if (sawDefault) {
  15584. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  15585. }
  15586. sawDefault = true;
  15587. cur.test = null;
  15588. }
  15589. this.expect(14);
  15590. } else {
  15591. if (cur) {
  15592. cur.consequent.push(this.parseStatementListItem());
  15593. } else {
  15594. this.unexpected();
  15595. }
  15596. }
  15597. }
  15598. this.scope.exit();
  15599. if (cur) this.finishNode(cur, "SwitchCase");
  15600. this.next();
  15601. this.state.labels.pop();
  15602. return this.finishNode(node, "SwitchStatement");
  15603. }
  15604. parseThrowStatement(node) {
  15605. this.next();
  15606. if (this.hasPrecedingLineBreak()) {
  15607. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  15608. }
  15609. node.argument = this.parseExpression();
  15610. this.semicolon();
  15611. return this.finishNode(node, "ThrowStatement");
  15612. }
  15613. parseCatchClauseParam() {
  15614. const param = this.parseBindingAtom();
  15615. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  15616. this.checkLVal(param, {
  15617. type: "CatchClause"
  15618. }, 9);
  15619. return param;
  15620. }
  15621. parseTryStatement(node) {
  15622. this.next();
  15623. node.block = this.parseBlock();
  15624. node.handler = null;
  15625. if (this.match(62)) {
  15626. const clause = this.startNode();
  15627. this.next();
  15628. if (this.match(10)) {
  15629. this.expect(10);
  15630. clause.param = this.parseCatchClauseParam();
  15631. this.expect(11);
  15632. } else {
  15633. clause.param = null;
  15634. this.scope.enter(0);
  15635. }
  15636. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  15637. this.scope.exit();
  15638. node.handler = this.finishNode(clause, "CatchClause");
  15639. }
  15640. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  15641. if (!node.handler && !node.finalizer) {
  15642. this.raise(Errors.NoCatchOrFinally, node);
  15643. }
  15644. return this.finishNode(node, "TryStatement");
  15645. }
  15646. parseVarStatement(node, kind, allowMissingInitializer = false) {
  15647. this.next();
  15648. this.parseVar(node, false, kind, allowMissingInitializer);
  15649. this.semicolon();
  15650. return this.finishNode(node, "VariableDeclaration");
  15651. }
  15652. parseWhileStatement(node) {
  15653. this.next();
  15654. node.test = this.parseHeaderExpression();
  15655. this.state.labels.push(loopLabel);
  15656. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15657. this.state.labels.pop();
  15658. return this.finishNode(node, "WhileStatement");
  15659. }
  15660. parseWithStatement(node) {
  15661. if (this.state.strict) {
  15662. this.raise(Errors.StrictWith, this.state.startLoc);
  15663. }
  15664. this.next();
  15665. node.object = this.parseHeaderExpression();
  15666. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15667. return this.finishNode(node, "WithStatement");
  15668. }
  15669. parseEmptyStatement(node) {
  15670. this.next();
  15671. return this.finishNode(node, "EmptyStatement");
  15672. }
  15673. parseLabeledStatement(node, maybeName, expr, flags) {
  15674. for (const label of this.state.labels) {
  15675. if (label.name === maybeName) {
  15676. this.raise(Errors.LabelRedeclaration, expr, {
  15677. labelName: maybeName
  15678. });
  15679. }
  15680. }
  15681. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  15682. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  15683. const label = this.state.labels[i];
  15684. if (label.statementStart === node.start) {
  15685. label.statementStart = this.sourceToOffsetPos(this.state.start);
  15686. label.kind = kind;
  15687. } else {
  15688. break;
  15689. }
  15690. }
  15691. this.state.labels.push({
  15692. name: maybeName,
  15693. kind: kind,
  15694. statementStart: this.sourceToOffsetPos(this.state.start)
  15695. });
  15696. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  15697. this.state.labels.pop();
  15698. node.label = expr;
  15699. return this.finishNode(node, "LabeledStatement");
  15700. }
  15701. parseExpressionStatement(node, expr, decorators) {
  15702. node.expression = expr;
  15703. this.semicolon();
  15704. return this.finishNode(node, "ExpressionStatement");
  15705. }
  15706. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  15707. const node = this.startNode();
  15708. if (allowDirectives) {
  15709. this.state.strictErrors.clear();
  15710. }
  15711. this.expect(5);
  15712. if (createNewLexicalScope) {
  15713. this.scope.enter(0);
  15714. }
  15715. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  15716. if (createNewLexicalScope) {
  15717. this.scope.exit();
  15718. }
  15719. return this.finishNode(node, "BlockStatement");
  15720. }
  15721. isValidDirective(stmt) {
  15722. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  15723. }
  15724. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  15725. const body = node.body = [];
  15726. const directives = node.directives = [];
  15727. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  15728. }
  15729. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  15730. const oldStrict = this.state.strict;
  15731. let hasStrictModeDirective = false;
  15732. let parsedNonDirective = false;
  15733. while (!this.match(end)) {
  15734. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  15735. if (directives && !parsedNonDirective) {
  15736. if (this.isValidDirective(stmt)) {
  15737. const directive = this.stmtToDirective(stmt);
  15738. directives.push(directive);
  15739. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  15740. hasStrictModeDirective = true;
  15741. this.setStrict(true);
  15742. }
  15743. continue;
  15744. }
  15745. parsedNonDirective = true;
  15746. this.state.strictErrors.clear();
  15747. }
  15748. body.push(stmt);
  15749. }
  15750. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  15751. if (!oldStrict) {
  15752. this.setStrict(false);
  15753. }
  15754. this.next();
  15755. }
  15756. parseFor(node, init) {
  15757. node.init = init;
  15758. this.semicolon(false);
  15759. node.test = this.match(13) ? null : this.parseExpression();
  15760. this.semicolon(false);
  15761. node.update = this.match(11) ? null : this.parseExpression();
  15762. this.expect(11);
  15763. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15764. this.scope.exit();
  15765. this.state.labels.pop();
  15766. return this.finishNode(node, "ForStatement");
  15767. }
  15768. parseForIn(node, init, awaitAt) {
  15769. const isForIn = this.match(58);
  15770. this.next();
  15771. if (isForIn) {
  15772. if (awaitAt !== null) this.unexpected(awaitAt);
  15773. } else {
  15774. node.await = awaitAt !== null;
  15775. }
  15776. 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")) {
  15777. this.raise(Errors.ForInOfLoopInitializer, init, {
  15778. type: isForIn ? "ForInStatement" : "ForOfStatement"
  15779. });
  15780. }
  15781. if (init.type === "AssignmentPattern") {
  15782. this.raise(Errors.InvalidLhs, init, {
  15783. ancestor: {
  15784. type: "ForStatement"
  15785. }
  15786. });
  15787. }
  15788. node.left = init;
  15789. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  15790. this.expect(11);
  15791. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15792. this.scope.exit();
  15793. this.state.labels.pop();
  15794. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  15795. }
  15796. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  15797. const declarations = node.declarations = [];
  15798. node.kind = kind;
  15799. for (;;) {
  15800. const decl = this.startNode();
  15801. this.parseVarId(decl, kind);
  15802. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  15803. if (decl.init === null && !allowMissingInitializer) {
  15804. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  15805. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  15806. kind: "destructuring"
  15807. });
  15808. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  15809. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  15810. kind
  15811. });
  15812. }
  15813. }
  15814. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  15815. if (!this.eat(12)) break;
  15816. }
  15817. return node;
  15818. }
  15819. parseVarId(decl, kind) {
  15820. const id = this.parseBindingAtom();
  15821. if (kind === "using" || kind === "await using") {
  15822. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  15823. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  15824. }
  15825. } else {
  15826. if (id.type === "VoidPattern") {
  15827. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  15828. }
  15829. }
  15830. this.checkLVal(id, {
  15831. type: "VariableDeclarator"
  15832. }, kind === "var" ? 5 : 8201);
  15833. decl.id = id;
  15834. }
  15835. parseAsyncFunctionExpression(node) {
  15836. return this.parseFunction(node, 8);
  15837. }
  15838. parseFunction(node, flags = 0) {
  15839. const hangingDeclaration = flags & 2;
  15840. const isDeclaration = !!(flags & 1);
  15841. const requireId = isDeclaration && !(flags & 4);
  15842. const isAsync = !!(flags & 8);
  15843. this.initFunction(node, isAsync);
  15844. if (this.match(55)) {
  15845. if (hangingDeclaration) {
  15846. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  15847. }
  15848. this.next();
  15849. node.generator = true;
  15850. }
  15851. if (isDeclaration) {
  15852. node.id = this.parseFunctionId(requireId);
  15853. }
  15854. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15855. this.state.maybeInArrowParameters = false;
  15856. this.scope.enter(514);
  15857. this.prodParam.enter(functionFlags(isAsync, node.generator));
  15858. if (!isDeclaration) {
  15859. node.id = this.parseFunctionId();
  15860. }
  15861. this.parseFunctionParams(node, false);
  15862. this.withSmartMixTopicForbiddingContext(() => {
  15863. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  15864. });
  15865. this.prodParam.exit();
  15866. this.scope.exit();
  15867. if (isDeclaration && !hangingDeclaration) {
  15868. this.registerFunctionStatementId(node);
  15869. }
  15870. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15871. return node;
  15872. }
  15873. parseFunctionId(requireId) {
  15874. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  15875. }
  15876. parseFunctionParams(node, isConstructor) {
  15877. this.expect(10);
  15878. this.expressionScope.enter(newParameterDeclarationScope());
  15879. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  15880. this.expressionScope.exit();
  15881. }
  15882. registerFunctionStatementId(node) {
  15883. if (!node.id) return;
  15884. 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);
  15885. }
  15886. parseClass(node, isStatement, optionalId) {
  15887. this.next();
  15888. const oldStrict = this.state.strict;
  15889. this.state.strict = true;
  15890. this.parseClassId(node, isStatement, optionalId);
  15891. this.parseClassSuper(node);
  15892. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  15893. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  15894. }
  15895. isClassProperty() {
  15896. return this.match(29) || this.match(13) || this.match(8);
  15897. }
  15898. isClassMethod() {
  15899. return this.match(10);
  15900. }
  15901. nameIsConstructor(key) {
  15902. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  15903. }
  15904. isNonstaticConstructor(method) {
  15905. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  15906. }
  15907. parseClassBody(hadSuperClass, oldStrict) {
  15908. this.classScope.enter();
  15909. const state = {
  15910. hadConstructor: false,
  15911. hadSuperClass
  15912. };
  15913. let decorators = [];
  15914. const classBody = this.startNode();
  15915. classBody.body = [];
  15916. this.expect(5);
  15917. this.withSmartMixTopicForbiddingContext(() => {
  15918. while (!this.match(8)) {
  15919. if (this.eat(13)) {
  15920. if (decorators.length > 0) {
  15921. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  15922. }
  15923. continue;
  15924. }
  15925. if (this.match(26)) {
  15926. decorators.push(this.parseDecorator());
  15927. continue;
  15928. }
  15929. const member = this.startNode();
  15930. if (decorators.length) {
  15931. member.decorators = decorators;
  15932. this.resetStartLocationFromNode(member, decorators[0]);
  15933. decorators = [];
  15934. }
  15935. this.parseClassMember(classBody, member, state);
  15936. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  15937. this.raise(Errors.DecoratorConstructor, member);
  15938. }
  15939. }
  15940. });
  15941. this.state.strict = oldStrict;
  15942. this.next();
  15943. if (decorators.length) {
  15944. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  15945. }
  15946. this.classScope.exit();
  15947. return this.finishNode(classBody, "ClassBody");
  15948. }
  15949. parseClassMemberFromModifier(classBody, member) {
  15950. const key = this.parseIdentifier(true);
  15951. if (this.isClassMethod()) {
  15952. const method = member;
  15953. method.kind = "method";
  15954. method.computed = false;
  15955. method.key = key;
  15956. method.static = false;
  15957. this.pushClassMethod(classBody, method, false, false, false, false);
  15958. return true;
  15959. } else if (this.isClassProperty()) {
  15960. const prop = member;
  15961. prop.computed = false;
  15962. prop.key = key;
  15963. prop.static = false;
  15964. classBody.body.push(this.parseClassProperty(prop));
  15965. return true;
  15966. }
  15967. this.resetPreviousNodeTrailingComments(key);
  15968. return false;
  15969. }
  15970. parseClassMember(classBody, member, state) {
  15971. const isStatic = this.isContextual(106);
  15972. if (isStatic) {
  15973. if (this.parseClassMemberFromModifier(classBody, member)) {
  15974. return;
  15975. }
  15976. if (this.eat(5)) {
  15977. this.parseClassStaticBlock(classBody, member);
  15978. return;
  15979. }
  15980. }
  15981. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  15982. }
  15983. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  15984. const publicMethod = member;
  15985. const privateMethod = member;
  15986. const publicProp = member;
  15987. const privateProp = member;
  15988. const accessorProp = member;
  15989. const method = publicMethod;
  15990. const publicMember = publicMethod;
  15991. member.static = isStatic;
  15992. this.parsePropertyNamePrefixOperator(member);
  15993. if (this.eat(55)) {
  15994. method.kind = "method";
  15995. const isPrivateName = this.match(139);
  15996. this.parseClassElementName(method);
  15997. this.parsePostMemberNameModifiers(method);
  15998. if (isPrivateName) {
  15999. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  16000. return;
  16001. }
  16002. if (this.isNonstaticConstructor(publicMethod)) {
  16003. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  16004. }
  16005. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  16006. return;
  16007. }
  16008. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  16009. const key = this.parseClassElementName(member);
  16010. const maybeContextualKw = isContextual ? key.name : null;
  16011. const isPrivate = this.isPrivateName(key);
  16012. const maybeQuestionTokenStartLoc = this.state.startLoc;
  16013. this.parsePostMemberNameModifiers(publicMember);
  16014. if (this.isClassMethod()) {
  16015. method.kind = "method";
  16016. if (isPrivate) {
  16017. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  16018. return;
  16019. }
  16020. const isConstructor = this.isNonstaticConstructor(publicMethod);
  16021. let allowsDirectSuper = false;
  16022. if (isConstructor) {
  16023. publicMethod.kind = "constructor";
  16024. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  16025. this.raise(Errors.DuplicateConstructor, key);
  16026. }
  16027. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  16028. this.raise(Errors.OverrideOnConstructor, key);
  16029. }
  16030. state.hadConstructor = true;
  16031. allowsDirectSuper = state.hadSuperClass;
  16032. }
  16033. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  16034. } else if (this.isClassProperty()) {
  16035. if (isPrivate) {
  16036. this.pushClassPrivateProperty(classBody, privateProp);
  16037. } else {
  16038. this.pushClassProperty(classBody, publicProp);
  16039. }
  16040. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  16041. this.resetPreviousNodeTrailingComments(key);
  16042. const isGenerator = this.eat(55);
  16043. if (publicMember.optional) {
  16044. this.unexpected(maybeQuestionTokenStartLoc);
  16045. }
  16046. method.kind = "method";
  16047. const isPrivate = this.match(139);
  16048. this.parseClassElementName(method);
  16049. this.parsePostMemberNameModifiers(publicMember);
  16050. if (isPrivate) {
  16051. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  16052. } else {
  16053. if (this.isNonstaticConstructor(publicMethod)) {
  16054. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  16055. }
  16056. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  16057. }
  16058. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  16059. this.resetPreviousNodeTrailingComments(key);
  16060. method.kind = maybeContextualKw;
  16061. const isPrivate = this.match(139);
  16062. this.parseClassElementName(publicMethod);
  16063. if (isPrivate) {
  16064. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  16065. } else {
  16066. if (this.isNonstaticConstructor(publicMethod)) {
  16067. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  16068. }
  16069. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  16070. }
  16071. this.checkGetterSetterParams(publicMethod);
  16072. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  16073. this.expectPlugin("decoratorAutoAccessors");
  16074. this.resetPreviousNodeTrailingComments(key);
  16075. const isPrivate = this.match(139);
  16076. this.parseClassElementName(publicProp);
  16077. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  16078. } else if (this.isLineTerminator()) {
  16079. if (isPrivate) {
  16080. this.pushClassPrivateProperty(classBody, privateProp);
  16081. } else {
  16082. this.pushClassProperty(classBody, publicProp);
  16083. }
  16084. } else {
  16085. this.unexpected();
  16086. }
  16087. }
  16088. parseClassElementName(member) {
  16089. const {
  16090. type,
  16091. value
  16092. } = this.state;
  16093. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  16094. this.raise(Errors.StaticPrototype, this.state.startLoc);
  16095. }
  16096. if (type === 139) {
  16097. if (value === "constructor") {
  16098. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  16099. }
  16100. const key = this.parsePrivateName();
  16101. member.key = key;
  16102. return key;
  16103. }
  16104. this.parsePropertyName(member);
  16105. return member.key;
  16106. }
  16107. parseClassStaticBlock(classBody, member) {
  16108. var _member$decorators;
  16109. this.scope.enter(576 | 128 | 16);
  16110. const oldLabels = this.state.labels;
  16111. this.state.labels = [];
  16112. this.prodParam.enter(0);
  16113. const body = member.body = [];
  16114. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  16115. this.prodParam.exit();
  16116. this.scope.exit();
  16117. this.state.labels = oldLabels;
  16118. classBody.body.push(this.finishNode(member, "StaticBlock"));
  16119. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  16120. this.raise(Errors.DecoratorStaticBlock, member);
  16121. }
  16122. }
  16123. pushClassProperty(classBody, prop) {
  16124. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  16125. this.raise(Errors.ConstructorClassField, prop.key);
  16126. }
  16127. classBody.body.push(this.parseClassProperty(prop));
  16128. }
  16129. pushClassPrivateProperty(classBody, prop) {
  16130. const node = this.parseClassPrivateProperty(prop);
  16131. classBody.body.push(node);
  16132. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  16133. }
  16134. pushClassAccessorProperty(classBody, prop, isPrivate) {
  16135. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  16136. this.raise(Errors.ConstructorClassField, prop.key);
  16137. }
  16138. const node = this.parseClassAccessorProperty(prop);
  16139. classBody.body.push(node);
  16140. if (isPrivate) {
  16141. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  16142. }
  16143. }
  16144. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  16145. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  16146. }
  16147. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  16148. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  16149. classBody.body.push(node);
  16150. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  16151. this.declareClassPrivateMethodInScope(node, kind);
  16152. }
  16153. declareClassPrivateMethodInScope(node, kind) {
  16154. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  16155. }
  16156. parsePostMemberNameModifiers(methodOrProp) {}
  16157. parseClassPrivateProperty(node) {
  16158. this.parseInitializer(node);
  16159. this.semicolon();
  16160. return this.finishNode(node, "ClassPrivateProperty");
  16161. }
  16162. parseClassProperty(node) {
  16163. this.parseInitializer(node);
  16164. this.semicolon();
  16165. return this.finishNode(node, "ClassProperty");
  16166. }
  16167. parseClassAccessorProperty(node) {
  16168. this.parseInitializer(node);
  16169. this.semicolon();
  16170. return this.finishNode(node, "ClassAccessorProperty");
  16171. }
  16172. parseInitializer(node) {
  16173. this.scope.enter(576 | 16);
  16174. this.expressionScope.enter(newExpressionScope());
  16175. this.prodParam.enter(0);
  16176. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  16177. this.expressionScope.exit();
  16178. this.prodParam.exit();
  16179. this.scope.exit();
  16180. }
  16181. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  16182. if (tokenIsIdentifier(this.state.type)) {
  16183. node.id = this.parseIdentifier();
  16184. if (isStatement) {
  16185. this.declareNameFromIdentifier(node.id, bindingType);
  16186. }
  16187. } else {
  16188. if (optionalId || !isStatement) {
  16189. node.id = null;
  16190. } else {
  16191. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  16192. }
  16193. }
  16194. }
  16195. parseClassSuper(node) {
  16196. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  16197. }
  16198. parseExport(node, decorators) {
  16199. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  16200. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  16201. const parseAfterDefault = !hasDefault || this.eat(12);
  16202. const hasStar = parseAfterDefault && this.eatExportStar(node);
  16203. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  16204. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  16205. const isFromRequired = hasDefault || hasStar;
  16206. if (hasStar && !hasNamespace) {
  16207. if (hasDefault) this.unexpected();
  16208. if (decorators) {
  16209. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16210. }
  16211. this.parseExportFrom(node, true);
  16212. this.sawUnambiguousESM = true;
  16213. return this.finishNode(node, "ExportAllDeclaration");
  16214. }
  16215. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  16216. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  16217. this.unexpected(null, 5);
  16218. }
  16219. if (hasNamespace && parseAfterNamespace) {
  16220. this.unexpected(null, 98);
  16221. }
  16222. let hasDeclaration;
  16223. if (isFromRequired || hasSpecifiers) {
  16224. hasDeclaration = false;
  16225. if (decorators) {
  16226. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16227. }
  16228. this.parseExportFrom(node, isFromRequired);
  16229. } else {
  16230. hasDeclaration = this.maybeParseExportDeclaration(node);
  16231. }
  16232. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  16233. var _node2$declaration;
  16234. const node2 = node;
  16235. this.checkExport(node2, true, false, !!node2.source);
  16236. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  16237. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  16238. } else if (decorators) {
  16239. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16240. }
  16241. this.sawUnambiguousESM = true;
  16242. return this.finishNode(node2, "ExportNamedDeclaration");
  16243. }
  16244. if (this.eat(65)) {
  16245. const node2 = node;
  16246. const decl = this.parseExportDefaultExpression();
  16247. node2.declaration = decl;
  16248. if (decl.type === "ClassDeclaration") {
  16249. this.maybeTakeDecorators(decorators, decl, node2);
  16250. } else if (decorators) {
  16251. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16252. }
  16253. this.checkExport(node2, true, true);
  16254. this.sawUnambiguousESM = true;
  16255. return this.finishNode(node2, "ExportDefaultDeclaration");
  16256. }
  16257. this.unexpected(null, 5);
  16258. }
  16259. eatExportStar(node) {
  16260. return this.eat(55);
  16261. }
  16262. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  16263. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  16264. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  16265. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  16266. const specifier = this.startNodeAtNode(id);
  16267. specifier.exported = id;
  16268. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  16269. return true;
  16270. }
  16271. return false;
  16272. }
  16273. maybeParseExportNamespaceSpecifier(node) {
  16274. if (this.isContextual(93)) {
  16275. var _ref, _ref$specifiers;
  16276. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  16277. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  16278. this.next();
  16279. specifier.exported = this.parseModuleExportName();
  16280. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  16281. return true;
  16282. }
  16283. return false;
  16284. }
  16285. maybeParseExportNamedSpecifiers(node) {
  16286. if (this.match(5)) {
  16287. const node2 = node;
  16288. if (!node2.specifiers) node2.specifiers = [];
  16289. const isTypeExport = node2.exportKind === "type";
  16290. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  16291. node2.source = null;
  16292. if (this.hasPlugin("importAssertions")) {
  16293. node2.assertions = [];
  16294. } else {
  16295. node2.attributes = [];
  16296. }
  16297. node2.declaration = null;
  16298. return true;
  16299. }
  16300. return false;
  16301. }
  16302. maybeParseExportDeclaration(node) {
  16303. if (this.shouldParseExportDeclaration()) {
  16304. node.specifiers = [];
  16305. node.source = null;
  16306. if (this.hasPlugin("importAssertions")) {
  16307. node.assertions = [];
  16308. } else {
  16309. node.attributes = [];
  16310. }
  16311. node.declaration = this.parseExportDeclaration(node);
  16312. return true;
  16313. }
  16314. return false;
  16315. }
  16316. isAsyncFunction() {
  16317. if (!this.isContextual(95)) return false;
  16318. const next = this.nextTokenInLineStart();
  16319. return this.isUnparsedContextual(next, "function");
  16320. }
  16321. parseExportDefaultExpression() {
  16322. const expr = this.startNode();
  16323. if (this.match(68)) {
  16324. this.next();
  16325. return this.parseFunction(expr, 1 | 4);
  16326. } else if (this.isAsyncFunction()) {
  16327. this.next();
  16328. this.next();
  16329. return this.parseFunction(expr, 1 | 4 | 8);
  16330. }
  16331. if (this.match(80)) {
  16332. return this.parseClass(expr, true, true);
  16333. }
  16334. if (this.match(26)) {
  16335. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  16336. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  16337. }
  16338. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  16339. }
  16340. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  16341. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  16342. }
  16343. const res = this.parseMaybeAssignAllowIn();
  16344. this.semicolon();
  16345. return res;
  16346. }
  16347. parseExportDeclaration(node) {
  16348. if (this.match(80)) {
  16349. const node = this.parseClass(this.startNode(), true, false);
  16350. return node;
  16351. }
  16352. return this.parseStatementListItem();
  16353. }
  16354. isExportDefaultSpecifier() {
  16355. const {
  16356. type
  16357. } = this.state;
  16358. if (tokenIsIdentifier(type)) {
  16359. if (type === 95 && !this.state.containsEsc || type === 100) {
  16360. return false;
  16361. }
  16362. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  16363. const next = this.nextTokenStart();
  16364. const nextChar = this.input.charCodeAt(next);
  16365. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  16366. this.expectOnePlugin(["flow", "typescript"]);
  16367. return false;
  16368. }
  16369. }
  16370. } else if (!this.match(65)) {
  16371. return false;
  16372. }
  16373. const next = this.nextTokenStart();
  16374. const hasFrom = this.isUnparsedContextual(next, "from");
  16375. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  16376. return true;
  16377. }
  16378. if (this.match(65) && hasFrom) {
  16379. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  16380. return nextAfterFrom === 34 || nextAfterFrom === 39;
  16381. }
  16382. return false;
  16383. }
  16384. parseExportFrom(node, expect) {
  16385. if (this.eatContextual(98)) {
  16386. node.source = this.parseImportSource();
  16387. this.checkExport(node);
  16388. this.maybeParseImportAttributes(node);
  16389. this.checkJSONModuleImport(node);
  16390. } else if (expect) {
  16391. this.unexpected();
  16392. }
  16393. this.semicolon();
  16394. }
  16395. shouldParseExportDeclaration() {
  16396. const {
  16397. type
  16398. } = this.state;
  16399. if (type === 26) {
  16400. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  16401. if (this.hasPlugin("decorators")) {
  16402. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  16403. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  16404. }
  16405. return true;
  16406. }
  16407. }
  16408. if (this.isUsing()) {
  16409. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  16410. return true;
  16411. }
  16412. if (this.isAwaitUsing()) {
  16413. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  16414. return true;
  16415. }
  16416. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  16417. }
  16418. checkExport(node, checkNames, isDefault, isFrom) {
  16419. if (checkNames) {
  16420. var _node$specifiers;
  16421. if (isDefault) {
  16422. this.checkDuplicateExports(node, "default");
  16423. if (this.hasPlugin("exportDefaultFrom")) {
  16424. var _declaration$extra;
  16425. const declaration = node.declaration;
  16426. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  16427. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  16428. }
  16429. }
  16430. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  16431. for (const specifier of node.specifiers) {
  16432. const {
  16433. exported
  16434. } = specifier;
  16435. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  16436. this.checkDuplicateExports(specifier, exportName);
  16437. if (!isFrom && specifier.local) {
  16438. const {
  16439. local
  16440. } = specifier;
  16441. if (local.type !== "Identifier") {
  16442. this.raise(Errors.ExportBindingIsString, specifier, {
  16443. localName: local.value,
  16444. exportName
  16445. });
  16446. } else {
  16447. this.checkReservedWord(local.name, local.loc.start, true, false);
  16448. this.scope.checkLocalExport(local);
  16449. }
  16450. }
  16451. }
  16452. } else if (node.declaration) {
  16453. const decl = node.declaration;
  16454. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  16455. const {
  16456. id
  16457. } = decl;
  16458. if (!id) throw new Error("Assertion failure");
  16459. this.checkDuplicateExports(node, id.name);
  16460. } else if (decl.type === "VariableDeclaration") {
  16461. for (const declaration of decl.declarations) {
  16462. this.checkDeclaration(declaration.id);
  16463. }
  16464. }
  16465. }
  16466. }
  16467. }
  16468. checkDeclaration(node) {
  16469. if (node.type === "Identifier") {
  16470. this.checkDuplicateExports(node, node.name);
  16471. } else if (node.type === "ObjectPattern") {
  16472. for (const prop of node.properties) {
  16473. this.checkDeclaration(prop);
  16474. }
  16475. } else if (node.type === "ArrayPattern") {
  16476. for (const elem of node.elements) {
  16477. if (elem) {
  16478. this.checkDeclaration(elem);
  16479. }
  16480. }
  16481. } else if (node.type === "ObjectProperty") {
  16482. this.checkDeclaration(node.value);
  16483. } else if (node.type === "RestElement") {
  16484. this.checkDeclaration(node.argument);
  16485. } else if (node.type === "AssignmentPattern") {
  16486. this.checkDeclaration(node.left);
  16487. }
  16488. }
  16489. checkDuplicateExports(node, exportName) {
  16490. if (this.exportedIdentifiers.has(exportName)) {
  16491. if (exportName === "default") {
  16492. this.raise(Errors.DuplicateDefaultExport, node);
  16493. } else {
  16494. this.raise(Errors.DuplicateExport, node, {
  16495. exportName
  16496. });
  16497. }
  16498. }
  16499. this.exportedIdentifiers.add(exportName);
  16500. }
  16501. parseExportSpecifiers(isInTypeExport) {
  16502. const nodes = [];
  16503. let first = true;
  16504. this.expect(5);
  16505. while (!this.eat(8)) {
  16506. if (first) {
  16507. first = false;
  16508. } else {
  16509. this.expect(12);
  16510. if (this.eat(8)) break;
  16511. }
  16512. const isMaybeTypeOnly = this.isContextual(130);
  16513. const isString = this.match(134);
  16514. const node = this.startNode();
  16515. node.local = this.parseModuleExportName();
  16516. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  16517. }
  16518. return nodes;
  16519. }
  16520. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  16521. if (this.eatContextual(93)) {
  16522. node.exported = this.parseModuleExportName();
  16523. } else if (isString) {
  16524. node.exported = this.cloneStringLiteral(node.local);
  16525. } else if (!node.exported) {
  16526. node.exported = this.cloneIdentifier(node.local);
  16527. }
  16528. return this.finishNode(node, "ExportSpecifier");
  16529. }
  16530. parseModuleExportName() {
  16531. if (this.match(134)) {
  16532. const result = this.parseStringLiteral(this.state.value);
  16533. const surrogate = loneSurrogate.exec(result.value);
  16534. if (surrogate) {
  16535. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  16536. surrogateCharCode: surrogate[0].charCodeAt(0)
  16537. });
  16538. }
  16539. return result;
  16540. }
  16541. return this.parseIdentifier(true);
  16542. }
  16543. isJSONModuleImport(node) {
  16544. if (node.assertions != null) {
  16545. return node.assertions.some(({
  16546. key,
  16547. value
  16548. }) => {
  16549. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  16550. });
  16551. }
  16552. return false;
  16553. }
  16554. checkImportReflection(node) {
  16555. const {
  16556. specifiers
  16557. } = node;
  16558. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  16559. if (node.phase === "source") {
  16560. if (singleBindingType !== "ImportDefaultSpecifier") {
  16561. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  16562. }
  16563. } else if (node.phase === "defer") {
  16564. if (singleBindingType !== "ImportNamespaceSpecifier") {
  16565. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  16566. }
  16567. } else if (node.module) {
  16568. var _node$assertions;
  16569. if (singleBindingType !== "ImportDefaultSpecifier") {
  16570. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  16571. }
  16572. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  16573. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  16574. }
  16575. }
  16576. }
  16577. checkJSONModuleImport(node) {
  16578. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  16579. const {
  16580. specifiers
  16581. } = node;
  16582. if (specifiers != null) {
  16583. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  16584. let imported;
  16585. if (specifier.type === "ExportSpecifier") {
  16586. imported = specifier.local;
  16587. } else if (specifier.type === "ImportSpecifier") {
  16588. imported = specifier.imported;
  16589. }
  16590. if (imported !== undefined) {
  16591. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  16592. }
  16593. });
  16594. if (nonDefaultNamedSpecifier !== undefined) {
  16595. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  16596. }
  16597. }
  16598. }
  16599. }
  16600. isPotentialImportPhase(isExport) {
  16601. if (isExport) return false;
  16602. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  16603. }
  16604. applyImportPhase(node, isExport, phase, loc) {
  16605. if (isExport) {
  16606. return;
  16607. }
  16608. if (phase === "module") {
  16609. this.expectPlugin("importReflection", loc);
  16610. node.module = true;
  16611. } else if (this.hasPlugin("importReflection")) {
  16612. node.module = false;
  16613. }
  16614. if (phase === "source") {
  16615. this.expectPlugin("sourcePhaseImports", loc);
  16616. node.phase = "source";
  16617. } else if (phase === "defer") {
  16618. this.expectPlugin("deferredImportEvaluation", loc);
  16619. node.phase = "defer";
  16620. } else if (this.hasPlugin("sourcePhaseImports")) {
  16621. node.phase = null;
  16622. }
  16623. }
  16624. parseMaybeImportPhase(node, isExport) {
  16625. if (!this.isPotentialImportPhase(isExport)) {
  16626. this.applyImportPhase(node, isExport, null);
  16627. return null;
  16628. }
  16629. const phaseIdentifier = this.startNode();
  16630. const phaseIdentifierName = this.parseIdentifierName(true);
  16631. const {
  16632. type
  16633. } = this.state;
  16634. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  16635. if (isImportPhase) {
  16636. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  16637. return null;
  16638. } else {
  16639. this.applyImportPhase(node, isExport, null);
  16640. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  16641. }
  16642. }
  16643. isPrecedingIdImportPhase(phase) {
  16644. const {
  16645. type
  16646. } = this.state;
  16647. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  16648. }
  16649. parseImport(node) {
  16650. if (this.match(134)) {
  16651. return this.parseImportSourceAndAttributes(node);
  16652. }
  16653. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  16654. }
  16655. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  16656. node.specifiers = [];
  16657. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  16658. const parseNext = !hasDefault || this.eat(12);
  16659. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  16660. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  16661. this.expectContextual(98);
  16662. return this.parseImportSourceAndAttributes(node);
  16663. }
  16664. parseImportSourceAndAttributes(node) {
  16665. var _node$specifiers2;
  16666. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  16667. node.source = this.parseImportSource();
  16668. this.maybeParseImportAttributes(node);
  16669. this.checkImportReflection(node);
  16670. this.checkJSONModuleImport(node);
  16671. this.semicolon();
  16672. this.sawUnambiguousESM = true;
  16673. return this.finishNode(node, "ImportDeclaration");
  16674. }
  16675. parseImportSource() {
  16676. if (!this.match(134)) this.unexpected();
  16677. return this.parseExprAtom();
  16678. }
  16679. parseImportSpecifierLocal(node, specifier, type) {
  16680. specifier.local = this.parseIdentifier();
  16681. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  16682. }
  16683. finishImportSpecifier(specifier, type, bindingType = 8201) {
  16684. this.checkLVal(specifier.local, {
  16685. type
  16686. }, bindingType);
  16687. return this.finishNode(specifier, type);
  16688. }
  16689. parseImportAttributes() {
  16690. this.expect(5);
  16691. const attrs = [];
  16692. const attrNames = new Set();
  16693. do {
  16694. if (this.match(8)) {
  16695. break;
  16696. }
  16697. const node = this.startNode();
  16698. const keyName = this.state.value;
  16699. if (attrNames.has(keyName)) {
  16700. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  16701. key: keyName
  16702. });
  16703. }
  16704. attrNames.add(keyName);
  16705. if (this.match(134)) {
  16706. node.key = this.parseStringLiteral(keyName);
  16707. } else {
  16708. node.key = this.parseIdentifier(true);
  16709. }
  16710. this.expect(14);
  16711. if (!this.match(134)) {
  16712. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  16713. }
  16714. node.value = this.parseStringLiteral(this.state.value);
  16715. attrs.push(this.finishNode(node, "ImportAttribute"));
  16716. } while (this.eat(12));
  16717. this.expect(8);
  16718. return attrs;
  16719. }
  16720. parseModuleAttributes() {
  16721. const attrs = [];
  16722. const attributes = new Set();
  16723. do {
  16724. const node = this.startNode();
  16725. node.key = this.parseIdentifier(true);
  16726. if (node.key.name !== "type") {
  16727. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  16728. }
  16729. if (attributes.has(node.key.name)) {
  16730. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  16731. key: node.key.name
  16732. });
  16733. }
  16734. attributes.add(node.key.name);
  16735. this.expect(14);
  16736. if (!this.match(134)) {
  16737. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  16738. }
  16739. node.value = this.parseStringLiteral(this.state.value);
  16740. attrs.push(this.finishNode(node, "ImportAttribute"));
  16741. } while (this.eat(12));
  16742. return attrs;
  16743. }
  16744. maybeParseImportAttributes(node) {
  16745. let attributes;
  16746. {
  16747. var useWith = false;
  16748. }
  16749. if (this.match(76)) {
  16750. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  16751. return;
  16752. }
  16753. this.next();
  16754. if (this.hasPlugin("moduleAttributes")) {
  16755. attributes = this.parseModuleAttributes();
  16756. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  16757. } else {
  16758. attributes = this.parseImportAttributes();
  16759. }
  16760. {
  16761. useWith = true;
  16762. }
  16763. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  16764. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  16765. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  16766. }
  16767. if (!this.hasPlugin("importAssertions")) {
  16768. this.addExtra(node, "deprecatedAssertSyntax", true);
  16769. }
  16770. this.next();
  16771. attributes = this.parseImportAttributes();
  16772. } else {
  16773. attributes = [];
  16774. }
  16775. if (!useWith && this.hasPlugin("importAssertions")) {
  16776. node.assertions = attributes;
  16777. } else {
  16778. node.attributes = attributes;
  16779. }
  16780. }
  16781. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  16782. if (maybeDefaultIdentifier) {
  16783. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  16784. specifier.local = maybeDefaultIdentifier;
  16785. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  16786. return true;
  16787. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  16788. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  16789. return true;
  16790. }
  16791. return false;
  16792. }
  16793. maybeParseStarImportSpecifier(node) {
  16794. if (this.match(55)) {
  16795. const specifier = this.startNode();
  16796. this.next();
  16797. this.expectContextual(93);
  16798. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  16799. return true;
  16800. }
  16801. return false;
  16802. }
  16803. parseNamedImportSpecifiers(node) {
  16804. let first = true;
  16805. this.expect(5);
  16806. while (!this.eat(8)) {
  16807. if (first) {
  16808. first = false;
  16809. } else {
  16810. if (this.eat(14)) {
  16811. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  16812. }
  16813. this.expect(12);
  16814. if (this.eat(8)) break;
  16815. }
  16816. const specifier = this.startNode();
  16817. const importedIsString = this.match(134);
  16818. const isMaybeTypeOnly = this.isContextual(130);
  16819. specifier.imported = this.parseModuleExportName();
  16820. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  16821. node.specifiers.push(importSpecifier);
  16822. }
  16823. }
  16824. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  16825. if (this.eatContextual(93)) {
  16826. specifier.local = this.parseIdentifier();
  16827. } else {
  16828. const {
  16829. imported
  16830. } = specifier;
  16831. if (importedIsString) {
  16832. throw this.raise(Errors.ImportBindingIsString, specifier, {
  16833. importName: imported.value
  16834. });
  16835. }
  16836. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  16837. if (!specifier.local) {
  16838. specifier.local = this.cloneIdentifier(imported);
  16839. }
  16840. }
  16841. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  16842. }
  16843. isThisParam(param) {
  16844. return param.type === "Identifier" && param.name === "this";
  16845. }
  16846. }
  16847. class Parser extends StatementParser {
  16848. constructor(options, input, pluginsMap) {
  16849. options = getOptions(options);
  16850. super(options, input);
  16851. this.options = options;
  16852. this.initializeScopes();
  16853. this.plugins = pluginsMap;
  16854. this.filename = options.sourceFilename;
  16855. this.startIndex = options.startIndex;
  16856. let optionFlags = 0;
  16857. if (options.allowAwaitOutsideFunction) {
  16858. optionFlags |= 1;
  16859. }
  16860. if (options.allowReturnOutsideFunction) {
  16861. optionFlags |= 2;
  16862. }
  16863. if (options.allowImportExportEverywhere) {
  16864. optionFlags |= 8;
  16865. }
  16866. if (options.allowSuperOutsideMethod) {
  16867. optionFlags |= 16;
  16868. }
  16869. if (options.allowUndeclaredExports) {
  16870. optionFlags |= 64;
  16871. }
  16872. if (options.allowNewTargetOutsideFunction) {
  16873. optionFlags |= 4;
  16874. }
  16875. if (options.allowYieldOutsideFunction) {
  16876. optionFlags |= 32;
  16877. }
  16878. if (options.ranges) {
  16879. optionFlags |= 128;
  16880. }
  16881. if (options.tokens) {
  16882. optionFlags |= 256;
  16883. }
  16884. if (options.createImportExpressions) {
  16885. optionFlags |= 512;
  16886. }
  16887. if (options.createParenthesizedExpressions) {
  16888. optionFlags |= 1024;
  16889. }
  16890. if (options.errorRecovery) {
  16891. optionFlags |= 2048;
  16892. }
  16893. if (options.attachComment) {
  16894. optionFlags |= 4096;
  16895. }
  16896. if (options.annexB) {
  16897. optionFlags |= 8192;
  16898. }
  16899. this.optionFlags = optionFlags;
  16900. }
  16901. getScopeHandler() {
  16902. return ScopeHandler;
  16903. }
  16904. parse() {
  16905. this.enterInitialScopes();
  16906. const file = this.startNode();
  16907. const program = this.startNode();
  16908. this.nextToken();
  16909. file.errors = null;
  16910. this.parseTopLevel(file, program);
  16911. file.errors = this.state.errors;
  16912. file.comments.length = this.state.commentsLen;
  16913. return file;
  16914. }
  16915. }
  16916. function parse(input, options) {
  16917. var _options;
  16918. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  16919. options = Object.assign({}, options);
  16920. try {
  16921. options.sourceType = "module";
  16922. const parser = getParser(options, input);
  16923. const ast = parser.parse();
  16924. if (parser.sawUnambiguousESM) {
  16925. return ast;
  16926. }
  16927. if (parser.ambiguousScriptDifferentAst) {
  16928. try {
  16929. options.sourceType = "script";
  16930. return getParser(options, input).parse();
  16931. } catch (_unused) {}
  16932. } else {
  16933. ast.program.sourceType = "script";
  16934. }
  16935. return ast;
  16936. } catch (moduleError) {
  16937. try {
  16938. options.sourceType = "script";
  16939. return getParser(options, input).parse();
  16940. } catch (_unused2) {}
  16941. throw moduleError;
  16942. }
  16943. } else {
  16944. return getParser(options, input).parse();
  16945. }
  16946. }
  16947. function parseExpression(input, options) {
  16948. const parser = getParser(options, input);
  16949. if (parser.options.strictMode) {
  16950. parser.state.strict = true;
  16951. }
  16952. return parser.getExpression();
  16953. }
  16954. function generateExportedTokenTypes(internalTokenTypes) {
  16955. const tokenTypes = {};
  16956. for (const typeName of Object.keys(internalTokenTypes)) {
  16957. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  16958. }
  16959. return tokenTypes;
  16960. }
  16961. const tokTypes = generateExportedTokenTypes(tt);
  16962. function getParser(options, input) {
  16963. let cls = Parser;
  16964. const pluginsMap = new Map();
  16965. if (options != null && options.plugins) {
  16966. for (const plugin of options.plugins) {
  16967. let name, opts;
  16968. if (typeof plugin === "string") {
  16969. name = plugin;
  16970. } else {
  16971. [name, opts] = plugin;
  16972. }
  16973. if (!pluginsMap.has(name)) {
  16974. pluginsMap.set(name, opts || {});
  16975. }
  16976. }
  16977. validatePlugins(pluginsMap);
  16978. cls = getParserClass(pluginsMap);
  16979. }
  16980. return new cls(options, input, pluginsMap);
  16981. }
  16982. const parserClassCache = new Map();
  16983. function getParserClass(pluginsMap) {
  16984. const pluginList = [];
  16985. for (const name of mixinPluginNames) {
  16986. if (pluginsMap.has(name)) {
  16987. pluginList.push(name);
  16988. }
  16989. }
  16990. const key = pluginList.join("|");
  16991. let cls = parserClassCache.get(key);
  16992. if (!cls) {
  16993. cls = Parser;
  16994. for (const plugin of pluginList) {
  16995. cls = mixinPlugins[plugin](cls);
  16996. }
  16997. parserClassCache.set(key, cls);
  16998. }
  16999. return cls;
  17000. }
  17001. lib.parse = parse;
  17002. lib.parseExpression = parseExpression;
  17003. lib.tokTypes = tokTypes;
  17004. return lib;
  17005. }
  17006. var libExports = /*@__PURE__*/ requireLib();
  17007. // @ts-check
  17008. /** @typedef { import('estree').BaseNode} BaseNode */
  17009. /** @typedef {{
  17010. skip: () => void;
  17011. remove: () => void;
  17012. replace: (node: BaseNode) => void;
  17013. }} WalkerContext */
  17014. class WalkerBase {
  17015. constructor() {
  17016. /** @type {boolean} */
  17017. this.should_skip = false;
  17018. /** @type {boolean} */
  17019. this.should_remove = false;
  17020. /** @type {BaseNode | null} */
  17021. this.replacement = null;
  17022. /** @type {WalkerContext} */
  17023. this.context = {
  17024. skip: () => (this.should_skip = true),
  17025. remove: () => (this.should_remove = true),
  17026. replace: (node) => (this.replacement = node)
  17027. };
  17028. }
  17029. /**
  17030. *
  17031. * @param {any} parent
  17032. * @param {string} prop
  17033. * @param {number} index
  17034. * @param {BaseNode} node
  17035. */
  17036. replace(parent, prop, index, node) {
  17037. if (parent) {
  17038. if (index !== null) {
  17039. parent[prop][index] = node;
  17040. } else {
  17041. parent[prop] = node;
  17042. }
  17043. }
  17044. }
  17045. /**
  17046. *
  17047. * @param {any} parent
  17048. * @param {string} prop
  17049. * @param {number} index
  17050. */
  17051. remove(parent, prop, index) {
  17052. if (parent) {
  17053. if (index !== null) {
  17054. parent[prop].splice(index, 1);
  17055. } else {
  17056. delete parent[prop];
  17057. }
  17058. }
  17059. }
  17060. }
  17061. // @ts-check
  17062. /** @typedef { import('estree').BaseNode} BaseNode */
  17063. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  17064. /** @typedef {(
  17065. * this: WalkerContext,
  17066. * node: BaseNode,
  17067. * parent: BaseNode,
  17068. * key: string,
  17069. * index: number
  17070. * ) => void} SyncHandler */
  17071. class SyncWalker extends WalkerBase {
  17072. /**
  17073. *
  17074. * @param {SyncHandler} enter
  17075. * @param {SyncHandler} leave
  17076. */
  17077. constructor(enter, leave) {
  17078. super();
  17079. /** @type {SyncHandler} */
  17080. this.enter = enter;
  17081. /** @type {SyncHandler} */
  17082. this.leave = leave;
  17083. }
  17084. /**
  17085. *
  17086. * @param {BaseNode} node
  17087. * @param {BaseNode} parent
  17088. * @param {string} [prop]
  17089. * @param {number} [index]
  17090. * @returns {BaseNode}
  17091. */
  17092. visit(node, parent, prop, index) {
  17093. if (node) {
  17094. if (this.enter) {
  17095. const _should_skip = this.should_skip;
  17096. const _should_remove = this.should_remove;
  17097. const _replacement = this.replacement;
  17098. this.should_skip = false;
  17099. this.should_remove = false;
  17100. this.replacement = null;
  17101. this.enter.call(this.context, node, parent, prop, index);
  17102. if (this.replacement) {
  17103. node = this.replacement;
  17104. this.replace(parent, prop, index, node);
  17105. }
  17106. if (this.should_remove) {
  17107. this.remove(parent, prop, index);
  17108. }
  17109. const skipped = this.should_skip;
  17110. const removed = this.should_remove;
  17111. this.should_skip = _should_skip;
  17112. this.should_remove = _should_remove;
  17113. this.replacement = _replacement;
  17114. if (skipped) return node;
  17115. if (removed) return null;
  17116. }
  17117. for (const key in node) {
  17118. const value = node[key];
  17119. if (typeof value !== "object") {
  17120. continue;
  17121. } else if (Array.isArray(value)) {
  17122. for (let i = 0; i < value.length; i += 1) {
  17123. if (value[i] !== null && typeof value[i].type === 'string') {
  17124. if (!this.visit(value[i], node, key, i)) {
  17125. // removed
  17126. i--;
  17127. }
  17128. }
  17129. }
  17130. } else if (value !== null && typeof value.type === "string") {
  17131. this.visit(value, node, key, null);
  17132. }
  17133. }
  17134. if (this.leave) {
  17135. const _replacement = this.replacement;
  17136. const _should_remove = this.should_remove;
  17137. this.replacement = null;
  17138. this.should_remove = false;
  17139. this.leave.call(this.context, node, parent, prop, index);
  17140. if (this.replacement) {
  17141. node = this.replacement;
  17142. this.replace(parent, prop, index, node);
  17143. }
  17144. if (this.should_remove) {
  17145. this.remove(parent, prop, index);
  17146. }
  17147. const removed = this.should_remove;
  17148. this.replacement = _replacement;
  17149. this.should_remove = _should_remove;
  17150. if (removed) return null;
  17151. }
  17152. }
  17153. return node;
  17154. }
  17155. }
  17156. // @ts-check
  17157. /** @typedef { import('estree').BaseNode} BaseNode */
  17158. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  17159. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  17160. /**
  17161. *
  17162. * @param {BaseNode} ast
  17163. * @param {{
  17164. * enter?: SyncHandler
  17165. * leave?: SyncHandler
  17166. * }} walker
  17167. * @returns {BaseNode}
  17168. */
  17169. function walk$2(ast, { enter, leave }) {
  17170. const instance = new SyncWalker(enter, leave);
  17171. return instance.visit(ast, null);
  17172. }
  17173. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  17174. const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
  17175. walk$2(root, {
  17176. enter(node, parent) {
  17177. parent && parentStack.push(parent);
  17178. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  17179. return this.skip();
  17180. }
  17181. if (node.type === "Identifier") {
  17182. const isLocal = !!knownIds[node.name];
  17183. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  17184. if (includeAll || isRefed && !isLocal) {
  17185. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  17186. }
  17187. } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
  17188. (parent == null ? void 0 : parent.type) === "ObjectPattern") {
  17189. node.inPattern = true;
  17190. } else if (isFunctionType(node)) {
  17191. if (node.scopeIds) {
  17192. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  17193. } else {
  17194. walkFunctionParams(
  17195. node,
  17196. (id) => markScopeIdentifier(node, id, knownIds)
  17197. );
  17198. }
  17199. } else if (node.type === "BlockStatement") {
  17200. if (node.scopeIds) {
  17201. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  17202. } else {
  17203. walkBlockDeclarations(
  17204. node,
  17205. (id) => markScopeIdentifier(node, id, knownIds)
  17206. );
  17207. }
  17208. } else if (node.type === "CatchClause" && node.param) {
  17209. for (const id of extractIdentifiers$1(node.param)) {
  17210. markScopeIdentifier(node, id, knownIds);
  17211. }
  17212. } else if (isForStatement(node)) {
  17213. walkForStatement(
  17214. node,
  17215. false,
  17216. (id) => markScopeIdentifier(node, id, knownIds)
  17217. );
  17218. }
  17219. },
  17220. leave(node, parent) {
  17221. parent && parentStack.pop();
  17222. if (node !== rootExp && node.scopeIds) {
  17223. for (const id of node.scopeIds) {
  17224. knownIds[id]--;
  17225. if (knownIds[id] === 0) {
  17226. delete knownIds[id];
  17227. }
  17228. }
  17229. }
  17230. }
  17231. });
  17232. }
  17233. function isReferencedIdentifier(id, parent, parentStack) {
  17234. if (!parent) {
  17235. return true;
  17236. }
  17237. if (id.name === "arguments") {
  17238. return false;
  17239. }
  17240. if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
  17241. return true;
  17242. }
  17243. switch (parent.type) {
  17244. case "AssignmentExpression":
  17245. case "AssignmentPattern":
  17246. return true;
  17247. case "ObjectProperty":
  17248. return parent.key !== id && isInDestructureAssignment(parent, parentStack);
  17249. case "ArrayPattern":
  17250. return isInDestructureAssignment(parent, parentStack);
  17251. }
  17252. return false;
  17253. }
  17254. function isInDestructureAssignment(parent, parentStack) {
  17255. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  17256. let i = parentStack.length;
  17257. while (i--) {
  17258. const p = parentStack[i];
  17259. if (p.type === "AssignmentExpression") {
  17260. return true;
  17261. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  17262. break;
  17263. }
  17264. }
  17265. }
  17266. return false;
  17267. }
  17268. function isInNewExpression(parentStack) {
  17269. let i = parentStack.length;
  17270. while (i--) {
  17271. const p = parentStack[i];
  17272. if (p.type === "NewExpression") {
  17273. return true;
  17274. } else if (p.type !== "MemberExpression") {
  17275. break;
  17276. }
  17277. }
  17278. return false;
  17279. }
  17280. function walkFunctionParams(node, onIdent) {
  17281. for (const p of node.params) {
  17282. for (const id of extractIdentifiers$1(p)) {
  17283. onIdent(id);
  17284. }
  17285. }
  17286. }
  17287. function walkBlockDeclarations(block, onIdent) {
  17288. for (const stmt of block.body) {
  17289. if (stmt.type === "VariableDeclaration") {
  17290. if (stmt.declare) continue;
  17291. for (const decl of stmt.declarations) {
  17292. for (const id of extractIdentifiers$1(decl.id)) {
  17293. onIdent(id);
  17294. }
  17295. }
  17296. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  17297. if (stmt.declare || !stmt.id) continue;
  17298. onIdent(stmt.id);
  17299. } else if (isForStatement(stmt)) {
  17300. walkForStatement(stmt, true, onIdent);
  17301. }
  17302. }
  17303. }
  17304. function isForStatement(stmt) {
  17305. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  17306. }
  17307. function walkForStatement(stmt, isVar, onIdent) {
  17308. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  17309. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  17310. for (const decl of variable.declarations) {
  17311. for (const id of extractIdentifiers$1(decl.id)) {
  17312. onIdent(id);
  17313. }
  17314. }
  17315. }
  17316. }
  17317. function extractIdentifiers$1(param, nodes = []) {
  17318. switch (param.type) {
  17319. case "Identifier":
  17320. nodes.push(param);
  17321. break;
  17322. case "MemberExpression":
  17323. let object = param;
  17324. while (object.type === "MemberExpression") {
  17325. object = object.object;
  17326. }
  17327. nodes.push(object);
  17328. break;
  17329. case "ObjectPattern":
  17330. for (const prop of param.properties) {
  17331. if (prop.type === "RestElement") {
  17332. extractIdentifiers$1(prop.argument, nodes);
  17333. } else {
  17334. extractIdentifiers$1(prop.value, nodes);
  17335. }
  17336. }
  17337. break;
  17338. case "ArrayPattern":
  17339. param.elements.forEach((element) => {
  17340. if (element) extractIdentifiers$1(element, nodes);
  17341. });
  17342. break;
  17343. case "RestElement":
  17344. extractIdentifiers$1(param.argument, nodes);
  17345. break;
  17346. case "AssignmentPattern":
  17347. extractIdentifiers$1(param.left, nodes);
  17348. break;
  17349. }
  17350. return nodes;
  17351. }
  17352. function markKnownIds(name, knownIds) {
  17353. if (name in knownIds) {
  17354. knownIds[name]++;
  17355. } else {
  17356. knownIds[name] = 1;
  17357. }
  17358. }
  17359. function markScopeIdentifier(node, child, knownIds) {
  17360. const { name } = child;
  17361. if (node.scopeIds && node.scopeIds.has(name)) {
  17362. return;
  17363. }
  17364. markKnownIds(name, knownIds);
  17365. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  17366. }
  17367. const isFunctionType = (node) => {
  17368. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  17369. };
  17370. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  17371. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  17372. function isReferenced(node, parent, grandparent) {
  17373. switch (parent.type) {
  17374. // yes: PARENT[NODE]
  17375. // yes: NODE.child
  17376. // no: parent.NODE
  17377. case "MemberExpression":
  17378. case "OptionalMemberExpression":
  17379. if (parent.property === node) {
  17380. return !!parent.computed;
  17381. }
  17382. return parent.object === node;
  17383. case "JSXMemberExpression":
  17384. return parent.object === node;
  17385. // no: let NODE = init;
  17386. // yes: let id = NODE;
  17387. case "VariableDeclarator":
  17388. return parent.init === node;
  17389. // yes: () => NODE
  17390. // no: (NODE) => {}
  17391. case "ArrowFunctionExpression":
  17392. return parent.body === node;
  17393. // no: class { #NODE; }
  17394. // no: class { get #NODE() {} }
  17395. // no: class { #NODE() {} }
  17396. // no: class { fn() { return this.#NODE; } }
  17397. case "PrivateName":
  17398. return false;
  17399. // no: class { NODE() {} }
  17400. // yes: class { [NODE]() {} }
  17401. // no: class { foo(NODE) {} }
  17402. case "ClassMethod":
  17403. case "ClassPrivateMethod":
  17404. case "ObjectMethod":
  17405. if (parent.key === node) {
  17406. return !!parent.computed;
  17407. }
  17408. return false;
  17409. // yes: { [NODE]: "" }
  17410. // no: { NODE: "" }
  17411. // depends: { NODE }
  17412. // depends: { key: NODE }
  17413. case "ObjectProperty":
  17414. if (parent.key === node) {
  17415. return !!parent.computed;
  17416. }
  17417. return !grandparent || grandparent.type !== "ObjectPattern";
  17418. // no: class { NODE = value; }
  17419. // yes: class { [NODE] = value; }
  17420. // yes: class { key = NODE; }
  17421. case "ClassProperty":
  17422. if (parent.key === node) {
  17423. return !!parent.computed;
  17424. }
  17425. return true;
  17426. case "ClassPrivateProperty":
  17427. return parent.key !== node;
  17428. // no: class NODE {}
  17429. // yes: class Foo extends NODE {}
  17430. case "ClassDeclaration":
  17431. case "ClassExpression":
  17432. return parent.superClass === node;
  17433. // yes: left = NODE;
  17434. // no: NODE = right;
  17435. case "AssignmentExpression":
  17436. return parent.right === node;
  17437. // no: [NODE = foo] = [];
  17438. // yes: [foo = NODE] = [];
  17439. case "AssignmentPattern":
  17440. return parent.right === node;
  17441. // no: NODE: for (;;) {}
  17442. case "LabeledStatement":
  17443. return false;
  17444. // no: try {} catch (NODE) {}
  17445. case "CatchClause":
  17446. return false;
  17447. // no: function foo(...NODE) {}
  17448. case "RestElement":
  17449. return false;
  17450. case "BreakStatement":
  17451. case "ContinueStatement":
  17452. return false;
  17453. // no: function NODE() {}
  17454. // no: function foo(NODE) {}
  17455. case "FunctionDeclaration":
  17456. case "FunctionExpression":
  17457. return false;
  17458. // no: export NODE from "foo";
  17459. // no: export * as NODE from "foo";
  17460. case "ExportNamespaceSpecifier":
  17461. case "ExportDefaultSpecifier":
  17462. return false;
  17463. // no: export { foo as NODE };
  17464. // yes: export { NODE as foo };
  17465. // no: export { NODE as foo } from "foo";
  17466. case "ExportSpecifier":
  17467. if (grandparent == null ? void 0 : grandparent.source) {
  17468. return false;
  17469. }
  17470. return parent.local === node;
  17471. // no: import NODE from "foo";
  17472. // no: import * as NODE from "foo";
  17473. // no: import { NODE as foo } from "foo";
  17474. // no: import { foo as NODE } from "foo";
  17475. // no: import NODE from "bar";
  17476. case "ImportDefaultSpecifier":
  17477. case "ImportNamespaceSpecifier":
  17478. case "ImportSpecifier":
  17479. return false;
  17480. // no: import "foo" assert { NODE: "json" }
  17481. case "ImportAttribute":
  17482. return false;
  17483. // no: <div NODE="foo" />
  17484. case "JSXAttribute":
  17485. return false;
  17486. // no: [NODE] = [];
  17487. // no: ({ NODE }) = [];
  17488. case "ObjectPattern":
  17489. case "ArrayPattern":
  17490. return false;
  17491. // no: new.NODE
  17492. // no: NODE.target
  17493. case "MetaProperty":
  17494. return false;
  17495. // yes: type X = { someProperty: NODE }
  17496. // no: type X = { NODE: OtherType }
  17497. case "ObjectTypeProperty":
  17498. return parent.key !== node;
  17499. // yes: enum X { Foo = NODE }
  17500. // no: enum X { NODE }
  17501. case "TSEnumMember":
  17502. return parent.id !== node;
  17503. // yes: { [NODE]: value }
  17504. // no: { NODE: value }
  17505. case "TSPropertySignature":
  17506. if (parent.key === node) {
  17507. return !!parent.computed;
  17508. }
  17509. return true;
  17510. }
  17511. return true;
  17512. }
  17513. const TS_NODE_TYPES = [
  17514. "TSAsExpression",
  17515. // foo as number
  17516. "TSTypeAssertion",
  17517. // (<number>foo)
  17518. "TSNonNullExpression",
  17519. // foo!
  17520. "TSInstantiationExpression",
  17521. // foo<string>
  17522. "TSSatisfiesExpression"
  17523. // foo satisfies T
  17524. ];
  17525. function unwrapTSNode(node) {
  17526. if (TS_NODE_TYPES.includes(node.type)) {
  17527. return unwrapTSNode(node.expression);
  17528. } else {
  17529. return node;
  17530. }
  17531. }
  17532. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  17533. function isCoreComponent(tag) {
  17534. switch (tag) {
  17535. case "Teleport":
  17536. case "teleport":
  17537. return TELEPORT;
  17538. case "Suspense":
  17539. case "suspense":
  17540. return SUSPENSE;
  17541. case "KeepAlive":
  17542. case "keep-alive":
  17543. return KEEP_ALIVE;
  17544. case "BaseTransition":
  17545. case "base-transition":
  17546. return BASE_TRANSITION;
  17547. }
  17548. }
  17549. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  17550. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  17551. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  17552. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  17553. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  17554. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  17555. const isMemberExpressionBrowser = (exp) => {
  17556. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  17557. let state = 0 /* inMemberExp */;
  17558. let stateStack = [];
  17559. let currentOpenBracketCount = 0;
  17560. let currentOpenParensCount = 0;
  17561. let currentStringType = null;
  17562. for (let i = 0; i < path.length; i++) {
  17563. const char = path.charAt(i);
  17564. switch (state) {
  17565. case 0 /* inMemberExp */:
  17566. if (char === "[") {
  17567. stateStack.push(state);
  17568. state = 1 /* inBrackets */;
  17569. currentOpenBracketCount++;
  17570. } else if (char === "(") {
  17571. stateStack.push(state);
  17572. state = 2 /* inParens */;
  17573. currentOpenParensCount++;
  17574. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  17575. return false;
  17576. }
  17577. break;
  17578. case 1 /* inBrackets */:
  17579. if (char === `'` || char === `"` || char === "`") {
  17580. stateStack.push(state);
  17581. state = 3 /* inString */;
  17582. currentStringType = char;
  17583. } else if (char === `[`) {
  17584. currentOpenBracketCount++;
  17585. } else if (char === `]`) {
  17586. if (!--currentOpenBracketCount) {
  17587. state = stateStack.pop();
  17588. }
  17589. }
  17590. break;
  17591. case 2 /* inParens */:
  17592. if (char === `'` || char === `"` || char === "`") {
  17593. stateStack.push(state);
  17594. state = 3 /* inString */;
  17595. currentStringType = char;
  17596. } else if (char === `(`) {
  17597. currentOpenParensCount++;
  17598. } else if (char === `)`) {
  17599. if (i === path.length - 1) {
  17600. return false;
  17601. }
  17602. if (!--currentOpenParensCount) {
  17603. state = stateStack.pop();
  17604. }
  17605. }
  17606. break;
  17607. case 3 /* inString */:
  17608. if (char === currentStringType) {
  17609. state = stateStack.pop();
  17610. currentStringType = null;
  17611. }
  17612. break;
  17613. }
  17614. }
  17615. return !currentOpenBracketCount && !currentOpenParensCount;
  17616. };
  17617. const isMemberExpressionNode = (exp, context) => {
  17618. try {
  17619. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  17620. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  17621. });
  17622. ret = unwrapTSNode(ret);
  17623. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
  17624. } catch (e) {
  17625. return false;
  17626. }
  17627. };
  17628. const isMemberExpression = isMemberExpressionNode;
  17629. const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  17630. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  17631. const isFnExpressionNode = (exp, context) => {
  17632. try {
  17633. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  17634. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  17635. });
  17636. if (ret.type === "Program") {
  17637. ret = ret.body[0];
  17638. if (ret.type === "ExpressionStatement") {
  17639. ret = ret.expression;
  17640. }
  17641. }
  17642. ret = unwrapTSNode(ret);
  17643. return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
  17644. } catch (e) {
  17645. return false;
  17646. }
  17647. };
  17648. const isFnExpression = isFnExpressionNode;
  17649. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  17650. return advancePositionWithMutation(
  17651. {
  17652. offset: pos.offset,
  17653. line: pos.line,
  17654. column: pos.column
  17655. },
  17656. source,
  17657. numberOfCharacters
  17658. );
  17659. }
  17660. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  17661. let linesCount = 0;
  17662. let lastNewLinePos = -1;
  17663. for (let i = 0; i < numberOfCharacters; i++) {
  17664. if (source.charCodeAt(i) === 10) {
  17665. linesCount++;
  17666. lastNewLinePos = i;
  17667. }
  17668. }
  17669. pos.offset += numberOfCharacters;
  17670. pos.line += linesCount;
  17671. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  17672. return pos;
  17673. }
  17674. function assert(condition, msg) {
  17675. if (!condition) {
  17676. throw new Error(msg || `unexpected compiler condition`);
  17677. }
  17678. }
  17679. function findDir(node, name, allowEmpty = false) {
  17680. for (let i = 0; i < node.props.length; i++) {
  17681. const p = node.props[i];
  17682. if (p.type === 7 && (allowEmpty || p.exp) && (isString$1(name) ? p.name === name : name.test(p.name))) {
  17683. return p;
  17684. }
  17685. }
  17686. }
  17687. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  17688. for (let i = 0; i < node.props.length; i++) {
  17689. const p = node.props[i];
  17690. if (p.type === 6) {
  17691. if (dynamicOnly) continue;
  17692. if (p.name === name && (p.value || allowEmpty)) {
  17693. return p;
  17694. }
  17695. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  17696. return p;
  17697. }
  17698. }
  17699. }
  17700. function isStaticArgOf(arg, name) {
  17701. return !!(arg && isStaticExp(arg) && arg.content === name);
  17702. }
  17703. function hasDynamicKeyVBind(node) {
  17704. return node.props.some(
  17705. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  17706. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  17707. !p.arg.isStatic)
  17708. // v-bind:[foo]
  17709. );
  17710. }
  17711. function isText$1(node) {
  17712. return node.type === 5 || node.type === 2;
  17713. }
  17714. function isVPre(p) {
  17715. return p.type === 7 && p.name === "pre";
  17716. }
  17717. function isVSlot(p) {
  17718. return p.type === 7 && p.name === "slot";
  17719. }
  17720. function isTemplateNode(node) {
  17721. return node.type === 1 && node.tagType === 3;
  17722. }
  17723. function isSlotOutlet(node) {
  17724. return node.type === 1 && node.tagType === 2;
  17725. }
  17726. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  17727. function getUnnormalizedProps(props, callPath = []) {
  17728. if (props && !isString$1(props) && props.type === 14) {
  17729. const callee = props.callee;
  17730. if (!isString$1(callee) && propsHelperSet.has(callee)) {
  17731. return getUnnormalizedProps(
  17732. props.arguments[0],
  17733. callPath.concat(props)
  17734. );
  17735. }
  17736. }
  17737. return [props, callPath];
  17738. }
  17739. function injectProp(node, prop, context) {
  17740. let propsWithInjection;
  17741. let props = node.type === 13 ? node.props : node.arguments[2];
  17742. let callPath = [];
  17743. let parentCall;
  17744. if (props && !isString$1(props) && props.type === 14) {
  17745. const ret = getUnnormalizedProps(props);
  17746. props = ret[0];
  17747. callPath = ret[1];
  17748. parentCall = callPath[callPath.length - 1];
  17749. }
  17750. if (props == null || isString$1(props)) {
  17751. propsWithInjection = createObjectExpression([prop]);
  17752. } else if (props.type === 14) {
  17753. const first = props.arguments[0];
  17754. if (!isString$1(first) && first.type === 15) {
  17755. if (!hasProp(prop, first)) {
  17756. first.properties.unshift(prop);
  17757. }
  17758. } else {
  17759. if (props.callee === TO_HANDLERS) {
  17760. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  17761. createObjectExpression([prop]),
  17762. props
  17763. ]);
  17764. } else {
  17765. props.arguments.unshift(createObjectExpression([prop]));
  17766. }
  17767. }
  17768. !propsWithInjection && (propsWithInjection = props);
  17769. } else if (props.type === 15) {
  17770. if (!hasProp(prop, props)) {
  17771. props.properties.unshift(prop);
  17772. }
  17773. propsWithInjection = props;
  17774. } else {
  17775. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  17776. createObjectExpression([prop]),
  17777. props
  17778. ]);
  17779. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  17780. parentCall = callPath[callPath.length - 2];
  17781. }
  17782. }
  17783. if (node.type === 13) {
  17784. if (parentCall) {
  17785. parentCall.arguments[0] = propsWithInjection;
  17786. } else {
  17787. node.props = propsWithInjection;
  17788. }
  17789. } else {
  17790. if (parentCall) {
  17791. parentCall.arguments[0] = propsWithInjection;
  17792. } else {
  17793. node.arguments[2] = propsWithInjection;
  17794. }
  17795. }
  17796. }
  17797. function hasProp(prop, props) {
  17798. let result = false;
  17799. if (prop.key.type === 4) {
  17800. const propKeyName = prop.key.content;
  17801. result = props.properties.some(
  17802. (p) => p.key.type === 4 && p.key.content === propKeyName
  17803. );
  17804. }
  17805. return result;
  17806. }
  17807. function toValidAssetId(name, type) {
  17808. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  17809. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  17810. })}`;
  17811. }
  17812. function hasScopeRef(node, ids) {
  17813. if (!node || Object.keys(ids).length === 0) {
  17814. return false;
  17815. }
  17816. switch (node.type) {
  17817. case 1:
  17818. for (let i = 0; i < node.props.length; i++) {
  17819. const p = node.props[i];
  17820. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  17821. return true;
  17822. }
  17823. }
  17824. return node.children.some((c) => hasScopeRef(c, ids));
  17825. case 11:
  17826. if (hasScopeRef(node.source, ids)) {
  17827. return true;
  17828. }
  17829. return node.children.some((c) => hasScopeRef(c, ids));
  17830. case 9:
  17831. return node.branches.some((b) => hasScopeRef(b, ids));
  17832. case 10:
  17833. if (hasScopeRef(node.condition, ids)) {
  17834. return true;
  17835. }
  17836. return node.children.some((c) => hasScopeRef(c, ids));
  17837. case 4:
  17838. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  17839. case 8:
  17840. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  17841. case 5:
  17842. case 12:
  17843. return hasScopeRef(node.content, ids);
  17844. case 2:
  17845. case 3:
  17846. case 20:
  17847. return false;
  17848. default:
  17849. return false;
  17850. }
  17851. }
  17852. function getMemoedVNodeCall(node) {
  17853. if (node.type === 14 && node.callee === WITH_MEMO) {
  17854. return node.arguments[1].returns;
  17855. } else {
  17856. return node;
  17857. }
  17858. }
  17859. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  17860. const defaultParserOptions = {
  17861. parseMode: "base",
  17862. ns: 0,
  17863. delimiters: [`{{`, `}}`],
  17864. getNamespace: () => 0,
  17865. isVoidTag: NO,
  17866. isPreTag: NO,
  17867. isIgnoreNewlineTag: NO,
  17868. isCustomElement: NO,
  17869. onError: defaultOnError,
  17870. onWarn: defaultOnWarn,
  17871. comments: true,
  17872. prefixIdentifiers: false
  17873. };
  17874. let currentOptions = defaultParserOptions;
  17875. let currentRoot = null;
  17876. let currentInput = "";
  17877. let currentOpenTag = null;
  17878. let currentProp = null;
  17879. let currentAttrValue = "";
  17880. let currentAttrStartIndex = -1;
  17881. let currentAttrEndIndex = -1;
  17882. let inPre = 0;
  17883. let inVPre = false;
  17884. let currentVPreBoundary = null;
  17885. const stack = [];
  17886. const tokenizer = new Tokenizer(stack, {
  17887. onerr: emitError,
  17888. ontext(start, end) {
  17889. onText(getSlice(start, end), start, end);
  17890. },
  17891. ontextentity(char, start, end) {
  17892. onText(char, start, end);
  17893. },
  17894. oninterpolation(start, end) {
  17895. if (inVPre) {
  17896. return onText(getSlice(start, end), start, end);
  17897. }
  17898. let innerStart = start + tokenizer.delimiterOpen.length;
  17899. let innerEnd = end - tokenizer.delimiterClose.length;
  17900. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  17901. innerStart++;
  17902. }
  17903. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  17904. innerEnd--;
  17905. }
  17906. let exp = getSlice(innerStart, innerEnd);
  17907. if (exp.includes("&")) {
  17908. {
  17909. exp = decodeHTML(exp);
  17910. }
  17911. }
  17912. addNode({
  17913. type: 5,
  17914. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  17915. loc: getLoc(start, end)
  17916. });
  17917. },
  17918. onopentagname(start, end) {
  17919. const name = getSlice(start, end);
  17920. currentOpenTag = {
  17921. type: 1,
  17922. tag: name,
  17923. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  17924. tagType: 0,
  17925. // will be refined on tag close
  17926. props: [],
  17927. children: [],
  17928. loc: getLoc(start - 1, end),
  17929. codegenNode: void 0
  17930. };
  17931. },
  17932. onopentagend(end) {
  17933. endOpenTag(end);
  17934. },
  17935. onclosetag(start, end) {
  17936. const name = getSlice(start, end);
  17937. if (!currentOptions.isVoidTag(name)) {
  17938. let found = false;
  17939. for (let i = 0; i < stack.length; i++) {
  17940. const e = stack[i];
  17941. if (e.tag.toLowerCase() === name.toLowerCase()) {
  17942. found = true;
  17943. if (i > 0) {
  17944. emitError(24, stack[0].loc.start.offset);
  17945. }
  17946. for (let j = 0; j <= i; j++) {
  17947. const el = stack.shift();
  17948. onCloseTag(el, end, j < i);
  17949. }
  17950. break;
  17951. }
  17952. }
  17953. if (!found) {
  17954. emitError(23, backTrack(start, 60));
  17955. }
  17956. }
  17957. },
  17958. onselfclosingtag(end) {
  17959. const name = currentOpenTag.tag;
  17960. currentOpenTag.isSelfClosing = true;
  17961. endOpenTag(end);
  17962. if (stack[0] && stack[0].tag === name) {
  17963. onCloseTag(stack.shift(), end);
  17964. }
  17965. },
  17966. onattribname(start, end) {
  17967. currentProp = {
  17968. type: 6,
  17969. name: getSlice(start, end),
  17970. nameLoc: getLoc(start, end),
  17971. value: void 0,
  17972. loc: getLoc(start)
  17973. };
  17974. },
  17975. ondirname(start, end) {
  17976. const raw = getSlice(start, end);
  17977. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  17978. if (!inVPre && name === "") {
  17979. emitError(26, start);
  17980. }
  17981. if (inVPre || name === "") {
  17982. currentProp = {
  17983. type: 6,
  17984. name: raw,
  17985. nameLoc: getLoc(start, end),
  17986. value: void 0,
  17987. loc: getLoc(start)
  17988. };
  17989. } else {
  17990. currentProp = {
  17991. type: 7,
  17992. name,
  17993. rawName: raw,
  17994. exp: void 0,
  17995. arg: void 0,
  17996. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  17997. loc: getLoc(start)
  17998. };
  17999. if (name === "pre") {
  18000. inVPre = tokenizer.inVPre = true;
  18001. currentVPreBoundary = currentOpenTag;
  18002. const props = currentOpenTag.props;
  18003. for (let i = 0; i < props.length; i++) {
  18004. if (props[i].type === 7) {
  18005. props[i] = dirToAttr(props[i]);
  18006. }
  18007. }
  18008. }
  18009. }
  18010. },
  18011. ondirarg(start, end) {
  18012. if (start === end) return;
  18013. const arg = getSlice(start, end);
  18014. if (inVPre && !isVPre(currentProp)) {
  18015. currentProp.name += arg;
  18016. setLocEnd(currentProp.nameLoc, end);
  18017. } else {
  18018. const isStatic = arg[0] !== `[`;
  18019. currentProp.arg = createExp(
  18020. isStatic ? arg : arg.slice(1, -1),
  18021. isStatic,
  18022. getLoc(start, end),
  18023. isStatic ? 3 : 0
  18024. );
  18025. }
  18026. },
  18027. ondirmodifier(start, end) {
  18028. const mod = getSlice(start, end);
  18029. if (inVPre && !isVPre(currentProp)) {
  18030. currentProp.name += "." + mod;
  18031. setLocEnd(currentProp.nameLoc, end);
  18032. } else if (currentProp.name === "slot") {
  18033. const arg = currentProp.arg;
  18034. if (arg) {
  18035. arg.content += "." + mod;
  18036. setLocEnd(arg.loc, end);
  18037. }
  18038. } else {
  18039. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  18040. currentProp.modifiers.push(exp);
  18041. }
  18042. },
  18043. onattribdata(start, end) {
  18044. currentAttrValue += getSlice(start, end);
  18045. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  18046. currentAttrEndIndex = end;
  18047. },
  18048. onattribentity(char, start, end) {
  18049. currentAttrValue += char;
  18050. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  18051. currentAttrEndIndex = end;
  18052. },
  18053. onattribnameend(end) {
  18054. const start = currentProp.loc.start.offset;
  18055. const name = getSlice(start, end);
  18056. if (currentProp.type === 7) {
  18057. currentProp.rawName = name;
  18058. }
  18059. if (currentOpenTag.props.some(
  18060. (p) => (p.type === 7 ? p.rawName : p.name) === name
  18061. )) {
  18062. emitError(2, start);
  18063. }
  18064. },
  18065. onattribend(quote, end) {
  18066. if (currentOpenTag && currentProp) {
  18067. setLocEnd(currentProp.loc, end);
  18068. if (quote !== 0) {
  18069. if (currentProp.type === 6) {
  18070. if (currentProp.name === "class") {
  18071. currentAttrValue = condense(currentAttrValue).trim();
  18072. }
  18073. if (quote === 1 && !currentAttrValue) {
  18074. emitError(13, end);
  18075. }
  18076. currentProp.value = {
  18077. type: 2,
  18078. content: currentAttrValue,
  18079. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  18080. };
  18081. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  18082. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  18083. }
  18084. } else {
  18085. let expParseMode = 0 /* Normal */;
  18086. {
  18087. if (currentProp.name === "for") {
  18088. expParseMode = 3 /* Skip */;
  18089. } else if (currentProp.name === "slot") {
  18090. expParseMode = 1 /* Params */;
  18091. } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
  18092. expParseMode = 2 /* Statements */;
  18093. }
  18094. }
  18095. currentProp.exp = createExp(
  18096. currentAttrValue,
  18097. false,
  18098. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  18099. 0,
  18100. expParseMode
  18101. );
  18102. if (currentProp.name === "for") {
  18103. currentProp.forParseResult = parseForExpression(currentProp.exp);
  18104. }
  18105. }
  18106. }
  18107. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  18108. currentOpenTag.props.push(currentProp);
  18109. }
  18110. }
  18111. currentAttrValue = "";
  18112. currentAttrStartIndex = currentAttrEndIndex = -1;
  18113. },
  18114. oncomment(start, end) {
  18115. if (currentOptions.comments) {
  18116. addNode({
  18117. type: 3,
  18118. content: getSlice(start, end),
  18119. loc: getLoc(start - 4, end + 3)
  18120. });
  18121. }
  18122. },
  18123. onend() {
  18124. const end = currentInput.length;
  18125. if (tokenizer.state !== 1) {
  18126. switch (tokenizer.state) {
  18127. case 5:
  18128. case 8:
  18129. emitError(5, end);
  18130. break;
  18131. case 3:
  18132. case 4:
  18133. emitError(
  18134. 25,
  18135. tokenizer.sectionStart
  18136. );
  18137. break;
  18138. case 28:
  18139. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  18140. emitError(6, end);
  18141. } else {
  18142. emitError(7, end);
  18143. }
  18144. break;
  18145. case 6:
  18146. case 7:
  18147. case 9:
  18148. case 11:
  18149. case 12:
  18150. case 13:
  18151. case 14:
  18152. case 15:
  18153. case 16:
  18154. case 17:
  18155. case 18:
  18156. case 19:
  18157. // "
  18158. case 20:
  18159. // '
  18160. case 21:
  18161. emitError(9, end);
  18162. break;
  18163. }
  18164. }
  18165. for (let index = 0; index < stack.length; index++) {
  18166. onCloseTag(stack[index], end - 1);
  18167. emitError(24, stack[index].loc.start.offset);
  18168. }
  18169. },
  18170. oncdata(start, end) {
  18171. if (stack[0].ns !== 0) {
  18172. onText(getSlice(start, end), start, end);
  18173. } else {
  18174. emitError(1, start - 9);
  18175. }
  18176. },
  18177. onprocessinginstruction(start) {
  18178. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  18179. emitError(
  18180. 21,
  18181. start - 1
  18182. );
  18183. }
  18184. }
  18185. });
  18186. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  18187. const stripParensRE = /^\(|\)$/g;
  18188. function parseForExpression(input) {
  18189. const loc = input.loc;
  18190. const exp = input.content;
  18191. const inMatch = exp.match(forAliasRE);
  18192. if (!inMatch) return;
  18193. const [, LHS, RHS] = inMatch;
  18194. const createAliasExpression = (content, offset, asParam = false) => {
  18195. const start = loc.start.offset + offset;
  18196. const end = start + content.length;
  18197. return createExp(
  18198. content,
  18199. false,
  18200. getLoc(start, end),
  18201. 0,
  18202. asParam ? 1 /* Params */ : 0 /* Normal */
  18203. );
  18204. };
  18205. const result = {
  18206. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  18207. value: void 0,
  18208. key: void 0,
  18209. index: void 0,
  18210. finalized: false
  18211. };
  18212. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  18213. const trimmedOffset = LHS.indexOf(valueContent);
  18214. const iteratorMatch = valueContent.match(forIteratorRE);
  18215. if (iteratorMatch) {
  18216. valueContent = valueContent.replace(forIteratorRE, "").trim();
  18217. const keyContent = iteratorMatch[1].trim();
  18218. let keyOffset;
  18219. if (keyContent) {
  18220. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  18221. result.key = createAliasExpression(keyContent, keyOffset, true);
  18222. }
  18223. if (iteratorMatch[2]) {
  18224. const indexContent = iteratorMatch[2].trim();
  18225. if (indexContent) {
  18226. result.index = createAliasExpression(
  18227. indexContent,
  18228. exp.indexOf(
  18229. indexContent,
  18230. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  18231. ),
  18232. true
  18233. );
  18234. }
  18235. }
  18236. }
  18237. if (valueContent) {
  18238. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  18239. }
  18240. return result;
  18241. }
  18242. function getSlice(start, end) {
  18243. return currentInput.slice(start, end);
  18244. }
  18245. function endOpenTag(end) {
  18246. if (tokenizer.inSFCRoot) {
  18247. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  18248. }
  18249. addNode(currentOpenTag);
  18250. const { tag, ns } = currentOpenTag;
  18251. if (ns === 0 && currentOptions.isPreTag(tag)) {
  18252. inPre++;
  18253. }
  18254. if (currentOptions.isVoidTag(tag)) {
  18255. onCloseTag(currentOpenTag, end);
  18256. } else {
  18257. stack.unshift(currentOpenTag);
  18258. if (ns === 1 || ns === 2) {
  18259. tokenizer.inXML = true;
  18260. }
  18261. }
  18262. currentOpenTag = null;
  18263. }
  18264. function onText(content, start, end) {
  18265. const parent = stack[0] || currentRoot;
  18266. const lastNode = parent.children[parent.children.length - 1];
  18267. if (lastNode && lastNode.type === 2) {
  18268. lastNode.content += content;
  18269. setLocEnd(lastNode.loc, end);
  18270. } else {
  18271. parent.children.push({
  18272. type: 2,
  18273. content,
  18274. loc: getLoc(start, end)
  18275. });
  18276. }
  18277. }
  18278. function onCloseTag(el, end, isImplied = false) {
  18279. if (isImplied) {
  18280. setLocEnd(el.loc, backTrack(end, 60));
  18281. } else {
  18282. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  18283. }
  18284. if (tokenizer.inSFCRoot) {
  18285. if (el.children.length) {
  18286. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  18287. } else {
  18288. el.innerLoc.end = extend({}, el.innerLoc.start);
  18289. }
  18290. el.innerLoc.source = getSlice(
  18291. el.innerLoc.start.offset,
  18292. el.innerLoc.end.offset
  18293. );
  18294. }
  18295. const { tag, ns, children } = el;
  18296. if (!inVPre) {
  18297. if (tag === "slot") {
  18298. el.tagType = 2;
  18299. } else if (isFragmentTemplate(el)) {
  18300. el.tagType = 3;
  18301. } else if (isComponent(el)) {
  18302. el.tagType = 1;
  18303. }
  18304. }
  18305. if (!tokenizer.inRCDATA) {
  18306. el.children = condenseWhitespace(children);
  18307. }
  18308. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  18309. const first = children[0];
  18310. if (first && first.type === 2) {
  18311. first.content = first.content.replace(/^\r?\n/, "");
  18312. }
  18313. }
  18314. if (ns === 0 && currentOptions.isPreTag(tag)) {
  18315. inPre--;
  18316. }
  18317. if (currentVPreBoundary === el) {
  18318. inVPre = tokenizer.inVPre = false;
  18319. currentVPreBoundary = null;
  18320. }
  18321. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  18322. tokenizer.inXML = false;
  18323. }
  18324. }
  18325. function lookAhead(index, c) {
  18326. let i = index;
  18327. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  18328. return i;
  18329. }
  18330. function backTrack(index, c) {
  18331. let i = index;
  18332. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  18333. return i;
  18334. }
  18335. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  18336. function isFragmentTemplate({ tag, props }) {
  18337. if (tag === "template") {
  18338. for (let i = 0; i < props.length; i++) {
  18339. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  18340. return true;
  18341. }
  18342. }
  18343. }
  18344. return false;
  18345. }
  18346. function isComponent({ tag, props }) {
  18347. if (currentOptions.isCustomElement(tag)) {
  18348. return false;
  18349. }
  18350. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  18351. return true;
  18352. }
  18353. for (let i = 0; i < props.length; i++) {
  18354. const p = props[i];
  18355. if (p.type === 6) {
  18356. if (p.name === "is" && p.value) {
  18357. if (p.value.content.startsWith("vue:")) {
  18358. return true;
  18359. }
  18360. }
  18361. }
  18362. }
  18363. return false;
  18364. }
  18365. function isUpperCase(c) {
  18366. return c > 64 && c < 91;
  18367. }
  18368. const windowsNewlineRE = /\r\n/g;
  18369. function condenseWhitespace(nodes) {
  18370. const shouldCondense = currentOptions.whitespace !== "preserve";
  18371. let removedWhitespace = false;
  18372. for (let i = 0; i < nodes.length; i++) {
  18373. const node = nodes[i];
  18374. if (node.type === 2) {
  18375. if (!inPre) {
  18376. if (isAllWhitespace(node.content)) {
  18377. const prev = nodes[i - 1] && nodes[i - 1].type;
  18378. const next = nodes[i + 1] && nodes[i + 1].type;
  18379. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  18380. removedWhitespace = true;
  18381. nodes[i] = null;
  18382. } else {
  18383. node.content = " ";
  18384. }
  18385. } else if (shouldCondense) {
  18386. node.content = condense(node.content);
  18387. }
  18388. } else {
  18389. node.content = node.content.replace(windowsNewlineRE, "\n");
  18390. }
  18391. }
  18392. }
  18393. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  18394. }
  18395. function isAllWhitespace(str) {
  18396. for (let i = 0; i < str.length; i++) {
  18397. if (!isWhitespace(str.charCodeAt(i))) {
  18398. return false;
  18399. }
  18400. }
  18401. return true;
  18402. }
  18403. function hasNewlineChar(str) {
  18404. for (let i = 0; i < str.length; i++) {
  18405. const c = str.charCodeAt(i);
  18406. if (c === 10 || c === 13) {
  18407. return true;
  18408. }
  18409. }
  18410. return false;
  18411. }
  18412. function condense(str) {
  18413. let ret = "";
  18414. let prevCharIsWhitespace = false;
  18415. for (let i = 0; i < str.length; i++) {
  18416. if (isWhitespace(str.charCodeAt(i))) {
  18417. if (!prevCharIsWhitespace) {
  18418. ret += " ";
  18419. prevCharIsWhitespace = true;
  18420. }
  18421. } else {
  18422. ret += str[i];
  18423. prevCharIsWhitespace = false;
  18424. }
  18425. }
  18426. return ret;
  18427. }
  18428. function addNode(node) {
  18429. (stack[0] || currentRoot).children.push(node);
  18430. }
  18431. function getLoc(start, end) {
  18432. return {
  18433. start: tokenizer.getPos(start),
  18434. // @ts-expect-error allow late attachment
  18435. end: end == null ? end : tokenizer.getPos(end),
  18436. // @ts-expect-error allow late attachment
  18437. source: end == null ? end : getSlice(start, end)
  18438. };
  18439. }
  18440. function cloneLoc(loc) {
  18441. return getLoc(loc.start.offset, loc.end.offset);
  18442. }
  18443. function setLocEnd(loc, end) {
  18444. loc.end = tokenizer.getPos(end);
  18445. loc.source = getSlice(loc.start.offset, end);
  18446. }
  18447. function dirToAttr(dir) {
  18448. const attr = {
  18449. type: 6,
  18450. name: dir.rawName,
  18451. nameLoc: getLoc(
  18452. dir.loc.start.offset,
  18453. dir.loc.start.offset + dir.rawName.length
  18454. ),
  18455. value: void 0,
  18456. loc: dir.loc
  18457. };
  18458. if (dir.exp) {
  18459. const loc = dir.exp.loc;
  18460. if (loc.end.offset < dir.loc.end.offset) {
  18461. loc.start.offset--;
  18462. loc.start.column--;
  18463. loc.end.offset++;
  18464. loc.end.column++;
  18465. }
  18466. attr.value = {
  18467. type: 2,
  18468. content: dir.exp.content,
  18469. loc
  18470. };
  18471. }
  18472. return attr;
  18473. }
  18474. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  18475. const exp = createSimpleExpression(content, isStatic, loc, constType);
  18476. if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
  18477. if (isSimpleIdentifier(content)) {
  18478. exp.ast = null;
  18479. return exp;
  18480. }
  18481. try {
  18482. const plugins = currentOptions.expressionPlugins;
  18483. const options = {
  18484. plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
  18485. };
  18486. if (parseMode === 2 /* Statements */) {
  18487. exp.ast = libExports.parse(` ${content} `, options).program;
  18488. } else if (parseMode === 1 /* Params */) {
  18489. exp.ast = libExports.parseExpression(`(${content})=>{}`, options);
  18490. } else {
  18491. exp.ast = libExports.parseExpression(`(${content})`, options);
  18492. }
  18493. } catch (e) {
  18494. exp.ast = false;
  18495. emitError(45, loc.start.offset, e.message);
  18496. }
  18497. }
  18498. return exp;
  18499. }
  18500. function emitError(code, index, message) {
  18501. currentOptions.onError(
  18502. createCompilerError(code, getLoc(index, index), void 0, message)
  18503. );
  18504. }
  18505. function reset() {
  18506. tokenizer.reset();
  18507. currentOpenTag = null;
  18508. currentProp = null;
  18509. currentAttrValue = "";
  18510. currentAttrStartIndex = -1;
  18511. currentAttrEndIndex = -1;
  18512. stack.length = 0;
  18513. }
  18514. function baseParse(input, options) {
  18515. reset();
  18516. currentInput = input;
  18517. currentOptions = extend({}, defaultParserOptions);
  18518. if (options) {
  18519. let key;
  18520. for (key in options) {
  18521. if (options[key] != null) {
  18522. currentOptions[key] = options[key];
  18523. }
  18524. }
  18525. }
  18526. {
  18527. if (currentOptions.decodeEntities) {
  18528. console.warn(
  18529. `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
  18530. );
  18531. }
  18532. }
  18533. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  18534. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  18535. const delimiters = options && options.delimiters;
  18536. if (delimiters) {
  18537. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  18538. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  18539. }
  18540. const root = currentRoot = createRoot([], input);
  18541. tokenizer.parse(currentInput);
  18542. root.loc = getLoc(0, input.length);
  18543. root.children = condenseWhitespace(root.children);
  18544. currentRoot = null;
  18545. return root;
  18546. }
  18547. function cacheStatic(root, context) {
  18548. walk$1(
  18549. root,
  18550. void 0,
  18551. context,
  18552. // Root node is unfortunately non-hoistable due to potential parent
  18553. // fallthrough attributes.
  18554. !!getSingleElementRoot(root)
  18555. );
  18556. }
  18557. function getSingleElementRoot(root) {
  18558. const children = root.children.filter((x) => x.type !== 3);
  18559. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  18560. }
  18561. function walk$1(node, parent, context, doNotHoistNode = false, inFor = false) {
  18562. const { children } = node;
  18563. const toCache = [];
  18564. for (let i = 0; i < children.length; i++) {
  18565. const child = children[i];
  18566. if (child.type === 1 && child.tagType === 0) {
  18567. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  18568. if (constantType > 0) {
  18569. if (constantType >= 2) {
  18570. child.codegenNode.patchFlag = -1;
  18571. toCache.push(child);
  18572. continue;
  18573. }
  18574. } else {
  18575. const codegenNode = child.codegenNode;
  18576. if (codegenNode.type === 13) {
  18577. const flag = codegenNode.patchFlag;
  18578. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  18579. const props = getNodeProps(child);
  18580. if (props) {
  18581. codegenNode.props = context.hoist(props);
  18582. }
  18583. }
  18584. if (codegenNode.dynamicProps) {
  18585. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  18586. }
  18587. }
  18588. }
  18589. } else if (child.type === 12) {
  18590. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  18591. if (constantType >= 2) {
  18592. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  18593. child.codegenNode.arguments.push(
  18594. -1 + (` /* ${PatchFlagNames[-1]} */` )
  18595. );
  18596. }
  18597. toCache.push(child);
  18598. continue;
  18599. }
  18600. }
  18601. if (child.type === 1) {
  18602. const isComponent = child.tagType === 1;
  18603. if (isComponent) {
  18604. context.scopes.vSlot++;
  18605. }
  18606. walk$1(child, node, context, false, inFor);
  18607. if (isComponent) {
  18608. context.scopes.vSlot--;
  18609. }
  18610. } else if (child.type === 11) {
  18611. walk$1(child, node, context, child.children.length === 1, true);
  18612. } else if (child.type === 9) {
  18613. for (let i2 = 0; i2 < child.branches.length; i2++) {
  18614. walk$1(
  18615. child.branches[i2],
  18616. node,
  18617. context,
  18618. child.branches[i2].children.length === 1,
  18619. inFor
  18620. );
  18621. }
  18622. }
  18623. }
  18624. let cachedAsArray = false;
  18625. if (toCache.length === children.length && node.type === 1) {
  18626. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  18627. node.codegenNode.children = getCacheExpression(
  18628. createArrayExpression(node.codegenNode.children)
  18629. );
  18630. cachedAsArray = true;
  18631. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray$3(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  18632. const slot = getSlotNode(node.codegenNode, "default");
  18633. if (slot) {
  18634. slot.returns = getCacheExpression(
  18635. createArrayExpression(slot.returns)
  18636. );
  18637. cachedAsArray = true;
  18638. }
  18639. } 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) {
  18640. const slotName = findDir(node, "slot", true);
  18641. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  18642. if (slot) {
  18643. slot.returns = getCacheExpression(
  18644. createArrayExpression(slot.returns)
  18645. );
  18646. cachedAsArray = true;
  18647. }
  18648. }
  18649. }
  18650. if (!cachedAsArray) {
  18651. for (const child of toCache) {
  18652. child.codegenNode = context.cache(child.codegenNode);
  18653. }
  18654. }
  18655. function getCacheExpression(value) {
  18656. const exp = context.cache(value);
  18657. exp.needArraySpread = true;
  18658. return exp;
  18659. }
  18660. function getSlotNode(node2, name) {
  18661. if (node2.children && !isArray$3(node2.children) && node2.children.type === 15) {
  18662. const slot = node2.children.properties.find(
  18663. (p) => p.key === name || p.key.content === name
  18664. );
  18665. return slot && slot.value;
  18666. }
  18667. }
  18668. if (toCache.length && context.transformHoist) {
  18669. context.transformHoist(children, context, node);
  18670. }
  18671. }
  18672. function getConstantType(node, context) {
  18673. const { constantCache } = context;
  18674. switch (node.type) {
  18675. case 1:
  18676. if (node.tagType !== 0) {
  18677. return 0;
  18678. }
  18679. const cached = constantCache.get(node);
  18680. if (cached !== void 0) {
  18681. return cached;
  18682. }
  18683. const codegenNode = node.codegenNode;
  18684. if (codegenNode.type !== 13) {
  18685. return 0;
  18686. }
  18687. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  18688. return 0;
  18689. }
  18690. if (codegenNode.patchFlag === void 0) {
  18691. let returnType2 = 3;
  18692. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  18693. if (generatedPropsType === 0) {
  18694. constantCache.set(node, 0);
  18695. return 0;
  18696. }
  18697. if (generatedPropsType < returnType2) {
  18698. returnType2 = generatedPropsType;
  18699. }
  18700. for (let i = 0; i < node.children.length; i++) {
  18701. const childType = getConstantType(node.children[i], context);
  18702. if (childType === 0) {
  18703. constantCache.set(node, 0);
  18704. return 0;
  18705. }
  18706. if (childType < returnType2) {
  18707. returnType2 = childType;
  18708. }
  18709. }
  18710. if (returnType2 > 1) {
  18711. for (let i = 0; i < node.props.length; i++) {
  18712. const p = node.props[i];
  18713. if (p.type === 7 && p.name === "bind" && p.exp) {
  18714. const expType = getConstantType(p.exp, context);
  18715. if (expType === 0) {
  18716. constantCache.set(node, 0);
  18717. return 0;
  18718. }
  18719. if (expType < returnType2) {
  18720. returnType2 = expType;
  18721. }
  18722. }
  18723. }
  18724. }
  18725. if (codegenNode.isBlock) {
  18726. for (let i = 0; i < node.props.length; i++) {
  18727. const p = node.props[i];
  18728. if (p.type === 7) {
  18729. constantCache.set(node, 0);
  18730. return 0;
  18731. }
  18732. }
  18733. context.removeHelper(OPEN_BLOCK);
  18734. context.removeHelper(
  18735. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  18736. );
  18737. codegenNode.isBlock = false;
  18738. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  18739. }
  18740. constantCache.set(node, returnType2);
  18741. return returnType2;
  18742. } else {
  18743. constantCache.set(node, 0);
  18744. return 0;
  18745. }
  18746. case 2:
  18747. case 3:
  18748. return 3;
  18749. case 9:
  18750. case 11:
  18751. case 10:
  18752. return 0;
  18753. case 5:
  18754. case 12:
  18755. return getConstantType(node.content, context);
  18756. case 4:
  18757. return node.constType;
  18758. case 8:
  18759. let returnType = 3;
  18760. for (let i = 0; i < node.children.length; i++) {
  18761. const child = node.children[i];
  18762. if (isString$1(child) || isSymbol$1(child)) {
  18763. continue;
  18764. }
  18765. const childType = getConstantType(child, context);
  18766. if (childType === 0) {
  18767. return 0;
  18768. } else if (childType < returnType) {
  18769. returnType = childType;
  18770. }
  18771. }
  18772. return returnType;
  18773. case 20:
  18774. return 2;
  18775. default:
  18776. return 0;
  18777. }
  18778. }
  18779. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  18780. NORMALIZE_CLASS,
  18781. NORMALIZE_STYLE,
  18782. NORMALIZE_PROPS,
  18783. GUARD_REACTIVE_PROPS
  18784. ]);
  18785. function getConstantTypeOfHelperCall(value, context) {
  18786. if (value.type === 14 && !isString$1(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  18787. const arg = value.arguments[0];
  18788. if (arg.type === 4) {
  18789. return getConstantType(arg, context);
  18790. } else if (arg.type === 14) {
  18791. return getConstantTypeOfHelperCall(arg, context);
  18792. }
  18793. }
  18794. return 0;
  18795. }
  18796. function getGeneratedPropsConstantType(node, context) {
  18797. let returnType = 3;
  18798. const props = getNodeProps(node);
  18799. if (props && props.type === 15) {
  18800. const { properties } = props;
  18801. for (let i = 0; i < properties.length; i++) {
  18802. const { key, value } = properties[i];
  18803. const keyType = getConstantType(key, context);
  18804. if (keyType === 0) {
  18805. return keyType;
  18806. }
  18807. if (keyType < returnType) {
  18808. returnType = keyType;
  18809. }
  18810. let valueType;
  18811. if (value.type === 4) {
  18812. valueType = getConstantType(value, context);
  18813. } else if (value.type === 14) {
  18814. valueType = getConstantTypeOfHelperCall(value, context);
  18815. } else {
  18816. valueType = 0;
  18817. }
  18818. if (valueType === 0) {
  18819. return valueType;
  18820. }
  18821. if (valueType < returnType) {
  18822. returnType = valueType;
  18823. }
  18824. }
  18825. }
  18826. return returnType;
  18827. }
  18828. function getNodeProps(node) {
  18829. const codegenNode = node.codegenNode;
  18830. if (codegenNode.type === 13) {
  18831. return codegenNode.props;
  18832. }
  18833. }
  18834. function createTransformContext(root, {
  18835. filename = "",
  18836. prefixIdentifiers = false,
  18837. hoistStatic = false,
  18838. hmr = false,
  18839. cacheHandlers = false,
  18840. nodeTransforms = [],
  18841. directiveTransforms = {},
  18842. transformHoist = null,
  18843. isBuiltInComponent = NOOP,
  18844. isCustomElement = NOOP,
  18845. expressionPlugins = [],
  18846. scopeId = null,
  18847. slotted = true,
  18848. ssr = false,
  18849. inSSR = false,
  18850. ssrCssVars = ``,
  18851. bindingMetadata = EMPTY_OBJ,
  18852. inline = false,
  18853. isTS = false,
  18854. onError = defaultOnError,
  18855. onWarn = defaultOnWarn,
  18856. compatConfig
  18857. }) {
  18858. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  18859. const context = {
  18860. // options
  18861. filename,
  18862. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  18863. prefixIdentifiers,
  18864. hoistStatic,
  18865. hmr,
  18866. cacheHandlers,
  18867. nodeTransforms,
  18868. directiveTransforms,
  18869. transformHoist,
  18870. isBuiltInComponent,
  18871. isCustomElement,
  18872. expressionPlugins,
  18873. scopeId,
  18874. slotted,
  18875. ssr,
  18876. inSSR,
  18877. ssrCssVars,
  18878. bindingMetadata,
  18879. inline,
  18880. isTS,
  18881. onError,
  18882. onWarn,
  18883. compatConfig,
  18884. // state
  18885. root,
  18886. helpers: /* @__PURE__ */ new Map(),
  18887. components: /* @__PURE__ */ new Set(),
  18888. directives: /* @__PURE__ */ new Set(),
  18889. hoists: [],
  18890. imports: [],
  18891. cached: [],
  18892. constantCache: /* @__PURE__ */ new WeakMap(),
  18893. temps: 0,
  18894. identifiers: /* @__PURE__ */ Object.create(null),
  18895. scopes: {
  18896. vFor: 0,
  18897. vSlot: 0,
  18898. vPre: 0,
  18899. vOnce: 0
  18900. },
  18901. parent: null,
  18902. grandParent: null,
  18903. currentNode: root,
  18904. childIndex: 0,
  18905. inVOnce: false,
  18906. // methods
  18907. helper(name) {
  18908. const count = context.helpers.get(name) || 0;
  18909. context.helpers.set(name, count + 1);
  18910. return name;
  18911. },
  18912. removeHelper(name) {
  18913. const count = context.helpers.get(name);
  18914. if (count) {
  18915. const currentCount = count - 1;
  18916. if (!currentCount) {
  18917. context.helpers.delete(name);
  18918. } else {
  18919. context.helpers.set(name, currentCount);
  18920. }
  18921. }
  18922. },
  18923. helperString(name) {
  18924. return `_${helperNameMap[context.helper(name)]}`;
  18925. },
  18926. replaceNode(node) {
  18927. {
  18928. if (!context.currentNode) {
  18929. throw new Error(`Node being replaced is already removed.`);
  18930. }
  18931. if (!context.parent) {
  18932. throw new Error(`Cannot replace root node.`);
  18933. }
  18934. }
  18935. context.parent.children[context.childIndex] = context.currentNode = node;
  18936. },
  18937. removeNode(node) {
  18938. if (!context.parent) {
  18939. throw new Error(`Cannot remove root node.`);
  18940. }
  18941. const list = context.parent.children;
  18942. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  18943. if (removalIndex < 0) {
  18944. throw new Error(`node being removed is not a child of current parent`);
  18945. }
  18946. if (!node || node === context.currentNode) {
  18947. context.currentNode = null;
  18948. context.onNodeRemoved();
  18949. } else {
  18950. if (context.childIndex > removalIndex) {
  18951. context.childIndex--;
  18952. context.onNodeRemoved();
  18953. }
  18954. }
  18955. context.parent.children.splice(removalIndex, 1);
  18956. },
  18957. onNodeRemoved: NOOP,
  18958. addIdentifiers(exp) {
  18959. {
  18960. if (isString$1(exp)) {
  18961. addId(exp);
  18962. } else if (exp.identifiers) {
  18963. exp.identifiers.forEach(addId);
  18964. } else if (exp.type === 4) {
  18965. addId(exp.content);
  18966. }
  18967. }
  18968. },
  18969. removeIdentifiers(exp) {
  18970. {
  18971. if (isString$1(exp)) {
  18972. removeId(exp);
  18973. } else if (exp.identifiers) {
  18974. exp.identifiers.forEach(removeId);
  18975. } else if (exp.type === 4) {
  18976. removeId(exp.content);
  18977. }
  18978. }
  18979. },
  18980. hoist(exp) {
  18981. if (isString$1(exp)) exp = createSimpleExpression(exp);
  18982. context.hoists.push(exp);
  18983. const identifier = createSimpleExpression(
  18984. `_hoisted_${context.hoists.length}`,
  18985. false,
  18986. exp.loc,
  18987. 2
  18988. );
  18989. identifier.hoisted = exp;
  18990. return identifier;
  18991. },
  18992. cache(exp, isVNode = false, inVOnce = false) {
  18993. const cacheExp = createCacheExpression(
  18994. context.cached.length,
  18995. exp,
  18996. isVNode,
  18997. inVOnce
  18998. );
  18999. context.cached.push(cacheExp);
  19000. return cacheExp;
  19001. }
  19002. };
  19003. function addId(id) {
  19004. const { identifiers } = context;
  19005. if (identifiers[id] === void 0) {
  19006. identifiers[id] = 0;
  19007. }
  19008. identifiers[id]++;
  19009. }
  19010. function removeId(id) {
  19011. context.identifiers[id]--;
  19012. }
  19013. return context;
  19014. }
  19015. function transform(root, options) {
  19016. const context = createTransformContext(root, options);
  19017. traverseNode(root, context);
  19018. if (options.hoistStatic) {
  19019. cacheStatic(root, context);
  19020. }
  19021. if (!options.ssr) {
  19022. createRootCodegen(root, context);
  19023. }
  19024. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  19025. root.components = [...context.components];
  19026. root.directives = [...context.directives];
  19027. root.imports = context.imports;
  19028. root.hoists = context.hoists;
  19029. root.temps = context.temps;
  19030. root.cached = context.cached;
  19031. root.transformed = true;
  19032. }
  19033. function createRootCodegen(root, context) {
  19034. const { helper } = context;
  19035. const { children } = root;
  19036. if (children.length === 1) {
  19037. const singleElementRootChild = getSingleElementRoot(root);
  19038. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  19039. const codegenNode = singleElementRootChild.codegenNode;
  19040. if (codegenNode.type === 13) {
  19041. convertToBlock(codegenNode, context);
  19042. }
  19043. root.codegenNode = codegenNode;
  19044. } else {
  19045. root.codegenNode = children[0];
  19046. }
  19047. } else if (children.length > 1) {
  19048. let patchFlag = 64;
  19049. if (children.filter((c) => c.type !== 3).length === 1) {
  19050. patchFlag |= 2048;
  19051. }
  19052. root.codegenNode = createVNodeCall(
  19053. context,
  19054. helper(FRAGMENT),
  19055. void 0,
  19056. root.children,
  19057. patchFlag,
  19058. void 0,
  19059. void 0,
  19060. true,
  19061. void 0,
  19062. false
  19063. );
  19064. } else ;
  19065. }
  19066. function traverseChildren(parent, context) {
  19067. let i = 0;
  19068. const nodeRemoved = () => {
  19069. i--;
  19070. };
  19071. for (; i < parent.children.length; i++) {
  19072. const child = parent.children[i];
  19073. if (isString$1(child)) continue;
  19074. context.grandParent = context.parent;
  19075. context.parent = parent;
  19076. context.childIndex = i;
  19077. context.onNodeRemoved = nodeRemoved;
  19078. traverseNode(child, context);
  19079. }
  19080. }
  19081. function traverseNode(node, context) {
  19082. context.currentNode = node;
  19083. const { nodeTransforms } = context;
  19084. const exitFns = [];
  19085. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  19086. const onExit = nodeTransforms[i2](node, context);
  19087. if (onExit) {
  19088. if (isArray$3(onExit)) {
  19089. exitFns.push(...onExit);
  19090. } else {
  19091. exitFns.push(onExit);
  19092. }
  19093. }
  19094. if (!context.currentNode) {
  19095. return;
  19096. } else {
  19097. node = context.currentNode;
  19098. }
  19099. }
  19100. switch (node.type) {
  19101. case 3:
  19102. if (!context.ssr) {
  19103. context.helper(CREATE_COMMENT);
  19104. }
  19105. break;
  19106. case 5:
  19107. if (!context.ssr) {
  19108. context.helper(TO_DISPLAY_STRING);
  19109. }
  19110. break;
  19111. // for container types, further traverse downwards
  19112. case 9:
  19113. for (let i2 = 0; i2 < node.branches.length; i2++) {
  19114. traverseNode(node.branches[i2], context);
  19115. }
  19116. break;
  19117. case 10:
  19118. case 11:
  19119. case 1:
  19120. case 0:
  19121. traverseChildren(node, context);
  19122. break;
  19123. }
  19124. context.currentNode = node;
  19125. let i = exitFns.length;
  19126. while (i--) {
  19127. exitFns[i]();
  19128. }
  19129. }
  19130. function createStructuralDirectiveTransform(name, fn) {
  19131. const matches = isString$1(name) ? (n) => n === name : (n) => name.test(n);
  19132. return (node, context) => {
  19133. if (node.type === 1) {
  19134. const { props } = node;
  19135. if (node.tagType === 3 && props.some(isVSlot)) {
  19136. return;
  19137. }
  19138. const exitFns = [];
  19139. for (let i = 0; i < props.length; i++) {
  19140. const prop = props[i];
  19141. if (prop.type === 7 && matches(prop.name)) {
  19142. props.splice(i, 1);
  19143. i--;
  19144. const onExit = fn(node, prop, context);
  19145. if (onExit) exitFns.push(onExit);
  19146. }
  19147. }
  19148. return exitFns;
  19149. }
  19150. };
  19151. }
  19152. var sourceMap$1 = {};
  19153. var sourceMapGenerator$1 = {};
  19154. var base64Vlq$1 = {};
  19155. var base64$1 = {};
  19156. /* -*- Mode: js; js-indent-level: 2; -*- */
  19157. var hasRequiredBase64$1;
  19158. function requireBase64$1 () {
  19159. if (hasRequiredBase64$1) return base64$1;
  19160. hasRequiredBase64$1 = 1;
  19161. /*
  19162. * Copyright 2011 Mozilla Foundation and contributors
  19163. * Licensed under the New BSD license. See LICENSE or:
  19164. * http://opensource.org/licenses/BSD-3-Clause
  19165. */
  19166. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  19167. /**
  19168. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  19169. */
  19170. base64$1.encode = function (number) {
  19171. if (0 <= number && number < intToCharMap.length) {
  19172. return intToCharMap[number];
  19173. }
  19174. throw new TypeError("Must be between 0 and 63: " + number);
  19175. };
  19176. /**
  19177. * Decode a single base 64 character code digit to an integer. Returns -1 on
  19178. * failure.
  19179. */
  19180. base64$1.decode = function (charCode) {
  19181. var bigA = 65; // 'A'
  19182. var bigZ = 90; // 'Z'
  19183. var littleA = 97; // 'a'
  19184. var littleZ = 122; // 'z'
  19185. var zero = 48; // '0'
  19186. var nine = 57; // '9'
  19187. var plus = 43; // '+'
  19188. var slash = 47; // '/'
  19189. var littleOffset = 26;
  19190. var numberOffset = 52;
  19191. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  19192. if (bigA <= charCode && charCode <= bigZ) {
  19193. return (charCode - bigA);
  19194. }
  19195. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  19196. if (littleA <= charCode && charCode <= littleZ) {
  19197. return (charCode - littleA + littleOffset);
  19198. }
  19199. // 52 - 61: 0123456789
  19200. if (zero <= charCode && charCode <= nine) {
  19201. return (charCode - zero + numberOffset);
  19202. }
  19203. // 62: +
  19204. if (charCode == plus) {
  19205. return 62;
  19206. }
  19207. // 63: /
  19208. if (charCode == slash) {
  19209. return 63;
  19210. }
  19211. // Invalid base64 digit.
  19212. return -1;
  19213. };
  19214. return base64$1;
  19215. }
  19216. /* -*- Mode: js; js-indent-level: 2; -*- */
  19217. var hasRequiredBase64Vlq$1;
  19218. function requireBase64Vlq$1 () {
  19219. if (hasRequiredBase64Vlq$1) return base64Vlq$1;
  19220. hasRequiredBase64Vlq$1 = 1;
  19221. /*
  19222. * Copyright 2011 Mozilla Foundation and contributors
  19223. * Licensed under the New BSD license. See LICENSE or:
  19224. * http://opensource.org/licenses/BSD-3-Clause
  19225. *
  19226. * Based on the Base 64 VLQ implementation in Closure Compiler:
  19227. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  19228. *
  19229. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  19230. * Redistribution and use in source and binary forms, with or without
  19231. * modification, are permitted provided that the following conditions are
  19232. * met:
  19233. *
  19234. * * Redistributions of source code must retain the above copyright
  19235. * notice, this list of conditions and the following disclaimer.
  19236. * * Redistributions in binary form must reproduce the above
  19237. * copyright notice, this list of conditions and the following
  19238. * disclaimer in the documentation and/or other materials provided
  19239. * with the distribution.
  19240. * * Neither the name of Google Inc. nor the names of its
  19241. * contributors may be used to endorse or promote products derived
  19242. * from this software without specific prior written permission.
  19243. *
  19244. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19245. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19246. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19247. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19248. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19249. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19250. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19251. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19252. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19253. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19254. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19255. */
  19256. var base64 = /*@__PURE__*/ requireBase64$1();
  19257. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  19258. // length quantities we use in the source map spec, the first bit is the sign,
  19259. // the next four bits are the actual value, and the 6th bit is the
  19260. // continuation bit. The continuation bit tells us whether there are more
  19261. // digits in this value following this digit.
  19262. //
  19263. // Continuation
  19264. // | Sign
  19265. // | |
  19266. // V V
  19267. // 101011
  19268. var VLQ_BASE_SHIFT = 5;
  19269. // binary: 100000
  19270. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  19271. // binary: 011111
  19272. var VLQ_BASE_MASK = VLQ_BASE - 1;
  19273. // binary: 100000
  19274. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  19275. /**
  19276. * Converts from a two-complement value to a value where the sign bit is
  19277. * placed in the least significant bit. For example, as decimals:
  19278. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  19279. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  19280. */
  19281. function toVLQSigned(aValue) {
  19282. return aValue < 0
  19283. ? ((-aValue) << 1) + 1
  19284. : (aValue << 1) + 0;
  19285. }
  19286. /**
  19287. * Converts to a two-complement value from a value where the sign bit is
  19288. * placed in the least significant bit. For example, as decimals:
  19289. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  19290. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  19291. */
  19292. function fromVLQSigned(aValue) {
  19293. var isNegative = (aValue & 1) === 1;
  19294. var shifted = aValue >> 1;
  19295. return isNegative
  19296. ? -shifted
  19297. : shifted;
  19298. }
  19299. /**
  19300. * Returns the base 64 VLQ encoded value.
  19301. */
  19302. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  19303. var encoded = "";
  19304. var digit;
  19305. var vlq = toVLQSigned(aValue);
  19306. do {
  19307. digit = vlq & VLQ_BASE_MASK;
  19308. vlq >>>= VLQ_BASE_SHIFT;
  19309. if (vlq > 0) {
  19310. // There are still more digits in this value, so we must make sure the
  19311. // continuation bit is marked.
  19312. digit |= VLQ_CONTINUATION_BIT;
  19313. }
  19314. encoded += base64.encode(digit);
  19315. } while (vlq > 0);
  19316. return encoded;
  19317. };
  19318. /**
  19319. * Decodes the next base 64 VLQ value from the given string and returns the
  19320. * value and the rest of the string via the out parameter.
  19321. */
  19322. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  19323. var strLen = aStr.length;
  19324. var result = 0;
  19325. var shift = 0;
  19326. var continuation, digit;
  19327. do {
  19328. if (aIndex >= strLen) {
  19329. throw new Error("Expected more digits in base 64 VLQ value.");
  19330. }
  19331. digit = base64.decode(aStr.charCodeAt(aIndex++));
  19332. if (digit === -1) {
  19333. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  19334. }
  19335. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  19336. digit &= VLQ_BASE_MASK;
  19337. result = result + (digit << shift);
  19338. shift += VLQ_BASE_SHIFT;
  19339. } while (continuation);
  19340. aOutParam.value = fromVLQSigned(result);
  19341. aOutParam.rest = aIndex;
  19342. };
  19343. return base64Vlq$1;
  19344. }
  19345. var util$2 = {};
  19346. /* -*- Mode: js; js-indent-level: 2; -*- */
  19347. var hasRequiredUtil$2;
  19348. function requireUtil$2 () {
  19349. if (hasRequiredUtil$2) return util$2;
  19350. hasRequiredUtil$2 = 1;
  19351. (function (exports) {
  19352. /*
  19353. * Copyright 2011 Mozilla Foundation and contributors
  19354. * Licensed under the New BSD license. See LICENSE or:
  19355. * http://opensource.org/licenses/BSD-3-Clause
  19356. */
  19357. /**
  19358. * This is a helper function for getting values from parameter/options
  19359. * objects.
  19360. *
  19361. * @param args The object we are extracting values from
  19362. * @param name The name of the property we are getting.
  19363. * @param defaultValue An optional value to return if the property is missing
  19364. * from the object. If this is not specified and the property is missing, an
  19365. * error will be thrown.
  19366. */
  19367. function getArg(aArgs, aName, aDefaultValue) {
  19368. if (aName in aArgs) {
  19369. return aArgs[aName];
  19370. } else if (arguments.length === 3) {
  19371. return aDefaultValue;
  19372. } else {
  19373. throw new Error('"' + aName + '" is a required argument.');
  19374. }
  19375. }
  19376. exports.getArg = getArg;
  19377. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  19378. var dataUrlRegexp = /^data:.+\,.+$/;
  19379. function urlParse(aUrl) {
  19380. var match = aUrl.match(urlRegexp);
  19381. if (!match) {
  19382. return null;
  19383. }
  19384. return {
  19385. scheme: match[1],
  19386. auth: match[2],
  19387. host: match[3],
  19388. port: match[4],
  19389. path: match[5]
  19390. };
  19391. }
  19392. exports.urlParse = urlParse;
  19393. function urlGenerate(aParsedUrl) {
  19394. var url = '';
  19395. if (aParsedUrl.scheme) {
  19396. url += aParsedUrl.scheme + ':';
  19397. }
  19398. url += '//';
  19399. if (aParsedUrl.auth) {
  19400. url += aParsedUrl.auth + '@';
  19401. }
  19402. if (aParsedUrl.host) {
  19403. url += aParsedUrl.host;
  19404. }
  19405. if (aParsedUrl.port) {
  19406. url += ":" + aParsedUrl.port;
  19407. }
  19408. if (aParsedUrl.path) {
  19409. url += aParsedUrl.path;
  19410. }
  19411. return url;
  19412. }
  19413. exports.urlGenerate = urlGenerate;
  19414. var MAX_CACHED_INPUTS = 32;
  19415. /**
  19416. * Takes some function `f(input) -> result` and returns a memoized version of
  19417. * `f`.
  19418. *
  19419. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  19420. * memoization is a dumb-simple, linear least-recently-used cache.
  19421. */
  19422. function lruMemoize(f) {
  19423. var cache = [];
  19424. return function(input) {
  19425. for (var i = 0; i < cache.length; i++) {
  19426. if (cache[i].input === input) {
  19427. var temp = cache[0];
  19428. cache[0] = cache[i];
  19429. cache[i] = temp;
  19430. return cache[0].result;
  19431. }
  19432. }
  19433. var result = f(input);
  19434. cache.unshift({
  19435. input,
  19436. result,
  19437. });
  19438. if (cache.length > MAX_CACHED_INPUTS) {
  19439. cache.pop();
  19440. }
  19441. return result;
  19442. };
  19443. }
  19444. /**
  19445. * Normalizes a path, or the path portion of a URL:
  19446. *
  19447. * - Replaces consecutive slashes with one slash.
  19448. * - Removes unnecessary '.' parts.
  19449. * - Removes unnecessary '<dir>/..' parts.
  19450. *
  19451. * Based on code in the Node.js 'path' core module.
  19452. *
  19453. * @param aPath The path or url to normalize.
  19454. */
  19455. var normalize = lruMemoize(function normalize(aPath) {
  19456. var path = aPath;
  19457. var url = urlParse(aPath);
  19458. if (url) {
  19459. if (!url.path) {
  19460. return aPath;
  19461. }
  19462. path = url.path;
  19463. }
  19464. var isAbsolute = exports.isAbsolute(path);
  19465. // Split the path into parts between `/` characters. This is much faster than
  19466. // using `.split(/\/+/g)`.
  19467. var parts = [];
  19468. var start = 0;
  19469. var i = 0;
  19470. while (true) {
  19471. start = i;
  19472. i = path.indexOf("/", start);
  19473. if (i === -1) {
  19474. parts.push(path.slice(start));
  19475. break;
  19476. } else {
  19477. parts.push(path.slice(start, i));
  19478. while (i < path.length && path[i] === "/") {
  19479. i++;
  19480. }
  19481. }
  19482. }
  19483. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  19484. part = parts[i];
  19485. if (part === '.') {
  19486. parts.splice(i, 1);
  19487. } else if (part === '..') {
  19488. up++;
  19489. } else if (up > 0) {
  19490. if (part === '') {
  19491. // The first part is blank if the path is absolute. Trying to go
  19492. // above the root is a no-op. Therefore we can remove all '..' parts
  19493. // directly after the root.
  19494. parts.splice(i + 1, up);
  19495. up = 0;
  19496. } else {
  19497. parts.splice(i, 2);
  19498. up--;
  19499. }
  19500. }
  19501. }
  19502. path = parts.join('/');
  19503. if (path === '') {
  19504. path = isAbsolute ? '/' : '.';
  19505. }
  19506. if (url) {
  19507. url.path = path;
  19508. return urlGenerate(url);
  19509. }
  19510. return path;
  19511. });
  19512. exports.normalize = normalize;
  19513. /**
  19514. * Joins two paths/URLs.
  19515. *
  19516. * @param aRoot The root path or URL.
  19517. * @param aPath The path or URL to be joined with the root.
  19518. *
  19519. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  19520. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  19521. * first.
  19522. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  19523. * is updated with the result and aRoot is returned. Otherwise the result
  19524. * is returned.
  19525. * - If aPath is absolute, the result is aPath.
  19526. * - Otherwise the two paths are joined with a slash.
  19527. * - Joining for example 'http://' and 'www.example.com' is also supported.
  19528. */
  19529. function join(aRoot, aPath) {
  19530. if (aRoot === "") {
  19531. aRoot = ".";
  19532. }
  19533. if (aPath === "") {
  19534. aPath = ".";
  19535. }
  19536. var aPathUrl = urlParse(aPath);
  19537. var aRootUrl = urlParse(aRoot);
  19538. if (aRootUrl) {
  19539. aRoot = aRootUrl.path || '/';
  19540. }
  19541. // `join(foo, '//www.example.org')`
  19542. if (aPathUrl && !aPathUrl.scheme) {
  19543. if (aRootUrl) {
  19544. aPathUrl.scheme = aRootUrl.scheme;
  19545. }
  19546. return urlGenerate(aPathUrl);
  19547. }
  19548. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  19549. return aPath;
  19550. }
  19551. // `join('http://', 'www.example.com')`
  19552. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  19553. aRootUrl.host = aPath;
  19554. return urlGenerate(aRootUrl);
  19555. }
  19556. var joined = aPath.charAt(0) === '/'
  19557. ? aPath
  19558. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  19559. if (aRootUrl) {
  19560. aRootUrl.path = joined;
  19561. return urlGenerate(aRootUrl);
  19562. }
  19563. return joined;
  19564. }
  19565. exports.join = join;
  19566. exports.isAbsolute = function (aPath) {
  19567. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  19568. };
  19569. /**
  19570. * Make a path relative to a URL or another path.
  19571. *
  19572. * @param aRoot The root path or URL.
  19573. * @param aPath The path or URL to be made relative to aRoot.
  19574. */
  19575. function relative(aRoot, aPath) {
  19576. if (aRoot === "") {
  19577. aRoot = ".";
  19578. }
  19579. aRoot = aRoot.replace(/\/$/, '');
  19580. // It is possible for the path to be above the root. In this case, simply
  19581. // checking whether the root is a prefix of the path won't work. Instead, we
  19582. // need to remove components from the root one by one, until either we find
  19583. // a prefix that fits, or we run out of components to remove.
  19584. var level = 0;
  19585. while (aPath.indexOf(aRoot + '/') !== 0) {
  19586. var index = aRoot.lastIndexOf("/");
  19587. if (index < 0) {
  19588. return aPath;
  19589. }
  19590. // If the only part of the root that is left is the scheme (i.e. http://,
  19591. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  19592. // have exhausted all components, so the path is not relative to the root.
  19593. aRoot = aRoot.slice(0, index);
  19594. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  19595. return aPath;
  19596. }
  19597. ++level;
  19598. }
  19599. // Make sure we add a "../" for each component we removed from the root.
  19600. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  19601. }
  19602. exports.relative = relative;
  19603. var supportsNullProto = (function () {
  19604. var obj = Object.create(null);
  19605. return !('__proto__' in obj);
  19606. }());
  19607. function identity (s) {
  19608. return s;
  19609. }
  19610. /**
  19611. * Because behavior goes wacky when you set `__proto__` on objects, we
  19612. * have to prefix all the strings in our set with an arbitrary character.
  19613. *
  19614. * See https://github.com/mozilla/source-map/pull/31 and
  19615. * https://github.com/mozilla/source-map/issues/30
  19616. *
  19617. * @param String aStr
  19618. */
  19619. function toSetString(aStr) {
  19620. if (isProtoString(aStr)) {
  19621. return '$' + aStr;
  19622. }
  19623. return aStr;
  19624. }
  19625. exports.toSetString = supportsNullProto ? identity : toSetString;
  19626. function fromSetString(aStr) {
  19627. if (isProtoString(aStr)) {
  19628. return aStr.slice(1);
  19629. }
  19630. return aStr;
  19631. }
  19632. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  19633. function isProtoString(s) {
  19634. if (!s) {
  19635. return false;
  19636. }
  19637. var length = s.length;
  19638. if (length < 9 /* "__proto__".length */) {
  19639. return false;
  19640. }
  19641. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  19642. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  19643. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  19644. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  19645. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  19646. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  19647. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  19648. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  19649. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  19650. return false;
  19651. }
  19652. for (var i = length - 10; i >= 0; i--) {
  19653. if (s.charCodeAt(i) !== 36 /* '$' */) {
  19654. return false;
  19655. }
  19656. }
  19657. return true;
  19658. }
  19659. /**
  19660. * Comparator between two mappings where the original positions are compared.
  19661. *
  19662. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  19663. * mappings with the same original source/line/column, but different generated
  19664. * line and column the same. Useful when searching for a mapping with a
  19665. * stubbed out mapping.
  19666. */
  19667. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  19668. var cmp = strcmp(mappingA.source, mappingB.source);
  19669. if (cmp !== 0) {
  19670. return cmp;
  19671. }
  19672. cmp = mappingA.originalLine - mappingB.originalLine;
  19673. if (cmp !== 0) {
  19674. return cmp;
  19675. }
  19676. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19677. if (cmp !== 0 || onlyCompareOriginal) {
  19678. return cmp;
  19679. }
  19680. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19681. if (cmp !== 0) {
  19682. return cmp;
  19683. }
  19684. cmp = mappingA.generatedLine - mappingB.generatedLine;
  19685. if (cmp !== 0) {
  19686. return cmp;
  19687. }
  19688. return strcmp(mappingA.name, mappingB.name);
  19689. }
  19690. exports.compareByOriginalPositions = compareByOriginalPositions;
  19691. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  19692. var cmp;
  19693. cmp = mappingA.originalLine - mappingB.originalLine;
  19694. if (cmp !== 0) {
  19695. return cmp;
  19696. }
  19697. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19698. if (cmp !== 0 || onlyCompareOriginal) {
  19699. return cmp;
  19700. }
  19701. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19702. if (cmp !== 0) {
  19703. return cmp;
  19704. }
  19705. cmp = mappingA.generatedLine - mappingB.generatedLine;
  19706. if (cmp !== 0) {
  19707. return cmp;
  19708. }
  19709. return strcmp(mappingA.name, mappingB.name);
  19710. }
  19711. exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  19712. /**
  19713. * Comparator between two mappings with deflated source and name indices where
  19714. * the generated positions are compared.
  19715. *
  19716. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  19717. * mappings with the same generated line and column, but different
  19718. * source/name/original line and column the same. Useful when searching for a
  19719. * mapping with a stubbed out mapping.
  19720. */
  19721. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  19722. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  19723. if (cmp !== 0) {
  19724. return cmp;
  19725. }
  19726. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19727. if (cmp !== 0 || onlyCompareGenerated) {
  19728. return cmp;
  19729. }
  19730. cmp = strcmp(mappingA.source, mappingB.source);
  19731. if (cmp !== 0) {
  19732. return cmp;
  19733. }
  19734. cmp = mappingA.originalLine - mappingB.originalLine;
  19735. if (cmp !== 0) {
  19736. return cmp;
  19737. }
  19738. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19739. if (cmp !== 0) {
  19740. return cmp;
  19741. }
  19742. return strcmp(mappingA.name, mappingB.name);
  19743. }
  19744. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  19745. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  19746. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19747. if (cmp !== 0 || onlyCompareGenerated) {
  19748. return cmp;
  19749. }
  19750. cmp = strcmp(mappingA.source, mappingB.source);
  19751. if (cmp !== 0) {
  19752. return cmp;
  19753. }
  19754. cmp = mappingA.originalLine - mappingB.originalLine;
  19755. if (cmp !== 0) {
  19756. return cmp;
  19757. }
  19758. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19759. if (cmp !== 0) {
  19760. return cmp;
  19761. }
  19762. return strcmp(mappingA.name, mappingB.name);
  19763. }
  19764. exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  19765. function strcmp(aStr1, aStr2) {
  19766. if (aStr1 === aStr2) {
  19767. return 0;
  19768. }
  19769. if (aStr1 === null) {
  19770. return 1; // aStr2 !== null
  19771. }
  19772. if (aStr2 === null) {
  19773. return -1; // aStr1 !== null
  19774. }
  19775. if (aStr1 > aStr2) {
  19776. return 1;
  19777. }
  19778. return -1;
  19779. }
  19780. /**
  19781. * Comparator between two mappings with inflated source and name strings where
  19782. * the generated positions are compared.
  19783. */
  19784. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  19785. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  19786. if (cmp !== 0) {
  19787. return cmp;
  19788. }
  19789. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19790. if (cmp !== 0) {
  19791. return cmp;
  19792. }
  19793. cmp = strcmp(mappingA.source, mappingB.source);
  19794. if (cmp !== 0) {
  19795. return cmp;
  19796. }
  19797. cmp = mappingA.originalLine - mappingB.originalLine;
  19798. if (cmp !== 0) {
  19799. return cmp;
  19800. }
  19801. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19802. if (cmp !== 0) {
  19803. return cmp;
  19804. }
  19805. return strcmp(mappingA.name, mappingB.name);
  19806. }
  19807. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  19808. /**
  19809. * Strip any JSON XSSI avoidance prefix from the string (as documented
  19810. * in the source maps specification), and then parse the string as
  19811. * JSON.
  19812. */
  19813. function parseSourceMapInput(str) {
  19814. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  19815. }
  19816. exports.parseSourceMapInput = parseSourceMapInput;
  19817. /**
  19818. * Compute the URL of a source given the the source root, the source's
  19819. * URL, and the source map's URL.
  19820. */
  19821. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  19822. sourceURL = sourceURL || '';
  19823. if (sourceRoot) {
  19824. // This follows what Chrome does.
  19825. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  19826. sourceRoot += '/';
  19827. }
  19828. // The spec says:
  19829. // Line 4: An optional source root, useful for relocating source
  19830. // files on a server or removing repeated values in the
  19831. // “sources” entry. This value is prepended to the individual
  19832. // entries in the “source” field.
  19833. sourceURL = sourceRoot + sourceURL;
  19834. }
  19835. // Historically, SourceMapConsumer did not take the sourceMapURL as
  19836. // a parameter. This mode is still somewhat supported, which is why
  19837. // this code block is conditional. However, it's preferable to pass
  19838. // the source map URL to SourceMapConsumer, so that this function
  19839. // can implement the source URL resolution algorithm as outlined in
  19840. // the spec. This block is basically the equivalent of:
  19841. // new URL(sourceURL, sourceMapURL).toString()
  19842. // ... except it avoids using URL, which wasn't available in the
  19843. // older releases of node still supported by this library.
  19844. //
  19845. // The spec says:
  19846. // If the sources are not absolute URLs after prepending of the
  19847. // “sourceRoot”, the sources are resolved relative to the
  19848. // SourceMap (like resolving script src in a html document).
  19849. if (sourceMapURL) {
  19850. var parsed = urlParse(sourceMapURL);
  19851. if (!parsed) {
  19852. throw new Error("sourceMapURL could not be parsed");
  19853. }
  19854. if (parsed.path) {
  19855. // Strip the last path component, but keep the "/".
  19856. var index = parsed.path.lastIndexOf('/');
  19857. if (index >= 0) {
  19858. parsed.path = parsed.path.substring(0, index + 1);
  19859. }
  19860. }
  19861. sourceURL = join(urlGenerate(parsed), sourceURL);
  19862. }
  19863. return normalize(sourceURL);
  19864. }
  19865. exports.computeSourceURL = computeSourceURL;
  19866. } (util$2));
  19867. return util$2;
  19868. }
  19869. var arraySet$1 = {};
  19870. /* -*- Mode: js; js-indent-level: 2; -*- */
  19871. var hasRequiredArraySet$1;
  19872. function requireArraySet$1 () {
  19873. if (hasRequiredArraySet$1) return arraySet$1;
  19874. hasRequiredArraySet$1 = 1;
  19875. /*
  19876. * Copyright 2011 Mozilla Foundation and contributors
  19877. * Licensed under the New BSD license. See LICENSE or:
  19878. * http://opensource.org/licenses/BSD-3-Clause
  19879. */
  19880. var util = /*@__PURE__*/ requireUtil$2();
  19881. var has = Object.prototype.hasOwnProperty;
  19882. var hasNativeMap = typeof Map !== "undefined";
  19883. /**
  19884. * A data structure which is a combination of an array and a set. Adding a new
  19885. * member is O(1), testing for membership is O(1), and finding the index of an
  19886. * element is O(1). Removing elements from the set is not supported. Only
  19887. * strings are supported for membership.
  19888. */
  19889. function ArraySet() {
  19890. this._array = [];
  19891. this._set = hasNativeMap ? new Map() : Object.create(null);
  19892. }
  19893. /**
  19894. * Static method for creating ArraySet instances from an existing array.
  19895. */
  19896. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  19897. var set = new ArraySet();
  19898. for (var i = 0, len = aArray.length; i < len; i++) {
  19899. set.add(aArray[i], aAllowDuplicates);
  19900. }
  19901. return set;
  19902. };
  19903. /**
  19904. * Return how many unique items are in this ArraySet. If duplicates have been
  19905. * added, than those do not count towards the size.
  19906. *
  19907. * @returns Number
  19908. */
  19909. ArraySet.prototype.size = function ArraySet_size() {
  19910. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  19911. };
  19912. /**
  19913. * Add the given string to this set.
  19914. *
  19915. * @param String aStr
  19916. */
  19917. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  19918. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  19919. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  19920. var idx = this._array.length;
  19921. if (!isDuplicate || aAllowDuplicates) {
  19922. this._array.push(aStr);
  19923. }
  19924. if (!isDuplicate) {
  19925. if (hasNativeMap) {
  19926. this._set.set(aStr, idx);
  19927. } else {
  19928. this._set[sStr] = idx;
  19929. }
  19930. }
  19931. };
  19932. /**
  19933. * Is the given string a member of this set?
  19934. *
  19935. * @param String aStr
  19936. */
  19937. ArraySet.prototype.has = function ArraySet_has(aStr) {
  19938. if (hasNativeMap) {
  19939. return this._set.has(aStr);
  19940. } else {
  19941. var sStr = util.toSetString(aStr);
  19942. return has.call(this._set, sStr);
  19943. }
  19944. };
  19945. /**
  19946. * What is the index of the given string in the array?
  19947. *
  19948. * @param String aStr
  19949. */
  19950. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  19951. if (hasNativeMap) {
  19952. var idx = this._set.get(aStr);
  19953. if (idx >= 0) {
  19954. return idx;
  19955. }
  19956. } else {
  19957. var sStr = util.toSetString(aStr);
  19958. if (has.call(this._set, sStr)) {
  19959. return this._set[sStr];
  19960. }
  19961. }
  19962. throw new Error('"' + aStr + '" is not in the set.');
  19963. };
  19964. /**
  19965. * What is the element at the given index?
  19966. *
  19967. * @param Number aIdx
  19968. */
  19969. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  19970. if (aIdx >= 0 && aIdx < this._array.length) {
  19971. return this._array[aIdx];
  19972. }
  19973. throw new Error('No element indexed by ' + aIdx);
  19974. };
  19975. /**
  19976. * Returns the array representation of this set (which has the proper indices
  19977. * indicated by indexOf). Note that this is a copy of the internal array used
  19978. * for storing the members so that no one can mess with internal state.
  19979. */
  19980. ArraySet.prototype.toArray = function ArraySet_toArray() {
  19981. return this._array.slice();
  19982. };
  19983. arraySet$1.ArraySet = ArraySet;
  19984. return arraySet$1;
  19985. }
  19986. var mappingList$1 = {};
  19987. /* -*- Mode: js; js-indent-level: 2; -*- */
  19988. var hasRequiredMappingList$1;
  19989. function requireMappingList$1 () {
  19990. if (hasRequiredMappingList$1) return mappingList$1;
  19991. hasRequiredMappingList$1 = 1;
  19992. /*
  19993. * Copyright 2014 Mozilla Foundation and contributors
  19994. * Licensed under the New BSD license. See LICENSE or:
  19995. * http://opensource.org/licenses/BSD-3-Clause
  19996. */
  19997. var util = /*@__PURE__*/ requireUtil$2();
  19998. /**
  19999. * Determine whether mappingB is after mappingA with respect to generated
  20000. * position.
  20001. */
  20002. function generatedPositionAfter(mappingA, mappingB) {
  20003. // Optimized for most common case
  20004. var lineA = mappingA.generatedLine;
  20005. var lineB = mappingB.generatedLine;
  20006. var columnA = mappingA.generatedColumn;
  20007. var columnB = mappingB.generatedColumn;
  20008. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  20009. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  20010. }
  20011. /**
  20012. * A data structure to provide a sorted view of accumulated mappings in a
  20013. * performance conscious manner. It trades a neglibable overhead in general
  20014. * case for a large speedup in case of mappings being added in order.
  20015. */
  20016. function MappingList() {
  20017. this._array = [];
  20018. this._sorted = true;
  20019. // Serves as infimum
  20020. this._last = {generatedLine: -1, generatedColumn: 0};
  20021. }
  20022. /**
  20023. * Iterate through internal items. This method takes the same arguments that
  20024. * `Array.prototype.forEach` takes.
  20025. *
  20026. * NOTE: The order of the mappings is NOT guaranteed.
  20027. */
  20028. MappingList.prototype.unsortedForEach =
  20029. function MappingList_forEach(aCallback, aThisArg) {
  20030. this._array.forEach(aCallback, aThisArg);
  20031. };
  20032. /**
  20033. * Add the given source mapping.
  20034. *
  20035. * @param Object aMapping
  20036. */
  20037. MappingList.prototype.add = function MappingList_add(aMapping) {
  20038. if (generatedPositionAfter(this._last, aMapping)) {
  20039. this._last = aMapping;
  20040. this._array.push(aMapping);
  20041. } else {
  20042. this._sorted = false;
  20043. this._array.push(aMapping);
  20044. }
  20045. };
  20046. /**
  20047. * Returns the flat, sorted array of mappings. The mappings are sorted by
  20048. * generated position.
  20049. *
  20050. * WARNING: This method returns internal data without copying, for
  20051. * performance. The return value must NOT be mutated, and should be treated as
  20052. * an immutable borrow. If you want to take ownership, you must make your own
  20053. * copy.
  20054. */
  20055. MappingList.prototype.toArray = function MappingList_toArray() {
  20056. if (!this._sorted) {
  20057. this._array.sort(util.compareByGeneratedPositionsInflated);
  20058. this._sorted = true;
  20059. }
  20060. return this._array;
  20061. };
  20062. mappingList$1.MappingList = MappingList;
  20063. return mappingList$1;
  20064. }
  20065. /* -*- Mode: js; js-indent-level: 2; -*- */
  20066. var hasRequiredSourceMapGenerator$1;
  20067. function requireSourceMapGenerator$1 () {
  20068. if (hasRequiredSourceMapGenerator$1) return sourceMapGenerator$1;
  20069. hasRequiredSourceMapGenerator$1 = 1;
  20070. /*
  20071. * Copyright 2011 Mozilla Foundation and contributors
  20072. * Licensed under the New BSD license. See LICENSE or:
  20073. * http://opensource.org/licenses/BSD-3-Clause
  20074. */
  20075. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  20076. var util = /*@__PURE__*/ requireUtil$2();
  20077. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  20078. var MappingList = /*@__PURE__*/ requireMappingList$1().MappingList;
  20079. /**
  20080. * An instance of the SourceMapGenerator represents a source map which is
  20081. * being built incrementally. You may pass an object with the following
  20082. * properties:
  20083. *
  20084. * - file: The filename of the generated source.
  20085. * - sourceRoot: A root for all relative URLs in this source map.
  20086. */
  20087. function SourceMapGenerator(aArgs) {
  20088. if (!aArgs) {
  20089. aArgs = {};
  20090. }
  20091. this._file = util.getArg(aArgs, 'file', null);
  20092. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  20093. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  20094. this._ignoreInvalidMapping = util.getArg(aArgs, 'ignoreInvalidMapping', false);
  20095. this._sources = new ArraySet();
  20096. this._names = new ArraySet();
  20097. this._mappings = new MappingList();
  20098. this._sourcesContents = null;
  20099. }
  20100. SourceMapGenerator.prototype._version = 3;
  20101. /**
  20102. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  20103. *
  20104. * @param aSourceMapConsumer The SourceMap.
  20105. */
  20106. SourceMapGenerator.fromSourceMap =
  20107. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
  20108. var sourceRoot = aSourceMapConsumer.sourceRoot;
  20109. var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
  20110. file: aSourceMapConsumer.file,
  20111. sourceRoot: sourceRoot
  20112. }));
  20113. aSourceMapConsumer.eachMapping(function (mapping) {
  20114. var newMapping = {
  20115. generated: {
  20116. line: mapping.generatedLine,
  20117. column: mapping.generatedColumn
  20118. }
  20119. };
  20120. if (mapping.source != null) {
  20121. newMapping.source = mapping.source;
  20122. if (sourceRoot != null) {
  20123. newMapping.source = util.relative(sourceRoot, newMapping.source);
  20124. }
  20125. newMapping.original = {
  20126. line: mapping.originalLine,
  20127. column: mapping.originalColumn
  20128. };
  20129. if (mapping.name != null) {
  20130. newMapping.name = mapping.name;
  20131. }
  20132. }
  20133. generator.addMapping(newMapping);
  20134. });
  20135. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  20136. var sourceRelative = sourceFile;
  20137. if (sourceRoot !== null) {
  20138. sourceRelative = util.relative(sourceRoot, sourceFile);
  20139. }
  20140. if (!generator._sources.has(sourceRelative)) {
  20141. generator._sources.add(sourceRelative);
  20142. }
  20143. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  20144. if (content != null) {
  20145. generator.setSourceContent(sourceFile, content);
  20146. }
  20147. });
  20148. return generator;
  20149. };
  20150. /**
  20151. * Add a single mapping from original source line and column to the generated
  20152. * source's line and column for this source map being created. The mapping
  20153. * object should have the following properties:
  20154. *
  20155. * - generated: An object with the generated line and column positions.
  20156. * - original: An object with the original line and column positions.
  20157. * - source: The original source file (relative to the sourceRoot).
  20158. * - name: An optional original token name for this mapping.
  20159. */
  20160. SourceMapGenerator.prototype.addMapping =
  20161. function SourceMapGenerator_addMapping(aArgs) {
  20162. var generated = util.getArg(aArgs, 'generated');
  20163. var original = util.getArg(aArgs, 'original', null);
  20164. var source = util.getArg(aArgs, 'source', null);
  20165. var name = util.getArg(aArgs, 'name', null);
  20166. if (!this._skipValidation) {
  20167. if (this._validateMapping(generated, original, source, name) === false) {
  20168. return;
  20169. }
  20170. }
  20171. if (source != null) {
  20172. source = String(source);
  20173. if (!this._sources.has(source)) {
  20174. this._sources.add(source);
  20175. }
  20176. }
  20177. if (name != null) {
  20178. name = String(name);
  20179. if (!this._names.has(name)) {
  20180. this._names.add(name);
  20181. }
  20182. }
  20183. this._mappings.add({
  20184. generatedLine: generated.line,
  20185. generatedColumn: generated.column,
  20186. originalLine: original != null && original.line,
  20187. originalColumn: original != null && original.column,
  20188. source: source,
  20189. name: name
  20190. });
  20191. };
  20192. /**
  20193. * Set the source content for a source file.
  20194. */
  20195. SourceMapGenerator.prototype.setSourceContent =
  20196. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  20197. var source = aSourceFile;
  20198. if (this._sourceRoot != null) {
  20199. source = util.relative(this._sourceRoot, source);
  20200. }
  20201. if (aSourceContent != null) {
  20202. // Add the source content to the _sourcesContents map.
  20203. // Create a new _sourcesContents map if the property is null.
  20204. if (!this._sourcesContents) {
  20205. this._sourcesContents = Object.create(null);
  20206. }
  20207. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  20208. } else if (this._sourcesContents) {
  20209. // Remove the source file from the _sourcesContents map.
  20210. // If the _sourcesContents map is empty, set the property to null.
  20211. delete this._sourcesContents[util.toSetString(source)];
  20212. if (Object.keys(this._sourcesContents).length === 0) {
  20213. this._sourcesContents = null;
  20214. }
  20215. }
  20216. };
  20217. /**
  20218. * Applies the mappings of a sub-source-map for a specific source file to the
  20219. * source map being generated. Each mapping to the supplied source file is
  20220. * rewritten using the supplied source map. Note: The resolution for the
  20221. * resulting mappings is the minimium of this map and the supplied map.
  20222. *
  20223. * @param aSourceMapConsumer The source map to be applied.
  20224. * @param aSourceFile Optional. The filename of the source file.
  20225. * If omitted, SourceMapConsumer's file property will be used.
  20226. * @param aSourceMapPath Optional. The dirname of the path to the source map
  20227. * to be applied. If relative, it is relative to the SourceMapConsumer.
  20228. * This parameter is needed when the two source maps aren't in the same
  20229. * directory, and the source map to be applied contains relative source
  20230. * paths. If so, those relative source paths need to be rewritten
  20231. * relative to the SourceMapGenerator.
  20232. */
  20233. SourceMapGenerator.prototype.applySourceMap =
  20234. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  20235. var sourceFile = aSourceFile;
  20236. // If aSourceFile is omitted, we will use the file property of the SourceMap
  20237. if (aSourceFile == null) {
  20238. if (aSourceMapConsumer.file == null) {
  20239. throw new Error(
  20240. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  20241. 'or the source map\'s "file" property. Both were omitted.'
  20242. );
  20243. }
  20244. sourceFile = aSourceMapConsumer.file;
  20245. }
  20246. var sourceRoot = this._sourceRoot;
  20247. // Make "sourceFile" relative if an absolute Url is passed.
  20248. if (sourceRoot != null) {
  20249. sourceFile = util.relative(sourceRoot, sourceFile);
  20250. }
  20251. // Applying the SourceMap can add and remove items from the sources and
  20252. // the names array.
  20253. var newSources = new ArraySet();
  20254. var newNames = new ArraySet();
  20255. // Find mappings for the "sourceFile"
  20256. this._mappings.unsortedForEach(function (mapping) {
  20257. if (mapping.source === sourceFile && mapping.originalLine != null) {
  20258. // Check if it can be mapped by the source map, then update the mapping.
  20259. var original = aSourceMapConsumer.originalPositionFor({
  20260. line: mapping.originalLine,
  20261. column: mapping.originalColumn
  20262. });
  20263. if (original.source != null) {
  20264. // Copy mapping
  20265. mapping.source = original.source;
  20266. if (aSourceMapPath != null) {
  20267. mapping.source = util.join(aSourceMapPath, mapping.source);
  20268. }
  20269. if (sourceRoot != null) {
  20270. mapping.source = util.relative(sourceRoot, mapping.source);
  20271. }
  20272. mapping.originalLine = original.line;
  20273. mapping.originalColumn = original.column;
  20274. if (original.name != null) {
  20275. mapping.name = original.name;
  20276. }
  20277. }
  20278. }
  20279. var source = mapping.source;
  20280. if (source != null && !newSources.has(source)) {
  20281. newSources.add(source);
  20282. }
  20283. var name = mapping.name;
  20284. if (name != null && !newNames.has(name)) {
  20285. newNames.add(name);
  20286. }
  20287. }, this);
  20288. this._sources = newSources;
  20289. this._names = newNames;
  20290. // Copy sourcesContents of applied map.
  20291. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  20292. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  20293. if (content != null) {
  20294. if (aSourceMapPath != null) {
  20295. sourceFile = util.join(aSourceMapPath, sourceFile);
  20296. }
  20297. if (sourceRoot != null) {
  20298. sourceFile = util.relative(sourceRoot, sourceFile);
  20299. }
  20300. this.setSourceContent(sourceFile, content);
  20301. }
  20302. }, this);
  20303. };
  20304. /**
  20305. * A mapping can have one of the three levels of data:
  20306. *
  20307. * 1. Just the generated position.
  20308. * 2. The Generated position, original position, and original source.
  20309. * 3. Generated and original position, original source, as well as a name
  20310. * token.
  20311. *
  20312. * To maintain consistency, we validate that any new mapping being added falls
  20313. * in to one of these categories.
  20314. */
  20315. SourceMapGenerator.prototype._validateMapping =
  20316. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  20317. aName) {
  20318. // When aOriginal is truthy but has empty values for .line and .column,
  20319. // it is most likely a programmer error. In this case we throw a very
  20320. // specific error message to try to guide them the right way.
  20321. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  20322. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  20323. var message = 'original.line and original.column are not numbers -- you probably meant to omit ' +
  20324. 'the original mapping entirely and only map the generated position. If so, pass ' +
  20325. 'null for the original mapping instead of an object with empty or null values.';
  20326. if (this._ignoreInvalidMapping) {
  20327. if (typeof console !== 'undefined' && console.warn) {
  20328. console.warn(message);
  20329. }
  20330. return false;
  20331. } else {
  20332. throw new Error(message);
  20333. }
  20334. }
  20335. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  20336. && aGenerated.line > 0 && aGenerated.column >= 0
  20337. && !aOriginal && !aSource && !aName) {
  20338. // Case 1.
  20339. return;
  20340. }
  20341. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  20342. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  20343. && aGenerated.line > 0 && aGenerated.column >= 0
  20344. && aOriginal.line > 0 && aOriginal.column >= 0
  20345. && aSource) {
  20346. // Cases 2 and 3.
  20347. return;
  20348. }
  20349. else {
  20350. var message = 'Invalid mapping: ' + JSON.stringify({
  20351. generated: aGenerated,
  20352. source: aSource,
  20353. original: aOriginal,
  20354. name: aName
  20355. });
  20356. if (this._ignoreInvalidMapping) {
  20357. if (typeof console !== 'undefined' && console.warn) {
  20358. console.warn(message);
  20359. }
  20360. return false;
  20361. } else {
  20362. throw new Error(message)
  20363. }
  20364. }
  20365. };
  20366. /**
  20367. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  20368. * specified by the source map format.
  20369. */
  20370. SourceMapGenerator.prototype._serializeMappings =
  20371. function SourceMapGenerator_serializeMappings() {
  20372. var previousGeneratedColumn = 0;
  20373. var previousGeneratedLine = 1;
  20374. var previousOriginalColumn = 0;
  20375. var previousOriginalLine = 0;
  20376. var previousName = 0;
  20377. var previousSource = 0;
  20378. var result = '';
  20379. var next;
  20380. var mapping;
  20381. var nameIdx;
  20382. var sourceIdx;
  20383. var mappings = this._mappings.toArray();
  20384. for (var i = 0, len = mappings.length; i < len; i++) {
  20385. mapping = mappings[i];
  20386. next = '';
  20387. if (mapping.generatedLine !== previousGeneratedLine) {
  20388. previousGeneratedColumn = 0;
  20389. while (mapping.generatedLine !== previousGeneratedLine) {
  20390. next += ';';
  20391. previousGeneratedLine++;
  20392. }
  20393. }
  20394. else {
  20395. if (i > 0) {
  20396. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  20397. continue;
  20398. }
  20399. next += ',';
  20400. }
  20401. }
  20402. next += base64VLQ.encode(mapping.generatedColumn
  20403. - previousGeneratedColumn);
  20404. previousGeneratedColumn = mapping.generatedColumn;
  20405. if (mapping.source != null) {
  20406. sourceIdx = this._sources.indexOf(mapping.source);
  20407. next += base64VLQ.encode(sourceIdx - previousSource);
  20408. previousSource = sourceIdx;
  20409. // lines are stored 0-based in SourceMap spec version 3
  20410. next += base64VLQ.encode(mapping.originalLine - 1
  20411. - previousOriginalLine);
  20412. previousOriginalLine = mapping.originalLine - 1;
  20413. next += base64VLQ.encode(mapping.originalColumn
  20414. - previousOriginalColumn);
  20415. previousOriginalColumn = mapping.originalColumn;
  20416. if (mapping.name != null) {
  20417. nameIdx = this._names.indexOf(mapping.name);
  20418. next += base64VLQ.encode(nameIdx - previousName);
  20419. previousName = nameIdx;
  20420. }
  20421. }
  20422. result += next;
  20423. }
  20424. return result;
  20425. };
  20426. SourceMapGenerator.prototype._generateSourcesContent =
  20427. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  20428. return aSources.map(function (source) {
  20429. if (!this._sourcesContents) {
  20430. return null;
  20431. }
  20432. if (aSourceRoot != null) {
  20433. source = util.relative(aSourceRoot, source);
  20434. }
  20435. var key = util.toSetString(source);
  20436. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  20437. ? this._sourcesContents[key]
  20438. : null;
  20439. }, this);
  20440. };
  20441. /**
  20442. * Externalize the source map.
  20443. */
  20444. SourceMapGenerator.prototype.toJSON =
  20445. function SourceMapGenerator_toJSON() {
  20446. var map = {
  20447. version: this._version,
  20448. sources: this._sources.toArray(),
  20449. names: this._names.toArray(),
  20450. mappings: this._serializeMappings()
  20451. };
  20452. if (this._file != null) {
  20453. map.file = this._file;
  20454. }
  20455. if (this._sourceRoot != null) {
  20456. map.sourceRoot = this._sourceRoot;
  20457. }
  20458. if (this._sourcesContents) {
  20459. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  20460. }
  20461. return map;
  20462. };
  20463. /**
  20464. * Render the source map being generated to a string.
  20465. */
  20466. SourceMapGenerator.prototype.toString =
  20467. function SourceMapGenerator_toString() {
  20468. return JSON.stringify(this.toJSON());
  20469. };
  20470. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator;
  20471. return sourceMapGenerator$1;
  20472. }
  20473. var sourceMapConsumer$1 = {};
  20474. var binarySearch$1 = {};
  20475. /* -*- Mode: js; js-indent-level: 2; -*- */
  20476. var hasRequiredBinarySearch$1;
  20477. function requireBinarySearch$1 () {
  20478. if (hasRequiredBinarySearch$1) return binarySearch$1;
  20479. hasRequiredBinarySearch$1 = 1;
  20480. (function (exports) {
  20481. /*
  20482. * Copyright 2011 Mozilla Foundation and contributors
  20483. * Licensed under the New BSD license. See LICENSE or:
  20484. * http://opensource.org/licenses/BSD-3-Clause
  20485. */
  20486. exports.GREATEST_LOWER_BOUND = 1;
  20487. exports.LEAST_UPPER_BOUND = 2;
  20488. /**
  20489. * Recursive implementation of binary search.
  20490. *
  20491. * @param aLow Indices here and lower do not contain the needle.
  20492. * @param aHigh Indices here and higher do not contain the needle.
  20493. * @param aNeedle The element being searched for.
  20494. * @param aHaystack The non-empty array being searched.
  20495. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  20496. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  20497. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  20498. * closest element that is smaller than or greater than the one we are
  20499. * searching for, respectively, if the exact element cannot be found.
  20500. */
  20501. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  20502. // This function terminates when one of the following is true:
  20503. //
  20504. // 1. We find the exact element we are looking for.
  20505. //
  20506. // 2. We did not find the exact element, but we can return the index of
  20507. // the next-closest element.
  20508. //
  20509. // 3. We did not find the exact element, and there is no next-closest
  20510. // element than the one we are searching for, so we return -1.
  20511. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  20512. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  20513. if (cmp === 0) {
  20514. // Found the element we are looking for.
  20515. return mid;
  20516. }
  20517. else if (cmp > 0) {
  20518. // Our needle is greater than aHaystack[mid].
  20519. if (aHigh - mid > 1) {
  20520. // The element is in the upper half.
  20521. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  20522. }
  20523. // The exact needle element was not found in this haystack. Determine if
  20524. // we are in termination case (3) or (2) and return the appropriate thing.
  20525. if (aBias == exports.LEAST_UPPER_BOUND) {
  20526. return aHigh < aHaystack.length ? aHigh : -1;
  20527. } else {
  20528. return mid;
  20529. }
  20530. }
  20531. else {
  20532. // Our needle is less than aHaystack[mid].
  20533. if (mid - aLow > 1) {
  20534. // The element is in the lower half.
  20535. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  20536. }
  20537. // we are in termination case (3) or (2) and return the appropriate thing.
  20538. if (aBias == exports.LEAST_UPPER_BOUND) {
  20539. return mid;
  20540. } else {
  20541. return aLow < 0 ? -1 : aLow;
  20542. }
  20543. }
  20544. }
  20545. /**
  20546. * This is an implementation of binary search which will always try and return
  20547. * the index of the closest element if there is no exact hit. This is because
  20548. * mappings between original and generated line/col pairs are single points,
  20549. * and there is an implicit region between each of them, so a miss just means
  20550. * that you aren't on the very start of a region.
  20551. *
  20552. * @param aNeedle The element you are looking for.
  20553. * @param aHaystack The array that is being searched.
  20554. * @param aCompare A function which takes the needle and an element in the
  20555. * array and returns -1, 0, or 1 depending on whether the needle is less
  20556. * than, equal to, or greater than the element, respectively.
  20557. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  20558. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  20559. * closest element that is smaller than or greater than the one we are
  20560. * searching for, respectively, if the exact element cannot be found.
  20561. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  20562. */
  20563. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  20564. if (aHaystack.length === 0) {
  20565. return -1;
  20566. }
  20567. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  20568. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  20569. if (index < 0) {
  20570. return -1;
  20571. }
  20572. // We have found either the exact element, or the next-closest element than
  20573. // the one we are searching for. However, there may be more than one such
  20574. // element. Make sure we always return the smallest of these.
  20575. while (index - 1 >= 0) {
  20576. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  20577. break;
  20578. }
  20579. --index;
  20580. }
  20581. return index;
  20582. };
  20583. } (binarySearch$1));
  20584. return binarySearch$1;
  20585. }
  20586. var quickSort$1 = {};
  20587. /* -*- Mode: js; js-indent-level: 2; -*- */
  20588. var hasRequiredQuickSort$1;
  20589. function requireQuickSort$1 () {
  20590. if (hasRequiredQuickSort$1) return quickSort$1;
  20591. hasRequiredQuickSort$1 = 1;
  20592. /*
  20593. * Copyright 2011 Mozilla Foundation and contributors
  20594. * Licensed under the New BSD license. See LICENSE or:
  20595. * http://opensource.org/licenses/BSD-3-Clause
  20596. */
  20597. // It turns out that some (most?) JavaScript engines don't self-host
  20598. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  20599. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  20600. // custom comparator function, calling back and forth between the VM's C++ and
  20601. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  20602. // worse generated code for the comparator function than would be optimal. In
  20603. // fact, when sorting with a comparator, these costs outweigh the benefits of
  20604. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  20605. // a ~3500ms mean speed-up in `bench/bench.html`.
  20606. function SortTemplate(comparator) {
  20607. /**
  20608. * Swap the elements indexed by `x` and `y` in the array `ary`.
  20609. *
  20610. * @param {Array} ary
  20611. * The array.
  20612. * @param {Number} x
  20613. * The index of the first item.
  20614. * @param {Number} y
  20615. * The index of the second item.
  20616. */
  20617. function swap(ary, x, y) {
  20618. var temp = ary[x];
  20619. ary[x] = ary[y];
  20620. ary[y] = temp;
  20621. }
  20622. /**
  20623. * Returns a random integer within the range `low .. high` inclusive.
  20624. *
  20625. * @param {Number} low
  20626. * The lower bound on the range.
  20627. * @param {Number} high
  20628. * The upper bound on the range.
  20629. */
  20630. function randomIntInRange(low, high) {
  20631. return Math.round(low + (Math.random() * (high - low)));
  20632. }
  20633. /**
  20634. * The Quick Sort algorithm.
  20635. *
  20636. * @param {Array} ary
  20637. * An array to sort.
  20638. * @param {function} comparator
  20639. * Function to use to compare two items.
  20640. * @param {Number} p
  20641. * Start index of the array
  20642. * @param {Number} r
  20643. * End index of the array
  20644. */
  20645. function doQuickSort(ary, comparator, p, r) {
  20646. // If our lower bound is less than our upper bound, we (1) partition the
  20647. // array into two pieces and (2) recurse on each half. If it is not, this is
  20648. // the empty array and our base case.
  20649. if (p < r) {
  20650. // (1) Partitioning.
  20651. //
  20652. // The partitioning chooses a pivot between `p` and `r` and moves all
  20653. // elements that are less than or equal to the pivot to the before it, and
  20654. // all the elements that are greater than it after it. The effect is that
  20655. // once partition is done, the pivot is in the exact place it will be when
  20656. // the array is put in sorted order, and it will not need to be moved
  20657. // again. This runs in O(n) time.
  20658. // Always choose a random pivot so that an input array which is reverse
  20659. // sorted does not cause O(n^2) running time.
  20660. var pivotIndex = randomIntInRange(p, r);
  20661. var i = p - 1;
  20662. swap(ary, pivotIndex, r);
  20663. var pivot = ary[r];
  20664. // Immediately after `j` is incremented in this loop, the following hold
  20665. // true:
  20666. //
  20667. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  20668. //
  20669. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  20670. for (var j = p; j < r; j++) {
  20671. if (comparator(ary[j], pivot, false) <= 0) {
  20672. i += 1;
  20673. swap(ary, i, j);
  20674. }
  20675. }
  20676. swap(ary, i + 1, j);
  20677. var q = i + 1;
  20678. // (2) Recurse on each half.
  20679. doQuickSort(ary, comparator, p, q - 1);
  20680. doQuickSort(ary, comparator, q + 1, r);
  20681. }
  20682. }
  20683. return doQuickSort;
  20684. }
  20685. function cloneSort(comparator) {
  20686. let template = SortTemplate.toString();
  20687. let templateFn = new Function(`return ${template}`)();
  20688. return templateFn(comparator);
  20689. }
  20690. /**
  20691. * Sort the given array in-place with the given comparator function.
  20692. *
  20693. * @param {Array} ary
  20694. * An array to sort.
  20695. * @param {function} comparator
  20696. * Function to use to compare two items.
  20697. */
  20698. let sortCache = new WeakMap();
  20699. quickSort$1.quickSort = function (ary, comparator, start = 0) {
  20700. let doQuickSort = sortCache.get(comparator);
  20701. if (doQuickSort === void 0) {
  20702. doQuickSort = cloneSort(comparator);
  20703. sortCache.set(comparator, doQuickSort);
  20704. }
  20705. doQuickSort(ary, comparator, start, ary.length - 1);
  20706. };
  20707. return quickSort$1;
  20708. }
  20709. /* -*- Mode: js; js-indent-level: 2; -*- */
  20710. var hasRequiredSourceMapConsumer$1;
  20711. function requireSourceMapConsumer$1 () {
  20712. if (hasRequiredSourceMapConsumer$1) return sourceMapConsumer$1;
  20713. hasRequiredSourceMapConsumer$1 = 1;
  20714. /*
  20715. * Copyright 2011 Mozilla Foundation and contributors
  20716. * Licensed under the New BSD license. See LICENSE or:
  20717. * http://opensource.org/licenses/BSD-3-Clause
  20718. */
  20719. var util = /*@__PURE__*/ requireUtil$2();
  20720. var binarySearch = /*@__PURE__*/ requireBinarySearch$1();
  20721. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  20722. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  20723. var quickSort = /*@__PURE__*/ requireQuickSort$1().quickSort;
  20724. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  20725. var sourceMap = aSourceMap;
  20726. if (typeof aSourceMap === 'string') {
  20727. sourceMap = util.parseSourceMapInput(aSourceMap);
  20728. }
  20729. return sourceMap.sections != null
  20730. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  20731. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  20732. }
  20733. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  20734. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  20735. };
  20736. /**
  20737. * The version of the source mapping spec that we are consuming.
  20738. */
  20739. SourceMapConsumer.prototype._version = 3;
  20740. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  20741. // parsed mapping coordinates from the source map's "mappings" attribute. They
  20742. // are lazily instantiated, accessed via the `_generatedMappings` and
  20743. // `_originalMappings` getters respectively, and we only parse the mappings
  20744. // and create these arrays once queried for a source location. We jump through
  20745. // these hoops because there can be many thousands of mappings, and parsing
  20746. // them is expensive, so we only want to do it if we must.
  20747. //
  20748. // Each object in the arrays is of the form:
  20749. //
  20750. // {
  20751. // generatedLine: The line number in the generated code,
  20752. // generatedColumn: The column number in the generated code,
  20753. // source: The path to the original source file that generated this
  20754. // chunk of code,
  20755. // originalLine: The line number in the original source that
  20756. // corresponds to this chunk of generated code,
  20757. // originalColumn: The column number in the original source that
  20758. // corresponds to this chunk of generated code,
  20759. // name: The name of the original symbol which generated this chunk of
  20760. // code.
  20761. // }
  20762. //
  20763. // All properties except for `generatedLine` and `generatedColumn` can be
  20764. // `null`.
  20765. //
  20766. // `_generatedMappings` is ordered by the generated positions.
  20767. //
  20768. // `_originalMappings` is ordered by the original positions.
  20769. SourceMapConsumer.prototype.__generatedMappings = null;
  20770. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  20771. configurable: true,
  20772. enumerable: true,
  20773. get: function () {
  20774. if (!this.__generatedMappings) {
  20775. this._parseMappings(this._mappings, this.sourceRoot);
  20776. }
  20777. return this.__generatedMappings;
  20778. }
  20779. });
  20780. SourceMapConsumer.prototype.__originalMappings = null;
  20781. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  20782. configurable: true,
  20783. enumerable: true,
  20784. get: function () {
  20785. if (!this.__originalMappings) {
  20786. this._parseMappings(this._mappings, this.sourceRoot);
  20787. }
  20788. return this.__originalMappings;
  20789. }
  20790. });
  20791. SourceMapConsumer.prototype._charIsMappingSeparator =
  20792. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  20793. var c = aStr.charAt(index);
  20794. return c === ";" || c === ",";
  20795. };
  20796. /**
  20797. * Parse the mappings in a string in to a data structure which we can easily
  20798. * query (the ordered arrays in the `this.__generatedMappings` and
  20799. * `this.__originalMappings` properties).
  20800. */
  20801. SourceMapConsumer.prototype._parseMappings =
  20802. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  20803. throw new Error("Subclasses must implement _parseMappings");
  20804. };
  20805. SourceMapConsumer.GENERATED_ORDER = 1;
  20806. SourceMapConsumer.ORIGINAL_ORDER = 2;
  20807. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  20808. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  20809. /**
  20810. * Iterate over each mapping between an original source/line/column and a
  20811. * generated line/column in this source map.
  20812. *
  20813. * @param Function aCallback
  20814. * The function that is called with each mapping.
  20815. * @param Object aContext
  20816. * Optional. If specified, this object will be the value of `this` every
  20817. * time that `aCallback` is called.
  20818. * @param aOrder
  20819. * Either `SourceMapConsumer.GENERATED_ORDER` or
  20820. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  20821. * iterate over the mappings sorted by the generated file's line/column
  20822. * order or the original's source/line/column order, respectively. Defaults to
  20823. * `SourceMapConsumer.GENERATED_ORDER`.
  20824. */
  20825. SourceMapConsumer.prototype.eachMapping =
  20826. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  20827. var context = aContext || null;
  20828. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  20829. var mappings;
  20830. switch (order) {
  20831. case SourceMapConsumer.GENERATED_ORDER:
  20832. mappings = this._generatedMappings;
  20833. break;
  20834. case SourceMapConsumer.ORIGINAL_ORDER:
  20835. mappings = this._originalMappings;
  20836. break;
  20837. default:
  20838. throw new Error("Unknown order of iteration.");
  20839. }
  20840. var sourceRoot = this.sourceRoot;
  20841. var boundCallback = aCallback.bind(context);
  20842. var names = this._names;
  20843. var sources = this._sources;
  20844. var sourceMapURL = this._sourceMapURL;
  20845. for (var i = 0, n = mappings.length; i < n; i++) {
  20846. var mapping = mappings[i];
  20847. var source = mapping.source === null ? null : sources.at(mapping.source);
  20848. if(source !== null) {
  20849. source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
  20850. }
  20851. boundCallback({
  20852. source: source,
  20853. generatedLine: mapping.generatedLine,
  20854. generatedColumn: mapping.generatedColumn,
  20855. originalLine: mapping.originalLine,
  20856. originalColumn: mapping.originalColumn,
  20857. name: mapping.name === null ? null : names.at(mapping.name)
  20858. });
  20859. }
  20860. };
  20861. /**
  20862. * Returns all generated line and column information for the original source,
  20863. * line, and column provided. If no column is provided, returns all mappings
  20864. * corresponding to a either the line we are searching for or the next
  20865. * closest line that has any mappings. Otherwise, returns all mappings
  20866. * corresponding to the given line and either the column we are searching for
  20867. * or the next closest column that has any offsets.
  20868. *
  20869. * The only argument is an object with the following properties:
  20870. *
  20871. * - source: The filename of the original source.
  20872. * - line: The line number in the original source. The line number is 1-based.
  20873. * - column: Optional. the column number in the original source.
  20874. * The column number is 0-based.
  20875. *
  20876. * and an array of objects is returned, each with the following properties:
  20877. *
  20878. * - line: The line number in the generated source, or null. The
  20879. * line number is 1-based.
  20880. * - column: The column number in the generated source, or null.
  20881. * The column number is 0-based.
  20882. */
  20883. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  20884. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  20885. var line = util.getArg(aArgs, 'line');
  20886. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  20887. // returns the index of the closest mapping less than the needle. By
  20888. // setting needle.originalColumn to 0, we thus find the last mapping for
  20889. // the given line, provided such a mapping exists.
  20890. var needle = {
  20891. source: util.getArg(aArgs, 'source'),
  20892. originalLine: line,
  20893. originalColumn: util.getArg(aArgs, 'column', 0)
  20894. };
  20895. needle.source = this._findSourceIndex(needle.source);
  20896. if (needle.source < 0) {
  20897. return [];
  20898. }
  20899. var mappings = [];
  20900. var index = this._findMapping(needle,
  20901. this._originalMappings,
  20902. "originalLine",
  20903. "originalColumn",
  20904. util.compareByOriginalPositions,
  20905. binarySearch.LEAST_UPPER_BOUND);
  20906. if (index >= 0) {
  20907. var mapping = this._originalMappings[index];
  20908. if (aArgs.column === undefined) {
  20909. var originalLine = mapping.originalLine;
  20910. // Iterate until either we run out of mappings, or we run into
  20911. // a mapping for a different line than the one we found. Since
  20912. // mappings are sorted, this is guaranteed to find all mappings for
  20913. // the line we found.
  20914. while (mapping && mapping.originalLine === originalLine) {
  20915. mappings.push({
  20916. line: util.getArg(mapping, 'generatedLine', null),
  20917. column: util.getArg(mapping, 'generatedColumn', null),
  20918. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  20919. });
  20920. mapping = this._originalMappings[++index];
  20921. }
  20922. } else {
  20923. var originalColumn = mapping.originalColumn;
  20924. // Iterate until either we run out of mappings, or we run into
  20925. // a mapping for a different line than the one we were searching for.
  20926. // Since mappings are sorted, this is guaranteed to find all mappings for
  20927. // the line we are searching for.
  20928. while (mapping &&
  20929. mapping.originalLine === line &&
  20930. mapping.originalColumn == originalColumn) {
  20931. mappings.push({
  20932. line: util.getArg(mapping, 'generatedLine', null),
  20933. column: util.getArg(mapping, 'generatedColumn', null),
  20934. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  20935. });
  20936. mapping = this._originalMappings[++index];
  20937. }
  20938. }
  20939. }
  20940. return mappings;
  20941. };
  20942. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer;
  20943. /**
  20944. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  20945. * query for information about the original file positions by giving it a file
  20946. * position in the generated source.
  20947. *
  20948. * The first parameter is the raw source map (either as a JSON string, or
  20949. * already parsed to an object). According to the spec, source maps have the
  20950. * following attributes:
  20951. *
  20952. * - version: Which version of the source map spec this map is following.
  20953. * - sources: An array of URLs to the original source files.
  20954. * - names: An array of identifiers which can be referrenced by individual mappings.
  20955. * - sourceRoot: Optional. The URL root from which all sources are relative.
  20956. * - sourcesContent: Optional. An array of contents of the original source files.
  20957. * - mappings: A string of base64 VLQs which contain the actual mappings.
  20958. * - file: Optional. The generated file this source map is associated with.
  20959. *
  20960. * Here is an example source map, taken from the source map spec[0]:
  20961. *
  20962. * {
  20963. * version : 3,
  20964. * file: "out.js",
  20965. * sourceRoot : "",
  20966. * sources: ["foo.js", "bar.js"],
  20967. * names: ["src", "maps", "are", "fun"],
  20968. * mappings: "AA,AB;;ABCDE;"
  20969. * }
  20970. *
  20971. * The second parameter, if given, is a string whose value is the URL
  20972. * at which the source map was found. This URL is used to compute the
  20973. * sources array.
  20974. *
  20975. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  20976. */
  20977. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  20978. var sourceMap = aSourceMap;
  20979. if (typeof aSourceMap === 'string') {
  20980. sourceMap = util.parseSourceMapInput(aSourceMap);
  20981. }
  20982. var version = util.getArg(sourceMap, 'version');
  20983. var sources = util.getArg(sourceMap, 'sources');
  20984. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  20985. // requires the array) to play nice here.
  20986. var names = util.getArg(sourceMap, 'names', []);
  20987. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  20988. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  20989. var mappings = util.getArg(sourceMap, 'mappings');
  20990. var file = util.getArg(sourceMap, 'file', null);
  20991. // Once again, Sass deviates from the spec and supplies the version as a
  20992. // string rather than a number, so we use loose equality checking here.
  20993. if (version != this._version) {
  20994. throw new Error('Unsupported version: ' + version);
  20995. }
  20996. if (sourceRoot) {
  20997. sourceRoot = util.normalize(sourceRoot);
  20998. }
  20999. sources = sources
  21000. .map(String)
  21001. // Some source maps produce relative source paths like "./foo.js" instead of
  21002. // "foo.js". Normalize these first so that future comparisons will succeed.
  21003. // See bugzil.la/1090768.
  21004. .map(util.normalize)
  21005. // Always ensure that absolute sources are internally stored relative to
  21006. // the source root, if the source root is absolute. Not doing this would
  21007. // be particularly problematic when the source root is a prefix of the
  21008. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  21009. .map(function (source) {
  21010. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  21011. ? util.relative(sourceRoot, source)
  21012. : source;
  21013. });
  21014. // Pass `true` below to allow duplicate names and sources. While source maps
  21015. // are intended to be compressed and deduplicated, the TypeScript compiler
  21016. // sometimes generates source maps with duplicates in them. See Github issue
  21017. // #72 and bugzil.la/889492.
  21018. this._names = ArraySet.fromArray(names.map(String), true);
  21019. this._sources = ArraySet.fromArray(sources, true);
  21020. this._absoluteSources = this._sources.toArray().map(function (s) {
  21021. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  21022. });
  21023. this.sourceRoot = sourceRoot;
  21024. this.sourcesContent = sourcesContent;
  21025. this._mappings = mappings;
  21026. this._sourceMapURL = aSourceMapURL;
  21027. this.file = file;
  21028. }
  21029. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  21030. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  21031. /**
  21032. * Utility function to find the index of a source. Returns -1 if not
  21033. * found.
  21034. */
  21035. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  21036. var relativeSource = aSource;
  21037. if (this.sourceRoot != null) {
  21038. relativeSource = util.relative(this.sourceRoot, relativeSource);
  21039. }
  21040. if (this._sources.has(relativeSource)) {
  21041. return this._sources.indexOf(relativeSource);
  21042. }
  21043. // Maybe aSource is an absolute URL as returned by |sources|. In
  21044. // this case we can't simply undo the transform.
  21045. var i;
  21046. for (i = 0; i < this._absoluteSources.length; ++i) {
  21047. if (this._absoluteSources[i] == aSource) {
  21048. return i;
  21049. }
  21050. }
  21051. return -1;
  21052. };
  21053. /**
  21054. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  21055. *
  21056. * @param SourceMapGenerator aSourceMap
  21057. * The source map that will be consumed.
  21058. * @param String aSourceMapURL
  21059. * The URL at which the source map can be found (optional)
  21060. * @returns BasicSourceMapConsumer
  21061. */
  21062. BasicSourceMapConsumer.fromSourceMap =
  21063. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  21064. var smc = Object.create(BasicSourceMapConsumer.prototype);
  21065. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  21066. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  21067. smc.sourceRoot = aSourceMap._sourceRoot;
  21068. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  21069. smc.sourceRoot);
  21070. smc.file = aSourceMap._file;
  21071. smc._sourceMapURL = aSourceMapURL;
  21072. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  21073. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  21074. });
  21075. // Because we are modifying the entries (by converting string sources and
  21076. // names to indices into the sources and names ArraySets), we have to make
  21077. // a copy of the entry or else bad things happen. Shared mutable state
  21078. // strikes again! See github issue #191.
  21079. var generatedMappings = aSourceMap._mappings.toArray().slice();
  21080. var destGeneratedMappings = smc.__generatedMappings = [];
  21081. var destOriginalMappings = smc.__originalMappings = [];
  21082. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  21083. var srcMapping = generatedMappings[i];
  21084. var destMapping = new Mapping;
  21085. destMapping.generatedLine = srcMapping.generatedLine;
  21086. destMapping.generatedColumn = srcMapping.generatedColumn;
  21087. if (srcMapping.source) {
  21088. destMapping.source = sources.indexOf(srcMapping.source);
  21089. destMapping.originalLine = srcMapping.originalLine;
  21090. destMapping.originalColumn = srcMapping.originalColumn;
  21091. if (srcMapping.name) {
  21092. destMapping.name = names.indexOf(srcMapping.name);
  21093. }
  21094. destOriginalMappings.push(destMapping);
  21095. }
  21096. destGeneratedMappings.push(destMapping);
  21097. }
  21098. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  21099. return smc;
  21100. };
  21101. /**
  21102. * The version of the source mapping spec that we are consuming.
  21103. */
  21104. BasicSourceMapConsumer.prototype._version = 3;
  21105. /**
  21106. * The list of original sources.
  21107. */
  21108. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  21109. get: function () {
  21110. return this._absoluteSources.slice();
  21111. }
  21112. });
  21113. /**
  21114. * Provide the JIT with a nice shape / hidden class.
  21115. */
  21116. function Mapping() {
  21117. this.generatedLine = 0;
  21118. this.generatedColumn = 0;
  21119. this.source = null;
  21120. this.originalLine = null;
  21121. this.originalColumn = null;
  21122. this.name = null;
  21123. }
  21124. /**
  21125. * Parse the mappings in a string in to a data structure which we can easily
  21126. * query (the ordered arrays in the `this.__generatedMappings` and
  21127. * `this.__originalMappings` properties).
  21128. */
  21129. const compareGenerated = util.compareByGeneratedPositionsDeflatedNoLine;
  21130. function sortGenerated(array, start) {
  21131. let l = array.length;
  21132. let n = array.length - start;
  21133. if (n <= 1) {
  21134. return;
  21135. } else if (n == 2) {
  21136. let a = array[start];
  21137. let b = array[start + 1];
  21138. if (compareGenerated(a, b) > 0) {
  21139. array[start] = b;
  21140. array[start + 1] = a;
  21141. }
  21142. } else if (n < 20) {
  21143. for (let i = start; i < l; i++) {
  21144. for (let j = i; j > start; j--) {
  21145. let a = array[j - 1];
  21146. let b = array[j];
  21147. if (compareGenerated(a, b) <= 0) {
  21148. break;
  21149. }
  21150. array[j - 1] = b;
  21151. array[j] = a;
  21152. }
  21153. }
  21154. } else {
  21155. quickSort(array, compareGenerated, start);
  21156. }
  21157. }
  21158. BasicSourceMapConsumer.prototype._parseMappings =
  21159. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  21160. var generatedLine = 1;
  21161. var previousGeneratedColumn = 0;
  21162. var previousOriginalLine = 0;
  21163. var previousOriginalColumn = 0;
  21164. var previousSource = 0;
  21165. var previousName = 0;
  21166. var length = aStr.length;
  21167. var index = 0;
  21168. var temp = {};
  21169. var originalMappings = [];
  21170. var generatedMappings = [];
  21171. var mapping, segment, end, value;
  21172. let subarrayStart = 0;
  21173. while (index < length) {
  21174. if (aStr.charAt(index) === ';') {
  21175. generatedLine++;
  21176. index++;
  21177. previousGeneratedColumn = 0;
  21178. sortGenerated(generatedMappings, subarrayStart);
  21179. subarrayStart = generatedMappings.length;
  21180. }
  21181. else if (aStr.charAt(index) === ',') {
  21182. index++;
  21183. }
  21184. else {
  21185. mapping = new Mapping();
  21186. mapping.generatedLine = generatedLine;
  21187. for (end = index; end < length; end++) {
  21188. if (this._charIsMappingSeparator(aStr, end)) {
  21189. break;
  21190. }
  21191. }
  21192. aStr.slice(index, end);
  21193. segment = [];
  21194. while (index < end) {
  21195. base64VLQ.decode(aStr, index, temp);
  21196. value = temp.value;
  21197. index = temp.rest;
  21198. segment.push(value);
  21199. }
  21200. if (segment.length === 2) {
  21201. throw new Error('Found a source, but no line and column');
  21202. }
  21203. if (segment.length === 3) {
  21204. throw new Error('Found a source and line, but no column');
  21205. }
  21206. // Generated column.
  21207. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  21208. previousGeneratedColumn = mapping.generatedColumn;
  21209. if (segment.length > 1) {
  21210. // Original source.
  21211. mapping.source = previousSource + segment[1];
  21212. previousSource += segment[1];
  21213. // Original line.
  21214. mapping.originalLine = previousOriginalLine + segment[2];
  21215. previousOriginalLine = mapping.originalLine;
  21216. // Lines are stored 0-based
  21217. mapping.originalLine += 1;
  21218. // Original column.
  21219. mapping.originalColumn = previousOriginalColumn + segment[3];
  21220. previousOriginalColumn = mapping.originalColumn;
  21221. if (segment.length > 4) {
  21222. // Original name.
  21223. mapping.name = previousName + segment[4];
  21224. previousName += segment[4];
  21225. }
  21226. }
  21227. generatedMappings.push(mapping);
  21228. if (typeof mapping.originalLine === 'number') {
  21229. let currentSource = mapping.source;
  21230. while (originalMappings.length <= currentSource) {
  21231. originalMappings.push(null);
  21232. }
  21233. if (originalMappings[currentSource] === null) {
  21234. originalMappings[currentSource] = [];
  21235. }
  21236. originalMappings[currentSource].push(mapping);
  21237. }
  21238. }
  21239. }
  21240. sortGenerated(generatedMappings, subarrayStart);
  21241. this.__generatedMappings = generatedMappings;
  21242. for (var i = 0; i < originalMappings.length; i++) {
  21243. if (originalMappings[i] != null) {
  21244. quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource);
  21245. }
  21246. }
  21247. this.__originalMappings = [].concat(...originalMappings);
  21248. };
  21249. /**
  21250. * Find the mapping that best matches the hypothetical "needle" mapping that
  21251. * we are searching for in the given "haystack" of mappings.
  21252. */
  21253. BasicSourceMapConsumer.prototype._findMapping =
  21254. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  21255. aColumnName, aComparator, aBias) {
  21256. // To return the position we are searching for, we must first find the
  21257. // mapping for the given position and then return the opposite position it
  21258. // points to. Because the mappings are sorted, we can use binary search to
  21259. // find the best mapping.
  21260. if (aNeedle[aLineName] <= 0) {
  21261. throw new TypeError('Line must be greater than or equal to 1, got '
  21262. + aNeedle[aLineName]);
  21263. }
  21264. if (aNeedle[aColumnName] < 0) {
  21265. throw new TypeError('Column must be greater than or equal to 0, got '
  21266. + aNeedle[aColumnName]);
  21267. }
  21268. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  21269. };
  21270. /**
  21271. * Compute the last column for each generated mapping. The last column is
  21272. * inclusive.
  21273. */
  21274. BasicSourceMapConsumer.prototype.computeColumnSpans =
  21275. function SourceMapConsumer_computeColumnSpans() {
  21276. for (var index = 0; index < this._generatedMappings.length; ++index) {
  21277. var mapping = this._generatedMappings[index];
  21278. // Mappings do not contain a field for the last generated columnt. We
  21279. // can come up with an optimistic estimate, however, by assuming that
  21280. // mappings are contiguous (i.e. given two consecutive mappings, the
  21281. // first mapping ends where the second one starts).
  21282. if (index + 1 < this._generatedMappings.length) {
  21283. var nextMapping = this._generatedMappings[index + 1];
  21284. if (mapping.generatedLine === nextMapping.generatedLine) {
  21285. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  21286. continue;
  21287. }
  21288. }
  21289. // The last mapping for each line spans the entire line.
  21290. mapping.lastGeneratedColumn = Infinity;
  21291. }
  21292. };
  21293. /**
  21294. * Returns the original source, line, and column information for the generated
  21295. * source's line and column positions provided. The only argument is an object
  21296. * with the following properties:
  21297. *
  21298. * - line: The line number in the generated source. The line number
  21299. * is 1-based.
  21300. * - column: The column number in the generated source. The column
  21301. * number is 0-based.
  21302. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  21303. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  21304. * closest element that is smaller than or greater than the one we are
  21305. * searching for, respectively, if the exact element cannot be found.
  21306. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  21307. *
  21308. * and an object is returned with the following properties:
  21309. *
  21310. * - source: The original source file, or null.
  21311. * - line: The line number in the original source, or null. The
  21312. * line number is 1-based.
  21313. * - column: The column number in the original source, or null. The
  21314. * column number is 0-based.
  21315. * - name: The original identifier, or null.
  21316. */
  21317. BasicSourceMapConsumer.prototype.originalPositionFor =
  21318. function SourceMapConsumer_originalPositionFor(aArgs) {
  21319. var needle = {
  21320. generatedLine: util.getArg(aArgs, 'line'),
  21321. generatedColumn: util.getArg(aArgs, 'column')
  21322. };
  21323. var index = this._findMapping(
  21324. needle,
  21325. this._generatedMappings,
  21326. "generatedLine",
  21327. "generatedColumn",
  21328. util.compareByGeneratedPositionsDeflated,
  21329. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  21330. );
  21331. if (index >= 0) {
  21332. var mapping = this._generatedMappings[index];
  21333. if (mapping.generatedLine === needle.generatedLine) {
  21334. var source = util.getArg(mapping, 'source', null);
  21335. if (source !== null) {
  21336. source = this._sources.at(source);
  21337. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  21338. }
  21339. var name = util.getArg(mapping, 'name', null);
  21340. if (name !== null) {
  21341. name = this._names.at(name);
  21342. }
  21343. return {
  21344. source: source,
  21345. line: util.getArg(mapping, 'originalLine', null),
  21346. column: util.getArg(mapping, 'originalColumn', null),
  21347. name: name
  21348. };
  21349. }
  21350. }
  21351. return {
  21352. source: null,
  21353. line: null,
  21354. column: null,
  21355. name: null
  21356. };
  21357. };
  21358. /**
  21359. * Return true if we have the source content for every source in the source
  21360. * map, false otherwise.
  21361. */
  21362. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  21363. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  21364. if (!this.sourcesContent) {
  21365. return false;
  21366. }
  21367. return this.sourcesContent.length >= this._sources.size() &&
  21368. !this.sourcesContent.some(function (sc) { return sc == null; });
  21369. };
  21370. /**
  21371. * Returns the original source content. The only argument is the url of the
  21372. * original source file. Returns null if no original source content is
  21373. * available.
  21374. */
  21375. BasicSourceMapConsumer.prototype.sourceContentFor =
  21376. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  21377. if (!this.sourcesContent) {
  21378. return null;
  21379. }
  21380. var index = this._findSourceIndex(aSource);
  21381. if (index >= 0) {
  21382. return this.sourcesContent[index];
  21383. }
  21384. var relativeSource = aSource;
  21385. if (this.sourceRoot != null) {
  21386. relativeSource = util.relative(this.sourceRoot, relativeSource);
  21387. }
  21388. var url;
  21389. if (this.sourceRoot != null
  21390. && (url = util.urlParse(this.sourceRoot))) {
  21391. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  21392. // many users. We can help them out when they expect file:// URIs to
  21393. // behave like it would if they were running a local HTTP server. See
  21394. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  21395. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  21396. if (url.scheme == "file"
  21397. && this._sources.has(fileUriAbsPath)) {
  21398. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  21399. }
  21400. if ((!url.path || url.path == "/")
  21401. && this._sources.has("/" + relativeSource)) {
  21402. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  21403. }
  21404. }
  21405. // This function is used recursively from
  21406. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  21407. // don't want to throw if we can't find the source - we just want to
  21408. // return null, so we provide a flag to exit gracefully.
  21409. if (nullOnMissing) {
  21410. return null;
  21411. }
  21412. else {
  21413. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  21414. }
  21415. };
  21416. /**
  21417. * Returns the generated line and column information for the original source,
  21418. * line, and column positions provided. The only argument is an object with
  21419. * the following properties:
  21420. *
  21421. * - source: The filename of the original source.
  21422. * - line: The line number in the original source. The line number
  21423. * is 1-based.
  21424. * - column: The column number in the original source. The column
  21425. * number is 0-based.
  21426. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  21427. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  21428. * closest element that is smaller than or greater than the one we are
  21429. * searching for, respectively, if the exact element cannot be found.
  21430. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  21431. *
  21432. * and an object is returned with the following properties:
  21433. *
  21434. * - line: The line number in the generated source, or null. The
  21435. * line number is 1-based.
  21436. * - column: The column number in the generated source, or null.
  21437. * The column number is 0-based.
  21438. */
  21439. BasicSourceMapConsumer.prototype.generatedPositionFor =
  21440. function SourceMapConsumer_generatedPositionFor(aArgs) {
  21441. var source = util.getArg(aArgs, 'source');
  21442. source = this._findSourceIndex(source);
  21443. if (source < 0) {
  21444. return {
  21445. line: null,
  21446. column: null,
  21447. lastColumn: null
  21448. };
  21449. }
  21450. var needle = {
  21451. source: source,
  21452. originalLine: util.getArg(aArgs, 'line'),
  21453. originalColumn: util.getArg(aArgs, 'column')
  21454. };
  21455. var index = this._findMapping(
  21456. needle,
  21457. this._originalMappings,
  21458. "originalLine",
  21459. "originalColumn",
  21460. util.compareByOriginalPositions,
  21461. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  21462. );
  21463. if (index >= 0) {
  21464. var mapping = this._originalMappings[index];
  21465. if (mapping.source === needle.source) {
  21466. return {
  21467. line: util.getArg(mapping, 'generatedLine', null),
  21468. column: util.getArg(mapping, 'generatedColumn', null),
  21469. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  21470. };
  21471. }
  21472. }
  21473. return {
  21474. line: null,
  21475. column: null,
  21476. lastColumn: null
  21477. };
  21478. };
  21479. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer;
  21480. /**
  21481. * An IndexedSourceMapConsumer instance represents a parsed source map which
  21482. * we can query for information. It differs from BasicSourceMapConsumer in
  21483. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  21484. * input.
  21485. *
  21486. * The first parameter is a raw source map (either as a JSON string, or already
  21487. * parsed to an object). According to the spec for indexed source maps, they
  21488. * have the following attributes:
  21489. *
  21490. * - version: Which version of the source map spec this map is following.
  21491. * - file: Optional. The generated file this source map is associated with.
  21492. * - sections: A list of section definitions.
  21493. *
  21494. * Each value under the "sections" field has two fields:
  21495. * - offset: The offset into the original specified at which this section
  21496. * begins to apply, defined as an object with a "line" and "column"
  21497. * field.
  21498. * - map: A source map definition. This source map could also be indexed,
  21499. * but doesn't have to be.
  21500. *
  21501. * Instead of the "map" field, it's also possible to have a "url" field
  21502. * specifying a URL to retrieve a source map from, but that's currently
  21503. * unsupported.
  21504. *
  21505. * Here's an example source map, taken from the source map spec[0], but
  21506. * modified to omit a section which uses the "url" field.
  21507. *
  21508. * {
  21509. * version : 3,
  21510. * file: "app.js",
  21511. * sections: [{
  21512. * offset: {line:100, column:10},
  21513. * map: {
  21514. * version : 3,
  21515. * file: "section.js",
  21516. * sources: ["foo.js", "bar.js"],
  21517. * names: ["src", "maps", "are", "fun"],
  21518. * mappings: "AAAA,E;;ABCDE;"
  21519. * }
  21520. * }],
  21521. * }
  21522. *
  21523. * The second parameter, if given, is a string whose value is the URL
  21524. * at which the source map was found. This URL is used to compute the
  21525. * sources array.
  21526. *
  21527. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  21528. */
  21529. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  21530. var sourceMap = aSourceMap;
  21531. if (typeof aSourceMap === 'string') {
  21532. sourceMap = util.parseSourceMapInput(aSourceMap);
  21533. }
  21534. var version = util.getArg(sourceMap, 'version');
  21535. var sections = util.getArg(sourceMap, 'sections');
  21536. if (version != this._version) {
  21537. throw new Error('Unsupported version: ' + version);
  21538. }
  21539. this._sources = new ArraySet();
  21540. this._names = new ArraySet();
  21541. var lastOffset = {
  21542. line: -1,
  21543. column: 0
  21544. };
  21545. this._sections = sections.map(function (s) {
  21546. if (s.url) {
  21547. // The url field will require support for asynchronicity.
  21548. // See https://github.com/mozilla/source-map/issues/16
  21549. throw new Error('Support for url field in sections not implemented.');
  21550. }
  21551. var offset = util.getArg(s, 'offset');
  21552. var offsetLine = util.getArg(offset, 'line');
  21553. var offsetColumn = util.getArg(offset, 'column');
  21554. if (offsetLine < lastOffset.line ||
  21555. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  21556. throw new Error('Section offsets must be ordered and non-overlapping.');
  21557. }
  21558. lastOffset = offset;
  21559. return {
  21560. generatedOffset: {
  21561. // The offset fields are 0-based, but we use 1-based indices when
  21562. // encoding/decoding from VLQ.
  21563. generatedLine: offsetLine + 1,
  21564. generatedColumn: offsetColumn + 1
  21565. },
  21566. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  21567. }
  21568. });
  21569. }
  21570. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  21571. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  21572. /**
  21573. * The version of the source mapping spec that we are consuming.
  21574. */
  21575. IndexedSourceMapConsumer.prototype._version = 3;
  21576. /**
  21577. * The list of original sources.
  21578. */
  21579. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  21580. get: function () {
  21581. var sources = [];
  21582. for (var i = 0; i < this._sections.length; i++) {
  21583. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  21584. sources.push(this._sections[i].consumer.sources[j]);
  21585. }
  21586. }
  21587. return sources;
  21588. }
  21589. });
  21590. /**
  21591. * Returns the original source, line, and column information for the generated
  21592. * source's line and column positions provided. The only argument is an object
  21593. * with the following properties:
  21594. *
  21595. * - line: The line number in the generated source. The line number
  21596. * is 1-based.
  21597. * - column: The column number in the generated source. The column
  21598. * number is 0-based.
  21599. *
  21600. * and an object is returned with the following properties:
  21601. *
  21602. * - source: The original source file, or null.
  21603. * - line: The line number in the original source, or null. The
  21604. * line number is 1-based.
  21605. * - column: The column number in the original source, or null. The
  21606. * column number is 0-based.
  21607. * - name: The original identifier, or null.
  21608. */
  21609. IndexedSourceMapConsumer.prototype.originalPositionFor =
  21610. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  21611. var needle = {
  21612. generatedLine: util.getArg(aArgs, 'line'),
  21613. generatedColumn: util.getArg(aArgs, 'column')
  21614. };
  21615. // Find the section containing the generated position we're trying to map
  21616. // to an original position.
  21617. var sectionIndex = binarySearch.search(needle, this._sections,
  21618. function(needle, section) {
  21619. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  21620. if (cmp) {
  21621. return cmp;
  21622. }
  21623. return (needle.generatedColumn -
  21624. section.generatedOffset.generatedColumn);
  21625. });
  21626. var section = this._sections[sectionIndex];
  21627. if (!section) {
  21628. return {
  21629. source: null,
  21630. line: null,
  21631. column: null,
  21632. name: null
  21633. };
  21634. }
  21635. return section.consumer.originalPositionFor({
  21636. line: needle.generatedLine -
  21637. (section.generatedOffset.generatedLine - 1),
  21638. column: needle.generatedColumn -
  21639. (section.generatedOffset.generatedLine === needle.generatedLine
  21640. ? section.generatedOffset.generatedColumn - 1
  21641. : 0),
  21642. bias: aArgs.bias
  21643. });
  21644. };
  21645. /**
  21646. * Return true if we have the source content for every source in the source
  21647. * map, false otherwise.
  21648. */
  21649. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  21650. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  21651. return this._sections.every(function (s) {
  21652. return s.consumer.hasContentsOfAllSources();
  21653. });
  21654. };
  21655. /**
  21656. * Returns the original source content. The only argument is the url of the
  21657. * original source file. Returns null if no original source content is
  21658. * available.
  21659. */
  21660. IndexedSourceMapConsumer.prototype.sourceContentFor =
  21661. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  21662. for (var i = 0; i < this._sections.length; i++) {
  21663. var section = this._sections[i];
  21664. var content = section.consumer.sourceContentFor(aSource, true);
  21665. if (content || content === '') {
  21666. return content;
  21667. }
  21668. }
  21669. if (nullOnMissing) {
  21670. return null;
  21671. }
  21672. else {
  21673. throw new Error('"' + aSource + '" is not in the SourceMap.');
  21674. }
  21675. };
  21676. /**
  21677. * Returns the generated line and column information for the original source,
  21678. * line, and column positions provided. The only argument is an object with
  21679. * the following properties:
  21680. *
  21681. * - source: The filename of the original source.
  21682. * - line: The line number in the original source. The line number
  21683. * is 1-based.
  21684. * - column: The column number in the original source. The column
  21685. * number is 0-based.
  21686. *
  21687. * and an object is returned with the following properties:
  21688. *
  21689. * - line: The line number in the generated source, or null. The
  21690. * line number is 1-based.
  21691. * - column: The column number in the generated source, or null.
  21692. * The column number is 0-based.
  21693. */
  21694. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  21695. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  21696. for (var i = 0; i < this._sections.length; i++) {
  21697. var section = this._sections[i];
  21698. // Only consider this section if the requested source is in the list of
  21699. // sources of the consumer.
  21700. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  21701. continue;
  21702. }
  21703. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  21704. if (generatedPosition) {
  21705. var ret = {
  21706. line: generatedPosition.line +
  21707. (section.generatedOffset.generatedLine - 1),
  21708. column: generatedPosition.column +
  21709. (section.generatedOffset.generatedLine === generatedPosition.line
  21710. ? section.generatedOffset.generatedColumn - 1
  21711. : 0)
  21712. };
  21713. return ret;
  21714. }
  21715. }
  21716. return {
  21717. line: null,
  21718. column: null
  21719. };
  21720. };
  21721. /**
  21722. * Parse the mappings in a string in to a data structure which we can easily
  21723. * query (the ordered arrays in the `this.__generatedMappings` and
  21724. * `this.__originalMappings` properties).
  21725. */
  21726. IndexedSourceMapConsumer.prototype._parseMappings =
  21727. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  21728. this.__generatedMappings = [];
  21729. this.__originalMappings = [];
  21730. for (var i = 0; i < this._sections.length; i++) {
  21731. var section = this._sections[i];
  21732. var sectionMappings = section.consumer._generatedMappings;
  21733. for (var j = 0; j < sectionMappings.length; j++) {
  21734. var mapping = sectionMappings[j];
  21735. var source = section.consumer._sources.at(mapping.source);
  21736. if(source !== null) {
  21737. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  21738. }
  21739. this._sources.add(source);
  21740. source = this._sources.indexOf(source);
  21741. var name = null;
  21742. if (mapping.name) {
  21743. name = section.consumer._names.at(mapping.name);
  21744. this._names.add(name);
  21745. name = this._names.indexOf(name);
  21746. }
  21747. // The mappings coming from the consumer for the section have
  21748. // generated positions relative to the start of the section, so we
  21749. // need to offset them to be relative to the start of the concatenated
  21750. // generated file.
  21751. var adjustedMapping = {
  21752. source: source,
  21753. generatedLine: mapping.generatedLine +
  21754. (section.generatedOffset.generatedLine - 1),
  21755. generatedColumn: mapping.generatedColumn +
  21756. (section.generatedOffset.generatedLine === mapping.generatedLine
  21757. ? section.generatedOffset.generatedColumn - 1
  21758. : 0),
  21759. originalLine: mapping.originalLine,
  21760. originalColumn: mapping.originalColumn,
  21761. name: name
  21762. };
  21763. this.__generatedMappings.push(adjustedMapping);
  21764. if (typeof adjustedMapping.originalLine === 'number') {
  21765. this.__originalMappings.push(adjustedMapping);
  21766. }
  21767. }
  21768. }
  21769. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  21770. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  21771. };
  21772. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  21773. return sourceMapConsumer$1;
  21774. }
  21775. var sourceNode$1 = {};
  21776. /* -*- Mode: js; js-indent-level: 2; -*- */
  21777. var hasRequiredSourceNode$1;
  21778. function requireSourceNode$1 () {
  21779. if (hasRequiredSourceNode$1) return sourceNode$1;
  21780. hasRequiredSourceNode$1 = 1;
  21781. /*
  21782. * Copyright 2011 Mozilla Foundation and contributors
  21783. * Licensed under the New BSD license. See LICENSE or:
  21784. * http://opensource.org/licenses/BSD-3-Clause
  21785. */
  21786. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  21787. var util = /*@__PURE__*/ requireUtil$2();
  21788. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  21789. // operating systems these days (capturing the result).
  21790. var REGEX_NEWLINE = /(\r?\n)/;
  21791. // Newline character code for charCodeAt() comparisons
  21792. var NEWLINE_CODE = 10;
  21793. // Private symbol for identifying `SourceNode`s when multiple versions of
  21794. // the source-map library are loaded. This MUST NOT CHANGE across
  21795. // versions!
  21796. var isSourceNode = "$$$isSourceNode$$$";
  21797. /**
  21798. * SourceNodes provide a way to abstract over interpolating/concatenating
  21799. * snippets of generated JavaScript source code while maintaining the line and
  21800. * column information associated with the original source code.
  21801. *
  21802. * @param aLine The original line number.
  21803. * @param aColumn The original column number.
  21804. * @param aSource The original source's filename.
  21805. * @param aChunks Optional. An array of strings which are snippets of
  21806. * generated JS, or other SourceNodes.
  21807. * @param aName The original identifier.
  21808. */
  21809. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  21810. this.children = [];
  21811. this.sourceContents = {};
  21812. this.line = aLine == null ? null : aLine;
  21813. this.column = aColumn == null ? null : aColumn;
  21814. this.source = aSource == null ? null : aSource;
  21815. this.name = aName == null ? null : aName;
  21816. this[isSourceNode] = true;
  21817. if (aChunks != null) this.add(aChunks);
  21818. }
  21819. /**
  21820. * Creates a SourceNode from generated code and a SourceMapConsumer.
  21821. *
  21822. * @param aGeneratedCode The generated code
  21823. * @param aSourceMapConsumer The SourceMap for the generated code
  21824. * @param aRelativePath Optional. The path that relative sources in the
  21825. * SourceMapConsumer should be relative to.
  21826. */
  21827. SourceNode.fromStringWithSourceMap =
  21828. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  21829. // The SourceNode we want to fill with the generated code
  21830. // and the SourceMap
  21831. var node = new SourceNode();
  21832. // All even indices of this array are one line of the generated code,
  21833. // while all odd indices are the newlines between two adjacent lines
  21834. // (since `REGEX_NEWLINE` captures its match).
  21835. // Processed fragments are accessed by calling `shiftNextLine`.
  21836. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  21837. var remainingLinesIndex = 0;
  21838. var shiftNextLine = function() {
  21839. var lineContents = getNextLine();
  21840. // The last line of a file might not have a newline.
  21841. var newLine = getNextLine() || "";
  21842. return lineContents + newLine;
  21843. function getNextLine() {
  21844. return remainingLinesIndex < remainingLines.length ?
  21845. remainingLines[remainingLinesIndex++] : undefined;
  21846. }
  21847. };
  21848. // We need to remember the position of "remainingLines"
  21849. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  21850. // The generate SourceNodes we need a code range.
  21851. // To extract it current and last mapping is used.
  21852. // Here we store the last mapping.
  21853. var lastMapping = null;
  21854. aSourceMapConsumer.eachMapping(function (mapping) {
  21855. if (lastMapping !== null) {
  21856. // We add the code from "lastMapping" to "mapping":
  21857. // First check if there is a new line in between.
  21858. if (lastGeneratedLine < mapping.generatedLine) {
  21859. // Associate first line with "lastMapping"
  21860. addMappingWithCode(lastMapping, shiftNextLine());
  21861. lastGeneratedLine++;
  21862. lastGeneratedColumn = 0;
  21863. // The remaining code is added without mapping
  21864. } else {
  21865. // There is no new line in between.
  21866. // Associate the code between "lastGeneratedColumn" and
  21867. // "mapping.generatedColumn" with "lastMapping"
  21868. var nextLine = remainingLines[remainingLinesIndex] || '';
  21869. var code = nextLine.substr(0, mapping.generatedColumn -
  21870. lastGeneratedColumn);
  21871. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  21872. lastGeneratedColumn);
  21873. lastGeneratedColumn = mapping.generatedColumn;
  21874. addMappingWithCode(lastMapping, code);
  21875. // No more remaining code, continue
  21876. lastMapping = mapping;
  21877. return;
  21878. }
  21879. }
  21880. // We add the generated code until the first mapping
  21881. // to the SourceNode without any mapping.
  21882. // Each line is added as separate string.
  21883. while (lastGeneratedLine < mapping.generatedLine) {
  21884. node.add(shiftNextLine());
  21885. lastGeneratedLine++;
  21886. }
  21887. if (lastGeneratedColumn < mapping.generatedColumn) {
  21888. var nextLine = remainingLines[remainingLinesIndex] || '';
  21889. node.add(nextLine.substr(0, mapping.generatedColumn));
  21890. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  21891. lastGeneratedColumn = mapping.generatedColumn;
  21892. }
  21893. lastMapping = mapping;
  21894. }, this);
  21895. // We have processed all mappings.
  21896. if (remainingLinesIndex < remainingLines.length) {
  21897. if (lastMapping) {
  21898. // Associate the remaining code in the current line with "lastMapping"
  21899. addMappingWithCode(lastMapping, shiftNextLine());
  21900. }
  21901. // and add the remaining lines without any mapping
  21902. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  21903. }
  21904. // Copy sourcesContent into SourceNode
  21905. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  21906. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  21907. if (content != null) {
  21908. if (aRelativePath != null) {
  21909. sourceFile = util.join(aRelativePath, sourceFile);
  21910. }
  21911. node.setSourceContent(sourceFile, content);
  21912. }
  21913. });
  21914. return node;
  21915. function addMappingWithCode(mapping, code) {
  21916. if (mapping === null || mapping.source === undefined) {
  21917. node.add(code);
  21918. } else {
  21919. var source = aRelativePath
  21920. ? util.join(aRelativePath, mapping.source)
  21921. : mapping.source;
  21922. node.add(new SourceNode(mapping.originalLine,
  21923. mapping.originalColumn,
  21924. source,
  21925. code,
  21926. mapping.name));
  21927. }
  21928. }
  21929. };
  21930. /**
  21931. * Add a chunk of generated JS to this source node.
  21932. *
  21933. * @param aChunk A string snippet of generated JS code, another instance of
  21934. * SourceNode, or an array where each member is one of those things.
  21935. */
  21936. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  21937. if (Array.isArray(aChunk)) {
  21938. aChunk.forEach(function (chunk) {
  21939. this.add(chunk);
  21940. }, this);
  21941. }
  21942. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  21943. if (aChunk) {
  21944. this.children.push(aChunk);
  21945. }
  21946. }
  21947. else {
  21948. throw new TypeError(
  21949. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  21950. );
  21951. }
  21952. return this;
  21953. };
  21954. /**
  21955. * Add a chunk of generated JS to the beginning of this source node.
  21956. *
  21957. * @param aChunk A string snippet of generated JS code, another instance of
  21958. * SourceNode, or an array where each member is one of those things.
  21959. */
  21960. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  21961. if (Array.isArray(aChunk)) {
  21962. for (var i = aChunk.length-1; i >= 0; i--) {
  21963. this.prepend(aChunk[i]);
  21964. }
  21965. }
  21966. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  21967. this.children.unshift(aChunk);
  21968. }
  21969. else {
  21970. throw new TypeError(
  21971. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  21972. );
  21973. }
  21974. return this;
  21975. };
  21976. /**
  21977. * Walk over the tree of JS snippets in this node and its children. The
  21978. * walking function is called once for each snippet of JS and is passed that
  21979. * snippet and the its original associated source's line/column location.
  21980. *
  21981. * @param aFn The traversal function.
  21982. */
  21983. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  21984. var chunk;
  21985. for (var i = 0, len = this.children.length; i < len; i++) {
  21986. chunk = this.children[i];
  21987. if (chunk[isSourceNode]) {
  21988. chunk.walk(aFn);
  21989. }
  21990. else {
  21991. if (chunk !== '') {
  21992. aFn(chunk, { source: this.source,
  21993. line: this.line,
  21994. column: this.column,
  21995. name: this.name });
  21996. }
  21997. }
  21998. }
  21999. };
  22000. /**
  22001. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  22002. * each of `this.children`.
  22003. *
  22004. * @param aSep The separator.
  22005. */
  22006. SourceNode.prototype.join = function SourceNode_join(aSep) {
  22007. var newChildren;
  22008. var i;
  22009. var len = this.children.length;
  22010. if (len > 0) {
  22011. newChildren = [];
  22012. for (i = 0; i < len-1; i++) {
  22013. newChildren.push(this.children[i]);
  22014. newChildren.push(aSep);
  22015. }
  22016. newChildren.push(this.children[i]);
  22017. this.children = newChildren;
  22018. }
  22019. return this;
  22020. };
  22021. /**
  22022. * Call String.prototype.replace on the very right-most source snippet. Useful
  22023. * for trimming whitespace from the end of a source node, etc.
  22024. *
  22025. * @param aPattern The pattern to replace.
  22026. * @param aReplacement The thing to replace the pattern with.
  22027. */
  22028. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  22029. var lastChild = this.children[this.children.length - 1];
  22030. if (lastChild[isSourceNode]) {
  22031. lastChild.replaceRight(aPattern, aReplacement);
  22032. }
  22033. else if (typeof lastChild === 'string') {
  22034. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  22035. }
  22036. else {
  22037. this.children.push(''.replace(aPattern, aReplacement));
  22038. }
  22039. return this;
  22040. };
  22041. /**
  22042. * Set the source content for a source file. This will be added to the SourceMapGenerator
  22043. * in the sourcesContent field.
  22044. *
  22045. * @param aSourceFile The filename of the source file
  22046. * @param aSourceContent The content of the source file
  22047. */
  22048. SourceNode.prototype.setSourceContent =
  22049. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  22050. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  22051. };
  22052. /**
  22053. * Walk over the tree of SourceNodes. The walking function is called for each
  22054. * source file content and is passed the filename and source content.
  22055. *
  22056. * @param aFn The traversal function.
  22057. */
  22058. SourceNode.prototype.walkSourceContents =
  22059. function SourceNode_walkSourceContents(aFn) {
  22060. for (var i = 0, len = this.children.length; i < len; i++) {
  22061. if (this.children[i][isSourceNode]) {
  22062. this.children[i].walkSourceContents(aFn);
  22063. }
  22064. }
  22065. var sources = Object.keys(this.sourceContents);
  22066. for (var i = 0, len = sources.length; i < len; i++) {
  22067. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  22068. }
  22069. };
  22070. /**
  22071. * Return the string representation of this source node. Walks over the tree
  22072. * and concatenates all the various snippets together to one string.
  22073. */
  22074. SourceNode.prototype.toString = function SourceNode_toString() {
  22075. var str = "";
  22076. this.walk(function (chunk) {
  22077. str += chunk;
  22078. });
  22079. return str;
  22080. };
  22081. /**
  22082. * Returns the string representation of this source node along with a source
  22083. * map.
  22084. */
  22085. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  22086. var generated = {
  22087. code: "",
  22088. line: 1,
  22089. column: 0
  22090. };
  22091. var map = new SourceMapGenerator(aArgs);
  22092. var sourceMappingActive = false;
  22093. var lastOriginalSource = null;
  22094. var lastOriginalLine = null;
  22095. var lastOriginalColumn = null;
  22096. var lastOriginalName = null;
  22097. this.walk(function (chunk, original) {
  22098. generated.code += chunk;
  22099. if (original.source !== null
  22100. && original.line !== null
  22101. && original.column !== null) {
  22102. if(lastOriginalSource !== original.source
  22103. || lastOriginalLine !== original.line
  22104. || lastOriginalColumn !== original.column
  22105. || lastOriginalName !== original.name) {
  22106. map.addMapping({
  22107. source: original.source,
  22108. original: {
  22109. line: original.line,
  22110. column: original.column
  22111. },
  22112. generated: {
  22113. line: generated.line,
  22114. column: generated.column
  22115. },
  22116. name: original.name
  22117. });
  22118. }
  22119. lastOriginalSource = original.source;
  22120. lastOriginalLine = original.line;
  22121. lastOriginalColumn = original.column;
  22122. lastOriginalName = original.name;
  22123. sourceMappingActive = true;
  22124. } else if (sourceMappingActive) {
  22125. map.addMapping({
  22126. generated: {
  22127. line: generated.line,
  22128. column: generated.column
  22129. }
  22130. });
  22131. lastOriginalSource = null;
  22132. sourceMappingActive = false;
  22133. }
  22134. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  22135. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  22136. generated.line++;
  22137. generated.column = 0;
  22138. // Mappings end at eol
  22139. if (idx + 1 === length) {
  22140. lastOriginalSource = null;
  22141. sourceMappingActive = false;
  22142. } else if (sourceMappingActive) {
  22143. map.addMapping({
  22144. source: original.source,
  22145. original: {
  22146. line: original.line,
  22147. column: original.column
  22148. },
  22149. generated: {
  22150. line: generated.line,
  22151. column: generated.column
  22152. },
  22153. name: original.name
  22154. });
  22155. }
  22156. } else {
  22157. generated.column++;
  22158. }
  22159. }
  22160. });
  22161. this.walkSourceContents(function (sourceFile, sourceContent) {
  22162. map.setSourceContent(sourceFile, sourceContent);
  22163. });
  22164. return { code: generated.code, map: map };
  22165. };
  22166. sourceNode$1.SourceNode = SourceNode;
  22167. return sourceNode$1;
  22168. }
  22169. /*
  22170. * Copyright 2009-2011 Mozilla Foundation and contributors
  22171. * Licensed under the New BSD license. See LICENSE.txt or:
  22172. * http://opensource.org/licenses/BSD-3-Clause
  22173. */
  22174. var hasRequiredSourceMap$1;
  22175. function requireSourceMap$1 () {
  22176. if (hasRequiredSourceMap$1) return sourceMap$1;
  22177. hasRequiredSourceMap$1 = 1;
  22178. sourceMap$1.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  22179. sourceMap$1.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer$1().SourceMapConsumer;
  22180. sourceMap$1.SourceNode = /*@__PURE__*/ requireSourceNode$1().SourceNode;
  22181. return sourceMap$1;
  22182. }
  22183. var sourceMapExports = /*@__PURE__*/ requireSourceMap$1();
  22184. const PURE_ANNOTATION = `/*@__PURE__*/`;
  22185. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  22186. function createCodegenContext(ast, {
  22187. mode = "function",
  22188. prefixIdentifiers = mode === "module",
  22189. sourceMap = false,
  22190. filename = `template.vue.html`,
  22191. scopeId = null,
  22192. optimizeImports = false,
  22193. runtimeGlobalName = `Vue`,
  22194. runtimeModuleName = `vue`,
  22195. ssrRuntimeModuleName = "vue/server-renderer",
  22196. ssr = false,
  22197. isTS = false,
  22198. inSSR = false
  22199. }) {
  22200. const context = {
  22201. mode,
  22202. prefixIdentifiers,
  22203. sourceMap,
  22204. filename,
  22205. scopeId,
  22206. optimizeImports,
  22207. runtimeGlobalName,
  22208. runtimeModuleName,
  22209. ssrRuntimeModuleName,
  22210. ssr,
  22211. isTS,
  22212. inSSR,
  22213. source: ast.source,
  22214. code: ``,
  22215. column: 1,
  22216. line: 1,
  22217. offset: 0,
  22218. indentLevel: 0,
  22219. pure: false,
  22220. map: void 0,
  22221. helper(key) {
  22222. return `_${helperNameMap[key]}`;
  22223. },
  22224. push(code, newlineIndex = -2 /* None */, node) {
  22225. context.code += code;
  22226. if (context.map) {
  22227. if (node) {
  22228. let name;
  22229. if (node.type === 4 && !node.isStatic) {
  22230. const content = node.content.replace(/^_ctx\./, "");
  22231. if (content !== node.content && isSimpleIdentifier(content)) {
  22232. name = content;
  22233. }
  22234. }
  22235. if (node.loc.source) {
  22236. addMapping(node.loc.start, name);
  22237. }
  22238. }
  22239. if (newlineIndex === -3 /* Unknown */) {
  22240. advancePositionWithMutation(context, code);
  22241. } else {
  22242. context.offset += code.length;
  22243. if (newlineIndex === -2 /* None */) {
  22244. context.column += code.length;
  22245. } else {
  22246. if (newlineIndex === -1 /* End */) {
  22247. newlineIndex = code.length - 1;
  22248. }
  22249. context.line++;
  22250. context.column = code.length - newlineIndex;
  22251. }
  22252. }
  22253. if (node && node.loc !== locStub && node.loc.source) {
  22254. addMapping(node.loc.end);
  22255. }
  22256. }
  22257. },
  22258. indent() {
  22259. newline(++context.indentLevel);
  22260. },
  22261. deindent(withoutNewLine = false) {
  22262. if (withoutNewLine) {
  22263. --context.indentLevel;
  22264. } else {
  22265. newline(--context.indentLevel);
  22266. }
  22267. },
  22268. newline() {
  22269. newline(context.indentLevel);
  22270. }
  22271. };
  22272. function newline(n) {
  22273. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  22274. }
  22275. function addMapping(loc, name = null) {
  22276. const { _names, _mappings } = context.map;
  22277. if (name !== null && !_names.has(name)) _names.add(name);
  22278. _mappings.add({
  22279. originalLine: loc.line,
  22280. originalColumn: loc.column - 1,
  22281. // source-map column is 0 based
  22282. generatedLine: context.line,
  22283. generatedColumn: context.column - 1,
  22284. source: filename,
  22285. name
  22286. });
  22287. }
  22288. if (sourceMap) {
  22289. context.map = new sourceMapExports.SourceMapGenerator();
  22290. context.map.setSourceContent(filename, context.source);
  22291. context.map._sources.add(filename);
  22292. }
  22293. return context;
  22294. }
  22295. function generate(ast, options = {}) {
  22296. const context = createCodegenContext(ast, options);
  22297. if (options.onContextCreated) options.onContextCreated(context);
  22298. const {
  22299. mode,
  22300. push,
  22301. prefixIdentifiers,
  22302. indent,
  22303. deindent,
  22304. newline,
  22305. scopeId,
  22306. ssr
  22307. } = context;
  22308. const helpers = Array.from(ast.helpers);
  22309. const hasHelpers = helpers.length > 0;
  22310. const useWithBlock = !prefixIdentifiers && mode !== "module";
  22311. const genScopeId = scopeId != null && mode === "module";
  22312. const isSetupInlined = !!options.inline;
  22313. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  22314. if (mode === "module") {
  22315. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  22316. } else {
  22317. genFunctionPreamble(ast, preambleContext);
  22318. }
  22319. const functionName = ssr ? `ssrRender` : `render`;
  22320. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  22321. if (options.bindingMetadata && !options.inline) {
  22322. args.push("$props", "$setup", "$data", "$options");
  22323. }
  22324. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  22325. if (isSetupInlined) {
  22326. push(`(${signature}) => {`);
  22327. } else {
  22328. push(`function ${functionName}(${signature}) {`);
  22329. }
  22330. indent();
  22331. if (useWithBlock) {
  22332. push(`with (_ctx) {`);
  22333. indent();
  22334. if (hasHelpers) {
  22335. push(
  22336. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  22337. `,
  22338. -1 /* End */
  22339. );
  22340. newline();
  22341. }
  22342. }
  22343. if (ast.components.length) {
  22344. genAssets(ast.components, "component", context);
  22345. if (ast.directives.length || ast.temps > 0) {
  22346. newline();
  22347. }
  22348. }
  22349. if (ast.directives.length) {
  22350. genAssets(ast.directives, "directive", context);
  22351. if (ast.temps > 0) {
  22352. newline();
  22353. }
  22354. }
  22355. if (ast.temps > 0) {
  22356. push(`let `);
  22357. for (let i = 0; i < ast.temps; i++) {
  22358. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  22359. }
  22360. }
  22361. if (ast.components.length || ast.directives.length || ast.temps) {
  22362. push(`
  22363. `, 0 /* Start */);
  22364. newline();
  22365. }
  22366. if (!ssr) {
  22367. push(`return `);
  22368. }
  22369. if (ast.codegenNode) {
  22370. genNode(ast.codegenNode, context);
  22371. } else {
  22372. push(`null`);
  22373. }
  22374. if (useWithBlock) {
  22375. deindent();
  22376. push(`}`);
  22377. }
  22378. deindent();
  22379. push(`}`);
  22380. return {
  22381. ast,
  22382. code: context.code,
  22383. preamble: isSetupInlined ? preambleContext.code : ``,
  22384. map: context.map ? context.map.toJSON() : void 0
  22385. };
  22386. }
  22387. function genFunctionPreamble(ast, context) {
  22388. const {
  22389. ssr,
  22390. prefixIdentifiers,
  22391. push,
  22392. newline,
  22393. runtimeModuleName,
  22394. runtimeGlobalName,
  22395. ssrRuntimeModuleName
  22396. } = context;
  22397. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  22398. const helpers = Array.from(ast.helpers);
  22399. if (helpers.length > 0) {
  22400. if (prefixIdentifiers) {
  22401. push(
  22402. `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  22403. `,
  22404. -1 /* End */
  22405. );
  22406. } else {
  22407. push(`const _Vue = ${VueBinding}
  22408. `, -1 /* End */);
  22409. if (ast.hoists.length) {
  22410. const staticHelpers = [
  22411. CREATE_VNODE,
  22412. CREATE_ELEMENT_VNODE,
  22413. CREATE_COMMENT,
  22414. CREATE_TEXT,
  22415. CREATE_STATIC
  22416. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  22417. push(`const { ${staticHelpers} } = _Vue
  22418. `, -1 /* End */);
  22419. }
  22420. }
  22421. }
  22422. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  22423. push(
  22424. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  22425. `,
  22426. -1 /* End */
  22427. );
  22428. }
  22429. genHoists(ast.hoists, context);
  22430. newline();
  22431. push(`return `);
  22432. }
  22433. function genModulePreamble(ast, context, genScopeId, inline) {
  22434. const {
  22435. push,
  22436. newline,
  22437. optimizeImports,
  22438. runtimeModuleName,
  22439. ssrRuntimeModuleName
  22440. } = context;
  22441. if (ast.helpers.size) {
  22442. const helpers = Array.from(ast.helpers);
  22443. if (optimizeImports) {
  22444. push(
  22445. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  22446. `,
  22447. -1 /* End */
  22448. );
  22449. push(
  22450. `
  22451. // Binding optimization for webpack code-split
  22452. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  22453. `,
  22454. -1 /* End */
  22455. );
  22456. } else {
  22457. push(
  22458. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  22459. `,
  22460. -1 /* End */
  22461. );
  22462. }
  22463. }
  22464. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  22465. push(
  22466. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  22467. `,
  22468. -1 /* End */
  22469. );
  22470. }
  22471. if (ast.imports.length) {
  22472. genImports(ast.imports, context);
  22473. newline();
  22474. }
  22475. genHoists(ast.hoists, context);
  22476. newline();
  22477. if (!inline) {
  22478. push(`export `);
  22479. }
  22480. }
  22481. function genAssets(assets, type, { helper, push, newline, isTS }) {
  22482. const resolver = helper(
  22483. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  22484. );
  22485. for (let i = 0; i < assets.length; i++) {
  22486. let id = assets[i];
  22487. const maybeSelfReference = id.endsWith("__self");
  22488. if (maybeSelfReference) {
  22489. id = id.slice(0, -6);
  22490. }
  22491. push(
  22492. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  22493. );
  22494. if (i < assets.length - 1) {
  22495. newline();
  22496. }
  22497. }
  22498. }
  22499. function genHoists(hoists, context) {
  22500. if (!hoists.length) {
  22501. return;
  22502. }
  22503. context.pure = true;
  22504. const { push, newline } = context;
  22505. newline();
  22506. for (let i = 0; i < hoists.length; i++) {
  22507. const exp = hoists[i];
  22508. if (exp) {
  22509. push(`const _hoisted_${i + 1} = `);
  22510. genNode(exp, context);
  22511. newline();
  22512. }
  22513. }
  22514. context.pure = false;
  22515. }
  22516. function genImports(importsOptions, context) {
  22517. if (!importsOptions.length) {
  22518. return;
  22519. }
  22520. importsOptions.forEach((imports) => {
  22521. context.push(`import `);
  22522. genNode(imports.exp, context);
  22523. context.push(` from '${imports.path}'`);
  22524. context.newline();
  22525. });
  22526. }
  22527. function isText(n) {
  22528. return isString$1(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  22529. }
  22530. function genNodeListAsArray(nodes, context) {
  22531. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  22532. context.push(`[`);
  22533. multilines && context.indent();
  22534. genNodeList(nodes, context, multilines);
  22535. multilines && context.deindent();
  22536. context.push(`]`);
  22537. }
  22538. function genNodeList(nodes, context, multilines = false, comma = true) {
  22539. const { push, newline } = context;
  22540. for (let i = 0; i < nodes.length; i++) {
  22541. const node = nodes[i];
  22542. if (isString$1(node)) {
  22543. push(node, -3 /* Unknown */);
  22544. } else if (isArray$3(node)) {
  22545. genNodeListAsArray(node, context);
  22546. } else {
  22547. genNode(node, context);
  22548. }
  22549. if (i < nodes.length - 1) {
  22550. if (multilines) {
  22551. comma && push(",");
  22552. newline();
  22553. } else {
  22554. comma && push(", ");
  22555. }
  22556. }
  22557. }
  22558. }
  22559. function genNode(node, context) {
  22560. if (isString$1(node)) {
  22561. context.push(node, -3 /* Unknown */);
  22562. return;
  22563. }
  22564. if (isSymbol$1(node)) {
  22565. context.push(context.helper(node));
  22566. return;
  22567. }
  22568. switch (node.type) {
  22569. case 1:
  22570. case 9:
  22571. case 11:
  22572. assert(
  22573. node.codegenNode != null,
  22574. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  22575. );
  22576. genNode(node.codegenNode, context);
  22577. break;
  22578. case 2:
  22579. genText(node, context);
  22580. break;
  22581. case 4:
  22582. genExpression(node, context);
  22583. break;
  22584. case 5:
  22585. genInterpolation(node, context);
  22586. break;
  22587. case 12:
  22588. genNode(node.codegenNode, context);
  22589. break;
  22590. case 8:
  22591. genCompoundExpression(node, context);
  22592. break;
  22593. case 3:
  22594. genComment(node, context);
  22595. break;
  22596. case 13:
  22597. genVNodeCall(node, context);
  22598. break;
  22599. case 14:
  22600. genCallExpression(node, context);
  22601. break;
  22602. case 15:
  22603. genObjectExpression(node, context);
  22604. break;
  22605. case 17:
  22606. genArrayExpression(node, context);
  22607. break;
  22608. case 18:
  22609. genFunctionExpression(node, context);
  22610. break;
  22611. case 19:
  22612. genConditionalExpression(node, context);
  22613. break;
  22614. case 20:
  22615. genCacheExpression(node, context);
  22616. break;
  22617. case 21:
  22618. genNodeList(node.body, context, true, false);
  22619. break;
  22620. // SSR only types
  22621. case 22:
  22622. genTemplateLiteral(node, context);
  22623. break;
  22624. case 23:
  22625. genIfStatement(node, context);
  22626. break;
  22627. case 24:
  22628. genAssignmentExpression(node, context);
  22629. break;
  22630. case 25:
  22631. genSequenceExpression(node, context);
  22632. break;
  22633. case 26:
  22634. genReturnStatement(node, context);
  22635. break;
  22636. /* v8 ignore start */
  22637. case 10:
  22638. break;
  22639. default:
  22640. {
  22641. assert(false, `unhandled codegen node type: ${node.type}`);
  22642. const exhaustiveCheck = node;
  22643. return exhaustiveCheck;
  22644. }
  22645. }
  22646. }
  22647. function genText(node, context) {
  22648. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  22649. }
  22650. function genExpression(node, context) {
  22651. const { content, isStatic } = node;
  22652. context.push(
  22653. isStatic ? JSON.stringify(content) : content,
  22654. -3 /* Unknown */,
  22655. node
  22656. );
  22657. }
  22658. function genInterpolation(node, context) {
  22659. const { push, helper, pure } = context;
  22660. if (pure) push(PURE_ANNOTATION);
  22661. push(`${helper(TO_DISPLAY_STRING)}(`);
  22662. genNode(node.content, context);
  22663. push(`)`);
  22664. }
  22665. function genCompoundExpression(node, context) {
  22666. for (let i = 0; i < node.children.length; i++) {
  22667. const child = node.children[i];
  22668. if (isString$1(child)) {
  22669. context.push(child, -3 /* Unknown */);
  22670. } else {
  22671. genNode(child, context);
  22672. }
  22673. }
  22674. }
  22675. function genExpressionAsPropertyKey(node, context) {
  22676. const { push } = context;
  22677. if (node.type === 8) {
  22678. push(`[`);
  22679. genCompoundExpression(node, context);
  22680. push(`]`);
  22681. } else if (node.isStatic) {
  22682. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  22683. push(text, -2 /* None */, node);
  22684. } else {
  22685. push(`[${node.content}]`, -3 /* Unknown */, node);
  22686. }
  22687. }
  22688. function genComment(node, context) {
  22689. const { push, helper, pure } = context;
  22690. if (pure) {
  22691. push(PURE_ANNOTATION);
  22692. }
  22693. push(
  22694. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  22695. -3 /* Unknown */,
  22696. node
  22697. );
  22698. }
  22699. function genVNodeCall(node, context) {
  22700. const { push, helper, pure } = context;
  22701. const {
  22702. tag,
  22703. props,
  22704. children,
  22705. patchFlag,
  22706. dynamicProps,
  22707. directives,
  22708. isBlock,
  22709. disableTracking,
  22710. isComponent
  22711. } = node;
  22712. let patchFlagString;
  22713. if (patchFlag) {
  22714. {
  22715. if (patchFlag < 0) {
  22716. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  22717. } else {
  22718. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  22719. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  22720. }
  22721. }
  22722. }
  22723. if (directives) {
  22724. push(helper(WITH_DIRECTIVES) + `(`);
  22725. }
  22726. if (isBlock) {
  22727. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  22728. }
  22729. if (pure) {
  22730. push(PURE_ANNOTATION);
  22731. }
  22732. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  22733. push(helper(callHelper) + `(`, -2 /* None */, node);
  22734. genNodeList(
  22735. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  22736. context
  22737. );
  22738. push(`)`);
  22739. if (isBlock) {
  22740. push(`)`);
  22741. }
  22742. if (directives) {
  22743. push(`, `);
  22744. genNode(directives, context);
  22745. push(`)`);
  22746. }
  22747. }
  22748. function genNullableArgs(args) {
  22749. let i = args.length;
  22750. while (i--) {
  22751. if (args[i] != null) break;
  22752. }
  22753. return args.slice(0, i + 1).map((arg) => arg || `null`);
  22754. }
  22755. function genCallExpression(node, context) {
  22756. const { push, helper, pure } = context;
  22757. const callee = isString$1(node.callee) ? node.callee : helper(node.callee);
  22758. if (pure) {
  22759. push(PURE_ANNOTATION);
  22760. }
  22761. push(callee + `(`, -2 /* None */, node);
  22762. genNodeList(node.arguments, context);
  22763. push(`)`);
  22764. }
  22765. function genObjectExpression(node, context) {
  22766. const { push, indent, deindent, newline } = context;
  22767. const { properties } = node;
  22768. if (!properties.length) {
  22769. push(`{}`, -2 /* None */, node);
  22770. return;
  22771. }
  22772. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  22773. push(multilines ? `{` : `{ `);
  22774. multilines && indent();
  22775. for (let i = 0; i < properties.length; i++) {
  22776. const { key, value } = properties[i];
  22777. genExpressionAsPropertyKey(key, context);
  22778. push(`: `);
  22779. genNode(value, context);
  22780. if (i < properties.length - 1) {
  22781. push(`,`);
  22782. newline();
  22783. }
  22784. }
  22785. multilines && deindent();
  22786. push(multilines ? `}` : ` }`);
  22787. }
  22788. function genArrayExpression(node, context) {
  22789. genNodeListAsArray(node.elements, context);
  22790. }
  22791. function genFunctionExpression(node, context) {
  22792. const { push, indent, deindent } = context;
  22793. const { params, returns, body, newline, isSlot } = node;
  22794. if (isSlot) {
  22795. push(`_${helperNameMap[WITH_CTX]}(`);
  22796. }
  22797. push(`(`, -2 /* None */, node);
  22798. if (isArray$3(params)) {
  22799. genNodeList(params, context);
  22800. } else if (params) {
  22801. genNode(params, context);
  22802. }
  22803. push(`) => `);
  22804. if (newline || body) {
  22805. push(`{`);
  22806. indent();
  22807. }
  22808. if (returns) {
  22809. if (newline) {
  22810. push(`return `);
  22811. }
  22812. if (isArray$3(returns)) {
  22813. genNodeListAsArray(returns, context);
  22814. } else {
  22815. genNode(returns, context);
  22816. }
  22817. } else if (body) {
  22818. genNode(body, context);
  22819. }
  22820. if (newline || body) {
  22821. deindent();
  22822. push(`}`);
  22823. }
  22824. if (isSlot) {
  22825. push(`)`);
  22826. }
  22827. }
  22828. function genConditionalExpression(node, context) {
  22829. const { test, consequent, alternate, newline: needNewline } = node;
  22830. const { push, indent, deindent, newline } = context;
  22831. if (test.type === 4) {
  22832. const needsParens = !isSimpleIdentifier(test.content);
  22833. needsParens && push(`(`);
  22834. genExpression(test, context);
  22835. needsParens && push(`)`);
  22836. } else {
  22837. push(`(`);
  22838. genNode(test, context);
  22839. push(`)`);
  22840. }
  22841. needNewline && indent();
  22842. context.indentLevel++;
  22843. needNewline || push(` `);
  22844. push(`? `);
  22845. genNode(consequent, context);
  22846. context.indentLevel--;
  22847. needNewline && newline();
  22848. needNewline || push(` `);
  22849. push(`: `);
  22850. const isNested = alternate.type === 19;
  22851. if (!isNested) {
  22852. context.indentLevel++;
  22853. }
  22854. genNode(alternate, context);
  22855. if (!isNested) {
  22856. context.indentLevel--;
  22857. }
  22858. needNewline && deindent(
  22859. true
  22860. /* without newline */
  22861. );
  22862. }
  22863. function genCacheExpression(node, context) {
  22864. const { push, helper, indent, deindent, newline } = context;
  22865. const { needPauseTracking, needArraySpread } = node;
  22866. if (needArraySpread) {
  22867. push(`[...(`);
  22868. }
  22869. push(`_cache[${node.index}] || (`);
  22870. if (needPauseTracking) {
  22871. indent();
  22872. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  22873. if (node.inVOnce) push(`, true`);
  22874. push(`),`);
  22875. newline();
  22876. push(`(`);
  22877. }
  22878. push(`_cache[${node.index}] = `);
  22879. genNode(node.value, context);
  22880. if (needPauseTracking) {
  22881. push(`).cacheIndex = ${node.index},`);
  22882. newline();
  22883. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  22884. newline();
  22885. push(`_cache[${node.index}]`);
  22886. deindent();
  22887. }
  22888. push(`)`);
  22889. if (needArraySpread) {
  22890. push(`)]`);
  22891. }
  22892. }
  22893. function genTemplateLiteral(node, context) {
  22894. const { push, indent, deindent } = context;
  22895. push("`");
  22896. const l = node.elements.length;
  22897. const multilines = l > 3;
  22898. for (let i = 0; i < l; i++) {
  22899. const e = node.elements[i];
  22900. if (isString$1(e)) {
  22901. push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
  22902. } else {
  22903. push("${");
  22904. if (multilines) indent();
  22905. genNode(e, context);
  22906. if (multilines) deindent();
  22907. push("}");
  22908. }
  22909. }
  22910. push("`");
  22911. }
  22912. function genIfStatement(node, context) {
  22913. const { push, indent, deindent } = context;
  22914. const { test, consequent, alternate } = node;
  22915. push(`if (`);
  22916. genNode(test, context);
  22917. push(`) {`);
  22918. indent();
  22919. genNode(consequent, context);
  22920. deindent();
  22921. push(`}`);
  22922. if (alternate) {
  22923. push(` else `);
  22924. if (alternate.type === 23) {
  22925. genIfStatement(alternate, context);
  22926. } else {
  22927. push(`{`);
  22928. indent();
  22929. genNode(alternate, context);
  22930. deindent();
  22931. push(`}`);
  22932. }
  22933. }
  22934. }
  22935. function genAssignmentExpression(node, context) {
  22936. genNode(node.left, context);
  22937. context.push(` = `);
  22938. genNode(node.right, context);
  22939. }
  22940. function genSequenceExpression(node, context) {
  22941. context.push(`(`);
  22942. genNodeList(node.expressions, context);
  22943. context.push(`)`);
  22944. }
  22945. function genReturnStatement({ returns }, context) {
  22946. context.push(`return `);
  22947. if (isArray$3(returns)) {
  22948. genNodeListAsArray(returns, context);
  22949. } else {
  22950. genNode(returns, context);
  22951. }
  22952. }
  22953. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  22954. const transformExpression = (node, context) => {
  22955. if (node.type === 5) {
  22956. node.content = processExpression(
  22957. node.content,
  22958. context
  22959. );
  22960. } else if (node.type === 1) {
  22961. const memo = findDir(node, "memo");
  22962. for (let i = 0; i < node.props.length; i++) {
  22963. const dir = node.props[i];
  22964. if (dir.type === 7 && dir.name !== "for") {
  22965. const exp = dir.exp;
  22966. const arg = dir.arg;
  22967. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  22968. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  22969. dir.exp = processExpression(
  22970. exp,
  22971. context,
  22972. // slot args must be processed as function params
  22973. dir.name === "slot"
  22974. );
  22975. }
  22976. if (arg && arg.type === 4 && !arg.isStatic) {
  22977. dir.arg = processExpression(arg, context);
  22978. }
  22979. }
  22980. }
  22981. }
  22982. };
  22983. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  22984. if (!context.prefixIdentifiers || !node.content.trim()) {
  22985. return node;
  22986. }
  22987. const { inline, bindingMetadata } = context;
  22988. const rewriteIdentifier = (raw, parent, id) => {
  22989. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  22990. if (inline) {
  22991. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  22992. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  22993. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  22994. const isNewExpression = parent && isInNewExpression(parentStack);
  22995. const wrapWithUnref = (raw2) => {
  22996. const wrapped = `${context.helperString(UNREF)}(${raw2})`;
  22997. return isNewExpression ? `(${wrapped})` : wrapped;
  22998. };
  22999. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  23000. return raw;
  23001. } else if (type === "setup-ref") {
  23002. return `${raw}.value`;
  23003. } else if (type === "setup-maybe-ref") {
  23004. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
  23005. } else if (type === "setup-let") {
  23006. if (isAssignmentLVal) {
  23007. const { right: rVal, operator } = parent;
  23008. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  23009. const rExpString = stringifyExpression(
  23010. processExpression(
  23011. createSimpleExpression(rExp, false),
  23012. context,
  23013. false,
  23014. false,
  23015. knownIds
  23016. )
  23017. );
  23018. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  23019. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  23020. } else if (isUpdateArg) {
  23021. id.start = parent.start;
  23022. id.end = parent.end;
  23023. const { prefix: isPrefix, operator } = parent;
  23024. const prefix = isPrefix ? operator : ``;
  23025. const postfix = isPrefix ? `` : operator;
  23026. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  23027. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  23028. } else if (isDestructureAssignment) {
  23029. return raw;
  23030. } else {
  23031. return wrapWithUnref(raw);
  23032. }
  23033. } else if (type === "props") {
  23034. return genPropsAccessExp(raw);
  23035. } else if (type === "props-aliased") {
  23036. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  23037. }
  23038. } else {
  23039. if (type && type.startsWith("setup") || type === "literal-const") {
  23040. return `$setup.${raw}`;
  23041. } else if (type === "props-aliased") {
  23042. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  23043. } else if (type) {
  23044. return `$${type}.${raw}`;
  23045. }
  23046. }
  23047. return `_ctx.${raw}`;
  23048. };
  23049. const rawExp = node.content;
  23050. let ast = node.ast;
  23051. if (ast === false) {
  23052. return node;
  23053. }
  23054. if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
  23055. const isScopeVarReference = context.identifiers[rawExp];
  23056. const isAllowedGlobal = isGloballyAllowed(rawExp);
  23057. const isLiteral = isLiteralWhitelisted(rawExp);
  23058. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  23059. if (isConst(bindingMetadata[rawExp])) {
  23060. node.constType = 1;
  23061. }
  23062. node.content = rewriteIdentifier(rawExp);
  23063. } else if (!isScopeVarReference) {
  23064. if (isLiteral) {
  23065. node.constType = 3;
  23066. } else {
  23067. node.constType = 2;
  23068. }
  23069. }
  23070. return node;
  23071. }
  23072. if (!ast) {
  23073. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  23074. try {
  23075. ast = libExports.parseExpression(source, {
  23076. sourceType: "module",
  23077. plugins: context.expressionPlugins
  23078. });
  23079. } catch (e) {
  23080. context.onError(
  23081. createCompilerError(
  23082. 45,
  23083. node.loc,
  23084. void 0,
  23085. e.message
  23086. )
  23087. );
  23088. return node;
  23089. }
  23090. }
  23091. const ids = [];
  23092. const parentStack = [];
  23093. const knownIds = Object.create(context.identifiers);
  23094. walkIdentifiers(
  23095. ast,
  23096. (node2, parent, _, isReferenced, isLocal) => {
  23097. if (isStaticPropertyKey(node2, parent)) {
  23098. return;
  23099. }
  23100. const needPrefix = isReferenced && canPrefix(node2);
  23101. if (needPrefix && !isLocal) {
  23102. if (isStaticProperty(parent) && parent.shorthand) {
  23103. node2.prefix = `${node2.name}: `;
  23104. }
  23105. node2.name = rewriteIdentifier(node2.name, parent, node2);
  23106. ids.push(node2);
  23107. } else {
  23108. if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
  23109. node2.isConstant = true;
  23110. }
  23111. ids.push(node2);
  23112. }
  23113. },
  23114. true,
  23115. // invoke on ALL identifiers
  23116. parentStack,
  23117. knownIds
  23118. );
  23119. const children = [];
  23120. ids.sort((a, b) => a.start - b.start);
  23121. ids.forEach((id, i) => {
  23122. const start = id.start - 1;
  23123. const end = id.end - 1;
  23124. const last = ids[i - 1];
  23125. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  23126. if (leadingText.length || id.prefix) {
  23127. children.push(leadingText + (id.prefix || ``));
  23128. }
  23129. const source = rawExp.slice(start, end);
  23130. children.push(
  23131. createSimpleExpression(
  23132. id.name,
  23133. false,
  23134. {
  23135. start: advancePositionWithClone(node.loc.start, source, start),
  23136. end: advancePositionWithClone(node.loc.start, source, end),
  23137. source
  23138. },
  23139. id.isConstant ? 3 : 0
  23140. )
  23141. );
  23142. if (i === ids.length - 1 && end < rawExp.length) {
  23143. children.push(rawExp.slice(end));
  23144. }
  23145. });
  23146. let ret;
  23147. if (children.length) {
  23148. ret = createCompoundExpression(children, node.loc);
  23149. ret.ast = ast;
  23150. } else {
  23151. ret = node;
  23152. ret.constType = 3;
  23153. }
  23154. ret.identifiers = Object.keys(knownIds);
  23155. return ret;
  23156. }
  23157. function canPrefix(id) {
  23158. if (isGloballyAllowed(id.name)) {
  23159. return false;
  23160. }
  23161. if (id.name === "require") {
  23162. return false;
  23163. }
  23164. return true;
  23165. }
  23166. function stringifyExpression(exp) {
  23167. if (isString$1(exp)) {
  23168. return exp;
  23169. } else if (exp.type === 4) {
  23170. return exp.content;
  23171. } else {
  23172. return exp.children.map(stringifyExpression).join("");
  23173. }
  23174. }
  23175. function isConst(type) {
  23176. return type === "setup-const" || type === "literal-const";
  23177. }
  23178. const transformIf = createStructuralDirectiveTransform(
  23179. /^(if|else|else-if)$/,
  23180. (node, dir, context) => {
  23181. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  23182. const siblings = context.parent.children;
  23183. let i = siblings.indexOf(ifNode);
  23184. let key = 0;
  23185. while (i-- >= 0) {
  23186. const sibling = siblings[i];
  23187. if (sibling && sibling.type === 9) {
  23188. key += sibling.branches.length;
  23189. }
  23190. }
  23191. return () => {
  23192. if (isRoot) {
  23193. ifNode.codegenNode = createCodegenNodeForBranch(
  23194. branch,
  23195. key,
  23196. context
  23197. );
  23198. } else {
  23199. const parentCondition = getParentCondition(ifNode.codegenNode);
  23200. parentCondition.alternate = createCodegenNodeForBranch(
  23201. branch,
  23202. key + ifNode.branches.length - 1,
  23203. context
  23204. );
  23205. }
  23206. };
  23207. });
  23208. }
  23209. );
  23210. function processIf(node, dir, context, processCodegen) {
  23211. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  23212. const loc = dir.exp ? dir.exp.loc : node.loc;
  23213. context.onError(
  23214. createCompilerError(28, dir.loc)
  23215. );
  23216. dir.exp = createSimpleExpression(`true`, false, loc);
  23217. }
  23218. if (context.prefixIdentifiers && dir.exp) {
  23219. dir.exp = processExpression(dir.exp, context);
  23220. }
  23221. if (dir.name === "if") {
  23222. const branch = createIfBranch(node, dir);
  23223. const ifNode = {
  23224. type: 9,
  23225. loc: cloneLoc(node.loc),
  23226. branches: [branch]
  23227. };
  23228. context.replaceNode(ifNode);
  23229. if (processCodegen) {
  23230. return processCodegen(ifNode, branch, true);
  23231. }
  23232. } else {
  23233. const siblings = context.parent.children;
  23234. const comments = [];
  23235. let i = siblings.indexOf(node);
  23236. while (i-- >= -1) {
  23237. const sibling = siblings[i];
  23238. if (sibling && sibling.type === 3) {
  23239. context.removeNode(sibling);
  23240. comments.unshift(sibling);
  23241. continue;
  23242. }
  23243. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  23244. context.removeNode(sibling);
  23245. continue;
  23246. }
  23247. if (sibling && sibling.type === 9) {
  23248. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  23249. context.onError(
  23250. createCompilerError(30, node.loc)
  23251. );
  23252. }
  23253. context.removeNode();
  23254. const branch = createIfBranch(node, dir);
  23255. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  23256. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  23257. branch.children = [...comments, ...branch.children];
  23258. }
  23259. {
  23260. const key = branch.userKey;
  23261. if (key) {
  23262. sibling.branches.forEach(({ userKey }) => {
  23263. if (isSameKey(userKey, key)) {
  23264. context.onError(
  23265. createCompilerError(
  23266. 29,
  23267. branch.userKey.loc
  23268. )
  23269. );
  23270. }
  23271. });
  23272. }
  23273. }
  23274. sibling.branches.push(branch);
  23275. const onExit = processCodegen && processCodegen(sibling, branch, false);
  23276. traverseNode(branch, context);
  23277. if (onExit) onExit();
  23278. context.currentNode = null;
  23279. } else {
  23280. context.onError(
  23281. createCompilerError(30, node.loc)
  23282. );
  23283. }
  23284. break;
  23285. }
  23286. }
  23287. }
  23288. function createIfBranch(node, dir) {
  23289. const isTemplateIf = node.tagType === 3;
  23290. return {
  23291. type: 10,
  23292. loc: node.loc,
  23293. condition: dir.name === "else" ? void 0 : dir.exp,
  23294. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  23295. userKey: findProp(node, `key`),
  23296. isTemplateIf
  23297. };
  23298. }
  23299. function createCodegenNodeForBranch(branch, keyIndex, context) {
  23300. if (branch.condition) {
  23301. return createConditionalExpression(
  23302. branch.condition,
  23303. createChildrenCodegenNode(branch, keyIndex, context),
  23304. // make sure to pass in asBlock: true so that the comment node call
  23305. // closes the current block.
  23306. createCallExpression(context.helper(CREATE_COMMENT), [
  23307. '"v-if"' ,
  23308. "true"
  23309. ])
  23310. );
  23311. } else {
  23312. return createChildrenCodegenNode(branch, keyIndex, context);
  23313. }
  23314. }
  23315. function createChildrenCodegenNode(branch, keyIndex, context) {
  23316. const { helper } = context;
  23317. const keyProperty = createObjectProperty(
  23318. `key`,
  23319. createSimpleExpression(
  23320. `${keyIndex}`,
  23321. false,
  23322. locStub,
  23323. 2
  23324. )
  23325. );
  23326. const { children } = branch;
  23327. const firstChild = children[0];
  23328. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  23329. if (needFragmentWrapper) {
  23330. if (children.length === 1 && firstChild.type === 11) {
  23331. const vnodeCall = firstChild.codegenNode;
  23332. injectProp(vnodeCall, keyProperty, context);
  23333. return vnodeCall;
  23334. } else {
  23335. let patchFlag = 64;
  23336. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  23337. patchFlag |= 2048;
  23338. }
  23339. return createVNodeCall(
  23340. context,
  23341. helper(FRAGMENT),
  23342. createObjectExpression([keyProperty]),
  23343. children,
  23344. patchFlag,
  23345. void 0,
  23346. void 0,
  23347. true,
  23348. false,
  23349. false,
  23350. branch.loc
  23351. );
  23352. }
  23353. } else {
  23354. const ret = firstChild.codegenNode;
  23355. const vnodeCall = getMemoedVNodeCall(ret);
  23356. if (vnodeCall.type === 13) {
  23357. convertToBlock(vnodeCall, context);
  23358. }
  23359. injectProp(vnodeCall, keyProperty, context);
  23360. return ret;
  23361. }
  23362. }
  23363. function isSameKey(a, b) {
  23364. if (!a || a.type !== b.type) {
  23365. return false;
  23366. }
  23367. if (a.type === 6) {
  23368. if (a.value.content !== b.value.content) {
  23369. return false;
  23370. }
  23371. } else {
  23372. const exp = a.exp;
  23373. const branchExp = b.exp;
  23374. if (exp.type !== branchExp.type) {
  23375. return false;
  23376. }
  23377. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  23378. return false;
  23379. }
  23380. }
  23381. return true;
  23382. }
  23383. function getParentCondition(node) {
  23384. while (true) {
  23385. if (node.type === 19) {
  23386. if (node.alternate.type === 19) {
  23387. node = node.alternate;
  23388. } else {
  23389. return node;
  23390. }
  23391. } else if (node.type === 20) {
  23392. node = node.value;
  23393. }
  23394. }
  23395. }
  23396. const transformBind = (dir, _node, context) => {
  23397. const { modifiers, loc } = dir;
  23398. const arg = dir.arg;
  23399. let { exp } = dir;
  23400. if (exp && exp.type === 4 && !exp.content.trim()) {
  23401. {
  23402. context.onError(
  23403. createCompilerError(34, loc)
  23404. );
  23405. return {
  23406. props: [
  23407. createObjectProperty(arg, createSimpleExpression("", true, loc))
  23408. ]
  23409. };
  23410. }
  23411. }
  23412. if (!exp) {
  23413. if (arg.type !== 4 || !arg.isStatic) {
  23414. context.onError(
  23415. createCompilerError(
  23416. 52,
  23417. arg.loc
  23418. )
  23419. );
  23420. return {
  23421. props: [
  23422. createObjectProperty(arg, createSimpleExpression("", true, loc))
  23423. ]
  23424. };
  23425. }
  23426. transformBindShorthand(dir, context);
  23427. exp = dir.exp;
  23428. }
  23429. if (arg.type !== 4) {
  23430. arg.children.unshift(`(`);
  23431. arg.children.push(`) || ""`);
  23432. } else if (!arg.isStatic) {
  23433. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  23434. }
  23435. if (modifiers.some((mod) => mod.content === "camel")) {
  23436. if (arg.type === 4) {
  23437. if (arg.isStatic) {
  23438. arg.content = camelize(arg.content);
  23439. } else {
  23440. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  23441. }
  23442. } else {
  23443. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  23444. arg.children.push(`)`);
  23445. }
  23446. }
  23447. if (!context.inSSR) {
  23448. if (modifiers.some((mod) => mod.content === "prop")) {
  23449. injectPrefix(arg, ".");
  23450. }
  23451. if (modifiers.some((mod) => mod.content === "attr")) {
  23452. injectPrefix(arg, "^");
  23453. }
  23454. }
  23455. return {
  23456. props: [createObjectProperty(arg, exp)]
  23457. };
  23458. };
  23459. const transformBindShorthand = (dir, context) => {
  23460. const arg = dir.arg;
  23461. const propName = camelize(arg.content);
  23462. dir.exp = createSimpleExpression(propName, false, arg.loc);
  23463. {
  23464. dir.exp = processExpression(dir.exp, context);
  23465. }
  23466. };
  23467. const injectPrefix = (arg, prefix) => {
  23468. if (arg.type === 4) {
  23469. if (arg.isStatic) {
  23470. arg.content = prefix + arg.content;
  23471. } else {
  23472. arg.content = `\`${prefix}\${${arg.content}}\``;
  23473. }
  23474. } else {
  23475. arg.children.unshift(`'${prefix}' + (`);
  23476. arg.children.push(`)`);
  23477. }
  23478. };
  23479. const transformFor = createStructuralDirectiveTransform(
  23480. "for",
  23481. (node, dir, context) => {
  23482. const { helper, removeHelper } = context;
  23483. return processFor(node, dir, context, (forNode) => {
  23484. const renderExp = createCallExpression(helper(RENDER_LIST), [
  23485. forNode.source
  23486. ]);
  23487. const isTemplate = isTemplateNode(node);
  23488. const memo = findDir(node, "memo");
  23489. const keyProp = findProp(node, `key`, false, true);
  23490. const isDirKey = keyProp && keyProp.type === 7;
  23491. if (isDirKey && !keyProp.exp) {
  23492. transformBindShorthand(keyProp, context);
  23493. }
  23494. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  23495. if (memo && keyExp && isDirKey) {
  23496. {
  23497. keyProp.exp = keyExp = processExpression(
  23498. keyExp,
  23499. context
  23500. );
  23501. }
  23502. }
  23503. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  23504. if (isTemplate) {
  23505. if (memo) {
  23506. memo.exp = processExpression(
  23507. memo.exp,
  23508. context
  23509. );
  23510. }
  23511. if (keyProperty && keyProp.type !== 6) {
  23512. keyProperty.value = processExpression(
  23513. keyProperty.value,
  23514. context
  23515. );
  23516. }
  23517. }
  23518. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  23519. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  23520. forNode.codegenNode = createVNodeCall(
  23521. context,
  23522. helper(FRAGMENT),
  23523. void 0,
  23524. renderExp,
  23525. fragmentFlag,
  23526. void 0,
  23527. void 0,
  23528. true,
  23529. !isStableFragment,
  23530. false,
  23531. node.loc
  23532. );
  23533. return () => {
  23534. let childBlock;
  23535. const { children } = forNode;
  23536. if (isTemplate) {
  23537. node.children.some((c) => {
  23538. if (c.type === 1) {
  23539. const key = findProp(c, "key");
  23540. if (key) {
  23541. context.onError(
  23542. createCompilerError(
  23543. 33,
  23544. key.loc
  23545. )
  23546. );
  23547. return true;
  23548. }
  23549. }
  23550. });
  23551. }
  23552. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  23553. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  23554. if (slotOutlet) {
  23555. childBlock = slotOutlet.codegenNode;
  23556. if (isTemplate && keyProperty) {
  23557. injectProp(childBlock, keyProperty, context);
  23558. }
  23559. } else if (needFragmentWrapper) {
  23560. childBlock = createVNodeCall(
  23561. context,
  23562. helper(FRAGMENT),
  23563. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  23564. node.children,
  23565. 64,
  23566. void 0,
  23567. void 0,
  23568. true,
  23569. void 0,
  23570. false
  23571. );
  23572. } else {
  23573. childBlock = children[0].codegenNode;
  23574. if (isTemplate && keyProperty) {
  23575. injectProp(childBlock, keyProperty, context);
  23576. }
  23577. if (childBlock.isBlock !== !isStableFragment) {
  23578. if (childBlock.isBlock) {
  23579. removeHelper(OPEN_BLOCK);
  23580. removeHelper(
  23581. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  23582. );
  23583. } else {
  23584. removeHelper(
  23585. getVNodeHelper(context.inSSR, childBlock.isComponent)
  23586. );
  23587. }
  23588. }
  23589. childBlock.isBlock = !isStableFragment;
  23590. if (childBlock.isBlock) {
  23591. helper(OPEN_BLOCK);
  23592. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  23593. } else {
  23594. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  23595. }
  23596. }
  23597. if (memo) {
  23598. const loop = createFunctionExpression(
  23599. createForLoopParams(forNode.parseResult, [
  23600. createSimpleExpression(`_cached`)
  23601. ])
  23602. );
  23603. loop.body = createBlockStatement([
  23604. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  23605. createCompoundExpression([
  23606. `if (_cached`,
  23607. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  23608. ` && ${context.helperString(
  23609. IS_MEMO_SAME
  23610. )}(_cached, _memo)) return _cached`
  23611. ]),
  23612. createCompoundExpression([`const _item = `, childBlock]),
  23613. createSimpleExpression(`_item.memo = _memo`),
  23614. createSimpleExpression(`return _item`)
  23615. ]);
  23616. renderExp.arguments.push(
  23617. loop,
  23618. createSimpleExpression(`_cache`),
  23619. createSimpleExpression(String(context.cached.length))
  23620. );
  23621. context.cached.push(null);
  23622. } else {
  23623. renderExp.arguments.push(
  23624. createFunctionExpression(
  23625. createForLoopParams(forNode.parseResult),
  23626. childBlock,
  23627. true
  23628. )
  23629. );
  23630. }
  23631. };
  23632. });
  23633. }
  23634. );
  23635. function processFor(node, dir, context, processCodegen) {
  23636. if (!dir.exp) {
  23637. context.onError(
  23638. createCompilerError(31, dir.loc)
  23639. );
  23640. return;
  23641. }
  23642. const parseResult = dir.forParseResult;
  23643. if (!parseResult) {
  23644. context.onError(
  23645. createCompilerError(32, dir.loc)
  23646. );
  23647. return;
  23648. }
  23649. finalizeForParseResult(parseResult, context);
  23650. const { addIdentifiers, removeIdentifiers, scopes } = context;
  23651. const { source, value, key, index } = parseResult;
  23652. const forNode = {
  23653. type: 11,
  23654. loc: dir.loc,
  23655. source,
  23656. valueAlias: value,
  23657. keyAlias: key,
  23658. objectIndexAlias: index,
  23659. parseResult,
  23660. children: isTemplateNode(node) ? node.children : [node]
  23661. };
  23662. context.replaceNode(forNode);
  23663. scopes.vFor++;
  23664. if (context.prefixIdentifiers) {
  23665. value && addIdentifiers(value);
  23666. key && addIdentifiers(key);
  23667. index && addIdentifiers(index);
  23668. }
  23669. const onExit = processCodegen && processCodegen(forNode);
  23670. return () => {
  23671. scopes.vFor--;
  23672. if (context.prefixIdentifiers) {
  23673. value && removeIdentifiers(value);
  23674. key && removeIdentifiers(key);
  23675. index && removeIdentifiers(index);
  23676. }
  23677. if (onExit) onExit();
  23678. };
  23679. }
  23680. function finalizeForParseResult(result, context) {
  23681. if (result.finalized) return;
  23682. if (context.prefixIdentifiers) {
  23683. result.source = processExpression(
  23684. result.source,
  23685. context
  23686. );
  23687. if (result.key) {
  23688. result.key = processExpression(
  23689. result.key,
  23690. context,
  23691. true
  23692. );
  23693. }
  23694. if (result.index) {
  23695. result.index = processExpression(
  23696. result.index,
  23697. context,
  23698. true
  23699. );
  23700. }
  23701. if (result.value) {
  23702. result.value = processExpression(
  23703. result.value,
  23704. context,
  23705. true
  23706. );
  23707. }
  23708. }
  23709. result.finalized = true;
  23710. }
  23711. function createForLoopParams({ value, key, index }, memoArgs = []) {
  23712. return createParamsList([value, key, index, ...memoArgs]);
  23713. }
  23714. function createParamsList(args) {
  23715. let i = args.length;
  23716. while (i--) {
  23717. if (args[i]) break;
  23718. }
  23719. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  23720. }
  23721. const defaultFallback = createSimpleExpression(`undefined`, false);
  23722. const trackSlotScopes = (node, context) => {
  23723. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  23724. const vSlot = findDir(node, "slot");
  23725. if (vSlot) {
  23726. const slotProps = vSlot.exp;
  23727. if (context.prefixIdentifiers) {
  23728. slotProps && context.addIdentifiers(slotProps);
  23729. }
  23730. context.scopes.vSlot++;
  23731. return () => {
  23732. if (context.prefixIdentifiers) {
  23733. slotProps && context.removeIdentifiers(slotProps);
  23734. }
  23735. context.scopes.vSlot--;
  23736. };
  23737. }
  23738. }
  23739. };
  23740. const trackVForSlotScopes = (node, context) => {
  23741. let vFor;
  23742. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  23743. const result = vFor.forParseResult;
  23744. if (result) {
  23745. finalizeForParseResult(result, context);
  23746. const { value, key, index } = result;
  23747. const { addIdentifiers, removeIdentifiers } = context;
  23748. value && addIdentifiers(value);
  23749. key && addIdentifiers(key);
  23750. index && addIdentifiers(index);
  23751. return () => {
  23752. value && removeIdentifiers(value);
  23753. key && removeIdentifiers(key);
  23754. index && removeIdentifiers(index);
  23755. };
  23756. }
  23757. }
  23758. };
  23759. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  23760. props,
  23761. children,
  23762. false,
  23763. true,
  23764. children.length ? children[0].loc : loc
  23765. );
  23766. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  23767. context.helper(WITH_CTX);
  23768. const { children, loc } = node;
  23769. const slotsProperties = [];
  23770. const dynamicSlots = [];
  23771. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  23772. if (!context.ssr && context.prefixIdentifiers) {
  23773. hasDynamicSlots = hasScopeRef(node, context.identifiers);
  23774. }
  23775. const onComponentSlot = findDir(node, "slot", true);
  23776. if (onComponentSlot) {
  23777. const { arg, exp } = onComponentSlot;
  23778. if (arg && !isStaticExp(arg)) {
  23779. hasDynamicSlots = true;
  23780. }
  23781. slotsProperties.push(
  23782. createObjectProperty(
  23783. arg || createSimpleExpression("default", true),
  23784. buildSlotFn(exp, void 0, children, loc)
  23785. )
  23786. );
  23787. }
  23788. let hasTemplateSlots = false;
  23789. let hasNamedDefaultSlot = false;
  23790. const implicitDefaultChildren = [];
  23791. const seenSlotNames = /* @__PURE__ */ new Set();
  23792. let conditionalBranchIndex = 0;
  23793. for (let i = 0; i < children.length; i++) {
  23794. const slotElement = children[i];
  23795. let slotDir;
  23796. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  23797. if (slotElement.type !== 3) {
  23798. implicitDefaultChildren.push(slotElement);
  23799. }
  23800. continue;
  23801. }
  23802. if (onComponentSlot) {
  23803. context.onError(
  23804. createCompilerError(37, slotDir.loc)
  23805. );
  23806. break;
  23807. }
  23808. hasTemplateSlots = true;
  23809. const { children: slotChildren, loc: slotLoc } = slotElement;
  23810. const {
  23811. arg: slotName = createSimpleExpression(`default`, true),
  23812. exp: slotProps,
  23813. loc: dirLoc
  23814. } = slotDir;
  23815. let staticSlotName;
  23816. if (isStaticExp(slotName)) {
  23817. staticSlotName = slotName ? slotName.content : `default`;
  23818. } else {
  23819. hasDynamicSlots = true;
  23820. }
  23821. const vFor = findDir(slotElement, "for");
  23822. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  23823. let vIf;
  23824. let vElse;
  23825. if (vIf = findDir(slotElement, "if")) {
  23826. hasDynamicSlots = true;
  23827. dynamicSlots.push(
  23828. createConditionalExpression(
  23829. vIf.exp,
  23830. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  23831. defaultFallback
  23832. )
  23833. );
  23834. } else if (vElse = findDir(
  23835. slotElement,
  23836. /^else(-if)?$/,
  23837. true
  23838. /* allowEmpty */
  23839. )) {
  23840. let j = i;
  23841. let prev;
  23842. while (j--) {
  23843. prev = children[j];
  23844. if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
  23845. break;
  23846. }
  23847. }
  23848. if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
  23849. let conditional = dynamicSlots[dynamicSlots.length - 1];
  23850. while (conditional.alternate.type === 19) {
  23851. conditional = conditional.alternate;
  23852. }
  23853. conditional.alternate = vElse.exp ? createConditionalExpression(
  23854. vElse.exp,
  23855. buildDynamicSlot(
  23856. slotName,
  23857. slotFunction,
  23858. conditionalBranchIndex++
  23859. ),
  23860. defaultFallback
  23861. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  23862. } else {
  23863. context.onError(
  23864. createCompilerError(30, vElse.loc)
  23865. );
  23866. }
  23867. } else if (vFor) {
  23868. hasDynamicSlots = true;
  23869. const parseResult = vFor.forParseResult;
  23870. if (parseResult) {
  23871. finalizeForParseResult(parseResult, context);
  23872. dynamicSlots.push(
  23873. createCallExpression(context.helper(RENDER_LIST), [
  23874. parseResult.source,
  23875. createFunctionExpression(
  23876. createForLoopParams(parseResult),
  23877. buildDynamicSlot(slotName, slotFunction),
  23878. true
  23879. )
  23880. ])
  23881. );
  23882. } else {
  23883. context.onError(
  23884. createCompilerError(
  23885. 32,
  23886. vFor.loc
  23887. )
  23888. );
  23889. }
  23890. } else {
  23891. if (staticSlotName) {
  23892. if (seenSlotNames.has(staticSlotName)) {
  23893. context.onError(
  23894. createCompilerError(
  23895. 38,
  23896. dirLoc
  23897. )
  23898. );
  23899. continue;
  23900. }
  23901. seenSlotNames.add(staticSlotName);
  23902. if (staticSlotName === "default") {
  23903. hasNamedDefaultSlot = true;
  23904. }
  23905. }
  23906. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  23907. }
  23908. }
  23909. if (!onComponentSlot) {
  23910. const buildDefaultSlotProperty = (props, children2) => {
  23911. const fn = buildSlotFn(props, void 0, children2, loc);
  23912. return createObjectProperty(`default`, fn);
  23913. };
  23914. if (!hasTemplateSlots) {
  23915. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  23916. } else if (implicitDefaultChildren.length && // #3766
  23917. // with whitespace: 'preserve', whitespaces between slots will end up in
  23918. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  23919. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  23920. if (hasNamedDefaultSlot) {
  23921. context.onError(
  23922. createCompilerError(
  23923. 39,
  23924. implicitDefaultChildren[0].loc
  23925. )
  23926. );
  23927. } else {
  23928. slotsProperties.push(
  23929. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  23930. );
  23931. }
  23932. }
  23933. }
  23934. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  23935. let slots = createObjectExpression(
  23936. slotsProperties.concat(
  23937. createObjectProperty(
  23938. `_`,
  23939. // 2 = compiled but dynamic = can skip normalization, but must run diff
  23940. // 1 = compiled and static = can skip normalization AND diff as optimized
  23941. createSimpleExpression(
  23942. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  23943. false
  23944. )
  23945. )
  23946. ),
  23947. loc
  23948. );
  23949. if (dynamicSlots.length) {
  23950. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  23951. slots,
  23952. createArrayExpression(dynamicSlots)
  23953. ]);
  23954. }
  23955. return {
  23956. slots,
  23957. hasDynamicSlots
  23958. };
  23959. }
  23960. function buildDynamicSlot(name, fn, index) {
  23961. const props = [
  23962. createObjectProperty(`name`, name),
  23963. createObjectProperty(`fn`, fn)
  23964. ];
  23965. if (index != null) {
  23966. props.push(
  23967. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  23968. );
  23969. }
  23970. return createObjectExpression(props);
  23971. }
  23972. function hasForwardedSlots(children) {
  23973. for (let i = 0; i < children.length; i++) {
  23974. const child = children[i];
  23975. switch (child.type) {
  23976. case 1:
  23977. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  23978. return true;
  23979. }
  23980. break;
  23981. case 9:
  23982. if (hasForwardedSlots(child.branches)) return true;
  23983. break;
  23984. case 10:
  23985. case 11:
  23986. if (hasForwardedSlots(child.children)) return true;
  23987. break;
  23988. }
  23989. }
  23990. return false;
  23991. }
  23992. function isNonWhitespaceContent(node) {
  23993. if (node.type !== 2 && node.type !== 12)
  23994. return true;
  23995. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  23996. }
  23997. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  23998. const transformElement = (node, context) => {
  23999. return function postTransformElement() {
  24000. node = context.currentNode;
  24001. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  24002. return;
  24003. }
  24004. const { tag, props } = node;
  24005. const isComponent = node.tagType === 1;
  24006. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  24007. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  24008. let vnodeProps;
  24009. let vnodeChildren;
  24010. let patchFlag = 0;
  24011. let vnodeDynamicProps;
  24012. let dynamicPropNames;
  24013. let vnodeDirectives;
  24014. let shouldUseBlock = (
  24015. // dynamic component may resolve to plain elements
  24016. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  24017. // updates inside get proper isSVG flag at runtime. (#639, #643)
  24018. // This is technically web-specific, but splitting the logic out of core
  24019. // leads to too much unnecessary complexity.
  24020. (tag === "svg" || tag === "foreignObject" || tag === "math")
  24021. );
  24022. if (props.length > 0) {
  24023. const propsBuildResult = buildProps(
  24024. node,
  24025. context,
  24026. void 0,
  24027. isComponent,
  24028. isDynamicComponent
  24029. );
  24030. vnodeProps = propsBuildResult.props;
  24031. patchFlag = propsBuildResult.patchFlag;
  24032. dynamicPropNames = propsBuildResult.dynamicPropNames;
  24033. const directives = propsBuildResult.directives;
  24034. vnodeDirectives = directives && directives.length ? createArrayExpression(
  24035. directives.map((dir) => buildDirectiveArgs(dir, context))
  24036. ) : void 0;
  24037. if (propsBuildResult.shouldUseBlock) {
  24038. shouldUseBlock = true;
  24039. }
  24040. }
  24041. if (node.children.length > 0) {
  24042. if (vnodeTag === KEEP_ALIVE) {
  24043. shouldUseBlock = true;
  24044. patchFlag |= 1024;
  24045. if (node.children.length > 1) {
  24046. context.onError(
  24047. createCompilerError(46, {
  24048. start: node.children[0].loc.start,
  24049. end: node.children[node.children.length - 1].loc.end,
  24050. source: ""
  24051. })
  24052. );
  24053. }
  24054. }
  24055. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  24056. vnodeTag !== TELEPORT && // explained above.
  24057. vnodeTag !== KEEP_ALIVE;
  24058. if (shouldBuildAsSlots) {
  24059. const { slots, hasDynamicSlots } = buildSlots(node, context);
  24060. vnodeChildren = slots;
  24061. if (hasDynamicSlots) {
  24062. patchFlag |= 1024;
  24063. }
  24064. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  24065. const child = node.children[0];
  24066. const type = child.type;
  24067. const hasDynamicTextChild = type === 5 || type === 8;
  24068. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  24069. patchFlag |= 1;
  24070. }
  24071. if (hasDynamicTextChild || type === 2) {
  24072. vnodeChildren = child;
  24073. } else {
  24074. vnodeChildren = node.children;
  24075. }
  24076. } else {
  24077. vnodeChildren = node.children;
  24078. }
  24079. }
  24080. if (dynamicPropNames && dynamicPropNames.length) {
  24081. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  24082. }
  24083. node.codegenNode = createVNodeCall(
  24084. context,
  24085. vnodeTag,
  24086. vnodeProps,
  24087. vnodeChildren,
  24088. patchFlag === 0 ? void 0 : patchFlag,
  24089. vnodeDynamicProps,
  24090. vnodeDirectives,
  24091. !!shouldUseBlock,
  24092. false,
  24093. isComponent,
  24094. node.loc
  24095. );
  24096. };
  24097. };
  24098. function resolveComponentType(node, context, ssr = false) {
  24099. let { tag } = node;
  24100. const isExplicitDynamic = isComponentTag(tag);
  24101. const isProp = findProp(
  24102. node,
  24103. "is",
  24104. false,
  24105. true
  24106. /* allow empty */
  24107. );
  24108. if (isProp) {
  24109. if (isExplicitDynamic || false) {
  24110. let exp;
  24111. if (isProp.type === 6) {
  24112. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  24113. } else {
  24114. exp = isProp.exp;
  24115. if (!exp) {
  24116. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  24117. {
  24118. exp = isProp.exp = processExpression(exp, context);
  24119. }
  24120. }
  24121. }
  24122. if (exp) {
  24123. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  24124. exp
  24125. ]);
  24126. }
  24127. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  24128. tag = isProp.value.content.slice(4);
  24129. }
  24130. }
  24131. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  24132. if (builtIn) {
  24133. if (!ssr) context.helper(builtIn);
  24134. return builtIn;
  24135. }
  24136. {
  24137. const fromSetup = resolveSetupReference(tag, context);
  24138. if (fromSetup) {
  24139. return fromSetup;
  24140. }
  24141. const dotIndex = tag.indexOf(".");
  24142. if (dotIndex > 0) {
  24143. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  24144. if (ns) {
  24145. return ns + tag.slice(dotIndex);
  24146. }
  24147. }
  24148. }
  24149. if (context.selfName && capitalize(camelize(tag)) === context.selfName) {
  24150. context.helper(RESOLVE_COMPONENT);
  24151. context.components.add(tag + `__self`);
  24152. return toValidAssetId(tag, `component`);
  24153. }
  24154. context.helper(RESOLVE_COMPONENT);
  24155. context.components.add(tag);
  24156. return toValidAssetId(tag, `component`);
  24157. }
  24158. function resolveSetupReference(name, context) {
  24159. const bindings = context.bindingMetadata;
  24160. if (!bindings || bindings.__isScriptSetup === false) {
  24161. return;
  24162. }
  24163. const camelName = camelize(name);
  24164. const PascalName = capitalize(camelName);
  24165. const checkType = (type) => {
  24166. if (bindings[name] === type) {
  24167. return name;
  24168. }
  24169. if (bindings[camelName] === type) {
  24170. return camelName;
  24171. }
  24172. if (bindings[PascalName] === type) {
  24173. return PascalName;
  24174. }
  24175. };
  24176. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  24177. if (fromConst) {
  24178. return context.inline ? (
  24179. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  24180. fromConst
  24181. ) : `$setup[${JSON.stringify(fromConst)}]`;
  24182. }
  24183. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  24184. if (fromMaybeRef) {
  24185. return context.inline ? (
  24186. // setup scope bindings that may be refs need to be unrefed
  24187. `${context.helperString(UNREF)}(${fromMaybeRef})`
  24188. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  24189. }
  24190. const fromProps = checkType("props");
  24191. if (fromProps) {
  24192. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  24193. }
  24194. }
  24195. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  24196. const { tag, loc: elementLoc, children } = node;
  24197. let properties = [];
  24198. const mergeArgs = [];
  24199. const runtimeDirectives = [];
  24200. const hasChildren = children.length > 0;
  24201. let shouldUseBlock = false;
  24202. let patchFlag = 0;
  24203. let hasRef = false;
  24204. let hasClassBinding = false;
  24205. let hasStyleBinding = false;
  24206. let hasHydrationEventBinding = false;
  24207. let hasDynamicKeys = false;
  24208. let hasVnodeHook = false;
  24209. const dynamicPropNames = [];
  24210. const pushMergeArg = (arg) => {
  24211. if (properties.length) {
  24212. mergeArgs.push(
  24213. createObjectExpression(dedupeProperties(properties), elementLoc)
  24214. );
  24215. properties = [];
  24216. }
  24217. if (arg) mergeArgs.push(arg);
  24218. };
  24219. const pushRefVForMarker = () => {
  24220. if (context.scopes.vFor > 0) {
  24221. properties.push(
  24222. createObjectProperty(
  24223. createSimpleExpression("ref_for", true),
  24224. createSimpleExpression("true")
  24225. )
  24226. );
  24227. }
  24228. };
  24229. const analyzePatchFlag = ({ key, value }) => {
  24230. if (isStaticExp(key)) {
  24231. const name = key.content;
  24232. const isEventHandler = isOn(name);
  24233. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  24234. // dedicated fast path.
  24235. name.toLowerCase() !== "onclick" && // omit v-model handlers
  24236. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  24237. !isReservedProp(name)) {
  24238. hasHydrationEventBinding = true;
  24239. }
  24240. if (isEventHandler && isReservedProp(name)) {
  24241. hasVnodeHook = true;
  24242. }
  24243. if (isEventHandler && value.type === 14) {
  24244. value = value.arguments[0];
  24245. }
  24246. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  24247. return;
  24248. }
  24249. if (name === "ref") {
  24250. hasRef = true;
  24251. } else if (name === "class") {
  24252. hasClassBinding = true;
  24253. } else if (name === "style") {
  24254. hasStyleBinding = true;
  24255. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  24256. dynamicPropNames.push(name);
  24257. }
  24258. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  24259. dynamicPropNames.push(name);
  24260. }
  24261. } else {
  24262. hasDynamicKeys = true;
  24263. }
  24264. };
  24265. for (let i = 0; i < props.length; i++) {
  24266. const prop = props[i];
  24267. if (prop.type === 6) {
  24268. const { loc, name, nameLoc, value } = prop;
  24269. let isStatic = true;
  24270. if (name === "ref") {
  24271. hasRef = true;
  24272. pushRefVForMarker();
  24273. if (value && context.inline) {
  24274. const binding = context.bindingMetadata[value.content];
  24275. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  24276. isStatic = false;
  24277. properties.push(
  24278. createObjectProperty(
  24279. createSimpleExpression("ref_key", true),
  24280. createSimpleExpression(value.content, true, value.loc)
  24281. )
  24282. );
  24283. }
  24284. }
  24285. }
  24286. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  24287. continue;
  24288. }
  24289. properties.push(
  24290. createObjectProperty(
  24291. createSimpleExpression(name, true, nameLoc),
  24292. createSimpleExpression(
  24293. value ? value.content : "",
  24294. isStatic,
  24295. value ? value.loc : loc
  24296. )
  24297. )
  24298. );
  24299. } else {
  24300. const { name, arg, exp, loc, modifiers } = prop;
  24301. const isVBind = name === "bind";
  24302. const isVOn = name === "on";
  24303. if (name === "slot") {
  24304. if (!isComponent) {
  24305. context.onError(
  24306. createCompilerError(40, loc)
  24307. );
  24308. }
  24309. continue;
  24310. }
  24311. if (name === "once" || name === "memo") {
  24312. continue;
  24313. }
  24314. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  24315. continue;
  24316. }
  24317. if (isVOn && ssr) {
  24318. continue;
  24319. }
  24320. if (
  24321. // #938: elements with dynamic keys should be forced into blocks
  24322. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  24323. // before children
  24324. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  24325. ) {
  24326. shouldUseBlock = true;
  24327. }
  24328. if (isVBind && isStaticArgOf(arg, "ref")) {
  24329. pushRefVForMarker();
  24330. }
  24331. if (!arg && (isVBind || isVOn)) {
  24332. hasDynamicKeys = true;
  24333. if (exp) {
  24334. if (isVBind) {
  24335. pushRefVForMarker();
  24336. pushMergeArg();
  24337. mergeArgs.push(exp);
  24338. } else {
  24339. pushMergeArg({
  24340. type: 14,
  24341. loc,
  24342. callee: context.helper(TO_HANDLERS),
  24343. arguments: isComponent ? [exp] : [exp, `true`]
  24344. });
  24345. }
  24346. } else {
  24347. context.onError(
  24348. createCompilerError(
  24349. isVBind ? 34 : 35,
  24350. loc
  24351. )
  24352. );
  24353. }
  24354. continue;
  24355. }
  24356. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  24357. patchFlag |= 32;
  24358. }
  24359. const directiveTransform = context.directiveTransforms[name];
  24360. if (directiveTransform) {
  24361. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  24362. !ssr && props2.forEach(analyzePatchFlag);
  24363. if (isVOn && arg && !isStaticExp(arg)) {
  24364. pushMergeArg(createObjectExpression(props2, elementLoc));
  24365. } else {
  24366. properties.push(...props2);
  24367. }
  24368. if (needRuntime) {
  24369. runtimeDirectives.push(prop);
  24370. if (isSymbol$1(needRuntime)) {
  24371. directiveImportMap.set(prop, needRuntime);
  24372. }
  24373. }
  24374. } else if (!isBuiltInDirective(name)) {
  24375. runtimeDirectives.push(prop);
  24376. if (hasChildren) {
  24377. shouldUseBlock = true;
  24378. }
  24379. }
  24380. }
  24381. }
  24382. let propsExpression = void 0;
  24383. if (mergeArgs.length) {
  24384. pushMergeArg();
  24385. if (mergeArgs.length > 1) {
  24386. propsExpression = createCallExpression(
  24387. context.helper(MERGE_PROPS),
  24388. mergeArgs,
  24389. elementLoc
  24390. );
  24391. } else {
  24392. propsExpression = mergeArgs[0];
  24393. }
  24394. } else if (properties.length) {
  24395. propsExpression = createObjectExpression(
  24396. dedupeProperties(properties),
  24397. elementLoc
  24398. );
  24399. }
  24400. if (hasDynamicKeys) {
  24401. patchFlag |= 16;
  24402. } else {
  24403. if (hasClassBinding && !isComponent) {
  24404. patchFlag |= 2;
  24405. }
  24406. if (hasStyleBinding && !isComponent) {
  24407. patchFlag |= 4;
  24408. }
  24409. if (dynamicPropNames.length) {
  24410. patchFlag |= 8;
  24411. }
  24412. if (hasHydrationEventBinding) {
  24413. patchFlag |= 32;
  24414. }
  24415. }
  24416. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  24417. patchFlag |= 512;
  24418. }
  24419. if (!context.inSSR && propsExpression) {
  24420. switch (propsExpression.type) {
  24421. case 15:
  24422. let classKeyIndex = -1;
  24423. let styleKeyIndex = -1;
  24424. let hasDynamicKey = false;
  24425. for (let i = 0; i < propsExpression.properties.length; i++) {
  24426. const key = propsExpression.properties[i].key;
  24427. if (isStaticExp(key)) {
  24428. if (key.content === "class") {
  24429. classKeyIndex = i;
  24430. } else if (key.content === "style") {
  24431. styleKeyIndex = i;
  24432. }
  24433. } else if (!key.isHandlerKey) {
  24434. hasDynamicKey = true;
  24435. }
  24436. }
  24437. const classProp = propsExpression.properties[classKeyIndex];
  24438. const styleProp = propsExpression.properties[styleKeyIndex];
  24439. if (!hasDynamicKey) {
  24440. if (classProp && !isStaticExp(classProp.value)) {
  24441. classProp.value = createCallExpression(
  24442. context.helper(NORMALIZE_CLASS),
  24443. [classProp.value]
  24444. );
  24445. }
  24446. if (styleProp && // the static style is compiled into an object,
  24447. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  24448. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  24449. // v-bind:style with static literal object
  24450. styleProp.value.type === 17)) {
  24451. styleProp.value = createCallExpression(
  24452. context.helper(NORMALIZE_STYLE),
  24453. [styleProp.value]
  24454. );
  24455. }
  24456. } else {
  24457. propsExpression = createCallExpression(
  24458. context.helper(NORMALIZE_PROPS),
  24459. [propsExpression]
  24460. );
  24461. }
  24462. break;
  24463. case 14:
  24464. break;
  24465. default:
  24466. propsExpression = createCallExpression(
  24467. context.helper(NORMALIZE_PROPS),
  24468. [
  24469. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  24470. propsExpression
  24471. ])
  24472. ]
  24473. );
  24474. break;
  24475. }
  24476. }
  24477. return {
  24478. props: propsExpression,
  24479. directives: runtimeDirectives,
  24480. patchFlag,
  24481. dynamicPropNames,
  24482. shouldUseBlock
  24483. };
  24484. }
  24485. function dedupeProperties(properties) {
  24486. const knownProps = /* @__PURE__ */ new Map();
  24487. const deduped = [];
  24488. for (let i = 0; i < properties.length; i++) {
  24489. const prop = properties[i];
  24490. if (prop.key.type === 8 || !prop.key.isStatic) {
  24491. deduped.push(prop);
  24492. continue;
  24493. }
  24494. const name = prop.key.content;
  24495. const existing = knownProps.get(name);
  24496. if (existing) {
  24497. if (name === "style" || name === "class" || isOn(name)) {
  24498. mergeAsArray(existing, prop);
  24499. }
  24500. } else {
  24501. knownProps.set(name, prop);
  24502. deduped.push(prop);
  24503. }
  24504. }
  24505. return deduped;
  24506. }
  24507. function mergeAsArray(existing, incoming) {
  24508. if (existing.value.type === 17) {
  24509. existing.value.elements.push(incoming.value);
  24510. } else {
  24511. existing.value = createArrayExpression(
  24512. [existing.value, incoming.value],
  24513. existing.loc
  24514. );
  24515. }
  24516. }
  24517. function buildDirectiveArgs(dir, context) {
  24518. const dirArgs = [];
  24519. const runtime = directiveImportMap.get(dir);
  24520. if (runtime) {
  24521. dirArgs.push(context.helperString(runtime));
  24522. } else {
  24523. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  24524. if (fromSetup) {
  24525. dirArgs.push(fromSetup);
  24526. } else {
  24527. context.helper(RESOLVE_DIRECTIVE);
  24528. context.directives.add(dir.name);
  24529. dirArgs.push(toValidAssetId(dir.name, `directive`));
  24530. }
  24531. }
  24532. const { loc } = dir;
  24533. if (dir.exp) dirArgs.push(dir.exp);
  24534. if (dir.arg) {
  24535. if (!dir.exp) {
  24536. dirArgs.push(`void 0`);
  24537. }
  24538. dirArgs.push(dir.arg);
  24539. }
  24540. if (Object.keys(dir.modifiers).length) {
  24541. if (!dir.arg) {
  24542. if (!dir.exp) {
  24543. dirArgs.push(`void 0`);
  24544. }
  24545. dirArgs.push(`void 0`);
  24546. }
  24547. const trueExpression = createSimpleExpression(`true`, false, loc);
  24548. dirArgs.push(
  24549. createObjectExpression(
  24550. dir.modifiers.map(
  24551. (modifier) => createObjectProperty(modifier, trueExpression)
  24552. ),
  24553. loc
  24554. )
  24555. );
  24556. }
  24557. return createArrayExpression(dirArgs, dir.loc);
  24558. }
  24559. function stringifyDynamicPropNames(props) {
  24560. let propsNamesString = `[`;
  24561. for (let i = 0, l = props.length; i < l; i++) {
  24562. propsNamesString += JSON.stringify(props[i]);
  24563. if (i < l - 1) propsNamesString += ", ";
  24564. }
  24565. return propsNamesString + `]`;
  24566. }
  24567. function isComponentTag(tag) {
  24568. return tag === "component" || tag === "Component";
  24569. }
  24570. const transformSlotOutlet = (node, context) => {
  24571. if (isSlotOutlet(node)) {
  24572. const { children, loc } = node;
  24573. const { slotName, slotProps } = processSlotOutlet(node, context);
  24574. const slotArgs = [
  24575. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  24576. slotName,
  24577. "{}",
  24578. "undefined",
  24579. "true"
  24580. ];
  24581. let expectedLen = 2;
  24582. if (slotProps) {
  24583. slotArgs[2] = slotProps;
  24584. expectedLen = 3;
  24585. }
  24586. if (children.length) {
  24587. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  24588. expectedLen = 4;
  24589. }
  24590. if (context.scopeId && !context.slotted) {
  24591. expectedLen = 5;
  24592. }
  24593. slotArgs.splice(expectedLen);
  24594. node.codegenNode = createCallExpression(
  24595. context.helper(RENDER_SLOT),
  24596. slotArgs,
  24597. loc
  24598. );
  24599. }
  24600. };
  24601. function processSlotOutlet(node, context) {
  24602. let slotName = `"default"`;
  24603. let slotProps = void 0;
  24604. const nonNameProps = [];
  24605. for (let i = 0; i < node.props.length; i++) {
  24606. const p = node.props[i];
  24607. if (p.type === 6) {
  24608. if (p.value) {
  24609. if (p.name === "name") {
  24610. slotName = JSON.stringify(p.value.content);
  24611. } else {
  24612. p.name = camelize(p.name);
  24613. nonNameProps.push(p);
  24614. }
  24615. }
  24616. } else {
  24617. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  24618. if (p.exp) {
  24619. slotName = p.exp;
  24620. } else if (p.arg && p.arg.type === 4) {
  24621. const name = camelize(p.arg.content);
  24622. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  24623. {
  24624. slotName = p.exp = processExpression(p.exp, context);
  24625. }
  24626. }
  24627. } else {
  24628. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  24629. p.arg.content = camelize(p.arg.content);
  24630. }
  24631. nonNameProps.push(p);
  24632. }
  24633. }
  24634. }
  24635. if (nonNameProps.length > 0) {
  24636. const { props, directives } = buildProps(
  24637. node,
  24638. context,
  24639. nonNameProps,
  24640. false,
  24641. false
  24642. );
  24643. slotProps = props;
  24644. if (directives.length) {
  24645. context.onError(
  24646. createCompilerError(
  24647. 36,
  24648. directives[0].loc
  24649. )
  24650. );
  24651. }
  24652. }
  24653. return {
  24654. slotName,
  24655. slotProps
  24656. };
  24657. }
  24658. const transformOn$1 = (dir, node, context, augmentor) => {
  24659. const { loc, modifiers, arg } = dir;
  24660. if (!dir.exp && !modifiers.length) {
  24661. context.onError(createCompilerError(35, loc));
  24662. }
  24663. let eventName;
  24664. if (arg.type === 4) {
  24665. if (arg.isStatic) {
  24666. let rawName = arg.content;
  24667. if (rawName.startsWith("vnode")) {
  24668. context.onError(createCompilerError(51, arg.loc));
  24669. }
  24670. if (rawName.startsWith("vue:")) {
  24671. rawName = `vnode-${rawName.slice(4)}`;
  24672. }
  24673. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  24674. // for non-element and vnode lifecycle event listeners, auto convert
  24675. // it to camelCase. See issue #2249
  24676. toHandlerKey(camelize(rawName))
  24677. ) : (
  24678. // preserve case for plain element listeners that have uppercase
  24679. // letters, as these may be custom elements' custom events
  24680. `on:${rawName}`
  24681. );
  24682. eventName = createSimpleExpression(eventString, true, arg.loc);
  24683. } else {
  24684. eventName = createCompoundExpression([
  24685. `${context.helperString(TO_HANDLER_KEY)}(`,
  24686. arg,
  24687. `)`
  24688. ]);
  24689. }
  24690. } else {
  24691. eventName = arg;
  24692. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  24693. eventName.children.push(`)`);
  24694. }
  24695. let exp = dir.exp;
  24696. if (exp && !exp.content.trim()) {
  24697. exp = void 0;
  24698. }
  24699. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  24700. if (exp) {
  24701. const isMemberExp = isMemberExpression(exp, context);
  24702. const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
  24703. const hasMultipleStatements = exp.content.includes(`;`);
  24704. if (context.prefixIdentifiers) {
  24705. isInlineStatement && context.addIdentifiers(`$event`);
  24706. exp = dir.exp = processExpression(
  24707. exp,
  24708. context,
  24709. false,
  24710. hasMultipleStatements
  24711. );
  24712. isInlineStatement && context.removeIdentifiers(`$event`);
  24713. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  24714. !context.inVOnce && // runtime constants don't need to be cached
  24715. // (this is analyzed by compileScript in SFC <script setup>)
  24716. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  24717. // we need to use the original function to preserve arity,
  24718. // e.g. <transition> relies on checking cb.length to determine
  24719. // transition end handling. Inline function is ok since its arity
  24720. // is preserved even when cached.
  24721. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  24722. // it must be passed fresh to avoid stale values.
  24723. !hasScopeRef(exp, context.identifiers);
  24724. if (shouldCache && isMemberExp) {
  24725. if (exp.type === 4) {
  24726. exp.content = `${exp.content} && ${exp.content}(...args)`;
  24727. } else {
  24728. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  24729. }
  24730. }
  24731. }
  24732. if (isInlineStatement || shouldCache && isMemberExp) {
  24733. exp = createCompoundExpression([
  24734. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  24735. //@ts-ignore
  24736. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  24737. exp,
  24738. hasMultipleStatements ? `}` : `)`
  24739. ]);
  24740. }
  24741. }
  24742. let ret = {
  24743. props: [
  24744. createObjectProperty(
  24745. eventName,
  24746. exp || createSimpleExpression(`() => {}`, false, loc)
  24747. )
  24748. ]
  24749. };
  24750. if (augmentor) {
  24751. ret = augmentor(ret);
  24752. }
  24753. if (shouldCache) {
  24754. ret.props[0].value = context.cache(ret.props[0].value);
  24755. }
  24756. ret.props.forEach((p) => p.key.isHandlerKey = true);
  24757. return ret;
  24758. };
  24759. const transformText = (node, context) => {
  24760. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  24761. return () => {
  24762. const children = node.children;
  24763. let currentContainer = void 0;
  24764. let hasText = false;
  24765. for (let i = 0; i < children.length; i++) {
  24766. const child = children[i];
  24767. if (isText$1(child)) {
  24768. hasText = true;
  24769. for (let j = i + 1; j < children.length; j++) {
  24770. const next = children[j];
  24771. if (isText$1(next)) {
  24772. if (!currentContainer) {
  24773. currentContainer = children[i] = createCompoundExpression(
  24774. [child],
  24775. child.loc
  24776. );
  24777. }
  24778. currentContainer.children.push(` + `, next);
  24779. children.splice(j, 1);
  24780. j--;
  24781. } else {
  24782. currentContainer = void 0;
  24783. break;
  24784. }
  24785. }
  24786. }
  24787. }
  24788. if (!hasText || // if this is a plain element with a single text child, leave it
  24789. // as-is since the runtime has dedicated fast path for this by directly
  24790. // setting textContent of the element.
  24791. // for component root it's always normalized anyway.
  24792. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  24793. // custom directives can potentially add DOM elements arbitrarily,
  24794. // we need to avoid setting textContent of the element at runtime
  24795. // to avoid accidentally overwriting the DOM elements added
  24796. // by the user through custom directives.
  24797. !node.props.find(
  24798. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  24799. ) && // in compat mode, <template> tags with no special directives
  24800. // will be rendered as a fragment so its children must be
  24801. // converted into vnodes.
  24802. true)) {
  24803. return;
  24804. }
  24805. for (let i = 0; i < children.length; i++) {
  24806. const child = children[i];
  24807. if (isText$1(child) || child.type === 8) {
  24808. const callArgs = [];
  24809. if (child.type !== 2 || child.content !== " ") {
  24810. callArgs.push(child);
  24811. }
  24812. if (!context.ssr && getConstantType(child, context) === 0) {
  24813. callArgs.push(
  24814. 1 + (` /* ${PatchFlagNames[1]} */` )
  24815. );
  24816. }
  24817. children[i] = {
  24818. type: 12,
  24819. content: child,
  24820. loc: child.loc,
  24821. codegenNode: createCallExpression(
  24822. context.helper(CREATE_TEXT),
  24823. callArgs
  24824. )
  24825. };
  24826. }
  24827. }
  24828. };
  24829. }
  24830. };
  24831. const seen$1 = /* @__PURE__ */ new WeakSet();
  24832. const transformOnce = (node, context) => {
  24833. if (node.type === 1 && findDir(node, "once", true)) {
  24834. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  24835. return;
  24836. }
  24837. seen$1.add(node);
  24838. context.inVOnce = true;
  24839. context.helper(SET_BLOCK_TRACKING);
  24840. return () => {
  24841. context.inVOnce = false;
  24842. const cur = context.currentNode;
  24843. if (cur.codegenNode) {
  24844. cur.codegenNode = context.cache(
  24845. cur.codegenNode,
  24846. true,
  24847. true
  24848. );
  24849. }
  24850. };
  24851. }
  24852. };
  24853. const transformModel$1 = (dir, node, context) => {
  24854. const { exp, arg } = dir;
  24855. if (!exp) {
  24856. context.onError(
  24857. createCompilerError(41, dir.loc)
  24858. );
  24859. return createTransformProps();
  24860. }
  24861. const rawExp = exp.loc.source.trim();
  24862. const expString = exp.type === 4 ? exp.content : rawExp;
  24863. const bindingType = context.bindingMetadata[rawExp];
  24864. if (bindingType === "props" || bindingType === "props-aliased") {
  24865. context.onError(createCompilerError(44, exp.loc));
  24866. return createTransformProps();
  24867. }
  24868. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  24869. if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
  24870. context.onError(
  24871. createCompilerError(42, exp.loc)
  24872. );
  24873. return createTransformProps();
  24874. }
  24875. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  24876. context.onError(
  24877. createCompilerError(43, exp.loc)
  24878. );
  24879. return createTransformProps();
  24880. }
  24881. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  24882. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  24883. let assignmentExp;
  24884. const eventArg = context.isTS ? `($event: any)` : `$event`;
  24885. if (maybeRef) {
  24886. if (bindingType === "setup-ref") {
  24887. assignmentExp = createCompoundExpression([
  24888. `${eventArg} => ((`,
  24889. createSimpleExpression(rawExp, false, exp.loc),
  24890. `).value = $event)`
  24891. ]);
  24892. } else {
  24893. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  24894. assignmentExp = createCompoundExpression([
  24895. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  24896. createSimpleExpression(rawExp, false, exp.loc),
  24897. `).value = $event : ${altAssignment})`
  24898. ]);
  24899. }
  24900. } else {
  24901. assignmentExp = createCompoundExpression([
  24902. `${eventArg} => ((`,
  24903. exp,
  24904. `) = $event)`
  24905. ]);
  24906. }
  24907. const props = [
  24908. // modelValue: foo
  24909. createObjectProperty(propName, dir.exp),
  24910. // "onUpdate:modelValue": $event => (foo = $event)
  24911. createObjectProperty(eventName, assignmentExp)
  24912. ];
  24913. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  24914. props[1].value = context.cache(props[1].value);
  24915. }
  24916. if (dir.modifiers.length && node.tagType === 1) {
  24917. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  24918. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  24919. props.push(
  24920. createObjectProperty(
  24921. modifiersKey,
  24922. createSimpleExpression(
  24923. `{ ${modifiers} }`,
  24924. false,
  24925. dir.loc,
  24926. 2
  24927. )
  24928. )
  24929. );
  24930. }
  24931. return createTransformProps(props);
  24932. };
  24933. function createTransformProps(props = []) {
  24934. return { props };
  24935. }
  24936. const seen = /* @__PURE__ */ new WeakSet();
  24937. const transformMemo = (node, context) => {
  24938. if (node.type === 1) {
  24939. const dir = findDir(node, "memo");
  24940. if (!dir || seen.has(node) || context.inSSR) {
  24941. return;
  24942. }
  24943. seen.add(node);
  24944. return () => {
  24945. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  24946. if (codegenNode && codegenNode.type === 13) {
  24947. if (node.tagType !== 1) {
  24948. convertToBlock(codegenNode, context);
  24949. }
  24950. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  24951. dir.exp,
  24952. createFunctionExpression(void 0, codegenNode),
  24953. `_cache`,
  24954. String(context.cached.length)
  24955. ]);
  24956. context.cached.push(null);
  24957. }
  24958. };
  24959. }
  24960. };
  24961. function getBaseTransformPreset(prefixIdentifiers) {
  24962. return [
  24963. [
  24964. transformOnce,
  24965. transformIf,
  24966. transformMemo,
  24967. transformFor,
  24968. ...[],
  24969. ...prefixIdentifiers ? [
  24970. // order is important
  24971. trackVForSlotScopes,
  24972. transformExpression
  24973. ] : [],
  24974. transformSlotOutlet,
  24975. transformElement,
  24976. trackSlotScopes,
  24977. transformText
  24978. ],
  24979. {
  24980. on: transformOn$1,
  24981. bind: transformBind,
  24982. model: transformModel$1
  24983. }
  24984. ];
  24985. }
  24986. function baseCompile(source, options = {}) {
  24987. const onError = options.onError || defaultOnError;
  24988. const isModuleMode = options.mode === "module";
  24989. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  24990. if (!prefixIdentifiers && options.cacheHandlers) {
  24991. onError(createCompilerError(49));
  24992. }
  24993. if (options.scopeId && !isModuleMode) {
  24994. onError(createCompilerError(50));
  24995. }
  24996. const resolvedOptions = extend({}, options, {
  24997. prefixIdentifiers
  24998. });
  24999. const ast = isString$1(source) ? baseParse(source, resolvedOptions) : source;
  25000. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  25001. if (options.isTS) {
  25002. const { expressionPlugins } = options;
  25003. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  25004. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  25005. }
  25006. }
  25007. transform(
  25008. ast,
  25009. extend({}, resolvedOptions, {
  25010. nodeTransforms: [
  25011. ...nodeTransforms,
  25012. ...options.nodeTransforms || []
  25013. // user transforms
  25014. ],
  25015. directiveTransforms: extend(
  25016. {},
  25017. directiveTransforms,
  25018. options.directiveTransforms || {}
  25019. // user transforms
  25020. )
  25021. })
  25022. );
  25023. return generate(ast, resolvedOptions);
  25024. }
  25025. const BindingTypes = {
  25026. "DATA": "data",
  25027. "PROPS": "props",
  25028. "PROPS_ALIASED": "props-aliased",
  25029. "SETUP_LET": "setup-let",
  25030. "SETUP_CONST": "setup-const",
  25031. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  25032. "SETUP_MAYBE_REF": "setup-maybe-ref",
  25033. "SETUP_REF": "setup-ref",
  25034. "OPTIONS": "options",
  25035. "LITERAL_CONST": "literal-const"
  25036. };
  25037. const noopDirectiveTransform = () => ({ props: [] });
  25038. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  25039. const V_MODEL_CHECKBOX = Symbol(
  25040. `vModelCheckbox`
  25041. );
  25042. const V_MODEL_TEXT = Symbol(`vModelText` );
  25043. const V_MODEL_SELECT = Symbol(
  25044. `vModelSelect`
  25045. );
  25046. const V_MODEL_DYNAMIC = Symbol(
  25047. `vModelDynamic`
  25048. );
  25049. const V_ON_WITH_MODIFIERS = Symbol(
  25050. `vOnModifiersGuard`
  25051. );
  25052. const V_ON_WITH_KEYS = Symbol(
  25053. `vOnKeysGuard`
  25054. );
  25055. const V_SHOW = Symbol(`vShow` );
  25056. const TRANSITION = Symbol(`Transition` );
  25057. const TRANSITION_GROUP = Symbol(
  25058. `TransitionGroup`
  25059. );
  25060. registerRuntimeHelpers({
  25061. [V_MODEL_RADIO]: `vModelRadio`,
  25062. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  25063. [V_MODEL_TEXT]: `vModelText`,
  25064. [V_MODEL_SELECT]: `vModelSelect`,
  25065. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  25066. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  25067. [V_ON_WITH_KEYS]: `withKeys`,
  25068. [V_SHOW]: `vShow`,
  25069. [TRANSITION]: `Transition`,
  25070. [TRANSITION_GROUP]: `TransitionGroup`
  25071. });
  25072. const parserOptions = {
  25073. parseMode: "html",
  25074. isVoidTag,
  25075. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  25076. isPreTag: (tag) => tag === "pre",
  25077. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  25078. decodeEntities: void 0,
  25079. isBuiltInComponent: (tag) => {
  25080. if (tag === "Transition" || tag === "transition") {
  25081. return TRANSITION;
  25082. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  25083. return TRANSITION_GROUP;
  25084. }
  25085. },
  25086. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  25087. getNamespace(tag, parent, rootNamespace) {
  25088. let ns = parent ? parent.ns : rootNamespace;
  25089. if (parent && ns === 2) {
  25090. if (parent.tag === "annotation-xml") {
  25091. if (tag === "svg") {
  25092. return 1;
  25093. }
  25094. if (parent.props.some(
  25095. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  25096. )) {
  25097. ns = 0;
  25098. }
  25099. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  25100. ns = 0;
  25101. }
  25102. } else if (parent && ns === 1) {
  25103. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  25104. ns = 0;
  25105. }
  25106. }
  25107. if (ns === 0) {
  25108. if (tag === "svg") {
  25109. return 1;
  25110. }
  25111. if (tag === "math") {
  25112. return 2;
  25113. }
  25114. }
  25115. return ns;
  25116. }
  25117. };
  25118. const transformStyle = (node) => {
  25119. if (node.type === 1) {
  25120. node.props.forEach((p, i) => {
  25121. if (p.type === 6 && p.name === "style" && p.value) {
  25122. node.props[i] = {
  25123. type: 7,
  25124. name: `bind`,
  25125. arg: createSimpleExpression(`style`, true, p.loc),
  25126. exp: parseInlineCSS(p.value.content, p.loc),
  25127. modifiers: [],
  25128. loc: p.loc
  25129. };
  25130. }
  25131. });
  25132. }
  25133. };
  25134. const parseInlineCSS = (cssText, loc) => {
  25135. const normalized = parseStringStyle(cssText);
  25136. return createSimpleExpression(
  25137. JSON.stringify(normalized),
  25138. false,
  25139. loc,
  25140. 3
  25141. );
  25142. };
  25143. function createDOMCompilerError(code, loc) {
  25144. return createCompilerError(
  25145. code,
  25146. loc,
  25147. DOMErrorMessages
  25148. );
  25149. }
  25150. const DOMErrorCodes = {
  25151. "X_V_HTML_NO_EXPRESSION": 53,
  25152. "53": "X_V_HTML_NO_EXPRESSION",
  25153. "X_V_HTML_WITH_CHILDREN": 54,
  25154. "54": "X_V_HTML_WITH_CHILDREN",
  25155. "X_V_TEXT_NO_EXPRESSION": 55,
  25156. "55": "X_V_TEXT_NO_EXPRESSION",
  25157. "X_V_TEXT_WITH_CHILDREN": 56,
  25158. "56": "X_V_TEXT_WITH_CHILDREN",
  25159. "X_V_MODEL_ON_INVALID_ELEMENT": 57,
  25160. "57": "X_V_MODEL_ON_INVALID_ELEMENT",
  25161. "X_V_MODEL_ARG_ON_ELEMENT": 58,
  25162. "58": "X_V_MODEL_ARG_ON_ELEMENT",
  25163. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
  25164. "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  25165. "X_V_MODEL_UNNECESSARY_VALUE": 60,
  25166. "60": "X_V_MODEL_UNNECESSARY_VALUE",
  25167. "X_V_SHOW_NO_EXPRESSION": 61,
  25168. "61": "X_V_SHOW_NO_EXPRESSION",
  25169. "X_TRANSITION_INVALID_CHILDREN": 62,
  25170. "62": "X_TRANSITION_INVALID_CHILDREN",
  25171. "X_IGNORED_SIDE_EFFECT_TAG": 63,
  25172. "63": "X_IGNORED_SIDE_EFFECT_TAG",
  25173. "__EXTEND_POINT__": 64,
  25174. "64": "__EXTEND_POINT__"
  25175. };
  25176. const DOMErrorMessages = {
  25177. [53]: `v-html is missing expression.`,
  25178. [54]: `v-html will override element children.`,
  25179. [55]: `v-text is missing expression.`,
  25180. [56]: `v-text will override element children.`,
  25181. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  25182. [58]: `v-model argument is not supported on plain elements.`,
  25183. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  25184. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  25185. [61]: `v-show is missing expression.`,
  25186. [62]: `<Transition> expects exactly one child element or component.`,
  25187. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  25188. };
  25189. const transformVHtml = (dir, node, context) => {
  25190. const { exp, loc } = dir;
  25191. if (!exp) {
  25192. context.onError(
  25193. createDOMCompilerError(53, loc)
  25194. );
  25195. }
  25196. if (node.children.length) {
  25197. context.onError(
  25198. createDOMCompilerError(54, loc)
  25199. );
  25200. node.children.length = 0;
  25201. }
  25202. return {
  25203. props: [
  25204. createObjectProperty(
  25205. createSimpleExpression(`innerHTML`, true, loc),
  25206. exp || createSimpleExpression("", true)
  25207. )
  25208. ]
  25209. };
  25210. };
  25211. const transformVText = (dir, node, context) => {
  25212. const { exp, loc } = dir;
  25213. if (!exp) {
  25214. context.onError(
  25215. createDOMCompilerError(55, loc)
  25216. );
  25217. }
  25218. if (node.children.length) {
  25219. context.onError(
  25220. createDOMCompilerError(56, loc)
  25221. );
  25222. node.children.length = 0;
  25223. }
  25224. return {
  25225. props: [
  25226. createObjectProperty(
  25227. createSimpleExpression(`textContent`, true),
  25228. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  25229. context.helperString(TO_DISPLAY_STRING),
  25230. [exp],
  25231. loc
  25232. ) : createSimpleExpression("", true)
  25233. )
  25234. ]
  25235. };
  25236. };
  25237. const transformModel = (dir, node, context) => {
  25238. const baseResult = transformModel$1(dir, node, context);
  25239. if (!baseResult.props.length || node.tagType === 1) {
  25240. return baseResult;
  25241. }
  25242. if (dir.arg) {
  25243. context.onError(
  25244. createDOMCompilerError(
  25245. 58,
  25246. dir.arg.loc
  25247. )
  25248. );
  25249. }
  25250. function checkDuplicatedValue() {
  25251. const value = findDir(node, "bind");
  25252. if (value && isStaticArgOf(value.arg, "value")) {
  25253. context.onError(
  25254. createDOMCompilerError(
  25255. 60,
  25256. value.loc
  25257. )
  25258. );
  25259. }
  25260. }
  25261. const { tag } = node;
  25262. const isCustomElement = context.isCustomElement(tag);
  25263. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  25264. let directiveToUse = V_MODEL_TEXT;
  25265. let isInvalidType = false;
  25266. if (tag === "input" || isCustomElement) {
  25267. const type = findProp(node, `type`);
  25268. if (type) {
  25269. if (type.type === 7) {
  25270. directiveToUse = V_MODEL_DYNAMIC;
  25271. } else if (type.value) {
  25272. switch (type.value.content) {
  25273. case "radio":
  25274. directiveToUse = V_MODEL_RADIO;
  25275. break;
  25276. case "checkbox":
  25277. directiveToUse = V_MODEL_CHECKBOX;
  25278. break;
  25279. case "file":
  25280. isInvalidType = true;
  25281. context.onError(
  25282. createDOMCompilerError(
  25283. 59,
  25284. dir.loc
  25285. )
  25286. );
  25287. break;
  25288. default:
  25289. checkDuplicatedValue();
  25290. break;
  25291. }
  25292. }
  25293. } else if (hasDynamicKeyVBind(node)) {
  25294. directiveToUse = V_MODEL_DYNAMIC;
  25295. } else {
  25296. checkDuplicatedValue();
  25297. }
  25298. } else if (tag === "select") {
  25299. directiveToUse = V_MODEL_SELECT;
  25300. } else {
  25301. checkDuplicatedValue();
  25302. }
  25303. if (!isInvalidType) {
  25304. baseResult.needRuntime = context.helper(directiveToUse);
  25305. }
  25306. } else {
  25307. context.onError(
  25308. createDOMCompilerError(
  25309. 57,
  25310. dir.loc
  25311. )
  25312. );
  25313. }
  25314. baseResult.props = baseResult.props.filter(
  25315. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  25316. );
  25317. return baseResult;
  25318. };
  25319. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  25320. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  25321. // event propagation management
  25322. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  25323. );
  25324. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  25325. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  25326. const resolveModifiers = (key, modifiers, context, loc) => {
  25327. const keyModifiers = [];
  25328. const nonKeyModifiers = [];
  25329. const eventOptionModifiers = [];
  25330. for (let i = 0; i < modifiers.length; i++) {
  25331. const modifier = modifiers[i].content;
  25332. if (isEventOptionModifier(modifier)) {
  25333. eventOptionModifiers.push(modifier);
  25334. } else {
  25335. if (maybeKeyModifier(modifier)) {
  25336. if (isStaticExp(key)) {
  25337. if (isKeyboardEvent(key.content.toLowerCase())) {
  25338. keyModifiers.push(modifier);
  25339. } else {
  25340. nonKeyModifiers.push(modifier);
  25341. }
  25342. } else {
  25343. keyModifiers.push(modifier);
  25344. nonKeyModifiers.push(modifier);
  25345. }
  25346. } else {
  25347. if (isNonKeyModifier(modifier)) {
  25348. nonKeyModifiers.push(modifier);
  25349. } else {
  25350. keyModifiers.push(modifier);
  25351. }
  25352. }
  25353. }
  25354. }
  25355. return {
  25356. keyModifiers,
  25357. nonKeyModifiers,
  25358. eventOptionModifiers
  25359. };
  25360. };
  25361. const transformClick = (key, event) => {
  25362. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  25363. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  25364. `(`,
  25365. key,
  25366. `) === "onClick" ? "${event}" : (`,
  25367. key,
  25368. `)`
  25369. ]) : key;
  25370. };
  25371. const transformOn = (dir, node, context) => {
  25372. return transformOn$1(dir, node, context, (baseResult) => {
  25373. const { modifiers } = dir;
  25374. if (!modifiers.length) return baseResult;
  25375. let { key, value: handlerExp } = baseResult.props[0];
  25376. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  25377. if (nonKeyModifiers.includes("right")) {
  25378. key = transformClick(key, `onContextmenu`);
  25379. }
  25380. if (nonKeyModifiers.includes("middle")) {
  25381. key = transformClick(key, `onMouseup`);
  25382. }
  25383. if (nonKeyModifiers.length) {
  25384. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  25385. handlerExp,
  25386. JSON.stringify(nonKeyModifiers)
  25387. ]);
  25388. }
  25389. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  25390. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  25391. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  25392. handlerExp,
  25393. JSON.stringify(keyModifiers)
  25394. ]);
  25395. }
  25396. if (eventOptionModifiers.length) {
  25397. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  25398. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  25399. }
  25400. return {
  25401. props: [createObjectProperty(key, handlerExp)]
  25402. };
  25403. });
  25404. };
  25405. const transformShow = (dir, node, context) => {
  25406. const { exp, loc } = dir;
  25407. if (!exp) {
  25408. context.onError(
  25409. createDOMCompilerError(61, loc)
  25410. );
  25411. }
  25412. return {
  25413. props: [],
  25414. needRuntime: context.helper(V_SHOW)
  25415. };
  25416. };
  25417. const transformTransition = (node, context) => {
  25418. if (node.type === 1 && node.tagType === 1) {
  25419. const component = context.isBuiltInComponent(node.tag);
  25420. if (component === TRANSITION) {
  25421. return () => {
  25422. if (!node.children.length) {
  25423. return;
  25424. }
  25425. if (hasMultipleChildren(node)) {
  25426. context.onError(
  25427. createDOMCompilerError(
  25428. 62,
  25429. {
  25430. start: node.children[0].loc.start,
  25431. end: node.children[node.children.length - 1].loc.end,
  25432. source: ""
  25433. }
  25434. )
  25435. );
  25436. }
  25437. const child = node.children[0];
  25438. if (child.type === 1) {
  25439. for (const p of child.props) {
  25440. if (p.type === 7 && p.name === "show") {
  25441. node.props.push({
  25442. type: 6,
  25443. name: "persisted",
  25444. nameLoc: node.loc,
  25445. value: void 0,
  25446. loc: node.loc
  25447. });
  25448. }
  25449. }
  25450. }
  25451. };
  25452. }
  25453. }
  25454. };
  25455. function hasMultipleChildren(node) {
  25456. const children = node.children = node.children.filter(
  25457. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  25458. );
  25459. const child = children[0];
  25460. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  25461. }
  25462. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  25463. const stringifyStatic = (children, context, parent) => {
  25464. if (context.scopes.vSlot > 0) {
  25465. return;
  25466. }
  25467. const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray$3(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
  25468. let nc = 0;
  25469. let ec = 0;
  25470. const currentChunk = [];
  25471. const stringifyCurrentChunk = (currentIndex) => {
  25472. if (nc >= 20 || ec >= 5) {
  25473. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  25474. JSON.stringify(
  25475. currentChunk.map((node) => stringifyNode(node, context)).join("")
  25476. ).replace(expReplaceRE, `" + $1 + "`),
  25477. // the 2nd argument indicates the number of DOM nodes this static vnode
  25478. // will insert / hydrate
  25479. String(currentChunk.length)
  25480. ]);
  25481. const deleteCount = currentChunk.length - 1;
  25482. if (isParentCached) {
  25483. children.splice(
  25484. currentIndex - currentChunk.length,
  25485. currentChunk.length,
  25486. // @ts-expect-error
  25487. staticCall
  25488. );
  25489. } else {
  25490. currentChunk[0].codegenNode.value = staticCall;
  25491. if (currentChunk.length > 1) {
  25492. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  25493. const cacheIndex = context.cached.indexOf(
  25494. currentChunk[currentChunk.length - 1].codegenNode
  25495. );
  25496. if (cacheIndex > -1) {
  25497. for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
  25498. const c = context.cached[i2];
  25499. if (c) c.index -= deleteCount;
  25500. }
  25501. context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
  25502. }
  25503. }
  25504. }
  25505. return deleteCount;
  25506. }
  25507. return 0;
  25508. };
  25509. let i = 0;
  25510. for (; i < children.length; i++) {
  25511. const child = children[i];
  25512. const isCached = isParentCached || getCachedNode(child);
  25513. if (isCached) {
  25514. const result = analyzeNode(child);
  25515. if (result) {
  25516. nc += result[0];
  25517. ec += result[1];
  25518. currentChunk.push(child);
  25519. continue;
  25520. }
  25521. }
  25522. i -= stringifyCurrentChunk(i);
  25523. nc = 0;
  25524. ec = 0;
  25525. currentChunk.length = 0;
  25526. }
  25527. stringifyCurrentChunk(i);
  25528. };
  25529. const getCachedNode = (node) => {
  25530. if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
  25531. return node.codegenNode;
  25532. }
  25533. };
  25534. const dataAriaRE = /^(data|aria)-/;
  25535. const isStringifiableAttr = (name, ns) => {
  25536. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : ns === 2 ? isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
  25537. };
  25538. const isNonStringifiable = /* @__PURE__ */ makeMap(
  25539. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  25540. );
  25541. function analyzeNode(node) {
  25542. if (node.type === 1 && isNonStringifiable(node.tag)) {
  25543. return false;
  25544. }
  25545. if (node.type === 12) {
  25546. return [1, 0];
  25547. }
  25548. let nc = 1;
  25549. let ec = node.props.length > 0 ? 1 : 0;
  25550. let bailed = false;
  25551. const bail = () => {
  25552. bailed = true;
  25553. return false;
  25554. };
  25555. function walk(node2) {
  25556. const isOptionTag = node2.tag === "option" && node2.ns === 0;
  25557. for (let i = 0; i < node2.props.length; i++) {
  25558. const p = node2.props[i];
  25559. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  25560. return bail();
  25561. }
  25562. if (p.type === 7 && p.name === "bind") {
  25563. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  25564. return bail();
  25565. }
  25566. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  25567. return bail();
  25568. }
  25569. if (isOptionTag && isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
  25570. return bail();
  25571. }
  25572. }
  25573. }
  25574. for (let i = 0; i < node2.children.length; i++) {
  25575. nc++;
  25576. const child = node2.children[i];
  25577. if (child.type === 1) {
  25578. if (child.props.length > 0) {
  25579. ec++;
  25580. }
  25581. walk(child);
  25582. if (bailed) {
  25583. return false;
  25584. }
  25585. }
  25586. }
  25587. return true;
  25588. }
  25589. return walk(node) ? [nc, ec] : false;
  25590. }
  25591. function stringifyNode(node, context) {
  25592. if (isString$1(node)) {
  25593. return node;
  25594. }
  25595. if (isSymbol$1(node)) {
  25596. return ``;
  25597. }
  25598. switch (node.type) {
  25599. case 1:
  25600. return stringifyElement(node, context);
  25601. case 2:
  25602. return escapeHtml(node.content);
  25603. case 3:
  25604. return `<!--${escapeHtml(node.content)}-->`;
  25605. case 5:
  25606. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  25607. case 8:
  25608. return escapeHtml(evaluateConstant(node));
  25609. case 12:
  25610. return stringifyNode(node.content, context);
  25611. default:
  25612. return "";
  25613. }
  25614. }
  25615. function stringifyElement(node, context) {
  25616. let res = `<${node.tag}`;
  25617. let innerHTML = "";
  25618. for (let i = 0; i < node.props.length; i++) {
  25619. const p = node.props[i];
  25620. if (p.type === 6) {
  25621. res += ` ${p.name}`;
  25622. if (p.value) {
  25623. res += `="${escapeHtml(p.value.content)}"`;
  25624. }
  25625. } else if (p.type === 7) {
  25626. if (p.name === "bind") {
  25627. const exp = p.exp;
  25628. if (exp.content[0] === "_") {
  25629. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  25630. continue;
  25631. }
  25632. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  25633. continue;
  25634. }
  25635. let evaluated = evaluateConstant(exp);
  25636. if (evaluated != null) {
  25637. const arg = p.arg && p.arg.content;
  25638. if (arg === "class") {
  25639. evaluated = normalizeClass(evaluated);
  25640. } else if (arg === "style") {
  25641. evaluated = stringifyStyle(normalizeStyle(evaluated));
  25642. }
  25643. res += ` ${p.arg.content}="${escapeHtml(
  25644. evaluated
  25645. )}"`;
  25646. }
  25647. } else if (p.name === "html") {
  25648. innerHTML = evaluateConstant(p.exp);
  25649. } else if (p.name === "text") {
  25650. innerHTML = escapeHtml(
  25651. toDisplayString(evaluateConstant(p.exp))
  25652. );
  25653. }
  25654. }
  25655. }
  25656. if (context.scopeId) {
  25657. res += ` ${context.scopeId}`;
  25658. }
  25659. res += `>`;
  25660. if (innerHTML) {
  25661. res += innerHTML;
  25662. } else {
  25663. for (let i = 0; i < node.children.length; i++) {
  25664. res += stringifyNode(node.children[i], context);
  25665. }
  25666. }
  25667. if (!isVoidTag(node.tag)) {
  25668. res += `</${node.tag}>`;
  25669. }
  25670. return res;
  25671. }
  25672. function evaluateConstant(exp) {
  25673. if (exp.type === 4) {
  25674. return new Function(`return (${exp.content})`)();
  25675. } else {
  25676. let res = ``;
  25677. exp.children.forEach((c) => {
  25678. if (isString$1(c) || isSymbol$1(c)) {
  25679. return;
  25680. }
  25681. if (c.type === 2) {
  25682. res += c.content;
  25683. } else if (c.type === 5) {
  25684. res += toDisplayString(evaluateConstant(c.content));
  25685. } else {
  25686. res += evaluateConstant(c);
  25687. }
  25688. });
  25689. return res;
  25690. }
  25691. }
  25692. const ignoreSideEffectTags = (node, context) => {
  25693. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  25694. context.onError(
  25695. createDOMCompilerError(
  25696. 63,
  25697. node.loc
  25698. )
  25699. );
  25700. context.removeNode();
  25701. }
  25702. };
  25703. function isValidHTMLNesting(parent, child) {
  25704. if (parent === "template") {
  25705. return true;
  25706. }
  25707. if (parent in onlyValidChildren) {
  25708. return onlyValidChildren[parent].has(child);
  25709. }
  25710. if (child in onlyValidParents) {
  25711. return onlyValidParents[child].has(parent);
  25712. }
  25713. if (parent in knownInvalidChildren) {
  25714. if (knownInvalidChildren[parent].has(child)) return false;
  25715. }
  25716. if (child in knownInvalidParents) {
  25717. if (knownInvalidParents[child].has(parent)) return false;
  25718. }
  25719. return true;
  25720. }
  25721. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  25722. const emptySet = /* @__PURE__ */ new Set([]);
  25723. const onlyValidChildren = {
  25724. head: /* @__PURE__ */ new Set([
  25725. "base",
  25726. "basefront",
  25727. "bgsound",
  25728. "link",
  25729. "meta",
  25730. "title",
  25731. "noscript",
  25732. "noframes",
  25733. "style",
  25734. "script",
  25735. "template"
  25736. ]),
  25737. optgroup: /* @__PURE__ */ new Set(["option"]),
  25738. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  25739. // table
  25740. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  25741. tr: /* @__PURE__ */ new Set(["td", "th"]),
  25742. colgroup: /* @__PURE__ */ new Set(["col"]),
  25743. tbody: /* @__PURE__ */ new Set(["tr"]),
  25744. thead: /* @__PURE__ */ new Set(["tr"]),
  25745. tfoot: /* @__PURE__ */ new Set(["tr"]),
  25746. // these elements can not have any children elements
  25747. script: emptySet,
  25748. iframe: emptySet,
  25749. option: emptySet,
  25750. textarea: emptySet,
  25751. style: emptySet,
  25752. title: emptySet
  25753. };
  25754. const onlyValidParents = {
  25755. // sections
  25756. html: emptySet,
  25757. body: /* @__PURE__ */ new Set(["html"]),
  25758. head: /* @__PURE__ */ new Set(["html"]),
  25759. // table
  25760. td: /* @__PURE__ */ new Set(["tr"]),
  25761. colgroup: /* @__PURE__ */ new Set(["table"]),
  25762. caption: /* @__PURE__ */ new Set(["table"]),
  25763. tbody: /* @__PURE__ */ new Set(["table"]),
  25764. tfoot: /* @__PURE__ */ new Set(["table"]),
  25765. col: /* @__PURE__ */ new Set(["colgroup"]),
  25766. th: /* @__PURE__ */ new Set(["tr"]),
  25767. thead: /* @__PURE__ */ new Set(["table"]),
  25768. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  25769. // data list
  25770. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  25771. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  25772. // other
  25773. figcaption: /* @__PURE__ */ new Set(["figure"]),
  25774. // li: new Set(["ul", "ol"]),
  25775. summary: /* @__PURE__ */ new Set(["details"]),
  25776. area: /* @__PURE__ */ new Set(["map"])
  25777. };
  25778. const knownInvalidChildren = {
  25779. p: /* @__PURE__ */ new Set([
  25780. "address",
  25781. "article",
  25782. "aside",
  25783. "blockquote",
  25784. "center",
  25785. "details",
  25786. "dialog",
  25787. "dir",
  25788. "div",
  25789. "dl",
  25790. "fieldset",
  25791. "figure",
  25792. "footer",
  25793. "form",
  25794. "h1",
  25795. "h2",
  25796. "h3",
  25797. "h4",
  25798. "h5",
  25799. "h6",
  25800. "header",
  25801. "hgroup",
  25802. "hr",
  25803. "li",
  25804. "main",
  25805. "nav",
  25806. "menu",
  25807. "ol",
  25808. "p",
  25809. "pre",
  25810. "section",
  25811. "table",
  25812. "ul"
  25813. ]),
  25814. svg: /* @__PURE__ */ new Set([
  25815. "b",
  25816. "blockquote",
  25817. "br",
  25818. "code",
  25819. "dd",
  25820. "div",
  25821. "dl",
  25822. "dt",
  25823. "em",
  25824. "embed",
  25825. "h1",
  25826. "h2",
  25827. "h3",
  25828. "h4",
  25829. "h5",
  25830. "h6",
  25831. "hr",
  25832. "i",
  25833. "img",
  25834. "li",
  25835. "menu",
  25836. "meta",
  25837. "ol",
  25838. "p",
  25839. "pre",
  25840. "ruby",
  25841. "s",
  25842. "small",
  25843. "span",
  25844. "strong",
  25845. "sub",
  25846. "sup",
  25847. "table",
  25848. "u",
  25849. "ul",
  25850. "var"
  25851. ])
  25852. };
  25853. const knownInvalidParents = {
  25854. a: /* @__PURE__ */ new Set(["a"]),
  25855. button: /* @__PURE__ */ new Set(["button"]),
  25856. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  25857. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  25858. form: /* @__PURE__ */ new Set(["form"]),
  25859. li: /* @__PURE__ */ new Set(["li"]),
  25860. h1: headings,
  25861. h2: headings,
  25862. h3: headings,
  25863. h4: headings,
  25864. h5: headings,
  25865. h6: headings
  25866. };
  25867. const validateHtmlNesting = (node, context) => {
  25868. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  25869. const error = new SyntaxError(
  25870. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  25871. );
  25872. error.loc = node.loc;
  25873. context.onWarn(error);
  25874. }
  25875. };
  25876. const DOMNodeTransforms = [
  25877. transformStyle,
  25878. ...[transformTransition, validateHtmlNesting]
  25879. ];
  25880. const DOMDirectiveTransforms = {
  25881. cloak: noopDirectiveTransform,
  25882. html: transformVHtml,
  25883. text: transformVText,
  25884. model: transformModel,
  25885. // override compiler-core
  25886. on: transformOn,
  25887. // override compiler-core
  25888. show: transformShow
  25889. };
  25890. function compile$1(src, options = {}) {
  25891. return baseCompile(
  25892. src,
  25893. extend({}, parserOptions, options, {
  25894. nodeTransforms: [
  25895. // ignore <script> and <tag>
  25896. // this is not put inside DOMNodeTransforms because that list is used
  25897. // by compiler-ssr to generate vnode fallback branches
  25898. ignoreSideEffectTags,
  25899. ...DOMNodeTransforms,
  25900. ...options.nodeTransforms || []
  25901. ],
  25902. directiveTransforms: extend(
  25903. {},
  25904. DOMDirectiveTransforms,
  25905. options.directiveTransforms || {}
  25906. ),
  25907. transformHoist: stringifyStatic
  25908. })
  25909. );
  25910. }
  25911. function parse$3(template, options = {}) {
  25912. return baseParse(template, extend({}, parserOptions, options));
  25913. }
  25914. var CompilerDOM = /*#__PURE__*/Object.freeze({
  25915. __proto__: null,
  25916. BASE_TRANSITION: BASE_TRANSITION,
  25917. BindingTypes: BindingTypes,
  25918. CAMELIZE: CAMELIZE,
  25919. CAPITALIZE: CAPITALIZE,
  25920. CREATE_BLOCK: CREATE_BLOCK,
  25921. CREATE_COMMENT: CREATE_COMMENT,
  25922. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  25923. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  25924. CREATE_SLOTS: CREATE_SLOTS,
  25925. CREATE_STATIC: CREATE_STATIC,
  25926. CREATE_TEXT: CREATE_TEXT,
  25927. CREATE_VNODE: CREATE_VNODE,
  25928. CompilerDeprecationTypes: CompilerDeprecationTypes,
  25929. ConstantTypes: ConstantTypes,
  25930. DOMDirectiveTransforms: DOMDirectiveTransforms,
  25931. DOMErrorCodes: DOMErrorCodes,
  25932. DOMErrorMessages: DOMErrorMessages,
  25933. DOMNodeTransforms: DOMNodeTransforms,
  25934. ElementTypes: ElementTypes,
  25935. ErrorCodes: ErrorCodes,
  25936. FRAGMENT: FRAGMENT,
  25937. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  25938. IS_MEMO_SAME: IS_MEMO_SAME,
  25939. IS_REF: IS_REF,
  25940. KEEP_ALIVE: KEEP_ALIVE,
  25941. MERGE_PROPS: MERGE_PROPS,
  25942. NORMALIZE_CLASS: NORMALIZE_CLASS,
  25943. NORMALIZE_PROPS: NORMALIZE_PROPS,
  25944. NORMALIZE_STYLE: NORMALIZE_STYLE,
  25945. Namespaces: Namespaces,
  25946. NodeTypes: NodeTypes,
  25947. OPEN_BLOCK: OPEN_BLOCK,
  25948. POP_SCOPE_ID: POP_SCOPE_ID,
  25949. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  25950. RENDER_LIST: RENDER_LIST,
  25951. RENDER_SLOT: RENDER_SLOT,
  25952. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  25953. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  25954. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  25955. RESOLVE_FILTER: RESOLVE_FILTER,
  25956. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  25957. SUSPENSE: SUSPENSE,
  25958. TELEPORT: TELEPORT,
  25959. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  25960. TO_HANDLERS: TO_HANDLERS,
  25961. TO_HANDLER_KEY: TO_HANDLER_KEY,
  25962. TRANSITION: TRANSITION,
  25963. TRANSITION_GROUP: TRANSITION_GROUP,
  25964. TS_NODE_TYPES: TS_NODE_TYPES,
  25965. UNREF: UNREF,
  25966. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  25967. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  25968. V_MODEL_RADIO: V_MODEL_RADIO,
  25969. V_MODEL_SELECT: V_MODEL_SELECT,
  25970. V_MODEL_TEXT: V_MODEL_TEXT,
  25971. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  25972. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  25973. V_SHOW: V_SHOW,
  25974. WITH_CTX: WITH_CTX,
  25975. WITH_DIRECTIVES: WITH_DIRECTIVES,
  25976. WITH_MEMO: WITH_MEMO,
  25977. advancePositionWithClone: advancePositionWithClone,
  25978. advancePositionWithMutation: advancePositionWithMutation,
  25979. assert: assert,
  25980. baseCompile: baseCompile,
  25981. baseParse: baseParse,
  25982. buildDirectiveArgs: buildDirectiveArgs,
  25983. buildProps: buildProps,
  25984. buildSlots: buildSlots,
  25985. checkCompatEnabled: checkCompatEnabled,
  25986. compile: compile$1,
  25987. convertToBlock: convertToBlock,
  25988. createArrayExpression: createArrayExpression,
  25989. createAssignmentExpression: createAssignmentExpression,
  25990. createBlockStatement: createBlockStatement,
  25991. createCacheExpression: createCacheExpression,
  25992. createCallExpression: createCallExpression,
  25993. createCompilerError: createCompilerError,
  25994. createCompoundExpression: createCompoundExpression,
  25995. createConditionalExpression: createConditionalExpression,
  25996. createDOMCompilerError: createDOMCompilerError,
  25997. createForLoopParams: createForLoopParams,
  25998. createFunctionExpression: createFunctionExpression,
  25999. createIfStatement: createIfStatement,
  26000. createInterpolation: createInterpolation,
  26001. createObjectExpression: createObjectExpression,
  26002. createObjectProperty: createObjectProperty,
  26003. createReturnStatement: createReturnStatement,
  26004. createRoot: createRoot,
  26005. createSequenceExpression: createSequenceExpression,
  26006. createSimpleExpression: createSimpleExpression,
  26007. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  26008. createTemplateLiteral: createTemplateLiteral,
  26009. createTransformContext: createTransformContext,
  26010. createVNodeCall: createVNodeCall,
  26011. errorMessages: errorMessages$1,
  26012. extractIdentifiers: extractIdentifiers$1,
  26013. findDir: findDir,
  26014. findProp: findProp,
  26015. forAliasRE: forAliasRE,
  26016. generate: generate,
  26017. generateCodeFrame: generateCodeFrame,
  26018. getBaseTransformPreset: getBaseTransformPreset,
  26019. getConstantType: getConstantType,
  26020. getMemoedVNodeCall: getMemoedVNodeCall,
  26021. getVNodeBlockHelper: getVNodeBlockHelper,
  26022. getVNodeHelper: getVNodeHelper,
  26023. hasDynamicKeyVBind: hasDynamicKeyVBind,
  26024. hasScopeRef: hasScopeRef,
  26025. helperNameMap: helperNameMap,
  26026. injectProp: injectProp,
  26027. isCoreComponent: isCoreComponent,
  26028. isFnExpression: isFnExpression,
  26029. isFnExpressionBrowser: isFnExpressionBrowser,
  26030. isFnExpressionNode: isFnExpressionNode,
  26031. isFunctionType: isFunctionType,
  26032. isInDestructureAssignment: isInDestructureAssignment,
  26033. isInNewExpression: isInNewExpression,
  26034. isMemberExpression: isMemberExpression,
  26035. isMemberExpressionBrowser: isMemberExpressionBrowser,
  26036. isMemberExpressionNode: isMemberExpressionNode,
  26037. isReferencedIdentifier: isReferencedIdentifier,
  26038. isSimpleIdentifier: isSimpleIdentifier,
  26039. isSlotOutlet: isSlotOutlet,
  26040. isStaticArgOf: isStaticArgOf,
  26041. isStaticExp: isStaticExp,
  26042. isStaticProperty: isStaticProperty,
  26043. isStaticPropertyKey: isStaticPropertyKey,
  26044. isTemplateNode: isTemplateNode,
  26045. isText: isText$1,
  26046. isVPre: isVPre,
  26047. isVSlot: isVSlot,
  26048. locStub: locStub,
  26049. noopDirectiveTransform: noopDirectiveTransform,
  26050. parse: parse$3,
  26051. parserOptions: parserOptions,
  26052. processExpression: processExpression,
  26053. processFor: processFor,
  26054. processIf: processIf,
  26055. processSlotOutlet: processSlotOutlet,
  26056. registerRuntimeHelpers: registerRuntimeHelpers,
  26057. resolveComponentType: resolveComponentType,
  26058. stringifyExpression: stringifyExpression,
  26059. toValidAssetId: toValidAssetId,
  26060. trackSlotScopes: trackSlotScopes,
  26061. trackVForSlotScopes: trackVForSlotScopes,
  26062. transform: transform,
  26063. transformBind: transformBind,
  26064. transformElement: transformElement,
  26065. transformExpression: transformExpression,
  26066. transformModel: transformModel$1,
  26067. transformOn: transformOn$1,
  26068. transformStyle: transformStyle,
  26069. traverseNode: traverseNode,
  26070. unwrapTSNode: unwrapTSNode,
  26071. walkBlockDeclarations: walkBlockDeclarations,
  26072. walkFunctionParams: walkFunctionParams,
  26073. walkIdentifiers: walkIdentifiers,
  26074. warnDeprecation: warnDeprecation
  26075. });
  26076. var hashSum;
  26077. var hasRequiredHashSum;
  26078. function requireHashSum () {
  26079. if (hasRequiredHashSum) return hashSum;
  26080. hasRequiredHashSum = 1;
  26081. function pad (hash, len) {
  26082. while (hash.length < len) {
  26083. hash = '0' + hash;
  26084. }
  26085. return hash;
  26086. }
  26087. function fold (hash, text) {
  26088. var i;
  26089. var chr;
  26090. var len;
  26091. if (text.length === 0) {
  26092. return hash;
  26093. }
  26094. for (i = 0, len = text.length; i < len; i++) {
  26095. chr = text.charCodeAt(i);
  26096. hash = ((hash << 5) - hash) + chr;
  26097. hash |= 0;
  26098. }
  26099. return hash < 0 ? hash * -2 : hash;
  26100. }
  26101. function foldObject (hash, o, seen) {
  26102. return Object.keys(o).sort().reduce(foldKey, hash);
  26103. function foldKey (hash, key) {
  26104. return foldValue(hash, o[key], key, seen);
  26105. }
  26106. }
  26107. function foldValue (input, value, key, seen) {
  26108. var hash = fold(fold(fold(input, key), toString(value)), typeof value);
  26109. if (value === null) {
  26110. return fold(hash, 'null');
  26111. }
  26112. if (value === undefined) {
  26113. return fold(hash, 'undefined');
  26114. }
  26115. if (typeof value === 'object' || typeof value === 'function') {
  26116. if (seen.indexOf(value) !== -1) {
  26117. return fold(hash, '[Circular]' + key);
  26118. }
  26119. seen.push(value);
  26120. var objHash = foldObject(hash, value, seen);
  26121. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  26122. return objHash;
  26123. }
  26124. try {
  26125. return fold(objHash, String(value.valueOf()))
  26126. } catch (err) {
  26127. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  26128. }
  26129. }
  26130. return fold(hash, value.toString());
  26131. }
  26132. function toString (o) {
  26133. return Object.prototype.toString.call(o);
  26134. }
  26135. function sum (o) {
  26136. return pad(foldValue(0, o, '', []).toString(16), 8);
  26137. }
  26138. hashSum = sum;
  26139. return hashSum;
  26140. }
  26141. var hashSumExports = /*@__PURE__*/ requireHashSum();
  26142. var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
  26143. const CSS_VARS_HELPER = `useCssVars`;
  26144. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  26145. return `{
  26146. ${vars.map(
  26147. (key) => (
  26148. // The `:` prefix here is used in `ssrRenderStyle` to distinguish whether
  26149. // a custom property comes from `ssrCssVars`. If it does, we need to reset
  26150. // its value to `initial` on the component instance to avoid unintentionally
  26151. // inheriting the same property value from a different instance of the same
  26152. // component in the outer scope.
  26153. `"${isSSR ? `:--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`
  26154. )
  26155. ).join(",\n ")}
  26156. }`;
  26157. }
  26158. function genVarName(id, raw, isProd, isSSR = false) {
  26159. if (isProd) {
  26160. return hash(id + raw);
  26161. } else {
  26162. return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
  26163. }
  26164. }
  26165. function normalizeExpression(exp) {
  26166. exp = exp.trim();
  26167. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  26168. return exp.slice(1, -1);
  26169. }
  26170. return exp;
  26171. }
  26172. const vBindRE = /v-bind\s*\(/g;
  26173. function parseCssVars(sfc) {
  26174. const vars = [];
  26175. sfc.styles.forEach((style) => {
  26176. let match;
  26177. const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
  26178. while (match = vBindRE.exec(content)) {
  26179. const start = match.index + match[0].length;
  26180. const end = lexBinding(content, start);
  26181. if (end !== null) {
  26182. const variable = normalizeExpression(content.slice(start, end));
  26183. if (!vars.includes(variable)) {
  26184. vars.push(variable);
  26185. }
  26186. }
  26187. }
  26188. });
  26189. return vars;
  26190. }
  26191. function lexBinding(content, start) {
  26192. let state = 0 /* inParens */;
  26193. let parenDepth = 0;
  26194. for (let i = start; i < content.length; i++) {
  26195. const char = content.charAt(i);
  26196. switch (state) {
  26197. case 0 /* inParens */:
  26198. if (char === `'`) {
  26199. state = 1 /* inSingleQuoteString */;
  26200. } else if (char === `"`) {
  26201. state = 2 /* inDoubleQuoteString */;
  26202. } else if (char === `(`) {
  26203. parenDepth++;
  26204. } else if (char === `)`) {
  26205. if (parenDepth > 0) {
  26206. parenDepth--;
  26207. } else {
  26208. return i;
  26209. }
  26210. }
  26211. break;
  26212. case 1 /* inSingleQuoteString */:
  26213. if (char === `'`) {
  26214. state = 0 /* inParens */;
  26215. }
  26216. break;
  26217. case 2 /* inDoubleQuoteString */:
  26218. if (char === `"`) {
  26219. state = 0 /* inParens */;
  26220. }
  26221. break;
  26222. }
  26223. }
  26224. return null;
  26225. }
  26226. const cssVarsPlugin = (opts) => {
  26227. const { id, isProd } = opts;
  26228. return {
  26229. postcssPlugin: "vue-sfc-vars",
  26230. Declaration(decl) {
  26231. const value = decl.value;
  26232. if (vBindRE.test(value)) {
  26233. vBindRE.lastIndex = 0;
  26234. let transformed = "";
  26235. let lastIndex = 0;
  26236. let match;
  26237. while (match = vBindRE.exec(value)) {
  26238. const start = match.index + match[0].length;
  26239. const end = lexBinding(value, start);
  26240. if (end !== null) {
  26241. const variable = normalizeExpression(value.slice(start, end));
  26242. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  26243. lastIndex = end + 1;
  26244. }
  26245. }
  26246. decl.value = transformed + value.slice(lastIndex);
  26247. }
  26248. }
  26249. };
  26250. };
  26251. cssVarsPlugin.postcss = true;
  26252. function genCssVarsCode(vars, bindings, id, isProd) {
  26253. const varsExp = genCssVarsFromList(vars, id, isProd);
  26254. const exp = createSimpleExpression(varsExp, false);
  26255. const context = createTransformContext(createRoot([]), {
  26256. prefixIdentifiers: true,
  26257. inline: true,
  26258. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  26259. });
  26260. const transformed = processExpression(exp, context);
  26261. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  26262. return typeof c === "string" ? c : c.content;
  26263. }).join("");
  26264. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  26265. }
  26266. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  26267. return `
  26268. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  26269. const __injectCSSVars__ = () => {
  26270. ${genCssVarsCode(
  26271. cssVars,
  26272. bindings,
  26273. id,
  26274. isProd
  26275. )}}
  26276. const __setup__ = ${defaultVar}.setup
  26277. ${defaultVar}.setup = __setup__
  26278. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  26279. : __injectCSSVars__
  26280. `;
  26281. }
  26282. var global$1 = (typeof global !== "undefined" ? global :
  26283. typeof self !== "undefined" ? self :
  26284. typeof window !== "undefined" ? window : {});
  26285. // shim for using process in browser
  26286. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  26287. function defaultSetTimout() {
  26288. throw new Error('setTimeout has not been defined');
  26289. }
  26290. function defaultClearTimeout () {
  26291. throw new Error('clearTimeout has not been defined');
  26292. }
  26293. var cachedSetTimeout = defaultSetTimout;
  26294. var cachedClearTimeout = defaultClearTimeout;
  26295. if (typeof global$1.setTimeout === 'function') {
  26296. cachedSetTimeout = setTimeout;
  26297. }
  26298. if (typeof global$1.clearTimeout === 'function') {
  26299. cachedClearTimeout = clearTimeout;
  26300. }
  26301. function runTimeout(fun) {
  26302. if (cachedSetTimeout === setTimeout) {
  26303. //normal enviroments in sane situations
  26304. return setTimeout(fun, 0);
  26305. }
  26306. // if setTimeout wasn't available but was latter defined
  26307. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  26308. cachedSetTimeout = setTimeout;
  26309. return setTimeout(fun, 0);
  26310. }
  26311. try {
  26312. // when when somebody has screwed with setTimeout but no I.E. maddness
  26313. return cachedSetTimeout(fun, 0);
  26314. } catch(e){
  26315. try {
  26316. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26317. return cachedSetTimeout.call(null, fun, 0);
  26318. } catch(e){
  26319. // 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
  26320. return cachedSetTimeout.call(this, fun, 0);
  26321. }
  26322. }
  26323. }
  26324. function runClearTimeout(marker) {
  26325. if (cachedClearTimeout === clearTimeout) {
  26326. //normal enviroments in sane situations
  26327. return clearTimeout(marker);
  26328. }
  26329. // if clearTimeout wasn't available but was latter defined
  26330. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  26331. cachedClearTimeout = clearTimeout;
  26332. return clearTimeout(marker);
  26333. }
  26334. try {
  26335. // when when somebody has screwed with setTimeout but no I.E. maddness
  26336. return cachedClearTimeout(marker);
  26337. } catch (e){
  26338. try {
  26339. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26340. return cachedClearTimeout.call(null, marker);
  26341. } catch (e){
  26342. // 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.
  26343. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  26344. return cachedClearTimeout.call(this, marker);
  26345. }
  26346. }
  26347. }
  26348. var queue = [];
  26349. var draining = false;
  26350. var currentQueue;
  26351. var queueIndex = -1;
  26352. function cleanUpNextTick() {
  26353. if (!draining || !currentQueue) {
  26354. return;
  26355. }
  26356. draining = false;
  26357. if (currentQueue.length) {
  26358. queue = currentQueue.concat(queue);
  26359. } else {
  26360. queueIndex = -1;
  26361. }
  26362. if (queue.length) {
  26363. drainQueue();
  26364. }
  26365. }
  26366. function drainQueue() {
  26367. if (draining) {
  26368. return;
  26369. }
  26370. var timeout = runTimeout(cleanUpNextTick);
  26371. draining = true;
  26372. var len = queue.length;
  26373. while(len) {
  26374. currentQueue = queue;
  26375. queue = [];
  26376. while (++queueIndex < len) {
  26377. if (currentQueue) {
  26378. currentQueue[queueIndex].run();
  26379. }
  26380. }
  26381. queueIndex = -1;
  26382. len = queue.length;
  26383. }
  26384. currentQueue = null;
  26385. draining = false;
  26386. runClearTimeout(timeout);
  26387. }
  26388. function nextTick(fun) {
  26389. var args = new Array(arguments.length - 1);
  26390. if (arguments.length > 1) {
  26391. for (var i = 1; i < arguments.length; i++) {
  26392. args[i - 1] = arguments[i];
  26393. }
  26394. }
  26395. queue.push(new Item(fun, args));
  26396. if (queue.length === 1 && !draining) {
  26397. runTimeout(drainQueue);
  26398. }
  26399. }
  26400. // v8 likes predictible objects
  26401. function Item(fun, array) {
  26402. this.fun = fun;
  26403. this.array = array;
  26404. }
  26405. Item.prototype.run = function () {
  26406. this.fun.apply(null, this.array);
  26407. };
  26408. var title = 'browser';
  26409. var platform = 'browser';
  26410. var browser = true;
  26411. var env = {};
  26412. var argv = [];
  26413. var version$1 = ''; // empty string to avoid regexp issues
  26414. var versions = {};
  26415. var release = {};
  26416. var config = {};
  26417. function noop() {}
  26418. var on = noop;
  26419. var addListener = noop;
  26420. var once = noop;
  26421. var off = noop;
  26422. var removeListener = noop;
  26423. var removeAllListeners = noop;
  26424. var emit = noop;
  26425. function binding(name) {
  26426. throw new Error('process.binding is not supported');
  26427. }
  26428. function cwd () { return '/' }
  26429. function chdir (dir) {
  26430. throw new Error('process.chdir is not supported');
  26431. }function umask() { return 0; }
  26432. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  26433. var performance = global$1.performance || {};
  26434. var performanceNow =
  26435. performance.now ||
  26436. performance.mozNow ||
  26437. performance.msNow ||
  26438. performance.oNow ||
  26439. performance.webkitNow ||
  26440. function(){ return (new Date()).getTime() };
  26441. // generate timestamp or delta
  26442. // see http://nodejs.org/api/process.html#process_process_hrtime
  26443. function hrtime(previousTimestamp){
  26444. var clocktime = performanceNow.call(performance)*1e-3;
  26445. var seconds = Math.floor(clocktime);
  26446. var nanoseconds = Math.floor((clocktime%1)*1e9);
  26447. if (previousTimestamp) {
  26448. seconds = seconds - previousTimestamp[0];
  26449. nanoseconds = nanoseconds - previousTimestamp[1];
  26450. if (nanoseconds<0) {
  26451. seconds--;
  26452. nanoseconds += 1e9;
  26453. }
  26454. }
  26455. return [seconds,nanoseconds]
  26456. }
  26457. var startTime = new Date();
  26458. function uptime() {
  26459. var currentTime = new Date();
  26460. var dif = currentTime - startTime;
  26461. return dif / 1000;
  26462. }
  26463. var browser$1 = {
  26464. nextTick: nextTick,
  26465. title: title,
  26466. browser: browser,
  26467. env: env,
  26468. argv: argv,
  26469. version: version$1,
  26470. versions: versions,
  26471. on: on,
  26472. addListener: addListener,
  26473. once: once,
  26474. off: off,
  26475. removeListener: removeListener,
  26476. removeAllListeners: removeAllListeners,
  26477. emit: emit,
  26478. binding: binding,
  26479. cwd: cwd,
  26480. chdir: chdir,
  26481. umask: umask,
  26482. hrtime: hrtime,
  26483. platform: platform,
  26484. release: release,
  26485. config: config,
  26486. uptime: uptime
  26487. };
  26488. function createCache(max = 500) {
  26489. {
  26490. return /* @__PURE__ */ new Map();
  26491. }
  26492. }
  26493. function isImportUsed(local, sfc) {
  26494. return resolveTemplateUsedIdentifiers(sfc).has(local);
  26495. }
  26496. const templateUsageCheckCache = createCache();
  26497. function resolveTemplateUsedIdentifiers(sfc) {
  26498. const { content, ast } = sfc.template;
  26499. const cached = templateUsageCheckCache.get(content);
  26500. if (cached) {
  26501. return cached;
  26502. }
  26503. const ids = /* @__PURE__ */ new Set();
  26504. ast.children.forEach(walk);
  26505. function walk(node) {
  26506. var _a;
  26507. switch (node.type) {
  26508. case 1:
  26509. let tag = node.tag;
  26510. if (tag.includes(".")) tag = tag.split(".")[0].trim();
  26511. if (!parserOptions.isNativeTag(tag) && !parserOptions.isBuiltInComponent(tag)) {
  26512. ids.add(camelize(tag));
  26513. ids.add(capitalize(camelize(tag)));
  26514. }
  26515. for (let i = 0; i < node.props.length; i++) {
  26516. const prop = node.props[i];
  26517. if (prop.type === 7) {
  26518. if (!isBuiltInDirective(prop.name)) {
  26519. ids.add(`v${capitalize(camelize(prop.name))}`);
  26520. }
  26521. if (prop.arg && !prop.arg.isStatic) {
  26522. extractIdentifiers(ids, prop.arg);
  26523. }
  26524. if (prop.name === "for") {
  26525. extractIdentifiers(ids, prop.forParseResult.source);
  26526. } else if (prop.exp) {
  26527. extractIdentifiers(ids, prop.exp);
  26528. } else if (prop.name === "bind" && !prop.exp) {
  26529. ids.add(camelize(prop.arg.content));
  26530. }
  26531. }
  26532. if (prop.type === 6 && prop.name === "ref" && ((_a = prop.value) == null ? void 0 : _a.content)) {
  26533. ids.add(prop.value.content);
  26534. }
  26535. }
  26536. node.children.forEach(walk);
  26537. break;
  26538. case 5:
  26539. extractIdentifiers(ids, node.content);
  26540. break;
  26541. }
  26542. }
  26543. templateUsageCheckCache.set(content, ids);
  26544. return ids;
  26545. }
  26546. function extractIdentifiers(ids, node) {
  26547. if (node.ast) {
  26548. walkIdentifiers(node.ast, (n) => ids.add(n.name));
  26549. } else if (node.ast === null) {
  26550. ids.add(node.content);
  26551. }
  26552. }
  26553. var __defProp$a = Object.defineProperty;
  26554. var __defProps$9 = Object.defineProperties;
  26555. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  26556. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  26557. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  26558. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  26559. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  26560. var __spreadValues$a = (a, b) => {
  26561. for (var prop in b || (b = {}))
  26562. if (__hasOwnProp$a.call(b, prop))
  26563. __defNormalProp$a(a, prop, b[prop]);
  26564. if (__getOwnPropSymbols$a)
  26565. for (var prop of __getOwnPropSymbols$a(b)) {
  26566. if (__propIsEnum$a.call(b, prop))
  26567. __defNormalProp$a(a, prop, b[prop]);
  26568. }
  26569. return a;
  26570. };
  26571. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  26572. const DEFAULT_FILENAME = "anonymous.vue";
  26573. const parseCache$1 = createCache();
  26574. function parse$2(source, options = {}) {
  26575. var _a;
  26576. const sourceKey = genCacheKey(source, __spreadProps$9(__spreadValues$a({}, options), {
  26577. compiler: { parse: (_a = options.compiler) == null ? void 0 : _a.parse }
  26578. }));
  26579. const cache = parseCache$1.get(sourceKey);
  26580. if (cache) {
  26581. return cache;
  26582. }
  26583. const {
  26584. sourceMap = true,
  26585. filename = DEFAULT_FILENAME,
  26586. sourceRoot = "",
  26587. pad = false,
  26588. ignoreEmpty = true,
  26589. compiler = CompilerDOM,
  26590. templateParseOptions = {}
  26591. } = options;
  26592. const descriptor = {
  26593. filename,
  26594. source,
  26595. template: null,
  26596. script: null,
  26597. scriptSetup: null,
  26598. styles: [],
  26599. customBlocks: [],
  26600. cssVars: [],
  26601. slotted: false,
  26602. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  26603. };
  26604. const errors = [];
  26605. const ast = compiler.parse(source, __spreadProps$9(__spreadValues$a({
  26606. parseMode: "sfc",
  26607. prefixIdentifiers: true
  26608. }, templateParseOptions), {
  26609. onError: (e) => {
  26610. errors.push(e);
  26611. }
  26612. }));
  26613. ast.children.forEach((node) => {
  26614. if (node.type !== 1) {
  26615. return;
  26616. }
  26617. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  26618. return;
  26619. }
  26620. switch (node.tag) {
  26621. case "template":
  26622. if (!descriptor.template) {
  26623. const templateBlock = descriptor.template = createBlock(
  26624. node,
  26625. source,
  26626. false
  26627. );
  26628. if (!templateBlock.attrs.src) {
  26629. templateBlock.ast = createRoot(node.children, source);
  26630. }
  26631. if (templateBlock.attrs.functional) {
  26632. const err = new SyntaxError(
  26633. `<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.`
  26634. );
  26635. err.loc = node.props.find(
  26636. (p) => p.type === 6 && p.name === "functional"
  26637. ).loc;
  26638. errors.push(err);
  26639. }
  26640. } else {
  26641. errors.push(createDuplicateBlockError(node));
  26642. }
  26643. break;
  26644. case "script":
  26645. const scriptBlock = createBlock(node, source, pad);
  26646. const isSetup = !!scriptBlock.attrs.setup;
  26647. if (isSetup && !descriptor.scriptSetup) {
  26648. descriptor.scriptSetup = scriptBlock;
  26649. break;
  26650. }
  26651. if (!isSetup && !descriptor.script) {
  26652. descriptor.script = scriptBlock;
  26653. break;
  26654. }
  26655. errors.push(createDuplicateBlockError(node, isSetup));
  26656. break;
  26657. case "style":
  26658. const styleBlock = createBlock(node, source, pad);
  26659. if (styleBlock.attrs.vars) {
  26660. errors.push(
  26661. new SyntaxError(
  26662. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  26663. )
  26664. );
  26665. }
  26666. descriptor.styles.push(styleBlock);
  26667. break;
  26668. default:
  26669. descriptor.customBlocks.push(createBlock(node, source, pad));
  26670. break;
  26671. }
  26672. });
  26673. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  26674. errors.push(
  26675. new SyntaxError(
  26676. `At least one <template> or <script> is required in a single file component. ${descriptor.filename}`
  26677. )
  26678. );
  26679. }
  26680. if (descriptor.scriptSetup) {
  26681. if (descriptor.scriptSetup.src) {
  26682. errors.push(
  26683. new SyntaxError(
  26684. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  26685. )
  26686. );
  26687. descriptor.scriptSetup = null;
  26688. }
  26689. if (descriptor.script && descriptor.script.src) {
  26690. errors.push(
  26691. new SyntaxError(
  26692. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  26693. )
  26694. );
  26695. descriptor.script = null;
  26696. }
  26697. }
  26698. let templateColumnOffset = 0;
  26699. if (descriptor.template && (descriptor.template.lang === "pug" || descriptor.template.lang === "jade")) {
  26700. [descriptor.template.content, templateColumnOffset] = dedent(
  26701. descriptor.template.content
  26702. );
  26703. }
  26704. if (sourceMap) {
  26705. const genMap = (block, columnOffset = 0) => {
  26706. if (block && !block.src) {
  26707. block.map = generateSourceMap(
  26708. filename,
  26709. source,
  26710. block.content,
  26711. sourceRoot,
  26712. !pad || block.type === "template" ? block.loc.start.line - 1 : 0,
  26713. columnOffset
  26714. );
  26715. }
  26716. };
  26717. genMap(descriptor.template, templateColumnOffset);
  26718. genMap(descriptor.script);
  26719. descriptor.styles.forEach((s) => genMap(s));
  26720. descriptor.customBlocks.forEach((s) => genMap(s));
  26721. }
  26722. descriptor.cssVars = parseCssVars(descriptor);
  26723. const slottedRE = /(?:::v-|:)slotted\(/;
  26724. descriptor.slotted = descriptor.styles.some(
  26725. (s) => s.scoped && slottedRE.test(s.content)
  26726. );
  26727. const result = {
  26728. descriptor,
  26729. errors
  26730. };
  26731. parseCache$1.set(sourceKey, result);
  26732. return result;
  26733. }
  26734. function createDuplicateBlockError(node, isScriptSetup = false) {
  26735. const err = new SyntaxError(
  26736. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  26737. );
  26738. err.loc = node.loc;
  26739. return err;
  26740. }
  26741. function createBlock(node, source, pad) {
  26742. const type = node.tag;
  26743. const loc = node.innerLoc;
  26744. const attrs = {};
  26745. const block = {
  26746. type,
  26747. content: source.slice(loc.start.offset, loc.end.offset),
  26748. loc,
  26749. attrs
  26750. };
  26751. if (pad) {
  26752. block.content = padContent(source, block, pad) + block.content;
  26753. }
  26754. node.props.forEach((p) => {
  26755. if (p.type === 6) {
  26756. const name = p.name;
  26757. attrs[name] = p.value ? p.value.content || true : true;
  26758. if (name === "lang") {
  26759. block.lang = p.value && p.value.content;
  26760. } else if (name === "src") {
  26761. block.src = p.value && p.value.content;
  26762. } else if (type === "style") {
  26763. if (name === "scoped") {
  26764. block.scoped = true;
  26765. } else if (name === "module") {
  26766. block.module = attrs[name];
  26767. }
  26768. } else if (type === "script" && name === "setup") {
  26769. block.setup = attrs.setup;
  26770. }
  26771. }
  26772. });
  26773. return block;
  26774. }
  26775. const splitRE = /\r?\n/g;
  26776. const emptyRE = /^(?:\/\/)?\s*$/;
  26777. const replaceRE = /./g;
  26778. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset, columnOffset) {
  26779. const map = new sourceMapExports.SourceMapGenerator({
  26780. file: filename.replace(/\\/g, "/"),
  26781. sourceRoot: sourceRoot.replace(/\\/g, "/")
  26782. });
  26783. map.setSourceContent(filename, source);
  26784. map._sources.add(filename);
  26785. generated.split(splitRE).forEach((line, index) => {
  26786. if (!emptyRE.test(line)) {
  26787. const originalLine = index + 1 + lineOffset;
  26788. const generatedLine = index + 1;
  26789. for (let i = 0; i < line.length; i++) {
  26790. if (!/\s/.test(line[i])) {
  26791. map._mappings.add({
  26792. originalLine,
  26793. originalColumn: i + columnOffset,
  26794. generatedLine,
  26795. generatedColumn: i,
  26796. source: filename,
  26797. name: null
  26798. });
  26799. }
  26800. }
  26801. }
  26802. });
  26803. return map.toJSON();
  26804. }
  26805. function padContent(content, block, pad) {
  26806. content = content.slice(0, block.loc.start.offset);
  26807. if (pad === "space") {
  26808. return content.replace(replaceRE, " ");
  26809. } else {
  26810. const offset = content.split(splitRE).length;
  26811. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  26812. return Array(offset).join(padChar);
  26813. }
  26814. }
  26815. function hasSrc(node) {
  26816. return node.props.some((p) => {
  26817. if (p.type !== 6) {
  26818. return false;
  26819. }
  26820. return p.name === "src";
  26821. });
  26822. }
  26823. function isEmpty(node) {
  26824. for (let i = 0; i < node.children.length; i++) {
  26825. const child = node.children[i];
  26826. if (child.type !== 2 || child.content.trim() !== "") {
  26827. return false;
  26828. }
  26829. }
  26830. return true;
  26831. }
  26832. function hmrShouldReload(prevImports, next) {
  26833. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  26834. return false;
  26835. }
  26836. for (const key in prevImports) {
  26837. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  26838. return true;
  26839. }
  26840. }
  26841. return false;
  26842. }
  26843. function dedent(s) {
  26844. const lines = s.split("\n");
  26845. const minIndent = lines.reduce(function(minIndent2, line) {
  26846. var _a, _b;
  26847. if (line.trim() === "") {
  26848. return minIndent2;
  26849. }
  26850. const indent = ((_b = (_a = line.match(/^\s*/)) == null ? void 0 : _a[0]) == null ? void 0 : _b.length) || 0;
  26851. return Math.min(indent, minIndent2);
  26852. }, Infinity);
  26853. if (minIndent === 0) {
  26854. return [s, minIndent];
  26855. }
  26856. return [
  26857. lines.map(function(line) {
  26858. return line.slice(minIndent);
  26859. }).join("\n"),
  26860. minIndent
  26861. ];
  26862. }
  26863. // Copyright Joyent, Inc. and other Node contributors.
  26864. //
  26865. // Permission is hereby granted, free of charge, to any person obtaining a
  26866. // copy of this software and associated documentation files (the
  26867. // "Software"), to deal in the Software without restriction, including
  26868. // without limitation the rights to use, copy, modify, merge, publish,
  26869. // distribute, sublicense, and/or sell copies of the Software, and to permit
  26870. // persons to whom the Software is furnished to do so, subject to the
  26871. // following conditions:
  26872. //
  26873. // The above copyright notice and this permission notice shall be included
  26874. // in all copies or substantial portions of the Software.
  26875. //
  26876. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  26877. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26878. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  26879. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  26880. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  26881. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  26882. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  26883. // resolves . and .. elements in a path array with directory names there
  26884. // must be no slashes, empty elements, or device names (c:\) in the array
  26885. // (so also no leading and trailing slashes - it does not distinguish
  26886. // relative and absolute paths)
  26887. function normalizeArray(parts, allowAboveRoot) {
  26888. // if the path tries to go above the root, `up` ends up > 0
  26889. var up = 0;
  26890. for (var i = parts.length - 1; i >= 0; i--) {
  26891. var last = parts[i];
  26892. if (last === '.') {
  26893. parts.splice(i, 1);
  26894. } else if (last === '..') {
  26895. parts.splice(i, 1);
  26896. up++;
  26897. } else if (up) {
  26898. parts.splice(i, 1);
  26899. up--;
  26900. }
  26901. }
  26902. // if the path is allowed to go above the root, restore leading ..s
  26903. if (allowAboveRoot) {
  26904. for (; up--; up) {
  26905. parts.unshift('..');
  26906. }
  26907. }
  26908. return parts;
  26909. }
  26910. // Split a filename into [root, dir, basename, ext], unix version
  26911. // 'root' is just a slash, or nothing.
  26912. var splitPathRe =
  26913. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  26914. var splitPath = function(filename) {
  26915. return splitPathRe.exec(filename).slice(1);
  26916. };
  26917. // path.resolve([from ...], to)
  26918. // posix version
  26919. function resolve() {
  26920. var resolvedPath = '',
  26921. resolvedAbsolute = false;
  26922. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  26923. var path = (i >= 0) ? arguments[i] : '/';
  26924. // Skip empty and invalid entries
  26925. if (typeof path !== 'string') {
  26926. throw new TypeError('Arguments to path.resolve must be strings');
  26927. } else if (!path) {
  26928. continue;
  26929. }
  26930. resolvedPath = path + '/' + resolvedPath;
  26931. resolvedAbsolute = path.charAt(0) === '/';
  26932. }
  26933. // At this point the path should be resolved to a full absolute path, but
  26934. // handle relative paths to be safe (might happen when process.cwd() fails)
  26935. // Normalize the path
  26936. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  26937. return !!p;
  26938. }), !resolvedAbsolute).join('/');
  26939. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  26940. }
  26941. // path.normalize(path)
  26942. // posix version
  26943. function normalize$1(path) {
  26944. var isPathAbsolute = isAbsolute(path),
  26945. trailingSlash = substr(path, -1) === '/';
  26946. // Normalize the path
  26947. path = normalizeArray(filter(path.split('/'), function(p) {
  26948. return !!p;
  26949. }), !isPathAbsolute).join('/');
  26950. if (!path && !isPathAbsolute) {
  26951. path = '.';
  26952. }
  26953. if (path && trailingSlash) {
  26954. path += '/';
  26955. }
  26956. return (isPathAbsolute ? '/' : '') + path;
  26957. }
  26958. // posix version
  26959. function isAbsolute(path) {
  26960. return path.charAt(0) === '/';
  26961. }
  26962. // posix version
  26963. function join() {
  26964. var paths = Array.prototype.slice.call(arguments, 0);
  26965. return normalize$1(filter(paths, function(p, index) {
  26966. if (typeof p !== 'string') {
  26967. throw new TypeError('Arguments to path.join must be strings');
  26968. }
  26969. return p;
  26970. }).join('/'));
  26971. }
  26972. // path.relative(from, to)
  26973. // posix version
  26974. function relative(from, to) {
  26975. from = resolve(from).substr(1);
  26976. to = resolve(to).substr(1);
  26977. function trim(arr) {
  26978. var start = 0;
  26979. for (; start < arr.length; start++) {
  26980. if (arr[start] !== '') break;
  26981. }
  26982. var end = arr.length - 1;
  26983. for (; end >= 0; end--) {
  26984. if (arr[end] !== '') break;
  26985. }
  26986. if (start > end) return [];
  26987. return arr.slice(start, end - start + 1);
  26988. }
  26989. var fromParts = trim(from.split('/'));
  26990. var toParts = trim(to.split('/'));
  26991. var length = Math.min(fromParts.length, toParts.length);
  26992. var samePartsLength = length;
  26993. for (var i = 0; i < length; i++) {
  26994. if (fromParts[i] !== toParts[i]) {
  26995. samePartsLength = i;
  26996. break;
  26997. }
  26998. }
  26999. var outputParts = [];
  27000. for (var i = samePartsLength; i < fromParts.length; i++) {
  27001. outputParts.push('..');
  27002. }
  27003. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  27004. return outputParts.join('/');
  27005. }
  27006. var sep = '/';
  27007. var delimiter$1 = ':';
  27008. function dirname(path) {
  27009. var result = splitPath(path),
  27010. root = result[0],
  27011. dir = result[1];
  27012. if (!root && !dir) {
  27013. // No dirname whatsoever
  27014. return '.';
  27015. }
  27016. if (dir) {
  27017. // It has a dirname, strip trailing slash
  27018. dir = dir.substr(0, dir.length - 1);
  27019. }
  27020. return root + dir;
  27021. }
  27022. function basename(path, ext) {
  27023. var f = splitPath(path)[2];
  27024. // TODO: make this comparison case-insensitive on windows?
  27025. if (ext && f.substr(-1 * ext.length) === ext) {
  27026. f = f.substr(0, f.length - ext.length);
  27027. }
  27028. return f;
  27029. }
  27030. function extname(path) {
  27031. return splitPath(path)[3];
  27032. }
  27033. var path = {
  27034. extname: extname,
  27035. basename: basename,
  27036. dirname: dirname,
  27037. sep: sep,
  27038. delimiter: delimiter$1,
  27039. relative: relative,
  27040. join: join,
  27041. isAbsolute: isAbsolute,
  27042. normalize: normalize$1,
  27043. resolve: resolve
  27044. };
  27045. function filter (xs, f) {
  27046. if (xs.filter) return xs.filter(f);
  27047. var res = [];
  27048. for (var i = 0; i < xs.length; i++) {
  27049. if (f(xs[i], i, xs)) res.push(xs[i]);
  27050. }
  27051. return res;
  27052. }
  27053. // String.prototype.substr - negative index don't work in IE8
  27054. var substr = 'ab'.substr(-1) === 'b' ?
  27055. function (str, start, len) { return str.substr(start, len) } :
  27056. function (str, start, len) {
  27057. if (start < 0) start = str.length + start;
  27058. return str.substr(start, len);
  27059. }
  27060. ;
  27061. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  27062. __proto__: null,
  27063. basename: basename,
  27064. default: path,
  27065. delimiter: delimiter$1,
  27066. dirname: dirname,
  27067. extname: extname,
  27068. isAbsolute: isAbsolute,
  27069. join: join,
  27070. normalize: normalize$1,
  27071. relative: relative,
  27072. resolve: resolve,
  27073. sep: sep
  27074. });
  27075. /*! https://mths.be/punycode v1.4.1 by @mathias */
  27076. /** Highest positive signed 32-bit float value */
  27077. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  27078. /** Bootstring parameters */
  27079. var base = 36;
  27080. var tMin = 1;
  27081. var tMax = 26;
  27082. var skew = 38;
  27083. var damp = 700;
  27084. var initialBias = 72;
  27085. var initialN = 128; // 0x80
  27086. var delimiter = '-'; // '\x2D'
  27087. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  27088. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  27089. /** Error messages */
  27090. var errors = {
  27091. 'overflow': 'Overflow: input needs wider integers to process',
  27092. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  27093. 'invalid-input': 'Invalid input'
  27094. };
  27095. /** Convenience shortcuts */
  27096. var baseMinusTMin = base - tMin;
  27097. var floor = Math.floor;
  27098. var stringFromCharCode = String.fromCharCode;
  27099. /*--------------------------------------------------------------------------*/
  27100. /**
  27101. * A generic error utility function.
  27102. * @private
  27103. * @param {String} type The error type.
  27104. * @returns {Error} Throws a `RangeError` with the applicable error message.
  27105. */
  27106. function error(type) {
  27107. throw new RangeError(errors[type]);
  27108. }
  27109. /**
  27110. * A generic `Array#map` utility function.
  27111. * @private
  27112. * @param {Array} array The array to iterate over.
  27113. * @param {Function} callback The function that gets called for every array
  27114. * item.
  27115. * @returns {Array} A new array of values returned by the callback function.
  27116. */
  27117. function map$1(array, fn) {
  27118. var length = array.length;
  27119. var result = [];
  27120. while (length--) {
  27121. result[length] = fn(array[length]);
  27122. }
  27123. return result;
  27124. }
  27125. /**
  27126. * A simple `Array#map`-like wrapper to work with domain name strings or email
  27127. * addresses.
  27128. * @private
  27129. * @param {String} domain The domain name or email address.
  27130. * @param {Function} callback The function that gets called for every
  27131. * character.
  27132. * @returns {Array} A new string of characters returned by the callback
  27133. * function.
  27134. */
  27135. function mapDomain(string, fn) {
  27136. var parts = string.split('@');
  27137. var result = '';
  27138. if (parts.length > 1) {
  27139. // In email addresses, only the domain name should be punycoded. Leave
  27140. // the local part (i.e. everything up to `@`) intact.
  27141. result = parts[0] + '@';
  27142. string = parts[1];
  27143. }
  27144. // Avoid `split(regex)` for IE8 compatibility. See #17.
  27145. string = string.replace(regexSeparators, '\x2E');
  27146. var labels = string.split('.');
  27147. var encoded = map$1(labels, fn).join('.');
  27148. return result + encoded;
  27149. }
  27150. /**
  27151. * Creates an array containing the numeric code points of each Unicode
  27152. * character in the string. While JavaScript uses UCS-2 internally,
  27153. * this function will convert a pair of surrogate halves (each of which
  27154. * UCS-2 exposes as separate characters) into a single code point,
  27155. * matching UTF-16.
  27156. * @see `punycode.ucs2.encode`
  27157. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  27158. * @memberOf punycode.ucs2
  27159. * @name decode
  27160. * @param {String} string The Unicode input string (UCS-2).
  27161. * @returns {Array} The new array of code points.
  27162. */
  27163. function ucs2decode(string) {
  27164. var output = [],
  27165. counter = 0,
  27166. length = string.length,
  27167. value,
  27168. extra;
  27169. while (counter < length) {
  27170. value = string.charCodeAt(counter++);
  27171. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  27172. // high surrogate, and there is a next character
  27173. extra = string.charCodeAt(counter++);
  27174. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  27175. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  27176. } else {
  27177. // unmatched surrogate; only append this code unit, in case the next
  27178. // code unit is the high surrogate of a surrogate pair
  27179. output.push(value);
  27180. counter--;
  27181. }
  27182. } else {
  27183. output.push(value);
  27184. }
  27185. }
  27186. return output;
  27187. }
  27188. /**
  27189. * Converts a digit/integer into a basic code point.
  27190. * @see `basicToDigit()`
  27191. * @private
  27192. * @param {Number} digit The numeric value of a basic code point.
  27193. * @returns {Number} The basic code point whose value (when used for
  27194. * representing integers) is `digit`, which needs to be in the range
  27195. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  27196. * used; else, the lowercase form is used. The behavior is undefined
  27197. * if `flag` is non-zero and `digit` has no uppercase form.
  27198. */
  27199. function digitToBasic(digit, flag) {
  27200. // 0..25 map to ASCII a..z or A..Z
  27201. // 26..35 map to ASCII 0..9
  27202. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  27203. }
  27204. /**
  27205. * Bias adaptation function as per section 3.4 of RFC 3492.
  27206. * https://tools.ietf.org/html/rfc3492#section-3.4
  27207. * @private
  27208. */
  27209. function adapt(delta, numPoints, firstTime) {
  27210. var k = 0;
  27211. delta = firstTime ? floor(delta / damp) : delta >> 1;
  27212. delta += floor(delta / numPoints);
  27213. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  27214. delta = floor(delta / baseMinusTMin);
  27215. }
  27216. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  27217. }
  27218. /**
  27219. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  27220. * Punycode string of ASCII-only symbols.
  27221. * @memberOf punycode
  27222. * @param {String} input The string of Unicode symbols.
  27223. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  27224. */
  27225. function encode$1(input) {
  27226. var n,
  27227. delta,
  27228. handledCPCount,
  27229. basicLength,
  27230. bias,
  27231. j,
  27232. m,
  27233. q,
  27234. k,
  27235. t,
  27236. currentValue,
  27237. output = [],
  27238. /** `inputLength` will hold the number of code points in `input`. */
  27239. inputLength,
  27240. /** Cached calculation results */
  27241. handledCPCountPlusOne,
  27242. baseMinusT,
  27243. qMinusT;
  27244. // Convert the input in UCS-2 to Unicode
  27245. input = ucs2decode(input);
  27246. // Cache the length
  27247. inputLength = input.length;
  27248. // Initialize the state
  27249. n = initialN;
  27250. delta = 0;
  27251. bias = initialBias;
  27252. // Handle the basic code points
  27253. for (j = 0; j < inputLength; ++j) {
  27254. currentValue = input[j];
  27255. if (currentValue < 0x80) {
  27256. output.push(stringFromCharCode(currentValue));
  27257. }
  27258. }
  27259. handledCPCount = basicLength = output.length;
  27260. // `handledCPCount` is the number of code points that have been handled;
  27261. // `basicLength` is the number of basic code points.
  27262. // Finish the basic string - if it is not empty - with a delimiter
  27263. if (basicLength) {
  27264. output.push(delimiter);
  27265. }
  27266. // Main encoding loop:
  27267. while (handledCPCount < inputLength) {
  27268. // All non-basic code points < n have been handled already. Find the next
  27269. // larger one:
  27270. for (m = maxInt, j = 0; j < inputLength; ++j) {
  27271. currentValue = input[j];
  27272. if (currentValue >= n && currentValue < m) {
  27273. m = currentValue;
  27274. }
  27275. }
  27276. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  27277. // but guard against overflow
  27278. handledCPCountPlusOne = handledCPCount + 1;
  27279. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  27280. error('overflow');
  27281. }
  27282. delta += (m - n) * handledCPCountPlusOne;
  27283. n = m;
  27284. for (j = 0; j < inputLength; ++j) {
  27285. currentValue = input[j];
  27286. if (currentValue < n && ++delta > maxInt) {
  27287. error('overflow');
  27288. }
  27289. if (currentValue == n) {
  27290. // Represent delta as a generalized variable-length integer
  27291. for (q = delta, k = base; /* no condition */ ; k += base) {
  27292. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  27293. if (q < t) {
  27294. break;
  27295. }
  27296. qMinusT = q - t;
  27297. baseMinusT = base - t;
  27298. output.push(
  27299. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  27300. );
  27301. q = floor(qMinusT / baseMinusT);
  27302. }
  27303. output.push(stringFromCharCode(digitToBasic(q, 0)));
  27304. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  27305. delta = 0;
  27306. ++handledCPCount;
  27307. }
  27308. }
  27309. ++delta;
  27310. ++n;
  27311. }
  27312. return output.join('');
  27313. }
  27314. /**
  27315. * Converts a Unicode string representing a domain name or an email address to
  27316. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  27317. * i.e. it doesn't matter if you call it with a domain that's already in
  27318. * ASCII.
  27319. * @memberOf punycode
  27320. * @param {String} input The domain name or email address to convert, as a
  27321. * Unicode string.
  27322. * @returns {String} The Punycode representation of the given domain name or
  27323. * email address.
  27324. */
  27325. function toASCII(input) {
  27326. return mapDomain(input, function(string) {
  27327. return regexNonASCII.test(string) ?
  27328. 'xn--' + encode$1(string) :
  27329. string;
  27330. });
  27331. }
  27332. var lookup = [];
  27333. var revLookup = [];
  27334. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  27335. var inited = false;
  27336. function init () {
  27337. inited = true;
  27338. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  27339. for (var i = 0, len = code.length; i < len; ++i) {
  27340. lookup[i] = code[i];
  27341. revLookup[code.charCodeAt(i)] = i;
  27342. }
  27343. revLookup['-'.charCodeAt(0)] = 62;
  27344. revLookup['_'.charCodeAt(0)] = 63;
  27345. }
  27346. function toByteArray (b64) {
  27347. if (!inited) {
  27348. init();
  27349. }
  27350. var i, j, l, tmp, placeHolders, arr;
  27351. var len = b64.length;
  27352. if (len % 4 > 0) {
  27353. throw new Error('Invalid string. Length must be a multiple of 4')
  27354. }
  27355. // the number of equal signs (place holders)
  27356. // if there are two placeholders, than the two characters before it
  27357. // represent one byte
  27358. // if there is only one, then the three characters before it represent 2 bytes
  27359. // this is just a cheap hack to not do indexOf twice
  27360. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  27361. // base64 is 4/3 + up to two characters of the original data
  27362. arr = new Arr(len * 3 / 4 - placeHolders);
  27363. // if there are placeholders, only get up to the last complete 4 chars
  27364. l = placeHolders > 0 ? len - 4 : len;
  27365. var L = 0;
  27366. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  27367. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  27368. arr[L++] = (tmp >> 16) & 0xFF;
  27369. arr[L++] = (tmp >> 8) & 0xFF;
  27370. arr[L++] = tmp & 0xFF;
  27371. }
  27372. if (placeHolders === 2) {
  27373. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  27374. arr[L++] = tmp & 0xFF;
  27375. } else if (placeHolders === 1) {
  27376. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  27377. arr[L++] = (tmp >> 8) & 0xFF;
  27378. arr[L++] = tmp & 0xFF;
  27379. }
  27380. return arr
  27381. }
  27382. function tripletToBase64 (num) {
  27383. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  27384. }
  27385. function encodeChunk (uint8, start, end) {
  27386. var tmp;
  27387. var output = [];
  27388. for (var i = start; i < end; i += 3) {
  27389. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  27390. output.push(tripletToBase64(tmp));
  27391. }
  27392. return output.join('')
  27393. }
  27394. function fromByteArray (uint8) {
  27395. if (!inited) {
  27396. init();
  27397. }
  27398. var tmp;
  27399. var len = uint8.length;
  27400. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  27401. var output = '';
  27402. var parts = [];
  27403. var maxChunkLength = 16383; // must be multiple of 3
  27404. // go through the array every three bytes, we'll deal with trailing stuff later
  27405. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  27406. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  27407. }
  27408. // pad the end with zeros, but make sure to not forget the extra bytes
  27409. if (extraBytes === 1) {
  27410. tmp = uint8[len - 1];
  27411. output += lookup[tmp >> 2];
  27412. output += lookup[(tmp << 4) & 0x3F];
  27413. output += '==';
  27414. } else if (extraBytes === 2) {
  27415. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  27416. output += lookup[tmp >> 10];
  27417. output += lookup[(tmp >> 4) & 0x3F];
  27418. output += lookup[(tmp << 2) & 0x3F];
  27419. output += '=';
  27420. }
  27421. parts.push(output);
  27422. return parts.join('')
  27423. }
  27424. function read (buffer, offset, isLE, mLen, nBytes) {
  27425. var e, m;
  27426. var eLen = nBytes * 8 - mLen - 1;
  27427. var eMax = (1 << eLen) - 1;
  27428. var eBias = eMax >> 1;
  27429. var nBits = -7;
  27430. var i = isLE ? (nBytes - 1) : 0;
  27431. var d = isLE ? -1 : 1;
  27432. var s = buffer[offset + i];
  27433. i += d;
  27434. e = s & ((1 << (-nBits)) - 1);
  27435. s >>= (-nBits);
  27436. nBits += eLen;
  27437. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27438. m = e & ((1 << (-nBits)) - 1);
  27439. e >>= (-nBits);
  27440. nBits += mLen;
  27441. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27442. if (e === 0) {
  27443. e = 1 - eBias;
  27444. } else if (e === eMax) {
  27445. return m ? NaN : ((s ? -1 : 1) * Infinity)
  27446. } else {
  27447. m = m + Math.pow(2, mLen);
  27448. e = e - eBias;
  27449. }
  27450. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  27451. }
  27452. function write (buffer, value, offset, isLE, mLen, nBytes) {
  27453. var e, m, c;
  27454. var eLen = nBytes * 8 - mLen - 1;
  27455. var eMax = (1 << eLen) - 1;
  27456. var eBias = eMax >> 1;
  27457. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  27458. var i = isLE ? 0 : (nBytes - 1);
  27459. var d = isLE ? 1 : -1;
  27460. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  27461. value = Math.abs(value);
  27462. if (isNaN(value) || value === Infinity) {
  27463. m = isNaN(value) ? 1 : 0;
  27464. e = eMax;
  27465. } else {
  27466. e = Math.floor(Math.log(value) / Math.LN2);
  27467. if (value * (c = Math.pow(2, -e)) < 1) {
  27468. e--;
  27469. c *= 2;
  27470. }
  27471. if (e + eBias >= 1) {
  27472. value += rt / c;
  27473. } else {
  27474. value += rt * Math.pow(2, 1 - eBias);
  27475. }
  27476. if (value * c >= 2) {
  27477. e++;
  27478. c /= 2;
  27479. }
  27480. if (e + eBias >= eMax) {
  27481. m = 0;
  27482. e = eMax;
  27483. } else if (e + eBias >= 1) {
  27484. m = (value * c - 1) * Math.pow(2, mLen);
  27485. e = e + eBias;
  27486. } else {
  27487. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  27488. e = 0;
  27489. }
  27490. }
  27491. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  27492. e = (e << mLen) | m;
  27493. eLen += mLen;
  27494. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  27495. buffer[offset + i - d] |= s * 128;
  27496. }
  27497. var toString$1 = {}.toString;
  27498. var isArray$2 = Array.isArray || function (arr) {
  27499. return toString$1.call(arr) == '[object Array]';
  27500. };
  27501. /*!
  27502. * The buffer module from node.js, for the browser.
  27503. *
  27504. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  27505. * @license MIT
  27506. */
  27507. /* eslint-disable no-proto */
  27508. var INSPECT_MAX_BYTES = 50;
  27509. /**
  27510. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  27511. * === true Use Uint8Array implementation (fastest)
  27512. * === false Use Object implementation (most compatible, even IE6)
  27513. *
  27514. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  27515. * Opera 11.6+, iOS 4.2+.
  27516. *
  27517. * Due to various browser bugs, sometimes the Object implementation will be used even
  27518. * when the browser supports typed arrays.
  27519. *
  27520. * Note:
  27521. *
  27522. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  27523. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  27524. *
  27525. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  27526. *
  27527. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  27528. * incorrect length in some situations.
  27529. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  27530. * get the Object implementation, which is slower but behaves correctly.
  27531. */
  27532. Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  27533. ? global$1.TYPED_ARRAY_SUPPORT
  27534. : true;
  27535. /*
  27536. * Export kMaxLength after typed array support is determined.
  27537. */
  27538. kMaxLength();
  27539. function kMaxLength () {
  27540. return Buffer$1.TYPED_ARRAY_SUPPORT
  27541. ? 0x7fffffff
  27542. : 0x3fffffff
  27543. }
  27544. function createBuffer (that, length) {
  27545. if (kMaxLength() < length) {
  27546. throw new RangeError('Invalid typed array length')
  27547. }
  27548. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27549. // Return an augmented `Uint8Array` instance, for best performance
  27550. that = new Uint8Array(length);
  27551. that.__proto__ = Buffer$1.prototype;
  27552. } else {
  27553. // Fallback: Return an object instance of the Buffer class
  27554. if (that === null) {
  27555. that = new Buffer$1(length);
  27556. }
  27557. that.length = length;
  27558. }
  27559. return that
  27560. }
  27561. /**
  27562. * The Buffer constructor returns instances of `Uint8Array` that have their
  27563. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  27564. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  27565. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  27566. * returns a single octet.
  27567. *
  27568. * The `Uint8Array` prototype remains unmodified.
  27569. */
  27570. function Buffer$1 (arg, encodingOrOffset, length) {
  27571. if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) {
  27572. return new Buffer$1(arg, encodingOrOffset, length)
  27573. }
  27574. // Common case.
  27575. if (typeof arg === 'number') {
  27576. if (typeof encodingOrOffset === 'string') {
  27577. throw new Error(
  27578. 'If encoding is specified then the first argument must be a string'
  27579. )
  27580. }
  27581. return allocUnsafe(this, arg)
  27582. }
  27583. return from(this, arg, encodingOrOffset, length)
  27584. }
  27585. Buffer$1.poolSize = 8192; // not used by this implementation
  27586. // TODO: Legacy, not needed anymore. Remove in next major version.
  27587. Buffer$1._augment = function (arr) {
  27588. arr.__proto__ = Buffer$1.prototype;
  27589. return arr
  27590. };
  27591. function from (that, value, encodingOrOffset, length) {
  27592. if (typeof value === 'number') {
  27593. throw new TypeError('"value" argument must not be a number')
  27594. }
  27595. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  27596. return fromArrayBuffer(that, value, encodingOrOffset, length)
  27597. }
  27598. if (typeof value === 'string') {
  27599. return fromString(that, value, encodingOrOffset)
  27600. }
  27601. return fromObject(that, value)
  27602. }
  27603. /**
  27604. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  27605. * if value is a number.
  27606. * Buffer.from(str[, encoding])
  27607. * Buffer.from(array)
  27608. * Buffer.from(buffer)
  27609. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  27610. **/
  27611. Buffer$1.from = function (value, encodingOrOffset, length) {
  27612. return from(null, value, encodingOrOffset, length)
  27613. };
  27614. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27615. Buffer$1.prototype.__proto__ = Uint8Array.prototype;
  27616. Buffer$1.__proto__ = Uint8Array;
  27617. if (typeof Symbol !== 'undefined' && Symbol.species &&
  27618. Buffer$1[Symbol.species] === Buffer$1) ;
  27619. }
  27620. function assertSize (size) {
  27621. if (typeof size !== 'number') {
  27622. throw new TypeError('"size" argument must be a number')
  27623. } else if (size < 0) {
  27624. throw new RangeError('"size" argument must not be negative')
  27625. }
  27626. }
  27627. function alloc (that, size, fill, encoding) {
  27628. assertSize(size);
  27629. if (size <= 0) {
  27630. return createBuffer(that, size)
  27631. }
  27632. if (fill !== undefined) {
  27633. // Only pay attention to encoding if it's a string. This
  27634. // prevents accidentally sending in a number that would
  27635. // be interpretted as a start offset.
  27636. return typeof encoding === 'string'
  27637. ? createBuffer(that, size).fill(fill, encoding)
  27638. : createBuffer(that, size).fill(fill)
  27639. }
  27640. return createBuffer(that, size)
  27641. }
  27642. /**
  27643. * Creates a new filled Buffer instance.
  27644. * alloc(size[, fill[, encoding]])
  27645. **/
  27646. Buffer$1.alloc = function (size, fill, encoding) {
  27647. return alloc(null, size, fill, encoding)
  27648. };
  27649. function allocUnsafe (that, size) {
  27650. assertSize(size);
  27651. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  27652. if (!Buffer$1.TYPED_ARRAY_SUPPORT) {
  27653. for (var i = 0; i < size; ++i) {
  27654. that[i] = 0;
  27655. }
  27656. }
  27657. return that
  27658. }
  27659. /**
  27660. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  27661. * */
  27662. Buffer$1.allocUnsafe = function (size) {
  27663. return allocUnsafe(null, size)
  27664. };
  27665. /**
  27666. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  27667. */
  27668. Buffer$1.allocUnsafeSlow = function (size) {
  27669. return allocUnsafe(null, size)
  27670. };
  27671. function fromString (that, string, encoding) {
  27672. if (typeof encoding !== 'string' || encoding === '') {
  27673. encoding = 'utf8';
  27674. }
  27675. if (!Buffer$1.isEncoding(encoding)) {
  27676. throw new TypeError('"encoding" must be a valid string encoding')
  27677. }
  27678. var length = byteLength(string, encoding) | 0;
  27679. that = createBuffer(that, length);
  27680. var actual = that.write(string, encoding);
  27681. if (actual !== length) {
  27682. // Writing a hex string, for example, that contains invalid characters will
  27683. // cause everything after the first invalid character to be ignored. (e.g.
  27684. // 'abxxcd' will be treated as 'ab')
  27685. that = that.slice(0, actual);
  27686. }
  27687. return that
  27688. }
  27689. function fromArrayLike (that, array) {
  27690. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  27691. that = createBuffer(that, length);
  27692. for (var i = 0; i < length; i += 1) {
  27693. that[i] = array[i] & 255;
  27694. }
  27695. return that
  27696. }
  27697. function fromArrayBuffer (that, array, byteOffset, length) {
  27698. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  27699. if (byteOffset < 0 || array.byteLength < byteOffset) {
  27700. throw new RangeError('\'offset\' is out of bounds')
  27701. }
  27702. if (array.byteLength < byteOffset + (length || 0)) {
  27703. throw new RangeError('\'length\' is out of bounds')
  27704. }
  27705. if (byteOffset === undefined && length === undefined) {
  27706. array = new Uint8Array(array);
  27707. } else if (length === undefined) {
  27708. array = new Uint8Array(array, byteOffset);
  27709. } else {
  27710. array = new Uint8Array(array, byteOffset, length);
  27711. }
  27712. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27713. // Return an augmented `Uint8Array` instance, for best performance
  27714. that = array;
  27715. that.__proto__ = Buffer$1.prototype;
  27716. } else {
  27717. // Fallback: Return an object instance of the Buffer class
  27718. that = fromArrayLike(that, array);
  27719. }
  27720. return that
  27721. }
  27722. function fromObject (that, obj) {
  27723. if (internalIsBuffer(obj)) {
  27724. var len = checked(obj.length) | 0;
  27725. that = createBuffer(that, len);
  27726. if (that.length === 0) {
  27727. return that
  27728. }
  27729. obj.copy(that, 0, 0, len);
  27730. return that
  27731. }
  27732. if (obj) {
  27733. if ((typeof ArrayBuffer !== 'undefined' &&
  27734. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  27735. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  27736. return createBuffer(that, 0)
  27737. }
  27738. return fromArrayLike(that, obj)
  27739. }
  27740. if (obj.type === 'Buffer' && isArray$2(obj.data)) {
  27741. return fromArrayLike(that, obj.data)
  27742. }
  27743. }
  27744. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  27745. }
  27746. function checked (length) {
  27747. // Note: cannot use `length < kMaxLength()` here because that fails when
  27748. // length is NaN (which is otherwise coerced to zero.)
  27749. if (length >= kMaxLength()) {
  27750. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  27751. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  27752. }
  27753. return length | 0
  27754. }
  27755. Buffer$1.isBuffer = isBuffer$1;
  27756. function internalIsBuffer (b) {
  27757. return !!(b != null && b._isBuffer)
  27758. }
  27759. Buffer$1.compare = function compare (a, b) {
  27760. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  27761. throw new TypeError('Arguments must be Buffers')
  27762. }
  27763. if (a === b) return 0
  27764. var x = a.length;
  27765. var y = b.length;
  27766. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  27767. if (a[i] !== b[i]) {
  27768. x = a[i];
  27769. y = b[i];
  27770. break
  27771. }
  27772. }
  27773. if (x < y) return -1
  27774. if (y < x) return 1
  27775. return 0
  27776. };
  27777. Buffer$1.isEncoding = function isEncoding (encoding) {
  27778. switch (String(encoding).toLowerCase()) {
  27779. case 'hex':
  27780. case 'utf8':
  27781. case 'utf-8':
  27782. case 'ascii':
  27783. case 'latin1':
  27784. case 'binary':
  27785. case 'base64':
  27786. case 'ucs2':
  27787. case 'ucs-2':
  27788. case 'utf16le':
  27789. case 'utf-16le':
  27790. return true
  27791. default:
  27792. return false
  27793. }
  27794. };
  27795. Buffer$1.concat = function concat (list, length) {
  27796. if (!isArray$2(list)) {
  27797. throw new TypeError('"list" argument must be an Array of Buffers')
  27798. }
  27799. if (list.length === 0) {
  27800. return Buffer$1.alloc(0)
  27801. }
  27802. var i;
  27803. if (length === undefined) {
  27804. length = 0;
  27805. for (i = 0; i < list.length; ++i) {
  27806. length += list[i].length;
  27807. }
  27808. }
  27809. var buffer = Buffer$1.allocUnsafe(length);
  27810. var pos = 0;
  27811. for (i = 0; i < list.length; ++i) {
  27812. var buf = list[i];
  27813. if (!internalIsBuffer(buf)) {
  27814. throw new TypeError('"list" argument must be an Array of Buffers')
  27815. }
  27816. buf.copy(buffer, pos);
  27817. pos += buf.length;
  27818. }
  27819. return buffer
  27820. };
  27821. function byteLength (string, encoding) {
  27822. if (internalIsBuffer(string)) {
  27823. return string.length
  27824. }
  27825. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  27826. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  27827. return string.byteLength
  27828. }
  27829. if (typeof string !== 'string') {
  27830. string = '' + string;
  27831. }
  27832. var len = string.length;
  27833. if (len === 0) return 0
  27834. // Use a for loop to avoid recursion
  27835. var loweredCase = false;
  27836. for (;;) {
  27837. switch (encoding) {
  27838. case 'ascii':
  27839. case 'latin1':
  27840. case 'binary':
  27841. return len
  27842. case 'utf8':
  27843. case 'utf-8':
  27844. case undefined:
  27845. return utf8ToBytes(string).length
  27846. case 'ucs2':
  27847. case 'ucs-2':
  27848. case 'utf16le':
  27849. case 'utf-16le':
  27850. return len * 2
  27851. case 'hex':
  27852. return len >>> 1
  27853. case 'base64':
  27854. return base64ToBytes(string).length
  27855. default:
  27856. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  27857. encoding = ('' + encoding).toLowerCase();
  27858. loweredCase = true;
  27859. }
  27860. }
  27861. }
  27862. Buffer$1.byteLength = byteLength;
  27863. function slowToString (encoding, start, end) {
  27864. var loweredCase = false;
  27865. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  27866. // property of a typed array.
  27867. // This behaves neither like String nor Uint8Array in that we set start/end
  27868. // to their upper/lower bounds if the value passed is out of range.
  27869. // undefined is handled specially as per ECMA-262 6th Edition,
  27870. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  27871. if (start === undefined || start < 0) {
  27872. start = 0;
  27873. }
  27874. // Return early if start > this.length. Done here to prevent potential uint32
  27875. // coercion fail below.
  27876. if (start > this.length) {
  27877. return ''
  27878. }
  27879. if (end === undefined || end > this.length) {
  27880. end = this.length;
  27881. }
  27882. if (end <= 0) {
  27883. return ''
  27884. }
  27885. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  27886. end >>>= 0;
  27887. start >>>= 0;
  27888. if (end <= start) {
  27889. return ''
  27890. }
  27891. if (!encoding) encoding = 'utf8';
  27892. while (true) {
  27893. switch (encoding) {
  27894. case 'hex':
  27895. return hexSlice(this, start, end)
  27896. case 'utf8':
  27897. case 'utf-8':
  27898. return utf8Slice(this, start, end)
  27899. case 'ascii':
  27900. return asciiSlice(this, start, end)
  27901. case 'latin1':
  27902. case 'binary':
  27903. return latin1Slice(this, start, end)
  27904. case 'base64':
  27905. return base64Slice(this, start, end)
  27906. case 'ucs2':
  27907. case 'ucs-2':
  27908. case 'utf16le':
  27909. case 'utf-16le':
  27910. return utf16leSlice(this, start, end)
  27911. default:
  27912. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  27913. encoding = (encoding + '').toLowerCase();
  27914. loweredCase = true;
  27915. }
  27916. }
  27917. }
  27918. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  27919. // Buffer instances.
  27920. Buffer$1.prototype._isBuffer = true;
  27921. function swap (b, n, m) {
  27922. var i = b[n];
  27923. b[n] = b[m];
  27924. b[m] = i;
  27925. }
  27926. Buffer$1.prototype.swap16 = function swap16 () {
  27927. var len = this.length;
  27928. if (len % 2 !== 0) {
  27929. throw new RangeError('Buffer size must be a multiple of 16-bits')
  27930. }
  27931. for (var i = 0; i < len; i += 2) {
  27932. swap(this, i, i + 1);
  27933. }
  27934. return this
  27935. };
  27936. Buffer$1.prototype.swap32 = function swap32 () {
  27937. var len = this.length;
  27938. if (len % 4 !== 0) {
  27939. throw new RangeError('Buffer size must be a multiple of 32-bits')
  27940. }
  27941. for (var i = 0; i < len; i += 4) {
  27942. swap(this, i, i + 3);
  27943. swap(this, i + 1, i + 2);
  27944. }
  27945. return this
  27946. };
  27947. Buffer$1.prototype.swap64 = function swap64 () {
  27948. var len = this.length;
  27949. if (len % 8 !== 0) {
  27950. throw new RangeError('Buffer size must be a multiple of 64-bits')
  27951. }
  27952. for (var i = 0; i < len; i += 8) {
  27953. swap(this, i, i + 7);
  27954. swap(this, i + 1, i + 6);
  27955. swap(this, i + 2, i + 5);
  27956. swap(this, i + 3, i + 4);
  27957. }
  27958. return this
  27959. };
  27960. Buffer$1.prototype.toString = function toString () {
  27961. var length = this.length | 0;
  27962. if (length === 0) return ''
  27963. if (arguments.length === 0) return utf8Slice(this, 0, length)
  27964. return slowToString.apply(this, arguments)
  27965. };
  27966. Buffer$1.prototype.equals = function equals (b) {
  27967. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  27968. if (this === b) return true
  27969. return Buffer$1.compare(this, b) === 0
  27970. };
  27971. Buffer$1.prototype.inspect = function inspect () {
  27972. var str = '';
  27973. var max = INSPECT_MAX_BYTES;
  27974. if (this.length > 0) {
  27975. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  27976. if (this.length > max) str += ' ... ';
  27977. }
  27978. return '<Buffer ' + str + '>'
  27979. };
  27980. Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  27981. if (!internalIsBuffer(target)) {
  27982. throw new TypeError('Argument must be a Buffer')
  27983. }
  27984. if (start === undefined) {
  27985. start = 0;
  27986. }
  27987. if (end === undefined) {
  27988. end = target ? target.length : 0;
  27989. }
  27990. if (thisStart === undefined) {
  27991. thisStart = 0;
  27992. }
  27993. if (thisEnd === undefined) {
  27994. thisEnd = this.length;
  27995. }
  27996. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  27997. throw new RangeError('out of range index')
  27998. }
  27999. if (thisStart >= thisEnd && start >= end) {
  28000. return 0
  28001. }
  28002. if (thisStart >= thisEnd) {
  28003. return -1
  28004. }
  28005. if (start >= end) {
  28006. return 1
  28007. }
  28008. start >>>= 0;
  28009. end >>>= 0;
  28010. thisStart >>>= 0;
  28011. thisEnd >>>= 0;
  28012. if (this === target) return 0
  28013. var x = thisEnd - thisStart;
  28014. var y = end - start;
  28015. var len = Math.min(x, y);
  28016. var thisCopy = this.slice(thisStart, thisEnd);
  28017. var targetCopy = target.slice(start, end);
  28018. for (var i = 0; i < len; ++i) {
  28019. if (thisCopy[i] !== targetCopy[i]) {
  28020. x = thisCopy[i];
  28021. y = targetCopy[i];
  28022. break
  28023. }
  28024. }
  28025. if (x < y) return -1
  28026. if (y < x) return 1
  28027. return 0
  28028. };
  28029. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  28030. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  28031. //
  28032. // Arguments:
  28033. // - buffer - a Buffer to search
  28034. // - val - a string, Buffer, or number
  28035. // - byteOffset - an index into `buffer`; will be clamped to an int32
  28036. // - encoding - an optional encoding, relevant is val is a string
  28037. // - dir - true for indexOf, false for lastIndexOf
  28038. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  28039. // Empty buffer means no match
  28040. if (buffer.length === 0) return -1
  28041. // Normalize byteOffset
  28042. if (typeof byteOffset === 'string') {
  28043. encoding = byteOffset;
  28044. byteOffset = 0;
  28045. } else if (byteOffset > 0x7fffffff) {
  28046. byteOffset = 0x7fffffff;
  28047. } else if (byteOffset < -2147483648) {
  28048. byteOffset = -2147483648;
  28049. }
  28050. byteOffset = +byteOffset; // Coerce to Number.
  28051. if (isNaN(byteOffset)) {
  28052. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  28053. byteOffset = dir ? 0 : (buffer.length - 1);
  28054. }
  28055. // Normalize byteOffset: negative offsets start from the end of the buffer
  28056. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  28057. if (byteOffset >= buffer.length) {
  28058. if (dir) return -1
  28059. else byteOffset = buffer.length - 1;
  28060. } else if (byteOffset < 0) {
  28061. if (dir) byteOffset = 0;
  28062. else return -1
  28063. }
  28064. // Normalize val
  28065. if (typeof val === 'string') {
  28066. val = Buffer$1.from(val, encoding);
  28067. }
  28068. // Finally, search either indexOf (if dir is true) or lastIndexOf
  28069. if (internalIsBuffer(val)) {
  28070. // Special case: looking for empty string/buffer always fails
  28071. if (val.length === 0) {
  28072. return -1
  28073. }
  28074. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  28075. } else if (typeof val === 'number') {
  28076. val = val & 0xFF; // Search for a byte value [0-255]
  28077. if (Buffer$1.TYPED_ARRAY_SUPPORT &&
  28078. typeof Uint8Array.prototype.indexOf === 'function') {
  28079. if (dir) {
  28080. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  28081. } else {
  28082. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  28083. }
  28084. }
  28085. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  28086. }
  28087. throw new TypeError('val must be string, number or Buffer')
  28088. }
  28089. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  28090. var indexSize = 1;
  28091. var arrLength = arr.length;
  28092. var valLength = val.length;
  28093. if (encoding !== undefined) {
  28094. encoding = String(encoding).toLowerCase();
  28095. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  28096. encoding === 'utf16le' || encoding === 'utf-16le') {
  28097. if (arr.length < 2 || val.length < 2) {
  28098. return -1
  28099. }
  28100. indexSize = 2;
  28101. arrLength /= 2;
  28102. valLength /= 2;
  28103. byteOffset /= 2;
  28104. }
  28105. }
  28106. function read (buf, i) {
  28107. if (indexSize === 1) {
  28108. return buf[i]
  28109. } else {
  28110. return buf.readUInt16BE(i * indexSize)
  28111. }
  28112. }
  28113. var i;
  28114. if (dir) {
  28115. var foundIndex = -1;
  28116. for (i = byteOffset; i < arrLength; i++) {
  28117. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  28118. if (foundIndex === -1) foundIndex = i;
  28119. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  28120. } else {
  28121. if (foundIndex !== -1) i -= i - foundIndex;
  28122. foundIndex = -1;
  28123. }
  28124. }
  28125. } else {
  28126. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  28127. for (i = byteOffset; i >= 0; i--) {
  28128. var found = true;
  28129. for (var j = 0; j < valLength; j++) {
  28130. if (read(arr, i + j) !== read(val, j)) {
  28131. found = false;
  28132. break
  28133. }
  28134. }
  28135. if (found) return i
  28136. }
  28137. }
  28138. return -1
  28139. }
  28140. Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) {
  28141. return this.indexOf(val, byteOffset, encoding) !== -1
  28142. };
  28143. Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  28144. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  28145. };
  28146. Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  28147. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  28148. };
  28149. function hexWrite (buf, string, offset, length) {
  28150. offset = Number(offset) || 0;
  28151. var remaining = buf.length - offset;
  28152. if (!length) {
  28153. length = remaining;
  28154. } else {
  28155. length = Number(length);
  28156. if (length > remaining) {
  28157. length = remaining;
  28158. }
  28159. }
  28160. // must be an even number of digits
  28161. var strLen = string.length;
  28162. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  28163. if (length > strLen / 2) {
  28164. length = strLen / 2;
  28165. }
  28166. for (var i = 0; i < length; ++i) {
  28167. var parsed = parseInt(string.substr(i * 2, 2), 16);
  28168. if (isNaN(parsed)) return i
  28169. buf[offset + i] = parsed;
  28170. }
  28171. return i
  28172. }
  28173. function utf8Write (buf, string, offset, length) {
  28174. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  28175. }
  28176. function asciiWrite (buf, string, offset, length) {
  28177. return blitBuffer(asciiToBytes(string), buf, offset, length)
  28178. }
  28179. function latin1Write (buf, string, offset, length) {
  28180. return asciiWrite(buf, string, offset, length)
  28181. }
  28182. function base64Write (buf, string, offset, length) {
  28183. return blitBuffer(base64ToBytes(string), buf, offset, length)
  28184. }
  28185. function ucs2Write (buf, string, offset, length) {
  28186. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  28187. }
  28188. Buffer$1.prototype.write = function write (string, offset, length, encoding) {
  28189. // Buffer#write(string)
  28190. if (offset === undefined) {
  28191. encoding = 'utf8';
  28192. length = this.length;
  28193. offset = 0;
  28194. // Buffer#write(string, encoding)
  28195. } else if (length === undefined && typeof offset === 'string') {
  28196. encoding = offset;
  28197. length = this.length;
  28198. offset = 0;
  28199. // Buffer#write(string, offset[, length][, encoding])
  28200. } else if (isFinite(offset)) {
  28201. offset = offset | 0;
  28202. if (isFinite(length)) {
  28203. length = length | 0;
  28204. if (encoding === undefined) encoding = 'utf8';
  28205. } else {
  28206. encoding = length;
  28207. length = undefined;
  28208. }
  28209. // legacy write(string, encoding, offset, length) - remove in v0.13
  28210. } else {
  28211. throw new Error(
  28212. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  28213. )
  28214. }
  28215. var remaining = this.length - offset;
  28216. if (length === undefined || length > remaining) length = remaining;
  28217. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  28218. throw new RangeError('Attempt to write outside buffer bounds')
  28219. }
  28220. if (!encoding) encoding = 'utf8';
  28221. var loweredCase = false;
  28222. for (;;) {
  28223. switch (encoding) {
  28224. case 'hex':
  28225. return hexWrite(this, string, offset, length)
  28226. case 'utf8':
  28227. case 'utf-8':
  28228. return utf8Write(this, string, offset, length)
  28229. case 'ascii':
  28230. return asciiWrite(this, string, offset, length)
  28231. case 'latin1':
  28232. case 'binary':
  28233. return latin1Write(this, string, offset, length)
  28234. case 'base64':
  28235. // Warning: maxLength not taken into account in base64Write
  28236. return base64Write(this, string, offset, length)
  28237. case 'ucs2':
  28238. case 'ucs-2':
  28239. case 'utf16le':
  28240. case 'utf-16le':
  28241. return ucs2Write(this, string, offset, length)
  28242. default:
  28243. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  28244. encoding = ('' + encoding).toLowerCase();
  28245. loweredCase = true;
  28246. }
  28247. }
  28248. };
  28249. Buffer$1.prototype.toJSON = function toJSON () {
  28250. return {
  28251. type: 'Buffer',
  28252. data: Array.prototype.slice.call(this._arr || this, 0)
  28253. }
  28254. };
  28255. function base64Slice (buf, start, end) {
  28256. if (start === 0 && end === buf.length) {
  28257. return fromByteArray(buf)
  28258. } else {
  28259. return fromByteArray(buf.slice(start, end))
  28260. }
  28261. }
  28262. function utf8Slice (buf, start, end) {
  28263. end = Math.min(buf.length, end);
  28264. var res = [];
  28265. var i = start;
  28266. while (i < end) {
  28267. var firstByte = buf[i];
  28268. var codePoint = null;
  28269. var bytesPerSequence = (firstByte > 0xEF) ? 4
  28270. : (firstByte > 0xDF) ? 3
  28271. : (firstByte > 0xBF) ? 2
  28272. : 1;
  28273. if (i + bytesPerSequence <= end) {
  28274. var secondByte, thirdByte, fourthByte, tempCodePoint;
  28275. switch (bytesPerSequence) {
  28276. case 1:
  28277. if (firstByte < 0x80) {
  28278. codePoint = firstByte;
  28279. }
  28280. break
  28281. case 2:
  28282. secondByte = buf[i + 1];
  28283. if ((secondByte & 0xC0) === 0x80) {
  28284. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  28285. if (tempCodePoint > 0x7F) {
  28286. codePoint = tempCodePoint;
  28287. }
  28288. }
  28289. break
  28290. case 3:
  28291. secondByte = buf[i + 1];
  28292. thirdByte = buf[i + 2];
  28293. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  28294. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  28295. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  28296. codePoint = tempCodePoint;
  28297. }
  28298. }
  28299. break
  28300. case 4:
  28301. secondByte = buf[i + 1];
  28302. thirdByte = buf[i + 2];
  28303. fourthByte = buf[i + 3];
  28304. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  28305. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  28306. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  28307. codePoint = tempCodePoint;
  28308. }
  28309. }
  28310. }
  28311. }
  28312. if (codePoint === null) {
  28313. // we did not generate a valid codePoint so insert a
  28314. // replacement char (U+FFFD) and advance only 1 byte
  28315. codePoint = 0xFFFD;
  28316. bytesPerSequence = 1;
  28317. } else if (codePoint > 0xFFFF) {
  28318. // encode to utf16 (surrogate pair dance)
  28319. codePoint -= 0x10000;
  28320. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  28321. codePoint = 0xDC00 | codePoint & 0x3FF;
  28322. }
  28323. res.push(codePoint);
  28324. i += bytesPerSequence;
  28325. }
  28326. return decodeCodePointsArray(res)
  28327. }
  28328. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  28329. // the lowest limit is Chrome, with 0x10000 args.
  28330. // We go 1 magnitude less, for safety
  28331. var MAX_ARGUMENTS_LENGTH = 0x1000;
  28332. function decodeCodePointsArray (codePoints) {
  28333. var len = codePoints.length;
  28334. if (len <= MAX_ARGUMENTS_LENGTH) {
  28335. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  28336. }
  28337. // Decode in chunks to avoid "call stack size exceeded".
  28338. var res = '';
  28339. var i = 0;
  28340. while (i < len) {
  28341. res += String.fromCharCode.apply(
  28342. String,
  28343. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  28344. );
  28345. }
  28346. return res
  28347. }
  28348. function asciiSlice (buf, start, end) {
  28349. var ret = '';
  28350. end = Math.min(buf.length, end);
  28351. for (var i = start; i < end; ++i) {
  28352. ret += String.fromCharCode(buf[i] & 0x7F);
  28353. }
  28354. return ret
  28355. }
  28356. function latin1Slice (buf, start, end) {
  28357. var ret = '';
  28358. end = Math.min(buf.length, end);
  28359. for (var i = start; i < end; ++i) {
  28360. ret += String.fromCharCode(buf[i]);
  28361. }
  28362. return ret
  28363. }
  28364. function hexSlice (buf, start, end) {
  28365. var len = buf.length;
  28366. if (!start || start < 0) start = 0;
  28367. if (!end || end < 0 || end > len) end = len;
  28368. var out = '';
  28369. for (var i = start; i < end; ++i) {
  28370. out += toHex(buf[i]);
  28371. }
  28372. return out
  28373. }
  28374. function utf16leSlice (buf, start, end) {
  28375. var bytes = buf.slice(start, end);
  28376. var res = '';
  28377. for (var i = 0; i < bytes.length; i += 2) {
  28378. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  28379. }
  28380. return res
  28381. }
  28382. Buffer$1.prototype.slice = function slice (start, end) {
  28383. var len = this.length;
  28384. start = ~~start;
  28385. end = end === undefined ? len : ~~end;
  28386. if (start < 0) {
  28387. start += len;
  28388. if (start < 0) start = 0;
  28389. } else if (start > len) {
  28390. start = len;
  28391. }
  28392. if (end < 0) {
  28393. end += len;
  28394. if (end < 0) end = 0;
  28395. } else if (end > len) {
  28396. end = len;
  28397. }
  28398. if (end < start) end = start;
  28399. var newBuf;
  28400. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28401. newBuf = this.subarray(start, end);
  28402. newBuf.__proto__ = Buffer$1.prototype;
  28403. } else {
  28404. var sliceLen = end - start;
  28405. newBuf = new Buffer$1(sliceLen, undefined);
  28406. for (var i = 0; i < sliceLen; ++i) {
  28407. newBuf[i] = this[i + start];
  28408. }
  28409. }
  28410. return newBuf
  28411. };
  28412. /*
  28413. * Need to make sure that buffer isn't trying to write out of bounds.
  28414. */
  28415. function checkOffset (offset, ext, length) {
  28416. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  28417. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  28418. }
  28419. Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  28420. offset = offset | 0;
  28421. byteLength = byteLength | 0;
  28422. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28423. var val = this[offset];
  28424. var mul = 1;
  28425. var i = 0;
  28426. while (++i < byteLength && (mul *= 0x100)) {
  28427. val += this[offset + i] * mul;
  28428. }
  28429. return val
  28430. };
  28431. Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  28432. offset = offset | 0;
  28433. byteLength = byteLength | 0;
  28434. if (!noAssert) {
  28435. checkOffset(offset, byteLength, this.length);
  28436. }
  28437. var val = this[offset + --byteLength];
  28438. var mul = 1;
  28439. while (byteLength > 0 && (mul *= 0x100)) {
  28440. val += this[offset + --byteLength] * mul;
  28441. }
  28442. return val
  28443. };
  28444. Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  28445. if (!noAssert) checkOffset(offset, 1, this.length);
  28446. return this[offset]
  28447. };
  28448. Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  28449. if (!noAssert) checkOffset(offset, 2, this.length);
  28450. return this[offset] | (this[offset + 1] << 8)
  28451. };
  28452. Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  28453. if (!noAssert) checkOffset(offset, 2, this.length);
  28454. return (this[offset] << 8) | this[offset + 1]
  28455. };
  28456. Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  28457. if (!noAssert) checkOffset(offset, 4, this.length);
  28458. return ((this[offset]) |
  28459. (this[offset + 1] << 8) |
  28460. (this[offset + 2] << 16)) +
  28461. (this[offset + 3] * 0x1000000)
  28462. };
  28463. Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  28464. if (!noAssert) checkOffset(offset, 4, this.length);
  28465. return (this[offset] * 0x1000000) +
  28466. ((this[offset + 1] << 16) |
  28467. (this[offset + 2] << 8) |
  28468. this[offset + 3])
  28469. };
  28470. Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  28471. offset = offset | 0;
  28472. byteLength = byteLength | 0;
  28473. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28474. var val = this[offset];
  28475. var mul = 1;
  28476. var i = 0;
  28477. while (++i < byteLength && (mul *= 0x100)) {
  28478. val += this[offset + i] * mul;
  28479. }
  28480. mul *= 0x80;
  28481. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28482. return val
  28483. };
  28484. Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  28485. offset = offset | 0;
  28486. byteLength = byteLength | 0;
  28487. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28488. var i = byteLength;
  28489. var mul = 1;
  28490. var val = this[offset + --i];
  28491. while (i > 0 && (mul *= 0x100)) {
  28492. val += this[offset + --i] * mul;
  28493. }
  28494. mul *= 0x80;
  28495. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28496. return val
  28497. };
  28498. Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) {
  28499. if (!noAssert) checkOffset(offset, 1, this.length);
  28500. if (!(this[offset] & 0x80)) return (this[offset])
  28501. return ((0xff - this[offset] + 1) * -1)
  28502. };
  28503. Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  28504. if (!noAssert) checkOffset(offset, 2, this.length);
  28505. var val = this[offset] | (this[offset + 1] << 8);
  28506. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28507. };
  28508. Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  28509. if (!noAssert) checkOffset(offset, 2, this.length);
  28510. var val = this[offset + 1] | (this[offset] << 8);
  28511. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28512. };
  28513. Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  28514. if (!noAssert) checkOffset(offset, 4, this.length);
  28515. return (this[offset]) |
  28516. (this[offset + 1] << 8) |
  28517. (this[offset + 2] << 16) |
  28518. (this[offset + 3] << 24)
  28519. };
  28520. Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  28521. if (!noAssert) checkOffset(offset, 4, this.length);
  28522. return (this[offset] << 24) |
  28523. (this[offset + 1] << 16) |
  28524. (this[offset + 2] << 8) |
  28525. (this[offset + 3])
  28526. };
  28527. Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  28528. if (!noAssert) checkOffset(offset, 4, this.length);
  28529. return read(this, offset, true, 23, 4)
  28530. };
  28531. Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  28532. if (!noAssert) checkOffset(offset, 4, this.length);
  28533. return read(this, offset, false, 23, 4)
  28534. };
  28535. Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  28536. if (!noAssert) checkOffset(offset, 8, this.length);
  28537. return read(this, offset, true, 52, 8)
  28538. };
  28539. Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  28540. if (!noAssert) checkOffset(offset, 8, this.length);
  28541. return read(this, offset, false, 52, 8)
  28542. };
  28543. function checkInt (buf, value, offset, ext, max, min) {
  28544. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  28545. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  28546. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28547. }
  28548. Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  28549. value = +value;
  28550. offset = offset | 0;
  28551. byteLength = byteLength | 0;
  28552. if (!noAssert) {
  28553. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28554. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28555. }
  28556. var mul = 1;
  28557. var i = 0;
  28558. this[offset] = value & 0xFF;
  28559. while (++i < byteLength && (mul *= 0x100)) {
  28560. this[offset + i] = (value / mul) & 0xFF;
  28561. }
  28562. return offset + byteLength
  28563. };
  28564. Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  28565. value = +value;
  28566. offset = offset | 0;
  28567. byteLength = byteLength | 0;
  28568. if (!noAssert) {
  28569. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28570. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28571. }
  28572. var i = byteLength - 1;
  28573. var mul = 1;
  28574. this[offset + i] = value & 0xFF;
  28575. while (--i >= 0 && (mul *= 0x100)) {
  28576. this[offset + i] = (value / mul) & 0xFF;
  28577. }
  28578. return offset + byteLength
  28579. };
  28580. Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  28581. value = +value;
  28582. offset = offset | 0;
  28583. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  28584. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28585. this[offset] = (value & 0xff);
  28586. return offset + 1
  28587. };
  28588. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  28589. if (value < 0) value = 0xffff + value + 1;
  28590. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  28591. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  28592. (littleEndian ? i : 1 - i) * 8;
  28593. }
  28594. }
  28595. Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  28596. value = +value;
  28597. offset = offset | 0;
  28598. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28599. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28600. this[offset] = (value & 0xff);
  28601. this[offset + 1] = (value >>> 8);
  28602. } else {
  28603. objectWriteUInt16(this, value, offset, true);
  28604. }
  28605. return offset + 2
  28606. };
  28607. Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  28608. value = +value;
  28609. offset = offset | 0;
  28610. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28611. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28612. this[offset] = (value >>> 8);
  28613. this[offset + 1] = (value & 0xff);
  28614. } else {
  28615. objectWriteUInt16(this, value, offset, false);
  28616. }
  28617. return offset + 2
  28618. };
  28619. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  28620. if (value < 0) value = 0xffffffff + value + 1;
  28621. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  28622. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  28623. }
  28624. }
  28625. Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  28626. value = +value;
  28627. offset = offset | 0;
  28628. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28629. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28630. this[offset + 3] = (value >>> 24);
  28631. this[offset + 2] = (value >>> 16);
  28632. this[offset + 1] = (value >>> 8);
  28633. this[offset] = (value & 0xff);
  28634. } else {
  28635. objectWriteUInt32(this, value, offset, true);
  28636. }
  28637. return offset + 4
  28638. };
  28639. Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  28640. value = +value;
  28641. offset = offset | 0;
  28642. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28643. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28644. this[offset] = (value >>> 24);
  28645. this[offset + 1] = (value >>> 16);
  28646. this[offset + 2] = (value >>> 8);
  28647. this[offset + 3] = (value & 0xff);
  28648. } else {
  28649. objectWriteUInt32(this, value, offset, false);
  28650. }
  28651. return offset + 4
  28652. };
  28653. Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  28654. value = +value;
  28655. offset = offset | 0;
  28656. if (!noAssert) {
  28657. var limit = Math.pow(2, 8 * byteLength - 1);
  28658. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28659. }
  28660. var i = 0;
  28661. var mul = 1;
  28662. var sub = 0;
  28663. this[offset] = value & 0xFF;
  28664. while (++i < byteLength && (mul *= 0x100)) {
  28665. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  28666. sub = 1;
  28667. }
  28668. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28669. }
  28670. return offset + byteLength
  28671. };
  28672. Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  28673. value = +value;
  28674. offset = offset | 0;
  28675. if (!noAssert) {
  28676. var limit = Math.pow(2, 8 * byteLength - 1);
  28677. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28678. }
  28679. var i = byteLength - 1;
  28680. var mul = 1;
  28681. var sub = 0;
  28682. this[offset + i] = value & 0xFF;
  28683. while (--i >= 0 && (mul *= 0x100)) {
  28684. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  28685. sub = 1;
  28686. }
  28687. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28688. }
  28689. return offset + byteLength
  28690. };
  28691. Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  28692. value = +value;
  28693. offset = offset | 0;
  28694. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
  28695. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28696. if (value < 0) value = 0xff + value + 1;
  28697. this[offset] = (value & 0xff);
  28698. return offset + 1
  28699. };
  28700. Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  28701. value = +value;
  28702. offset = offset | 0;
  28703. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  28704. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28705. this[offset] = (value & 0xff);
  28706. this[offset + 1] = (value >>> 8);
  28707. } else {
  28708. objectWriteUInt16(this, value, offset, true);
  28709. }
  28710. return offset + 2
  28711. };
  28712. Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  28713. value = +value;
  28714. offset = offset | 0;
  28715. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  28716. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28717. this[offset] = (value >>> 8);
  28718. this[offset + 1] = (value & 0xff);
  28719. } else {
  28720. objectWriteUInt16(this, value, offset, false);
  28721. }
  28722. return offset + 2
  28723. };
  28724. Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  28725. value = +value;
  28726. offset = offset | 0;
  28727. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  28728. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28729. this[offset] = (value & 0xff);
  28730. this[offset + 1] = (value >>> 8);
  28731. this[offset + 2] = (value >>> 16);
  28732. this[offset + 3] = (value >>> 24);
  28733. } else {
  28734. objectWriteUInt32(this, value, offset, true);
  28735. }
  28736. return offset + 4
  28737. };
  28738. Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  28739. value = +value;
  28740. offset = offset | 0;
  28741. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  28742. if (value < 0) value = 0xffffffff + value + 1;
  28743. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28744. this[offset] = (value >>> 24);
  28745. this[offset + 1] = (value >>> 16);
  28746. this[offset + 2] = (value >>> 8);
  28747. this[offset + 3] = (value & 0xff);
  28748. } else {
  28749. objectWriteUInt32(this, value, offset, false);
  28750. }
  28751. return offset + 4
  28752. };
  28753. function checkIEEE754 (buf, value, offset, ext, max, min) {
  28754. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28755. if (offset < 0) throw new RangeError('Index out of range')
  28756. }
  28757. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  28758. if (!noAssert) {
  28759. checkIEEE754(buf, value, offset, 4);
  28760. }
  28761. write(buf, value, offset, littleEndian, 23, 4);
  28762. return offset + 4
  28763. }
  28764. Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  28765. return writeFloat(this, value, offset, true, noAssert)
  28766. };
  28767. Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  28768. return writeFloat(this, value, offset, false, noAssert)
  28769. };
  28770. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  28771. if (!noAssert) {
  28772. checkIEEE754(buf, value, offset, 8);
  28773. }
  28774. write(buf, value, offset, littleEndian, 52, 8);
  28775. return offset + 8
  28776. }
  28777. Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  28778. return writeDouble(this, value, offset, true, noAssert)
  28779. };
  28780. Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  28781. return writeDouble(this, value, offset, false, noAssert)
  28782. };
  28783. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  28784. Buffer$1.prototype.copy = function copy (target, targetStart, start, end) {
  28785. if (!start) start = 0;
  28786. if (!end && end !== 0) end = this.length;
  28787. if (targetStart >= target.length) targetStart = target.length;
  28788. if (!targetStart) targetStart = 0;
  28789. if (end > 0 && end < start) end = start;
  28790. // Copy 0 bytes; we're done
  28791. if (end === start) return 0
  28792. if (target.length === 0 || this.length === 0) return 0
  28793. // Fatal error conditions
  28794. if (targetStart < 0) {
  28795. throw new RangeError('targetStart out of bounds')
  28796. }
  28797. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  28798. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  28799. // Are we oob?
  28800. if (end > this.length) end = this.length;
  28801. if (target.length - targetStart < end - start) {
  28802. end = target.length - targetStart + start;
  28803. }
  28804. var len = end - start;
  28805. var i;
  28806. if (this === target && start < targetStart && targetStart < end) {
  28807. // descending copy from end
  28808. for (i = len - 1; i >= 0; --i) {
  28809. target[i + targetStart] = this[i + start];
  28810. }
  28811. } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) {
  28812. // ascending copy from start
  28813. for (i = 0; i < len; ++i) {
  28814. target[i + targetStart] = this[i + start];
  28815. }
  28816. } else {
  28817. Uint8Array.prototype.set.call(
  28818. target,
  28819. this.subarray(start, start + len),
  28820. targetStart
  28821. );
  28822. }
  28823. return len
  28824. };
  28825. // Usage:
  28826. // buffer.fill(number[, offset[, end]])
  28827. // buffer.fill(buffer[, offset[, end]])
  28828. // buffer.fill(string[, offset[, end]][, encoding])
  28829. Buffer$1.prototype.fill = function fill (val, start, end, encoding) {
  28830. // Handle string cases:
  28831. if (typeof val === 'string') {
  28832. if (typeof start === 'string') {
  28833. encoding = start;
  28834. start = 0;
  28835. end = this.length;
  28836. } else if (typeof end === 'string') {
  28837. encoding = end;
  28838. end = this.length;
  28839. }
  28840. if (val.length === 1) {
  28841. var code = val.charCodeAt(0);
  28842. if (code < 256) {
  28843. val = code;
  28844. }
  28845. }
  28846. if (encoding !== undefined && typeof encoding !== 'string') {
  28847. throw new TypeError('encoding must be a string')
  28848. }
  28849. if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) {
  28850. throw new TypeError('Unknown encoding: ' + encoding)
  28851. }
  28852. } else if (typeof val === 'number') {
  28853. val = val & 255;
  28854. }
  28855. // Invalid ranges are not set to a default, so can range check early.
  28856. if (start < 0 || this.length < start || this.length < end) {
  28857. throw new RangeError('Out of range index')
  28858. }
  28859. if (end <= start) {
  28860. return this
  28861. }
  28862. start = start >>> 0;
  28863. end = end === undefined ? this.length : end >>> 0;
  28864. if (!val) val = 0;
  28865. var i;
  28866. if (typeof val === 'number') {
  28867. for (i = start; i < end; ++i) {
  28868. this[i] = val;
  28869. }
  28870. } else {
  28871. var bytes = internalIsBuffer(val)
  28872. ? val
  28873. : utf8ToBytes(new Buffer$1(val, encoding).toString());
  28874. var len = bytes.length;
  28875. for (i = 0; i < end - start; ++i) {
  28876. this[i + start] = bytes[i % len];
  28877. }
  28878. }
  28879. return this
  28880. };
  28881. // HELPER FUNCTIONS
  28882. // ================
  28883. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  28884. function base64clean (str) {
  28885. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  28886. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  28887. // Node converts strings with length < 2 to ''
  28888. if (str.length < 2) return ''
  28889. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  28890. while (str.length % 4 !== 0) {
  28891. str = str + '=';
  28892. }
  28893. return str
  28894. }
  28895. function stringtrim (str) {
  28896. if (str.trim) return str.trim()
  28897. return str.replace(/^\s+|\s+$/g, '')
  28898. }
  28899. function toHex (n) {
  28900. if (n < 16) return '0' + n.toString(16)
  28901. return n.toString(16)
  28902. }
  28903. function utf8ToBytes (string, units) {
  28904. units = units || Infinity;
  28905. var codePoint;
  28906. var length = string.length;
  28907. var leadSurrogate = null;
  28908. var bytes = [];
  28909. for (var i = 0; i < length; ++i) {
  28910. codePoint = string.charCodeAt(i);
  28911. // is surrogate component
  28912. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  28913. // last char was a lead
  28914. if (!leadSurrogate) {
  28915. // no lead yet
  28916. if (codePoint > 0xDBFF) {
  28917. // unexpected trail
  28918. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28919. continue
  28920. } else if (i + 1 === length) {
  28921. // unpaired lead
  28922. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28923. continue
  28924. }
  28925. // valid lead
  28926. leadSurrogate = codePoint;
  28927. continue
  28928. }
  28929. // 2 leads in a row
  28930. if (codePoint < 0xDC00) {
  28931. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28932. leadSurrogate = codePoint;
  28933. continue
  28934. }
  28935. // valid surrogate pair
  28936. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  28937. } else if (leadSurrogate) {
  28938. // valid bmp char, but last char was a lead
  28939. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28940. }
  28941. leadSurrogate = null;
  28942. // encode utf8
  28943. if (codePoint < 0x80) {
  28944. if ((units -= 1) < 0) break
  28945. bytes.push(codePoint);
  28946. } else if (codePoint < 0x800) {
  28947. if ((units -= 2) < 0) break
  28948. bytes.push(
  28949. codePoint >> 0x6 | 0xC0,
  28950. codePoint & 0x3F | 0x80
  28951. );
  28952. } else if (codePoint < 0x10000) {
  28953. if ((units -= 3) < 0) break
  28954. bytes.push(
  28955. codePoint >> 0xC | 0xE0,
  28956. codePoint >> 0x6 & 0x3F | 0x80,
  28957. codePoint & 0x3F | 0x80
  28958. );
  28959. } else if (codePoint < 0x110000) {
  28960. if ((units -= 4) < 0) break
  28961. bytes.push(
  28962. codePoint >> 0x12 | 0xF0,
  28963. codePoint >> 0xC & 0x3F | 0x80,
  28964. codePoint >> 0x6 & 0x3F | 0x80,
  28965. codePoint & 0x3F | 0x80
  28966. );
  28967. } else {
  28968. throw new Error('Invalid code point')
  28969. }
  28970. }
  28971. return bytes
  28972. }
  28973. function asciiToBytes (str) {
  28974. var byteArray = [];
  28975. for (var i = 0; i < str.length; ++i) {
  28976. // Node's code seems to be doing this and not & 0x7F..
  28977. byteArray.push(str.charCodeAt(i) & 0xFF);
  28978. }
  28979. return byteArray
  28980. }
  28981. function utf16leToBytes (str, units) {
  28982. var c, hi, lo;
  28983. var byteArray = [];
  28984. for (var i = 0; i < str.length; ++i) {
  28985. if ((units -= 2) < 0) break
  28986. c = str.charCodeAt(i);
  28987. hi = c >> 8;
  28988. lo = c % 256;
  28989. byteArray.push(lo);
  28990. byteArray.push(hi);
  28991. }
  28992. return byteArray
  28993. }
  28994. function base64ToBytes (str) {
  28995. return toByteArray(base64clean(str))
  28996. }
  28997. function blitBuffer (src, dst, offset, length) {
  28998. for (var i = 0; i < length; ++i) {
  28999. if ((i + offset >= dst.length) || (i >= src.length)) break
  29000. dst[i + offset] = src[i];
  29001. }
  29002. return i
  29003. }
  29004. function isnan (val) {
  29005. return val !== val // eslint-disable-line no-self-compare
  29006. }
  29007. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  29008. // The _isBuffer check is for Safari 5-7 support, because it's missing
  29009. // Object.prototype.constructor. Remove this eventually
  29010. function isBuffer$1(obj) {
  29011. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  29012. }
  29013. function isFastBuffer (obj) {
  29014. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  29015. }
  29016. // For Node v0.10 support. Remove this eventually.
  29017. function isSlowBuffer (obj) {
  29018. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  29019. }
  29020. var inherits;
  29021. if (typeof Object.create === 'function'){
  29022. inherits = function inherits(ctor, superCtor) {
  29023. // implementation from standard node.js 'util' module
  29024. ctor.super_ = superCtor;
  29025. ctor.prototype = Object.create(superCtor.prototype, {
  29026. constructor: {
  29027. value: ctor,
  29028. enumerable: false,
  29029. writable: true,
  29030. configurable: true
  29031. }
  29032. });
  29033. };
  29034. } else {
  29035. inherits = function inherits(ctor, superCtor) {
  29036. ctor.super_ = superCtor;
  29037. var TempCtor = function () {};
  29038. TempCtor.prototype = superCtor.prototype;
  29039. ctor.prototype = new TempCtor();
  29040. ctor.prototype.constructor = ctor;
  29041. };
  29042. }
  29043. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  29044. function getOwnPropertyDescriptors(obj) {
  29045. var keys = Object.keys(obj);
  29046. var descriptors = {};
  29047. for (var i = 0; i < keys.length; i++) {
  29048. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  29049. }
  29050. return descriptors;
  29051. };
  29052. var formatRegExp = /%[sdj%]/g;
  29053. function format$1(f) {
  29054. if (!isString(f)) {
  29055. var objects = [];
  29056. for (var i = 0; i < arguments.length; i++) {
  29057. objects.push(inspect(arguments[i]));
  29058. }
  29059. return objects.join(' ');
  29060. }
  29061. var i = 1;
  29062. var args = arguments;
  29063. var len = args.length;
  29064. var str = String(f).replace(formatRegExp, function(x) {
  29065. if (x === '%%') return '%';
  29066. if (i >= len) return x;
  29067. switch (x) {
  29068. case '%s': return String(args[i++]);
  29069. case '%d': return Number(args[i++]);
  29070. case '%j':
  29071. try {
  29072. return JSON.stringify(args[i++]);
  29073. } catch (_) {
  29074. return '[Circular]';
  29075. }
  29076. default:
  29077. return x;
  29078. }
  29079. });
  29080. for (var x = args[i]; i < len; x = args[++i]) {
  29081. if (isNull(x) || !isObject$1(x)) {
  29082. str += ' ' + x;
  29083. } else {
  29084. str += ' ' + inspect(x);
  29085. }
  29086. }
  29087. return str;
  29088. }
  29089. // Mark that a method should not be used.
  29090. // Returns a modified function which warns once by default.
  29091. // If --no-deprecation is set, then it is a no-op.
  29092. function deprecate(fn, msg) {
  29093. // Allow for deprecating things in the process of starting up.
  29094. if (isUndefined(global$1.process)) {
  29095. return function() {
  29096. return deprecate(fn, msg).apply(this, arguments);
  29097. };
  29098. }
  29099. if (browser$1.noDeprecation === true) {
  29100. return fn;
  29101. }
  29102. var warned = false;
  29103. function deprecated() {
  29104. if (!warned) {
  29105. if (browser$1.throwDeprecation) {
  29106. throw new Error(msg);
  29107. } else if (browser$1.traceDeprecation) {
  29108. console.trace(msg);
  29109. } else {
  29110. console.error(msg);
  29111. }
  29112. warned = true;
  29113. }
  29114. return fn.apply(this, arguments);
  29115. }
  29116. return deprecated;
  29117. }
  29118. var debugs = {};
  29119. var debugEnviron;
  29120. function debuglog(set) {
  29121. if (isUndefined(debugEnviron))
  29122. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29123. set = set.toUpperCase();
  29124. if (!debugs[set]) {
  29125. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29126. var pid = 0;
  29127. debugs[set] = function() {
  29128. var msg = format$1.apply(null, arguments);
  29129. console.error('%s %d: %s', set, pid, msg);
  29130. };
  29131. } else {
  29132. debugs[set] = function() {};
  29133. }
  29134. }
  29135. return debugs[set];
  29136. }
  29137. /**
  29138. * Echos the value of a value. Trys to print the value out
  29139. * in the best way possible given the different types.
  29140. *
  29141. * @param {Object} obj The object to print out.
  29142. * @param {Object} opts Optional options object that alters the output.
  29143. */
  29144. /* legacy: obj, showHidden, depth, colors*/
  29145. function inspect(obj, opts) {
  29146. // default options
  29147. var ctx = {
  29148. seen: [],
  29149. stylize: stylizeNoColor
  29150. };
  29151. // legacy...
  29152. if (arguments.length >= 3) ctx.depth = arguments[2];
  29153. if (arguments.length >= 4) ctx.colors = arguments[3];
  29154. if (isBoolean(opts)) {
  29155. // legacy...
  29156. ctx.showHidden = opts;
  29157. } else if (opts) {
  29158. // got an "options" object
  29159. _extend(ctx, opts);
  29160. }
  29161. // set default options
  29162. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29163. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29164. if (isUndefined(ctx.colors)) ctx.colors = false;
  29165. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29166. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29167. return formatValue(ctx, obj, ctx.depth);
  29168. }
  29169. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29170. inspect.colors = {
  29171. 'bold' : [1, 22],
  29172. 'italic' : [3, 23],
  29173. 'underline' : [4, 24],
  29174. 'inverse' : [7, 27],
  29175. 'white' : [37, 39],
  29176. 'grey' : [90, 39],
  29177. 'black' : [30, 39],
  29178. 'blue' : [34, 39],
  29179. 'cyan' : [36, 39],
  29180. 'green' : [32, 39],
  29181. 'magenta' : [35, 39],
  29182. 'red' : [31, 39],
  29183. 'yellow' : [33, 39]
  29184. };
  29185. // Don't use 'blue' not visible on cmd.exe
  29186. inspect.styles = {
  29187. 'special': 'cyan',
  29188. 'number': 'yellow',
  29189. 'boolean': 'yellow',
  29190. 'undefined': 'grey',
  29191. 'null': 'bold',
  29192. 'string': 'green',
  29193. 'date': 'magenta',
  29194. // "name": intentionally not styling
  29195. 'regexp': 'red'
  29196. };
  29197. function stylizeWithColor(str, styleType) {
  29198. var style = inspect.styles[styleType];
  29199. if (style) {
  29200. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29201. '\u001b[' + inspect.colors[style][1] + 'm';
  29202. } else {
  29203. return str;
  29204. }
  29205. }
  29206. function stylizeNoColor(str, styleType) {
  29207. return str;
  29208. }
  29209. function arrayToHash(array) {
  29210. var hash = {};
  29211. array.forEach(function(val, idx) {
  29212. hash[val] = true;
  29213. });
  29214. return hash;
  29215. }
  29216. function formatValue(ctx, value, recurseTimes) {
  29217. // Provide a hook for user-specified inspect functions.
  29218. // Check that value is an object with an inspect function on it
  29219. if (ctx.customInspect &&
  29220. value &&
  29221. isFunction(value.inspect) &&
  29222. // Filter out the util module, it's inspect function is special
  29223. value.inspect !== inspect &&
  29224. // Also filter out any prototype objects using the circular check.
  29225. !(value.constructor && value.constructor.prototype === value)) {
  29226. var ret = value.inspect(recurseTimes, ctx);
  29227. if (!isString(ret)) {
  29228. ret = formatValue(ctx, ret, recurseTimes);
  29229. }
  29230. return ret;
  29231. }
  29232. // Primitive types cannot have properties
  29233. var primitive = formatPrimitive(ctx, value);
  29234. if (primitive) {
  29235. return primitive;
  29236. }
  29237. // Look up the keys of the object.
  29238. var keys = Object.keys(value);
  29239. var visibleKeys = arrayToHash(keys);
  29240. if (ctx.showHidden) {
  29241. keys = Object.getOwnPropertyNames(value);
  29242. }
  29243. // IE doesn't make error fields non-enumerable
  29244. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29245. if (isError(value)
  29246. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29247. return formatError(value);
  29248. }
  29249. // Some type of object without properties can be shortcutted.
  29250. if (keys.length === 0) {
  29251. if (isFunction(value)) {
  29252. var name = value.name ? ': ' + value.name : '';
  29253. return ctx.stylize('[Function' + name + ']', 'special');
  29254. }
  29255. if (isRegExp(value)) {
  29256. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29257. }
  29258. if (isDate(value)) {
  29259. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29260. }
  29261. if (isError(value)) {
  29262. return formatError(value);
  29263. }
  29264. }
  29265. var base = '', array = false, braces = ['{', '}'];
  29266. // Make Array say that they are Array
  29267. if (isArray$1(value)) {
  29268. array = true;
  29269. braces = ['[', ']'];
  29270. }
  29271. // Make functions say that they are functions
  29272. if (isFunction(value)) {
  29273. var n = value.name ? ': ' + value.name : '';
  29274. base = ' [Function' + n + ']';
  29275. }
  29276. // Make RegExps say that they are RegExps
  29277. if (isRegExp(value)) {
  29278. base = ' ' + RegExp.prototype.toString.call(value);
  29279. }
  29280. // Make dates with properties first say the date
  29281. if (isDate(value)) {
  29282. base = ' ' + Date.prototype.toUTCString.call(value);
  29283. }
  29284. // Make error with message first say the error
  29285. if (isError(value)) {
  29286. base = ' ' + formatError(value);
  29287. }
  29288. if (keys.length === 0 && (!array || value.length == 0)) {
  29289. return braces[0] + base + braces[1];
  29290. }
  29291. if (recurseTimes < 0) {
  29292. if (isRegExp(value)) {
  29293. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29294. } else {
  29295. return ctx.stylize('[Object]', 'special');
  29296. }
  29297. }
  29298. ctx.seen.push(value);
  29299. var output;
  29300. if (array) {
  29301. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29302. } else {
  29303. output = keys.map(function(key) {
  29304. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29305. });
  29306. }
  29307. ctx.seen.pop();
  29308. return reduceToSingleString(output, base, braces);
  29309. }
  29310. function formatPrimitive(ctx, value) {
  29311. if (isUndefined(value))
  29312. return ctx.stylize('undefined', 'undefined');
  29313. if (isString(value)) {
  29314. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29315. .replace(/'/g, "\\'")
  29316. .replace(/\\"/g, '"') + '\'';
  29317. return ctx.stylize(simple, 'string');
  29318. }
  29319. if (isNumber(value))
  29320. return ctx.stylize('' + value, 'number');
  29321. if (isBoolean(value))
  29322. return ctx.stylize('' + value, 'boolean');
  29323. // For some reason typeof null is "object", so special case here.
  29324. if (isNull(value))
  29325. return ctx.stylize('null', 'null');
  29326. }
  29327. function formatError(value) {
  29328. return '[' + Error.prototype.toString.call(value) + ']';
  29329. }
  29330. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29331. var output = [];
  29332. for (var i = 0, l = value.length; i < l; ++i) {
  29333. if (hasOwnProperty$2(value, String(i))) {
  29334. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29335. String(i), true));
  29336. } else {
  29337. output.push('');
  29338. }
  29339. }
  29340. keys.forEach(function(key) {
  29341. if (!key.match(/^\d+$/)) {
  29342. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29343. key, true));
  29344. }
  29345. });
  29346. return output;
  29347. }
  29348. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29349. var name, str, desc;
  29350. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29351. if (desc.get) {
  29352. if (desc.set) {
  29353. str = ctx.stylize('[Getter/Setter]', 'special');
  29354. } else {
  29355. str = ctx.stylize('[Getter]', 'special');
  29356. }
  29357. } else {
  29358. if (desc.set) {
  29359. str = ctx.stylize('[Setter]', 'special');
  29360. }
  29361. }
  29362. if (!hasOwnProperty$2(visibleKeys, key)) {
  29363. name = '[' + key + ']';
  29364. }
  29365. if (!str) {
  29366. if (ctx.seen.indexOf(desc.value) < 0) {
  29367. if (isNull(recurseTimes)) {
  29368. str = formatValue(ctx, desc.value, null);
  29369. } else {
  29370. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29371. }
  29372. if (str.indexOf('\n') > -1) {
  29373. if (array) {
  29374. str = str.split('\n').map(function(line) {
  29375. return ' ' + line;
  29376. }).join('\n').substr(2);
  29377. } else {
  29378. str = '\n' + str.split('\n').map(function(line) {
  29379. return ' ' + line;
  29380. }).join('\n');
  29381. }
  29382. }
  29383. } else {
  29384. str = ctx.stylize('[Circular]', 'special');
  29385. }
  29386. }
  29387. if (isUndefined(name)) {
  29388. if (array && key.match(/^\d+$/)) {
  29389. return str;
  29390. }
  29391. name = JSON.stringify('' + key);
  29392. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29393. name = name.substr(1, name.length - 2);
  29394. name = ctx.stylize(name, 'name');
  29395. } else {
  29396. name = name.replace(/'/g, "\\'")
  29397. .replace(/\\"/g, '"')
  29398. .replace(/(^"|"$)/g, "'");
  29399. name = ctx.stylize(name, 'string');
  29400. }
  29401. }
  29402. return name + ': ' + str;
  29403. }
  29404. function reduceToSingleString(output, base, braces) {
  29405. var length = output.reduce(function(prev, cur) {
  29406. if (cur.indexOf('\n') >= 0) ;
  29407. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29408. }, 0);
  29409. if (length > 60) {
  29410. return braces[0] +
  29411. (base === '' ? '' : base + '\n ') +
  29412. ' ' +
  29413. output.join(',\n ') +
  29414. ' ' +
  29415. braces[1];
  29416. }
  29417. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29418. }
  29419. // NOTE: These type checking functions intentionally don't use `instanceof`
  29420. // because it is fragile and can be easily faked with `Object.create()`.
  29421. function isArray$1(ar) {
  29422. return Array.isArray(ar);
  29423. }
  29424. function isBoolean(arg) {
  29425. return typeof arg === 'boolean';
  29426. }
  29427. function isNull(arg) {
  29428. return arg === null;
  29429. }
  29430. function isNullOrUndefined(arg) {
  29431. return arg == null;
  29432. }
  29433. function isNumber(arg) {
  29434. return typeof arg === 'number';
  29435. }
  29436. function isString(arg) {
  29437. return typeof arg === 'string';
  29438. }
  29439. function isSymbol(arg) {
  29440. return typeof arg === 'symbol';
  29441. }
  29442. function isUndefined(arg) {
  29443. return arg === void 0;
  29444. }
  29445. function isRegExp(re) {
  29446. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29447. }
  29448. function isObject$1(arg) {
  29449. return typeof arg === 'object' && arg !== null;
  29450. }
  29451. function isDate(d) {
  29452. return isObject$1(d) && objectToString(d) === '[object Date]';
  29453. }
  29454. function isError(e) {
  29455. return isObject$1(e) &&
  29456. (objectToString(e) === '[object Error]' || e instanceof Error);
  29457. }
  29458. function isFunction(arg) {
  29459. return typeof arg === 'function';
  29460. }
  29461. function isPrimitive(arg) {
  29462. return arg === null ||
  29463. typeof arg === 'boolean' ||
  29464. typeof arg === 'number' ||
  29465. typeof arg === 'string' ||
  29466. typeof arg === 'symbol' || // ES6 symbol
  29467. typeof arg === 'undefined';
  29468. }
  29469. function isBuffer(maybeBuf) {
  29470. return Buffer$1.isBuffer(maybeBuf);
  29471. }
  29472. function objectToString(o) {
  29473. return Object.prototype.toString.call(o);
  29474. }
  29475. function pad(n) {
  29476. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29477. }
  29478. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29479. 'Oct', 'Nov', 'Dec'];
  29480. // 26 Feb 16:19:34
  29481. function timestamp() {
  29482. var d = new Date();
  29483. var time = [pad(d.getHours()),
  29484. pad(d.getMinutes()),
  29485. pad(d.getSeconds())].join(':');
  29486. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29487. }
  29488. // log is just a thin wrapper to console.log that prepends a timestamp
  29489. function log() {
  29490. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29491. }
  29492. function _extend(origin, add) {
  29493. // Don't do anything if add isn't an object
  29494. if (!add || !isObject$1(add)) return origin;
  29495. var keys = Object.keys(add);
  29496. var i = keys.length;
  29497. while (i--) {
  29498. origin[keys[i]] = add[keys[i]];
  29499. }
  29500. return origin;
  29501. }
  29502. function hasOwnProperty$2(obj, prop) {
  29503. return Object.prototype.hasOwnProperty.call(obj, prop);
  29504. }
  29505. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29506. function promisify(original) {
  29507. if (typeof original !== 'function')
  29508. throw new TypeError('The "original" argument must be of type Function');
  29509. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29510. var fn = original[kCustomPromisifiedSymbol];
  29511. if (typeof fn !== 'function') {
  29512. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29513. }
  29514. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29515. value: fn, enumerable: false, writable: false, configurable: true
  29516. });
  29517. return fn;
  29518. }
  29519. function fn() {
  29520. var promiseResolve, promiseReject;
  29521. var promise = new Promise(function (resolve, reject) {
  29522. promiseResolve = resolve;
  29523. promiseReject = reject;
  29524. });
  29525. var args = [];
  29526. for (var i = 0; i < arguments.length; i++) {
  29527. args.push(arguments[i]);
  29528. }
  29529. args.push(function (err, value) {
  29530. if (err) {
  29531. promiseReject(err);
  29532. } else {
  29533. promiseResolve(value);
  29534. }
  29535. });
  29536. try {
  29537. original.apply(this, args);
  29538. } catch (err) {
  29539. promiseReject(err);
  29540. }
  29541. return promise;
  29542. }
  29543. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29544. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29545. value: fn, enumerable: false, writable: false, configurable: true
  29546. });
  29547. return Object.defineProperties(
  29548. fn,
  29549. getOwnPropertyDescriptors(original)
  29550. );
  29551. }
  29552. promisify.custom = kCustomPromisifiedSymbol;
  29553. function callbackifyOnRejected(reason, cb) {
  29554. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29555. // Because `null` is a special error value in callbacks which means "no error
  29556. // occurred", we error-wrap so the callback consumer can distinguish between
  29557. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29558. if (!reason) {
  29559. var newReason = new Error('Promise was rejected with a falsy value');
  29560. newReason.reason = reason;
  29561. reason = newReason;
  29562. }
  29563. return cb(reason);
  29564. }
  29565. function callbackify(original) {
  29566. if (typeof original !== 'function') {
  29567. throw new TypeError('The "original" argument must be of type Function');
  29568. }
  29569. // We DO NOT return the promise as it gives the user a false sense that
  29570. // the promise is actually somehow related to the callback's execution
  29571. // and that the callback throwing will reject the promise.
  29572. function callbackified() {
  29573. var args = [];
  29574. for (var i = 0; i < arguments.length; i++) {
  29575. args.push(arguments[i]);
  29576. }
  29577. var maybeCb = args.pop();
  29578. if (typeof maybeCb !== 'function') {
  29579. throw new TypeError('The last argument must be of type Function');
  29580. }
  29581. var self = this;
  29582. var cb = function() {
  29583. return maybeCb.apply(self, arguments);
  29584. };
  29585. // In true node style we process the callback on `nextTick` with all the
  29586. // implications (stack, `uncaughtException`, `async_hooks`)
  29587. original.apply(this, args)
  29588. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29589. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29590. }
  29591. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29592. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29593. return callbackified;
  29594. }
  29595. var _polyfillNode_util = {
  29596. inherits: inherits,
  29597. _extend: _extend,
  29598. log: log,
  29599. isBuffer: isBuffer,
  29600. isPrimitive: isPrimitive,
  29601. isFunction: isFunction,
  29602. isError: isError,
  29603. isDate: isDate,
  29604. isObject: isObject$1,
  29605. isRegExp: isRegExp,
  29606. isUndefined: isUndefined,
  29607. isSymbol: isSymbol,
  29608. isString: isString,
  29609. isNumber: isNumber,
  29610. isNullOrUndefined: isNullOrUndefined,
  29611. isNull: isNull,
  29612. isBoolean: isBoolean,
  29613. isArray: isArray$1,
  29614. inspect: inspect,
  29615. deprecate: deprecate,
  29616. format: format$1,
  29617. debuglog: debuglog,
  29618. promisify: promisify,
  29619. callbackify: callbackify,
  29620. };
  29621. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29622. __proto__: null,
  29623. _extend: _extend,
  29624. callbackify: callbackify,
  29625. debuglog: debuglog,
  29626. default: _polyfillNode_util,
  29627. deprecate: deprecate,
  29628. format: format$1,
  29629. inherits: inherits,
  29630. inspect: inspect,
  29631. isArray: isArray$1,
  29632. isBoolean: isBoolean,
  29633. isBuffer: isBuffer,
  29634. isDate: isDate,
  29635. isError: isError,
  29636. isFunction: isFunction,
  29637. isNull: isNull,
  29638. isNullOrUndefined: isNullOrUndefined,
  29639. isNumber: isNumber,
  29640. isObject: isObject$1,
  29641. isPrimitive: isPrimitive,
  29642. isRegExp: isRegExp,
  29643. isString: isString,
  29644. isSymbol: isSymbol,
  29645. isUndefined: isUndefined,
  29646. log: log,
  29647. promisify: promisify
  29648. });
  29649. // Copyright Joyent, Inc. and other Node contributors.
  29650. //
  29651. // Permission is hereby granted, free of charge, to any person obtaining a
  29652. // copy of this software and associated documentation files (the
  29653. // "Software"), to deal in the Software without restriction, including
  29654. // without limitation the rights to use, copy, modify, merge, publish,
  29655. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29656. // persons to whom the Software is furnished to do so, subject to the
  29657. // following conditions:
  29658. //
  29659. // The above copyright notice and this permission notice shall be included
  29660. // in all copies or substantial portions of the Software.
  29661. //
  29662. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29663. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29664. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29665. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29666. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29667. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29668. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29669. // If obj.hasOwnProperty has been overridden, then calling
  29670. // obj.hasOwnProperty(prop) will break.
  29671. // See: https://github.com/joyent/node/issues/1707
  29672. function hasOwnProperty$1(obj, prop) {
  29673. return Object.prototype.hasOwnProperty.call(obj, prop);
  29674. }
  29675. var isArray = Array.isArray || function (xs) {
  29676. return Object.prototype.toString.call(xs) === '[object Array]';
  29677. };
  29678. function stringifyPrimitive(v) {
  29679. switch (typeof v) {
  29680. case 'string':
  29681. return v;
  29682. case 'boolean':
  29683. return v ? 'true' : 'false';
  29684. case 'number':
  29685. return isFinite(v) ? v : '';
  29686. default:
  29687. return '';
  29688. }
  29689. }
  29690. function stringify (obj, sep, eq, name) {
  29691. sep = sep || '&';
  29692. eq = eq || '=';
  29693. if (obj === null) {
  29694. obj = undefined;
  29695. }
  29696. if (typeof obj === 'object') {
  29697. return map(objectKeys(obj), function(k) {
  29698. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29699. if (isArray(obj[k])) {
  29700. return map(obj[k], function(v) {
  29701. return ks + encodeURIComponent(stringifyPrimitive(v));
  29702. }).join(sep);
  29703. } else {
  29704. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29705. }
  29706. }).join(sep);
  29707. }
  29708. if (!name) return '';
  29709. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29710. encodeURIComponent(stringifyPrimitive(obj));
  29711. }
  29712. function map (xs, f) {
  29713. if (xs.map) return xs.map(f);
  29714. var res = [];
  29715. for (var i = 0; i < xs.length; i++) {
  29716. res.push(f(xs[i], i));
  29717. }
  29718. return res;
  29719. }
  29720. var objectKeys = Object.keys || function (obj) {
  29721. var res = [];
  29722. for (var key in obj) {
  29723. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29724. }
  29725. return res;
  29726. };
  29727. function parse$1(qs, sep, eq, options) {
  29728. sep = sep || '&';
  29729. eq = eq || '=';
  29730. var obj = {};
  29731. if (typeof qs !== 'string' || qs.length === 0) {
  29732. return obj;
  29733. }
  29734. var regexp = /\+/g;
  29735. qs = qs.split(sep);
  29736. var maxKeys = 1000;
  29737. if (options && typeof options.maxKeys === 'number') {
  29738. maxKeys = options.maxKeys;
  29739. }
  29740. var len = qs.length;
  29741. // maxKeys <= 0 means that we should not limit keys count
  29742. if (maxKeys > 0 && len > maxKeys) {
  29743. len = maxKeys;
  29744. }
  29745. for (var i = 0; i < len; ++i) {
  29746. var x = qs[i].replace(regexp, '%20'),
  29747. idx = x.indexOf(eq),
  29748. kstr, vstr, k, v;
  29749. if (idx >= 0) {
  29750. kstr = x.substr(0, idx);
  29751. vstr = x.substr(idx + 1);
  29752. } else {
  29753. kstr = x;
  29754. vstr = '';
  29755. }
  29756. k = decodeURIComponent(kstr);
  29757. v = decodeURIComponent(vstr);
  29758. if (!hasOwnProperty$1(obj, k)) {
  29759. obj[k] = v;
  29760. } else if (isArray(obj[k])) {
  29761. obj[k].push(v);
  29762. } else {
  29763. obj[k] = [obj[k], v];
  29764. }
  29765. }
  29766. return obj;
  29767. }
  29768. // WHATWG API
  29769. const URL$1 = global$1.URL;
  29770. const URLSearchParams = global$1.URLSearchParams;
  29771. var _polyfillNode_url = {
  29772. parse: urlParse,
  29773. resolve: urlResolve,
  29774. resolveObject: urlResolveObject,
  29775. fileURLToPath: urlFileURLToPath,
  29776. format: urlFormat,
  29777. Url: Url,
  29778. // WHATWG API
  29779. URL: URL$1,
  29780. URLSearchParams,
  29781. };
  29782. function Url() {
  29783. this.protocol = null;
  29784. this.slashes = null;
  29785. this.auth = null;
  29786. this.host = null;
  29787. this.port = null;
  29788. this.hostname = null;
  29789. this.hash = null;
  29790. this.search = null;
  29791. this.query = null;
  29792. this.pathname = null;
  29793. this.path = null;
  29794. this.href = null;
  29795. }
  29796. // Reference: RFC 3986, RFC 1808, RFC 2396
  29797. // define these here so at least they only have to be
  29798. // compiled once on the first module load.
  29799. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  29800. portPattern = /:[0-9]*$/,
  29801. // Special case for a simple path URL
  29802. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  29803. // RFC 2396: characters reserved for delimiting URLs.
  29804. // We actually just auto-escape these.
  29805. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  29806. // RFC 2396: characters not allowed for various reasons.
  29807. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  29808. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  29809. autoEscape = ['\''].concat(unwise),
  29810. // Characters that are never ever allowed in a hostname.
  29811. // Note that any invalid chars are also handled, but these
  29812. // are the ones that are *expected* to be seen, so we fast-path
  29813. // them.
  29814. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  29815. hostEndingChars = ['/', '?', '#'],
  29816. hostnameMaxLen = 255,
  29817. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  29818. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  29819. // protocols that can allow "unsafe" and "unwise" chars.
  29820. unsafeProtocol = {
  29821. 'javascript': true,
  29822. 'javascript:': true
  29823. },
  29824. // protocols that never have a hostname.
  29825. hostlessProtocol = {
  29826. 'javascript': true,
  29827. 'javascript:': true
  29828. },
  29829. // protocols that always contain a // bit.
  29830. slashedProtocol = {
  29831. 'http': true,
  29832. 'https': true,
  29833. 'ftp': true,
  29834. 'gopher': true,
  29835. 'file': true,
  29836. 'http:': true,
  29837. 'https:': true,
  29838. 'ftp:': true,
  29839. 'gopher:': true,
  29840. 'file:': true
  29841. };
  29842. function urlParse(url, parseQueryString, slashesDenoteHost) {
  29843. if (url && isObject$1(url) && url instanceof Url) return url;
  29844. var u = new Url;
  29845. u.parse(url, parseQueryString, slashesDenoteHost);
  29846. return u;
  29847. }
  29848. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  29849. return parse(this, url, parseQueryString, slashesDenoteHost);
  29850. };
  29851. function parse(self, url, parseQueryString, slashesDenoteHost) {
  29852. if (!isString(url)) {
  29853. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  29854. }
  29855. // Copy chrome, IE, opera backslash-handling behavior.
  29856. // Back slashes before the query string get converted to forward slashes
  29857. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  29858. var queryIndex = url.indexOf('?'),
  29859. splitter =
  29860. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  29861. uSplit = url.split(splitter),
  29862. slashRegex = /\\/g;
  29863. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  29864. url = uSplit.join(splitter);
  29865. var rest = url;
  29866. // trim before proceeding.
  29867. // This is to support parse stuff like " http://foo.com \n"
  29868. rest = rest.trim();
  29869. if (!slashesDenoteHost && url.split('#').length === 1) {
  29870. // Try fast path regexp
  29871. var simplePath = simplePathPattern.exec(rest);
  29872. if (simplePath) {
  29873. self.path = rest;
  29874. self.href = rest;
  29875. self.pathname = simplePath[1];
  29876. if (simplePath[2]) {
  29877. self.search = simplePath[2];
  29878. if (parseQueryString) {
  29879. self.query = parse$1(self.search.substr(1));
  29880. } else {
  29881. self.query = self.search.substr(1);
  29882. }
  29883. } else if (parseQueryString) {
  29884. self.search = '';
  29885. self.query = {};
  29886. }
  29887. return self;
  29888. }
  29889. }
  29890. var proto = protocolPattern.exec(rest);
  29891. if (proto) {
  29892. proto = proto[0];
  29893. var lowerProto = proto.toLowerCase();
  29894. self.protocol = lowerProto;
  29895. rest = rest.substr(proto.length);
  29896. }
  29897. // figure out if it's got a host
  29898. // user@server is *always* interpreted as a hostname, and url
  29899. // resolution will treat //foo/bar as host=foo,path=bar because that's
  29900. // how the browser resolves relative URLs.
  29901. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  29902. var slashes = rest.substr(0, 2) === '//';
  29903. if (slashes && !(proto && hostlessProtocol[proto])) {
  29904. rest = rest.substr(2);
  29905. self.slashes = true;
  29906. }
  29907. }
  29908. var i, hec, l, p;
  29909. if (!hostlessProtocol[proto] &&
  29910. (slashes || (proto && !slashedProtocol[proto]))) {
  29911. // there's a hostname.
  29912. // the first instance of /, ?, ;, or # ends the host.
  29913. //
  29914. // If there is an @ in the hostname, then non-host chars *are* allowed
  29915. // to the left of the last @ sign, unless some host-ending character
  29916. // comes *before* the @-sign.
  29917. // URLs are obnoxious.
  29918. //
  29919. // ex:
  29920. // http://a@b@c/ => user:a@b host:c
  29921. // http://a@b?@c => user:a host:c path:/?@c
  29922. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  29923. // Review our test case against browsers more comprehensively.
  29924. // find the first instance of any hostEndingChars
  29925. var hostEnd = -1;
  29926. for (i = 0; i < hostEndingChars.length; i++) {
  29927. hec = rest.indexOf(hostEndingChars[i]);
  29928. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29929. hostEnd = hec;
  29930. }
  29931. // at this point, either we have an explicit point where the
  29932. // auth portion cannot go past, or the last @ char is the decider.
  29933. var auth, atSign;
  29934. if (hostEnd === -1) {
  29935. // atSign can be anywhere.
  29936. atSign = rest.lastIndexOf('@');
  29937. } else {
  29938. // atSign must be in auth portion.
  29939. // http://a@b/c@d => host:b auth:a path:/c@d
  29940. atSign = rest.lastIndexOf('@', hostEnd);
  29941. }
  29942. // Now we have a portion which is definitely the auth.
  29943. // Pull that off.
  29944. if (atSign !== -1) {
  29945. auth = rest.slice(0, atSign);
  29946. rest = rest.slice(atSign + 1);
  29947. self.auth = decodeURIComponent(auth);
  29948. }
  29949. // the host is the remaining to the left of the first non-host char
  29950. hostEnd = -1;
  29951. for (i = 0; i < nonHostChars.length; i++) {
  29952. hec = rest.indexOf(nonHostChars[i]);
  29953. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29954. hostEnd = hec;
  29955. }
  29956. // if we still have not hit it, then the entire thing is a host.
  29957. if (hostEnd === -1)
  29958. hostEnd = rest.length;
  29959. self.host = rest.slice(0, hostEnd);
  29960. rest = rest.slice(hostEnd);
  29961. // pull out port.
  29962. parseHost(self);
  29963. // we've indicated that there is a hostname,
  29964. // so even if it's empty, it has to be present.
  29965. self.hostname = self.hostname || '';
  29966. // if hostname begins with [ and ends with ]
  29967. // assume that it's an IPv6 address.
  29968. var ipv6Hostname = self.hostname[0] === '[' &&
  29969. self.hostname[self.hostname.length - 1] === ']';
  29970. // validate a little.
  29971. if (!ipv6Hostname) {
  29972. var hostparts = self.hostname.split(/\./);
  29973. for (i = 0, l = hostparts.length; i < l; i++) {
  29974. var part = hostparts[i];
  29975. if (!part) continue;
  29976. if (!part.match(hostnamePartPattern)) {
  29977. var newpart = '';
  29978. for (var j = 0, k = part.length; j < k; j++) {
  29979. if (part.charCodeAt(j) > 127) {
  29980. // we replace non-ASCII char with a temporary placeholder
  29981. // we need this to make sure size of hostname is not
  29982. // broken by replacing non-ASCII by nothing
  29983. newpart += 'x';
  29984. } else {
  29985. newpart += part[j];
  29986. }
  29987. }
  29988. // we test again with ASCII char only
  29989. if (!newpart.match(hostnamePartPattern)) {
  29990. var validParts = hostparts.slice(0, i);
  29991. var notHost = hostparts.slice(i + 1);
  29992. var bit = part.match(hostnamePartStart);
  29993. if (bit) {
  29994. validParts.push(bit[1]);
  29995. notHost.unshift(bit[2]);
  29996. }
  29997. if (notHost.length) {
  29998. rest = '/' + notHost.join('.') + rest;
  29999. }
  30000. self.hostname = validParts.join('.');
  30001. break;
  30002. }
  30003. }
  30004. }
  30005. }
  30006. if (self.hostname.length > hostnameMaxLen) {
  30007. self.hostname = '';
  30008. } else {
  30009. // hostnames are always lower case.
  30010. self.hostname = self.hostname.toLowerCase();
  30011. }
  30012. if (!ipv6Hostname) {
  30013. // IDNA Support: Returns a punycoded representation of "domain".
  30014. // It only converts parts of the domain name that
  30015. // have non-ASCII characters, i.e. it doesn't matter if
  30016. // you call it with a domain that already is ASCII-only.
  30017. self.hostname = toASCII(self.hostname);
  30018. }
  30019. p = self.port ? ':' + self.port : '';
  30020. var h = self.hostname || '';
  30021. self.host = h + p;
  30022. self.href += self.host;
  30023. // strip [ and ] from the hostname
  30024. // the host field still retains them, though
  30025. if (ipv6Hostname) {
  30026. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  30027. if (rest[0] !== '/') {
  30028. rest = '/' + rest;
  30029. }
  30030. }
  30031. }
  30032. // now rest is set to the post-host stuff.
  30033. // chop off any delim chars.
  30034. if (!unsafeProtocol[lowerProto]) {
  30035. // First, make 100% sure that any "autoEscape" chars get
  30036. // escaped, even if encodeURIComponent doesn't think they
  30037. // need to be.
  30038. for (i = 0, l = autoEscape.length; i < l; i++) {
  30039. var ae = autoEscape[i];
  30040. if (rest.indexOf(ae) === -1)
  30041. continue;
  30042. var esc = encodeURIComponent(ae);
  30043. if (esc === ae) {
  30044. esc = escape(ae);
  30045. }
  30046. rest = rest.split(ae).join(esc);
  30047. }
  30048. }
  30049. // chop off from the tail first.
  30050. var hash = rest.indexOf('#');
  30051. if (hash !== -1) {
  30052. // got a fragment string.
  30053. self.hash = rest.substr(hash);
  30054. rest = rest.slice(0, hash);
  30055. }
  30056. var qm = rest.indexOf('?');
  30057. if (qm !== -1) {
  30058. self.search = rest.substr(qm);
  30059. self.query = rest.substr(qm + 1);
  30060. if (parseQueryString) {
  30061. self.query = parse$1(self.query);
  30062. }
  30063. rest = rest.slice(0, qm);
  30064. } else if (parseQueryString) {
  30065. // no query string, but parseQueryString still requested
  30066. self.search = '';
  30067. self.query = {};
  30068. }
  30069. if (rest) self.pathname = rest;
  30070. if (slashedProtocol[lowerProto] &&
  30071. self.hostname && !self.pathname) {
  30072. self.pathname = '/';
  30073. }
  30074. //to support http.request
  30075. if (self.pathname || self.search) {
  30076. p = self.pathname || '';
  30077. var s = self.search || '';
  30078. self.path = p + s;
  30079. }
  30080. // finally, reconstruct the href based on what has been validated.
  30081. self.href = format(self);
  30082. return self;
  30083. }
  30084. function urlFileURLToPath(path) {
  30085. if (typeof path === 'string')
  30086. path = new Url().parse(path);
  30087. else if (!(path instanceof Url))
  30088. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  30089. if (path.protocol !== 'file:')
  30090. throw new TypeError('The URL must be of scheme file');
  30091. return getPathFromURLPosix(path);
  30092. }
  30093. function getPathFromURLPosix(url) {
  30094. const pathname = url.pathname;
  30095. for (let n = 0; n < pathname.length; n++) {
  30096. if (pathname[n] === '%') {
  30097. const third = pathname.codePointAt(n + 2) | 0x20;
  30098. if (pathname[n + 1] === '2' && third === 102) {
  30099. throw new TypeError(
  30100. 'must not include encoded / characters'
  30101. );
  30102. }
  30103. }
  30104. }
  30105. return decodeURIComponent(pathname);
  30106. }
  30107. // format a parsed object into a url string
  30108. function urlFormat(obj) {
  30109. // ensure it's an object, and not a string url.
  30110. // If it's an obj, this is a no-op.
  30111. // this way, you can call url_format() on strings
  30112. // to clean up potentially wonky urls.
  30113. if (isString(obj)) obj = parse({}, obj);
  30114. return format(obj);
  30115. }
  30116. function format(self) {
  30117. var auth = self.auth || '';
  30118. if (auth) {
  30119. auth = encodeURIComponent(auth);
  30120. auth = auth.replace(/%3A/i, ':');
  30121. auth += '@';
  30122. }
  30123. var protocol = self.protocol || '',
  30124. pathname = self.pathname || '',
  30125. hash = self.hash || '',
  30126. host = false,
  30127. query = '';
  30128. if (self.host) {
  30129. host = auth + self.host;
  30130. } else if (self.hostname) {
  30131. host = auth + (self.hostname.indexOf(':') === -1 ?
  30132. self.hostname :
  30133. '[' + this.hostname + ']');
  30134. if (self.port) {
  30135. host += ':' + self.port;
  30136. }
  30137. }
  30138. if (self.query &&
  30139. isObject$1(self.query) &&
  30140. Object.keys(self.query).length) {
  30141. query = stringify(self.query);
  30142. }
  30143. var search = self.search || (query && ('?' + query)) || '';
  30144. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30145. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30146. // unless they had them to begin with.
  30147. if (self.slashes ||
  30148. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30149. host = '//' + (host || '');
  30150. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30151. } else if (!host) {
  30152. host = '';
  30153. }
  30154. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30155. if (search && search.charAt(0) !== '?') search = '?' + search;
  30156. pathname = pathname.replace(/[?#]/g, function(match) {
  30157. return encodeURIComponent(match);
  30158. });
  30159. search = search.replace('#', '%23');
  30160. return protocol + host + pathname + search + hash;
  30161. }
  30162. Url.prototype.format = function() {
  30163. return format(this);
  30164. };
  30165. function urlResolve(source, relative) {
  30166. return urlParse(source, false, true).resolve(relative);
  30167. }
  30168. Url.prototype.resolve = function(relative) {
  30169. return this.resolveObject(urlParse(relative, false, true)).format();
  30170. };
  30171. function urlResolveObject(source, relative) {
  30172. if (!source) return relative;
  30173. return urlParse(source, false, true).resolveObject(relative);
  30174. }
  30175. Url.prototype.resolveObject = function(relative) {
  30176. if (isString(relative)) {
  30177. var rel = new Url();
  30178. rel.parse(relative, false, true);
  30179. relative = rel;
  30180. }
  30181. var result = new Url();
  30182. var tkeys = Object.keys(this);
  30183. for (var tk = 0; tk < tkeys.length; tk++) {
  30184. var tkey = tkeys[tk];
  30185. result[tkey] = this[tkey];
  30186. }
  30187. // hash is always overridden, no matter what.
  30188. // even href="" will remove it.
  30189. result.hash = relative.hash;
  30190. // if the relative url is empty, then there's nothing left to do here.
  30191. if (relative.href === '') {
  30192. result.href = result.format();
  30193. return result;
  30194. }
  30195. // hrefs like //foo/bar always cut to the protocol.
  30196. if (relative.slashes && !relative.protocol) {
  30197. // take everything except the protocol from relative
  30198. var rkeys = Object.keys(relative);
  30199. for (var rk = 0; rk < rkeys.length; rk++) {
  30200. var rkey = rkeys[rk];
  30201. if (rkey !== 'protocol')
  30202. result[rkey] = relative[rkey];
  30203. }
  30204. //urlParse appends trailing / to urls like http://www.example.com
  30205. if (slashedProtocol[result.protocol] &&
  30206. result.hostname && !result.pathname) {
  30207. result.path = result.pathname = '/';
  30208. }
  30209. result.href = result.format();
  30210. return result;
  30211. }
  30212. var relPath;
  30213. if (relative.protocol && relative.protocol !== result.protocol) {
  30214. // if it's a known url protocol, then changing
  30215. // the protocol does weird things
  30216. // first, if it's not file:, then we MUST have a host,
  30217. // and if there was a path
  30218. // to begin with, then we MUST have a path.
  30219. // if it is file:, then the host is dropped,
  30220. // because that's known to be hostless.
  30221. // anything else is assumed to be absolute.
  30222. if (!slashedProtocol[relative.protocol]) {
  30223. var keys = Object.keys(relative);
  30224. for (var v = 0; v < keys.length; v++) {
  30225. var k = keys[v];
  30226. result[k] = relative[k];
  30227. }
  30228. result.href = result.format();
  30229. return result;
  30230. }
  30231. result.protocol = relative.protocol;
  30232. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30233. relPath = (relative.pathname || '').split('/');
  30234. while (relPath.length && !(relative.host = relPath.shift()));
  30235. if (!relative.host) relative.host = '';
  30236. if (!relative.hostname) relative.hostname = '';
  30237. if (relPath[0] !== '') relPath.unshift('');
  30238. if (relPath.length < 2) relPath.unshift('');
  30239. result.pathname = relPath.join('/');
  30240. } else {
  30241. result.pathname = relative.pathname;
  30242. }
  30243. result.search = relative.search;
  30244. result.query = relative.query;
  30245. result.host = relative.host || '';
  30246. result.auth = relative.auth;
  30247. result.hostname = relative.hostname || relative.host;
  30248. result.port = relative.port;
  30249. // to support http.request
  30250. if (result.pathname || result.search) {
  30251. var p = result.pathname || '';
  30252. var s = result.search || '';
  30253. result.path = p + s;
  30254. }
  30255. result.slashes = result.slashes || relative.slashes;
  30256. result.href = result.format();
  30257. return result;
  30258. }
  30259. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30260. isRelAbs = (
  30261. relative.host ||
  30262. relative.pathname && relative.pathname.charAt(0) === '/'
  30263. ),
  30264. mustEndAbs = (isRelAbs || isSourceAbs ||
  30265. (result.host && relative.pathname)),
  30266. removeAllDots = mustEndAbs,
  30267. srcPath = result.pathname && result.pathname.split('/') || [],
  30268. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30269. relPath = relative.pathname && relative.pathname.split('/') || [];
  30270. // if the url is a non-slashed url, then relative
  30271. // links like ../.. should be able
  30272. // to crawl up to the hostname, as well. This is strange.
  30273. // result.protocol has already been set by now.
  30274. // Later on, put the first path part into the host field.
  30275. if (psychotic) {
  30276. result.hostname = '';
  30277. result.port = null;
  30278. if (result.host) {
  30279. if (srcPath[0] === '') srcPath[0] = result.host;
  30280. else srcPath.unshift(result.host);
  30281. }
  30282. result.host = '';
  30283. if (relative.protocol) {
  30284. relative.hostname = null;
  30285. relative.port = null;
  30286. if (relative.host) {
  30287. if (relPath[0] === '') relPath[0] = relative.host;
  30288. else relPath.unshift(relative.host);
  30289. }
  30290. relative.host = null;
  30291. }
  30292. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30293. }
  30294. var authInHost;
  30295. if (isRelAbs) {
  30296. // it's absolute.
  30297. result.host = (relative.host || relative.host === '') ?
  30298. relative.host : result.host;
  30299. result.hostname = (relative.hostname || relative.hostname === '') ?
  30300. relative.hostname : result.hostname;
  30301. result.search = relative.search;
  30302. result.query = relative.query;
  30303. srcPath = relPath;
  30304. // fall through to the dot-handling below.
  30305. } else if (relPath.length) {
  30306. // it's relative
  30307. // throw away the existing file, and take the new path instead.
  30308. if (!srcPath) srcPath = [];
  30309. srcPath.pop();
  30310. srcPath = srcPath.concat(relPath);
  30311. result.search = relative.search;
  30312. result.query = relative.query;
  30313. } else if (!isNullOrUndefined(relative.search)) {
  30314. // just pull out the search.
  30315. // like href='?foo'.
  30316. // Put this after the other two cases because it simplifies the booleans
  30317. if (psychotic) {
  30318. result.hostname = result.host = srcPath.shift();
  30319. //occationaly the auth can get stuck only in host
  30320. //this especially happens in cases like
  30321. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30322. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30323. result.host.split('@') : false;
  30324. if (authInHost) {
  30325. result.auth = authInHost.shift();
  30326. result.host = result.hostname = authInHost.shift();
  30327. }
  30328. }
  30329. result.search = relative.search;
  30330. result.query = relative.query;
  30331. //to support http.request
  30332. if (!isNull(result.pathname) || !isNull(result.search)) {
  30333. result.path = (result.pathname ? result.pathname : '') +
  30334. (result.search ? result.search : '');
  30335. }
  30336. result.href = result.format();
  30337. return result;
  30338. }
  30339. if (!srcPath.length) {
  30340. // no path at all. easy.
  30341. // we've already handled the other stuff above.
  30342. result.pathname = null;
  30343. //to support http.request
  30344. if (result.search) {
  30345. result.path = '/' + result.search;
  30346. } else {
  30347. result.path = null;
  30348. }
  30349. result.href = result.format();
  30350. return result;
  30351. }
  30352. // if a url ENDs in . or .., then it must get a trailing slash.
  30353. // however, if it ends in anything else non-slashy,
  30354. // then it must NOT get a trailing slash.
  30355. var last = srcPath.slice(-1)[0];
  30356. var hasTrailingSlash = (
  30357. (result.host || relative.host || srcPath.length > 1) &&
  30358. (last === '.' || last === '..') || last === '');
  30359. // strip single dots, resolve double dots to parent dir
  30360. // if the path tries to go above the root, `up` ends up > 0
  30361. var up = 0;
  30362. for (var i = srcPath.length; i >= 0; i--) {
  30363. last = srcPath[i];
  30364. if (last === '.') {
  30365. srcPath.splice(i, 1);
  30366. } else if (last === '..') {
  30367. srcPath.splice(i, 1);
  30368. up++;
  30369. } else if (up) {
  30370. srcPath.splice(i, 1);
  30371. up--;
  30372. }
  30373. }
  30374. // if the path is allowed to go above the root, restore leading ..s
  30375. if (!mustEndAbs && !removeAllDots) {
  30376. for (; up--; up) {
  30377. srcPath.unshift('..');
  30378. }
  30379. }
  30380. if (mustEndAbs && srcPath[0] !== '' &&
  30381. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30382. srcPath.unshift('');
  30383. }
  30384. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30385. srcPath.push('');
  30386. }
  30387. var isAbsolute = srcPath[0] === '' ||
  30388. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30389. // put the host back
  30390. if (psychotic) {
  30391. result.hostname = result.host = isAbsolute ? '' :
  30392. srcPath.length ? srcPath.shift() : '';
  30393. //occationaly the auth can get stuck only in host
  30394. //this especially happens in cases like
  30395. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30396. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30397. result.host.split('@') : false;
  30398. if (authInHost) {
  30399. result.auth = authInHost.shift();
  30400. result.host = result.hostname = authInHost.shift();
  30401. }
  30402. }
  30403. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30404. if (mustEndAbs && !isAbsolute) {
  30405. srcPath.unshift('');
  30406. }
  30407. if (!srcPath.length) {
  30408. result.pathname = null;
  30409. result.path = null;
  30410. } else {
  30411. result.pathname = srcPath.join('/');
  30412. }
  30413. //to support request.http
  30414. if (!isNull(result.pathname) || !isNull(result.search)) {
  30415. result.path = (result.pathname ? result.pathname : '') +
  30416. (result.search ? result.search : '');
  30417. }
  30418. result.auth = relative.auth || result.auth;
  30419. result.slashes = result.slashes || relative.slashes;
  30420. result.href = result.format();
  30421. return result;
  30422. };
  30423. Url.prototype.parseHost = function() {
  30424. return parseHost(this);
  30425. };
  30426. function parseHost(self) {
  30427. var host = self.host;
  30428. var port = portPattern.exec(host);
  30429. if (port) {
  30430. port = port[0];
  30431. if (port !== ':') {
  30432. self.port = port.substr(1);
  30433. }
  30434. host = host.substr(0, host.length - port.length);
  30435. }
  30436. if (host) self.hostname = host;
  30437. }
  30438. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30439. __proto__: null,
  30440. URL: URL$1,
  30441. URLSearchParams: URLSearchParams,
  30442. Url: Url,
  30443. default: _polyfillNode_url,
  30444. fileURLToPath: urlFileURLToPath,
  30445. format: urlFormat,
  30446. parse: urlParse,
  30447. resolve: urlResolve,
  30448. resolveObject: urlResolveObject
  30449. });
  30450. function isRelativeUrl(url) {
  30451. const firstChar = url.charAt(0);
  30452. return firstChar === "." || firstChar === "~" || firstChar === "@";
  30453. }
  30454. const externalRE = /^(https?:)?\/\//;
  30455. function isExternalUrl(url) {
  30456. return externalRE.test(url);
  30457. }
  30458. const dataUrlRE = /^\s*data:/i;
  30459. function isDataUrl(url) {
  30460. return dataUrlRE.test(url);
  30461. }
  30462. function parseUrl(url) {
  30463. const firstChar = url.charAt(0);
  30464. if (firstChar === "~") {
  30465. const secondChar = url.charAt(1);
  30466. url = url.slice(secondChar === "/" ? 2 : 1);
  30467. }
  30468. return parseUriParts(url);
  30469. }
  30470. function parseUriParts(urlString) {
  30471. return urlParse(isString$1(urlString) ? urlString : "", false, true);
  30472. }
  30473. var __defProp$9 = Object.defineProperty;
  30474. var __defProps$8 = Object.defineProperties;
  30475. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  30476. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30477. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30478. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30479. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30480. var __spreadValues$9 = (a, b) => {
  30481. for (var prop in b || (b = {}))
  30482. if (__hasOwnProp$9.call(b, prop))
  30483. __defNormalProp$9(a, prop, b[prop]);
  30484. if (__getOwnPropSymbols$9)
  30485. for (var prop of __getOwnPropSymbols$9(b)) {
  30486. if (__propIsEnum$9.call(b, prop))
  30487. __defNormalProp$9(a, prop, b[prop]);
  30488. }
  30489. return a;
  30490. };
  30491. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  30492. const defaultAssetUrlOptions = {
  30493. base: null,
  30494. includeAbsolute: false,
  30495. tags: {
  30496. video: ["src", "poster"],
  30497. source: ["src"],
  30498. img: ["src"],
  30499. image: ["xlink:href", "href"],
  30500. use: ["xlink:href", "href"]
  30501. }
  30502. };
  30503. const normalizeOptions = (options) => {
  30504. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30505. return __spreadProps$8(__spreadValues$9({}, defaultAssetUrlOptions), {
  30506. tags: options
  30507. });
  30508. }
  30509. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30510. };
  30511. const createAssetUrlTransformWithOptions = (options) => {
  30512. return (node, context) => transformAssetUrl(node, context, options);
  30513. };
  30514. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30515. if (node.type === 1) {
  30516. if (!node.props.length) {
  30517. return;
  30518. }
  30519. const tags = options.tags || defaultAssetUrlOptions.tags;
  30520. const attrs = tags[node.tag];
  30521. const wildCardAttrs = tags["*"];
  30522. if (!attrs && !wildCardAttrs) {
  30523. return;
  30524. }
  30525. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30526. node.props.forEach((attr, index) => {
  30527. if (attr.type !== 6 || !assetAttrs.includes(attr.name) || !attr.value || isExternalUrl(attr.value.content) || isDataUrl(attr.value.content) || attr.value.content[0] === "#" || !options.includeAbsolute && !isRelativeUrl(attr.value.content)) {
  30528. return;
  30529. }
  30530. const url = parseUrl(attr.value.content);
  30531. if (options.base && attr.value.content[0] === ".") {
  30532. const base = parseUrl(options.base);
  30533. const protocol = base.protocol || "";
  30534. const host = base.host ? protocol + "//" + base.host : "";
  30535. const basePath = base.path || "/";
  30536. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30537. return;
  30538. }
  30539. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30540. node.props[index] = {
  30541. type: 7,
  30542. name: "bind",
  30543. arg: createSimpleExpression(attr.name, true, attr.loc),
  30544. exp,
  30545. modifiers: [],
  30546. loc: attr.loc
  30547. };
  30548. });
  30549. }
  30550. };
  30551. function getImportsExpressionExp(path2, hash, loc, context) {
  30552. if (path2) {
  30553. let name;
  30554. let exp;
  30555. const existingIndex = context.imports.findIndex((i) => i.path === path2);
  30556. if (existingIndex > -1) {
  30557. name = `_imports_${existingIndex}`;
  30558. exp = context.imports[existingIndex].exp;
  30559. } else {
  30560. name = `_imports_${context.imports.length}`;
  30561. exp = createSimpleExpression(
  30562. name,
  30563. false,
  30564. loc,
  30565. 3
  30566. );
  30567. context.imports.push({
  30568. exp,
  30569. path: decodeURIComponent(path2)
  30570. });
  30571. }
  30572. if (!hash) {
  30573. return exp;
  30574. }
  30575. const hashExp = `${name} + '${hash}'`;
  30576. const finalExp = createSimpleExpression(
  30577. hashExp,
  30578. false,
  30579. loc,
  30580. 3
  30581. );
  30582. if (!context.hoistStatic) {
  30583. return finalExp;
  30584. }
  30585. const existingHoistIndex = context.hoists.findIndex((h) => {
  30586. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30587. });
  30588. if (existingHoistIndex > -1) {
  30589. return createSimpleExpression(
  30590. `_hoisted_${existingHoistIndex + 1}`,
  30591. false,
  30592. loc,
  30593. 3
  30594. );
  30595. }
  30596. return context.hoist(finalExp);
  30597. } else {
  30598. return createSimpleExpression(`''`, false, loc, 3);
  30599. }
  30600. }
  30601. const srcsetTags = ["img", "source"];
  30602. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30603. const createSrcsetTransformWithOptions = (options) => {
  30604. return (node, context) => transformSrcset(node, context, options);
  30605. };
  30606. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30607. if (node.type === 1) {
  30608. if (srcsetTags.includes(node.tag) && node.props.length) {
  30609. node.props.forEach((attr, index) => {
  30610. if (attr.name === "srcset" && attr.type === 6) {
  30611. if (!attr.value) return;
  30612. const value = attr.value.content;
  30613. if (!value) return;
  30614. const imageCandidates = value.split(",").map((s) => {
  30615. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30616. return { url, descriptor };
  30617. });
  30618. for (let i = 0; i < imageCandidates.length; i++) {
  30619. const { url } = imageCandidates[i];
  30620. if (isDataUrl(url)) {
  30621. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30622. imageCandidates.splice(i, 1);
  30623. }
  30624. }
  30625. const shouldProcessUrl = (url) => {
  30626. return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30627. };
  30628. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30629. return;
  30630. }
  30631. if (options.base) {
  30632. const base = options.base;
  30633. const set = [];
  30634. let needImportTransform = false;
  30635. imageCandidates.forEach((candidate) => {
  30636. let { url, descriptor } = candidate;
  30637. descriptor = descriptor ? ` ${descriptor}` : ``;
  30638. if (url[0] === ".") {
  30639. candidate.url = (path.posix || path).join(base, url);
  30640. set.push(candidate.url + descriptor);
  30641. } else if (shouldProcessUrl(url)) {
  30642. needImportTransform = true;
  30643. } else {
  30644. set.push(url + descriptor);
  30645. }
  30646. });
  30647. if (!needImportTransform) {
  30648. attr.value.content = set.join(", ");
  30649. return;
  30650. }
  30651. }
  30652. const compoundExpression = createCompoundExpression([], attr.loc);
  30653. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30654. if (shouldProcessUrl(url)) {
  30655. const { path: path2 } = parseUrl(url);
  30656. let exp2;
  30657. if (path2) {
  30658. const existingImportsIndex = context.imports.findIndex(
  30659. (i) => i.path === path2
  30660. );
  30661. if (existingImportsIndex > -1) {
  30662. exp2 = createSimpleExpression(
  30663. `_imports_${existingImportsIndex}`,
  30664. false,
  30665. attr.loc,
  30666. 3
  30667. );
  30668. } else {
  30669. exp2 = createSimpleExpression(
  30670. `_imports_${context.imports.length}`,
  30671. false,
  30672. attr.loc,
  30673. 3
  30674. );
  30675. context.imports.push({ exp: exp2, path: path2 });
  30676. }
  30677. compoundExpression.children.push(exp2);
  30678. }
  30679. } else {
  30680. const exp2 = createSimpleExpression(
  30681. `"${url}"`,
  30682. false,
  30683. attr.loc,
  30684. 3
  30685. );
  30686. compoundExpression.children.push(exp2);
  30687. }
  30688. const isNotLast = imageCandidates.length - 1 > index2;
  30689. if (descriptor && isNotLast) {
  30690. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30691. } else if (descriptor) {
  30692. compoundExpression.children.push(` + ' ${descriptor}'`);
  30693. } else if (isNotLast) {
  30694. compoundExpression.children.push(` + ', ' + `);
  30695. }
  30696. });
  30697. let exp = compoundExpression;
  30698. if (context.hoistStatic) {
  30699. exp = context.hoist(compoundExpression);
  30700. exp.constType = 3;
  30701. }
  30702. node.props[index] = {
  30703. type: 7,
  30704. name: "bind",
  30705. arg: createSimpleExpression("srcset", true, attr.loc),
  30706. exp,
  30707. modifiers: [],
  30708. loc: attr.loc
  30709. };
  30710. }
  30711. });
  30712. }
  30713. }
  30714. };
  30715. const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
  30716. const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
  30717. const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
  30718. const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
  30719. const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
  30720. const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
  30721. const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
  30722. const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
  30723. const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`);
  30724. const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`);
  30725. const SSR_RENDER_LIST = Symbol(`ssrRenderList`);
  30726. const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(
  30727. `ssrIncludeBooleanAttr`
  30728. );
  30729. const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`);
  30730. const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`);
  30731. const SSR_RENDER_DYNAMIC_MODEL = Symbol(
  30732. `ssrRenderDynamicModel`
  30733. );
  30734. const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(
  30735. `ssrGetDynamicModelProps`
  30736. );
  30737. const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
  30738. const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
  30739. const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`);
  30740. const ssrHelpers = {
  30741. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30742. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30743. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30744. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30745. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30746. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30747. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30748. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30749. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30750. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30751. [SSR_RENDER_LIST]: `ssrRenderList`,
  30752. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30753. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  30754. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  30755. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  30756. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  30757. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  30758. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  30759. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  30760. };
  30761. registerRuntimeHelpers(ssrHelpers);
  30762. const ssrTransformIf = createStructuralDirectiveTransform(
  30763. /^(if|else|else-if)$/,
  30764. processIf
  30765. );
  30766. function ssrProcessIf(node, context, disableNestedFragments = false, disableComment = false) {
  30767. const [rootBranch] = node.branches;
  30768. const ifStatement = createIfStatement(
  30769. rootBranch.condition,
  30770. processIfBranch(rootBranch, context, disableNestedFragments)
  30771. );
  30772. context.pushStatement(ifStatement);
  30773. let currentIf = ifStatement;
  30774. for (let i = 1; i < node.branches.length; i++) {
  30775. const branch = node.branches[i];
  30776. const branchBlockStatement = processIfBranch(
  30777. branch,
  30778. context,
  30779. disableNestedFragments
  30780. );
  30781. if (branch.condition) {
  30782. currentIf = currentIf.alternate = createIfStatement(
  30783. branch.condition,
  30784. branchBlockStatement
  30785. );
  30786. } else {
  30787. currentIf.alternate = branchBlockStatement;
  30788. }
  30789. }
  30790. if (!currentIf.alternate && !disableComment) {
  30791. currentIf.alternate = createBlockStatement([
  30792. createCallExpression(`_push`, ["`<!---->`"])
  30793. ]);
  30794. }
  30795. }
  30796. function processIfBranch(branch, context, disableNestedFragments = false) {
  30797. const { children } = branch;
  30798. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  30799. !(children.length === 1 && children[0].type === 11);
  30800. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  30801. }
  30802. const ssrTransformFor = createStructuralDirectiveTransform("for", processFor);
  30803. function ssrProcessFor(node, context, disableNestedFragments = false) {
  30804. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  30805. const renderLoop = createFunctionExpression(
  30806. createForLoopParams(node.parseResult)
  30807. );
  30808. renderLoop.body = processChildrenAsStatement(
  30809. node,
  30810. context,
  30811. needFragmentWrapper
  30812. );
  30813. if (!disableNestedFragments) {
  30814. context.pushStringPart(`<!--[-->`);
  30815. }
  30816. context.pushStatement(
  30817. createCallExpression(context.helper(SSR_RENDER_LIST), [
  30818. node.source,
  30819. renderLoop
  30820. ])
  30821. );
  30822. if (!disableNestedFragments) {
  30823. context.pushStringPart(`<!--]-->`);
  30824. }
  30825. }
  30826. const ssrTransformSlotOutlet = (node, context) => {
  30827. if (isSlotOutlet(node)) {
  30828. const { slotName, slotProps } = processSlotOutlet(node, context);
  30829. const args = [
  30830. `_ctx.$slots`,
  30831. slotName,
  30832. slotProps || `{}`,
  30833. // fallback content placeholder. will be replaced in the process phase
  30834. `null`,
  30835. `_push`,
  30836. `_parent`
  30837. ];
  30838. if (context.scopeId && context.slotted !== false) {
  30839. args.push(`"${context.scopeId}-s"`);
  30840. }
  30841. let method = SSR_RENDER_SLOT;
  30842. let parent = context.parent;
  30843. if (parent) {
  30844. const children = parent.children;
  30845. if (parent.type === 10) {
  30846. parent = context.grandParent;
  30847. }
  30848. let componentType;
  30849. if (parent.type === 1 && parent.tagType === 1 && ((componentType = resolveComponentType(parent, context, true)) === TRANSITION || componentType === TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) {
  30850. method = SSR_RENDER_SLOT_INNER;
  30851. if (!(context.scopeId && context.slotted !== false)) {
  30852. args.push("null");
  30853. }
  30854. args.push("true");
  30855. }
  30856. }
  30857. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  30858. }
  30859. };
  30860. function ssrProcessSlotOutlet(node, context) {
  30861. const renderCall = node.ssrCodegenNode;
  30862. if (node.children.length) {
  30863. const fallbackRenderFn = createFunctionExpression([]);
  30864. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  30865. renderCall.arguments[3] = fallbackRenderFn;
  30866. }
  30867. if (context.withSlotScopeId) {
  30868. const slotScopeId = renderCall.arguments[6];
  30869. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  30870. }
  30871. context.pushStatement(node.ssrCodegenNode);
  30872. }
  30873. function createSSRCompilerError(code, loc) {
  30874. return createCompilerError(code, loc, SSRErrorMessages);
  30875. }
  30876. const SSRErrorMessages = {
  30877. [65]: `Unsafe attribute name for SSR.`,
  30878. [66]: `Missing the 'to' prop on teleport element.`,
  30879. [67]: `Invalid AST node during SSR transform.`
  30880. };
  30881. function ssrProcessTeleport(node, context) {
  30882. const targetProp = findProp(node, "to");
  30883. if (!targetProp) {
  30884. context.onError(
  30885. createSSRCompilerError(66, node.loc)
  30886. );
  30887. return;
  30888. }
  30889. let target;
  30890. if (targetProp.type === 6) {
  30891. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  30892. } else {
  30893. target = targetProp.exp;
  30894. }
  30895. if (!target) {
  30896. context.onError(
  30897. createSSRCompilerError(
  30898. 66,
  30899. targetProp.loc
  30900. )
  30901. );
  30902. return;
  30903. }
  30904. const disabledProp = findProp(
  30905. node,
  30906. "disabled",
  30907. false,
  30908. true
  30909. /* allow empty */
  30910. );
  30911. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  30912. const contentRenderFn = createFunctionExpression(
  30913. [`_push`],
  30914. void 0,
  30915. // Body is added later
  30916. true,
  30917. // newline
  30918. false,
  30919. // isSlot
  30920. node.loc
  30921. );
  30922. contentRenderFn.body = processChildrenAsStatement(node, context);
  30923. context.pushStatement(
  30924. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  30925. `_push`,
  30926. contentRenderFn,
  30927. target,
  30928. disabled,
  30929. `_parent`
  30930. ])
  30931. );
  30932. }
  30933. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  30934. function ssrTransformSuspense(node, context) {
  30935. return () => {
  30936. if (node.children.length) {
  30937. const wipEntry = {
  30938. slotsExp: null,
  30939. // to be immediately set
  30940. wipSlots: []
  30941. };
  30942. wipMap$3.set(node, wipEntry);
  30943. wipEntry.slotsExp = buildSlots(
  30944. node,
  30945. context,
  30946. (_props, _vForExp, children, loc) => {
  30947. const fn = createFunctionExpression(
  30948. [],
  30949. void 0,
  30950. // no return, assign body later
  30951. true,
  30952. // newline
  30953. false,
  30954. // suspense slots are not treated as normal slots
  30955. loc
  30956. );
  30957. wipEntry.wipSlots.push({
  30958. fn,
  30959. children
  30960. });
  30961. return fn;
  30962. }
  30963. ).slots;
  30964. }
  30965. };
  30966. }
  30967. function ssrProcessSuspense(node, context) {
  30968. const wipEntry = wipMap$3.get(node);
  30969. if (!wipEntry) {
  30970. return;
  30971. }
  30972. const { slotsExp, wipSlots } = wipEntry;
  30973. for (let i = 0; i < wipSlots.length; i++) {
  30974. const slot = wipSlots[i];
  30975. slot.fn.body = processChildrenAsStatement(slot, context);
  30976. }
  30977. context.pushStatement(
  30978. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  30979. `_push`,
  30980. slotsExp
  30981. ])
  30982. );
  30983. }
  30984. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  30985. const ssrTransformElement = (node, context) => {
  30986. if (node.type !== 1 || node.tagType !== 0) {
  30987. return;
  30988. }
  30989. return function ssrPostTransformElement() {
  30990. const openTag = [`<${node.tag}`];
  30991. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  30992. const hasDynamicVBind = hasDynamicKeyVBind(node);
  30993. const hasCustomDir = node.props.some(
  30994. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  30995. );
  30996. const needMergeProps = hasDynamicVBind || hasCustomDir;
  30997. if (needMergeProps) {
  30998. const { props, directives } = buildProps(
  30999. node,
  31000. context,
  31001. node.props,
  31002. false,
  31003. false,
  31004. true
  31005. );
  31006. if (props || directives.length) {
  31007. const mergedProps = buildSSRProps(props, directives, context);
  31008. const propsExp = createCallExpression(
  31009. context.helper(SSR_RENDER_ATTRS),
  31010. [mergedProps]
  31011. );
  31012. if (node.tag === "textarea") {
  31013. const existingText = node.children[0];
  31014. if (!existingText || existingText.type !== 5) {
  31015. const tempId = `_temp${context.temps++}`;
  31016. propsExp.arguments = [
  31017. createAssignmentExpression(
  31018. createSimpleExpression(tempId, false),
  31019. mergedProps
  31020. )
  31021. ];
  31022. rawChildrenMap.set(
  31023. node,
  31024. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31025. createConditionalExpression(
  31026. createSimpleExpression(`"value" in ${tempId}`, false),
  31027. createSimpleExpression(`${tempId}.value`, false),
  31028. createSimpleExpression(
  31029. existingText ? existingText.content : ``,
  31030. true
  31031. ),
  31032. false
  31033. )
  31034. ])
  31035. );
  31036. }
  31037. } else if (node.tag === "input") {
  31038. const vModel = findVModel(node);
  31039. if (vModel) {
  31040. const tempId = `_temp${context.temps++}`;
  31041. const tempExp = createSimpleExpression(tempId, false);
  31042. propsExp.arguments = [
  31043. createSequenceExpression([
  31044. createAssignmentExpression(tempExp, mergedProps),
  31045. createCallExpression(context.helper(MERGE_PROPS), [
  31046. tempExp,
  31047. createCallExpression(
  31048. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  31049. [
  31050. tempExp,
  31051. // existing props
  31052. vModel.exp
  31053. // model
  31054. ]
  31055. )
  31056. ])
  31057. ])
  31058. ];
  31059. }
  31060. } else if (directives.length && !node.children.length) {
  31061. const vText = findDir(node, "text");
  31062. if (!vText) {
  31063. const tempId = `_temp${context.temps++}`;
  31064. propsExp.arguments = [
  31065. createAssignmentExpression(
  31066. createSimpleExpression(tempId, false),
  31067. mergedProps
  31068. )
  31069. ];
  31070. rawChildrenMap.set(
  31071. node,
  31072. createConditionalExpression(
  31073. createSimpleExpression(`"textContent" in ${tempId}`, false),
  31074. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31075. createSimpleExpression(`${tempId}.textContent`, false)
  31076. ]),
  31077. createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
  31078. false
  31079. )
  31080. );
  31081. }
  31082. }
  31083. if (needTagForRuntime) {
  31084. propsExp.arguments.push(`"${node.tag}"`);
  31085. }
  31086. openTag.push(propsExp);
  31087. }
  31088. }
  31089. let dynamicClassBinding = void 0;
  31090. let staticClassBinding = void 0;
  31091. let dynamicStyleBinding = void 0;
  31092. for (let i = 0; i < node.props.length; i++) {
  31093. const prop = node.props[i];
  31094. if (node.tag === "input" && isTrueFalseValue(prop)) {
  31095. continue;
  31096. }
  31097. if (prop.type === 7) {
  31098. if (prop.name === "html" && prop.exp) {
  31099. rawChildrenMap.set(
  31100. node,
  31101. createCompoundExpression([`(`, prop.exp, `) ?? ''`])
  31102. );
  31103. } else if (prop.name === "text" && prop.exp) {
  31104. node.children = [createInterpolation(prop.exp, prop.loc)];
  31105. } else if (prop.name === "slot") {
  31106. context.onError(
  31107. createCompilerError(40, prop.loc)
  31108. );
  31109. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  31110. if (!needMergeProps) {
  31111. node.children = [createInterpolation(prop.exp, prop.loc)];
  31112. }
  31113. } else if (!needMergeProps && prop.name !== "on") {
  31114. const directiveTransform = context.directiveTransforms[prop.name];
  31115. if (directiveTransform) {
  31116. const { props, ssrTagParts } = directiveTransform(
  31117. prop,
  31118. node,
  31119. context
  31120. );
  31121. if (ssrTagParts) {
  31122. openTag.push(...ssrTagParts);
  31123. }
  31124. for (let j = 0; j < props.length; j++) {
  31125. const { key, value } = props[j];
  31126. if (isStaticExp(key)) {
  31127. let attrName = key.content;
  31128. if (attrName === "key" || attrName === "ref") {
  31129. continue;
  31130. }
  31131. if (attrName === "class") {
  31132. openTag.push(
  31133. ` class="`,
  31134. dynamicClassBinding = createCallExpression(
  31135. context.helper(SSR_RENDER_CLASS),
  31136. [value]
  31137. ),
  31138. `"`
  31139. );
  31140. } else if (attrName === "style") {
  31141. if (dynamicStyleBinding) {
  31142. mergeCall(dynamicStyleBinding, value);
  31143. } else {
  31144. openTag.push(
  31145. ` style="`,
  31146. dynamicStyleBinding = createCallExpression(
  31147. context.helper(SSR_RENDER_STYLE),
  31148. [value]
  31149. ),
  31150. `"`
  31151. );
  31152. }
  31153. } else {
  31154. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31155. if (isBooleanAttr(attrName)) {
  31156. openTag.push(
  31157. createConditionalExpression(
  31158. createCallExpression(
  31159. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31160. [value]
  31161. ),
  31162. createSimpleExpression(" " + attrName, true),
  31163. createSimpleExpression("", true),
  31164. false
  31165. )
  31166. );
  31167. } else if (isSSRSafeAttrName(attrName)) {
  31168. openTag.push(
  31169. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31170. key,
  31171. value
  31172. ])
  31173. );
  31174. } else {
  31175. context.onError(
  31176. createSSRCompilerError(
  31177. 65,
  31178. key.loc
  31179. )
  31180. );
  31181. }
  31182. }
  31183. } else {
  31184. const args = [key, value];
  31185. if (needTagForRuntime) {
  31186. args.push(`"${node.tag}"`);
  31187. }
  31188. openTag.push(
  31189. createCallExpression(
  31190. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31191. args
  31192. )
  31193. );
  31194. }
  31195. }
  31196. }
  31197. }
  31198. } else {
  31199. const name = prop.name;
  31200. if (node.tag === "textarea" && name === "value" && prop.value) {
  31201. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31202. } else if (!needMergeProps) {
  31203. if (name === "key" || name === "ref") {
  31204. continue;
  31205. }
  31206. if (name === "class" && prop.value) {
  31207. staticClassBinding = JSON.stringify(prop.value.content);
  31208. }
  31209. openTag.push(
  31210. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31211. );
  31212. }
  31213. }
  31214. }
  31215. if (dynamicClassBinding && staticClassBinding) {
  31216. mergeCall(dynamicClassBinding, staticClassBinding);
  31217. removeStaticBinding(openTag, "class");
  31218. }
  31219. if (context.scopeId) {
  31220. openTag.push(` ${context.scopeId}`);
  31221. }
  31222. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31223. };
  31224. };
  31225. function buildSSRProps(props, directives, context) {
  31226. let mergePropsArgs = [];
  31227. if (props) {
  31228. if (props.type === 14) {
  31229. mergePropsArgs = props.arguments;
  31230. } else {
  31231. mergePropsArgs.push(props);
  31232. }
  31233. }
  31234. if (directives.length) {
  31235. for (const dir of directives) {
  31236. mergePropsArgs.push(
  31237. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31238. `_ctx`,
  31239. ...buildDirectiveArgs(dir, context).elements
  31240. ])
  31241. );
  31242. }
  31243. }
  31244. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31245. }
  31246. function isTrueFalseValue(prop) {
  31247. if (prop.type === 7) {
  31248. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31249. } else {
  31250. return prop.name === "true-value" || prop.name === "false-value";
  31251. }
  31252. }
  31253. function isTextareaWithValue(node, prop) {
  31254. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31255. }
  31256. function mergeCall(call, arg) {
  31257. const existing = call.arguments[0];
  31258. if (existing.type === 17) {
  31259. existing.elements.push(arg);
  31260. } else {
  31261. call.arguments[0] = createArrayExpression([existing, arg]);
  31262. }
  31263. }
  31264. function removeStaticBinding(tag, binding) {
  31265. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31266. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31267. if (i > -1) {
  31268. tag.splice(i, 1);
  31269. }
  31270. }
  31271. function findVModel(node) {
  31272. return node.props.find(
  31273. (p) => p.type === 7 && p.name === "model" && p.exp
  31274. );
  31275. }
  31276. function ssrProcessElement(node, context) {
  31277. const isVoidTag = context.options.isVoidTag || NO;
  31278. const elementsToAdd = node.ssrCodegenNode.elements;
  31279. for (let j = 0; j < elementsToAdd.length; j++) {
  31280. context.pushStringPart(elementsToAdd[j]);
  31281. }
  31282. if (context.withSlotScopeId) {
  31283. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31284. }
  31285. context.pushStringPart(`>`);
  31286. const rawChildren = rawChildrenMap.get(node);
  31287. if (rawChildren) {
  31288. context.pushStringPart(rawChildren);
  31289. } else if (node.children.length) {
  31290. processChildren(node, context);
  31291. }
  31292. if (!isVoidTag(node.tag)) {
  31293. context.pushStringPart(`</${node.tag}>`);
  31294. }
  31295. }
  31296. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  31297. function ssrTransformTransitionGroup(node, context) {
  31298. return () => {
  31299. const tag = findProp(node, "tag");
  31300. if (tag) {
  31301. const otherProps = node.props.filter((p) => p !== tag);
  31302. const { props, directives } = buildProps(
  31303. node,
  31304. context,
  31305. otherProps,
  31306. true,
  31307. false,
  31308. true
  31309. );
  31310. let propsExp = null;
  31311. if (props || directives.length) {
  31312. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31313. buildSSRProps(props, directives, context)
  31314. ]);
  31315. }
  31316. wipMap$2.set(node, {
  31317. tag,
  31318. propsExp,
  31319. scopeId: context.scopeId || null
  31320. });
  31321. }
  31322. };
  31323. }
  31324. function ssrProcessTransitionGroup(node, context) {
  31325. const entry = wipMap$2.get(node);
  31326. if (entry) {
  31327. const { tag, propsExp, scopeId } = entry;
  31328. if (tag.type === 7) {
  31329. context.pushStringPart(`<`);
  31330. context.pushStringPart(tag.exp);
  31331. if (propsExp) {
  31332. context.pushStringPart(propsExp);
  31333. }
  31334. if (scopeId) {
  31335. context.pushStringPart(` ${scopeId}`);
  31336. }
  31337. context.pushStringPart(`>`);
  31338. processChildren(
  31339. node,
  31340. context,
  31341. false,
  31342. /**
  31343. * TransitionGroup has the special runtime behavior of flattening and
  31344. * concatenating all children into a single fragment (in order for them to
  31345. * be patched using the same key map) so we need to account for that here
  31346. * by disabling nested fragment wrappers from being generated.
  31347. */
  31348. true,
  31349. /**
  31350. * TransitionGroup filters out comment children at runtime and thus
  31351. * doesn't expect comments to be present during hydration. We need to
  31352. * account for that by disabling the empty comment that is otherwise
  31353. * rendered for a falsy v-if that has no v-else specified. (#6715)
  31354. */
  31355. true
  31356. );
  31357. context.pushStringPart(`</`);
  31358. context.pushStringPart(tag.exp);
  31359. context.pushStringPart(`>`);
  31360. } else {
  31361. context.pushStringPart(`<${tag.value.content}`);
  31362. if (propsExp) {
  31363. context.pushStringPart(propsExp);
  31364. }
  31365. if (scopeId) {
  31366. context.pushStringPart(` ${scopeId}`);
  31367. }
  31368. context.pushStringPart(`>`);
  31369. processChildren(node, context, false, true, true);
  31370. context.pushStringPart(`</${tag.value.content}>`);
  31371. }
  31372. } else {
  31373. processChildren(node, context, true, true, true);
  31374. }
  31375. }
  31376. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31377. function ssrTransformTransition(node, context) {
  31378. return () => {
  31379. const appear = findProp(node, "appear", false, true);
  31380. wipMap$1.set(node, !!appear);
  31381. };
  31382. }
  31383. function ssrProcessTransition(node, context) {
  31384. node.children = node.children.filter((c) => c.type !== 3);
  31385. const appear = wipMap$1.get(node);
  31386. if (appear) {
  31387. context.pushStringPart(`<template>`);
  31388. processChildren(node, context, false, true);
  31389. context.pushStringPart(`</template>`);
  31390. } else {
  31391. processChildren(node, context, false, true);
  31392. }
  31393. }
  31394. var __defProp$8 = Object.defineProperty;
  31395. var __defProps$7 = Object.defineProperties;
  31396. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  31397. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31398. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31399. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31400. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31401. var __spreadValues$8 = (a, b) => {
  31402. for (var prop in b || (b = {}))
  31403. if (__hasOwnProp$8.call(b, prop))
  31404. __defNormalProp$8(a, prop, b[prop]);
  31405. if (__getOwnPropSymbols$8)
  31406. for (var prop of __getOwnPropSymbols$8(b)) {
  31407. if (__propIsEnum$8.call(b, prop))
  31408. __defNormalProp$8(a, prop, b[prop]);
  31409. }
  31410. return a;
  31411. };
  31412. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  31413. const wipMap = /* @__PURE__ */ new WeakMap();
  31414. const WIP_SLOT = Symbol();
  31415. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31416. const ssrTransformComponent = (node, context) => {
  31417. if (node.type !== 1 || node.tagType !== 1) {
  31418. return;
  31419. }
  31420. const component = resolveComponentType(
  31421. node,
  31422. context,
  31423. true
  31424. /* ssr */
  31425. );
  31426. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31427. componentTypeMap.set(node, component);
  31428. if (isSymbol$1(component)) {
  31429. if (component === SUSPENSE) {
  31430. return ssrTransformSuspense(node, context);
  31431. } else if (component === TRANSITION_GROUP) {
  31432. return ssrTransformTransitionGroup(node, context);
  31433. } else if (component === TRANSITION) {
  31434. return ssrTransformTransition(node);
  31435. }
  31436. return;
  31437. }
  31438. const vnodeBranches = [];
  31439. const clonedNode = clone(node);
  31440. return function ssrPostTransformComponent() {
  31441. if (clonedNode.children.length) {
  31442. buildSlots(clonedNode, context, (props, vFor, children) => {
  31443. vnodeBranches.push(
  31444. createVNodeSlotBranch(props, vFor, children, context)
  31445. );
  31446. return createFunctionExpression(void 0);
  31447. });
  31448. }
  31449. let propsExp = `null`;
  31450. if (node.props.length) {
  31451. const { props, directives } = buildProps(
  31452. node,
  31453. context,
  31454. void 0,
  31455. true,
  31456. isDynamicComponent
  31457. );
  31458. if (props || directives.length) {
  31459. propsExp = buildSSRProps(props, directives, context);
  31460. }
  31461. }
  31462. const wipEntries = [];
  31463. wipMap.set(node, wipEntries);
  31464. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  31465. const param0 = props && stringifyExpression(props) || `_`;
  31466. const fn = createFunctionExpression(
  31467. [param0, `_push`, `_parent`, `_scopeId`],
  31468. void 0,
  31469. // no return, assign body later
  31470. true,
  31471. // newline
  31472. true,
  31473. // isSlot
  31474. loc
  31475. );
  31476. wipEntries.push({
  31477. type: WIP_SLOT,
  31478. fn,
  31479. children,
  31480. // also collect the corresponding vnode branch built earlier
  31481. vnodeBranch: vnodeBranches[wipEntries.length]
  31482. });
  31483. return fn;
  31484. };
  31485. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31486. if (typeof component !== "string") {
  31487. node.ssrCodegenNode = createCallExpression(
  31488. context.helper(SSR_RENDER_VNODE),
  31489. [
  31490. `_push`,
  31491. createCallExpression(context.helper(CREATE_VNODE), [
  31492. component,
  31493. propsExp,
  31494. slots
  31495. ]),
  31496. `_parent`
  31497. ]
  31498. );
  31499. } else {
  31500. node.ssrCodegenNode = createCallExpression(
  31501. context.helper(SSR_RENDER_COMPONENT),
  31502. [component, propsExp, slots, `_parent`]
  31503. );
  31504. }
  31505. };
  31506. };
  31507. function ssrProcessComponent(node, context, parent) {
  31508. const component = componentTypeMap.get(node);
  31509. if (!node.ssrCodegenNode) {
  31510. if (component === TELEPORT) {
  31511. return ssrProcessTeleport(node, context);
  31512. } else if (component === SUSPENSE) {
  31513. return ssrProcessSuspense(node, context);
  31514. } else if (component === TRANSITION_GROUP) {
  31515. return ssrProcessTransitionGroup(node, context);
  31516. } else {
  31517. if (parent.type === WIP_SLOT) {
  31518. context.pushStringPart(``);
  31519. }
  31520. if (component === TRANSITION) {
  31521. return ssrProcessTransition(node, context);
  31522. }
  31523. processChildren(node, context);
  31524. }
  31525. } else {
  31526. const wipEntries = wipMap.get(node) || [];
  31527. for (let i = 0; i < wipEntries.length; i++) {
  31528. const { fn, vnodeBranch } = wipEntries[i];
  31529. fn.body = createIfStatement(
  31530. createSimpleExpression(`_push`, false),
  31531. processChildrenAsStatement(
  31532. wipEntries[i],
  31533. context,
  31534. false,
  31535. true
  31536. ),
  31537. vnodeBranch
  31538. );
  31539. }
  31540. if (context.withSlotScopeId) {
  31541. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31542. }
  31543. if (typeof component === "string") {
  31544. context.pushStatement(
  31545. createCallExpression(`_push`, [node.ssrCodegenNode])
  31546. );
  31547. } else {
  31548. context.pushStatement(node.ssrCodegenNode);
  31549. }
  31550. }
  31551. }
  31552. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31553. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31554. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31555. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31556. function createVNodeSlotBranch(slotProps, vFor, children, parentContext) {
  31557. const rawOptions = rawOptionsMap.get(parentContext.root);
  31558. const subOptions = __spreadProps$7(__spreadValues$8({}, rawOptions), {
  31559. // overwrite with vnode-based transforms
  31560. nodeTransforms: [
  31561. ...vnodeNodeTransforms,
  31562. ...rawOptions.nodeTransforms || []
  31563. ],
  31564. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31565. });
  31566. const wrapperProps = [];
  31567. if (slotProps) {
  31568. wrapperProps.push({
  31569. type: 7,
  31570. name: "slot",
  31571. exp: slotProps,
  31572. arg: void 0,
  31573. modifiers: [],
  31574. loc: locStub
  31575. });
  31576. }
  31577. if (vFor) {
  31578. wrapperProps.push(extend({}, vFor));
  31579. }
  31580. const wrapperNode = {
  31581. type: 1,
  31582. ns: 0,
  31583. tag: "template",
  31584. tagType: 3,
  31585. props: wrapperProps,
  31586. children,
  31587. loc: locStub,
  31588. codegenNode: void 0
  31589. };
  31590. subTransform(wrapperNode, subOptions, parentContext);
  31591. return createReturnStatement(children);
  31592. }
  31593. function subTransform(node, options, parentContext) {
  31594. const childRoot = createRoot([node]);
  31595. const childContext = createTransformContext(childRoot, options);
  31596. childContext.ssr = false;
  31597. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31598. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31599. childContext.imports = parentContext.imports;
  31600. traverseNode(childRoot, childContext);
  31601. ["helpers", "components", "directives"].forEach((key) => {
  31602. childContext[key].forEach((value, helperKey) => {
  31603. if (key === "helpers") {
  31604. const parentCount = parentContext.helpers.get(helperKey);
  31605. if (parentCount === void 0) {
  31606. parentContext.helpers.set(helperKey, value);
  31607. } else {
  31608. parentContext.helpers.set(helperKey, value + parentCount);
  31609. }
  31610. } else {
  31611. parentContext[key].add(value);
  31612. }
  31613. });
  31614. });
  31615. }
  31616. function clone(v) {
  31617. if (isArray$3(v)) {
  31618. return v.map(clone);
  31619. } else if (isPlainObject(v)) {
  31620. const res = {};
  31621. for (const key in v) {
  31622. res[key] = clone(v[key]);
  31623. }
  31624. return res;
  31625. } else {
  31626. return v;
  31627. }
  31628. }
  31629. function ssrCodegenTransform(ast, options) {
  31630. const context = createSSRTransformContext(ast, options);
  31631. if (options.ssrCssVars) {
  31632. const cssContext = createTransformContext(createRoot([]), options);
  31633. const varsExp = processExpression(
  31634. createSimpleExpression(options.ssrCssVars, false),
  31635. cssContext
  31636. );
  31637. context.body.push(
  31638. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31639. );
  31640. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31641. ast.helpers.add(helper);
  31642. });
  31643. }
  31644. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31645. processChildren(ast, context, isFragment);
  31646. ast.codegenNode = createBlockStatement(context.body);
  31647. ast.ssrHelpers = Array.from(
  31648. /* @__PURE__ */ new Set([
  31649. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31650. ...context.helpers
  31651. ])
  31652. );
  31653. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31654. }
  31655. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31656. const body = [];
  31657. let currentString = null;
  31658. return {
  31659. root,
  31660. options,
  31661. body,
  31662. helpers,
  31663. withSlotScopeId,
  31664. onError: options.onError || ((e) => {
  31665. throw e;
  31666. }),
  31667. helper(name) {
  31668. helpers.add(name);
  31669. return name;
  31670. },
  31671. pushStringPart(part) {
  31672. if (!currentString) {
  31673. const currentCall = createCallExpression(`_push`);
  31674. body.push(currentCall);
  31675. currentString = createTemplateLiteral([]);
  31676. currentCall.arguments.push(currentString);
  31677. }
  31678. const bufferedElements = currentString.elements;
  31679. const lastItem = bufferedElements[bufferedElements.length - 1];
  31680. if (isString$1(part) && isString$1(lastItem)) {
  31681. bufferedElements[bufferedElements.length - 1] += part;
  31682. } else {
  31683. bufferedElements.push(part);
  31684. }
  31685. },
  31686. pushStatement(statement) {
  31687. currentString = null;
  31688. body.push(statement);
  31689. }
  31690. };
  31691. }
  31692. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31693. return createSSRTransformContext(
  31694. parent.root,
  31695. parent.options,
  31696. parent.helpers,
  31697. withSlotScopeId
  31698. );
  31699. }
  31700. function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableComment = false) {
  31701. if (asFragment) {
  31702. context.pushStringPart(`<!--[-->`);
  31703. }
  31704. const { children } = parent;
  31705. for (let i = 0; i < children.length; i++) {
  31706. const child = children[i];
  31707. switch (child.type) {
  31708. case 1:
  31709. switch (child.tagType) {
  31710. case 0:
  31711. ssrProcessElement(child, context);
  31712. break;
  31713. case 1:
  31714. ssrProcessComponent(child, context, parent);
  31715. break;
  31716. case 2:
  31717. ssrProcessSlotOutlet(child, context);
  31718. break;
  31719. case 3:
  31720. break;
  31721. default:
  31722. context.onError(
  31723. createSSRCompilerError(
  31724. 67,
  31725. child.loc
  31726. )
  31727. );
  31728. const exhaustiveCheck2 = child;
  31729. return exhaustiveCheck2;
  31730. }
  31731. break;
  31732. case 2:
  31733. context.pushStringPart(escapeHtml(child.content));
  31734. break;
  31735. case 3:
  31736. if (!disableComment) {
  31737. context.pushStringPart(`<!--${child.content}-->`);
  31738. }
  31739. break;
  31740. case 5:
  31741. context.pushStringPart(
  31742. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31743. child.content
  31744. ])
  31745. );
  31746. break;
  31747. case 9:
  31748. ssrProcessIf(child, context, disableNestedFragments, disableComment);
  31749. break;
  31750. case 11:
  31751. ssrProcessFor(child, context, disableNestedFragments);
  31752. break;
  31753. case 10:
  31754. break;
  31755. case 12:
  31756. case 8:
  31757. break;
  31758. default:
  31759. context.onError(
  31760. createSSRCompilerError(
  31761. 67,
  31762. child.loc
  31763. )
  31764. );
  31765. const exhaustiveCheck = child;
  31766. return exhaustiveCheck;
  31767. }
  31768. }
  31769. if (asFragment) {
  31770. context.pushStringPart(`<!--]-->`);
  31771. }
  31772. }
  31773. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  31774. const childContext = createChildContext(parentContext, withSlotScopeId);
  31775. processChildren(parent, childContext, asFragment);
  31776. return createBlockStatement(childContext.body);
  31777. }
  31778. const ssrTransformModel = (dir, node, context) => {
  31779. const model = dir.exp;
  31780. function checkDuplicatedValue() {
  31781. const value = findProp(node, "value");
  31782. if (value) {
  31783. context.onError(
  31784. createDOMCompilerError(
  31785. 60,
  31786. value.loc
  31787. )
  31788. );
  31789. }
  31790. }
  31791. const processSelectChildren = (children) => {
  31792. children.forEach((child) => {
  31793. if (child.type === 1) {
  31794. processOption(child);
  31795. } else if (child.type === 11) {
  31796. processSelectChildren(child.children);
  31797. } else if (child.type === 9) {
  31798. child.branches.forEach((b) => processSelectChildren(b.children));
  31799. }
  31800. });
  31801. };
  31802. function processOption(plainNode) {
  31803. if (plainNode.tag === "option") {
  31804. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  31805. const value = findValueBinding(plainNode);
  31806. plainNode.ssrCodegenNode.elements.push(
  31807. createConditionalExpression(
  31808. createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  31809. createConditionalExpression(
  31810. createCallExpression(`Array.isArray`, [model]),
  31811. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31812. model,
  31813. value
  31814. ]),
  31815. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31816. model,
  31817. value
  31818. ])
  31819. )
  31820. ]),
  31821. createSimpleExpression(" selected", true),
  31822. createSimpleExpression("", true),
  31823. false
  31824. )
  31825. );
  31826. }
  31827. } else if (plainNode.tag === "optgroup") {
  31828. processSelectChildren(plainNode.children);
  31829. }
  31830. }
  31831. if (node.tagType === 0) {
  31832. const res = { props: [] };
  31833. const defaultProps = [
  31834. // default value binding for text type inputs
  31835. createObjectProperty(`value`, model)
  31836. ];
  31837. if (node.tag === "input") {
  31838. const type = findProp(node, "type");
  31839. if (type) {
  31840. const value = findValueBinding(node);
  31841. if (type.type === 7) {
  31842. res.ssrTagParts = [
  31843. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  31844. type.exp,
  31845. model,
  31846. value
  31847. ])
  31848. ];
  31849. } else if (type.value) {
  31850. switch (type.value.content) {
  31851. case "radio":
  31852. res.props = [
  31853. createObjectProperty(
  31854. `checked`,
  31855. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31856. model,
  31857. value
  31858. ])
  31859. )
  31860. ];
  31861. break;
  31862. case "checkbox":
  31863. const trueValueBinding = findProp(node, "true-value");
  31864. if (trueValueBinding) {
  31865. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  31866. res.props = [
  31867. createObjectProperty(
  31868. `checked`,
  31869. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31870. model,
  31871. trueValue
  31872. ])
  31873. )
  31874. ];
  31875. } else {
  31876. res.props = [
  31877. createObjectProperty(
  31878. `checked`,
  31879. createConditionalExpression(
  31880. createCallExpression(`Array.isArray`, [model]),
  31881. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31882. model,
  31883. value
  31884. ]),
  31885. model
  31886. )
  31887. )
  31888. ];
  31889. }
  31890. break;
  31891. case "file":
  31892. context.onError(
  31893. createDOMCompilerError(
  31894. 59,
  31895. dir.loc
  31896. )
  31897. );
  31898. break;
  31899. default:
  31900. checkDuplicatedValue();
  31901. res.props = defaultProps;
  31902. break;
  31903. }
  31904. }
  31905. } else if (hasDynamicKeyVBind(node)) ; else {
  31906. checkDuplicatedValue();
  31907. res.props = defaultProps;
  31908. }
  31909. } else if (node.tag === "textarea") {
  31910. checkDuplicatedValue();
  31911. node.children = [createInterpolation(model, model.loc)];
  31912. } else if (node.tag === "select") {
  31913. processSelectChildren(node.children);
  31914. } else {
  31915. context.onError(
  31916. createDOMCompilerError(
  31917. 57,
  31918. dir.loc
  31919. )
  31920. );
  31921. }
  31922. return res;
  31923. } else {
  31924. return transformModel$1(dir, node, context);
  31925. }
  31926. };
  31927. function findValueBinding(node) {
  31928. const valueBinding = findProp(node, "value");
  31929. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  31930. }
  31931. const ssrTransformShow = (dir, node, context) => {
  31932. if (!dir.exp) {
  31933. context.onError(
  31934. createDOMCompilerError(61)
  31935. );
  31936. }
  31937. return {
  31938. props: [
  31939. createObjectProperty(
  31940. `style`,
  31941. createConditionalExpression(
  31942. dir.exp,
  31943. createSimpleExpression(`null`, false),
  31944. createObjectExpression([
  31945. createObjectProperty(
  31946. `display`,
  31947. createSimpleExpression(`none`, true)
  31948. )
  31949. ]),
  31950. false
  31951. )
  31952. )
  31953. ]
  31954. };
  31955. };
  31956. const filterChild = (node) => node.children.filter((n) => n.type !== 3);
  31957. const hasSingleChild = (node) => filterChild(node).length === 1;
  31958. const ssrInjectFallthroughAttrs = (node, context) => {
  31959. if (node.type === 0) {
  31960. context.identifiers._attrs = 1;
  31961. }
  31962. if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) {
  31963. const rootChildren = filterChild(context.root);
  31964. if (rootChildren.length === 1 && rootChildren[0] === node) {
  31965. if (hasSingleChild(node)) {
  31966. injectFallthroughAttrs(node.children[0]);
  31967. }
  31968. return;
  31969. }
  31970. }
  31971. const parent = context.parent;
  31972. if (!parent || parent.type !== 0) {
  31973. return;
  31974. }
  31975. if (node.type === 10 && hasSingleChild(node)) {
  31976. let hasEncounteredIf = false;
  31977. for (const c of filterChild(parent)) {
  31978. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  31979. if (hasEncounteredIf) return;
  31980. hasEncounteredIf = true;
  31981. } else if (
  31982. // node before v-if
  31983. !hasEncounteredIf || // non else nodes
  31984. !(c.type === 1 && findDir(c, /else/, true))
  31985. ) {
  31986. return;
  31987. }
  31988. }
  31989. injectFallthroughAttrs(node.children[0]);
  31990. } else if (hasSingleChild(parent)) {
  31991. injectFallthroughAttrs(node);
  31992. }
  31993. };
  31994. function injectFallthroughAttrs(node) {
  31995. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  31996. node.props.push({
  31997. type: 7,
  31998. name: "bind",
  31999. arg: void 0,
  32000. exp: createSimpleExpression(`_attrs`, false),
  32001. modifiers: [],
  32002. loc: locStub
  32003. });
  32004. }
  32005. }
  32006. const ssrInjectCssVars = (node, context) => {
  32007. if (!context.ssrCssVars) {
  32008. return;
  32009. }
  32010. if (node.type === 0) {
  32011. context.identifiers._cssVars = 1;
  32012. }
  32013. const parent = context.parent;
  32014. if (!parent || parent.type !== 0) {
  32015. return;
  32016. }
  32017. if (node.type === 10) {
  32018. for (const child of node.children) {
  32019. injectCssVars(child);
  32020. }
  32021. } else {
  32022. injectCssVars(node);
  32023. }
  32024. };
  32025. function injectCssVars(node) {
  32026. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32027. if (node.tag === "suspense" || node.tag === "Suspense") {
  32028. for (const child of node.children) {
  32029. if (child.type === 1 && child.tagType === 3) {
  32030. child.children.forEach(injectCssVars);
  32031. } else {
  32032. injectCssVars(child);
  32033. }
  32034. }
  32035. } else {
  32036. node.props.push({
  32037. type: 7,
  32038. name: "bind",
  32039. arg: void 0,
  32040. exp: createSimpleExpression(`_cssVars`, false),
  32041. modifiers: [],
  32042. loc: locStub
  32043. });
  32044. }
  32045. }
  32046. }
  32047. var __defProp$7 = Object.defineProperty;
  32048. var __defProps$6 = Object.defineProperties;
  32049. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  32050. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  32051. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  32052. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  32053. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32054. var __spreadValues$7 = (a, b) => {
  32055. for (var prop in b || (b = {}))
  32056. if (__hasOwnProp$7.call(b, prop))
  32057. __defNormalProp$7(a, prop, b[prop]);
  32058. if (__getOwnPropSymbols$7)
  32059. for (var prop of __getOwnPropSymbols$7(b)) {
  32060. if (__propIsEnum$7.call(b, prop))
  32061. __defNormalProp$7(a, prop, b[prop]);
  32062. }
  32063. return a;
  32064. };
  32065. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  32066. function compile(source, options = {}) {
  32067. options = __spreadProps$6(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  32068. ssr: true,
  32069. inSSR: true,
  32070. scopeId: options.mode === "function" ? null : options.scopeId,
  32071. // always prefix since compiler-ssr doesn't have size concern
  32072. prefixIdentifiers: true,
  32073. // disable optimizations that are unnecessary for ssr
  32074. cacheHandlers: false,
  32075. hoistStatic: false
  32076. });
  32077. const ast = typeof source === "string" ? baseParse(source, options) : source;
  32078. rawOptionsMap.set(ast, options);
  32079. transform(ast, __spreadProps$6(__spreadValues$7({}, options), {
  32080. hoistStatic: false,
  32081. nodeTransforms: [
  32082. ssrTransformIf,
  32083. ssrTransformFor,
  32084. trackVForSlotScopes,
  32085. transformExpression,
  32086. ssrTransformSlotOutlet,
  32087. ssrInjectFallthroughAttrs,
  32088. ssrInjectCssVars,
  32089. ssrTransformElement,
  32090. ssrTransformComponent,
  32091. trackSlotScopes,
  32092. transformStyle,
  32093. ...options.nodeTransforms || []
  32094. // user transforms
  32095. ],
  32096. directiveTransforms: __spreadValues$7({
  32097. // reusing core v-bind
  32098. bind: transformBind,
  32099. on: transformOn$1,
  32100. // model and show have dedicated SSR handling
  32101. model: ssrTransformModel,
  32102. show: ssrTransformShow,
  32103. // the following are ignored during SSR
  32104. // on: noopDirectiveTransform,
  32105. cloak: noopDirectiveTransform,
  32106. once: noopDirectiveTransform,
  32107. memo: noopDirectiveTransform
  32108. }, options.directiveTransforms || {})
  32109. }));
  32110. ssrCodegenTransform(ast, options);
  32111. return generate(ast, options);
  32112. }
  32113. var CompilerSSR = /*#__PURE__*/Object.freeze({
  32114. __proto__: null,
  32115. compile: compile
  32116. });
  32117. var _polyfillNode_fs = {};
  32118. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  32119. __proto__: null,
  32120. default: _polyfillNode_fs
  32121. });
  32122. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  32123. var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  32124. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  32125. const hasWarned = {};
  32126. function warnOnce$1(msg) {
  32127. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  32128. if (!isNodeProd && true && !hasWarned[msg]) {
  32129. hasWarned[msg] = true;
  32130. warn(msg);
  32131. }
  32132. }
  32133. function warn(msg) {
  32134. console.warn(
  32135. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  32136. `
  32137. );
  32138. }
  32139. var __defProp$6 = Object.defineProperty;
  32140. var __defProps$5 = Object.defineProperties;
  32141. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  32142. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  32143. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  32144. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  32145. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32146. var __spreadValues$6 = (a, b) => {
  32147. for (var prop in b || (b = {}))
  32148. if (__hasOwnProp$6.call(b, prop))
  32149. __defNormalProp$6(a, prop, b[prop]);
  32150. if (__getOwnPropSymbols$6)
  32151. for (var prop of __getOwnPropSymbols$6(b)) {
  32152. if (__propIsEnum$6.call(b, prop))
  32153. __defNormalProp$6(a, prop, b[prop]);
  32154. }
  32155. return a;
  32156. };
  32157. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  32158. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  32159. let res = "";
  32160. let err = null;
  32161. preprocessor.render(
  32162. source,
  32163. __spreadValues$6({ filename }, preprocessOptions),
  32164. (_err, _res) => {
  32165. if (_err) err = _err;
  32166. res = _res;
  32167. }
  32168. );
  32169. if (err) throw err;
  32170. return res;
  32171. }
  32172. function compileTemplate(options) {
  32173. const { preprocessLang, preprocessCustomRequire } = options;
  32174. if (preprocessLang && !preprocessCustomRequire) {
  32175. throw new Error(
  32176. `[@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 }.`
  32177. );
  32178. }
  32179. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  32180. if (preprocessor) {
  32181. try {
  32182. return doCompileTemplate(__spreadProps$5(__spreadValues$6({}, options), {
  32183. source: preprocess$1(options, preprocessor),
  32184. ast: void 0
  32185. // invalidate AST if template goes through preprocessor
  32186. }));
  32187. } catch (e) {
  32188. return {
  32189. code: `export default function render() {}`,
  32190. source: options.source,
  32191. tips: [],
  32192. errors: [e]
  32193. };
  32194. }
  32195. } else if (preprocessLang) {
  32196. return {
  32197. code: `export default function render() {}`,
  32198. source: options.source,
  32199. tips: [
  32200. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  32201. ],
  32202. errors: [
  32203. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  32204. ]
  32205. };
  32206. } else {
  32207. return doCompileTemplate(options);
  32208. }
  32209. }
  32210. function doCompileTemplate({
  32211. filename,
  32212. id,
  32213. scoped,
  32214. slotted,
  32215. inMap,
  32216. source,
  32217. ast: inAST,
  32218. ssr = false,
  32219. ssrCssVars,
  32220. isProd = false,
  32221. compiler,
  32222. compilerOptions = {},
  32223. transformAssetUrls
  32224. }) {
  32225. const errors = [];
  32226. const warnings = [];
  32227. let nodeTransforms = [];
  32228. if (isObject$2(transformAssetUrls)) {
  32229. const assetOptions = normalizeOptions(transformAssetUrls);
  32230. nodeTransforms = [
  32231. createAssetUrlTransformWithOptions(assetOptions),
  32232. createSrcsetTransformWithOptions(assetOptions)
  32233. ];
  32234. } else if (transformAssetUrls !== false) {
  32235. nodeTransforms = [transformAssetUrl, transformSrcset];
  32236. }
  32237. if (ssr && !ssrCssVars) {
  32238. warnOnce$1(
  32239. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.`
  32240. );
  32241. }
  32242. if (!id) {
  32243. warnOnce$1(`compileTemplate now requires the \`id\` option.`);
  32244. id = "";
  32245. }
  32246. const shortId = id.replace(/^data-v-/, "");
  32247. const longId = `data-v-${shortId}`;
  32248. const defaultCompiler = ssr ? CompilerSSR : CompilerDOM;
  32249. compiler = compiler || defaultCompiler;
  32250. if (compiler !== defaultCompiler) {
  32251. inAST = void 0;
  32252. }
  32253. if (inAST == null ? void 0 : inAST.transformed) {
  32254. const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, __spreadProps$5(__spreadValues$6({
  32255. prefixIdentifiers: true
  32256. }, compilerOptions), {
  32257. parseMode: "sfc",
  32258. onError: (e) => errors.push(e)
  32259. }));
  32260. const template = newAST.children.find(
  32261. (node) => node.type === 1 && node.tag === "template"
  32262. );
  32263. inAST = createRoot(template.children, inAST.source);
  32264. }
  32265. let { code, ast, preamble, map } = compiler.compile(inAST || source, __spreadProps$5(__spreadValues$6({
  32266. mode: "module",
  32267. prefixIdentifiers: true,
  32268. hoistStatic: true,
  32269. cacheHandlers: true,
  32270. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32271. scopeId: scoped ? longId : void 0,
  32272. slotted,
  32273. sourceMap: true
  32274. }, compilerOptions), {
  32275. hmr: !isProd,
  32276. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32277. filename,
  32278. onError: (e) => errors.push(e),
  32279. onWarn: (w) => warnings.push(w)
  32280. }));
  32281. if (inMap && !inAST) {
  32282. if (map) {
  32283. map = mapLines(inMap, map);
  32284. }
  32285. if (errors.length) {
  32286. patchErrors(errors, source, inMap);
  32287. }
  32288. }
  32289. const tips = warnings.map((w) => {
  32290. let msg = w.message;
  32291. if (w.loc) {
  32292. msg += `
  32293. ${generateCodeFrame(
  32294. (inAST == null ? void 0 : inAST.source) || source,
  32295. w.loc.start.offset,
  32296. w.loc.end.offset
  32297. )}`;
  32298. }
  32299. return msg;
  32300. });
  32301. return { code, ast, preamble, source, errors, tips, map };
  32302. }
  32303. function mapLines(oldMap, newMap) {
  32304. if (!oldMap) return newMap;
  32305. if (!newMap) return oldMap;
  32306. const oldMapConsumer = new sourceMapExports.SourceMapConsumer(oldMap);
  32307. const newMapConsumer = new sourceMapExports.SourceMapConsumer(newMap);
  32308. const mergedMapGenerator = new sourceMapExports.SourceMapGenerator();
  32309. newMapConsumer.eachMapping((m) => {
  32310. if (m.originalLine == null) {
  32311. return;
  32312. }
  32313. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32314. line: m.originalLine,
  32315. column: m.originalColumn
  32316. });
  32317. if (origPosInOldMap.source == null) {
  32318. return;
  32319. }
  32320. mergedMapGenerator.addMapping({
  32321. generated: {
  32322. line: m.generatedLine,
  32323. column: m.generatedColumn
  32324. },
  32325. original: {
  32326. line: origPosInOldMap.line,
  32327. // map line
  32328. // use current column, since the oldMap produced by @vue/compiler-sfc
  32329. // does not
  32330. column: m.originalColumn
  32331. },
  32332. source: origPosInOldMap.source,
  32333. name: origPosInOldMap.name
  32334. });
  32335. });
  32336. const generator = mergedMapGenerator;
  32337. oldMapConsumer.sources.forEach((sourceFile) => {
  32338. generator._sources.add(sourceFile);
  32339. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32340. if (sourceContent != null) {
  32341. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32342. }
  32343. });
  32344. generator._sourceRoot = oldMap.sourceRoot;
  32345. generator._file = oldMap.file;
  32346. return generator.toJSON();
  32347. }
  32348. function patchErrors(errors, source, inMap) {
  32349. const originalSource = inMap.sourcesContent[0];
  32350. const offset = originalSource.indexOf(source);
  32351. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32352. errors.forEach((err) => {
  32353. if (err.loc) {
  32354. err.loc.start.line += lineOffset;
  32355. err.loc.start.offset += offset;
  32356. if (err.loc.end !== err.loc.start) {
  32357. err.loc.end.line += lineOffset;
  32358. err.loc.end.offset += offset;
  32359. }
  32360. }
  32361. });
  32362. }
  32363. var picocolors = {exports: {}};
  32364. var hasRequiredPicocolors;
  32365. function requirePicocolors () {
  32366. if (hasRequiredPicocolors) return picocolors.exports;
  32367. hasRequiredPicocolors = 1;
  32368. let p = browser$1 || {}, argv = p.argv || [], env = p.env || {};
  32369. let isColorSupported =
  32370. !(!!env.NO_COLOR || argv.includes("--no-color")) &&
  32371. (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
  32372. let formatter = (open, close, replace = open) =>
  32373. input => {
  32374. let string = "" + input, index = string.indexOf(close, open.length);
  32375. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
  32376. };
  32377. let replaceClose = (string, close, replace, index) => {
  32378. let result = "", cursor = 0;
  32379. do {
  32380. result += string.substring(cursor, index) + replace;
  32381. cursor = index + close.length;
  32382. index = string.indexOf(close, cursor);
  32383. } while (~index)
  32384. return result + string.substring(cursor)
  32385. };
  32386. let createColors = (enabled = isColorSupported) => {
  32387. let f = enabled ? formatter : () => String;
  32388. return {
  32389. isColorSupported: enabled,
  32390. reset: f("\x1b[0m", "\x1b[0m"),
  32391. bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
  32392. dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
  32393. italic: f("\x1b[3m", "\x1b[23m"),
  32394. underline: f("\x1b[4m", "\x1b[24m"),
  32395. inverse: f("\x1b[7m", "\x1b[27m"),
  32396. hidden: f("\x1b[8m", "\x1b[28m"),
  32397. strikethrough: f("\x1b[9m", "\x1b[29m"),
  32398. black: f("\x1b[30m", "\x1b[39m"),
  32399. red: f("\x1b[31m", "\x1b[39m"),
  32400. green: f("\x1b[32m", "\x1b[39m"),
  32401. yellow: f("\x1b[33m", "\x1b[39m"),
  32402. blue: f("\x1b[34m", "\x1b[39m"),
  32403. magenta: f("\x1b[35m", "\x1b[39m"),
  32404. cyan: f("\x1b[36m", "\x1b[39m"),
  32405. white: f("\x1b[37m", "\x1b[39m"),
  32406. gray: f("\x1b[90m", "\x1b[39m"),
  32407. bgBlack: f("\x1b[40m", "\x1b[49m"),
  32408. bgRed: f("\x1b[41m", "\x1b[49m"),
  32409. bgGreen: f("\x1b[42m", "\x1b[49m"),
  32410. bgYellow: f("\x1b[43m", "\x1b[49m"),
  32411. bgBlue: f("\x1b[44m", "\x1b[49m"),
  32412. bgMagenta: f("\x1b[45m", "\x1b[49m"),
  32413. bgCyan: f("\x1b[46m", "\x1b[49m"),
  32414. bgWhite: f("\x1b[47m", "\x1b[49m"),
  32415. blackBright: f("\x1b[90m", "\x1b[39m"),
  32416. redBright: f("\x1b[91m", "\x1b[39m"),
  32417. greenBright: f("\x1b[92m", "\x1b[39m"),
  32418. yellowBright: f("\x1b[93m", "\x1b[39m"),
  32419. blueBright: f("\x1b[94m", "\x1b[39m"),
  32420. magentaBright: f("\x1b[95m", "\x1b[39m"),
  32421. cyanBright: f("\x1b[96m", "\x1b[39m"),
  32422. whiteBright: f("\x1b[97m", "\x1b[39m"),
  32423. bgBlackBright: f("\x1b[100m", "\x1b[49m"),
  32424. bgRedBright: f("\x1b[101m", "\x1b[49m"),
  32425. bgGreenBright: f("\x1b[102m", "\x1b[49m"),
  32426. bgYellowBright: f("\x1b[103m", "\x1b[49m"),
  32427. bgBlueBright: f("\x1b[104m", "\x1b[49m"),
  32428. bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
  32429. bgCyanBright: f("\x1b[106m", "\x1b[49m"),
  32430. bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
  32431. }
  32432. };
  32433. picocolors.exports = createColors();
  32434. picocolors.exports.createColors = createColors;
  32435. return picocolors.exports;
  32436. }
  32437. var tokenize$1;
  32438. var hasRequiredTokenize$1;
  32439. function requireTokenize$1 () {
  32440. if (hasRequiredTokenize$1) return tokenize$1;
  32441. hasRequiredTokenize$1 = 1;
  32442. const SINGLE_QUOTE = "'".charCodeAt(0);
  32443. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32444. const BACKSLASH = '\\'.charCodeAt(0);
  32445. const SLASH = '/'.charCodeAt(0);
  32446. const NEWLINE = '\n'.charCodeAt(0);
  32447. const SPACE = ' '.charCodeAt(0);
  32448. const FEED = '\f'.charCodeAt(0);
  32449. const TAB = '\t'.charCodeAt(0);
  32450. const CR = '\r'.charCodeAt(0);
  32451. const OPEN_SQUARE = '['.charCodeAt(0);
  32452. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32453. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32454. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32455. const OPEN_CURLY = '{'.charCodeAt(0);
  32456. const CLOSE_CURLY = '}'.charCodeAt(0);
  32457. const SEMICOLON = ';'.charCodeAt(0);
  32458. const ASTERISK = '*'.charCodeAt(0);
  32459. const COLON = ':'.charCodeAt(0);
  32460. const AT = '@'.charCodeAt(0);
  32461. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32462. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32463. const RE_BAD_BRACKET = /.[\r\n"'(/\\]/;
  32464. const RE_HEX_ESCAPE = /[\da-f]/i;
  32465. tokenize$1 = function tokenizer(input, options = {}) {
  32466. let css = input.css.valueOf();
  32467. let ignore = options.ignoreErrors;
  32468. let code, content, escape, next, quote;
  32469. let currentToken, escaped, escapePos, n, prev;
  32470. let length = css.length;
  32471. let pos = 0;
  32472. let buffer = [];
  32473. let returned = [];
  32474. function position() {
  32475. return pos
  32476. }
  32477. function unclosed(what) {
  32478. throw input.error('Unclosed ' + what, pos)
  32479. }
  32480. function endOfFile() {
  32481. return returned.length === 0 && pos >= length
  32482. }
  32483. function nextToken(opts) {
  32484. if (returned.length) return returned.pop()
  32485. if (pos >= length) return
  32486. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32487. code = css.charCodeAt(pos);
  32488. switch (code) {
  32489. case NEWLINE:
  32490. case SPACE:
  32491. case TAB:
  32492. case CR:
  32493. case FEED: {
  32494. next = pos;
  32495. do {
  32496. next += 1;
  32497. code = css.charCodeAt(next);
  32498. } while (
  32499. code === SPACE ||
  32500. code === NEWLINE ||
  32501. code === TAB ||
  32502. code === CR ||
  32503. code === FEED
  32504. )
  32505. currentToken = ['space', css.slice(pos, next)];
  32506. pos = next - 1;
  32507. break
  32508. }
  32509. case OPEN_SQUARE:
  32510. case CLOSE_SQUARE:
  32511. case OPEN_CURLY:
  32512. case CLOSE_CURLY:
  32513. case COLON:
  32514. case SEMICOLON:
  32515. case CLOSE_PARENTHESES: {
  32516. let controlChar = String.fromCharCode(code);
  32517. currentToken = [controlChar, controlChar, pos];
  32518. break
  32519. }
  32520. case OPEN_PARENTHESES: {
  32521. prev = buffer.length ? buffer.pop()[1] : '';
  32522. n = css.charCodeAt(pos + 1);
  32523. if (
  32524. prev === 'url' &&
  32525. n !== SINGLE_QUOTE &&
  32526. n !== DOUBLE_QUOTE &&
  32527. n !== SPACE &&
  32528. n !== NEWLINE &&
  32529. n !== TAB &&
  32530. n !== FEED &&
  32531. n !== CR
  32532. ) {
  32533. next = pos;
  32534. do {
  32535. escaped = false;
  32536. next = css.indexOf(')', next + 1);
  32537. if (next === -1) {
  32538. if (ignore || ignoreUnclosed) {
  32539. next = pos;
  32540. break
  32541. } else {
  32542. unclosed('bracket');
  32543. }
  32544. }
  32545. escapePos = next;
  32546. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32547. escapePos -= 1;
  32548. escaped = !escaped;
  32549. }
  32550. } while (escaped)
  32551. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32552. pos = next;
  32553. } else {
  32554. next = css.indexOf(')', pos + 1);
  32555. content = css.slice(pos, next + 1);
  32556. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32557. currentToken = ['(', '(', pos];
  32558. } else {
  32559. currentToken = ['brackets', content, pos, next];
  32560. pos = next;
  32561. }
  32562. }
  32563. break
  32564. }
  32565. case SINGLE_QUOTE:
  32566. case DOUBLE_QUOTE: {
  32567. quote = code === SINGLE_QUOTE ? "'" : '"';
  32568. next = pos;
  32569. do {
  32570. escaped = false;
  32571. next = css.indexOf(quote, next + 1);
  32572. if (next === -1) {
  32573. if (ignore || ignoreUnclosed) {
  32574. next = pos + 1;
  32575. break
  32576. } else {
  32577. unclosed('string');
  32578. }
  32579. }
  32580. escapePos = next;
  32581. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32582. escapePos -= 1;
  32583. escaped = !escaped;
  32584. }
  32585. } while (escaped)
  32586. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32587. pos = next;
  32588. break
  32589. }
  32590. case AT: {
  32591. RE_AT_END.lastIndex = pos + 1;
  32592. RE_AT_END.test(css);
  32593. if (RE_AT_END.lastIndex === 0) {
  32594. next = css.length - 1;
  32595. } else {
  32596. next = RE_AT_END.lastIndex - 2;
  32597. }
  32598. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32599. pos = next;
  32600. break
  32601. }
  32602. case BACKSLASH: {
  32603. next = pos;
  32604. escape = true;
  32605. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32606. next += 1;
  32607. escape = !escape;
  32608. }
  32609. code = css.charCodeAt(next + 1);
  32610. if (
  32611. escape &&
  32612. code !== SLASH &&
  32613. code !== SPACE &&
  32614. code !== NEWLINE &&
  32615. code !== TAB &&
  32616. code !== CR &&
  32617. code !== FEED
  32618. ) {
  32619. next += 1;
  32620. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32621. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32622. next += 1;
  32623. }
  32624. if (css.charCodeAt(next + 1) === SPACE) {
  32625. next += 1;
  32626. }
  32627. }
  32628. }
  32629. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32630. pos = next;
  32631. break
  32632. }
  32633. default: {
  32634. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32635. next = css.indexOf('*/', pos + 2) + 1;
  32636. if (next === 0) {
  32637. if (ignore || ignoreUnclosed) {
  32638. next = css.length;
  32639. } else {
  32640. unclosed('comment');
  32641. }
  32642. }
  32643. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32644. pos = next;
  32645. } else {
  32646. RE_WORD_END.lastIndex = pos + 1;
  32647. RE_WORD_END.test(css);
  32648. if (RE_WORD_END.lastIndex === 0) {
  32649. next = css.length - 1;
  32650. } else {
  32651. next = RE_WORD_END.lastIndex - 2;
  32652. }
  32653. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32654. buffer.push(currentToken);
  32655. pos = next;
  32656. }
  32657. break
  32658. }
  32659. }
  32660. pos++;
  32661. return currentToken
  32662. }
  32663. function back(token) {
  32664. returned.push(token);
  32665. }
  32666. return {
  32667. back,
  32668. endOfFile,
  32669. nextToken,
  32670. position
  32671. }
  32672. };
  32673. return tokenize$1;
  32674. }
  32675. var terminalHighlight_1;
  32676. var hasRequiredTerminalHighlight;
  32677. function requireTerminalHighlight () {
  32678. if (hasRequiredTerminalHighlight) return terminalHighlight_1;
  32679. hasRequiredTerminalHighlight = 1;
  32680. let pico = /*@__PURE__*/ requirePicocolors();
  32681. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  32682. let Input;
  32683. function registerInput(dependant) {
  32684. Input = dependant;
  32685. }
  32686. const HIGHLIGHT_THEME = {
  32687. ';': pico.yellow,
  32688. ':': pico.yellow,
  32689. '(': pico.cyan,
  32690. ')': pico.cyan,
  32691. '[': pico.yellow,
  32692. ']': pico.yellow,
  32693. '{': pico.yellow,
  32694. '}': pico.yellow,
  32695. 'at-word': pico.cyan,
  32696. 'brackets': pico.cyan,
  32697. 'call': pico.cyan,
  32698. 'class': pico.yellow,
  32699. 'comment': pico.gray,
  32700. 'hash': pico.magenta,
  32701. 'string': pico.green
  32702. };
  32703. function getTokenType([type, value], processor) {
  32704. if (type === 'word') {
  32705. if (value[0] === '.') {
  32706. return 'class'
  32707. }
  32708. if (value[0] === '#') {
  32709. return 'hash'
  32710. }
  32711. }
  32712. if (!processor.endOfFile()) {
  32713. let next = processor.nextToken();
  32714. processor.back(next);
  32715. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32716. }
  32717. return type
  32718. }
  32719. function terminalHighlight(css) {
  32720. let processor = tokenizer(new Input(css), { ignoreErrors: true });
  32721. let result = '';
  32722. while (!processor.endOfFile()) {
  32723. let token = processor.nextToken();
  32724. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32725. if (color) {
  32726. result += token[1]
  32727. .split(/\r?\n/)
  32728. .map(i => color(i))
  32729. .join('\n');
  32730. } else {
  32731. result += token[1];
  32732. }
  32733. }
  32734. return result
  32735. }
  32736. terminalHighlight.registerInput = registerInput;
  32737. terminalHighlight_1 = terminalHighlight;
  32738. return terminalHighlight_1;
  32739. }
  32740. var cssSyntaxError;
  32741. var hasRequiredCssSyntaxError;
  32742. function requireCssSyntaxError () {
  32743. if (hasRequiredCssSyntaxError) return cssSyntaxError;
  32744. hasRequiredCssSyntaxError = 1;
  32745. let pico = /*@__PURE__*/ requirePicocolors();
  32746. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  32747. class CssSyntaxError extends Error {
  32748. constructor(message, line, column, source, file, plugin) {
  32749. super(message);
  32750. this.name = 'CssSyntaxError';
  32751. this.reason = message;
  32752. if (file) {
  32753. this.file = file;
  32754. }
  32755. if (source) {
  32756. this.source = source;
  32757. }
  32758. if (plugin) {
  32759. this.plugin = plugin;
  32760. }
  32761. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  32762. if (typeof line === 'number') {
  32763. this.line = line;
  32764. this.column = column;
  32765. } else {
  32766. this.line = line.line;
  32767. this.column = line.column;
  32768. this.endLine = column.line;
  32769. this.endColumn = column.column;
  32770. }
  32771. }
  32772. this.setMessage();
  32773. if (Error.captureStackTrace) {
  32774. Error.captureStackTrace(this, CssSyntaxError);
  32775. }
  32776. }
  32777. setMessage() {
  32778. this.message = this.plugin ? this.plugin + ': ' : '';
  32779. this.message += this.file ? this.file : '<css input>';
  32780. if (typeof this.line !== 'undefined') {
  32781. this.message += ':' + this.line + ':' + this.column;
  32782. }
  32783. this.message += ': ' + this.reason;
  32784. }
  32785. showSourceCode(color) {
  32786. if (!this.source) return ''
  32787. let css = this.source;
  32788. if (color == null) color = pico.isColorSupported;
  32789. let aside = text => text;
  32790. let mark = text => text;
  32791. let highlight = text => text;
  32792. if (color) {
  32793. let { bold, gray, red } = pico.createColors(true);
  32794. mark = text => bold(red(text));
  32795. aside = text => gray(text);
  32796. if (terminalHighlight) {
  32797. highlight = text => terminalHighlight(text);
  32798. }
  32799. }
  32800. let lines = css.split(/\r?\n/);
  32801. let start = Math.max(this.line - 3, 0);
  32802. let end = Math.min(this.line + 2, lines.length);
  32803. let maxWidth = String(end).length;
  32804. return lines
  32805. .slice(start, end)
  32806. .map((line, index) => {
  32807. let number = start + 1 + index;
  32808. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  32809. if (number === this.line) {
  32810. if (line.length > 160) {
  32811. let padding = 20;
  32812. let subLineStart = Math.max(0, this.column - padding);
  32813. let subLineEnd = Math.max(
  32814. this.column + padding,
  32815. this.endColumn + padding
  32816. );
  32817. let subLine = line.slice(subLineStart, subLineEnd);
  32818. let spacing =
  32819. aside(gutter.replace(/\d/g, ' ')) +
  32820. line
  32821. .slice(0, Math.min(this.column - 1, padding - 1))
  32822. .replace(/[^\t]/g, ' ');
  32823. return (
  32824. mark('>') +
  32825. aside(gutter) +
  32826. highlight(subLine) +
  32827. '\n ' +
  32828. spacing +
  32829. mark('^')
  32830. )
  32831. }
  32832. let spacing =
  32833. aside(gutter.replace(/\d/g, ' ')) +
  32834. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  32835. return (
  32836. mark('>') +
  32837. aside(gutter) +
  32838. highlight(line) +
  32839. '\n ' +
  32840. spacing +
  32841. mark('^')
  32842. )
  32843. }
  32844. return ' ' + aside(gutter) + highlight(line)
  32845. })
  32846. .join('\n')
  32847. }
  32848. toString() {
  32849. let code = this.showSourceCode();
  32850. if (code) {
  32851. code = '\n\n' + code + '\n';
  32852. }
  32853. return this.name + ': ' + this.message + code
  32854. }
  32855. }
  32856. cssSyntaxError = CssSyntaxError;
  32857. CssSyntaxError.default = CssSyntaxError;
  32858. return cssSyntaxError;
  32859. }
  32860. var stringifier;
  32861. var hasRequiredStringifier;
  32862. function requireStringifier () {
  32863. if (hasRequiredStringifier) return stringifier;
  32864. hasRequiredStringifier = 1;
  32865. const DEFAULT_RAW = {
  32866. after: '\n',
  32867. beforeClose: '\n',
  32868. beforeComment: '\n',
  32869. beforeDecl: '\n',
  32870. beforeOpen: ' ',
  32871. beforeRule: '\n',
  32872. colon: ': ',
  32873. commentLeft: ' ',
  32874. commentRight: ' ',
  32875. emptyBody: '',
  32876. indent: ' ',
  32877. semicolon: false
  32878. };
  32879. function capitalize(str) {
  32880. return str[0].toUpperCase() + str.slice(1)
  32881. }
  32882. class Stringifier {
  32883. constructor(builder) {
  32884. this.builder = builder;
  32885. }
  32886. atrule(node, semicolon) {
  32887. let name = '@' + node.name;
  32888. let params = node.params ? this.rawValue(node, 'params') : '';
  32889. if (typeof node.raws.afterName !== 'undefined') {
  32890. name += node.raws.afterName;
  32891. } else if (params) {
  32892. name += ' ';
  32893. }
  32894. if (node.nodes) {
  32895. this.block(node, name + params);
  32896. } else {
  32897. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  32898. this.builder(name + params + end, node);
  32899. }
  32900. }
  32901. beforeAfter(node, detect) {
  32902. let value;
  32903. if (node.type === 'decl') {
  32904. value = this.raw(node, null, 'beforeDecl');
  32905. } else if (node.type === 'comment') {
  32906. value = this.raw(node, null, 'beforeComment');
  32907. } else if (detect === 'before') {
  32908. value = this.raw(node, null, 'beforeRule');
  32909. } else {
  32910. value = this.raw(node, null, 'beforeClose');
  32911. }
  32912. let buf = node.parent;
  32913. let depth = 0;
  32914. while (buf && buf.type !== 'root') {
  32915. depth += 1;
  32916. buf = buf.parent;
  32917. }
  32918. if (value.includes('\n')) {
  32919. let indent = this.raw(node, null, 'indent');
  32920. if (indent.length) {
  32921. for (let step = 0; step < depth; step++) value += indent;
  32922. }
  32923. }
  32924. return value
  32925. }
  32926. block(node, start) {
  32927. let between = this.raw(node, 'between', 'beforeOpen');
  32928. this.builder(start + between + '{', node, 'start');
  32929. let after;
  32930. if (node.nodes && node.nodes.length) {
  32931. this.body(node);
  32932. after = this.raw(node, 'after');
  32933. } else {
  32934. after = this.raw(node, 'after', 'emptyBody');
  32935. }
  32936. if (after) this.builder(after);
  32937. this.builder('}', node, 'end');
  32938. }
  32939. body(node) {
  32940. let last = node.nodes.length - 1;
  32941. while (last > 0) {
  32942. if (node.nodes[last].type !== 'comment') break
  32943. last -= 1;
  32944. }
  32945. let semicolon = this.raw(node, 'semicolon');
  32946. for (let i = 0; i < node.nodes.length; i++) {
  32947. let child = node.nodes[i];
  32948. let before = this.raw(child, 'before');
  32949. if (before) this.builder(before);
  32950. this.stringify(child, last !== i || semicolon);
  32951. }
  32952. }
  32953. comment(node) {
  32954. let left = this.raw(node, 'left', 'commentLeft');
  32955. let right = this.raw(node, 'right', 'commentRight');
  32956. this.builder('/*' + left + node.text + right + '*/', node);
  32957. }
  32958. decl(node, semicolon) {
  32959. let between = this.raw(node, 'between', 'colon');
  32960. let string = node.prop + between + this.rawValue(node, 'value');
  32961. if (node.important) {
  32962. string += node.raws.important || ' !important';
  32963. }
  32964. if (semicolon) string += ';';
  32965. this.builder(string, node);
  32966. }
  32967. document(node) {
  32968. this.body(node);
  32969. }
  32970. raw(node, own, detect) {
  32971. let value;
  32972. if (!detect) detect = own;
  32973. // Already had
  32974. if (own) {
  32975. value = node.raws[own];
  32976. if (typeof value !== 'undefined') return value
  32977. }
  32978. let parent = node.parent;
  32979. if (detect === 'before') {
  32980. // Hack for first rule in CSS
  32981. if (!parent || (parent.type === 'root' && parent.first === node)) {
  32982. return ''
  32983. }
  32984. // `root` nodes in `document` should use only their own raws
  32985. if (parent && parent.type === 'document') {
  32986. return ''
  32987. }
  32988. }
  32989. // Floating child without parent
  32990. if (!parent) return DEFAULT_RAW[detect]
  32991. // Detect style by other nodes
  32992. let root = node.root();
  32993. if (!root.rawCache) root.rawCache = {};
  32994. if (typeof root.rawCache[detect] !== 'undefined') {
  32995. return root.rawCache[detect]
  32996. }
  32997. if (detect === 'before' || detect === 'after') {
  32998. return this.beforeAfter(node, detect)
  32999. } else {
  33000. let method = 'raw' + capitalize(detect);
  33001. if (this[method]) {
  33002. value = this[method](root, node);
  33003. } else {
  33004. root.walk(i => {
  33005. value = i.raws[own];
  33006. if (typeof value !== 'undefined') return false
  33007. });
  33008. }
  33009. }
  33010. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33011. root.rawCache[detect] = value;
  33012. return value
  33013. }
  33014. rawBeforeClose(root) {
  33015. let value;
  33016. root.walk(i => {
  33017. if (i.nodes && i.nodes.length > 0) {
  33018. if (typeof i.raws.after !== 'undefined') {
  33019. value = i.raws.after;
  33020. if (value.includes('\n')) {
  33021. value = value.replace(/[^\n]+$/, '');
  33022. }
  33023. return false
  33024. }
  33025. }
  33026. });
  33027. if (value) value = value.replace(/\S/g, '');
  33028. return value
  33029. }
  33030. rawBeforeComment(root, node) {
  33031. let value;
  33032. root.walkComments(i => {
  33033. if (typeof i.raws.before !== 'undefined') {
  33034. value = i.raws.before;
  33035. if (value.includes('\n')) {
  33036. value = value.replace(/[^\n]+$/, '');
  33037. }
  33038. return false
  33039. }
  33040. });
  33041. if (typeof value === 'undefined') {
  33042. value = this.raw(node, null, 'beforeDecl');
  33043. } else if (value) {
  33044. value = value.replace(/\S/g, '');
  33045. }
  33046. return value
  33047. }
  33048. rawBeforeDecl(root, node) {
  33049. let value;
  33050. root.walkDecls(i => {
  33051. if (typeof i.raws.before !== 'undefined') {
  33052. value = i.raws.before;
  33053. if (value.includes('\n')) {
  33054. value = value.replace(/[^\n]+$/, '');
  33055. }
  33056. return false
  33057. }
  33058. });
  33059. if (typeof value === 'undefined') {
  33060. value = this.raw(node, null, 'beforeRule');
  33061. } else if (value) {
  33062. value = value.replace(/\S/g, '');
  33063. }
  33064. return value
  33065. }
  33066. rawBeforeOpen(root) {
  33067. let value;
  33068. root.walk(i => {
  33069. if (i.type !== 'decl') {
  33070. value = i.raws.between;
  33071. if (typeof value !== 'undefined') return false
  33072. }
  33073. });
  33074. return value
  33075. }
  33076. rawBeforeRule(root) {
  33077. let value;
  33078. root.walk(i => {
  33079. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33080. if (typeof i.raws.before !== 'undefined') {
  33081. value = i.raws.before;
  33082. if (value.includes('\n')) {
  33083. value = value.replace(/[^\n]+$/, '');
  33084. }
  33085. return false
  33086. }
  33087. }
  33088. });
  33089. if (value) value = value.replace(/\S/g, '');
  33090. return value
  33091. }
  33092. rawColon(root) {
  33093. let value;
  33094. root.walkDecls(i => {
  33095. if (typeof i.raws.between !== 'undefined') {
  33096. value = i.raws.between.replace(/[^\s:]/g, '');
  33097. return false
  33098. }
  33099. });
  33100. return value
  33101. }
  33102. rawEmptyBody(root) {
  33103. let value;
  33104. root.walk(i => {
  33105. if (i.nodes && i.nodes.length === 0) {
  33106. value = i.raws.after;
  33107. if (typeof value !== 'undefined') return false
  33108. }
  33109. });
  33110. return value
  33111. }
  33112. rawIndent(root) {
  33113. if (root.raws.indent) return root.raws.indent
  33114. let value;
  33115. root.walk(i => {
  33116. let p = i.parent;
  33117. if (p && p !== root && p.parent && p.parent === root) {
  33118. if (typeof i.raws.before !== 'undefined') {
  33119. let parts = i.raws.before.split('\n');
  33120. value = parts[parts.length - 1];
  33121. value = value.replace(/\S/g, '');
  33122. return false
  33123. }
  33124. }
  33125. });
  33126. return value
  33127. }
  33128. rawSemicolon(root) {
  33129. let value;
  33130. root.walk(i => {
  33131. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33132. value = i.raws.semicolon;
  33133. if (typeof value !== 'undefined') return false
  33134. }
  33135. });
  33136. return value
  33137. }
  33138. rawValue(node, prop) {
  33139. let value = node[prop];
  33140. let raw = node.raws[prop];
  33141. if (raw && raw.value === value) {
  33142. return raw.raw
  33143. }
  33144. return value
  33145. }
  33146. root(node) {
  33147. this.body(node);
  33148. if (node.raws.after) this.builder(node.raws.after);
  33149. }
  33150. rule(node) {
  33151. this.block(node, this.rawValue(node, 'selector'));
  33152. if (node.raws.ownSemicolon) {
  33153. this.builder(node.raws.ownSemicolon, node, 'end');
  33154. }
  33155. }
  33156. stringify(node, semicolon) {
  33157. /* c8 ignore start */
  33158. if (!this[node.type]) {
  33159. throw new Error(
  33160. 'Unknown AST node type ' +
  33161. node.type +
  33162. '. ' +
  33163. 'Maybe you need to change PostCSS stringifier.'
  33164. )
  33165. }
  33166. /* c8 ignore stop */
  33167. this[node.type](node, semicolon);
  33168. }
  33169. }
  33170. stringifier = Stringifier;
  33171. Stringifier.default = Stringifier;
  33172. return stringifier;
  33173. }
  33174. var stringify_1;
  33175. var hasRequiredStringify;
  33176. function requireStringify () {
  33177. if (hasRequiredStringify) return stringify_1;
  33178. hasRequiredStringify = 1;
  33179. let Stringifier = /*@__PURE__*/ requireStringifier();
  33180. function stringify(node, builder) {
  33181. let str = new Stringifier(builder);
  33182. str.stringify(node);
  33183. }
  33184. stringify_1 = stringify;
  33185. stringify.default = stringify;
  33186. return stringify_1;
  33187. }
  33188. var symbols = {};
  33189. var hasRequiredSymbols;
  33190. function requireSymbols () {
  33191. if (hasRequiredSymbols) return symbols;
  33192. hasRequiredSymbols = 1;
  33193. symbols.isClean = Symbol('isClean');
  33194. symbols.my = Symbol('my');
  33195. return symbols;
  33196. }
  33197. var node$2;
  33198. var hasRequiredNode$2;
  33199. function requireNode$2 () {
  33200. if (hasRequiredNode$2) return node$2;
  33201. hasRequiredNode$2 = 1;
  33202. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  33203. let Stringifier = /*@__PURE__*/ requireStringifier();
  33204. let stringify = /*@__PURE__*/ requireStringify();
  33205. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33206. function cloneNode(obj, parent) {
  33207. let cloned = new obj.constructor();
  33208. for (let i in obj) {
  33209. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33210. /* c8 ignore next 2 */
  33211. continue
  33212. }
  33213. if (i === 'proxyCache') continue
  33214. let value = obj[i];
  33215. let type = typeof value;
  33216. if (i === 'parent' && type === 'object') {
  33217. if (parent) cloned[i] = parent;
  33218. } else if (i === 'source') {
  33219. cloned[i] = value;
  33220. } else if (Array.isArray(value)) {
  33221. cloned[i] = value.map(j => cloneNode(j, cloned));
  33222. } else {
  33223. if (type === 'object' && value !== null) value = cloneNode(value);
  33224. cloned[i] = value;
  33225. }
  33226. }
  33227. return cloned
  33228. }
  33229. function sourceOffset(inputCSS, position) {
  33230. // Not all custom syntaxes support `offset` in `source.start` and `source.end`
  33231. if (position && typeof position.offset !== 'undefined') {
  33232. return position.offset
  33233. }
  33234. let column = 1;
  33235. let line = 1;
  33236. let offset = 0;
  33237. for (let i = 0; i < inputCSS.length; i++) {
  33238. if (line === position.line && column === position.column) {
  33239. offset = i;
  33240. break
  33241. }
  33242. if (inputCSS[i] === '\n') {
  33243. column = 1;
  33244. line += 1;
  33245. } else {
  33246. column += 1;
  33247. }
  33248. }
  33249. return offset
  33250. }
  33251. class Node {
  33252. get proxyOf() {
  33253. return this
  33254. }
  33255. constructor(defaults = {}) {
  33256. this.raws = {};
  33257. this[isClean] = false;
  33258. this[my] = true;
  33259. for (let name in defaults) {
  33260. if (name === 'nodes') {
  33261. this.nodes = [];
  33262. for (let node of defaults[name]) {
  33263. if (typeof node.clone === 'function') {
  33264. this.append(node.clone());
  33265. } else {
  33266. this.append(node);
  33267. }
  33268. }
  33269. } else {
  33270. this[name] = defaults[name];
  33271. }
  33272. }
  33273. }
  33274. addToError(error) {
  33275. error.postcssNode = this;
  33276. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33277. let s = this.source;
  33278. error.stack = error.stack.replace(
  33279. /\n\s{4}at /,
  33280. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33281. );
  33282. }
  33283. return error
  33284. }
  33285. after(add) {
  33286. this.parent.insertAfter(this, add);
  33287. return this
  33288. }
  33289. assign(overrides = {}) {
  33290. for (let name in overrides) {
  33291. this[name] = overrides[name];
  33292. }
  33293. return this
  33294. }
  33295. before(add) {
  33296. this.parent.insertBefore(this, add);
  33297. return this
  33298. }
  33299. cleanRaws(keepBetween) {
  33300. delete this.raws.before;
  33301. delete this.raws.after;
  33302. if (!keepBetween) delete this.raws.between;
  33303. }
  33304. clone(overrides = {}) {
  33305. let cloned = cloneNode(this);
  33306. for (let name in overrides) {
  33307. cloned[name] = overrides[name];
  33308. }
  33309. return cloned
  33310. }
  33311. cloneAfter(overrides = {}) {
  33312. let cloned = this.clone(overrides);
  33313. this.parent.insertAfter(this, cloned);
  33314. return cloned
  33315. }
  33316. cloneBefore(overrides = {}) {
  33317. let cloned = this.clone(overrides);
  33318. this.parent.insertBefore(this, cloned);
  33319. return cloned
  33320. }
  33321. error(message, opts = {}) {
  33322. if (this.source) {
  33323. let { end, start } = this.rangeBy(opts);
  33324. return this.source.input.error(
  33325. message,
  33326. { column: start.column, line: start.line },
  33327. { column: end.column, line: end.line },
  33328. opts
  33329. )
  33330. }
  33331. return new CssSyntaxError(message)
  33332. }
  33333. getProxyProcessor() {
  33334. return {
  33335. get(node, prop) {
  33336. if (prop === 'proxyOf') {
  33337. return node
  33338. } else if (prop === 'root') {
  33339. return () => node.root().toProxy()
  33340. } else {
  33341. return node[prop]
  33342. }
  33343. },
  33344. set(node, prop, value) {
  33345. if (node[prop] === value) return true
  33346. node[prop] = value;
  33347. if (
  33348. prop === 'prop' ||
  33349. prop === 'value' ||
  33350. prop === 'name' ||
  33351. prop === 'params' ||
  33352. prop === 'important' ||
  33353. /* c8 ignore next */
  33354. prop === 'text'
  33355. ) {
  33356. node.markDirty();
  33357. }
  33358. return true
  33359. }
  33360. }
  33361. }
  33362. /* c8 ignore next 3 */
  33363. markClean() {
  33364. this[isClean] = true;
  33365. }
  33366. markDirty() {
  33367. if (this[isClean]) {
  33368. this[isClean] = false;
  33369. let next = this;
  33370. while ((next = next.parent)) {
  33371. next[isClean] = false;
  33372. }
  33373. }
  33374. }
  33375. next() {
  33376. if (!this.parent) return undefined
  33377. let index = this.parent.index(this);
  33378. return this.parent.nodes[index + 1]
  33379. }
  33380. positionBy(opts = {}) {
  33381. let pos = this.source.start;
  33382. if (opts.index) {
  33383. pos = this.positionInside(opts.index);
  33384. } else if (opts.word) {
  33385. let inputString =
  33386. 'document' in this.source.input
  33387. ? this.source.input.document
  33388. : this.source.input.css;
  33389. let stringRepresentation = inputString.slice(
  33390. sourceOffset(inputString, this.source.start),
  33391. sourceOffset(inputString, this.source.end)
  33392. );
  33393. let index = stringRepresentation.indexOf(opts.word);
  33394. if (index !== -1) pos = this.positionInside(index);
  33395. }
  33396. return pos
  33397. }
  33398. positionInside(index) {
  33399. let column = this.source.start.column;
  33400. let line = this.source.start.line;
  33401. let inputString =
  33402. 'document' in this.source.input
  33403. ? this.source.input.document
  33404. : this.source.input.css;
  33405. let offset = sourceOffset(inputString, this.source.start);
  33406. let end = offset + index;
  33407. for (let i = offset; i < end; i++) {
  33408. if (inputString[i] === '\n') {
  33409. column = 1;
  33410. line += 1;
  33411. } else {
  33412. column += 1;
  33413. }
  33414. }
  33415. return { column, line, offset: end }
  33416. }
  33417. prev() {
  33418. if (!this.parent) return undefined
  33419. let index = this.parent.index(this);
  33420. return this.parent.nodes[index - 1]
  33421. }
  33422. rangeBy(opts = {}) {
  33423. let inputString =
  33424. 'document' in this.source.input
  33425. ? this.source.input.document
  33426. : this.source.input.css;
  33427. let start = {
  33428. column: this.source.start.column,
  33429. line: this.source.start.line,
  33430. offset: sourceOffset(inputString, this.source.start)
  33431. };
  33432. let end = this.source.end
  33433. ? {
  33434. column: this.source.end.column + 1,
  33435. line: this.source.end.line,
  33436. offset:
  33437. typeof this.source.end.offset === 'number'
  33438. ? // `source.end.offset` is exclusive, so we don't need to add 1
  33439. this.source.end.offset
  33440. : // Since line/column in this.source.end is inclusive,
  33441. // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
  33442. // So, we add 1 to convert it to exclusive.
  33443. sourceOffset(inputString, this.source.end) + 1
  33444. }
  33445. : {
  33446. column: start.column + 1,
  33447. line: start.line,
  33448. offset: start.offset + 1
  33449. };
  33450. if (opts.word) {
  33451. let stringRepresentation = inputString.slice(
  33452. sourceOffset(inputString, this.source.start),
  33453. sourceOffset(inputString, this.source.end)
  33454. );
  33455. let index = stringRepresentation.indexOf(opts.word);
  33456. if (index !== -1) {
  33457. start = this.positionInside(index);
  33458. end = this.positionInside(index + opts.word.length);
  33459. }
  33460. } else {
  33461. if (opts.start) {
  33462. start = {
  33463. column: opts.start.column,
  33464. line: opts.start.line,
  33465. offset: sourceOffset(inputString, opts.start)
  33466. };
  33467. } else if (opts.index) {
  33468. start = this.positionInside(opts.index);
  33469. }
  33470. if (opts.end) {
  33471. end = {
  33472. column: opts.end.column,
  33473. line: opts.end.line,
  33474. offset: sourceOffset(inputString, opts.end)
  33475. };
  33476. } else if (typeof opts.endIndex === 'number') {
  33477. end = this.positionInside(opts.endIndex);
  33478. } else if (opts.index) {
  33479. end = this.positionInside(opts.index + 1);
  33480. }
  33481. }
  33482. if (
  33483. end.line < start.line ||
  33484. (end.line === start.line && end.column <= start.column)
  33485. ) {
  33486. end = {
  33487. column: start.column + 1,
  33488. line: start.line,
  33489. offset: start.offset + 1
  33490. };
  33491. }
  33492. return { end, start }
  33493. }
  33494. raw(prop, defaultType) {
  33495. let str = new Stringifier();
  33496. return str.raw(this, prop, defaultType)
  33497. }
  33498. remove() {
  33499. if (this.parent) {
  33500. this.parent.removeChild(this);
  33501. }
  33502. this.parent = undefined;
  33503. return this
  33504. }
  33505. replaceWith(...nodes) {
  33506. if (this.parent) {
  33507. let bookmark = this;
  33508. let foundSelf = false;
  33509. for (let node of nodes) {
  33510. if (node === this) {
  33511. foundSelf = true;
  33512. } else if (foundSelf) {
  33513. this.parent.insertAfter(bookmark, node);
  33514. bookmark = node;
  33515. } else {
  33516. this.parent.insertBefore(bookmark, node);
  33517. }
  33518. }
  33519. if (!foundSelf) {
  33520. this.remove();
  33521. }
  33522. }
  33523. return this
  33524. }
  33525. root() {
  33526. let result = this;
  33527. while (result.parent && result.parent.type !== 'document') {
  33528. result = result.parent;
  33529. }
  33530. return result
  33531. }
  33532. toJSON(_, inputs) {
  33533. let fixed = {};
  33534. let emitInputs = inputs == null;
  33535. inputs = inputs || new Map();
  33536. let inputsNextIndex = 0;
  33537. for (let name in this) {
  33538. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33539. /* c8 ignore next 2 */
  33540. continue
  33541. }
  33542. if (name === 'parent' || name === 'proxyCache') continue
  33543. let value = this[name];
  33544. if (Array.isArray(value)) {
  33545. fixed[name] = value.map(i => {
  33546. if (typeof i === 'object' && i.toJSON) {
  33547. return i.toJSON(null, inputs)
  33548. } else {
  33549. return i
  33550. }
  33551. });
  33552. } else if (typeof value === 'object' && value.toJSON) {
  33553. fixed[name] = value.toJSON(null, inputs);
  33554. } else if (name === 'source') {
  33555. if (value == null) continue
  33556. let inputId = inputs.get(value.input);
  33557. if (inputId == null) {
  33558. inputId = inputsNextIndex;
  33559. inputs.set(value.input, inputsNextIndex);
  33560. inputsNextIndex++;
  33561. }
  33562. fixed[name] = {
  33563. end: value.end,
  33564. inputId,
  33565. start: value.start
  33566. };
  33567. } else {
  33568. fixed[name] = value;
  33569. }
  33570. }
  33571. if (emitInputs) {
  33572. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33573. }
  33574. return fixed
  33575. }
  33576. toProxy() {
  33577. if (!this.proxyCache) {
  33578. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33579. }
  33580. return this.proxyCache
  33581. }
  33582. toString(stringifier = stringify) {
  33583. if (stringifier.stringify) stringifier = stringifier.stringify;
  33584. let result = '';
  33585. stringifier(this, i => {
  33586. result += i;
  33587. });
  33588. return result
  33589. }
  33590. warn(result, text, opts = {}) {
  33591. let data = { node: this };
  33592. for (let i in opts) data[i] = opts[i];
  33593. return result.warn(text, data)
  33594. }
  33595. }
  33596. node$2 = Node;
  33597. Node.default = Node;
  33598. return node$2;
  33599. }
  33600. var comment$1;
  33601. var hasRequiredComment$1;
  33602. function requireComment$1 () {
  33603. if (hasRequiredComment$1) return comment$1;
  33604. hasRequiredComment$1 = 1;
  33605. let Node = /*@__PURE__*/ requireNode$2();
  33606. class Comment extends Node {
  33607. constructor(defaults) {
  33608. super(defaults);
  33609. this.type = 'comment';
  33610. }
  33611. }
  33612. comment$1 = Comment;
  33613. Comment.default = Comment;
  33614. return comment$1;
  33615. }
  33616. var declaration;
  33617. var hasRequiredDeclaration;
  33618. function requireDeclaration () {
  33619. if (hasRequiredDeclaration) return declaration;
  33620. hasRequiredDeclaration = 1;
  33621. let Node = /*@__PURE__*/ requireNode$2();
  33622. class Declaration extends Node {
  33623. get variable() {
  33624. return this.prop.startsWith('--') || this.prop[0] === '$'
  33625. }
  33626. constructor(defaults) {
  33627. if (
  33628. defaults &&
  33629. typeof defaults.value !== 'undefined' &&
  33630. typeof defaults.value !== 'string'
  33631. ) {
  33632. defaults = { ...defaults, value: String(defaults.value) };
  33633. }
  33634. super(defaults);
  33635. this.type = 'decl';
  33636. }
  33637. }
  33638. declaration = Declaration;
  33639. Declaration.default = Declaration;
  33640. return declaration;
  33641. }
  33642. var container$1;
  33643. var hasRequiredContainer$1;
  33644. function requireContainer$1 () {
  33645. if (hasRequiredContainer$1) return container$1;
  33646. hasRequiredContainer$1 = 1;
  33647. let Comment = /*@__PURE__*/ requireComment$1();
  33648. let Declaration = /*@__PURE__*/ requireDeclaration();
  33649. let Node = /*@__PURE__*/ requireNode$2();
  33650. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33651. let AtRule, parse, Root, Rule;
  33652. function cleanSource(nodes) {
  33653. return nodes.map(i => {
  33654. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33655. delete i.source;
  33656. return i
  33657. })
  33658. }
  33659. function markTreeDirty(node) {
  33660. node[isClean] = false;
  33661. if (node.proxyOf.nodes) {
  33662. for (let i of node.proxyOf.nodes) {
  33663. markTreeDirty(i);
  33664. }
  33665. }
  33666. }
  33667. class Container extends Node {
  33668. get first() {
  33669. if (!this.proxyOf.nodes) return undefined
  33670. return this.proxyOf.nodes[0]
  33671. }
  33672. get last() {
  33673. if (!this.proxyOf.nodes) return undefined
  33674. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  33675. }
  33676. append(...children) {
  33677. for (let child of children) {
  33678. let nodes = this.normalize(child, this.last);
  33679. for (let node of nodes) this.proxyOf.nodes.push(node);
  33680. }
  33681. this.markDirty();
  33682. return this
  33683. }
  33684. cleanRaws(keepBetween) {
  33685. super.cleanRaws(keepBetween);
  33686. if (this.nodes) {
  33687. for (let node of this.nodes) node.cleanRaws(keepBetween);
  33688. }
  33689. }
  33690. each(callback) {
  33691. if (!this.proxyOf.nodes) return undefined
  33692. let iterator = this.getIterator();
  33693. let index, result;
  33694. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  33695. index = this.indexes[iterator];
  33696. result = callback(this.proxyOf.nodes[index], index);
  33697. if (result === false) break
  33698. this.indexes[iterator] += 1;
  33699. }
  33700. delete this.indexes[iterator];
  33701. return result
  33702. }
  33703. every(condition) {
  33704. return this.nodes.every(condition)
  33705. }
  33706. getIterator() {
  33707. if (!this.lastEach) this.lastEach = 0;
  33708. if (!this.indexes) this.indexes = {};
  33709. this.lastEach += 1;
  33710. let iterator = this.lastEach;
  33711. this.indexes[iterator] = 0;
  33712. return iterator
  33713. }
  33714. getProxyProcessor() {
  33715. return {
  33716. get(node, prop) {
  33717. if (prop === 'proxyOf') {
  33718. return node
  33719. } else if (!node[prop]) {
  33720. return node[prop]
  33721. } else if (
  33722. prop === 'each' ||
  33723. (typeof prop === 'string' && prop.startsWith('walk'))
  33724. ) {
  33725. return (...args) => {
  33726. return node[prop](
  33727. ...args.map(i => {
  33728. if (typeof i === 'function') {
  33729. return (child, index) => i(child.toProxy(), index)
  33730. } else {
  33731. return i
  33732. }
  33733. })
  33734. )
  33735. }
  33736. } else if (prop === 'every' || prop === 'some') {
  33737. return cb => {
  33738. return node[prop]((child, ...other) =>
  33739. cb(child.toProxy(), ...other)
  33740. )
  33741. }
  33742. } else if (prop === 'root') {
  33743. return () => node.root().toProxy()
  33744. } else if (prop === 'nodes') {
  33745. return node.nodes.map(i => i.toProxy())
  33746. } else if (prop === 'first' || prop === 'last') {
  33747. return node[prop].toProxy()
  33748. } else {
  33749. return node[prop]
  33750. }
  33751. },
  33752. set(node, prop, value) {
  33753. if (node[prop] === value) return true
  33754. node[prop] = value;
  33755. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  33756. node.markDirty();
  33757. }
  33758. return true
  33759. }
  33760. }
  33761. }
  33762. index(child) {
  33763. if (typeof child === 'number') return child
  33764. if (child.proxyOf) child = child.proxyOf;
  33765. return this.proxyOf.nodes.indexOf(child)
  33766. }
  33767. insertAfter(exist, add) {
  33768. let existIndex = this.index(exist);
  33769. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  33770. existIndex = this.index(exist);
  33771. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  33772. let index;
  33773. for (let id in this.indexes) {
  33774. index = this.indexes[id];
  33775. if (existIndex < index) {
  33776. this.indexes[id] = index + nodes.length;
  33777. }
  33778. }
  33779. this.markDirty();
  33780. return this
  33781. }
  33782. insertBefore(exist, add) {
  33783. let existIndex = this.index(exist);
  33784. let type = existIndex === 0 ? 'prepend' : false;
  33785. let nodes = this.normalize(
  33786. add,
  33787. this.proxyOf.nodes[existIndex],
  33788. type
  33789. ).reverse();
  33790. existIndex = this.index(exist);
  33791. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  33792. let index;
  33793. for (let id in this.indexes) {
  33794. index = this.indexes[id];
  33795. if (existIndex <= index) {
  33796. this.indexes[id] = index + nodes.length;
  33797. }
  33798. }
  33799. this.markDirty();
  33800. return this
  33801. }
  33802. normalize(nodes, sample) {
  33803. if (typeof nodes === 'string') {
  33804. nodes = cleanSource(parse(nodes).nodes);
  33805. } else if (typeof nodes === 'undefined') {
  33806. nodes = [];
  33807. } else if (Array.isArray(nodes)) {
  33808. nodes = nodes.slice(0);
  33809. for (let i of nodes) {
  33810. if (i.parent) i.parent.removeChild(i, 'ignore');
  33811. }
  33812. } else if (nodes.type === 'root' && this.type !== 'document') {
  33813. nodes = nodes.nodes.slice(0);
  33814. for (let i of nodes) {
  33815. if (i.parent) i.parent.removeChild(i, 'ignore');
  33816. }
  33817. } else if (nodes.type) {
  33818. nodes = [nodes];
  33819. } else if (nodes.prop) {
  33820. if (typeof nodes.value === 'undefined') {
  33821. throw new Error('Value field is missed in node creation')
  33822. } else if (typeof nodes.value !== 'string') {
  33823. nodes.value = String(nodes.value);
  33824. }
  33825. nodes = [new Declaration(nodes)];
  33826. } else if (nodes.selector || nodes.selectors) {
  33827. nodes = [new Rule(nodes)];
  33828. } else if (nodes.name) {
  33829. nodes = [new AtRule(nodes)];
  33830. } else if (nodes.text) {
  33831. nodes = [new Comment(nodes)];
  33832. } else {
  33833. throw new Error('Unknown node type in node creation')
  33834. }
  33835. let processed = nodes.map(i => {
  33836. /* c8 ignore next */
  33837. if (!i[my]) Container.rebuild(i);
  33838. i = i.proxyOf;
  33839. if (i.parent) i.parent.removeChild(i);
  33840. if (i[isClean]) markTreeDirty(i);
  33841. if (!i.raws) i.raws = {};
  33842. if (typeof i.raws.before === 'undefined') {
  33843. if (sample && typeof sample.raws.before !== 'undefined') {
  33844. i.raws.before = sample.raws.before.replace(/\S/g, '');
  33845. }
  33846. }
  33847. i.parent = this.proxyOf;
  33848. return i
  33849. });
  33850. return processed
  33851. }
  33852. prepend(...children) {
  33853. children = children.reverse();
  33854. for (let child of children) {
  33855. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  33856. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  33857. for (let id in this.indexes) {
  33858. this.indexes[id] = this.indexes[id] + nodes.length;
  33859. }
  33860. }
  33861. this.markDirty();
  33862. return this
  33863. }
  33864. push(child) {
  33865. child.parent = this;
  33866. this.proxyOf.nodes.push(child);
  33867. return this
  33868. }
  33869. removeAll() {
  33870. for (let node of this.proxyOf.nodes) node.parent = undefined;
  33871. this.proxyOf.nodes = [];
  33872. this.markDirty();
  33873. return this
  33874. }
  33875. removeChild(child) {
  33876. child = this.index(child);
  33877. this.proxyOf.nodes[child].parent = undefined;
  33878. this.proxyOf.nodes.splice(child, 1);
  33879. let index;
  33880. for (let id in this.indexes) {
  33881. index = this.indexes[id];
  33882. if (index >= child) {
  33883. this.indexes[id] = index - 1;
  33884. }
  33885. }
  33886. this.markDirty();
  33887. return this
  33888. }
  33889. replaceValues(pattern, opts, callback) {
  33890. if (!callback) {
  33891. callback = opts;
  33892. opts = {};
  33893. }
  33894. this.walkDecls(decl => {
  33895. if (opts.props && !opts.props.includes(decl.prop)) return
  33896. if (opts.fast && !decl.value.includes(opts.fast)) return
  33897. decl.value = decl.value.replace(pattern, callback);
  33898. });
  33899. this.markDirty();
  33900. return this
  33901. }
  33902. some(condition) {
  33903. return this.nodes.some(condition)
  33904. }
  33905. walk(callback) {
  33906. return this.each((child, i) => {
  33907. let result;
  33908. try {
  33909. result = callback(child, i);
  33910. } catch (e) {
  33911. throw child.addToError(e)
  33912. }
  33913. if (result !== false && child.walk) {
  33914. result = child.walk(callback);
  33915. }
  33916. return result
  33917. })
  33918. }
  33919. walkAtRules(name, callback) {
  33920. if (!callback) {
  33921. callback = name;
  33922. return this.walk((child, i) => {
  33923. if (child.type === 'atrule') {
  33924. return callback(child, i)
  33925. }
  33926. })
  33927. }
  33928. if (name instanceof RegExp) {
  33929. return this.walk((child, i) => {
  33930. if (child.type === 'atrule' && name.test(child.name)) {
  33931. return callback(child, i)
  33932. }
  33933. })
  33934. }
  33935. return this.walk((child, i) => {
  33936. if (child.type === 'atrule' && child.name === name) {
  33937. return callback(child, i)
  33938. }
  33939. })
  33940. }
  33941. walkComments(callback) {
  33942. return this.walk((child, i) => {
  33943. if (child.type === 'comment') {
  33944. return callback(child, i)
  33945. }
  33946. })
  33947. }
  33948. walkDecls(prop, callback) {
  33949. if (!callback) {
  33950. callback = prop;
  33951. return this.walk((child, i) => {
  33952. if (child.type === 'decl') {
  33953. return callback(child, i)
  33954. }
  33955. })
  33956. }
  33957. if (prop instanceof RegExp) {
  33958. return this.walk((child, i) => {
  33959. if (child.type === 'decl' && prop.test(child.prop)) {
  33960. return callback(child, i)
  33961. }
  33962. })
  33963. }
  33964. return this.walk((child, i) => {
  33965. if (child.type === 'decl' && child.prop === prop) {
  33966. return callback(child, i)
  33967. }
  33968. })
  33969. }
  33970. walkRules(selector, callback) {
  33971. if (!callback) {
  33972. callback = selector;
  33973. return this.walk((child, i) => {
  33974. if (child.type === 'rule') {
  33975. return callback(child, i)
  33976. }
  33977. })
  33978. }
  33979. if (selector instanceof RegExp) {
  33980. return this.walk((child, i) => {
  33981. if (child.type === 'rule' && selector.test(child.selector)) {
  33982. return callback(child, i)
  33983. }
  33984. })
  33985. }
  33986. return this.walk((child, i) => {
  33987. if (child.type === 'rule' && child.selector === selector) {
  33988. return callback(child, i)
  33989. }
  33990. })
  33991. }
  33992. }
  33993. Container.registerParse = dependant => {
  33994. parse = dependant;
  33995. };
  33996. Container.registerRule = dependant => {
  33997. Rule = dependant;
  33998. };
  33999. Container.registerAtRule = dependant => {
  34000. AtRule = dependant;
  34001. };
  34002. Container.registerRoot = dependant => {
  34003. Root = dependant;
  34004. };
  34005. container$1 = Container;
  34006. Container.default = Container;
  34007. /* c8 ignore start */
  34008. Container.rebuild = node => {
  34009. if (node.type === 'atrule') {
  34010. Object.setPrototypeOf(node, AtRule.prototype);
  34011. } else if (node.type === 'rule') {
  34012. Object.setPrototypeOf(node, Rule.prototype);
  34013. } else if (node.type === 'decl') {
  34014. Object.setPrototypeOf(node, Declaration.prototype);
  34015. } else if (node.type === 'comment') {
  34016. Object.setPrototypeOf(node, Comment.prototype);
  34017. } else if (node.type === 'root') {
  34018. Object.setPrototypeOf(node, Root.prototype);
  34019. }
  34020. node[my] = true;
  34021. if (node.nodes) {
  34022. node.nodes.forEach(child => {
  34023. Container.rebuild(child);
  34024. });
  34025. }
  34026. };
  34027. /* c8 ignore stop */
  34028. return container$1;
  34029. }
  34030. var atRule;
  34031. var hasRequiredAtRule;
  34032. function requireAtRule () {
  34033. if (hasRequiredAtRule) return atRule;
  34034. hasRequiredAtRule = 1;
  34035. let Container = /*@__PURE__*/ requireContainer$1();
  34036. class AtRule extends Container {
  34037. constructor(defaults) {
  34038. super(defaults);
  34039. this.type = 'atrule';
  34040. }
  34041. append(...children) {
  34042. if (!this.proxyOf.nodes) this.nodes = [];
  34043. return super.append(...children)
  34044. }
  34045. prepend(...children) {
  34046. if (!this.proxyOf.nodes) this.nodes = [];
  34047. return super.prepend(...children)
  34048. }
  34049. }
  34050. atRule = AtRule;
  34051. AtRule.default = AtRule;
  34052. Container.registerAtRule(AtRule);
  34053. return atRule;
  34054. }
  34055. var document;
  34056. var hasRequiredDocument;
  34057. function requireDocument () {
  34058. if (hasRequiredDocument) return document;
  34059. hasRequiredDocument = 1;
  34060. let Container = /*@__PURE__*/ requireContainer$1();
  34061. let LazyResult, Processor;
  34062. class Document extends Container {
  34063. constructor(defaults) {
  34064. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34065. super({ type: 'document', ...defaults });
  34066. if (!this.nodes) {
  34067. this.nodes = [];
  34068. }
  34069. }
  34070. toResult(opts = {}) {
  34071. let lazy = new LazyResult(new Processor(), this, opts);
  34072. return lazy.stringify()
  34073. }
  34074. }
  34075. Document.registerLazyResult = dependant => {
  34076. LazyResult = dependant;
  34077. };
  34078. Document.registerProcessor = dependant => {
  34079. Processor = dependant;
  34080. };
  34081. document = Document;
  34082. Document.default = Document;
  34083. return document;
  34084. }
  34085. var nonSecure;
  34086. var hasRequiredNonSecure;
  34087. function requireNonSecure () {
  34088. if (hasRequiredNonSecure) return nonSecure;
  34089. hasRequiredNonSecure = 1;
  34090. // This alphabet uses `A-Za-z0-9_-` symbols.
  34091. // The order of characters is optimized for better gzip and brotli compression.
  34092. // References to the same file (works both for gzip and brotli):
  34093. // `'use`, `andom`, and `rict'`
  34094. // References to the brotli default dictionary:
  34095. // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
  34096. let urlAlphabet =
  34097. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  34098. let customAlphabet = (alphabet, defaultSize = 21) => {
  34099. return (size = defaultSize) => {
  34100. let id = '';
  34101. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34102. let i = size | 0;
  34103. while (i--) {
  34104. // `| 0` is more compact and faster than `Math.floor()`.
  34105. id += alphabet[(Math.random() * alphabet.length) | 0];
  34106. }
  34107. return id
  34108. }
  34109. };
  34110. let nanoid = (size = 21) => {
  34111. let id = '';
  34112. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34113. let i = size | 0;
  34114. while (i--) {
  34115. // `| 0` is more compact and faster than `Math.floor()`.
  34116. id += urlAlphabet[(Math.random() * 64) | 0];
  34117. }
  34118. return id
  34119. };
  34120. nonSecure = { nanoid, customAlphabet };
  34121. return nonSecure;
  34122. }
  34123. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  34124. var previousMap;
  34125. var hasRequiredPreviousMap;
  34126. function requirePreviousMap () {
  34127. if (hasRequiredPreviousMap) return previousMap;
  34128. hasRequiredPreviousMap = 1;
  34129. let { existsSync, readFileSync } = require$$0$1;
  34130. let { dirname, join } = require$$1;
  34131. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34132. function fromBase64(str) {
  34133. if (Buffer$1) {
  34134. return Buffer$1.from(str, 'base64').toString()
  34135. } else {
  34136. /* c8 ignore next 2 */
  34137. return window.atob(str)
  34138. }
  34139. }
  34140. class PreviousMap {
  34141. constructor(css, opts) {
  34142. if (opts.map === false) return
  34143. this.loadAnnotation(css);
  34144. this.inline = this.startWith(this.annotation, 'data:');
  34145. let prev = opts.map ? opts.map.prev : undefined;
  34146. let text = this.loadMap(opts.from, prev);
  34147. if (!this.mapFile && opts.from) {
  34148. this.mapFile = opts.from;
  34149. }
  34150. if (this.mapFile) this.root = dirname(this.mapFile);
  34151. if (text) this.text = text;
  34152. }
  34153. consumer() {
  34154. if (!this.consumerCache) {
  34155. this.consumerCache = new SourceMapConsumer(this.text);
  34156. }
  34157. return this.consumerCache
  34158. }
  34159. decodeInline(text) {
  34160. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  34161. let baseUri = /^data:application\/json;base64,/;
  34162. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  34163. let uri = /^data:application\/json,/;
  34164. let uriMatch = text.match(charsetUri) || text.match(uri);
  34165. if (uriMatch) {
  34166. return decodeURIComponent(text.substr(uriMatch[0].length))
  34167. }
  34168. let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
  34169. if (baseUriMatch) {
  34170. return fromBase64(text.substr(baseUriMatch[0].length))
  34171. }
  34172. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  34173. throw new Error('Unsupported source map encoding ' + encoding)
  34174. }
  34175. getAnnotationURL(sourceMapString) {
  34176. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  34177. }
  34178. isMap(map) {
  34179. if (typeof map !== 'object') return false
  34180. return (
  34181. typeof map.mappings === 'string' ||
  34182. typeof map._mappings === 'string' ||
  34183. Array.isArray(map.sections)
  34184. )
  34185. }
  34186. loadAnnotation(css) {
  34187. let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
  34188. if (!comments) return
  34189. // sourceMappingURLs from comments, strings, etc.
  34190. let start = css.lastIndexOf(comments.pop());
  34191. let end = css.indexOf('*/', start);
  34192. if (start > -1 && end > -1) {
  34193. // Locate the last sourceMappingURL to avoid pickin
  34194. this.annotation = this.getAnnotationURL(css.substring(start, end));
  34195. }
  34196. }
  34197. loadFile(path) {
  34198. this.root = dirname(path);
  34199. if (existsSync(path)) {
  34200. this.mapFile = path;
  34201. return readFileSync(path, 'utf-8').toString().trim()
  34202. }
  34203. }
  34204. loadMap(file, prev) {
  34205. if (prev === false) return false
  34206. if (prev) {
  34207. if (typeof prev === 'string') {
  34208. return prev
  34209. } else if (typeof prev === 'function') {
  34210. let prevPath = prev(file);
  34211. if (prevPath) {
  34212. let map = this.loadFile(prevPath);
  34213. if (!map) {
  34214. throw new Error(
  34215. 'Unable to load previous source map: ' + prevPath.toString()
  34216. )
  34217. }
  34218. return map
  34219. }
  34220. } else if (prev instanceof SourceMapConsumer) {
  34221. return SourceMapGenerator.fromSourceMap(prev).toString()
  34222. } else if (prev instanceof SourceMapGenerator) {
  34223. return prev.toString()
  34224. } else if (this.isMap(prev)) {
  34225. return JSON.stringify(prev)
  34226. } else {
  34227. throw new Error(
  34228. 'Unsupported previous source map format: ' + prev.toString()
  34229. )
  34230. }
  34231. } else if (this.inline) {
  34232. return this.decodeInline(this.annotation)
  34233. } else if (this.annotation) {
  34234. let map = this.annotation;
  34235. if (file) map = join(dirname(file), map);
  34236. return this.loadFile(map)
  34237. }
  34238. }
  34239. startWith(string, start) {
  34240. if (!string) return false
  34241. return string.substr(0, start.length) === start
  34242. }
  34243. withContent() {
  34244. return !!(
  34245. this.consumer().sourcesContent &&
  34246. this.consumer().sourcesContent.length > 0
  34247. )
  34248. }
  34249. }
  34250. previousMap = PreviousMap;
  34251. PreviousMap.default = PreviousMap;
  34252. return previousMap;
  34253. }
  34254. var input;
  34255. var hasRequiredInput;
  34256. function requireInput () {
  34257. if (hasRequiredInput) return input;
  34258. hasRequiredInput = 1;
  34259. let { nanoid } = /*@__PURE__*/ requireNonSecure();
  34260. let { isAbsolute, resolve } = require$$1;
  34261. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34262. let { fileURLToPath, pathToFileURL } = require$$2;
  34263. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  34264. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34265. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  34266. let lineToIndexCache = Symbol('lineToIndexCache');
  34267. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34268. let pathAvailable = Boolean(resolve && isAbsolute);
  34269. function getLineToIndex(input) {
  34270. if (input[lineToIndexCache]) return input[lineToIndexCache]
  34271. let lines = input.css.split('\n');
  34272. let lineToIndex = new Array(lines.length);
  34273. let prevIndex = 0;
  34274. for (let i = 0, l = lines.length; i < l; i++) {
  34275. lineToIndex[i] = prevIndex;
  34276. prevIndex += lines[i].length + 1;
  34277. }
  34278. input[lineToIndexCache] = lineToIndex;
  34279. return lineToIndex
  34280. }
  34281. class Input {
  34282. get from() {
  34283. return this.file || this.id
  34284. }
  34285. constructor(css, opts = {}) {
  34286. if (
  34287. css === null ||
  34288. typeof css === 'undefined' ||
  34289. (typeof css === 'object' && !css.toString)
  34290. ) {
  34291. throw new Error(`PostCSS received ${css} instead of CSS string`)
  34292. }
  34293. this.css = css.toString();
  34294. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  34295. this.hasBOM = true;
  34296. this.css = this.css.slice(1);
  34297. } else {
  34298. this.hasBOM = false;
  34299. }
  34300. this.document = this.css;
  34301. if (opts.document) this.document = opts.document.toString();
  34302. if (opts.from) {
  34303. if (
  34304. !pathAvailable ||
  34305. /^\w+:\/\//.test(opts.from) ||
  34306. isAbsolute(opts.from)
  34307. ) {
  34308. this.file = opts.from;
  34309. } else {
  34310. this.file = resolve(opts.from);
  34311. }
  34312. }
  34313. if (pathAvailable && sourceMapAvailable) {
  34314. let map = new PreviousMap(this.css, opts);
  34315. if (map.text) {
  34316. this.map = map;
  34317. let file = map.consumer().file;
  34318. if (!this.file && file) this.file = this.mapResolve(file);
  34319. }
  34320. }
  34321. if (!this.file) {
  34322. this.id = '<input css ' + nanoid(6) + '>';
  34323. }
  34324. if (this.map) this.map.file = this.from;
  34325. }
  34326. error(message, line, column, opts = {}) {
  34327. let endColumn, endLine, endOffset, offset, result;
  34328. if (line && typeof line === 'object') {
  34329. let start = line;
  34330. let end = column;
  34331. if (typeof start.offset === 'number') {
  34332. offset = start.offset;
  34333. let pos = this.fromOffset(offset);
  34334. line = pos.line;
  34335. column = pos.col;
  34336. } else {
  34337. line = start.line;
  34338. column = start.column;
  34339. offset = this.fromLineAndColumn(line, column);
  34340. }
  34341. if (typeof end.offset === 'number') {
  34342. endOffset = end.offset;
  34343. let pos = this.fromOffset(endOffset);
  34344. endLine = pos.line;
  34345. endColumn = pos.col;
  34346. } else {
  34347. endLine = end.line;
  34348. endColumn = end.column;
  34349. endOffset = this.fromLineAndColumn(end.line, end.column);
  34350. }
  34351. } else if (!column) {
  34352. offset = line;
  34353. let pos = this.fromOffset(offset);
  34354. line = pos.line;
  34355. column = pos.col;
  34356. } else {
  34357. offset = this.fromLineAndColumn(line, column);
  34358. }
  34359. let origin = this.origin(line, column, endLine, endColumn);
  34360. if (origin) {
  34361. result = new CssSyntaxError(
  34362. message,
  34363. origin.endLine === undefined
  34364. ? origin.line
  34365. : { column: origin.column, line: origin.line },
  34366. origin.endLine === undefined
  34367. ? origin.column
  34368. : { column: origin.endColumn, line: origin.endLine },
  34369. origin.source,
  34370. origin.file,
  34371. opts.plugin
  34372. );
  34373. } else {
  34374. result = new CssSyntaxError(
  34375. message,
  34376. endLine === undefined ? line : { column, line },
  34377. endLine === undefined ? column : { column: endColumn, line: endLine },
  34378. this.css,
  34379. this.file,
  34380. opts.plugin
  34381. );
  34382. }
  34383. result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
  34384. if (this.file) {
  34385. if (pathToFileURL) {
  34386. result.input.url = pathToFileURL(this.file).toString();
  34387. }
  34388. result.input.file = this.file;
  34389. }
  34390. return result
  34391. }
  34392. fromLineAndColumn(line, column) {
  34393. let lineToIndex = getLineToIndex(this);
  34394. let index = lineToIndex[line - 1];
  34395. return index + column - 1
  34396. }
  34397. fromOffset(offset) {
  34398. let lineToIndex = getLineToIndex(this);
  34399. let lastLine = lineToIndex[lineToIndex.length - 1];
  34400. let min = 0;
  34401. if (offset >= lastLine) {
  34402. min = lineToIndex.length - 1;
  34403. } else {
  34404. let max = lineToIndex.length - 2;
  34405. let mid;
  34406. while (min < max) {
  34407. mid = min + ((max - min) >> 1);
  34408. if (offset < lineToIndex[mid]) {
  34409. max = mid - 1;
  34410. } else if (offset >= lineToIndex[mid + 1]) {
  34411. min = mid + 1;
  34412. } else {
  34413. min = mid;
  34414. break
  34415. }
  34416. }
  34417. }
  34418. return {
  34419. col: offset - lineToIndex[min] + 1,
  34420. line: min + 1
  34421. }
  34422. }
  34423. mapResolve(file) {
  34424. if (/^\w+:\/\//.test(file)) {
  34425. return file
  34426. }
  34427. return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
  34428. }
  34429. origin(line, column, endLine, endColumn) {
  34430. if (!this.map) return false
  34431. let consumer = this.map.consumer();
  34432. let from = consumer.originalPositionFor({ column, line });
  34433. if (!from.source) return false
  34434. let to;
  34435. if (typeof endLine === 'number') {
  34436. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  34437. }
  34438. let fromUrl;
  34439. if (isAbsolute(from.source)) {
  34440. fromUrl = pathToFileURL(from.source);
  34441. } else {
  34442. fromUrl = new URL(
  34443. from.source,
  34444. this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
  34445. );
  34446. }
  34447. let result = {
  34448. column: from.column,
  34449. endColumn: to && to.column,
  34450. endLine: to && to.line,
  34451. line: from.line,
  34452. url: fromUrl.toString()
  34453. };
  34454. if (fromUrl.protocol === 'file:') {
  34455. if (fileURLToPath) {
  34456. result.file = fileURLToPath(fromUrl);
  34457. } else {
  34458. /* c8 ignore next 2 */
  34459. throw new Error(`file: protocol is not available in this PostCSS build`)
  34460. }
  34461. }
  34462. let source = consumer.sourceContentFor(from.source);
  34463. if (source) result.source = source;
  34464. return result
  34465. }
  34466. toJSON() {
  34467. let json = {};
  34468. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  34469. if (this[name] != null) {
  34470. json[name] = this[name];
  34471. }
  34472. }
  34473. if (this.map) {
  34474. json.map = { ...this.map };
  34475. if (json.map.consumerCache) {
  34476. json.map.consumerCache = undefined;
  34477. }
  34478. }
  34479. return json
  34480. }
  34481. }
  34482. input = Input;
  34483. Input.default = Input;
  34484. if (terminalHighlight && terminalHighlight.registerInput) {
  34485. terminalHighlight.registerInput(Input);
  34486. }
  34487. return input;
  34488. }
  34489. var root$1;
  34490. var hasRequiredRoot$1;
  34491. function requireRoot$1 () {
  34492. if (hasRequiredRoot$1) return root$1;
  34493. hasRequiredRoot$1 = 1;
  34494. let Container = /*@__PURE__*/ requireContainer$1();
  34495. let LazyResult, Processor;
  34496. class Root extends Container {
  34497. constructor(defaults) {
  34498. super(defaults);
  34499. this.type = 'root';
  34500. if (!this.nodes) this.nodes = [];
  34501. }
  34502. normalize(child, sample, type) {
  34503. let nodes = super.normalize(child);
  34504. if (sample) {
  34505. if (type === 'prepend') {
  34506. if (this.nodes.length > 1) {
  34507. sample.raws.before = this.nodes[1].raws.before;
  34508. } else {
  34509. delete sample.raws.before;
  34510. }
  34511. } else if (this.first !== sample) {
  34512. for (let node of nodes) {
  34513. node.raws.before = sample.raws.before;
  34514. }
  34515. }
  34516. }
  34517. return nodes
  34518. }
  34519. removeChild(child, ignore) {
  34520. let index = this.index(child);
  34521. if (!ignore && index === 0 && this.nodes.length > 1) {
  34522. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34523. }
  34524. return super.removeChild(child)
  34525. }
  34526. toResult(opts = {}) {
  34527. let lazy = new LazyResult(new Processor(), this, opts);
  34528. return lazy.stringify()
  34529. }
  34530. }
  34531. Root.registerLazyResult = dependant => {
  34532. LazyResult = dependant;
  34533. };
  34534. Root.registerProcessor = dependant => {
  34535. Processor = dependant;
  34536. };
  34537. root$1 = Root;
  34538. Root.default = Root;
  34539. Container.registerRoot(Root);
  34540. return root$1;
  34541. }
  34542. var list_1;
  34543. var hasRequiredList;
  34544. function requireList () {
  34545. if (hasRequiredList) return list_1;
  34546. hasRequiredList = 1;
  34547. let list = {
  34548. comma(string) {
  34549. return list.split(string, [','], true)
  34550. },
  34551. space(string) {
  34552. let spaces = [' ', '\n', '\t'];
  34553. return list.split(string, spaces)
  34554. },
  34555. split(string, separators, last) {
  34556. let array = [];
  34557. let current = '';
  34558. let split = false;
  34559. let func = 0;
  34560. let inQuote = false;
  34561. let prevQuote = '';
  34562. let escape = false;
  34563. for (let letter of string) {
  34564. if (escape) {
  34565. escape = false;
  34566. } else if (letter === '\\') {
  34567. escape = true;
  34568. } else if (inQuote) {
  34569. if (letter === prevQuote) {
  34570. inQuote = false;
  34571. }
  34572. } else if (letter === '"' || letter === "'") {
  34573. inQuote = true;
  34574. prevQuote = letter;
  34575. } else if (letter === '(') {
  34576. func += 1;
  34577. } else if (letter === ')') {
  34578. if (func > 0) func -= 1;
  34579. } else if (func === 0) {
  34580. if (separators.includes(letter)) split = true;
  34581. }
  34582. if (split) {
  34583. if (current !== '') array.push(current.trim());
  34584. current = '';
  34585. split = false;
  34586. } else {
  34587. current += letter;
  34588. }
  34589. }
  34590. if (last || current !== '') array.push(current.trim());
  34591. return array
  34592. }
  34593. };
  34594. list_1 = list;
  34595. list.default = list;
  34596. return list_1;
  34597. }
  34598. var rule;
  34599. var hasRequiredRule;
  34600. function requireRule () {
  34601. if (hasRequiredRule) return rule;
  34602. hasRequiredRule = 1;
  34603. let Container = /*@__PURE__*/ requireContainer$1();
  34604. let list = /*@__PURE__*/ requireList();
  34605. class Rule extends Container {
  34606. get selectors() {
  34607. return list.comma(this.selector)
  34608. }
  34609. set selectors(values) {
  34610. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34611. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34612. this.selector = values.join(sep);
  34613. }
  34614. constructor(defaults) {
  34615. super(defaults);
  34616. this.type = 'rule';
  34617. if (!this.nodes) this.nodes = [];
  34618. }
  34619. }
  34620. rule = Rule;
  34621. Rule.default = Rule;
  34622. Container.registerRule(Rule);
  34623. return rule;
  34624. }
  34625. var fromJSON_1;
  34626. var hasRequiredFromJSON;
  34627. function requireFromJSON () {
  34628. if (hasRequiredFromJSON) return fromJSON_1;
  34629. hasRequiredFromJSON = 1;
  34630. let AtRule = /*@__PURE__*/ requireAtRule();
  34631. let Comment = /*@__PURE__*/ requireComment$1();
  34632. let Declaration = /*@__PURE__*/ requireDeclaration();
  34633. let Input = /*@__PURE__*/ requireInput();
  34634. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34635. let Root = /*@__PURE__*/ requireRoot$1();
  34636. let Rule = /*@__PURE__*/ requireRule();
  34637. function fromJSON(json, inputs) {
  34638. if (Array.isArray(json)) return json.map(n => fromJSON(n))
  34639. let { inputs: ownInputs, ...defaults } = json;
  34640. if (ownInputs) {
  34641. inputs = [];
  34642. for (let input of ownInputs) {
  34643. let inputHydrated = { ...input, __proto__: Input.prototype };
  34644. if (inputHydrated.map) {
  34645. inputHydrated.map = {
  34646. ...inputHydrated.map,
  34647. __proto__: PreviousMap.prototype
  34648. };
  34649. }
  34650. inputs.push(inputHydrated);
  34651. }
  34652. }
  34653. if (defaults.nodes) {
  34654. defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
  34655. }
  34656. if (defaults.source) {
  34657. let { inputId, ...source } = defaults.source;
  34658. defaults.source = source;
  34659. if (inputId != null) {
  34660. defaults.source.input = inputs[inputId];
  34661. }
  34662. }
  34663. if (defaults.type === 'root') {
  34664. return new Root(defaults)
  34665. } else if (defaults.type === 'decl') {
  34666. return new Declaration(defaults)
  34667. } else if (defaults.type === 'rule') {
  34668. return new Rule(defaults)
  34669. } else if (defaults.type === 'comment') {
  34670. return new Comment(defaults)
  34671. } else if (defaults.type === 'atrule') {
  34672. return new AtRule(defaults)
  34673. } else {
  34674. throw new Error('Unknown node type: ' + json.type)
  34675. }
  34676. }
  34677. fromJSON_1 = fromJSON;
  34678. fromJSON.default = fromJSON;
  34679. return fromJSON_1;
  34680. }
  34681. var mapGenerator;
  34682. var hasRequiredMapGenerator;
  34683. function requireMapGenerator () {
  34684. if (hasRequiredMapGenerator) return mapGenerator;
  34685. hasRequiredMapGenerator = 1;
  34686. let { dirname, relative, resolve, sep } = require$$1;
  34687. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34688. let { pathToFileURL } = require$$2;
  34689. let Input = /*@__PURE__*/ requireInput();
  34690. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34691. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  34692. class MapGenerator {
  34693. constructor(stringify, root, opts, cssString) {
  34694. this.stringify = stringify;
  34695. this.mapOpts = opts.map || {};
  34696. this.root = root;
  34697. this.opts = opts;
  34698. this.css = cssString;
  34699. this.originalCSS = cssString;
  34700. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  34701. this.memoizedFileURLs = new Map();
  34702. this.memoizedPaths = new Map();
  34703. this.memoizedURLs = new Map();
  34704. }
  34705. addAnnotation() {
  34706. let content;
  34707. if (this.isInline()) {
  34708. content =
  34709. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  34710. } else if (typeof this.mapOpts.annotation === 'string') {
  34711. content = this.mapOpts.annotation;
  34712. } else if (typeof this.mapOpts.annotation === 'function') {
  34713. content = this.mapOpts.annotation(this.opts.to, this.root);
  34714. } else {
  34715. content = this.outputFile() + '.map';
  34716. }
  34717. let eol = '\n';
  34718. if (this.css.includes('\r\n')) eol = '\r\n';
  34719. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  34720. }
  34721. applyPrevMaps() {
  34722. for (let prev of this.previous()) {
  34723. let from = this.toUrl(this.path(prev.file));
  34724. let root = prev.root || dirname(prev.file);
  34725. let map;
  34726. if (this.mapOpts.sourcesContent === false) {
  34727. map = new SourceMapConsumer(prev.text);
  34728. if (map.sourcesContent) {
  34729. map.sourcesContent = null;
  34730. }
  34731. } else {
  34732. map = prev.consumer();
  34733. }
  34734. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  34735. }
  34736. }
  34737. clearAnnotation() {
  34738. if (this.mapOpts.annotation === false) return
  34739. if (this.root) {
  34740. let node;
  34741. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  34742. node = this.root.nodes[i];
  34743. if (node.type !== 'comment') continue
  34744. if (node.text.startsWith('# sourceMappingURL=')) {
  34745. this.root.removeChild(i);
  34746. }
  34747. }
  34748. } else if (this.css) {
  34749. this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '');
  34750. }
  34751. }
  34752. generate() {
  34753. this.clearAnnotation();
  34754. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  34755. return this.generateMap()
  34756. } else {
  34757. let result = '';
  34758. this.stringify(this.root, i => {
  34759. result += i;
  34760. });
  34761. return [result]
  34762. }
  34763. }
  34764. generateMap() {
  34765. if (this.root) {
  34766. this.generateString();
  34767. } else if (this.previous().length === 1) {
  34768. let prev = this.previous()[0].consumer();
  34769. prev.file = this.outputFile();
  34770. this.map = SourceMapGenerator.fromSourceMap(prev, {
  34771. ignoreInvalidMapping: true
  34772. });
  34773. } else {
  34774. this.map = new SourceMapGenerator({
  34775. file: this.outputFile(),
  34776. ignoreInvalidMapping: true
  34777. });
  34778. this.map.addMapping({
  34779. generated: { column: 0, line: 1 },
  34780. original: { column: 0, line: 1 },
  34781. source: this.opts.from
  34782. ? this.toUrl(this.path(this.opts.from))
  34783. : '<no source>'
  34784. });
  34785. }
  34786. if (this.isSourcesContent()) this.setSourcesContent();
  34787. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  34788. if (this.isAnnotation()) this.addAnnotation();
  34789. if (this.isInline()) {
  34790. return [this.css]
  34791. } else {
  34792. return [this.css, this.map]
  34793. }
  34794. }
  34795. generateString() {
  34796. this.css = '';
  34797. this.map = new SourceMapGenerator({
  34798. file: this.outputFile(),
  34799. ignoreInvalidMapping: true
  34800. });
  34801. let line = 1;
  34802. let column = 1;
  34803. let noSource = '<no source>';
  34804. let mapping = {
  34805. generated: { column: 0, line: 0 },
  34806. original: { column: 0, line: 0 },
  34807. source: ''
  34808. };
  34809. let last, lines;
  34810. this.stringify(this.root, (str, node, type) => {
  34811. this.css += str;
  34812. if (node && type !== 'end') {
  34813. mapping.generated.line = line;
  34814. mapping.generated.column = column - 1;
  34815. if (node.source && node.source.start) {
  34816. mapping.source = this.sourcePath(node);
  34817. mapping.original.line = node.source.start.line;
  34818. mapping.original.column = node.source.start.column - 1;
  34819. this.map.addMapping(mapping);
  34820. } else {
  34821. mapping.source = noSource;
  34822. mapping.original.line = 1;
  34823. mapping.original.column = 0;
  34824. this.map.addMapping(mapping);
  34825. }
  34826. }
  34827. lines = str.match(/\n/g);
  34828. if (lines) {
  34829. line += lines.length;
  34830. last = str.lastIndexOf('\n');
  34831. column = str.length - last;
  34832. } else {
  34833. column += str.length;
  34834. }
  34835. if (node && type !== 'start') {
  34836. let p = node.parent || { raws: {} };
  34837. let childless =
  34838. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  34839. if (!childless || node !== p.last || p.raws.semicolon) {
  34840. if (node.source && node.source.end) {
  34841. mapping.source = this.sourcePath(node);
  34842. mapping.original.line = node.source.end.line;
  34843. mapping.original.column = node.source.end.column - 1;
  34844. mapping.generated.line = line;
  34845. mapping.generated.column = column - 2;
  34846. this.map.addMapping(mapping);
  34847. } else {
  34848. mapping.source = noSource;
  34849. mapping.original.line = 1;
  34850. mapping.original.column = 0;
  34851. mapping.generated.line = line;
  34852. mapping.generated.column = column - 1;
  34853. this.map.addMapping(mapping);
  34854. }
  34855. }
  34856. }
  34857. });
  34858. }
  34859. isAnnotation() {
  34860. if (this.isInline()) {
  34861. return true
  34862. }
  34863. if (typeof this.mapOpts.annotation !== 'undefined') {
  34864. return this.mapOpts.annotation
  34865. }
  34866. if (this.previous().length) {
  34867. return this.previous().some(i => i.annotation)
  34868. }
  34869. return true
  34870. }
  34871. isInline() {
  34872. if (typeof this.mapOpts.inline !== 'undefined') {
  34873. return this.mapOpts.inline
  34874. }
  34875. let annotation = this.mapOpts.annotation;
  34876. if (typeof annotation !== 'undefined' && annotation !== true) {
  34877. return false
  34878. }
  34879. if (this.previous().length) {
  34880. return this.previous().some(i => i.inline)
  34881. }
  34882. return true
  34883. }
  34884. isMap() {
  34885. if (typeof this.opts.map !== 'undefined') {
  34886. return !!this.opts.map
  34887. }
  34888. return this.previous().length > 0
  34889. }
  34890. isSourcesContent() {
  34891. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  34892. return this.mapOpts.sourcesContent
  34893. }
  34894. if (this.previous().length) {
  34895. return this.previous().some(i => i.withContent())
  34896. }
  34897. return true
  34898. }
  34899. outputFile() {
  34900. if (this.opts.to) {
  34901. return this.path(this.opts.to)
  34902. } else if (this.opts.from) {
  34903. return this.path(this.opts.from)
  34904. } else {
  34905. return 'to.css'
  34906. }
  34907. }
  34908. path(file) {
  34909. if (this.mapOpts.absolute) return file
  34910. if (file.charCodeAt(0) === 60 /* `<` */) return file
  34911. if (/^\w+:\/\//.test(file)) return file
  34912. let cached = this.memoizedPaths.get(file);
  34913. if (cached) return cached
  34914. let from = this.opts.to ? dirname(this.opts.to) : '.';
  34915. if (typeof this.mapOpts.annotation === 'string') {
  34916. from = dirname(resolve(from, this.mapOpts.annotation));
  34917. }
  34918. let path = relative(from, file);
  34919. this.memoizedPaths.set(file, path);
  34920. return path
  34921. }
  34922. previous() {
  34923. if (!this.previousMaps) {
  34924. this.previousMaps = [];
  34925. if (this.root) {
  34926. this.root.walk(node => {
  34927. if (node.source && node.source.input.map) {
  34928. let map = node.source.input.map;
  34929. if (!this.previousMaps.includes(map)) {
  34930. this.previousMaps.push(map);
  34931. }
  34932. }
  34933. });
  34934. } else {
  34935. let input = new Input(this.originalCSS, this.opts);
  34936. if (input.map) this.previousMaps.push(input.map);
  34937. }
  34938. }
  34939. return this.previousMaps
  34940. }
  34941. setSourcesContent() {
  34942. let already = {};
  34943. if (this.root) {
  34944. this.root.walk(node => {
  34945. if (node.source) {
  34946. let from = node.source.input.from;
  34947. if (from && !already[from]) {
  34948. already[from] = true;
  34949. let fromUrl = this.usesFileUrls
  34950. ? this.toFileUrl(from)
  34951. : this.toUrl(this.path(from));
  34952. this.map.setSourceContent(fromUrl, node.source.input.css);
  34953. }
  34954. }
  34955. });
  34956. } else if (this.css) {
  34957. let from = this.opts.from
  34958. ? this.toUrl(this.path(this.opts.from))
  34959. : '<no source>';
  34960. this.map.setSourceContent(from, this.css);
  34961. }
  34962. }
  34963. sourcePath(node) {
  34964. if (this.mapOpts.from) {
  34965. return this.toUrl(this.mapOpts.from)
  34966. } else if (this.usesFileUrls) {
  34967. return this.toFileUrl(node.source.input.from)
  34968. } else {
  34969. return this.toUrl(this.path(node.source.input.from))
  34970. }
  34971. }
  34972. toBase64(str) {
  34973. if (Buffer$1) {
  34974. return Buffer$1.from(str).toString('base64')
  34975. } else {
  34976. return window.btoa(unescape(encodeURIComponent(str)))
  34977. }
  34978. }
  34979. toFileUrl(path) {
  34980. let cached = this.memoizedFileURLs.get(path);
  34981. if (cached) return cached
  34982. if (pathToFileURL) {
  34983. let fileURL = pathToFileURL(path).toString();
  34984. this.memoizedFileURLs.set(path, fileURL);
  34985. return fileURL
  34986. } else {
  34987. throw new Error(
  34988. '`map.absolute` option is not available in this PostCSS build'
  34989. )
  34990. }
  34991. }
  34992. toUrl(path) {
  34993. let cached = this.memoizedURLs.get(path);
  34994. if (cached) return cached
  34995. if (sep === '\\') {
  34996. path = path.replace(/\\/g, '/');
  34997. }
  34998. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  34999. this.memoizedURLs.set(path, url);
  35000. return url
  35001. }
  35002. }
  35003. mapGenerator = MapGenerator;
  35004. return mapGenerator;
  35005. }
  35006. var parser$1;
  35007. var hasRequiredParser$1;
  35008. function requireParser$1 () {
  35009. if (hasRequiredParser$1) return parser$1;
  35010. hasRequiredParser$1 = 1;
  35011. let AtRule = /*@__PURE__*/ requireAtRule();
  35012. let Comment = /*@__PURE__*/ requireComment$1();
  35013. let Declaration = /*@__PURE__*/ requireDeclaration();
  35014. let Root = /*@__PURE__*/ requireRoot$1();
  35015. let Rule = /*@__PURE__*/ requireRule();
  35016. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  35017. const SAFE_COMMENT_NEIGHBOR = {
  35018. empty: true,
  35019. space: true
  35020. };
  35021. function findLastWithPosition(tokens) {
  35022. for (let i = tokens.length - 1; i >= 0; i--) {
  35023. let token = tokens[i];
  35024. let pos = token[3] || token[2];
  35025. if (pos) return pos
  35026. }
  35027. }
  35028. class Parser {
  35029. constructor(input) {
  35030. this.input = input;
  35031. this.root = new Root();
  35032. this.current = this.root;
  35033. this.spaces = '';
  35034. this.semicolon = false;
  35035. this.createTokenizer();
  35036. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  35037. }
  35038. atrule(token) {
  35039. let node = new AtRule();
  35040. node.name = token[1].slice(1);
  35041. if (node.name === '') {
  35042. this.unnamedAtrule(node, token);
  35043. }
  35044. this.init(node, token[2]);
  35045. let type;
  35046. let prev;
  35047. let shift;
  35048. let last = false;
  35049. let open = false;
  35050. let params = [];
  35051. let brackets = [];
  35052. while (!this.tokenizer.endOfFile()) {
  35053. token = this.tokenizer.nextToken();
  35054. type = token[0];
  35055. if (type === '(' || type === '[') {
  35056. brackets.push(type === '(' ? ')' : ']');
  35057. } else if (type === '{' && brackets.length > 0) {
  35058. brackets.push('}');
  35059. } else if (type === brackets[brackets.length - 1]) {
  35060. brackets.pop();
  35061. }
  35062. if (brackets.length === 0) {
  35063. if (type === ';') {
  35064. node.source.end = this.getPosition(token[2]);
  35065. node.source.end.offset++;
  35066. this.semicolon = true;
  35067. break
  35068. } else if (type === '{') {
  35069. open = true;
  35070. break
  35071. } else if (type === '}') {
  35072. if (params.length > 0) {
  35073. shift = params.length - 1;
  35074. prev = params[shift];
  35075. while (prev && prev[0] === 'space') {
  35076. prev = params[--shift];
  35077. }
  35078. if (prev) {
  35079. node.source.end = this.getPosition(prev[3] || prev[2]);
  35080. node.source.end.offset++;
  35081. }
  35082. }
  35083. this.end(token);
  35084. break
  35085. } else {
  35086. params.push(token);
  35087. }
  35088. } else {
  35089. params.push(token);
  35090. }
  35091. if (this.tokenizer.endOfFile()) {
  35092. last = true;
  35093. break
  35094. }
  35095. }
  35096. node.raws.between = this.spacesAndCommentsFromEnd(params);
  35097. if (params.length) {
  35098. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  35099. this.raw(node, 'params', params);
  35100. if (last) {
  35101. token = params[params.length - 1];
  35102. node.source.end = this.getPosition(token[3] || token[2]);
  35103. node.source.end.offset++;
  35104. this.spaces = node.raws.between;
  35105. node.raws.between = '';
  35106. }
  35107. } else {
  35108. node.raws.afterName = '';
  35109. node.params = '';
  35110. }
  35111. if (open) {
  35112. node.nodes = [];
  35113. this.current = node;
  35114. }
  35115. }
  35116. checkMissedSemicolon(tokens) {
  35117. let colon = this.colon(tokens);
  35118. if (colon === false) return
  35119. let founded = 0;
  35120. let token;
  35121. for (let j = colon - 1; j >= 0; j--) {
  35122. token = tokens[j];
  35123. if (token[0] !== 'space') {
  35124. founded += 1;
  35125. if (founded === 2) break
  35126. }
  35127. }
  35128. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35129. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35130. // And because we need it after that one we do +1 to get the next one.
  35131. throw this.input.error(
  35132. 'Missed semicolon',
  35133. token[0] === 'word' ? token[3] + 1 : token[2]
  35134. )
  35135. }
  35136. colon(tokens) {
  35137. let brackets = 0;
  35138. let prev, token, type;
  35139. for (let [i, element] of tokens.entries()) {
  35140. token = element;
  35141. type = token[0];
  35142. if (type === '(') {
  35143. brackets += 1;
  35144. }
  35145. if (type === ')') {
  35146. brackets -= 1;
  35147. }
  35148. if (brackets === 0 && type === ':') {
  35149. if (!prev) {
  35150. this.doubleColon(token);
  35151. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  35152. continue
  35153. } else {
  35154. return i
  35155. }
  35156. }
  35157. prev = token;
  35158. }
  35159. return false
  35160. }
  35161. comment(token) {
  35162. let node = new Comment();
  35163. this.init(node, token[2]);
  35164. node.source.end = this.getPosition(token[3] || token[2]);
  35165. node.source.end.offset++;
  35166. let text = token[1].slice(2, -2);
  35167. if (/^\s*$/.test(text)) {
  35168. node.text = '';
  35169. node.raws.left = text;
  35170. node.raws.right = '';
  35171. } else {
  35172. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  35173. node.text = match[2];
  35174. node.raws.left = match[1];
  35175. node.raws.right = match[3];
  35176. }
  35177. }
  35178. createTokenizer() {
  35179. this.tokenizer = tokenizer(this.input);
  35180. }
  35181. decl(tokens, customProperty) {
  35182. let node = new Declaration();
  35183. this.init(node, tokens[0][2]);
  35184. let last = tokens[tokens.length - 1];
  35185. if (last[0] === ';') {
  35186. this.semicolon = true;
  35187. tokens.pop();
  35188. }
  35189. node.source.end = this.getPosition(
  35190. last[3] || last[2] || findLastWithPosition(tokens)
  35191. );
  35192. node.source.end.offset++;
  35193. while (tokens[0][0] !== 'word') {
  35194. if (tokens.length === 1) this.unknownWord(tokens);
  35195. node.raws.before += tokens.shift()[1];
  35196. }
  35197. node.source.start = this.getPosition(tokens[0][2]);
  35198. node.prop = '';
  35199. while (tokens.length) {
  35200. let type = tokens[0][0];
  35201. if (type === ':' || type === 'space' || type === 'comment') {
  35202. break
  35203. }
  35204. node.prop += tokens.shift()[1];
  35205. }
  35206. node.raws.between = '';
  35207. let token;
  35208. while (tokens.length) {
  35209. token = tokens.shift();
  35210. if (token[0] === ':') {
  35211. node.raws.between += token[1];
  35212. break
  35213. } else {
  35214. if (token[0] === 'word' && /\w/.test(token[1])) {
  35215. this.unknownWord([token]);
  35216. }
  35217. node.raws.between += token[1];
  35218. }
  35219. }
  35220. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35221. node.raws.before += node.prop[0];
  35222. node.prop = node.prop.slice(1);
  35223. }
  35224. let firstSpaces = [];
  35225. let next;
  35226. while (tokens.length) {
  35227. next = tokens[0][0];
  35228. if (next !== 'space' && next !== 'comment') break
  35229. firstSpaces.push(tokens.shift());
  35230. }
  35231. this.precheckMissedSemicolon(tokens);
  35232. for (let i = tokens.length - 1; i >= 0; i--) {
  35233. token = tokens[i];
  35234. if (token[1].toLowerCase() === '!important') {
  35235. node.important = true;
  35236. let string = this.stringFrom(tokens, i);
  35237. string = this.spacesFromEnd(tokens) + string;
  35238. if (string !== ' !important') node.raws.important = string;
  35239. break
  35240. } else if (token[1].toLowerCase() === 'important') {
  35241. let cache = tokens.slice(0);
  35242. let str = '';
  35243. for (let j = i; j > 0; j--) {
  35244. let type = cache[j][0];
  35245. if (str.trim().startsWith('!') && type !== 'space') {
  35246. break
  35247. }
  35248. str = cache.pop()[1] + str;
  35249. }
  35250. if (str.trim().startsWith('!')) {
  35251. node.important = true;
  35252. node.raws.important = str;
  35253. tokens = cache;
  35254. }
  35255. }
  35256. if (token[0] !== 'space' && token[0] !== 'comment') {
  35257. break
  35258. }
  35259. }
  35260. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35261. if (hasWord) {
  35262. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35263. firstSpaces = [];
  35264. }
  35265. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35266. if (node.value.includes(':') && !customProperty) {
  35267. this.checkMissedSemicolon(tokens);
  35268. }
  35269. }
  35270. doubleColon(token) {
  35271. throw this.input.error(
  35272. 'Double colon',
  35273. { offset: token[2] },
  35274. { offset: token[2] + token[1].length }
  35275. )
  35276. }
  35277. emptyRule(token) {
  35278. let node = new Rule();
  35279. this.init(node, token[2]);
  35280. node.selector = '';
  35281. node.raws.between = '';
  35282. this.current = node;
  35283. }
  35284. end(token) {
  35285. if (this.current.nodes && this.current.nodes.length) {
  35286. this.current.raws.semicolon = this.semicolon;
  35287. }
  35288. this.semicolon = false;
  35289. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35290. this.spaces = '';
  35291. if (this.current.parent) {
  35292. this.current.source.end = this.getPosition(token[2]);
  35293. this.current.source.end.offset++;
  35294. this.current = this.current.parent;
  35295. } else {
  35296. this.unexpectedClose(token);
  35297. }
  35298. }
  35299. endFile() {
  35300. if (this.current.parent) this.unclosedBlock();
  35301. if (this.current.nodes && this.current.nodes.length) {
  35302. this.current.raws.semicolon = this.semicolon;
  35303. }
  35304. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35305. this.root.source.end = this.getPosition(this.tokenizer.position());
  35306. }
  35307. freeSemicolon(token) {
  35308. this.spaces += token[1];
  35309. if (this.current.nodes) {
  35310. let prev = this.current.nodes[this.current.nodes.length - 1];
  35311. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35312. prev.raws.ownSemicolon = this.spaces;
  35313. this.spaces = '';
  35314. prev.source.end = this.getPosition(token[2]);
  35315. prev.source.end.offset += prev.raws.ownSemicolon.length;
  35316. }
  35317. }
  35318. }
  35319. // Helpers
  35320. getPosition(offset) {
  35321. let pos = this.input.fromOffset(offset);
  35322. return {
  35323. column: pos.col,
  35324. line: pos.line,
  35325. offset
  35326. }
  35327. }
  35328. init(node, offset) {
  35329. this.current.push(node);
  35330. node.source = {
  35331. input: this.input,
  35332. start: this.getPosition(offset)
  35333. };
  35334. node.raws.before = this.spaces;
  35335. this.spaces = '';
  35336. if (node.type !== 'comment') this.semicolon = false;
  35337. }
  35338. other(start) {
  35339. let end = false;
  35340. let type = null;
  35341. let colon = false;
  35342. let bracket = null;
  35343. let brackets = [];
  35344. let customProperty = start[1].startsWith('--');
  35345. let tokens = [];
  35346. let token = start;
  35347. while (token) {
  35348. type = token[0];
  35349. tokens.push(token);
  35350. if (type === '(' || type === '[') {
  35351. if (!bracket) bracket = token;
  35352. brackets.push(type === '(' ? ')' : ']');
  35353. } else if (customProperty && colon && type === '{') {
  35354. if (!bracket) bracket = token;
  35355. brackets.push('}');
  35356. } else if (brackets.length === 0) {
  35357. if (type === ';') {
  35358. if (colon) {
  35359. this.decl(tokens, customProperty);
  35360. return
  35361. } else {
  35362. break
  35363. }
  35364. } else if (type === '{') {
  35365. this.rule(tokens);
  35366. return
  35367. } else if (type === '}') {
  35368. this.tokenizer.back(tokens.pop());
  35369. end = true;
  35370. break
  35371. } else if (type === ':') {
  35372. colon = true;
  35373. }
  35374. } else if (type === brackets[brackets.length - 1]) {
  35375. brackets.pop();
  35376. if (brackets.length === 0) bracket = null;
  35377. }
  35378. token = this.tokenizer.nextToken();
  35379. }
  35380. if (this.tokenizer.endOfFile()) end = true;
  35381. if (brackets.length > 0) this.unclosedBracket(bracket);
  35382. if (end && colon) {
  35383. if (!customProperty) {
  35384. while (tokens.length) {
  35385. token = tokens[tokens.length - 1][0];
  35386. if (token !== 'space' && token !== 'comment') break
  35387. this.tokenizer.back(tokens.pop());
  35388. }
  35389. }
  35390. this.decl(tokens, customProperty);
  35391. } else {
  35392. this.unknownWord(tokens);
  35393. }
  35394. }
  35395. parse() {
  35396. let token;
  35397. while (!this.tokenizer.endOfFile()) {
  35398. token = this.tokenizer.nextToken();
  35399. switch (token[0]) {
  35400. case 'space':
  35401. this.spaces += token[1];
  35402. break
  35403. case ';':
  35404. this.freeSemicolon(token);
  35405. break
  35406. case '}':
  35407. this.end(token);
  35408. break
  35409. case 'comment':
  35410. this.comment(token);
  35411. break
  35412. case 'at-word':
  35413. this.atrule(token);
  35414. break
  35415. case '{':
  35416. this.emptyRule(token);
  35417. break
  35418. default:
  35419. this.other(token);
  35420. break
  35421. }
  35422. }
  35423. this.endFile();
  35424. }
  35425. precheckMissedSemicolon(/* tokens */) {
  35426. // Hook for Safe Parser
  35427. }
  35428. raw(node, prop, tokens, customProperty) {
  35429. let token, type;
  35430. let length = tokens.length;
  35431. let value = '';
  35432. let clean = true;
  35433. let next, prev;
  35434. for (let i = 0; i < length; i += 1) {
  35435. token = tokens[i];
  35436. type = token[0];
  35437. if (type === 'space' && i === length - 1 && !customProperty) {
  35438. clean = false;
  35439. } else if (type === 'comment') {
  35440. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35441. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35442. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35443. if (value.slice(-1) === ',') {
  35444. clean = false;
  35445. } else {
  35446. value += token[1];
  35447. }
  35448. } else {
  35449. clean = false;
  35450. }
  35451. } else {
  35452. value += token[1];
  35453. }
  35454. }
  35455. if (!clean) {
  35456. let raw = tokens.reduce((all, i) => all + i[1], '');
  35457. node.raws[prop] = { raw, value };
  35458. }
  35459. node[prop] = value;
  35460. }
  35461. rule(tokens) {
  35462. tokens.pop();
  35463. let node = new Rule();
  35464. this.init(node, tokens[0][2]);
  35465. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35466. this.raw(node, 'selector', tokens);
  35467. this.current = node;
  35468. }
  35469. spacesAndCommentsFromEnd(tokens) {
  35470. let lastTokenType;
  35471. let spaces = '';
  35472. while (tokens.length) {
  35473. lastTokenType = tokens[tokens.length - 1][0];
  35474. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35475. spaces = tokens.pop()[1] + spaces;
  35476. }
  35477. return spaces
  35478. }
  35479. // Errors
  35480. spacesAndCommentsFromStart(tokens) {
  35481. let next;
  35482. let spaces = '';
  35483. while (tokens.length) {
  35484. next = tokens[0][0];
  35485. if (next !== 'space' && next !== 'comment') break
  35486. spaces += tokens.shift()[1];
  35487. }
  35488. return spaces
  35489. }
  35490. spacesFromEnd(tokens) {
  35491. let lastTokenType;
  35492. let spaces = '';
  35493. while (tokens.length) {
  35494. lastTokenType = tokens[tokens.length - 1][0];
  35495. if (lastTokenType !== 'space') break
  35496. spaces = tokens.pop()[1] + spaces;
  35497. }
  35498. return spaces
  35499. }
  35500. stringFrom(tokens, from) {
  35501. let result = '';
  35502. for (let i = from; i < tokens.length; i++) {
  35503. result += tokens[i][1];
  35504. }
  35505. tokens.splice(from, tokens.length - from);
  35506. return result
  35507. }
  35508. unclosedBlock() {
  35509. let pos = this.current.source.start;
  35510. throw this.input.error('Unclosed block', pos.line, pos.column)
  35511. }
  35512. unclosedBracket(bracket) {
  35513. throw this.input.error(
  35514. 'Unclosed bracket',
  35515. { offset: bracket[2] },
  35516. { offset: bracket[2] + 1 }
  35517. )
  35518. }
  35519. unexpectedClose(token) {
  35520. throw this.input.error(
  35521. 'Unexpected }',
  35522. { offset: token[2] },
  35523. { offset: token[2] + 1 }
  35524. )
  35525. }
  35526. unknownWord(tokens) {
  35527. throw this.input.error(
  35528. 'Unknown word ' + tokens[0][1],
  35529. { offset: tokens[0][2] },
  35530. { offset: tokens[0][2] + tokens[0][1].length }
  35531. )
  35532. }
  35533. unnamedAtrule(node, token) {
  35534. throw this.input.error(
  35535. 'At-rule without name',
  35536. { offset: token[2] },
  35537. { offset: token[2] + token[1].length }
  35538. )
  35539. }
  35540. }
  35541. parser$1 = Parser;
  35542. return parser$1;
  35543. }
  35544. var parse_1;
  35545. var hasRequiredParse;
  35546. function requireParse () {
  35547. if (hasRequiredParse) return parse_1;
  35548. hasRequiredParse = 1;
  35549. let Container = /*@__PURE__*/ requireContainer$1();
  35550. let Input = /*@__PURE__*/ requireInput();
  35551. let Parser = /*@__PURE__*/ requireParser$1();
  35552. function parse(css, opts) {
  35553. let input = new Input(css, opts);
  35554. let parser = new Parser(input);
  35555. try {
  35556. parser.parse();
  35557. } catch (e) {
  35558. if (browser$1.env.NODE_ENV !== 'production') {
  35559. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35560. if (/\.scss$/i.test(opts.from)) {
  35561. e.message +=
  35562. '\nYou tried to parse SCSS with ' +
  35563. 'the standard CSS parser; ' +
  35564. 'try again with the postcss-scss parser';
  35565. } else if (/\.sass/i.test(opts.from)) {
  35566. e.message +=
  35567. '\nYou tried to parse Sass with ' +
  35568. 'the standard CSS parser; ' +
  35569. 'try again with the postcss-sass parser';
  35570. } else if (/\.less$/i.test(opts.from)) {
  35571. e.message +=
  35572. '\nYou tried to parse Less with ' +
  35573. 'the standard CSS parser; ' +
  35574. 'try again with the postcss-less parser';
  35575. }
  35576. }
  35577. }
  35578. throw e
  35579. }
  35580. return parser.root
  35581. }
  35582. parse_1 = parse;
  35583. parse.default = parse;
  35584. Container.registerParse(parse);
  35585. return parse_1;
  35586. }
  35587. var warning;
  35588. var hasRequiredWarning;
  35589. function requireWarning () {
  35590. if (hasRequiredWarning) return warning;
  35591. hasRequiredWarning = 1;
  35592. class Warning {
  35593. constructor(text, opts = {}) {
  35594. this.type = 'warning';
  35595. this.text = text;
  35596. if (opts.node && opts.node.source) {
  35597. let range = opts.node.rangeBy(opts);
  35598. this.line = range.start.line;
  35599. this.column = range.start.column;
  35600. this.endLine = range.end.line;
  35601. this.endColumn = range.end.column;
  35602. }
  35603. for (let opt in opts) this[opt] = opts[opt];
  35604. }
  35605. toString() {
  35606. if (this.node) {
  35607. return this.node.error(this.text, {
  35608. index: this.index,
  35609. plugin: this.plugin,
  35610. word: this.word
  35611. }).message
  35612. }
  35613. if (this.plugin) {
  35614. return this.plugin + ': ' + this.text
  35615. }
  35616. return this.text
  35617. }
  35618. }
  35619. warning = Warning;
  35620. Warning.default = Warning;
  35621. return warning;
  35622. }
  35623. var result;
  35624. var hasRequiredResult;
  35625. function requireResult () {
  35626. if (hasRequiredResult) return result;
  35627. hasRequiredResult = 1;
  35628. let Warning = /*@__PURE__*/ requireWarning();
  35629. class Result {
  35630. get content() {
  35631. return this.css
  35632. }
  35633. constructor(processor, root, opts) {
  35634. this.processor = processor;
  35635. this.messages = [];
  35636. this.root = root;
  35637. this.opts = opts;
  35638. this.css = '';
  35639. this.map = undefined;
  35640. }
  35641. toString() {
  35642. return this.css
  35643. }
  35644. warn(text, opts = {}) {
  35645. if (!opts.plugin) {
  35646. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  35647. opts.plugin = this.lastPlugin.postcssPlugin;
  35648. }
  35649. }
  35650. let warning = new Warning(text, opts);
  35651. this.messages.push(warning);
  35652. return warning
  35653. }
  35654. warnings() {
  35655. return this.messages.filter(i => i.type === 'warning')
  35656. }
  35657. }
  35658. result = Result;
  35659. Result.default = Result;
  35660. return result;
  35661. }
  35662. /* eslint-disable no-console */
  35663. var warnOnce;
  35664. var hasRequiredWarnOnce;
  35665. function requireWarnOnce () {
  35666. if (hasRequiredWarnOnce) return warnOnce;
  35667. hasRequiredWarnOnce = 1;
  35668. let printed = {};
  35669. warnOnce = function warnOnce(message) {
  35670. if (printed[message]) return
  35671. printed[message] = true;
  35672. if (typeof console !== 'undefined' && console.warn) {
  35673. console.warn(message);
  35674. }
  35675. };
  35676. return warnOnce;
  35677. }
  35678. var lazyResult;
  35679. var hasRequiredLazyResult;
  35680. function requireLazyResult () {
  35681. if (hasRequiredLazyResult) return lazyResult;
  35682. hasRequiredLazyResult = 1;
  35683. let Container = /*@__PURE__*/ requireContainer$1();
  35684. let Document = /*@__PURE__*/ requireDocument();
  35685. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  35686. let parse = /*@__PURE__*/ requireParse();
  35687. let Result = /*@__PURE__*/ requireResult();
  35688. let Root = /*@__PURE__*/ requireRoot$1();
  35689. let stringify = /*@__PURE__*/ requireStringify();
  35690. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  35691. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  35692. const TYPE_TO_CLASS_NAME = {
  35693. atrule: 'AtRule',
  35694. comment: 'Comment',
  35695. decl: 'Declaration',
  35696. document: 'Document',
  35697. root: 'Root',
  35698. rule: 'Rule'
  35699. };
  35700. const PLUGIN_PROPS = {
  35701. AtRule: true,
  35702. AtRuleExit: true,
  35703. Comment: true,
  35704. CommentExit: true,
  35705. Declaration: true,
  35706. DeclarationExit: true,
  35707. Document: true,
  35708. DocumentExit: true,
  35709. Once: true,
  35710. OnceExit: true,
  35711. postcssPlugin: true,
  35712. prepare: true,
  35713. Root: true,
  35714. RootExit: true,
  35715. Rule: true,
  35716. RuleExit: true
  35717. };
  35718. const NOT_VISITORS = {
  35719. Once: true,
  35720. postcssPlugin: true,
  35721. prepare: true
  35722. };
  35723. const CHILDREN = 0;
  35724. function isPromise(obj) {
  35725. return typeof obj === 'object' && typeof obj.then === 'function'
  35726. }
  35727. function getEvents(node) {
  35728. let key = false;
  35729. let type = TYPE_TO_CLASS_NAME[node.type];
  35730. if (node.type === 'decl') {
  35731. key = node.prop.toLowerCase();
  35732. } else if (node.type === 'atrule') {
  35733. key = node.name.toLowerCase();
  35734. }
  35735. if (key && node.append) {
  35736. return [
  35737. type,
  35738. type + '-' + key,
  35739. CHILDREN,
  35740. type + 'Exit',
  35741. type + 'Exit-' + key
  35742. ]
  35743. } else if (key) {
  35744. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35745. } else if (node.append) {
  35746. return [type, CHILDREN, type + 'Exit']
  35747. } else {
  35748. return [type, type + 'Exit']
  35749. }
  35750. }
  35751. function toStack(node) {
  35752. let events;
  35753. if (node.type === 'document') {
  35754. events = ['Document', CHILDREN, 'DocumentExit'];
  35755. } else if (node.type === 'root') {
  35756. events = ['Root', CHILDREN, 'RootExit'];
  35757. } else {
  35758. events = getEvents(node);
  35759. }
  35760. return {
  35761. eventIndex: 0,
  35762. events,
  35763. iterator: 0,
  35764. node,
  35765. visitorIndex: 0,
  35766. visitors: []
  35767. }
  35768. }
  35769. function cleanMarks(node) {
  35770. node[isClean] = false;
  35771. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  35772. return node
  35773. }
  35774. let postcss = {};
  35775. class LazyResult {
  35776. get content() {
  35777. return this.stringify().content
  35778. }
  35779. get css() {
  35780. return this.stringify().css
  35781. }
  35782. get map() {
  35783. return this.stringify().map
  35784. }
  35785. get messages() {
  35786. return this.sync().messages
  35787. }
  35788. get opts() {
  35789. return this.result.opts
  35790. }
  35791. get processor() {
  35792. return this.result.processor
  35793. }
  35794. get root() {
  35795. return this.sync().root
  35796. }
  35797. get [Symbol.toStringTag]() {
  35798. return 'LazyResult'
  35799. }
  35800. constructor(processor, css, opts) {
  35801. this.stringified = false;
  35802. this.processed = false;
  35803. let root;
  35804. if (
  35805. typeof css === 'object' &&
  35806. css !== null &&
  35807. (css.type === 'root' || css.type === 'document')
  35808. ) {
  35809. root = cleanMarks(css);
  35810. } else if (css instanceof LazyResult || css instanceof Result) {
  35811. root = cleanMarks(css.root);
  35812. if (css.map) {
  35813. if (typeof opts.map === 'undefined') opts.map = {};
  35814. if (!opts.map.inline) opts.map.inline = false;
  35815. opts.map.prev = css.map;
  35816. }
  35817. } else {
  35818. let parser = parse;
  35819. if (opts.syntax) parser = opts.syntax.parse;
  35820. if (opts.parser) parser = opts.parser;
  35821. if (parser.parse) parser = parser.parse;
  35822. try {
  35823. root = parser(css, opts);
  35824. } catch (error) {
  35825. this.processed = true;
  35826. this.error = error;
  35827. }
  35828. if (root && !root[my]) {
  35829. /* c8 ignore next 2 */
  35830. Container.rebuild(root);
  35831. }
  35832. }
  35833. this.result = new Result(processor, root, opts);
  35834. this.helpers = { ...postcss, postcss, result: this.result };
  35835. this.plugins = this.processor.plugins.map(plugin => {
  35836. if (typeof plugin === 'object' && plugin.prepare) {
  35837. return { ...plugin, ...plugin.prepare(this.result) }
  35838. } else {
  35839. return plugin
  35840. }
  35841. });
  35842. }
  35843. async() {
  35844. if (this.error) return Promise.reject(this.error)
  35845. if (this.processed) return Promise.resolve(this.result)
  35846. if (!this.processing) {
  35847. this.processing = this.runAsync();
  35848. }
  35849. return this.processing
  35850. }
  35851. catch(onRejected) {
  35852. return this.async().catch(onRejected)
  35853. }
  35854. finally(onFinally) {
  35855. return this.async().then(onFinally, onFinally)
  35856. }
  35857. getAsyncError() {
  35858. throw new Error('Use process(css).then(cb) to work with async plugins')
  35859. }
  35860. handleError(error, node) {
  35861. let plugin = this.result.lastPlugin;
  35862. try {
  35863. if (node) node.addToError(error);
  35864. this.error = error;
  35865. if (error.name === 'CssSyntaxError' && !error.plugin) {
  35866. error.plugin = plugin.postcssPlugin;
  35867. error.setMessage();
  35868. } else if (plugin.postcssVersion) {
  35869. if (browser$1.env.NODE_ENV !== 'production') {
  35870. let pluginName = plugin.postcssPlugin;
  35871. let pluginVer = plugin.postcssVersion;
  35872. let runtimeVer = this.result.processor.version;
  35873. let a = pluginVer.split('.');
  35874. let b = runtimeVer.split('.');
  35875. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  35876. // eslint-disable-next-line no-console
  35877. console.error(
  35878. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  35879. 'version is ' +
  35880. runtimeVer +
  35881. ', but ' +
  35882. pluginName +
  35883. ' uses ' +
  35884. pluginVer +
  35885. '. Perhaps this is the source of the error below.'
  35886. );
  35887. }
  35888. }
  35889. }
  35890. } catch (err) {
  35891. /* c8 ignore next 3 */
  35892. // eslint-disable-next-line no-console
  35893. if (console && console.error) console.error(err);
  35894. }
  35895. return error
  35896. }
  35897. prepareVisitors() {
  35898. this.listeners = {};
  35899. let add = (plugin, type, cb) => {
  35900. if (!this.listeners[type]) this.listeners[type] = [];
  35901. this.listeners[type].push([plugin, cb]);
  35902. };
  35903. for (let plugin of this.plugins) {
  35904. if (typeof plugin === 'object') {
  35905. for (let event in plugin) {
  35906. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  35907. throw new Error(
  35908. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  35909. `Try to update PostCSS (${this.processor.version} now).`
  35910. )
  35911. }
  35912. if (!NOT_VISITORS[event]) {
  35913. if (typeof plugin[event] === 'object') {
  35914. for (let filter in plugin[event]) {
  35915. if (filter === '*') {
  35916. add(plugin, event, plugin[event][filter]);
  35917. } else {
  35918. add(
  35919. plugin,
  35920. event + '-' + filter.toLowerCase(),
  35921. plugin[event][filter]
  35922. );
  35923. }
  35924. }
  35925. } else if (typeof plugin[event] === 'function') {
  35926. add(plugin, event, plugin[event]);
  35927. }
  35928. }
  35929. }
  35930. }
  35931. }
  35932. this.hasListener = Object.keys(this.listeners).length > 0;
  35933. }
  35934. async runAsync() {
  35935. this.plugin = 0;
  35936. for (let i = 0; i < this.plugins.length; i++) {
  35937. let plugin = this.plugins[i];
  35938. let promise = this.runOnRoot(plugin);
  35939. if (isPromise(promise)) {
  35940. try {
  35941. await promise;
  35942. } catch (error) {
  35943. throw this.handleError(error)
  35944. }
  35945. }
  35946. }
  35947. this.prepareVisitors();
  35948. if (this.hasListener) {
  35949. let root = this.result.root;
  35950. while (!root[isClean]) {
  35951. root[isClean] = true;
  35952. let stack = [toStack(root)];
  35953. while (stack.length > 0) {
  35954. let promise = this.visitTick(stack);
  35955. if (isPromise(promise)) {
  35956. try {
  35957. await promise;
  35958. } catch (e) {
  35959. let node = stack[stack.length - 1].node;
  35960. throw this.handleError(e, node)
  35961. }
  35962. }
  35963. }
  35964. }
  35965. if (this.listeners.OnceExit) {
  35966. for (let [plugin, visitor] of this.listeners.OnceExit) {
  35967. this.result.lastPlugin = plugin;
  35968. try {
  35969. if (root.type === 'document') {
  35970. let roots = root.nodes.map(subRoot =>
  35971. visitor(subRoot, this.helpers)
  35972. );
  35973. await Promise.all(roots);
  35974. } else {
  35975. await visitor(root, this.helpers);
  35976. }
  35977. } catch (e) {
  35978. throw this.handleError(e)
  35979. }
  35980. }
  35981. }
  35982. }
  35983. this.processed = true;
  35984. return this.stringify()
  35985. }
  35986. runOnRoot(plugin) {
  35987. this.result.lastPlugin = plugin;
  35988. try {
  35989. if (typeof plugin === 'object' && plugin.Once) {
  35990. if (this.result.root.type === 'document') {
  35991. let roots = this.result.root.nodes.map(root =>
  35992. plugin.Once(root, this.helpers)
  35993. );
  35994. if (isPromise(roots[0])) {
  35995. return Promise.all(roots)
  35996. }
  35997. return roots
  35998. }
  35999. return plugin.Once(this.result.root, this.helpers)
  36000. } else if (typeof plugin === 'function') {
  36001. return plugin(this.result.root, this.result)
  36002. }
  36003. } catch (error) {
  36004. throw this.handleError(error)
  36005. }
  36006. }
  36007. stringify() {
  36008. if (this.error) throw this.error
  36009. if (this.stringified) return this.result
  36010. this.stringified = true;
  36011. this.sync();
  36012. let opts = this.result.opts;
  36013. let str = stringify;
  36014. if (opts.syntax) str = opts.syntax.stringify;
  36015. if (opts.stringifier) str = opts.stringifier;
  36016. if (str.stringify) str = str.stringify;
  36017. let map = new MapGenerator(str, this.result.root, this.result.opts);
  36018. let data = map.generate();
  36019. this.result.css = data[0];
  36020. this.result.map = data[1];
  36021. return this.result
  36022. }
  36023. sync() {
  36024. if (this.error) throw this.error
  36025. if (this.processed) return this.result
  36026. this.processed = true;
  36027. if (this.processing) {
  36028. throw this.getAsyncError()
  36029. }
  36030. for (let plugin of this.plugins) {
  36031. let promise = this.runOnRoot(plugin);
  36032. if (isPromise(promise)) {
  36033. throw this.getAsyncError()
  36034. }
  36035. }
  36036. this.prepareVisitors();
  36037. if (this.hasListener) {
  36038. let root = this.result.root;
  36039. while (!root[isClean]) {
  36040. root[isClean] = true;
  36041. this.walkSync(root);
  36042. }
  36043. if (this.listeners.OnceExit) {
  36044. if (root.type === 'document') {
  36045. for (let subRoot of root.nodes) {
  36046. this.visitSync(this.listeners.OnceExit, subRoot);
  36047. }
  36048. } else {
  36049. this.visitSync(this.listeners.OnceExit, root);
  36050. }
  36051. }
  36052. }
  36053. return this.result
  36054. }
  36055. then(onFulfilled, onRejected) {
  36056. if (browser$1.env.NODE_ENV !== 'production') {
  36057. if (!('from' in this.opts)) {
  36058. warnOnce(
  36059. 'Without `from` option PostCSS could generate wrong source map ' +
  36060. 'and will not find Browserslist config. Set it to CSS file path ' +
  36061. 'or to `undefined` to prevent this warning.'
  36062. );
  36063. }
  36064. }
  36065. return this.async().then(onFulfilled, onRejected)
  36066. }
  36067. toString() {
  36068. return this.css
  36069. }
  36070. visitSync(visitors, node) {
  36071. for (let [plugin, visitor] of visitors) {
  36072. this.result.lastPlugin = plugin;
  36073. let promise;
  36074. try {
  36075. promise = visitor(node, this.helpers);
  36076. } catch (e) {
  36077. throw this.handleError(e, node.proxyOf)
  36078. }
  36079. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36080. return true
  36081. }
  36082. if (isPromise(promise)) {
  36083. throw this.getAsyncError()
  36084. }
  36085. }
  36086. }
  36087. visitTick(stack) {
  36088. let visit = stack[stack.length - 1];
  36089. let { node, visitors } = visit;
  36090. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36091. stack.pop();
  36092. return
  36093. }
  36094. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  36095. let [plugin, visitor] = visitors[visit.visitorIndex];
  36096. visit.visitorIndex += 1;
  36097. if (visit.visitorIndex === visitors.length) {
  36098. visit.visitors = [];
  36099. visit.visitorIndex = 0;
  36100. }
  36101. this.result.lastPlugin = plugin;
  36102. try {
  36103. return visitor(node.toProxy(), this.helpers)
  36104. } catch (e) {
  36105. throw this.handleError(e, node)
  36106. }
  36107. }
  36108. if (visit.iterator !== 0) {
  36109. let iterator = visit.iterator;
  36110. let child;
  36111. while ((child = node.nodes[node.indexes[iterator]])) {
  36112. node.indexes[iterator] += 1;
  36113. if (!child[isClean]) {
  36114. child[isClean] = true;
  36115. stack.push(toStack(child));
  36116. return
  36117. }
  36118. }
  36119. visit.iterator = 0;
  36120. delete node.indexes[iterator];
  36121. }
  36122. let events = visit.events;
  36123. while (visit.eventIndex < events.length) {
  36124. let event = events[visit.eventIndex];
  36125. visit.eventIndex += 1;
  36126. if (event === CHILDREN) {
  36127. if (node.nodes && node.nodes.length) {
  36128. node[isClean] = true;
  36129. visit.iterator = node.getIterator();
  36130. }
  36131. return
  36132. } else if (this.listeners[event]) {
  36133. visit.visitors = this.listeners[event];
  36134. return
  36135. }
  36136. }
  36137. stack.pop();
  36138. }
  36139. walkSync(node) {
  36140. node[isClean] = true;
  36141. let events = getEvents(node);
  36142. for (let event of events) {
  36143. if (event === CHILDREN) {
  36144. if (node.nodes) {
  36145. node.each(child => {
  36146. if (!child[isClean]) this.walkSync(child);
  36147. });
  36148. }
  36149. } else {
  36150. let visitors = this.listeners[event];
  36151. if (visitors) {
  36152. if (this.visitSync(visitors, node.toProxy())) return
  36153. }
  36154. }
  36155. }
  36156. }
  36157. warnings() {
  36158. return this.sync().warnings()
  36159. }
  36160. }
  36161. LazyResult.registerPostcss = dependant => {
  36162. postcss = dependant;
  36163. };
  36164. lazyResult = LazyResult;
  36165. LazyResult.default = LazyResult;
  36166. Root.registerLazyResult(LazyResult);
  36167. Document.registerLazyResult(LazyResult);
  36168. return lazyResult;
  36169. }
  36170. var noWorkResult;
  36171. var hasRequiredNoWorkResult;
  36172. function requireNoWorkResult () {
  36173. if (hasRequiredNoWorkResult) return noWorkResult;
  36174. hasRequiredNoWorkResult = 1;
  36175. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  36176. let parse = /*@__PURE__*/ requireParse();
  36177. const Result = /*@__PURE__*/ requireResult();
  36178. let stringify = /*@__PURE__*/ requireStringify();
  36179. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  36180. class NoWorkResult {
  36181. get content() {
  36182. return this.result.css
  36183. }
  36184. get css() {
  36185. return this.result.css
  36186. }
  36187. get map() {
  36188. return this.result.map
  36189. }
  36190. get messages() {
  36191. return []
  36192. }
  36193. get opts() {
  36194. return this.result.opts
  36195. }
  36196. get processor() {
  36197. return this.result.processor
  36198. }
  36199. get root() {
  36200. if (this._root) {
  36201. return this._root
  36202. }
  36203. let root;
  36204. let parser = parse;
  36205. try {
  36206. root = parser(this._css, this._opts);
  36207. } catch (error) {
  36208. this.error = error;
  36209. }
  36210. if (this.error) {
  36211. throw this.error
  36212. } else {
  36213. this._root = root;
  36214. return root
  36215. }
  36216. }
  36217. get [Symbol.toStringTag]() {
  36218. return 'NoWorkResult'
  36219. }
  36220. constructor(processor, css, opts) {
  36221. css = css.toString();
  36222. this.stringified = false;
  36223. this._processor = processor;
  36224. this._css = css;
  36225. this._opts = opts;
  36226. this._map = undefined;
  36227. let root;
  36228. let str = stringify;
  36229. this.result = new Result(this._processor, root, this._opts);
  36230. this.result.css = css;
  36231. let self = this;
  36232. Object.defineProperty(this.result, 'root', {
  36233. get() {
  36234. return self.root
  36235. }
  36236. });
  36237. let map = new MapGenerator(str, root, this._opts, css);
  36238. if (map.isMap()) {
  36239. let [generatedCSS, generatedMap] = map.generate();
  36240. if (generatedCSS) {
  36241. this.result.css = generatedCSS;
  36242. }
  36243. if (generatedMap) {
  36244. this.result.map = generatedMap;
  36245. }
  36246. } else {
  36247. map.clearAnnotation();
  36248. this.result.css = map.css;
  36249. }
  36250. }
  36251. async() {
  36252. if (this.error) return Promise.reject(this.error)
  36253. return Promise.resolve(this.result)
  36254. }
  36255. catch(onRejected) {
  36256. return this.async().catch(onRejected)
  36257. }
  36258. finally(onFinally) {
  36259. return this.async().then(onFinally, onFinally)
  36260. }
  36261. sync() {
  36262. if (this.error) throw this.error
  36263. return this.result
  36264. }
  36265. then(onFulfilled, onRejected) {
  36266. if (browser$1.env.NODE_ENV !== 'production') {
  36267. if (!('from' in this._opts)) {
  36268. warnOnce(
  36269. 'Without `from` option PostCSS could generate wrong source map ' +
  36270. 'and will not find Browserslist config. Set it to CSS file path ' +
  36271. 'or to `undefined` to prevent this warning.'
  36272. );
  36273. }
  36274. }
  36275. return this.async().then(onFulfilled, onRejected)
  36276. }
  36277. toString() {
  36278. return this._css
  36279. }
  36280. warnings() {
  36281. return []
  36282. }
  36283. }
  36284. noWorkResult = NoWorkResult;
  36285. NoWorkResult.default = NoWorkResult;
  36286. return noWorkResult;
  36287. }
  36288. var processor$1;
  36289. var hasRequiredProcessor$1;
  36290. function requireProcessor$1 () {
  36291. if (hasRequiredProcessor$1) return processor$1;
  36292. hasRequiredProcessor$1 = 1;
  36293. let Document = /*@__PURE__*/ requireDocument();
  36294. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36295. let NoWorkResult = /*@__PURE__*/ requireNoWorkResult();
  36296. let Root = /*@__PURE__*/ requireRoot$1();
  36297. class Processor {
  36298. constructor(plugins = []) {
  36299. this.version = '8.5.6';
  36300. this.plugins = this.normalize(plugins);
  36301. }
  36302. normalize(plugins) {
  36303. let normalized = [];
  36304. for (let i of plugins) {
  36305. if (i.postcss === true) {
  36306. i = i();
  36307. } else if (i.postcss) {
  36308. i = i.postcss;
  36309. }
  36310. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  36311. normalized = normalized.concat(i.plugins);
  36312. } else if (typeof i === 'object' && i.postcssPlugin) {
  36313. normalized.push(i);
  36314. } else if (typeof i === 'function') {
  36315. normalized.push(i);
  36316. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36317. if (browser$1.env.NODE_ENV !== 'production') {
  36318. throw new Error(
  36319. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36320. 'one of the syntax/parser/stringifier options as outlined ' +
  36321. 'in your PostCSS runner documentation.'
  36322. )
  36323. }
  36324. } else {
  36325. throw new Error(i + ' is not a PostCSS plugin')
  36326. }
  36327. }
  36328. return normalized
  36329. }
  36330. process(css, opts = {}) {
  36331. if (
  36332. !this.plugins.length &&
  36333. !opts.parser &&
  36334. !opts.stringifier &&
  36335. !opts.syntax
  36336. ) {
  36337. return new NoWorkResult(this, css, opts)
  36338. } else {
  36339. return new LazyResult(this, css, opts)
  36340. }
  36341. }
  36342. use(plugin) {
  36343. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36344. return this
  36345. }
  36346. }
  36347. processor$1 = Processor;
  36348. Processor.default = Processor;
  36349. Root.registerProcessor(Processor);
  36350. Document.registerProcessor(Processor);
  36351. return processor$1;
  36352. }
  36353. var postcss_1;
  36354. var hasRequiredPostcss;
  36355. function requirePostcss () {
  36356. if (hasRequiredPostcss) return postcss_1;
  36357. hasRequiredPostcss = 1;
  36358. let AtRule = /*@__PURE__*/ requireAtRule();
  36359. let Comment = /*@__PURE__*/ requireComment$1();
  36360. let Container = /*@__PURE__*/ requireContainer$1();
  36361. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  36362. let Declaration = /*@__PURE__*/ requireDeclaration();
  36363. let Document = /*@__PURE__*/ requireDocument();
  36364. let fromJSON = /*@__PURE__*/ requireFromJSON();
  36365. let Input = /*@__PURE__*/ requireInput();
  36366. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36367. let list = /*@__PURE__*/ requireList();
  36368. let Node = /*@__PURE__*/ requireNode$2();
  36369. let parse = /*@__PURE__*/ requireParse();
  36370. let Processor = /*@__PURE__*/ requireProcessor$1();
  36371. let Result = /*@__PURE__*/ requireResult();
  36372. let Root = /*@__PURE__*/ requireRoot$1();
  36373. let Rule = /*@__PURE__*/ requireRule();
  36374. let stringify = /*@__PURE__*/ requireStringify();
  36375. let Warning = /*@__PURE__*/ requireWarning();
  36376. function postcss(...plugins) {
  36377. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36378. plugins = plugins[0];
  36379. }
  36380. return new Processor(plugins)
  36381. }
  36382. postcss.plugin = function plugin(name, initializer) {
  36383. let warningPrinted = false;
  36384. function creator(...args) {
  36385. // eslint-disable-next-line no-console
  36386. if (console && console.warn && !warningPrinted) {
  36387. warningPrinted = true;
  36388. // eslint-disable-next-line no-console
  36389. console.warn(
  36390. name +
  36391. ': postcss.plugin was deprecated. Migration guide:\n' +
  36392. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36393. );
  36394. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36395. /* c8 ignore next 7 */
  36396. // eslint-disable-next-line no-console
  36397. console.warn(
  36398. name +
  36399. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36400. 'https://www.w3ctech.com/topic/2226'
  36401. );
  36402. }
  36403. }
  36404. let transformer = initializer(...args);
  36405. transformer.postcssPlugin = name;
  36406. transformer.postcssVersion = new Processor().version;
  36407. return transformer
  36408. }
  36409. let cache;
  36410. Object.defineProperty(creator, 'postcss', {
  36411. get() {
  36412. if (!cache) cache = creator();
  36413. return cache
  36414. }
  36415. });
  36416. creator.process = function (css, processOpts, pluginOpts) {
  36417. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36418. };
  36419. return creator
  36420. };
  36421. postcss.stringify = stringify;
  36422. postcss.parse = parse;
  36423. postcss.fromJSON = fromJSON;
  36424. postcss.list = list;
  36425. postcss.comment = defaults => new Comment(defaults);
  36426. postcss.atRule = defaults => new AtRule(defaults);
  36427. postcss.decl = defaults => new Declaration(defaults);
  36428. postcss.rule = defaults => new Rule(defaults);
  36429. postcss.root = defaults => new Root(defaults);
  36430. postcss.document = defaults => new Document(defaults);
  36431. postcss.CssSyntaxError = CssSyntaxError;
  36432. postcss.Declaration = Declaration;
  36433. postcss.Container = Container;
  36434. postcss.Processor = Processor;
  36435. postcss.Document = Document;
  36436. postcss.Comment = Comment;
  36437. postcss.Warning = Warning;
  36438. postcss.AtRule = AtRule;
  36439. postcss.Result = Result;
  36440. postcss.Input = Input;
  36441. postcss.Rule = Rule;
  36442. postcss.Root = Root;
  36443. postcss.Node = Node;
  36444. LazyResult.registerPostcss(postcss);
  36445. postcss_1 = postcss;
  36446. postcss.default = postcss;
  36447. return postcss_1;
  36448. }
  36449. var postcssExports = /*@__PURE__*/ requirePostcss();
  36450. var postcss = /*@__PURE__*/getDefaultExportFromCjs(postcssExports);
  36451. postcss.stringify;
  36452. postcss.fromJSON;
  36453. postcss.plugin;
  36454. postcss.parse;
  36455. postcss.list;
  36456. postcss.document;
  36457. postcss.comment;
  36458. postcss.atRule;
  36459. postcss.rule;
  36460. postcss.decl;
  36461. postcss.root;
  36462. postcss.CssSyntaxError;
  36463. postcss.Declaration;
  36464. postcss.Container;
  36465. postcss.Processor;
  36466. postcss.Document;
  36467. postcss.Comment;
  36468. postcss.Warning;
  36469. postcss.AtRule;
  36470. postcss.Result;
  36471. postcss.Input;
  36472. const Rule = postcss.Rule;
  36473. postcss.Root;
  36474. postcss.Node;
  36475. const trimPlugin = () => {
  36476. return {
  36477. postcssPlugin: "vue-sfc-trim",
  36478. Once(root) {
  36479. root.walk(({ type, raws }) => {
  36480. if (type === "rule" || type === "atrule") {
  36481. if (raws.before) raws.before = "\n";
  36482. if ("after" in raws && raws.after) raws.after = "\n";
  36483. }
  36484. });
  36485. }
  36486. };
  36487. };
  36488. trimPlugin.postcss = true;
  36489. var dist = {exports: {}};
  36490. var processor = {exports: {}};
  36491. var parser = {exports: {}};
  36492. var root = {exports: {}};
  36493. var container = {exports: {}};
  36494. var node$1 = {exports: {}};
  36495. var util$1 = {};
  36496. var unesc = {exports: {}};
  36497. var hasRequiredUnesc;
  36498. function requireUnesc () {
  36499. if (hasRequiredUnesc) return unesc.exports;
  36500. hasRequiredUnesc = 1;
  36501. (function (module, exports) {
  36502. exports.__esModule = true;
  36503. exports["default"] = unesc;
  36504. // Many thanks for this post which made this migration much easier.
  36505. // https://mathiasbynens.be/notes/css-escapes
  36506. /**
  36507. *
  36508. * @param {string} str
  36509. * @returns {[string, number]|undefined}
  36510. */
  36511. function gobbleHex(str) {
  36512. var lower = str.toLowerCase();
  36513. var hex = '';
  36514. var spaceTerminated = false;
  36515. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36516. var code = lower.charCodeAt(i);
  36517. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36518. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36519. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36520. spaceTerminated = code === 32;
  36521. if (!valid) {
  36522. break;
  36523. }
  36524. hex += lower[i];
  36525. }
  36526. if (hex.length === 0) {
  36527. return undefined;
  36528. }
  36529. var codePoint = parseInt(hex, 16);
  36530. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36531. // Add special case for
  36532. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36533. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36534. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36535. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36536. }
  36537. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36538. }
  36539. var CONTAINS_ESCAPE = /\\/;
  36540. function unesc(str) {
  36541. var needToProcess = CONTAINS_ESCAPE.test(str);
  36542. if (!needToProcess) {
  36543. return str;
  36544. }
  36545. var ret = "";
  36546. for (var i = 0; i < str.length; i++) {
  36547. if (str[i] === "\\") {
  36548. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36549. if (gobbled !== undefined) {
  36550. ret += gobbled[0];
  36551. i += gobbled[1];
  36552. continue;
  36553. }
  36554. // Retain a pair of \\ if double escaped `\\\\`
  36555. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36556. if (str[i + 1] === "\\") {
  36557. ret += "\\";
  36558. i++;
  36559. continue;
  36560. }
  36561. // if \\ is at the end of the string retain it
  36562. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36563. if (str.length === i + 1) {
  36564. ret += str[i];
  36565. }
  36566. continue;
  36567. }
  36568. ret += str[i];
  36569. }
  36570. return ret;
  36571. }
  36572. module.exports = exports.default;
  36573. } (unesc, unesc.exports));
  36574. return unesc.exports;
  36575. }
  36576. var getProp = {exports: {}};
  36577. var hasRequiredGetProp;
  36578. function requireGetProp () {
  36579. if (hasRequiredGetProp) return getProp.exports;
  36580. hasRequiredGetProp = 1;
  36581. (function (module, exports) {
  36582. exports.__esModule = true;
  36583. exports["default"] = getProp;
  36584. function getProp(obj) {
  36585. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36586. props[_key - 1] = arguments[_key];
  36587. }
  36588. while (props.length > 0) {
  36589. var prop = props.shift();
  36590. if (!obj[prop]) {
  36591. return undefined;
  36592. }
  36593. obj = obj[prop];
  36594. }
  36595. return obj;
  36596. }
  36597. module.exports = exports.default;
  36598. } (getProp, getProp.exports));
  36599. return getProp.exports;
  36600. }
  36601. var ensureObject = {exports: {}};
  36602. var hasRequiredEnsureObject;
  36603. function requireEnsureObject () {
  36604. if (hasRequiredEnsureObject) return ensureObject.exports;
  36605. hasRequiredEnsureObject = 1;
  36606. (function (module, exports) {
  36607. exports.__esModule = true;
  36608. exports["default"] = ensureObject;
  36609. function ensureObject(obj) {
  36610. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36611. props[_key - 1] = arguments[_key];
  36612. }
  36613. while (props.length > 0) {
  36614. var prop = props.shift();
  36615. if (!obj[prop]) {
  36616. obj[prop] = {};
  36617. }
  36618. obj = obj[prop];
  36619. }
  36620. }
  36621. module.exports = exports.default;
  36622. } (ensureObject, ensureObject.exports));
  36623. return ensureObject.exports;
  36624. }
  36625. var stripComments = {exports: {}};
  36626. var hasRequiredStripComments;
  36627. function requireStripComments () {
  36628. if (hasRequiredStripComments) return stripComments.exports;
  36629. hasRequiredStripComments = 1;
  36630. (function (module, exports) {
  36631. exports.__esModule = true;
  36632. exports["default"] = stripComments;
  36633. function stripComments(str) {
  36634. var s = "";
  36635. var commentStart = str.indexOf("/*");
  36636. var lastEnd = 0;
  36637. while (commentStart >= 0) {
  36638. s = s + str.slice(lastEnd, commentStart);
  36639. var commentEnd = str.indexOf("*/", commentStart + 2);
  36640. if (commentEnd < 0) {
  36641. return s;
  36642. }
  36643. lastEnd = commentEnd + 2;
  36644. commentStart = str.indexOf("/*", lastEnd);
  36645. }
  36646. s = s + str.slice(lastEnd);
  36647. return s;
  36648. }
  36649. module.exports = exports.default;
  36650. } (stripComments, stripComments.exports));
  36651. return stripComments.exports;
  36652. }
  36653. var hasRequiredUtil$1;
  36654. function requireUtil$1 () {
  36655. if (hasRequiredUtil$1) return util$1;
  36656. hasRequiredUtil$1 = 1;
  36657. util$1.__esModule = true;
  36658. util$1.unesc = util$1.stripComments = util$1.getProp = util$1.ensureObject = void 0;
  36659. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  36660. util$1.unesc = _unesc["default"];
  36661. var _getProp = _interopRequireDefault(/*@__PURE__*/ requireGetProp());
  36662. util$1.getProp = _getProp["default"];
  36663. var _ensureObject = _interopRequireDefault(/*@__PURE__*/ requireEnsureObject());
  36664. util$1.ensureObject = _ensureObject["default"];
  36665. var _stripComments = _interopRequireDefault(/*@__PURE__*/ requireStripComments());
  36666. util$1.stripComments = _stripComments["default"];
  36667. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36668. return util$1;
  36669. }
  36670. var hasRequiredNode$1;
  36671. function requireNode$1 () {
  36672. if (hasRequiredNode$1) return node$1.exports;
  36673. hasRequiredNode$1 = 1;
  36674. (function (module, exports) {
  36675. exports.__esModule = true;
  36676. exports["default"] = void 0;
  36677. var _util = /*@__PURE__*/ requireUtil$1();
  36678. 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); } }
  36679. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36680. var cloneNode = function cloneNode(obj, parent) {
  36681. if (typeof obj !== 'object' || obj === null) {
  36682. return obj;
  36683. }
  36684. var cloned = new obj.constructor();
  36685. for (var i in obj) {
  36686. if (!obj.hasOwnProperty(i)) {
  36687. continue;
  36688. }
  36689. var value = obj[i];
  36690. var type = typeof value;
  36691. if (i === 'parent' && type === 'object') {
  36692. if (parent) {
  36693. cloned[i] = parent;
  36694. }
  36695. } else if (value instanceof Array) {
  36696. cloned[i] = value.map(function (j) {
  36697. return cloneNode(j, cloned);
  36698. });
  36699. } else {
  36700. cloned[i] = cloneNode(value, cloned);
  36701. }
  36702. }
  36703. return cloned;
  36704. };
  36705. var Node = /*#__PURE__*/function () {
  36706. function Node(opts) {
  36707. if (opts === void 0) {
  36708. opts = {};
  36709. }
  36710. Object.assign(this, opts);
  36711. this.spaces = this.spaces || {};
  36712. this.spaces.before = this.spaces.before || '';
  36713. this.spaces.after = this.spaces.after || '';
  36714. }
  36715. var _proto = Node.prototype;
  36716. _proto.remove = function remove() {
  36717. if (this.parent) {
  36718. this.parent.removeChild(this);
  36719. }
  36720. this.parent = undefined;
  36721. return this;
  36722. };
  36723. _proto.replaceWith = function replaceWith() {
  36724. if (this.parent) {
  36725. for (var index in arguments) {
  36726. this.parent.insertBefore(this, arguments[index]);
  36727. }
  36728. this.remove();
  36729. }
  36730. return this;
  36731. };
  36732. _proto.next = function next() {
  36733. return this.parent.at(this.parent.index(this) + 1);
  36734. };
  36735. _proto.prev = function prev() {
  36736. return this.parent.at(this.parent.index(this) - 1);
  36737. };
  36738. _proto.clone = function clone(overrides) {
  36739. if (overrides === void 0) {
  36740. overrides = {};
  36741. }
  36742. var cloned = cloneNode(this);
  36743. for (var name in overrides) {
  36744. cloned[name] = overrides[name];
  36745. }
  36746. return cloned;
  36747. }
  36748. /**
  36749. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36750. * This allows non standard syntax to be appended to an existing property
  36751. * by specifying the escaped value. By specifying the escaped value,
  36752. * illegal characters are allowed to be directly inserted into css output.
  36753. * @param {string} name the property to set
  36754. * @param {any} value the unescaped value of the property
  36755. * @param {string} valueEscaped optional. the escaped value of the property.
  36756. */;
  36757. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  36758. if (!this.raws) {
  36759. this.raws = {};
  36760. }
  36761. var originalValue = this[name];
  36762. var originalEscaped = this.raws[name];
  36763. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  36764. if (originalEscaped || valueEscaped !== value) {
  36765. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  36766. } else {
  36767. delete this.raws[name]; // delete any escaped value that was created by the setter.
  36768. }
  36769. }
  36770. /**
  36771. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36772. * This allows the escaped value to be specified directly, allowing illegal
  36773. * characters to be directly inserted into css output.
  36774. * @param {string} name the property to set
  36775. * @param {any} value the unescaped value of the property
  36776. * @param {string} valueEscaped the escaped value of the property.
  36777. */;
  36778. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  36779. if (!this.raws) {
  36780. this.raws = {};
  36781. }
  36782. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36783. this.raws[name] = valueEscaped;
  36784. }
  36785. /**
  36786. * When you want a value to passed through to CSS directly. This method
  36787. * deletes the corresponding raw value causing the stringifier to fallback
  36788. * to the unescaped value.
  36789. * @param {string} name the property to set.
  36790. * @param {any} value The value that is both escaped and unescaped.
  36791. */;
  36792. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  36793. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36794. if (this.raws) {
  36795. delete this.raws[name];
  36796. }
  36797. }
  36798. /**
  36799. *
  36800. * @param {number} line The number (starting with 1)
  36801. * @param {number} column The column number (starting with 1)
  36802. */;
  36803. _proto.isAtPosition = function isAtPosition(line, column) {
  36804. if (this.source && this.source.start && this.source.end) {
  36805. if (this.source.start.line > line) {
  36806. return false;
  36807. }
  36808. if (this.source.end.line < line) {
  36809. return false;
  36810. }
  36811. if (this.source.start.line === line && this.source.start.column > column) {
  36812. return false;
  36813. }
  36814. if (this.source.end.line === line && this.source.end.column < column) {
  36815. return false;
  36816. }
  36817. return true;
  36818. }
  36819. return undefined;
  36820. };
  36821. _proto.stringifyProperty = function stringifyProperty(name) {
  36822. return this.raws && this.raws[name] || this[name];
  36823. };
  36824. _proto.valueToString = function valueToString() {
  36825. return String(this.stringifyProperty("value"));
  36826. };
  36827. _proto.toString = function toString() {
  36828. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  36829. };
  36830. _createClass(Node, [{
  36831. key: "rawSpaceBefore",
  36832. get: function get() {
  36833. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  36834. if (rawSpace === undefined) {
  36835. rawSpace = this.spaces && this.spaces.before;
  36836. }
  36837. return rawSpace || "";
  36838. },
  36839. set: function set(raw) {
  36840. (0, _util.ensureObject)(this, "raws", "spaces");
  36841. this.raws.spaces.before = raw;
  36842. }
  36843. }, {
  36844. key: "rawSpaceAfter",
  36845. get: function get() {
  36846. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  36847. if (rawSpace === undefined) {
  36848. rawSpace = this.spaces.after;
  36849. }
  36850. return rawSpace || "";
  36851. },
  36852. set: function set(raw) {
  36853. (0, _util.ensureObject)(this, "raws", "spaces");
  36854. this.raws.spaces.after = raw;
  36855. }
  36856. }]);
  36857. return Node;
  36858. }();
  36859. exports["default"] = Node;
  36860. module.exports = exports.default;
  36861. } (node$1, node$1.exports));
  36862. return node$1.exports;
  36863. }
  36864. var types = {};
  36865. var hasRequiredTypes;
  36866. function requireTypes () {
  36867. if (hasRequiredTypes) return types;
  36868. hasRequiredTypes = 1;
  36869. types.__esModule = true;
  36870. 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;
  36871. var TAG = 'tag';
  36872. types.TAG = TAG;
  36873. var STRING = 'string';
  36874. types.STRING = STRING;
  36875. var SELECTOR = 'selector';
  36876. types.SELECTOR = SELECTOR;
  36877. var ROOT = 'root';
  36878. types.ROOT = ROOT;
  36879. var PSEUDO = 'pseudo';
  36880. types.PSEUDO = PSEUDO;
  36881. var NESTING = 'nesting';
  36882. types.NESTING = NESTING;
  36883. var ID = 'id';
  36884. types.ID = ID;
  36885. var COMMENT = 'comment';
  36886. types.COMMENT = COMMENT;
  36887. var COMBINATOR = 'combinator';
  36888. types.COMBINATOR = COMBINATOR;
  36889. var CLASS = 'class';
  36890. types.CLASS = CLASS;
  36891. var ATTRIBUTE = 'attribute';
  36892. types.ATTRIBUTE = ATTRIBUTE;
  36893. var UNIVERSAL = 'universal';
  36894. types.UNIVERSAL = UNIVERSAL;
  36895. return types;
  36896. }
  36897. var hasRequiredContainer;
  36898. function requireContainer () {
  36899. if (hasRequiredContainer) return container.exports;
  36900. hasRequiredContainer = 1;
  36901. (function (module, exports) {
  36902. exports.__esModule = true;
  36903. exports["default"] = void 0;
  36904. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  36905. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  36906. 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); }
  36907. 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; }
  36908. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36909. 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."); }
  36910. 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); }
  36911. 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; }
  36912. 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); } }
  36913. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36914. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36915. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36916. var Container = /*#__PURE__*/function (_Node) {
  36917. _inheritsLoose(Container, _Node);
  36918. function Container(opts) {
  36919. var _this;
  36920. _this = _Node.call(this, opts) || this;
  36921. if (!_this.nodes) {
  36922. _this.nodes = [];
  36923. }
  36924. return _this;
  36925. }
  36926. var _proto = Container.prototype;
  36927. _proto.append = function append(selector) {
  36928. selector.parent = this;
  36929. this.nodes.push(selector);
  36930. return this;
  36931. };
  36932. _proto.prepend = function prepend(selector) {
  36933. selector.parent = this;
  36934. this.nodes.unshift(selector);
  36935. for (var id in this.indexes) {
  36936. this.indexes[id]++;
  36937. }
  36938. return this;
  36939. };
  36940. _proto.at = function at(index) {
  36941. return this.nodes[index];
  36942. };
  36943. _proto.index = function index(child) {
  36944. if (typeof child === 'number') {
  36945. return child;
  36946. }
  36947. return this.nodes.indexOf(child);
  36948. };
  36949. _proto.removeChild = function removeChild(child) {
  36950. child = this.index(child);
  36951. this.at(child).parent = undefined;
  36952. this.nodes.splice(child, 1);
  36953. var index;
  36954. for (var id in this.indexes) {
  36955. index = this.indexes[id];
  36956. if (index >= child) {
  36957. this.indexes[id] = index - 1;
  36958. }
  36959. }
  36960. return this;
  36961. };
  36962. _proto.removeAll = function removeAll() {
  36963. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  36964. var node = _step.value;
  36965. node.parent = undefined;
  36966. }
  36967. this.nodes = [];
  36968. return this;
  36969. };
  36970. _proto.empty = function empty() {
  36971. return this.removeAll();
  36972. };
  36973. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  36974. var _this$nodes;
  36975. newNode.parent = this;
  36976. var oldIndex = this.index(oldNode);
  36977. var resetNode = [];
  36978. for (var i = 2; i < arguments.length; i++) {
  36979. resetNode.push(arguments[i]);
  36980. }
  36981. (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
  36982. newNode.parent = this;
  36983. var index;
  36984. for (var id in this.indexes) {
  36985. index = this.indexes[id];
  36986. if (oldIndex < index) {
  36987. this.indexes[id] = index + arguments.length - 1;
  36988. }
  36989. }
  36990. return this;
  36991. };
  36992. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  36993. var _this$nodes2;
  36994. newNode.parent = this;
  36995. var oldIndex = this.index(oldNode);
  36996. var resetNode = [];
  36997. for (var i = 2; i < arguments.length; i++) {
  36998. resetNode.push(arguments[i]);
  36999. }
  37000. (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
  37001. newNode.parent = this;
  37002. var index;
  37003. for (var id in this.indexes) {
  37004. index = this.indexes[id];
  37005. if (index >= oldIndex) {
  37006. this.indexes[id] = index + arguments.length - 1;
  37007. }
  37008. }
  37009. return this;
  37010. };
  37011. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  37012. var found = undefined;
  37013. this.each(function (node) {
  37014. if (node.atPosition) {
  37015. var foundChild = node.atPosition(line, col);
  37016. if (foundChild) {
  37017. found = foundChild;
  37018. return false;
  37019. }
  37020. } else if (node.isAtPosition(line, col)) {
  37021. found = node;
  37022. return false;
  37023. }
  37024. });
  37025. return found;
  37026. }
  37027. /**
  37028. * Return the most specific node at the line and column number given.
  37029. * The source location is based on the original parsed location, locations aren't
  37030. * updated as selector nodes are mutated.
  37031. *
  37032. * Note that this location is relative to the location of the first character
  37033. * of the selector, and not the location of the selector in the overall document
  37034. * when used in conjunction with postcss.
  37035. *
  37036. * If not found, returns undefined.
  37037. * @param {number} line The line number of the node to find. (1-based index)
  37038. * @param {number} col The column number of the node to find. (1-based index)
  37039. */;
  37040. _proto.atPosition = function atPosition(line, col) {
  37041. if (this.isAtPosition(line, col)) {
  37042. return this._findChildAtPosition(line, col) || this;
  37043. } else {
  37044. return undefined;
  37045. }
  37046. };
  37047. _proto._inferEndPosition = function _inferEndPosition() {
  37048. if (this.last && this.last.source && this.last.source.end) {
  37049. this.source = this.source || {};
  37050. this.source.end = this.source.end || {};
  37051. Object.assign(this.source.end, this.last.source.end);
  37052. }
  37053. };
  37054. _proto.each = function each(callback) {
  37055. if (!this.lastEach) {
  37056. this.lastEach = 0;
  37057. }
  37058. if (!this.indexes) {
  37059. this.indexes = {};
  37060. }
  37061. this.lastEach++;
  37062. var id = this.lastEach;
  37063. this.indexes[id] = 0;
  37064. if (!this.length) {
  37065. return undefined;
  37066. }
  37067. var index, result;
  37068. while (this.indexes[id] < this.length) {
  37069. index = this.indexes[id];
  37070. result = callback(this.at(index), index);
  37071. if (result === false) {
  37072. break;
  37073. }
  37074. this.indexes[id] += 1;
  37075. }
  37076. delete this.indexes[id];
  37077. if (result === false) {
  37078. return false;
  37079. }
  37080. };
  37081. _proto.walk = function walk(callback) {
  37082. return this.each(function (node, i) {
  37083. var result = callback(node, i);
  37084. if (result !== false && node.length) {
  37085. result = node.walk(callback);
  37086. }
  37087. if (result === false) {
  37088. return false;
  37089. }
  37090. });
  37091. };
  37092. _proto.walkAttributes = function walkAttributes(callback) {
  37093. var _this2 = this;
  37094. return this.walk(function (selector) {
  37095. if (selector.type === types.ATTRIBUTE) {
  37096. return callback.call(_this2, selector);
  37097. }
  37098. });
  37099. };
  37100. _proto.walkClasses = function walkClasses(callback) {
  37101. var _this3 = this;
  37102. return this.walk(function (selector) {
  37103. if (selector.type === types.CLASS) {
  37104. return callback.call(_this3, selector);
  37105. }
  37106. });
  37107. };
  37108. _proto.walkCombinators = function walkCombinators(callback) {
  37109. var _this4 = this;
  37110. return this.walk(function (selector) {
  37111. if (selector.type === types.COMBINATOR) {
  37112. return callback.call(_this4, selector);
  37113. }
  37114. });
  37115. };
  37116. _proto.walkComments = function walkComments(callback) {
  37117. var _this5 = this;
  37118. return this.walk(function (selector) {
  37119. if (selector.type === types.COMMENT) {
  37120. return callback.call(_this5, selector);
  37121. }
  37122. });
  37123. };
  37124. _proto.walkIds = function walkIds(callback) {
  37125. var _this6 = this;
  37126. return this.walk(function (selector) {
  37127. if (selector.type === types.ID) {
  37128. return callback.call(_this6, selector);
  37129. }
  37130. });
  37131. };
  37132. _proto.walkNesting = function walkNesting(callback) {
  37133. var _this7 = this;
  37134. return this.walk(function (selector) {
  37135. if (selector.type === types.NESTING) {
  37136. return callback.call(_this7, selector);
  37137. }
  37138. });
  37139. };
  37140. _proto.walkPseudos = function walkPseudos(callback) {
  37141. var _this8 = this;
  37142. return this.walk(function (selector) {
  37143. if (selector.type === types.PSEUDO) {
  37144. return callback.call(_this8, selector);
  37145. }
  37146. });
  37147. };
  37148. _proto.walkTags = function walkTags(callback) {
  37149. var _this9 = this;
  37150. return this.walk(function (selector) {
  37151. if (selector.type === types.TAG) {
  37152. return callback.call(_this9, selector);
  37153. }
  37154. });
  37155. };
  37156. _proto.walkUniversals = function walkUniversals(callback) {
  37157. var _this10 = this;
  37158. return this.walk(function (selector) {
  37159. if (selector.type === types.UNIVERSAL) {
  37160. return callback.call(_this10, selector);
  37161. }
  37162. });
  37163. };
  37164. _proto.split = function split(callback) {
  37165. var _this11 = this;
  37166. var current = [];
  37167. return this.reduce(function (memo, node, index) {
  37168. var split = callback.call(_this11, node);
  37169. current.push(node);
  37170. if (split) {
  37171. memo.push(current);
  37172. current = [];
  37173. } else if (index === _this11.length - 1) {
  37174. memo.push(current);
  37175. }
  37176. return memo;
  37177. }, []);
  37178. };
  37179. _proto.map = function map(callback) {
  37180. return this.nodes.map(callback);
  37181. };
  37182. _proto.reduce = function reduce(callback, memo) {
  37183. return this.nodes.reduce(callback, memo);
  37184. };
  37185. _proto.every = function every(callback) {
  37186. return this.nodes.every(callback);
  37187. };
  37188. _proto.some = function some(callback) {
  37189. return this.nodes.some(callback);
  37190. };
  37191. _proto.filter = function filter(callback) {
  37192. return this.nodes.filter(callback);
  37193. };
  37194. _proto.sort = function sort(callback) {
  37195. return this.nodes.sort(callback);
  37196. };
  37197. _proto.toString = function toString() {
  37198. return this.map(String).join('');
  37199. };
  37200. _createClass(Container, [{
  37201. key: "first",
  37202. get: function get() {
  37203. return this.at(0);
  37204. }
  37205. }, {
  37206. key: "last",
  37207. get: function get() {
  37208. return this.at(this.length - 1);
  37209. }
  37210. }, {
  37211. key: "length",
  37212. get: function get() {
  37213. return this.nodes.length;
  37214. }
  37215. }]);
  37216. return Container;
  37217. }(_node["default"]);
  37218. exports["default"] = Container;
  37219. module.exports = exports.default;
  37220. } (container, container.exports));
  37221. return container.exports;
  37222. }
  37223. var hasRequiredRoot;
  37224. function requireRoot () {
  37225. if (hasRequiredRoot) return root.exports;
  37226. hasRequiredRoot = 1;
  37227. (function (module, exports) {
  37228. exports.__esModule = true;
  37229. exports["default"] = void 0;
  37230. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37231. var _types = /*@__PURE__*/ requireTypes();
  37232. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37233. 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); } }
  37234. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37235. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37236. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37237. var Root = /*#__PURE__*/function (_Container) {
  37238. _inheritsLoose(Root, _Container);
  37239. function Root(opts) {
  37240. var _this;
  37241. _this = _Container.call(this, opts) || this;
  37242. _this.type = _types.ROOT;
  37243. return _this;
  37244. }
  37245. var _proto = Root.prototype;
  37246. _proto.toString = function toString() {
  37247. var str = this.reduce(function (memo, selector) {
  37248. memo.push(String(selector));
  37249. return memo;
  37250. }, []).join(',');
  37251. return this.trailingComma ? str + ',' : str;
  37252. };
  37253. _proto.error = function error(message, options) {
  37254. if (this._error) {
  37255. return this._error(message, options);
  37256. } else {
  37257. return new Error(message);
  37258. }
  37259. };
  37260. _createClass(Root, [{
  37261. key: "errorGenerator",
  37262. set: function set(handler) {
  37263. this._error = handler;
  37264. }
  37265. }]);
  37266. return Root;
  37267. }(_container["default"]);
  37268. exports["default"] = Root;
  37269. module.exports = exports.default;
  37270. } (root, root.exports));
  37271. return root.exports;
  37272. }
  37273. var selector = {exports: {}};
  37274. var hasRequiredSelector;
  37275. function requireSelector () {
  37276. if (hasRequiredSelector) return selector.exports;
  37277. hasRequiredSelector = 1;
  37278. (function (module, exports) {
  37279. exports.__esModule = true;
  37280. exports["default"] = void 0;
  37281. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37282. var _types = /*@__PURE__*/ requireTypes();
  37283. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37284. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37285. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37286. var Selector = /*#__PURE__*/function (_Container) {
  37287. _inheritsLoose(Selector, _Container);
  37288. function Selector(opts) {
  37289. var _this;
  37290. _this = _Container.call(this, opts) || this;
  37291. _this.type = _types.SELECTOR;
  37292. return _this;
  37293. }
  37294. return Selector;
  37295. }(_container["default"]);
  37296. exports["default"] = Selector;
  37297. module.exports = exports.default;
  37298. } (selector, selector.exports));
  37299. return selector.exports;
  37300. }
  37301. var className = {exports: {}};
  37302. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  37303. var cssesc_1;
  37304. var hasRequiredCssesc;
  37305. function requireCssesc () {
  37306. if (hasRequiredCssesc) return cssesc_1;
  37307. hasRequiredCssesc = 1;
  37308. var object = {};
  37309. var hasOwnProperty = object.hasOwnProperty;
  37310. var merge = function merge(options, defaults) {
  37311. if (!options) {
  37312. return defaults;
  37313. }
  37314. var result = {};
  37315. for (var key in defaults) {
  37316. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  37317. // only recognized option names are used.
  37318. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  37319. }
  37320. return result;
  37321. };
  37322. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  37323. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  37324. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  37325. // https://mathiasbynens.be/notes/css-escapes#css
  37326. var cssesc = function cssesc(string, options) {
  37327. options = merge(options, cssesc.options);
  37328. if (options.quotes != 'single' && options.quotes != 'double') {
  37329. options.quotes = 'single';
  37330. }
  37331. var quote = options.quotes == 'double' ? '"' : '\'';
  37332. var isIdentifier = options.isIdentifier;
  37333. var firstChar = string.charAt(0);
  37334. var output = '';
  37335. var counter = 0;
  37336. var length = string.length;
  37337. while (counter < length) {
  37338. var character = string.charAt(counter++);
  37339. var codePoint = character.charCodeAt();
  37340. var value = void 0;
  37341. // If it’s not a printable ASCII character…
  37342. if (codePoint < 0x20 || codePoint > 0x7E) {
  37343. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37344. // It’s a high surrogate, and there is a next character.
  37345. var extra = string.charCodeAt(counter++);
  37346. if ((extra & 0xFC00) == 0xDC00) {
  37347. // next character is low surrogate
  37348. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37349. } else {
  37350. // It’s an unmatched surrogate; only append this code unit, in case
  37351. // the next code unit is the high surrogate of a surrogate pair.
  37352. counter--;
  37353. }
  37354. }
  37355. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37356. } else {
  37357. if (options.escapeEverything) {
  37358. if (regexAnySingleEscape.test(character)) {
  37359. value = '\\' + character;
  37360. } else {
  37361. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37362. }
  37363. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37364. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37365. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37366. value = '\\' + character;
  37367. } else {
  37368. value = character;
  37369. }
  37370. }
  37371. output += value;
  37372. }
  37373. if (isIdentifier) {
  37374. if (/^-[-\d]/.test(output)) {
  37375. output = '\\-' + output.slice(1);
  37376. } else if (/\d/.test(firstChar)) {
  37377. output = '\\3' + firstChar + ' ' + output.slice(1);
  37378. }
  37379. }
  37380. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37381. // since they’re redundant. Note that this is only possible if the escape
  37382. // sequence isn’t preceded by an odd number of backslashes.
  37383. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37384. if ($1 && $1.length % 2) {
  37385. // It’s not safe to remove the space, so don’t.
  37386. return $0;
  37387. }
  37388. // Strip the space.
  37389. return ($1 || '') + $2;
  37390. });
  37391. if (!isIdentifier && options.wrap) {
  37392. return quote + output + quote;
  37393. }
  37394. return output;
  37395. };
  37396. // Expose default options (so they can be overridden globally).
  37397. cssesc.options = {
  37398. 'escapeEverything': false,
  37399. 'isIdentifier': false,
  37400. 'quotes': 'single',
  37401. 'wrap': false
  37402. };
  37403. cssesc.version = '3.0.0';
  37404. cssesc_1 = cssesc;
  37405. return cssesc_1;
  37406. }
  37407. var hasRequiredClassName;
  37408. function requireClassName () {
  37409. if (hasRequiredClassName) return className.exports;
  37410. hasRequiredClassName = 1;
  37411. (function (module, exports) {
  37412. exports.__esModule = true;
  37413. exports["default"] = void 0;
  37414. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37415. var _util = /*@__PURE__*/ requireUtil$1();
  37416. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37417. var _types = /*@__PURE__*/ requireTypes();
  37418. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37419. 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); } }
  37420. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37421. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37422. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37423. var ClassName = /*#__PURE__*/function (_Node) {
  37424. _inheritsLoose(ClassName, _Node);
  37425. function ClassName(opts) {
  37426. var _this;
  37427. _this = _Node.call(this, opts) || this;
  37428. _this.type = _types.CLASS;
  37429. _this._constructed = true;
  37430. return _this;
  37431. }
  37432. var _proto = ClassName.prototype;
  37433. _proto.valueToString = function valueToString() {
  37434. return '.' + _Node.prototype.valueToString.call(this);
  37435. };
  37436. _createClass(ClassName, [{
  37437. key: "value",
  37438. get: function get() {
  37439. return this._value;
  37440. },
  37441. set: function set(v) {
  37442. if (this._constructed) {
  37443. var escaped = (0, _cssesc["default"])(v, {
  37444. isIdentifier: true
  37445. });
  37446. if (escaped !== v) {
  37447. (0, _util.ensureObject)(this, "raws");
  37448. this.raws.value = escaped;
  37449. } else if (this.raws) {
  37450. delete this.raws.value;
  37451. }
  37452. }
  37453. this._value = v;
  37454. }
  37455. }]);
  37456. return ClassName;
  37457. }(_node["default"]);
  37458. exports["default"] = ClassName;
  37459. module.exports = exports.default;
  37460. } (className, className.exports));
  37461. return className.exports;
  37462. }
  37463. var comment = {exports: {}};
  37464. var hasRequiredComment;
  37465. function requireComment () {
  37466. if (hasRequiredComment) return comment.exports;
  37467. hasRequiredComment = 1;
  37468. (function (module, exports) {
  37469. exports.__esModule = true;
  37470. exports["default"] = void 0;
  37471. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37472. var _types = /*@__PURE__*/ requireTypes();
  37473. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37474. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37475. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37476. var Comment = /*#__PURE__*/function (_Node) {
  37477. _inheritsLoose(Comment, _Node);
  37478. function Comment(opts) {
  37479. var _this;
  37480. _this = _Node.call(this, opts) || this;
  37481. _this.type = _types.COMMENT;
  37482. return _this;
  37483. }
  37484. return Comment;
  37485. }(_node["default"]);
  37486. exports["default"] = Comment;
  37487. module.exports = exports.default;
  37488. } (comment, comment.exports));
  37489. return comment.exports;
  37490. }
  37491. var id = {exports: {}};
  37492. var hasRequiredId;
  37493. function requireId () {
  37494. if (hasRequiredId) return id.exports;
  37495. hasRequiredId = 1;
  37496. (function (module, exports) {
  37497. exports.__esModule = true;
  37498. exports["default"] = void 0;
  37499. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37500. var _types = /*@__PURE__*/ requireTypes();
  37501. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37502. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37503. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37504. var ID = /*#__PURE__*/function (_Node) {
  37505. _inheritsLoose(ID, _Node);
  37506. function ID(opts) {
  37507. var _this;
  37508. _this = _Node.call(this, opts) || this;
  37509. _this.type = _types.ID;
  37510. return _this;
  37511. }
  37512. var _proto = ID.prototype;
  37513. _proto.valueToString = function valueToString() {
  37514. return '#' + _Node.prototype.valueToString.call(this);
  37515. };
  37516. return ID;
  37517. }(_node["default"]);
  37518. exports["default"] = ID;
  37519. module.exports = exports.default;
  37520. } (id, id.exports));
  37521. return id.exports;
  37522. }
  37523. var tag = {exports: {}};
  37524. var namespace = {exports: {}};
  37525. var hasRequiredNamespace;
  37526. function requireNamespace () {
  37527. if (hasRequiredNamespace) return namespace.exports;
  37528. hasRequiredNamespace = 1;
  37529. (function (module, exports) {
  37530. exports.__esModule = true;
  37531. exports["default"] = void 0;
  37532. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37533. var _util = /*@__PURE__*/ requireUtil$1();
  37534. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37535. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37536. 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); } }
  37537. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37538. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37539. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37540. var Namespace = /*#__PURE__*/function (_Node) {
  37541. _inheritsLoose(Namespace, _Node);
  37542. function Namespace() {
  37543. return _Node.apply(this, arguments) || this;
  37544. }
  37545. var _proto = Namespace.prototype;
  37546. _proto.qualifiedName = function qualifiedName(value) {
  37547. if (this.namespace) {
  37548. return this.namespaceString + "|" + value;
  37549. } else {
  37550. return value;
  37551. }
  37552. };
  37553. _proto.valueToString = function valueToString() {
  37554. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37555. };
  37556. _createClass(Namespace, [{
  37557. key: "namespace",
  37558. get: function get() {
  37559. return this._namespace;
  37560. },
  37561. set: function set(namespace) {
  37562. if (namespace === true || namespace === "*" || namespace === "&") {
  37563. this._namespace = namespace;
  37564. if (this.raws) {
  37565. delete this.raws.namespace;
  37566. }
  37567. return;
  37568. }
  37569. var escaped = (0, _cssesc["default"])(namespace, {
  37570. isIdentifier: true
  37571. });
  37572. this._namespace = namespace;
  37573. if (escaped !== namespace) {
  37574. (0, _util.ensureObject)(this, "raws");
  37575. this.raws.namespace = escaped;
  37576. } else if (this.raws) {
  37577. delete this.raws.namespace;
  37578. }
  37579. }
  37580. }, {
  37581. key: "ns",
  37582. get: function get() {
  37583. return this._namespace;
  37584. },
  37585. set: function set(namespace) {
  37586. this.namespace = namespace;
  37587. }
  37588. }, {
  37589. key: "namespaceString",
  37590. get: function get() {
  37591. if (this.namespace) {
  37592. var ns = this.stringifyProperty("namespace");
  37593. if (ns === true) {
  37594. return '';
  37595. } else {
  37596. return ns;
  37597. }
  37598. } else {
  37599. return '';
  37600. }
  37601. }
  37602. }]);
  37603. return Namespace;
  37604. }(_node["default"]);
  37605. exports["default"] = Namespace;
  37606. module.exports = exports.default;
  37607. } (namespace, namespace.exports));
  37608. return namespace.exports;
  37609. }
  37610. var hasRequiredTag;
  37611. function requireTag () {
  37612. if (hasRequiredTag) return tag.exports;
  37613. hasRequiredTag = 1;
  37614. (function (module, exports) {
  37615. exports.__esModule = true;
  37616. exports["default"] = void 0;
  37617. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37618. var _types = /*@__PURE__*/ requireTypes();
  37619. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37620. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37621. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37622. var Tag = /*#__PURE__*/function (_Namespace) {
  37623. _inheritsLoose(Tag, _Namespace);
  37624. function Tag(opts) {
  37625. var _this;
  37626. _this = _Namespace.call(this, opts) || this;
  37627. _this.type = _types.TAG;
  37628. return _this;
  37629. }
  37630. return Tag;
  37631. }(_namespace["default"]);
  37632. exports["default"] = Tag;
  37633. module.exports = exports.default;
  37634. } (tag, tag.exports));
  37635. return tag.exports;
  37636. }
  37637. var string = {exports: {}};
  37638. var hasRequiredString;
  37639. function requireString () {
  37640. if (hasRequiredString) return string.exports;
  37641. hasRequiredString = 1;
  37642. (function (module, exports) {
  37643. exports.__esModule = true;
  37644. exports["default"] = void 0;
  37645. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37646. var _types = /*@__PURE__*/ requireTypes();
  37647. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37648. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37649. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37650. var String = /*#__PURE__*/function (_Node) {
  37651. _inheritsLoose(String, _Node);
  37652. function String(opts) {
  37653. var _this;
  37654. _this = _Node.call(this, opts) || this;
  37655. _this.type = _types.STRING;
  37656. return _this;
  37657. }
  37658. return String;
  37659. }(_node["default"]);
  37660. exports["default"] = String;
  37661. module.exports = exports.default;
  37662. } (string, string.exports));
  37663. return string.exports;
  37664. }
  37665. var pseudo = {exports: {}};
  37666. var hasRequiredPseudo;
  37667. function requirePseudo () {
  37668. if (hasRequiredPseudo) return pseudo.exports;
  37669. hasRequiredPseudo = 1;
  37670. (function (module, exports) {
  37671. exports.__esModule = true;
  37672. exports["default"] = void 0;
  37673. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37674. var _types = /*@__PURE__*/ requireTypes();
  37675. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37676. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37677. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37678. var Pseudo = /*#__PURE__*/function (_Container) {
  37679. _inheritsLoose(Pseudo, _Container);
  37680. function Pseudo(opts) {
  37681. var _this;
  37682. _this = _Container.call(this, opts) || this;
  37683. _this.type = _types.PSEUDO;
  37684. return _this;
  37685. }
  37686. var _proto = Pseudo.prototype;
  37687. _proto.toString = function toString() {
  37688. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37689. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37690. };
  37691. return Pseudo;
  37692. }(_container["default"]);
  37693. exports["default"] = Pseudo;
  37694. module.exports = exports.default;
  37695. } (pseudo, pseudo.exports));
  37696. return pseudo.exports;
  37697. }
  37698. var attribute = {};
  37699. var node;
  37700. var hasRequiredNode;
  37701. function requireNode () {
  37702. if (hasRequiredNode) return node;
  37703. hasRequiredNode = 1;
  37704. /**
  37705. * For Node.js, simply re-export the core `util.deprecate` function.
  37706. */
  37707. node = require$$0.deprecate;
  37708. return node;
  37709. }
  37710. var hasRequiredAttribute;
  37711. function requireAttribute () {
  37712. if (hasRequiredAttribute) return attribute;
  37713. hasRequiredAttribute = 1;
  37714. (function (exports) {
  37715. exports.__esModule = true;
  37716. exports["default"] = void 0;
  37717. exports.unescapeValue = unescapeValue;
  37718. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37719. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  37720. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37721. var _types = /*@__PURE__*/ requireTypes();
  37722. var _CSSESC_QUOTE_OPTIONS;
  37723. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37724. 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); } }
  37725. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37726. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37727. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37728. var deprecate = /*@__PURE__*/ requireNode();
  37729. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37730. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37731. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37732. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37733. function unescapeValue(value) {
  37734. var deprecatedUsage = false;
  37735. var quoteMark = null;
  37736. var unescaped = value;
  37737. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37738. if (m) {
  37739. quoteMark = m[1];
  37740. unescaped = m[2];
  37741. }
  37742. unescaped = (0, _unesc["default"])(unescaped);
  37743. if (unescaped !== value) {
  37744. deprecatedUsage = true;
  37745. }
  37746. return {
  37747. deprecatedUsage: deprecatedUsage,
  37748. unescaped: unescaped,
  37749. quoteMark: quoteMark
  37750. };
  37751. }
  37752. function handleDeprecatedContructorOpts(opts) {
  37753. if (opts.quoteMark !== undefined) {
  37754. return opts;
  37755. }
  37756. if (opts.value === undefined) {
  37757. return opts;
  37758. }
  37759. warnOfDeprecatedConstructor();
  37760. var _unescapeValue = unescapeValue(opts.value),
  37761. quoteMark = _unescapeValue.quoteMark,
  37762. unescaped = _unescapeValue.unescaped;
  37763. if (!opts.raws) {
  37764. opts.raws = {};
  37765. }
  37766. if (opts.raws.value === undefined) {
  37767. opts.raws.value = opts.value;
  37768. }
  37769. opts.value = unescaped;
  37770. opts.quoteMark = quoteMark;
  37771. return opts;
  37772. }
  37773. var Attribute = /*#__PURE__*/function (_Namespace) {
  37774. _inheritsLoose(Attribute, _Namespace);
  37775. function Attribute(opts) {
  37776. var _this;
  37777. if (opts === void 0) {
  37778. opts = {};
  37779. }
  37780. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  37781. _this.type = _types.ATTRIBUTE;
  37782. _this.raws = _this.raws || {};
  37783. Object.defineProperty(_this.raws, 'unquoted', {
  37784. get: deprecate(function () {
  37785. return _this.value;
  37786. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  37787. set: deprecate(function () {
  37788. return _this.value;
  37789. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  37790. });
  37791. _this._constructed = true;
  37792. return _this;
  37793. }
  37794. /**
  37795. * Returns the Attribute's value quoted such that it would be legal to use
  37796. * in the value of a css file. The original value's quotation setting
  37797. * used for stringification is left unchanged. See `setValue(value, options)`
  37798. * if you want to control the quote settings of a new value for the attribute.
  37799. *
  37800. * You can also change the quotation used for the current value by setting quoteMark.
  37801. *
  37802. * Options:
  37803. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  37804. * option is not set, the original value for quoteMark will be used. If
  37805. * indeterminate, a double quote is used. The legal values are:
  37806. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  37807. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  37808. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  37809. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  37810. * over the quoteMark option value.
  37811. * * smart {boolean} - if true, will select a quote mark based on the value
  37812. * and the other options specified here. See the `smartQuoteMark()`
  37813. * method.
  37814. **/
  37815. var _proto = Attribute.prototype;
  37816. _proto.getQuotedValue = function getQuotedValue(options) {
  37817. if (options === void 0) {
  37818. options = {};
  37819. }
  37820. var quoteMark = this._determineQuoteMark(options);
  37821. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  37822. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  37823. return escaped;
  37824. };
  37825. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  37826. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  37827. }
  37828. /**
  37829. * Set the unescaped value with the specified quotation options. The value
  37830. * provided must not include any wrapping quote marks -- those quotes will
  37831. * be interpreted as part of the value and escaped accordingly.
  37832. */;
  37833. _proto.setValue = function setValue(value, options) {
  37834. if (options === void 0) {
  37835. options = {};
  37836. }
  37837. this._value = value;
  37838. this._quoteMark = this._determineQuoteMark(options);
  37839. this._syncRawValue();
  37840. }
  37841. /**
  37842. * Intelligently select a quoteMark value based on the value's contents. If
  37843. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  37844. * mark will be picked that minimizes the number of escapes.
  37845. *
  37846. * If there's no clear winner, the quote mark from these options is used,
  37847. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  37848. * true). If the quoteMark is unspecified, a double quote is used.
  37849. *
  37850. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  37851. * from the quoteValue method.
  37852. */;
  37853. _proto.smartQuoteMark = function smartQuoteMark(options) {
  37854. var v = this.value;
  37855. var numSingleQuotes = v.replace(/[^']/g, '').length;
  37856. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  37857. if (numSingleQuotes + numDoubleQuotes === 0) {
  37858. var escaped = (0, _cssesc["default"])(v, {
  37859. isIdentifier: true
  37860. });
  37861. if (escaped === v) {
  37862. return Attribute.NO_QUOTE;
  37863. } else {
  37864. var pref = this.preferredQuoteMark(options);
  37865. if (pref === Attribute.NO_QUOTE) {
  37866. // pick a quote mark that isn't none and see if it's smaller
  37867. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  37868. var opts = CSSESC_QUOTE_OPTIONS[quote];
  37869. var quoteValue = (0, _cssesc["default"])(v, opts);
  37870. if (quoteValue.length < escaped.length) {
  37871. return quote;
  37872. }
  37873. }
  37874. return pref;
  37875. }
  37876. } else if (numDoubleQuotes === numSingleQuotes) {
  37877. return this.preferredQuoteMark(options);
  37878. } else if (numDoubleQuotes < numSingleQuotes) {
  37879. return Attribute.DOUBLE_QUOTE;
  37880. } else {
  37881. return Attribute.SINGLE_QUOTE;
  37882. }
  37883. }
  37884. /**
  37885. * Selects the preferred quote mark based on the options and the current quote mark value.
  37886. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  37887. * instead.
  37888. */;
  37889. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  37890. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  37891. if (quoteMark === undefined) {
  37892. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  37893. }
  37894. if (quoteMark === undefined) {
  37895. quoteMark = Attribute.DOUBLE_QUOTE;
  37896. }
  37897. return quoteMark;
  37898. };
  37899. _proto._syncRawValue = function _syncRawValue() {
  37900. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  37901. if (rawValue === this._value) {
  37902. if (this.raws) {
  37903. delete this.raws.value;
  37904. }
  37905. } else {
  37906. this.raws.value = rawValue;
  37907. }
  37908. };
  37909. _proto._handleEscapes = function _handleEscapes(prop, value) {
  37910. if (this._constructed) {
  37911. var escaped = (0, _cssesc["default"])(value, {
  37912. isIdentifier: true
  37913. });
  37914. if (escaped !== value) {
  37915. this.raws[prop] = escaped;
  37916. } else {
  37917. delete this.raws[prop];
  37918. }
  37919. }
  37920. };
  37921. _proto._spacesFor = function _spacesFor(name) {
  37922. var attrSpaces = {
  37923. before: '',
  37924. after: ''
  37925. };
  37926. var spaces = this.spaces[name] || {};
  37927. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  37928. return Object.assign(attrSpaces, spaces, rawSpaces);
  37929. };
  37930. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  37931. if (spaceName === void 0) {
  37932. spaceName = name;
  37933. }
  37934. if (concat === void 0) {
  37935. concat = defaultAttrConcat;
  37936. }
  37937. var attrSpaces = this._spacesFor(spaceName);
  37938. return concat(this.stringifyProperty(name), attrSpaces);
  37939. }
  37940. /**
  37941. * returns the offset of the attribute part specified relative to the
  37942. * start of the node of the output string.
  37943. *
  37944. * * "ns" - alias for "namespace"
  37945. * * "namespace" - the namespace if it exists.
  37946. * * "attribute" - the attribute name
  37947. * * "attributeNS" - the start of the attribute or its namespace
  37948. * * "operator" - the match operator of the attribute
  37949. * * "value" - The value (string or identifier)
  37950. * * "insensitive" - the case insensitivity flag;
  37951. * @param part One of the possible values inside an attribute.
  37952. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  37953. */;
  37954. _proto.offsetOf = function offsetOf(name) {
  37955. var count = 1;
  37956. var attributeSpaces = this._spacesFor("attribute");
  37957. count += attributeSpaces.before.length;
  37958. if (name === "namespace" || name === "ns") {
  37959. return this.namespace ? count : -1;
  37960. }
  37961. if (name === "attributeNS") {
  37962. return count;
  37963. }
  37964. count += this.namespaceString.length;
  37965. if (this.namespace) {
  37966. count += 1;
  37967. }
  37968. if (name === "attribute") {
  37969. return count;
  37970. }
  37971. count += this.stringifyProperty("attribute").length;
  37972. count += attributeSpaces.after.length;
  37973. var operatorSpaces = this._spacesFor("operator");
  37974. count += operatorSpaces.before.length;
  37975. var operator = this.stringifyProperty("operator");
  37976. if (name === "operator") {
  37977. return operator ? count : -1;
  37978. }
  37979. count += operator.length;
  37980. count += operatorSpaces.after.length;
  37981. var valueSpaces = this._spacesFor("value");
  37982. count += valueSpaces.before.length;
  37983. var value = this.stringifyProperty("value");
  37984. if (name === "value") {
  37985. return value ? count : -1;
  37986. }
  37987. count += value.length;
  37988. count += valueSpaces.after.length;
  37989. var insensitiveSpaces = this._spacesFor("insensitive");
  37990. count += insensitiveSpaces.before.length;
  37991. if (name === "insensitive") {
  37992. return this.insensitive ? count : -1;
  37993. }
  37994. return -1;
  37995. };
  37996. _proto.toString = function toString() {
  37997. var _this2 = this;
  37998. var selector = [this.rawSpaceBefore, '['];
  37999. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  38000. if (this.operator && (this.value || this.value === '')) {
  38001. selector.push(this._stringFor('operator'));
  38002. selector.push(this._stringFor('value'));
  38003. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  38004. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  38005. attrSpaces.before = " ";
  38006. }
  38007. return defaultAttrConcat(attrValue, attrSpaces);
  38008. }));
  38009. }
  38010. selector.push(']');
  38011. selector.push(this.rawSpaceAfter);
  38012. return selector.join('');
  38013. };
  38014. _createClass(Attribute, [{
  38015. key: "quoted",
  38016. get: function get() {
  38017. var qm = this.quoteMark;
  38018. return qm === "'" || qm === '"';
  38019. },
  38020. set: function set(value) {
  38021. warnOfDeprecatedQuotedAssignment();
  38022. }
  38023. /**
  38024. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  38025. * returns `null` if the value is not quoted.
  38026. * returns `undefined` if the quotation state is unknown (this can happen when
  38027. * the attribute is constructed without specifying a quote mark.)
  38028. */
  38029. }, {
  38030. key: "quoteMark",
  38031. get: function get() {
  38032. return this._quoteMark;
  38033. }
  38034. /**
  38035. * Set the quote mark to be used by this attribute's value.
  38036. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  38037. * value is updated accordingly.
  38038. *
  38039. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  38040. */,
  38041. set: function set(quoteMark) {
  38042. if (!this._constructed) {
  38043. this._quoteMark = quoteMark;
  38044. return;
  38045. }
  38046. if (this._quoteMark !== quoteMark) {
  38047. this._quoteMark = quoteMark;
  38048. this._syncRawValue();
  38049. }
  38050. }
  38051. }, {
  38052. key: "qualifiedAttribute",
  38053. get: function get() {
  38054. return this.qualifiedName(this.raws.attribute || this.attribute);
  38055. }
  38056. }, {
  38057. key: "insensitiveFlag",
  38058. get: function get() {
  38059. return this.insensitive ? 'i' : '';
  38060. }
  38061. }, {
  38062. key: "value",
  38063. get: function get() {
  38064. return this._value;
  38065. },
  38066. set:
  38067. /**
  38068. * Before 3.0, the value had to be set to an escaped value including any wrapped
  38069. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  38070. * is unescaped during parsing and any quote marks are removed.
  38071. *
  38072. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  38073. * a deprecation warning is raised when the new value contains any characters that would
  38074. * require escaping (including if it contains wrapped quotes).
  38075. *
  38076. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  38077. * how the new value is quoted.
  38078. */
  38079. function set(v) {
  38080. if (this._constructed) {
  38081. var _unescapeValue2 = unescapeValue(v),
  38082. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  38083. unescaped = _unescapeValue2.unescaped,
  38084. quoteMark = _unescapeValue2.quoteMark;
  38085. if (deprecatedUsage) {
  38086. warnOfDeprecatedValueAssignment();
  38087. }
  38088. if (unescaped === this._value && quoteMark === this._quoteMark) {
  38089. return;
  38090. }
  38091. this._value = unescaped;
  38092. this._quoteMark = quoteMark;
  38093. this._syncRawValue();
  38094. } else {
  38095. this._value = v;
  38096. }
  38097. }
  38098. }, {
  38099. key: "insensitive",
  38100. get: function get() {
  38101. return this._insensitive;
  38102. }
  38103. /**
  38104. * Set the case insensitive flag.
  38105. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  38106. * of the attribute is updated accordingly.
  38107. *
  38108. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  38109. */,
  38110. set: function set(insensitive) {
  38111. if (!insensitive) {
  38112. this._insensitive = false;
  38113. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  38114. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  38115. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  38116. this.raws.insensitiveFlag = undefined;
  38117. }
  38118. }
  38119. this._insensitive = insensitive;
  38120. }
  38121. }, {
  38122. key: "attribute",
  38123. get: function get() {
  38124. return this._attribute;
  38125. },
  38126. set: function set(name) {
  38127. this._handleEscapes("attribute", name);
  38128. this._attribute = name;
  38129. }
  38130. }]);
  38131. return Attribute;
  38132. }(_namespace["default"]);
  38133. exports["default"] = Attribute;
  38134. Attribute.NO_QUOTE = null;
  38135. Attribute.SINGLE_QUOTE = "'";
  38136. Attribute.DOUBLE_QUOTE = '"';
  38137. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  38138. "'": {
  38139. quotes: 'single',
  38140. wrap: true
  38141. },
  38142. '"': {
  38143. quotes: 'double',
  38144. wrap: true
  38145. }
  38146. }, _CSSESC_QUOTE_OPTIONS[null] = {
  38147. isIdentifier: true
  38148. }, _CSSESC_QUOTE_OPTIONS);
  38149. function defaultAttrConcat(attrValue, attrSpaces) {
  38150. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  38151. }
  38152. } (attribute));
  38153. return attribute;
  38154. }
  38155. var universal = {exports: {}};
  38156. var hasRequiredUniversal;
  38157. function requireUniversal () {
  38158. if (hasRequiredUniversal) return universal.exports;
  38159. hasRequiredUniversal = 1;
  38160. (function (module, exports) {
  38161. exports.__esModule = true;
  38162. exports["default"] = void 0;
  38163. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  38164. var _types = /*@__PURE__*/ requireTypes();
  38165. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38166. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38167. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38168. var Universal = /*#__PURE__*/function (_Namespace) {
  38169. _inheritsLoose(Universal, _Namespace);
  38170. function Universal(opts) {
  38171. var _this;
  38172. _this = _Namespace.call(this, opts) || this;
  38173. _this.type = _types.UNIVERSAL;
  38174. _this.value = '*';
  38175. return _this;
  38176. }
  38177. return Universal;
  38178. }(_namespace["default"]);
  38179. exports["default"] = Universal;
  38180. module.exports = exports.default;
  38181. } (universal, universal.exports));
  38182. return universal.exports;
  38183. }
  38184. var combinator = {exports: {}};
  38185. var hasRequiredCombinator;
  38186. function requireCombinator () {
  38187. if (hasRequiredCombinator) return combinator.exports;
  38188. hasRequiredCombinator = 1;
  38189. (function (module, exports) {
  38190. exports.__esModule = true;
  38191. exports["default"] = void 0;
  38192. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38193. var _types = /*@__PURE__*/ requireTypes();
  38194. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38195. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38196. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38197. var Combinator = /*#__PURE__*/function (_Node) {
  38198. _inheritsLoose(Combinator, _Node);
  38199. function Combinator(opts) {
  38200. var _this;
  38201. _this = _Node.call(this, opts) || this;
  38202. _this.type = _types.COMBINATOR;
  38203. return _this;
  38204. }
  38205. return Combinator;
  38206. }(_node["default"]);
  38207. exports["default"] = Combinator;
  38208. module.exports = exports.default;
  38209. } (combinator, combinator.exports));
  38210. return combinator.exports;
  38211. }
  38212. var nesting = {exports: {}};
  38213. var hasRequiredNesting;
  38214. function requireNesting () {
  38215. if (hasRequiredNesting) return nesting.exports;
  38216. hasRequiredNesting = 1;
  38217. (function (module, exports) {
  38218. exports.__esModule = true;
  38219. exports["default"] = void 0;
  38220. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38221. var _types = /*@__PURE__*/ requireTypes();
  38222. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38223. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38224. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38225. var Nesting = /*#__PURE__*/function (_Node) {
  38226. _inheritsLoose(Nesting, _Node);
  38227. function Nesting(opts) {
  38228. var _this;
  38229. _this = _Node.call(this, opts) || this;
  38230. _this.type = _types.NESTING;
  38231. _this.value = '&';
  38232. return _this;
  38233. }
  38234. return Nesting;
  38235. }(_node["default"]);
  38236. exports["default"] = Nesting;
  38237. module.exports = exports.default;
  38238. } (nesting, nesting.exports));
  38239. return nesting.exports;
  38240. }
  38241. var sortAscending = {exports: {}};
  38242. var hasRequiredSortAscending;
  38243. function requireSortAscending () {
  38244. if (hasRequiredSortAscending) return sortAscending.exports;
  38245. hasRequiredSortAscending = 1;
  38246. (function (module, exports) {
  38247. exports.__esModule = true;
  38248. exports["default"] = sortAscending;
  38249. function sortAscending(list) {
  38250. return list.sort(function (a, b) {
  38251. return a - b;
  38252. });
  38253. }
  38254. module.exports = exports.default;
  38255. } (sortAscending, sortAscending.exports));
  38256. return sortAscending.exports;
  38257. }
  38258. var tokenize = {};
  38259. var tokenTypes = {};
  38260. var hasRequiredTokenTypes;
  38261. function requireTokenTypes () {
  38262. if (hasRequiredTokenTypes) return tokenTypes;
  38263. hasRequiredTokenTypes = 1;
  38264. tokenTypes.__esModule = true;
  38265. 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;
  38266. var ampersand = 38; // `&`.charCodeAt(0);
  38267. tokenTypes.ampersand = ampersand;
  38268. var asterisk = 42; // `*`.charCodeAt(0);
  38269. tokenTypes.asterisk = asterisk;
  38270. var at = 64; // `@`.charCodeAt(0);
  38271. tokenTypes.at = at;
  38272. var comma = 44; // `,`.charCodeAt(0);
  38273. tokenTypes.comma = comma;
  38274. var colon = 58; // `:`.charCodeAt(0);
  38275. tokenTypes.colon = colon;
  38276. var semicolon = 59; // `;`.charCodeAt(0);
  38277. tokenTypes.semicolon = semicolon;
  38278. var openParenthesis = 40; // `(`.charCodeAt(0);
  38279. tokenTypes.openParenthesis = openParenthesis;
  38280. var closeParenthesis = 41; // `)`.charCodeAt(0);
  38281. tokenTypes.closeParenthesis = closeParenthesis;
  38282. var openSquare = 91; // `[`.charCodeAt(0);
  38283. tokenTypes.openSquare = openSquare;
  38284. var closeSquare = 93; // `]`.charCodeAt(0);
  38285. tokenTypes.closeSquare = closeSquare;
  38286. var dollar = 36; // `$`.charCodeAt(0);
  38287. tokenTypes.dollar = dollar;
  38288. var tilde = 126; // `~`.charCodeAt(0);
  38289. tokenTypes.tilde = tilde;
  38290. var caret = 94; // `^`.charCodeAt(0);
  38291. tokenTypes.caret = caret;
  38292. var plus = 43; // `+`.charCodeAt(0);
  38293. tokenTypes.plus = plus;
  38294. var equals = 61; // `=`.charCodeAt(0);
  38295. tokenTypes.equals = equals;
  38296. var pipe = 124; // `|`.charCodeAt(0);
  38297. tokenTypes.pipe = pipe;
  38298. var greaterThan = 62; // `>`.charCodeAt(0);
  38299. tokenTypes.greaterThan = greaterThan;
  38300. var space = 32; // ` `.charCodeAt(0);
  38301. tokenTypes.space = space;
  38302. var singleQuote = 39; // `'`.charCodeAt(0);
  38303. tokenTypes.singleQuote = singleQuote;
  38304. var doubleQuote = 34; // `"`.charCodeAt(0);
  38305. tokenTypes.doubleQuote = doubleQuote;
  38306. var slash = 47; // `/`.charCodeAt(0);
  38307. tokenTypes.slash = slash;
  38308. var bang = 33; // `!`.charCodeAt(0);
  38309. tokenTypes.bang = bang;
  38310. var backslash = 92; // '\\'.charCodeAt(0);
  38311. tokenTypes.backslash = backslash;
  38312. var cr = 13; // '\r'.charCodeAt(0);
  38313. tokenTypes.cr = cr;
  38314. var feed = 12; // '\f'.charCodeAt(0);
  38315. tokenTypes.feed = feed;
  38316. var newline = 10; // '\n'.charCodeAt(0);
  38317. tokenTypes.newline = newline;
  38318. var tab = 9; // '\t'.charCodeAt(0);
  38319. // Expose aliases primarily for readability.
  38320. tokenTypes.tab = tab;
  38321. var str = singleQuote;
  38322. // No good single character representation!
  38323. tokenTypes.str = str;
  38324. var comment = -1;
  38325. tokenTypes.comment = comment;
  38326. var word = -2;
  38327. tokenTypes.word = word;
  38328. var combinator = -3;
  38329. tokenTypes.combinator = combinator;
  38330. return tokenTypes;
  38331. }
  38332. var hasRequiredTokenize;
  38333. function requireTokenize () {
  38334. if (hasRequiredTokenize) return tokenize;
  38335. hasRequiredTokenize = 1;
  38336. (function (exports) {
  38337. exports.__esModule = true;
  38338. exports.FIELDS = void 0;
  38339. exports["default"] = tokenize;
  38340. var t = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38341. var _unescapable, _wordDelimiters;
  38342. 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); }
  38343. 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; }
  38344. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  38345. 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);
  38346. var hex = {};
  38347. var hexChars = "0123456789abcdefABCDEF";
  38348. for (var i = 0; i < hexChars.length; i++) {
  38349. hex[hexChars.charCodeAt(i)] = true;
  38350. }
  38351. /**
  38352. * Returns the last index of the bar css word
  38353. * @param {string} css The string in which the word begins
  38354. * @param {number} start The index into the string where word's first letter occurs
  38355. */
  38356. function consumeWord(css, start) {
  38357. var next = start;
  38358. var code;
  38359. do {
  38360. code = css.charCodeAt(next);
  38361. if (wordDelimiters[code]) {
  38362. return next - 1;
  38363. } else if (code === t.backslash) {
  38364. next = consumeEscape(css, next) + 1;
  38365. } else {
  38366. // All other characters are part of the word
  38367. next++;
  38368. }
  38369. } while (next < css.length);
  38370. return next - 1;
  38371. }
  38372. /**
  38373. * Returns the last index of the escape sequence
  38374. * @param {string} css The string in which the sequence begins
  38375. * @param {number} start The index into the string where escape character (`\`) occurs.
  38376. */
  38377. function consumeEscape(css, start) {
  38378. var next = start;
  38379. var code = css.charCodeAt(next + 1);
  38380. if (unescapable[code]) ; else if (hex[code]) {
  38381. var hexDigits = 0;
  38382. // consume up to 6 hex chars
  38383. do {
  38384. next++;
  38385. hexDigits++;
  38386. code = css.charCodeAt(next + 1);
  38387. } while (hex[code] && hexDigits < 6);
  38388. // if fewer than 6 hex chars, a trailing space ends the escape
  38389. if (hexDigits < 6 && code === t.space) {
  38390. next++;
  38391. }
  38392. } else {
  38393. // the next char is part of the current word
  38394. next++;
  38395. }
  38396. return next;
  38397. }
  38398. var FIELDS = {
  38399. TYPE: 0,
  38400. START_LINE: 1,
  38401. START_COL: 2,
  38402. END_LINE: 3,
  38403. END_COL: 4,
  38404. START_POS: 5,
  38405. END_POS: 6
  38406. };
  38407. exports.FIELDS = FIELDS;
  38408. function tokenize(input) {
  38409. var tokens = [];
  38410. var css = input.css.valueOf();
  38411. var _css = css,
  38412. length = _css.length;
  38413. var offset = -1;
  38414. var line = 1;
  38415. var start = 0;
  38416. var end = 0;
  38417. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  38418. function unclosed(what, fix) {
  38419. if (input.safe) {
  38420. // fyi: this is never set to true.
  38421. css += fix;
  38422. next = css.length - 1;
  38423. } else {
  38424. throw input.error('Unclosed ' + what, line, start - offset, start);
  38425. }
  38426. }
  38427. while (start < length) {
  38428. code = css.charCodeAt(start);
  38429. if (code === t.newline) {
  38430. offset = start;
  38431. line += 1;
  38432. }
  38433. switch (code) {
  38434. case t.space:
  38435. case t.tab:
  38436. case t.newline:
  38437. case t.cr:
  38438. case t.feed:
  38439. next = start;
  38440. do {
  38441. next += 1;
  38442. code = css.charCodeAt(next);
  38443. if (code === t.newline) {
  38444. offset = next;
  38445. line += 1;
  38446. }
  38447. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38448. tokenType = t.space;
  38449. endLine = line;
  38450. endColumn = next - offset - 1;
  38451. end = next;
  38452. break;
  38453. case t.plus:
  38454. case t.greaterThan:
  38455. case t.tilde:
  38456. case t.pipe:
  38457. next = start;
  38458. do {
  38459. next += 1;
  38460. code = css.charCodeAt(next);
  38461. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38462. tokenType = t.combinator;
  38463. endLine = line;
  38464. endColumn = start - offset;
  38465. end = next;
  38466. break;
  38467. // Consume these characters as single tokens.
  38468. case t.asterisk:
  38469. case t.ampersand:
  38470. case t.bang:
  38471. case t.comma:
  38472. case t.equals:
  38473. case t.dollar:
  38474. case t.caret:
  38475. case t.openSquare:
  38476. case t.closeSquare:
  38477. case t.colon:
  38478. case t.semicolon:
  38479. case t.openParenthesis:
  38480. case t.closeParenthesis:
  38481. next = start;
  38482. tokenType = code;
  38483. endLine = line;
  38484. endColumn = start - offset;
  38485. end = next + 1;
  38486. break;
  38487. case t.singleQuote:
  38488. case t.doubleQuote:
  38489. quote = code === t.singleQuote ? "'" : '"';
  38490. next = start;
  38491. do {
  38492. escaped = false;
  38493. next = css.indexOf(quote, next + 1);
  38494. if (next === -1) {
  38495. unclosed('quote', quote);
  38496. }
  38497. escapePos = next;
  38498. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38499. escapePos -= 1;
  38500. escaped = !escaped;
  38501. }
  38502. } while (escaped);
  38503. tokenType = t.str;
  38504. endLine = line;
  38505. endColumn = start - offset;
  38506. end = next + 1;
  38507. break;
  38508. default:
  38509. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38510. next = css.indexOf('*/', start + 2) + 1;
  38511. if (next === 0) {
  38512. unclosed('comment', '*/');
  38513. }
  38514. content = css.slice(start, next + 1);
  38515. lines = content.split('\n');
  38516. last = lines.length - 1;
  38517. if (last > 0) {
  38518. nextLine = line + last;
  38519. nextOffset = next - lines[last].length;
  38520. } else {
  38521. nextLine = line;
  38522. nextOffset = offset;
  38523. }
  38524. tokenType = t.comment;
  38525. line = nextLine;
  38526. endLine = nextLine;
  38527. endColumn = next - nextOffset;
  38528. } else if (code === t.slash) {
  38529. next = start;
  38530. tokenType = code;
  38531. endLine = line;
  38532. endColumn = start - offset;
  38533. end = next + 1;
  38534. } else {
  38535. next = consumeWord(css, start);
  38536. tokenType = t.word;
  38537. endLine = line;
  38538. endColumn = next - offset;
  38539. }
  38540. end = next + 1;
  38541. break;
  38542. }
  38543. // Ensure that the token structure remains consistent
  38544. tokens.push([tokenType,
  38545. // [0] Token type
  38546. line,
  38547. // [1] Starting line
  38548. start - offset,
  38549. // [2] Starting column
  38550. endLine,
  38551. // [3] Ending line
  38552. endColumn,
  38553. // [4] Ending column
  38554. start,
  38555. // [5] Start position / Source index
  38556. end // [6] End position
  38557. ]);
  38558. // Reset offset for the next token
  38559. if (nextOffset) {
  38560. offset = nextOffset;
  38561. nextOffset = null;
  38562. }
  38563. start = end;
  38564. }
  38565. return tokens;
  38566. }
  38567. } (tokenize));
  38568. return tokenize;
  38569. }
  38570. var hasRequiredParser;
  38571. function requireParser () {
  38572. if (hasRequiredParser) return parser.exports;
  38573. hasRequiredParser = 1;
  38574. (function (module, exports) {
  38575. exports.__esModule = true;
  38576. exports["default"] = void 0;
  38577. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  38578. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  38579. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  38580. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  38581. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  38582. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  38583. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  38584. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  38585. var _attribute = _interopRequireWildcard(/*@__PURE__*/ requireAttribute());
  38586. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  38587. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  38588. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  38589. var _sortAscending = _interopRequireDefault(/*@__PURE__*/ requireSortAscending());
  38590. var _tokenize = _interopRequireWildcard(/*@__PURE__*/ requireTokenize());
  38591. var tokens = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38592. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  38593. var _util = /*@__PURE__*/ requireUtil$1();
  38594. var _WHITESPACE_TOKENS, _Object$assign;
  38595. 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); }
  38596. 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; }
  38597. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38598. 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); } }
  38599. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38600. 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);
  38601. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38602. function tokenStart(token) {
  38603. return {
  38604. line: token[_tokenize.FIELDS.START_LINE],
  38605. column: token[_tokenize.FIELDS.START_COL]
  38606. };
  38607. }
  38608. function tokenEnd(token) {
  38609. return {
  38610. line: token[_tokenize.FIELDS.END_LINE],
  38611. column: token[_tokenize.FIELDS.END_COL]
  38612. };
  38613. }
  38614. function getSource(startLine, startColumn, endLine, endColumn) {
  38615. return {
  38616. start: {
  38617. line: startLine,
  38618. column: startColumn
  38619. },
  38620. end: {
  38621. line: endLine,
  38622. column: endColumn
  38623. }
  38624. };
  38625. }
  38626. function getTokenSource(token) {
  38627. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38628. }
  38629. function getTokenSourceSpan(startToken, endToken) {
  38630. if (!startToken) {
  38631. return undefined;
  38632. }
  38633. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38634. }
  38635. function unescapeProp(node, prop) {
  38636. var value = node[prop];
  38637. if (typeof value !== "string") {
  38638. return;
  38639. }
  38640. if (value.indexOf("\\") !== -1) {
  38641. (0, _util.ensureObject)(node, 'raws');
  38642. node[prop] = (0, _util.unesc)(value);
  38643. if (node.raws[prop] === undefined) {
  38644. node.raws[prop] = value;
  38645. }
  38646. }
  38647. return node;
  38648. }
  38649. function indexesOf(array, item) {
  38650. var i = -1;
  38651. var indexes = [];
  38652. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38653. indexes.push(i);
  38654. }
  38655. return indexes;
  38656. }
  38657. function uniqs() {
  38658. var list = Array.prototype.concat.apply([], arguments);
  38659. return list.filter(function (item, i) {
  38660. return i === list.indexOf(item);
  38661. });
  38662. }
  38663. var Parser = /*#__PURE__*/function () {
  38664. function Parser(rule, options) {
  38665. if (options === void 0) {
  38666. options = {};
  38667. }
  38668. this.rule = rule;
  38669. this.options = Object.assign({
  38670. lossy: false,
  38671. safe: false
  38672. }, options);
  38673. this.position = 0;
  38674. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38675. this.tokens = (0, _tokenize["default"])({
  38676. css: this.css,
  38677. error: this._errorGenerator(),
  38678. safe: this.options.safe
  38679. });
  38680. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38681. this.root = new _root["default"]({
  38682. source: rootSource
  38683. });
  38684. this.root.errorGenerator = this._errorGenerator();
  38685. var selector = new _selector["default"]({
  38686. source: {
  38687. start: {
  38688. line: 1,
  38689. column: 1
  38690. }
  38691. },
  38692. sourceIndex: 0
  38693. });
  38694. this.root.append(selector);
  38695. this.current = selector;
  38696. this.loop();
  38697. }
  38698. var _proto = Parser.prototype;
  38699. _proto._errorGenerator = function _errorGenerator() {
  38700. var _this = this;
  38701. return function (message, errorOptions) {
  38702. if (typeof _this.rule === 'string') {
  38703. return new Error(message);
  38704. }
  38705. return _this.rule.error(message, errorOptions);
  38706. };
  38707. };
  38708. _proto.attribute = function attribute() {
  38709. var attr = [];
  38710. var startingToken = this.currToken;
  38711. this.position++;
  38712. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38713. attr.push(this.currToken);
  38714. this.position++;
  38715. }
  38716. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38717. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38718. }
  38719. var len = attr.length;
  38720. var node = {
  38721. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38722. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38723. };
  38724. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38725. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38726. }
  38727. var pos = 0;
  38728. var spaceBefore = '';
  38729. var commentBefore = '';
  38730. var lastAdded = null;
  38731. var spaceAfterMeaningfulToken = false;
  38732. while (pos < len) {
  38733. var token = attr[pos];
  38734. var content = this.content(token);
  38735. var next = attr[pos + 1];
  38736. switch (token[_tokenize.FIELDS.TYPE]) {
  38737. case tokens.space:
  38738. // if (
  38739. // len === 1 ||
  38740. // pos === 0 && this.content(next) === '|'
  38741. // ) {
  38742. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38743. // }
  38744. spaceAfterMeaningfulToken = true;
  38745. if (this.options.lossy) {
  38746. break;
  38747. }
  38748. if (lastAdded) {
  38749. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38750. var prevContent = node.spaces[lastAdded].after || '';
  38751. node.spaces[lastAdded].after = prevContent + content;
  38752. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38753. if (existingComment) {
  38754. node.raws.spaces[lastAdded].after = existingComment + content;
  38755. }
  38756. } else {
  38757. spaceBefore = spaceBefore + content;
  38758. commentBefore = commentBefore + content;
  38759. }
  38760. break;
  38761. case tokens.asterisk:
  38762. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38763. node.operator = content;
  38764. lastAdded = 'operator';
  38765. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  38766. if (spaceBefore) {
  38767. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38768. node.spaces.attribute.before = spaceBefore;
  38769. spaceBefore = '';
  38770. }
  38771. if (commentBefore) {
  38772. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38773. node.raws.spaces.attribute.before = spaceBefore;
  38774. commentBefore = '';
  38775. }
  38776. node.namespace = (node.namespace || "") + content;
  38777. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  38778. if (rawValue) {
  38779. node.raws.namespace += content;
  38780. }
  38781. lastAdded = 'namespace';
  38782. }
  38783. spaceAfterMeaningfulToken = false;
  38784. break;
  38785. case tokens.dollar:
  38786. if (lastAdded === "value") {
  38787. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  38788. node.value += "$";
  38789. if (oldRawValue) {
  38790. node.raws.value = oldRawValue + "$";
  38791. }
  38792. break;
  38793. }
  38794. // Falls through
  38795. case tokens.caret:
  38796. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38797. node.operator = content;
  38798. lastAdded = 'operator';
  38799. }
  38800. spaceAfterMeaningfulToken = false;
  38801. break;
  38802. case tokens.combinator:
  38803. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38804. node.operator = content;
  38805. lastAdded = 'operator';
  38806. }
  38807. if (content !== '|') {
  38808. spaceAfterMeaningfulToken = false;
  38809. break;
  38810. }
  38811. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38812. node.operator = content;
  38813. lastAdded = 'operator';
  38814. } else if (!node.namespace && !node.attribute) {
  38815. node.namespace = true;
  38816. }
  38817. spaceAfterMeaningfulToken = false;
  38818. break;
  38819. case tokens.word:
  38820. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  38821. // this look-ahead probably fails with comment nodes involved.
  38822. !node.operator && !node.namespace) {
  38823. node.namespace = content;
  38824. lastAdded = 'namespace';
  38825. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  38826. if (spaceBefore) {
  38827. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38828. node.spaces.attribute.before = spaceBefore;
  38829. spaceBefore = '';
  38830. }
  38831. if (commentBefore) {
  38832. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38833. node.raws.spaces.attribute.before = commentBefore;
  38834. commentBefore = '';
  38835. }
  38836. node.attribute = (node.attribute || "") + content;
  38837. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  38838. if (_rawValue) {
  38839. node.raws.attribute += content;
  38840. }
  38841. lastAdded = 'attribute';
  38842. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  38843. var _unescaped = (0, _util.unesc)(content);
  38844. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  38845. var oldValue = node.value || '';
  38846. node.value = oldValue + _unescaped;
  38847. node.quoteMark = null;
  38848. if (_unescaped !== content || _oldRawValue) {
  38849. (0, _util.ensureObject)(node, 'raws');
  38850. node.raws.value = (_oldRawValue || oldValue) + content;
  38851. }
  38852. lastAdded = 'value';
  38853. } else {
  38854. var insensitive = content === 'i' || content === "I";
  38855. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  38856. node.insensitive = insensitive;
  38857. if (!insensitive || content === "I") {
  38858. (0, _util.ensureObject)(node, 'raws');
  38859. node.raws.insensitiveFlag = content;
  38860. }
  38861. lastAdded = 'insensitive';
  38862. if (spaceBefore) {
  38863. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  38864. node.spaces.insensitive.before = spaceBefore;
  38865. spaceBefore = '';
  38866. }
  38867. if (commentBefore) {
  38868. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  38869. node.raws.spaces.insensitive.before = commentBefore;
  38870. commentBefore = '';
  38871. }
  38872. } else if (node.value || node.value === '') {
  38873. lastAdded = 'value';
  38874. node.value += content;
  38875. if (node.raws.value) {
  38876. node.raws.value += content;
  38877. }
  38878. }
  38879. }
  38880. spaceAfterMeaningfulToken = false;
  38881. break;
  38882. case tokens.str:
  38883. if (!node.attribute || !node.operator) {
  38884. return this.error("Expected an attribute followed by an operator preceding the string.", {
  38885. index: token[_tokenize.FIELDS.START_POS]
  38886. });
  38887. }
  38888. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  38889. unescaped = _unescapeValue.unescaped,
  38890. quoteMark = _unescapeValue.quoteMark;
  38891. node.value = unescaped;
  38892. node.quoteMark = quoteMark;
  38893. lastAdded = 'value';
  38894. (0, _util.ensureObject)(node, 'raws');
  38895. node.raws.value = content;
  38896. spaceAfterMeaningfulToken = false;
  38897. break;
  38898. case tokens.equals:
  38899. if (!node.attribute) {
  38900. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  38901. }
  38902. if (node.value) {
  38903. return this.error('Unexpected "=" found; an operator was already defined.', {
  38904. index: token[_tokenize.FIELDS.START_POS]
  38905. });
  38906. }
  38907. node.operator = node.operator ? node.operator + content : content;
  38908. lastAdded = 'operator';
  38909. spaceAfterMeaningfulToken = false;
  38910. break;
  38911. case tokens.comment:
  38912. if (lastAdded) {
  38913. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  38914. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  38915. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  38916. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  38917. node.raws.spaces[lastAdded].after = rawLastComment + content;
  38918. } else {
  38919. var lastValue = node[lastAdded] || '';
  38920. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  38921. (0, _util.ensureObject)(node, 'raws');
  38922. node.raws[lastAdded] = rawLastValue + content;
  38923. }
  38924. } else {
  38925. commentBefore = commentBefore + content;
  38926. }
  38927. break;
  38928. default:
  38929. return this.error("Unexpected \"" + content + "\" found.", {
  38930. index: token[_tokenize.FIELDS.START_POS]
  38931. });
  38932. }
  38933. pos++;
  38934. }
  38935. unescapeProp(node, "attribute");
  38936. unescapeProp(node, "namespace");
  38937. this.newNode(new _attribute["default"](node));
  38938. this.position++;
  38939. }
  38940. /**
  38941. * return a node containing meaningless garbage up to (but not including) the specified token position.
  38942. * if the token position is negative, all remaining tokens are consumed.
  38943. *
  38944. * This returns an array containing a single string node if all whitespace,
  38945. * otherwise an array of comment nodes with space before and after.
  38946. *
  38947. * These tokens are not added to the current selector, the caller can add them or use them to amend
  38948. * a previous node's space metadata.
  38949. *
  38950. * In lossy mode, this returns only comments.
  38951. */;
  38952. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  38953. if (stopPosition < 0) {
  38954. stopPosition = this.tokens.length;
  38955. }
  38956. var startPosition = this.position;
  38957. var nodes = [];
  38958. var space = "";
  38959. var lastComment = undefined;
  38960. do {
  38961. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  38962. if (!this.options.lossy) {
  38963. space += this.content();
  38964. }
  38965. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  38966. var spaces = {};
  38967. if (space) {
  38968. spaces.before = space;
  38969. space = "";
  38970. }
  38971. lastComment = new _comment["default"]({
  38972. value: this.content(),
  38973. source: getTokenSource(this.currToken),
  38974. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38975. spaces: spaces
  38976. });
  38977. nodes.push(lastComment);
  38978. }
  38979. } while (++this.position < stopPosition);
  38980. if (space) {
  38981. if (lastComment) {
  38982. lastComment.spaces.after = space;
  38983. } else if (!this.options.lossy) {
  38984. var firstToken = this.tokens[startPosition];
  38985. var lastToken = this.tokens[this.position - 1];
  38986. nodes.push(new _string["default"]({
  38987. value: '',
  38988. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  38989. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38990. spaces: {
  38991. before: space,
  38992. after: ''
  38993. }
  38994. }));
  38995. }
  38996. }
  38997. return nodes;
  38998. }
  38999. /**
  39000. *
  39001. * @param {*} nodes
  39002. */;
  39003. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  39004. var _this2 = this;
  39005. if (requiredSpace === void 0) {
  39006. requiredSpace = false;
  39007. }
  39008. var space = "";
  39009. var rawSpace = "";
  39010. nodes.forEach(function (n) {
  39011. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  39012. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  39013. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  39014. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  39015. });
  39016. if (rawSpace === space) {
  39017. rawSpace = undefined;
  39018. }
  39019. var result = {
  39020. space: space,
  39021. rawSpace: rawSpace
  39022. };
  39023. return result;
  39024. };
  39025. _proto.isNamedCombinator = function isNamedCombinator(position) {
  39026. if (position === void 0) {
  39027. position = this.position;
  39028. }
  39029. 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;
  39030. };
  39031. _proto.namedCombinator = function namedCombinator() {
  39032. if (this.isNamedCombinator()) {
  39033. var nameRaw = this.content(this.tokens[this.position + 1]);
  39034. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  39035. var raws = {};
  39036. if (name !== nameRaw) {
  39037. raws.value = "/" + nameRaw + "/";
  39038. }
  39039. var node = new _combinator["default"]({
  39040. value: "/" + name + "/",
  39041. 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]),
  39042. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39043. raws: raws
  39044. });
  39045. this.position = this.position + 3;
  39046. return node;
  39047. } else {
  39048. this.unexpected();
  39049. }
  39050. };
  39051. _proto.combinator = function combinator() {
  39052. var _this3 = this;
  39053. if (this.content() === '|') {
  39054. return this.namespace();
  39055. }
  39056. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  39057. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  39058. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39059. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39060. if (nodes.length > 0) {
  39061. var last = this.current.last;
  39062. if (last) {
  39063. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  39064. space = _this$convertWhitespa.space,
  39065. rawSpace = _this$convertWhitespa.rawSpace;
  39066. if (rawSpace !== undefined) {
  39067. last.rawSpaceAfter += rawSpace;
  39068. }
  39069. last.spaces.after += space;
  39070. } else {
  39071. nodes.forEach(function (n) {
  39072. return _this3.newNode(n);
  39073. });
  39074. }
  39075. }
  39076. return;
  39077. }
  39078. var firstToken = this.currToken;
  39079. var spaceOrDescendantSelectorNodes = undefined;
  39080. if (nextSigTokenPos > this.position) {
  39081. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39082. }
  39083. var node;
  39084. if (this.isNamedCombinator()) {
  39085. node = this.namedCombinator();
  39086. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  39087. node = new _combinator["default"]({
  39088. value: this.content(),
  39089. source: getTokenSource(this.currToken),
  39090. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  39091. });
  39092. this.position++;
  39093. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  39094. this.unexpected();
  39095. }
  39096. if (node) {
  39097. if (spaceOrDescendantSelectorNodes) {
  39098. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  39099. _space = _this$convertWhitespa2.space,
  39100. _rawSpace = _this$convertWhitespa2.rawSpace;
  39101. node.spaces.before = _space;
  39102. node.rawSpaceBefore = _rawSpace;
  39103. }
  39104. } else {
  39105. // descendant combinator
  39106. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  39107. _space2 = _this$convertWhitespa3.space,
  39108. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  39109. if (!_rawSpace2) {
  39110. _rawSpace2 = _space2;
  39111. }
  39112. var spaces = {};
  39113. var raws = {
  39114. spaces: {}
  39115. };
  39116. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  39117. spaces.before = _space2.slice(0, _space2.length - 1);
  39118. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  39119. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  39120. spaces.after = _space2.slice(1);
  39121. raws.spaces.after = _rawSpace2.slice(1);
  39122. } else {
  39123. raws.value = _rawSpace2;
  39124. }
  39125. node = new _combinator["default"]({
  39126. value: ' ',
  39127. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  39128. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39129. spaces: spaces,
  39130. raws: raws
  39131. });
  39132. }
  39133. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  39134. node.spaces.after = this.optionalSpace(this.content());
  39135. this.position++;
  39136. }
  39137. return this.newNode(node);
  39138. };
  39139. _proto.comma = function comma() {
  39140. if (this.position === this.tokens.length - 1) {
  39141. this.root.trailingComma = true;
  39142. this.position++;
  39143. return;
  39144. }
  39145. this.current._inferEndPosition();
  39146. var selector = new _selector["default"]({
  39147. source: {
  39148. start: tokenStart(this.tokens[this.position + 1])
  39149. },
  39150. sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
  39151. });
  39152. this.current.parent.append(selector);
  39153. this.current = selector;
  39154. this.position++;
  39155. };
  39156. _proto.comment = function comment() {
  39157. var current = this.currToken;
  39158. this.newNode(new _comment["default"]({
  39159. value: this.content(),
  39160. source: getTokenSource(current),
  39161. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39162. }));
  39163. this.position++;
  39164. };
  39165. _proto.error = function error(message, opts) {
  39166. throw this.root.error(message, opts);
  39167. };
  39168. _proto.missingBackslash = function missingBackslash() {
  39169. return this.error('Expected a backslash preceding the semicolon.', {
  39170. index: this.currToken[_tokenize.FIELDS.START_POS]
  39171. });
  39172. };
  39173. _proto.missingParenthesis = function missingParenthesis() {
  39174. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39175. };
  39176. _proto.missingSquareBracket = function missingSquareBracket() {
  39177. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  39178. };
  39179. _proto.unexpected = function unexpected() {
  39180. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  39181. };
  39182. _proto.unexpectedPipe = function unexpectedPipe() {
  39183. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  39184. };
  39185. _proto.namespace = function namespace() {
  39186. var before = this.prevToken && this.content(this.prevToken) || true;
  39187. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39188. this.position++;
  39189. return this.word(before);
  39190. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  39191. this.position++;
  39192. return this.universal(before);
  39193. }
  39194. this.unexpectedPipe();
  39195. };
  39196. _proto.nesting = function nesting() {
  39197. if (this.nextToken) {
  39198. var nextContent = this.content(this.nextToken);
  39199. if (nextContent === "|") {
  39200. this.position++;
  39201. return;
  39202. }
  39203. }
  39204. var current = this.currToken;
  39205. this.newNode(new _nesting["default"]({
  39206. value: this.content(),
  39207. source: getTokenSource(current),
  39208. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39209. }));
  39210. this.position++;
  39211. };
  39212. _proto.parentheses = function parentheses() {
  39213. var last = this.current.last;
  39214. var unbalanced = 1;
  39215. this.position++;
  39216. if (last && last.type === types.PSEUDO) {
  39217. var selector = new _selector["default"]({
  39218. source: {
  39219. start: tokenStart(this.tokens[this.position])
  39220. },
  39221. sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
  39222. });
  39223. var cache = this.current;
  39224. last.append(selector);
  39225. this.current = selector;
  39226. while (this.position < this.tokens.length && unbalanced) {
  39227. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39228. unbalanced++;
  39229. }
  39230. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39231. unbalanced--;
  39232. }
  39233. if (unbalanced) {
  39234. this.parse();
  39235. } else {
  39236. this.current.source.end = tokenEnd(this.currToken);
  39237. this.current.parent.source.end = tokenEnd(this.currToken);
  39238. this.position++;
  39239. }
  39240. }
  39241. this.current = cache;
  39242. } else {
  39243. // I think this case should be an error. It's used to implement a basic parse of media queries
  39244. // but I don't think it's a good idea.
  39245. var parenStart = this.currToken;
  39246. var parenValue = "(";
  39247. var parenEnd;
  39248. while (this.position < this.tokens.length && unbalanced) {
  39249. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39250. unbalanced++;
  39251. }
  39252. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39253. unbalanced--;
  39254. }
  39255. parenEnd = this.currToken;
  39256. parenValue += this.parseParenthesisToken(this.currToken);
  39257. this.position++;
  39258. }
  39259. if (last) {
  39260. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  39261. } else {
  39262. this.newNode(new _string["default"]({
  39263. value: parenValue,
  39264. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  39265. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  39266. }));
  39267. }
  39268. }
  39269. if (unbalanced) {
  39270. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39271. }
  39272. };
  39273. _proto.pseudo = function pseudo() {
  39274. var _this4 = this;
  39275. var pseudoStr = '';
  39276. var startingToken = this.currToken;
  39277. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  39278. pseudoStr += this.content();
  39279. this.position++;
  39280. }
  39281. if (!this.currToken) {
  39282. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  39283. }
  39284. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39285. this.splitWord(false, function (first, length) {
  39286. pseudoStr += first;
  39287. _this4.newNode(new _pseudo["default"]({
  39288. value: pseudoStr,
  39289. source: getTokenSourceSpan(startingToken, _this4.currToken),
  39290. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  39291. }));
  39292. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39293. _this4.error('Misplaced parenthesis.', {
  39294. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  39295. });
  39296. }
  39297. });
  39298. } else {
  39299. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  39300. }
  39301. };
  39302. _proto.space = function space() {
  39303. var content = this.content();
  39304. // Handle space before and after the selector
  39305. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  39306. return node.type === 'comment';
  39307. })) {
  39308. this.spaces = this.optionalSpace(content);
  39309. this.position++;
  39310. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39311. this.current.last.spaces.after = this.optionalSpace(content);
  39312. this.position++;
  39313. } else {
  39314. this.combinator();
  39315. }
  39316. };
  39317. _proto.string = function string() {
  39318. var current = this.currToken;
  39319. this.newNode(new _string["default"]({
  39320. value: this.content(),
  39321. source: getTokenSource(current),
  39322. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39323. }));
  39324. this.position++;
  39325. };
  39326. _proto.universal = function universal(namespace) {
  39327. var nextToken = this.nextToken;
  39328. if (nextToken && this.content(nextToken) === '|') {
  39329. this.position++;
  39330. return this.namespace();
  39331. }
  39332. var current = this.currToken;
  39333. this.newNode(new _universal["default"]({
  39334. value: this.content(),
  39335. source: getTokenSource(current),
  39336. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39337. }), namespace);
  39338. this.position++;
  39339. };
  39340. _proto.splitWord = function splitWord(namespace, firstCallback) {
  39341. var _this5 = this;
  39342. var nextToken = this.nextToken;
  39343. var word = this.content();
  39344. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  39345. this.position++;
  39346. var current = this.content();
  39347. word += current;
  39348. if (current.lastIndexOf('\\') === current.length - 1) {
  39349. var next = this.nextToken;
  39350. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  39351. word += this.requiredSpace(this.content(next));
  39352. this.position++;
  39353. }
  39354. }
  39355. nextToken = this.nextToken;
  39356. }
  39357. var hasClass = indexesOf(word, '.').filter(function (i) {
  39358. // Allow escaped dot within class name
  39359. var escapedDot = word[i - 1] === '\\';
  39360. // Allow decimal numbers percent in @keyframes
  39361. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  39362. return !escapedDot && !isKeyframesPercent;
  39363. });
  39364. var hasId = indexesOf(word, '#').filter(function (i) {
  39365. return word[i - 1] !== '\\';
  39366. });
  39367. // Eliminate Sass interpolations from the list of id indexes
  39368. var interpolations = indexesOf(word, '#{');
  39369. if (interpolations.length) {
  39370. hasId = hasId.filter(function (hashIndex) {
  39371. return !~interpolations.indexOf(hashIndex);
  39372. });
  39373. }
  39374. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  39375. indices.forEach(function (ind, i) {
  39376. var index = indices[i + 1] || word.length;
  39377. var value = word.slice(ind, index);
  39378. if (i === 0 && firstCallback) {
  39379. return firstCallback.call(_this5, value, indices.length);
  39380. }
  39381. var node;
  39382. var current = _this5.currToken;
  39383. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  39384. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  39385. if (~hasClass.indexOf(ind)) {
  39386. var classNameOpts = {
  39387. value: value.slice(1),
  39388. source: source,
  39389. sourceIndex: sourceIndex
  39390. };
  39391. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  39392. } else if (~hasId.indexOf(ind)) {
  39393. var idOpts = {
  39394. value: value.slice(1),
  39395. source: source,
  39396. sourceIndex: sourceIndex
  39397. };
  39398. node = new _id["default"](unescapeProp(idOpts, "value"));
  39399. } else {
  39400. var tagOpts = {
  39401. value: value,
  39402. source: source,
  39403. sourceIndex: sourceIndex
  39404. };
  39405. unescapeProp(tagOpts, "value");
  39406. node = new _tag["default"](tagOpts);
  39407. }
  39408. _this5.newNode(node, namespace);
  39409. // Ensure that the namespace is used only once
  39410. namespace = null;
  39411. });
  39412. this.position++;
  39413. };
  39414. _proto.word = function word(namespace) {
  39415. var nextToken = this.nextToken;
  39416. if (nextToken && this.content(nextToken) === '|') {
  39417. this.position++;
  39418. return this.namespace();
  39419. }
  39420. return this.splitWord(namespace);
  39421. };
  39422. _proto.loop = function loop() {
  39423. while (this.position < this.tokens.length) {
  39424. this.parse(true);
  39425. }
  39426. this.current._inferEndPosition();
  39427. return this.root;
  39428. };
  39429. _proto.parse = function parse(throwOnParenthesis) {
  39430. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  39431. case tokens.space:
  39432. this.space();
  39433. break;
  39434. case tokens.comment:
  39435. this.comment();
  39436. break;
  39437. case tokens.openParenthesis:
  39438. this.parentheses();
  39439. break;
  39440. case tokens.closeParenthesis:
  39441. if (throwOnParenthesis) {
  39442. this.missingParenthesis();
  39443. }
  39444. break;
  39445. case tokens.openSquare:
  39446. this.attribute();
  39447. break;
  39448. case tokens.dollar:
  39449. case tokens.caret:
  39450. case tokens.equals:
  39451. case tokens.word:
  39452. this.word();
  39453. break;
  39454. case tokens.colon:
  39455. this.pseudo();
  39456. break;
  39457. case tokens.comma:
  39458. this.comma();
  39459. break;
  39460. case tokens.asterisk:
  39461. this.universal();
  39462. break;
  39463. case tokens.ampersand:
  39464. this.nesting();
  39465. break;
  39466. case tokens.slash:
  39467. case tokens.combinator:
  39468. this.combinator();
  39469. break;
  39470. case tokens.str:
  39471. this.string();
  39472. break;
  39473. // These cases throw; no break needed.
  39474. case tokens.closeSquare:
  39475. this.missingSquareBracket();
  39476. case tokens.semicolon:
  39477. this.missingBackslash();
  39478. default:
  39479. this.unexpected();
  39480. }
  39481. }
  39482. /**
  39483. * Helpers
  39484. */;
  39485. _proto.expected = function expected(description, index, found) {
  39486. if (Array.isArray(description)) {
  39487. var last = description.pop();
  39488. description = description.join(', ') + " or " + last;
  39489. }
  39490. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39491. if (!found) {
  39492. return this.error("Expected " + an + " " + description + ".", {
  39493. index: index
  39494. });
  39495. }
  39496. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39497. index: index
  39498. });
  39499. };
  39500. _proto.requiredSpace = function requiredSpace(space) {
  39501. return this.options.lossy ? ' ' : space;
  39502. };
  39503. _proto.optionalSpace = function optionalSpace(space) {
  39504. return this.options.lossy ? '' : space;
  39505. };
  39506. _proto.lossySpace = function lossySpace(space, required) {
  39507. if (this.options.lossy) {
  39508. return required ? ' ' : '';
  39509. } else {
  39510. return space;
  39511. }
  39512. };
  39513. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39514. var content = this.content(token);
  39515. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39516. return this.requiredSpace(content);
  39517. } else {
  39518. return content;
  39519. }
  39520. };
  39521. _proto.newNode = function newNode(node, namespace) {
  39522. if (namespace) {
  39523. if (/^ +$/.test(namespace)) {
  39524. if (!this.options.lossy) {
  39525. this.spaces = (this.spaces || '') + namespace;
  39526. }
  39527. namespace = true;
  39528. }
  39529. node.namespace = namespace;
  39530. unescapeProp(node, "namespace");
  39531. }
  39532. if (this.spaces) {
  39533. node.spaces.before = this.spaces;
  39534. this.spaces = '';
  39535. }
  39536. return this.current.append(node);
  39537. };
  39538. _proto.content = function content(token) {
  39539. if (token === void 0) {
  39540. token = this.currToken;
  39541. }
  39542. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39543. };
  39544. /**
  39545. * returns the index of the next non-whitespace, non-comment token.
  39546. * returns -1 if no meaningful token is found.
  39547. */
  39548. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39549. if (startPosition === void 0) {
  39550. startPosition = this.position + 1;
  39551. }
  39552. var searchPosition = startPosition;
  39553. while (searchPosition < this.tokens.length) {
  39554. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39555. searchPosition++;
  39556. continue;
  39557. } else {
  39558. return searchPosition;
  39559. }
  39560. }
  39561. return -1;
  39562. };
  39563. _createClass(Parser, [{
  39564. key: "currToken",
  39565. get: function get() {
  39566. return this.tokens[this.position];
  39567. }
  39568. }, {
  39569. key: "nextToken",
  39570. get: function get() {
  39571. return this.tokens[this.position + 1];
  39572. }
  39573. }, {
  39574. key: "prevToken",
  39575. get: function get() {
  39576. return this.tokens[this.position - 1];
  39577. }
  39578. }]);
  39579. return Parser;
  39580. }();
  39581. exports["default"] = Parser;
  39582. module.exports = exports.default;
  39583. } (parser, parser.exports));
  39584. return parser.exports;
  39585. }
  39586. var hasRequiredProcessor;
  39587. function requireProcessor () {
  39588. if (hasRequiredProcessor) return processor.exports;
  39589. hasRequiredProcessor = 1;
  39590. (function (module, exports) {
  39591. exports.__esModule = true;
  39592. exports["default"] = void 0;
  39593. var _parser = _interopRequireDefault(/*@__PURE__*/ requireParser());
  39594. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39595. var Processor = /*#__PURE__*/function () {
  39596. function Processor(func, options) {
  39597. this.func = func || function noop() {};
  39598. this.funcRes = null;
  39599. this.options = options;
  39600. }
  39601. var _proto = Processor.prototype;
  39602. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39603. if (options === void 0) {
  39604. options = {};
  39605. }
  39606. var merged = Object.assign({}, this.options, options);
  39607. if (merged.updateSelector === false) {
  39608. return false;
  39609. } else {
  39610. return typeof rule !== "string";
  39611. }
  39612. };
  39613. _proto._isLossy = function _isLossy(options) {
  39614. if (options === void 0) {
  39615. options = {};
  39616. }
  39617. var merged = Object.assign({}, this.options, options);
  39618. if (merged.lossless === false) {
  39619. return true;
  39620. } else {
  39621. return false;
  39622. }
  39623. };
  39624. _proto._root = function _root(rule, options) {
  39625. if (options === void 0) {
  39626. options = {};
  39627. }
  39628. var parser = new _parser["default"](rule, this._parseOptions(options));
  39629. return parser.root;
  39630. };
  39631. _proto._parseOptions = function _parseOptions(options) {
  39632. return {
  39633. lossy: this._isLossy(options)
  39634. };
  39635. };
  39636. _proto._run = function _run(rule, options) {
  39637. var _this = this;
  39638. if (options === void 0) {
  39639. options = {};
  39640. }
  39641. return new Promise(function (resolve, reject) {
  39642. try {
  39643. var root = _this._root(rule, options);
  39644. Promise.resolve(_this.func(root)).then(function (transform) {
  39645. var string = undefined;
  39646. if (_this._shouldUpdateSelector(rule, options)) {
  39647. string = root.toString();
  39648. rule.selector = string;
  39649. }
  39650. return {
  39651. transform: transform,
  39652. root: root,
  39653. string: string
  39654. };
  39655. }).then(resolve, reject);
  39656. } catch (e) {
  39657. reject(e);
  39658. return;
  39659. }
  39660. });
  39661. };
  39662. _proto._runSync = function _runSync(rule, options) {
  39663. if (options === void 0) {
  39664. options = {};
  39665. }
  39666. var root = this._root(rule, options);
  39667. var transform = this.func(root);
  39668. if (transform && typeof transform.then === "function") {
  39669. throw new Error("Selector processor returned a promise to a synchronous call.");
  39670. }
  39671. var string = undefined;
  39672. if (options.updateSelector && typeof rule !== "string") {
  39673. string = root.toString();
  39674. rule.selector = string;
  39675. }
  39676. return {
  39677. transform: transform,
  39678. root: root,
  39679. string: string
  39680. };
  39681. }
  39682. /**
  39683. * Process rule into a selector AST.
  39684. *
  39685. * @param rule {postcss.Rule | string} The css selector to be processed
  39686. * @param options The options for processing
  39687. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39688. */;
  39689. _proto.ast = function ast(rule, options) {
  39690. return this._run(rule, options).then(function (result) {
  39691. return result.root;
  39692. });
  39693. }
  39694. /**
  39695. * Process rule into a selector AST synchronously.
  39696. *
  39697. * @param rule {postcss.Rule | string} The css selector to be processed
  39698. * @param options The options for processing
  39699. * @returns {parser.Root} The AST of the selector after processing it.
  39700. */;
  39701. _proto.astSync = function astSync(rule, options) {
  39702. return this._runSync(rule, options).root;
  39703. }
  39704. /**
  39705. * Process a selector into a transformed value asynchronously
  39706. *
  39707. * @param rule {postcss.Rule | string} The css selector to be processed
  39708. * @param options The options for processing
  39709. * @returns {Promise<any>} The value returned by the processor.
  39710. */;
  39711. _proto.transform = function transform(rule, options) {
  39712. return this._run(rule, options).then(function (result) {
  39713. return result.transform;
  39714. });
  39715. }
  39716. /**
  39717. * Process a selector into a transformed value synchronously.
  39718. *
  39719. * @param rule {postcss.Rule | string} The css selector to be processed
  39720. * @param options The options for processing
  39721. * @returns {any} The value returned by the processor.
  39722. */;
  39723. _proto.transformSync = function transformSync(rule, options) {
  39724. return this._runSync(rule, options).transform;
  39725. }
  39726. /**
  39727. * Process a selector into a new selector string asynchronously.
  39728. *
  39729. * @param rule {postcss.Rule | string} The css selector to be processed
  39730. * @param options The options for processing
  39731. * @returns {string} the selector after processing.
  39732. */;
  39733. _proto.process = function process(rule, options) {
  39734. return this._run(rule, options).then(function (result) {
  39735. return result.string || result.root.toString();
  39736. });
  39737. }
  39738. /**
  39739. * Process a selector into a new selector string synchronously.
  39740. *
  39741. * @param rule {postcss.Rule | string} The css selector to be processed
  39742. * @param options The options for processing
  39743. * @returns {string} the selector after processing.
  39744. */;
  39745. _proto.processSync = function processSync(rule, options) {
  39746. var result = this._runSync(rule, options);
  39747. return result.string || result.root.toString();
  39748. };
  39749. return Processor;
  39750. }();
  39751. exports["default"] = Processor;
  39752. module.exports = exports.default;
  39753. } (processor, processor.exports));
  39754. return processor.exports;
  39755. }
  39756. var selectors = {};
  39757. var constructors = {};
  39758. var hasRequiredConstructors;
  39759. function requireConstructors () {
  39760. if (hasRequiredConstructors) return constructors;
  39761. hasRequiredConstructors = 1;
  39762. constructors.__esModule = true;
  39763. 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;
  39764. var _attribute = _interopRequireDefault(/*@__PURE__*/ requireAttribute());
  39765. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  39766. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  39767. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  39768. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  39769. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  39770. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  39771. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  39772. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  39773. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  39774. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  39775. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  39776. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39777. var attribute = function attribute(opts) {
  39778. return new _attribute["default"](opts);
  39779. };
  39780. constructors.attribute = attribute;
  39781. var className = function className(opts) {
  39782. return new _className["default"](opts);
  39783. };
  39784. constructors.className = className;
  39785. var combinator = function combinator(opts) {
  39786. return new _combinator["default"](opts);
  39787. };
  39788. constructors.combinator = combinator;
  39789. var comment = function comment(opts) {
  39790. return new _comment["default"](opts);
  39791. };
  39792. constructors.comment = comment;
  39793. var id = function id(opts) {
  39794. return new _id["default"](opts);
  39795. };
  39796. constructors.id = id;
  39797. var nesting = function nesting(opts) {
  39798. return new _nesting["default"](opts);
  39799. };
  39800. constructors.nesting = nesting;
  39801. var pseudo = function pseudo(opts) {
  39802. return new _pseudo["default"](opts);
  39803. };
  39804. constructors.pseudo = pseudo;
  39805. var root = function root(opts) {
  39806. return new _root["default"](opts);
  39807. };
  39808. constructors.root = root;
  39809. var selector = function selector(opts) {
  39810. return new _selector["default"](opts);
  39811. };
  39812. constructors.selector = selector;
  39813. var string = function string(opts) {
  39814. return new _string["default"](opts);
  39815. };
  39816. constructors.string = string;
  39817. var tag = function tag(opts) {
  39818. return new _tag["default"](opts);
  39819. };
  39820. constructors.tag = tag;
  39821. var universal = function universal(opts) {
  39822. return new _universal["default"](opts);
  39823. };
  39824. constructors.universal = universal;
  39825. return constructors;
  39826. }
  39827. var guards = {};
  39828. var hasRequiredGuards;
  39829. function requireGuards () {
  39830. if (hasRequiredGuards) return guards;
  39831. hasRequiredGuards = 1;
  39832. guards.__esModule = true;
  39833. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  39834. guards.isContainer = isContainer;
  39835. guards.isIdentifier = void 0;
  39836. guards.isNamespace = isNamespace;
  39837. guards.isNesting = void 0;
  39838. guards.isNode = isNode;
  39839. guards.isPseudo = void 0;
  39840. guards.isPseudoClass = isPseudoClass;
  39841. guards.isPseudoElement = isPseudoElement;
  39842. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  39843. var _types = /*@__PURE__*/ requireTypes();
  39844. var _IS_TYPE;
  39845. 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);
  39846. function isNode(node) {
  39847. return typeof node === "object" && IS_TYPE[node.type];
  39848. }
  39849. function isNodeType(type, node) {
  39850. return isNode(node) && node.type === type;
  39851. }
  39852. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  39853. guards.isAttribute = isAttribute;
  39854. var isClassName = isNodeType.bind(null, _types.CLASS);
  39855. guards.isClassName = isClassName;
  39856. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  39857. guards.isCombinator = isCombinator;
  39858. var isComment = isNodeType.bind(null, _types.COMMENT);
  39859. guards.isComment = isComment;
  39860. var isIdentifier = isNodeType.bind(null, _types.ID);
  39861. guards.isIdentifier = isIdentifier;
  39862. var isNesting = isNodeType.bind(null, _types.NESTING);
  39863. guards.isNesting = isNesting;
  39864. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  39865. guards.isPseudo = isPseudo;
  39866. var isRoot = isNodeType.bind(null, _types.ROOT);
  39867. guards.isRoot = isRoot;
  39868. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  39869. guards.isSelector = isSelector;
  39870. var isString = isNodeType.bind(null, _types.STRING);
  39871. guards.isString = isString;
  39872. var isTag = isNodeType.bind(null, _types.TAG);
  39873. guards.isTag = isTag;
  39874. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  39875. guards.isUniversal = isUniversal;
  39876. function isPseudoElement(node) {
  39877. 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");
  39878. }
  39879. function isPseudoClass(node) {
  39880. return isPseudo(node) && !isPseudoElement(node);
  39881. }
  39882. function isContainer(node) {
  39883. return !!(isNode(node) && node.walk);
  39884. }
  39885. function isNamespace(node) {
  39886. return isAttribute(node) || isTag(node);
  39887. }
  39888. return guards;
  39889. }
  39890. var hasRequiredSelectors;
  39891. function requireSelectors () {
  39892. if (hasRequiredSelectors) return selectors;
  39893. hasRequiredSelectors = 1;
  39894. (function (exports) {
  39895. exports.__esModule = true;
  39896. var _types = /*@__PURE__*/ requireTypes();
  39897. Object.keys(_types).forEach(function (key) {
  39898. if (key === "default" || key === "__esModule") return;
  39899. if (key in exports && exports[key] === _types[key]) return;
  39900. exports[key] = _types[key];
  39901. });
  39902. var _constructors = /*@__PURE__*/ requireConstructors();
  39903. Object.keys(_constructors).forEach(function (key) {
  39904. if (key === "default" || key === "__esModule") return;
  39905. if (key in exports && exports[key] === _constructors[key]) return;
  39906. exports[key] = _constructors[key];
  39907. });
  39908. var _guards = /*@__PURE__*/ requireGuards();
  39909. Object.keys(_guards).forEach(function (key) {
  39910. if (key === "default" || key === "__esModule") return;
  39911. if (key in exports && exports[key] === _guards[key]) return;
  39912. exports[key] = _guards[key];
  39913. });
  39914. } (selectors));
  39915. return selectors;
  39916. }
  39917. var hasRequiredDist;
  39918. function requireDist () {
  39919. if (hasRequiredDist) return dist.exports;
  39920. hasRequiredDist = 1;
  39921. (function (module, exports) {
  39922. exports.__esModule = true;
  39923. exports["default"] = void 0;
  39924. var _processor = _interopRequireDefault(/*@__PURE__*/ requireProcessor());
  39925. var selectors = _interopRequireWildcard(/*@__PURE__*/ requireSelectors());
  39926. 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); }
  39927. 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; }
  39928. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39929. var parser = function parser(processor) {
  39930. return new _processor["default"](processor);
  39931. };
  39932. Object.assign(parser, selectors);
  39933. delete parser.__esModule;
  39934. var _default = parser;
  39935. exports["default"] = _default;
  39936. module.exports = exports.default;
  39937. } (dist, dist.exports));
  39938. return dist.exports;
  39939. }
  39940. var distExports = /*@__PURE__*/ requireDist();
  39941. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  39942. const animationNameRE = /^(-\w+-)?animation-name$/;
  39943. const animationRE = /^(-\w+-)?animation$/;
  39944. const keyframesRE = /^(?:-\w+-)?keyframes$/;
  39945. const scopedPlugin = (id = "") => {
  39946. const keyframes = /* @__PURE__ */ Object.create(null);
  39947. const shortId = id.replace(/^data-v-/, "");
  39948. return {
  39949. postcssPlugin: "vue-sfc-scoped",
  39950. Rule(rule) {
  39951. processRule(id, rule);
  39952. },
  39953. AtRule(node) {
  39954. if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  39955. keyframes[node.params] = node.params = node.params + "-" + shortId;
  39956. }
  39957. },
  39958. OnceExit(root) {
  39959. if (Object.keys(keyframes).length) {
  39960. root.walkDecls((decl) => {
  39961. if (animationNameRE.test(decl.prop)) {
  39962. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  39963. }
  39964. if (animationRE.test(decl.prop)) {
  39965. decl.value = decl.value.split(",").map((v) => {
  39966. const vals = v.trim().split(/\s+/);
  39967. const i = vals.findIndex((val) => keyframes[val]);
  39968. if (i !== -1) {
  39969. vals.splice(i, 1, keyframes[vals[i]]);
  39970. return vals.join(" ");
  39971. } else {
  39972. return v;
  39973. }
  39974. }).join(",");
  39975. }
  39976. });
  39977. }
  39978. }
  39979. };
  39980. };
  39981. const processedRules = /* @__PURE__ */ new WeakSet();
  39982. function processRule(id, rule) {
  39983. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
  39984. return;
  39985. }
  39986. processedRules.add(rule);
  39987. let deep = false;
  39988. let parent = rule.parent;
  39989. while (parent && parent.type !== "root") {
  39990. if (parent.__deep) {
  39991. deep = true;
  39992. break;
  39993. }
  39994. parent = parent.parent;
  39995. }
  39996. rule.selector = selectorParser((selectorRoot) => {
  39997. selectorRoot.each((selector) => {
  39998. rewriteSelector(id, rule, selector, selectorRoot, deep);
  39999. });
  40000. }).processSync(rule.selector);
  40001. }
  40002. function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
  40003. let node = null;
  40004. let shouldInject = !deep;
  40005. selector.each((n) => {
  40006. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  40007. n.value = " ";
  40008. n.spaces.before = n.spaces.after = "";
  40009. warn(
  40010. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  40011. );
  40012. return false;
  40013. }
  40014. if (n.type === "pseudo") {
  40015. const { value } = n;
  40016. if (value === ":deep" || value === "::v-deep") {
  40017. rule.__deep = true;
  40018. if (n.nodes.length) {
  40019. let last = n;
  40020. n.nodes[0].each((ss) => {
  40021. selector.insertAfter(last, ss);
  40022. last = ss;
  40023. });
  40024. const prev = selector.at(selector.index(n) - 1);
  40025. if (!prev || !isSpaceCombinator(prev)) {
  40026. selector.insertAfter(
  40027. n,
  40028. selectorParser.combinator({
  40029. value: " "
  40030. })
  40031. );
  40032. }
  40033. selector.removeChild(n);
  40034. } else {
  40035. warn(
  40036. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  40037. );
  40038. const prev = selector.at(selector.index(n) - 1);
  40039. if (prev && isSpaceCombinator(prev)) {
  40040. selector.removeChild(prev);
  40041. }
  40042. selector.removeChild(n);
  40043. }
  40044. return false;
  40045. }
  40046. if (value === ":slotted" || value === "::v-slotted") {
  40047. rewriteSelector(
  40048. id,
  40049. rule,
  40050. n.nodes[0],
  40051. selectorRoot,
  40052. deep,
  40053. true
  40054. );
  40055. let last = n;
  40056. n.nodes[0].each((ss) => {
  40057. selector.insertAfter(last, ss);
  40058. last = ss;
  40059. });
  40060. selector.removeChild(n);
  40061. shouldInject = false;
  40062. return false;
  40063. }
  40064. if (value === ":global" || value === "::v-global") {
  40065. selector.replaceWith(n.nodes[0]);
  40066. return false;
  40067. }
  40068. }
  40069. if (n.type === "universal") {
  40070. const prev = selector.at(selector.index(n) - 1);
  40071. const next = selector.at(selector.index(n) + 1);
  40072. if (!prev) {
  40073. if (next) {
  40074. if (next.type === "combinator" && next.value === " ") {
  40075. selector.removeChild(next);
  40076. }
  40077. selector.removeChild(n);
  40078. return;
  40079. } else {
  40080. node = selectorParser.combinator({
  40081. value: ""
  40082. });
  40083. selector.insertBefore(n, node);
  40084. selector.removeChild(n);
  40085. return false;
  40086. }
  40087. }
  40088. if (node) return;
  40089. }
  40090. if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
  40091. node = n;
  40092. }
  40093. });
  40094. if (rule.nodes.some((node2) => node2.type === "rule")) {
  40095. const deep2 = rule.__deep;
  40096. if (!deep2) {
  40097. extractAndWrapNodes(rule);
  40098. const atruleNodes = rule.nodes.filter((node2) => node2.type === "atrule");
  40099. for (const atnode of atruleNodes) {
  40100. extractAndWrapNodes(atnode);
  40101. }
  40102. }
  40103. shouldInject = deep2;
  40104. }
  40105. if (node) {
  40106. const { type, value } = node;
  40107. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  40108. node.nodes.forEach(
  40109. (value2) => rewriteSelector(id, rule, value2, selectorRoot, deep, slotted)
  40110. );
  40111. shouldInject = false;
  40112. }
  40113. }
  40114. if (node) {
  40115. node.spaces.after = "";
  40116. } else {
  40117. selector.first.spaces.before = "";
  40118. }
  40119. if (shouldInject) {
  40120. const idToAdd = slotted ? id + "-s" : id;
  40121. selector.insertAfter(
  40122. // If node is null it means we need to inject [id] at the start
  40123. // insertAfter can handle `null` here
  40124. node,
  40125. selectorParser.attribute({
  40126. attribute: idToAdd,
  40127. value: idToAdd,
  40128. raws: {},
  40129. quoteMark: `"`
  40130. })
  40131. );
  40132. }
  40133. }
  40134. function isSpaceCombinator(node) {
  40135. return node.type === "combinator" && /^\s+$/.test(node.value);
  40136. }
  40137. function extractAndWrapNodes(parentNode) {
  40138. if (!parentNode.nodes) return;
  40139. const nodes = parentNode.nodes.filter(
  40140. (node) => node.type === "decl" || node.type === "comment"
  40141. );
  40142. if (nodes.length) {
  40143. for (const node of nodes) {
  40144. parentNode.removeChild(node);
  40145. }
  40146. const wrappedRule = new Rule({
  40147. nodes,
  40148. selector: "&"
  40149. });
  40150. parentNode.prepend(wrappedRule);
  40151. }
  40152. }
  40153. scopedPlugin.postcss = true;
  40154. var sourceMap = {};
  40155. var sourceMapGenerator = {};
  40156. var base64Vlq = {};
  40157. var base64 = {};
  40158. /* -*- Mode: js; js-indent-level: 2; -*- */
  40159. var hasRequiredBase64;
  40160. function requireBase64 () {
  40161. if (hasRequiredBase64) return base64;
  40162. hasRequiredBase64 = 1;
  40163. /*
  40164. * Copyright 2011 Mozilla Foundation and contributors
  40165. * Licensed under the New BSD license. See LICENSE or:
  40166. * http://opensource.org/licenses/BSD-3-Clause
  40167. */
  40168. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  40169. /**
  40170. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  40171. */
  40172. base64.encode = function (number) {
  40173. if (0 <= number && number < intToCharMap.length) {
  40174. return intToCharMap[number];
  40175. }
  40176. throw new TypeError("Must be between 0 and 63: " + number);
  40177. };
  40178. /**
  40179. * Decode a single base 64 character code digit to an integer. Returns -1 on
  40180. * failure.
  40181. */
  40182. base64.decode = function (charCode) {
  40183. var bigA = 65; // 'A'
  40184. var bigZ = 90; // 'Z'
  40185. var littleA = 97; // 'a'
  40186. var littleZ = 122; // 'z'
  40187. var zero = 48; // '0'
  40188. var nine = 57; // '9'
  40189. var plus = 43; // '+'
  40190. var slash = 47; // '/'
  40191. var littleOffset = 26;
  40192. var numberOffset = 52;
  40193. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  40194. if (bigA <= charCode && charCode <= bigZ) {
  40195. return (charCode - bigA);
  40196. }
  40197. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  40198. if (littleA <= charCode && charCode <= littleZ) {
  40199. return (charCode - littleA + littleOffset);
  40200. }
  40201. // 52 - 61: 0123456789
  40202. if (zero <= charCode && charCode <= nine) {
  40203. return (charCode - zero + numberOffset);
  40204. }
  40205. // 62: +
  40206. if (charCode == plus) {
  40207. return 62;
  40208. }
  40209. // 63: /
  40210. if (charCode == slash) {
  40211. return 63;
  40212. }
  40213. // Invalid base64 digit.
  40214. return -1;
  40215. };
  40216. return base64;
  40217. }
  40218. /* -*- Mode: js; js-indent-level: 2; -*- */
  40219. var hasRequiredBase64Vlq;
  40220. function requireBase64Vlq () {
  40221. if (hasRequiredBase64Vlq) return base64Vlq;
  40222. hasRequiredBase64Vlq = 1;
  40223. /*
  40224. * Copyright 2011 Mozilla Foundation and contributors
  40225. * Licensed under the New BSD license. See LICENSE or:
  40226. * http://opensource.org/licenses/BSD-3-Clause
  40227. *
  40228. * Based on the Base 64 VLQ implementation in Closure Compiler:
  40229. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  40230. *
  40231. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  40232. * Redistribution and use in source and binary forms, with or without
  40233. * modification, are permitted provided that the following conditions are
  40234. * met:
  40235. *
  40236. * * Redistributions of source code must retain the above copyright
  40237. * notice, this list of conditions and the following disclaimer.
  40238. * * Redistributions in binary form must reproduce the above
  40239. * copyright notice, this list of conditions and the following
  40240. * disclaimer in the documentation and/or other materials provided
  40241. * with the distribution.
  40242. * * Neither the name of Google Inc. nor the names of its
  40243. * contributors may be used to endorse or promote products derived
  40244. * from this software without specific prior written permission.
  40245. *
  40246. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40247. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40248. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  40249. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40250. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40251. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40252. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40253. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  40254. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40255. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40256. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40257. */
  40258. var base64 = /*@__PURE__*/ requireBase64();
  40259. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  40260. // length quantities we use in the source map spec, the first bit is the sign,
  40261. // the next four bits are the actual value, and the 6th bit is the
  40262. // continuation bit. The continuation bit tells us whether there are more
  40263. // digits in this value following this digit.
  40264. //
  40265. // Continuation
  40266. // | Sign
  40267. // | |
  40268. // V V
  40269. // 101011
  40270. var VLQ_BASE_SHIFT = 5;
  40271. // binary: 100000
  40272. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  40273. // binary: 011111
  40274. var VLQ_BASE_MASK = VLQ_BASE - 1;
  40275. // binary: 100000
  40276. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  40277. /**
  40278. * Converts from a two-complement value to a value where the sign bit is
  40279. * placed in the least significant bit. For example, as decimals:
  40280. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  40281. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  40282. */
  40283. function toVLQSigned(aValue) {
  40284. return aValue < 0
  40285. ? ((-aValue) << 1) + 1
  40286. : (aValue << 1) + 0;
  40287. }
  40288. /**
  40289. * Converts to a two-complement value from a value where the sign bit is
  40290. * placed in the least significant bit. For example, as decimals:
  40291. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  40292. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  40293. */
  40294. function fromVLQSigned(aValue) {
  40295. var isNegative = (aValue & 1) === 1;
  40296. var shifted = aValue >> 1;
  40297. return isNegative
  40298. ? -shifted
  40299. : shifted;
  40300. }
  40301. /**
  40302. * Returns the base 64 VLQ encoded value.
  40303. */
  40304. base64Vlq.encode = function base64VLQ_encode(aValue) {
  40305. var encoded = "";
  40306. var digit;
  40307. var vlq = toVLQSigned(aValue);
  40308. do {
  40309. digit = vlq & VLQ_BASE_MASK;
  40310. vlq >>>= VLQ_BASE_SHIFT;
  40311. if (vlq > 0) {
  40312. // There are still more digits in this value, so we must make sure the
  40313. // continuation bit is marked.
  40314. digit |= VLQ_CONTINUATION_BIT;
  40315. }
  40316. encoded += base64.encode(digit);
  40317. } while (vlq > 0);
  40318. return encoded;
  40319. };
  40320. /**
  40321. * Decodes the next base 64 VLQ value from the given string and returns the
  40322. * value and the rest of the string via the out parameter.
  40323. */
  40324. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  40325. var strLen = aStr.length;
  40326. var result = 0;
  40327. var shift = 0;
  40328. var continuation, digit;
  40329. do {
  40330. if (aIndex >= strLen) {
  40331. throw new Error("Expected more digits in base 64 VLQ value.");
  40332. }
  40333. digit = base64.decode(aStr.charCodeAt(aIndex++));
  40334. if (digit === -1) {
  40335. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  40336. }
  40337. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  40338. digit &= VLQ_BASE_MASK;
  40339. result = result + (digit << shift);
  40340. shift += VLQ_BASE_SHIFT;
  40341. } while (continuation);
  40342. aOutParam.value = fromVLQSigned(result);
  40343. aOutParam.rest = aIndex;
  40344. };
  40345. return base64Vlq;
  40346. }
  40347. var util = {};
  40348. /* -*- Mode: js; js-indent-level: 2; -*- */
  40349. var hasRequiredUtil;
  40350. function requireUtil () {
  40351. if (hasRequiredUtil) return util;
  40352. hasRequiredUtil = 1;
  40353. (function (exports) {
  40354. /*
  40355. * Copyright 2011 Mozilla Foundation and contributors
  40356. * Licensed under the New BSD license. See LICENSE or:
  40357. * http://opensource.org/licenses/BSD-3-Clause
  40358. */
  40359. /**
  40360. * This is a helper function for getting values from parameter/options
  40361. * objects.
  40362. *
  40363. * @param args The object we are extracting values from
  40364. * @param name The name of the property we are getting.
  40365. * @param defaultValue An optional value to return if the property is missing
  40366. * from the object. If this is not specified and the property is missing, an
  40367. * error will be thrown.
  40368. */
  40369. function getArg(aArgs, aName, aDefaultValue) {
  40370. if (aName in aArgs) {
  40371. return aArgs[aName];
  40372. } else if (arguments.length === 3) {
  40373. return aDefaultValue;
  40374. } else {
  40375. throw new Error('"' + aName + '" is a required argument.');
  40376. }
  40377. }
  40378. exports.getArg = getArg;
  40379. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  40380. var dataUrlRegexp = /^data:.+\,.+$/;
  40381. function urlParse(aUrl) {
  40382. var match = aUrl.match(urlRegexp);
  40383. if (!match) {
  40384. return null;
  40385. }
  40386. return {
  40387. scheme: match[1],
  40388. auth: match[2],
  40389. host: match[3],
  40390. port: match[4],
  40391. path: match[5]
  40392. };
  40393. }
  40394. exports.urlParse = urlParse;
  40395. function urlGenerate(aParsedUrl) {
  40396. var url = '';
  40397. if (aParsedUrl.scheme) {
  40398. url += aParsedUrl.scheme + ':';
  40399. }
  40400. url += '//';
  40401. if (aParsedUrl.auth) {
  40402. url += aParsedUrl.auth + '@';
  40403. }
  40404. if (aParsedUrl.host) {
  40405. url += aParsedUrl.host;
  40406. }
  40407. if (aParsedUrl.port) {
  40408. url += ":" + aParsedUrl.port;
  40409. }
  40410. if (aParsedUrl.path) {
  40411. url += aParsedUrl.path;
  40412. }
  40413. return url;
  40414. }
  40415. exports.urlGenerate = urlGenerate;
  40416. /**
  40417. * Normalizes a path, or the path portion of a URL:
  40418. *
  40419. * - Replaces consecutive slashes with one slash.
  40420. * - Removes unnecessary '.' parts.
  40421. * - Removes unnecessary '<dir>/..' parts.
  40422. *
  40423. * Based on code in the Node.js 'path' core module.
  40424. *
  40425. * @param aPath The path or url to normalize.
  40426. */
  40427. function normalize(aPath) {
  40428. var path = aPath;
  40429. var url = urlParse(aPath);
  40430. if (url) {
  40431. if (!url.path) {
  40432. return aPath;
  40433. }
  40434. path = url.path;
  40435. }
  40436. var isAbsolute = exports.isAbsolute(path);
  40437. var parts = path.split(/\/+/);
  40438. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  40439. part = parts[i];
  40440. if (part === '.') {
  40441. parts.splice(i, 1);
  40442. } else if (part === '..') {
  40443. up++;
  40444. } else if (up > 0) {
  40445. if (part === '') {
  40446. // The first part is blank if the path is absolute. Trying to go
  40447. // above the root is a no-op. Therefore we can remove all '..' parts
  40448. // directly after the root.
  40449. parts.splice(i + 1, up);
  40450. up = 0;
  40451. } else {
  40452. parts.splice(i, 2);
  40453. up--;
  40454. }
  40455. }
  40456. }
  40457. path = parts.join('/');
  40458. if (path === '') {
  40459. path = isAbsolute ? '/' : '.';
  40460. }
  40461. if (url) {
  40462. url.path = path;
  40463. return urlGenerate(url);
  40464. }
  40465. return path;
  40466. }
  40467. exports.normalize = normalize;
  40468. /**
  40469. * Joins two paths/URLs.
  40470. *
  40471. * @param aRoot The root path or URL.
  40472. * @param aPath The path or URL to be joined with the root.
  40473. *
  40474. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  40475. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  40476. * first.
  40477. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  40478. * is updated with the result and aRoot is returned. Otherwise the result
  40479. * is returned.
  40480. * - If aPath is absolute, the result is aPath.
  40481. * - Otherwise the two paths are joined with a slash.
  40482. * - Joining for example 'http://' and 'www.example.com' is also supported.
  40483. */
  40484. function join(aRoot, aPath) {
  40485. if (aRoot === "") {
  40486. aRoot = ".";
  40487. }
  40488. if (aPath === "") {
  40489. aPath = ".";
  40490. }
  40491. var aPathUrl = urlParse(aPath);
  40492. var aRootUrl = urlParse(aRoot);
  40493. if (aRootUrl) {
  40494. aRoot = aRootUrl.path || '/';
  40495. }
  40496. // `join(foo, '//www.example.org')`
  40497. if (aPathUrl && !aPathUrl.scheme) {
  40498. if (aRootUrl) {
  40499. aPathUrl.scheme = aRootUrl.scheme;
  40500. }
  40501. return urlGenerate(aPathUrl);
  40502. }
  40503. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  40504. return aPath;
  40505. }
  40506. // `join('http://', 'www.example.com')`
  40507. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  40508. aRootUrl.host = aPath;
  40509. return urlGenerate(aRootUrl);
  40510. }
  40511. var joined = aPath.charAt(0) === '/'
  40512. ? aPath
  40513. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  40514. if (aRootUrl) {
  40515. aRootUrl.path = joined;
  40516. return urlGenerate(aRootUrl);
  40517. }
  40518. return joined;
  40519. }
  40520. exports.join = join;
  40521. exports.isAbsolute = function (aPath) {
  40522. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  40523. };
  40524. /**
  40525. * Make a path relative to a URL or another path.
  40526. *
  40527. * @param aRoot The root path or URL.
  40528. * @param aPath The path or URL to be made relative to aRoot.
  40529. */
  40530. function relative(aRoot, aPath) {
  40531. if (aRoot === "") {
  40532. aRoot = ".";
  40533. }
  40534. aRoot = aRoot.replace(/\/$/, '');
  40535. // It is possible for the path to be above the root. In this case, simply
  40536. // checking whether the root is a prefix of the path won't work. Instead, we
  40537. // need to remove components from the root one by one, until either we find
  40538. // a prefix that fits, or we run out of components to remove.
  40539. var level = 0;
  40540. while (aPath.indexOf(aRoot + '/') !== 0) {
  40541. var index = aRoot.lastIndexOf("/");
  40542. if (index < 0) {
  40543. return aPath;
  40544. }
  40545. // If the only part of the root that is left is the scheme (i.e. http://,
  40546. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40547. // have exhausted all components, so the path is not relative to the root.
  40548. aRoot = aRoot.slice(0, index);
  40549. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40550. return aPath;
  40551. }
  40552. ++level;
  40553. }
  40554. // Make sure we add a "../" for each component we removed from the root.
  40555. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40556. }
  40557. exports.relative = relative;
  40558. var supportsNullProto = (function () {
  40559. var obj = Object.create(null);
  40560. return !('__proto__' in obj);
  40561. }());
  40562. function identity (s) {
  40563. return s;
  40564. }
  40565. /**
  40566. * Because behavior goes wacky when you set `__proto__` on objects, we
  40567. * have to prefix all the strings in our set with an arbitrary character.
  40568. *
  40569. * See https://github.com/mozilla/source-map/pull/31 and
  40570. * https://github.com/mozilla/source-map/issues/30
  40571. *
  40572. * @param String aStr
  40573. */
  40574. function toSetString(aStr) {
  40575. if (isProtoString(aStr)) {
  40576. return '$' + aStr;
  40577. }
  40578. return aStr;
  40579. }
  40580. exports.toSetString = supportsNullProto ? identity : toSetString;
  40581. function fromSetString(aStr) {
  40582. if (isProtoString(aStr)) {
  40583. return aStr.slice(1);
  40584. }
  40585. return aStr;
  40586. }
  40587. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  40588. function isProtoString(s) {
  40589. if (!s) {
  40590. return false;
  40591. }
  40592. var length = s.length;
  40593. if (length < 9 /* "__proto__".length */) {
  40594. return false;
  40595. }
  40596. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40597. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40598. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40599. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40600. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40601. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40602. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40603. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40604. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40605. return false;
  40606. }
  40607. for (var i = length - 10; i >= 0; i--) {
  40608. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40609. return false;
  40610. }
  40611. }
  40612. return true;
  40613. }
  40614. /**
  40615. * Comparator between two mappings where the original positions are compared.
  40616. *
  40617. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40618. * mappings with the same original source/line/column, but different generated
  40619. * line and column the same. Useful when searching for a mapping with a
  40620. * stubbed out mapping.
  40621. */
  40622. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40623. var cmp = strcmp(mappingA.source, mappingB.source);
  40624. if (cmp !== 0) {
  40625. return cmp;
  40626. }
  40627. cmp = mappingA.originalLine - mappingB.originalLine;
  40628. if (cmp !== 0) {
  40629. return cmp;
  40630. }
  40631. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40632. if (cmp !== 0 || onlyCompareOriginal) {
  40633. return cmp;
  40634. }
  40635. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40636. if (cmp !== 0) {
  40637. return cmp;
  40638. }
  40639. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40640. if (cmp !== 0) {
  40641. return cmp;
  40642. }
  40643. return strcmp(mappingA.name, mappingB.name);
  40644. }
  40645. exports.compareByOriginalPositions = compareByOriginalPositions;
  40646. /**
  40647. * Comparator between two mappings with deflated source and name indices where
  40648. * the generated positions are compared.
  40649. *
  40650. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40651. * mappings with the same generated line and column, but different
  40652. * source/name/original line and column the same. Useful when searching for a
  40653. * mapping with a stubbed out mapping.
  40654. */
  40655. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40656. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40657. if (cmp !== 0) {
  40658. return cmp;
  40659. }
  40660. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40661. if (cmp !== 0 || onlyCompareGenerated) {
  40662. return cmp;
  40663. }
  40664. cmp = strcmp(mappingA.source, mappingB.source);
  40665. if (cmp !== 0) {
  40666. return cmp;
  40667. }
  40668. cmp = mappingA.originalLine - mappingB.originalLine;
  40669. if (cmp !== 0) {
  40670. return cmp;
  40671. }
  40672. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40673. if (cmp !== 0) {
  40674. return cmp;
  40675. }
  40676. return strcmp(mappingA.name, mappingB.name);
  40677. }
  40678. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  40679. function strcmp(aStr1, aStr2) {
  40680. if (aStr1 === aStr2) {
  40681. return 0;
  40682. }
  40683. if (aStr1 === null) {
  40684. return 1; // aStr2 !== null
  40685. }
  40686. if (aStr2 === null) {
  40687. return -1; // aStr1 !== null
  40688. }
  40689. if (aStr1 > aStr2) {
  40690. return 1;
  40691. }
  40692. return -1;
  40693. }
  40694. /**
  40695. * Comparator between two mappings with inflated source and name strings where
  40696. * the generated positions are compared.
  40697. */
  40698. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  40699. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40700. if (cmp !== 0) {
  40701. return cmp;
  40702. }
  40703. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40704. if (cmp !== 0) {
  40705. return cmp;
  40706. }
  40707. cmp = strcmp(mappingA.source, mappingB.source);
  40708. if (cmp !== 0) {
  40709. return cmp;
  40710. }
  40711. cmp = mappingA.originalLine - mappingB.originalLine;
  40712. if (cmp !== 0) {
  40713. return cmp;
  40714. }
  40715. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40716. if (cmp !== 0) {
  40717. return cmp;
  40718. }
  40719. return strcmp(mappingA.name, mappingB.name);
  40720. }
  40721. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  40722. /**
  40723. * Strip any JSON XSSI avoidance prefix from the string (as documented
  40724. * in the source maps specification), and then parse the string as
  40725. * JSON.
  40726. */
  40727. function parseSourceMapInput(str) {
  40728. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  40729. }
  40730. exports.parseSourceMapInput = parseSourceMapInput;
  40731. /**
  40732. * Compute the URL of a source given the the source root, the source's
  40733. * URL, and the source map's URL.
  40734. */
  40735. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  40736. sourceURL = sourceURL || '';
  40737. if (sourceRoot) {
  40738. // This follows what Chrome does.
  40739. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  40740. sourceRoot += '/';
  40741. }
  40742. // The spec says:
  40743. // Line 4: An optional source root, useful for relocating source
  40744. // files on a server or removing repeated values in the
  40745. // “sources” entry. This value is prepended to the individual
  40746. // entries in the “source” field.
  40747. sourceURL = sourceRoot + sourceURL;
  40748. }
  40749. // Historically, SourceMapConsumer did not take the sourceMapURL as
  40750. // a parameter. This mode is still somewhat supported, which is why
  40751. // this code block is conditional. However, it's preferable to pass
  40752. // the source map URL to SourceMapConsumer, so that this function
  40753. // can implement the source URL resolution algorithm as outlined in
  40754. // the spec. This block is basically the equivalent of:
  40755. // new URL(sourceURL, sourceMapURL).toString()
  40756. // ... except it avoids using URL, which wasn't available in the
  40757. // older releases of node still supported by this library.
  40758. //
  40759. // The spec says:
  40760. // If the sources are not absolute URLs after prepending of the
  40761. // “sourceRoot”, the sources are resolved relative to the
  40762. // SourceMap (like resolving script src in a html document).
  40763. if (sourceMapURL) {
  40764. var parsed = urlParse(sourceMapURL);
  40765. if (!parsed) {
  40766. throw new Error("sourceMapURL could not be parsed");
  40767. }
  40768. if (parsed.path) {
  40769. // Strip the last path component, but keep the "/".
  40770. var index = parsed.path.lastIndexOf('/');
  40771. if (index >= 0) {
  40772. parsed.path = parsed.path.substring(0, index + 1);
  40773. }
  40774. }
  40775. sourceURL = join(urlGenerate(parsed), sourceURL);
  40776. }
  40777. return normalize(sourceURL);
  40778. }
  40779. exports.computeSourceURL = computeSourceURL;
  40780. } (util));
  40781. return util;
  40782. }
  40783. var arraySet = {};
  40784. /* -*- Mode: js; js-indent-level: 2; -*- */
  40785. var hasRequiredArraySet;
  40786. function requireArraySet () {
  40787. if (hasRequiredArraySet) return arraySet;
  40788. hasRequiredArraySet = 1;
  40789. /*
  40790. * Copyright 2011 Mozilla Foundation and contributors
  40791. * Licensed under the New BSD license. See LICENSE or:
  40792. * http://opensource.org/licenses/BSD-3-Clause
  40793. */
  40794. var util = /*@__PURE__*/ requireUtil();
  40795. var has = Object.prototype.hasOwnProperty;
  40796. var hasNativeMap = typeof Map !== "undefined";
  40797. /**
  40798. * A data structure which is a combination of an array and a set. Adding a new
  40799. * member is O(1), testing for membership is O(1), and finding the index of an
  40800. * element is O(1). Removing elements from the set is not supported. Only
  40801. * strings are supported for membership.
  40802. */
  40803. function ArraySet() {
  40804. this._array = [];
  40805. this._set = hasNativeMap ? new Map() : Object.create(null);
  40806. }
  40807. /**
  40808. * Static method for creating ArraySet instances from an existing array.
  40809. */
  40810. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  40811. var set = new ArraySet();
  40812. for (var i = 0, len = aArray.length; i < len; i++) {
  40813. set.add(aArray[i], aAllowDuplicates);
  40814. }
  40815. return set;
  40816. };
  40817. /**
  40818. * Return how many unique items are in this ArraySet. If duplicates have been
  40819. * added, than those do not count towards the size.
  40820. *
  40821. * @returns Number
  40822. */
  40823. ArraySet.prototype.size = function ArraySet_size() {
  40824. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  40825. };
  40826. /**
  40827. * Add the given string to this set.
  40828. *
  40829. * @param String aStr
  40830. */
  40831. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  40832. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  40833. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  40834. var idx = this._array.length;
  40835. if (!isDuplicate || aAllowDuplicates) {
  40836. this._array.push(aStr);
  40837. }
  40838. if (!isDuplicate) {
  40839. if (hasNativeMap) {
  40840. this._set.set(aStr, idx);
  40841. } else {
  40842. this._set[sStr] = idx;
  40843. }
  40844. }
  40845. };
  40846. /**
  40847. * Is the given string a member of this set?
  40848. *
  40849. * @param String aStr
  40850. */
  40851. ArraySet.prototype.has = function ArraySet_has(aStr) {
  40852. if (hasNativeMap) {
  40853. return this._set.has(aStr);
  40854. } else {
  40855. var sStr = util.toSetString(aStr);
  40856. return has.call(this._set, sStr);
  40857. }
  40858. };
  40859. /**
  40860. * What is the index of the given string in the array?
  40861. *
  40862. * @param String aStr
  40863. */
  40864. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  40865. if (hasNativeMap) {
  40866. var idx = this._set.get(aStr);
  40867. if (idx >= 0) {
  40868. return idx;
  40869. }
  40870. } else {
  40871. var sStr = util.toSetString(aStr);
  40872. if (has.call(this._set, sStr)) {
  40873. return this._set[sStr];
  40874. }
  40875. }
  40876. throw new Error('"' + aStr + '" is not in the set.');
  40877. };
  40878. /**
  40879. * What is the element at the given index?
  40880. *
  40881. * @param Number aIdx
  40882. */
  40883. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  40884. if (aIdx >= 0 && aIdx < this._array.length) {
  40885. return this._array[aIdx];
  40886. }
  40887. throw new Error('No element indexed by ' + aIdx);
  40888. };
  40889. /**
  40890. * Returns the array representation of this set (which has the proper indices
  40891. * indicated by indexOf). Note that this is a copy of the internal array used
  40892. * for storing the members so that no one can mess with internal state.
  40893. */
  40894. ArraySet.prototype.toArray = function ArraySet_toArray() {
  40895. return this._array.slice();
  40896. };
  40897. arraySet.ArraySet = ArraySet;
  40898. return arraySet;
  40899. }
  40900. var mappingList = {};
  40901. /* -*- Mode: js; js-indent-level: 2; -*- */
  40902. var hasRequiredMappingList;
  40903. function requireMappingList () {
  40904. if (hasRequiredMappingList) return mappingList;
  40905. hasRequiredMappingList = 1;
  40906. /*
  40907. * Copyright 2014 Mozilla Foundation and contributors
  40908. * Licensed under the New BSD license. See LICENSE or:
  40909. * http://opensource.org/licenses/BSD-3-Clause
  40910. */
  40911. var util = /*@__PURE__*/ requireUtil();
  40912. /**
  40913. * Determine whether mappingB is after mappingA with respect to generated
  40914. * position.
  40915. */
  40916. function generatedPositionAfter(mappingA, mappingB) {
  40917. // Optimized for most common case
  40918. var lineA = mappingA.generatedLine;
  40919. var lineB = mappingB.generatedLine;
  40920. var columnA = mappingA.generatedColumn;
  40921. var columnB = mappingB.generatedColumn;
  40922. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  40923. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  40924. }
  40925. /**
  40926. * A data structure to provide a sorted view of accumulated mappings in a
  40927. * performance conscious manner. It trades a neglibable overhead in general
  40928. * case for a large speedup in case of mappings being added in order.
  40929. */
  40930. function MappingList() {
  40931. this._array = [];
  40932. this._sorted = true;
  40933. // Serves as infimum
  40934. this._last = {generatedLine: -1, generatedColumn: 0};
  40935. }
  40936. /**
  40937. * Iterate through internal items. This method takes the same arguments that
  40938. * `Array.prototype.forEach` takes.
  40939. *
  40940. * NOTE: The order of the mappings is NOT guaranteed.
  40941. */
  40942. MappingList.prototype.unsortedForEach =
  40943. function MappingList_forEach(aCallback, aThisArg) {
  40944. this._array.forEach(aCallback, aThisArg);
  40945. };
  40946. /**
  40947. * Add the given source mapping.
  40948. *
  40949. * @param Object aMapping
  40950. */
  40951. MappingList.prototype.add = function MappingList_add(aMapping) {
  40952. if (generatedPositionAfter(this._last, aMapping)) {
  40953. this._last = aMapping;
  40954. this._array.push(aMapping);
  40955. } else {
  40956. this._sorted = false;
  40957. this._array.push(aMapping);
  40958. }
  40959. };
  40960. /**
  40961. * Returns the flat, sorted array of mappings. The mappings are sorted by
  40962. * generated position.
  40963. *
  40964. * WARNING: This method returns internal data without copying, for
  40965. * performance. The return value must NOT be mutated, and should be treated as
  40966. * an immutable borrow. If you want to take ownership, you must make your own
  40967. * copy.
  40968. */
  40969. MappingList.prototype.toArray = function MappingList_toArray() {
  40970. if (!this._sorted) {
  40971. this._array.sort(util.compareByGeneratedPositionsInflated);
  40972. this._sorted = true;
  40973. }
  40974. return this._array;
  40975. };
  40976. mappingList.MappingList = MappingList;
  40977. return mappingList;
  40978. }
  40979. /* -*- Mode: js; js-indent-level: 2; -*- */
  40980. var hasRequiredSourceMapGenerator;
  40981. function requireSourceMapGenerator () {
  40982. if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
  40983. hasRequiredSourceMapGenerator = 1;
  40984. /*
  40985. * Copyright 2011 Mozilla Foundation and contributors
  40986. * Licensed under the New BSD license. See LICENSE or:
  40987. * http://opensource.org/licenses/BSD-3-Clause
  40988. */
  40989. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  40990. var util = /*@__PURE__*/ requireUtil();
  40991. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  40992. var MappingList = /*@__PURE__*/ requireMappingList().MappingList;
  40993. /**
  40994. * An instance of the SourceMapGenerator represents a source map which is
  40995. * being built incrementally. You may pass an object with the following
  40996. * properties:
  40997. *
  40998. * - file: The filename of the generated source.
  40999. * - sourceRoot: A root for all relative URLs in this source map.
  41000. */
  41001. function SourceMapGenerator(aArgs) {
  41002. if (!aArgs) {
  41003. aArgs = {};
  41004. }
  41005. this._file = util.getArg(aArgs, 'file', null);
  41006. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  41007. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  41008. this._sources = new ArraySet();
  41009. this._names = new ArraySet();
  41010. this._mappings = new MappingList();
  41011. this._sourcesContents = null;
  41012. }
  41013. SourceMapGenerator.prototype._version = 3;
  41014. /**
  41015. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  41016. *
  41017. * @param aSourceMapConsumer The SourceMap.
  41018. */
  41019. SourceMapGenerator.fromSourceMap =
  41020. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  41021. var sourceRoot = aSourceMapConsumer.sourceRoot;
  41022. var generator = new SourceMapGenerator({
  41023. file: aSourceMapConsumer.file,
  41024. sourceRoot: sourceRoot
  41025. });
  41026. aSourceMapConsumer.eachMapping(function (mapping) {
  41027. var newMapping = {
  41028. generated: {
  41029. line: mapping.generatedLine,
  41030. column: mapping.generatedColumn
  41031. }
  41032. };
  41033. if (mapping.source != null) {
  41034. newMapping.source = mapping.source;
  41035. if (sourceRoot != null) {
  41036. newMapping.source = util.relative(sourceRoot, newMapping.source);
  41037. }
  41038. newMapping.original = {
  41039. line: mapping.originalLine,
  41040. column: mapping.originalColumn
  41041. };
  41042. if (mapping.name != null) {
  41043. newMapping.name = mapping.name;
  41044. }
  41045. }
  41046. generator.addMapping(newMapping);
  41047. });
  41048. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41049. var sourceRelative = sourceFile;
  41050. if (sourceRoot !== null) {
  41051. sourceRelative = util.relative(sourceRoot, sourceFile);
  41052. }
  41053. if (!generator._sources.has(sourceRelative)) {
  41054. generator._sources.add(sourceRelative);
  41055. }
  41056. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41057. if (content != null) {
  41058. generator.setSourceContent(sourceFile, content);
  41059. }
  41060. });
  41061. return generator;
  41062. };
  41063. /**
  41064. * Add a single mapping from original source line and column to the generated
  41065. * source's line and column for this source map being created. The mapping
  41066. * object should have the following properties:
  41067. *
  41068. * - generated: An object with the generated line and column positions.
  41069. * - original: An object with the original line and column positions.
  41070. * - source: The original source file (relative to the sourceRoot).
  41071. * - name: An optional original token name for this mapping.
  41072. */
  41073. SourceMapGenerator.prototype.addMapping =
  41074. function SourceMapGenerator_addMapping(aArgs) {
  41075. var generated = util.getArg(aArgs, 'generated');
  41076. var original = util.getArg(aArgs, 'original', null);
  41077. var source = util.getArg(aArgs, 'source', null);
  41078. var name = util.getArg(aArgs, 'name', null);
  41079. if (!this._skipValidation) {
  41080. this._validateMapping(generated, original, source, name);
  41081. }
  41082. if (source != null) {
  41083. source = String(source);
  41084. if (!this._sources.has(source)) {
  41085. this._sources.add(source);
  41086. }
  41087. }
  41088. if (name != null) {
  41089. name = String(name);
  41090. if (!this._names.has(name)) {
  41091. this._names.add(name);
  41092. }
  41093. }
  41094. this._mappings.add({
  41095. generatedLine: generated.line,
  41096. generatedColumn: generated.column,
  41097. originalLine: original != null && original.line,
  41098. originalColumn: original != null && original.column,
  41099. source: source,
  41100. name: name
  41101. });
  41102. };
  41103. /**
  41104. * Set the source content for a source file.
  41105. */
  41106. SourceMapGenerator.prototype.setSourceContent =
  41107. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  41108. var source = aSourceFile;
  41109. if (this._sourceRoot != null) {
  41110. source = util.relative(this._sourceRoot, source);
  41111. }
  41112. if (aSourceContent != null) {
  41113. // Add the source content to the _sourcesContents map.
  41114. // Create a new _sourcesContents map if the property is null.
  41115. if (!this._sourcesContents) {
  41116. this._sourcesContents = Object.create(null);
  41117. }
  41118. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  41119. } else if (this._sourcesContents) {
  41120. // Remove the source file from the _sourcesContents map.
  41121. // If the _sourcesContents map is empty, set the property to null.
  41122. delete this._sourcesContents[util.toSetString(source)];
  41123. if (Object.keys(this._sourcesContents).length === 0) {
  41124. this._sourcesContents = null;
  41125. }
  41126. }
  41127. };
  41128. /**
  41129. * Applies the mappings of a sub-source-map for a specific source file to the
  41130. * source map being generated. Each mapping to the supplied source file is
  41131. * rewritten using the supplied source map. Note: The resolution for the
  41132. * resulting mappings is the minimium of this map and the supplied map.
  41133. *
  41134. * @param aSourceMapConsumer The source map to be applied.
  41135. * @param aSourceFile Optional. The filename of the source file.
  41136. * If omitted, SourceMapConsumer's file property will be used.
  41137. * @param aSourceMapPath Optional. The dirname of the path to the source map
  41138. * to be applied. If relative, it is relative to the SourceMapConsumer.
  41139. * This parameter is needed when the two source maps aren't in the same
  41140. * directory, and the source map to be applied contains relative source
  41141. * paths. If so, those relative source paths need to be rewritten
  41142. * relative to the SourceMapGenerator.
  41143. */
  41144. SourceMapGenerator.prototype.applySourceMap =
  41145. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  41146. var sourceFile = aSourceFile;
  41147. // If aSourceFile is omitted, we will use the file property of the SourceMap
  41148. if (aSourceFile == null) {
  41149. if (aSourceMapConsumer.file == null) {
  41150. throw new Error(
  41151. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  41152. 'or the source map\'s "file" property. Both were omitted.'
  41153. );
  41154. }
  41155. sourceFile = aSourceMapConsumer.file;
  41156. }
  41157. var sourceRoot = this._sourceRoot;
  41158. // Make "sourceFile" relative if an absolute Url is passed.
  41159. if (sourceRoot != null) {
  41160. sourceFile = util.relative(sourceRoot, sourceFile);
  41161. }
  41162. // Applying the SourceMap can add and remove items from the sources and
  41163. // the names array.
  41164. var newSources = new ArraySet();
  41165. var newNames = new ArraySet();
  41166. // Find mappings for the "sourceFile"
  41167. this._mappings.unsortedForEach(function (mapping) {
  41168. if (mapping.source === sourceFile && mapping.originalLine != null) {
  41169. // Check if it can be mapped by the source map, then update the mapping.
  41170. var original = aSourceMapConsumer.originalPositionFor({
  41171. line: mapping.originalLine,
  41172. column: mapping.originalColumn
  41173. });
  41174. if (original.source != null) {
  41175. // Copy mapping
  41176. mapping.source = original.source;
  41177. if (aSourceMapPath != null) {
  41178. mapping.source = util.join(aSourceMapPath, mapping.source);
  41179. }
  41180. if (sourceRoot != null) {
  41181. mapping.source = util.relative(sourceRoot, mapping.source);
  41182. }
  41183. mapping.originalLine = original.line;
  41184. mapping.originalColumn = original.column;
  41185. if (original.name != null) {
  41186. mapping.name = original.name;
  41187. }
  41188. }
  41189. }
  41190. var source = mapping.source;
  41191. if (source != null && !newSources.has(source)) {
  41192. newSources.add(source);
  41193. }
  41194. var name = mapping.name;
  41195. if (name != null && !newNames.has(name)) {
  41196. newNames.add(name);
  41197. }
  41198. }, this);
  41199. this._sources = newSources;
  41200. this._names = newNames;
  41201. // Copy sourcesContents of applied map.
  41202. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41203. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41204. if (content != null) {
  41205. if (aSourceMapPath != null) {
  41206. sourceFile = util.join(aSourceMapPath, sourceFile);
  41207. }
  41208. if (sourceRoot != null) {
  41209. sourceFile = util.relative(sourceRoot, sourceFile);
  41210. }
  41211. this.setSourceContent(sourceFile, content);
  41212. }
  41213. }, this);
  41214. };
  41215. /**
  41216. * A mapping can have one of the three levels of data:
  41217. *
  41218. * 1. Just the generated position.
  41219. * 2. The Generated position, original position, and original source.
  41220. * 3. Generated and original position, original source, as well as a name
  41221. * token.
  41222. *
  41223. * To maintain consistency, we validate that any new mapping being added falls
  41224. * in to one of these categories.
  41225. */
  41226. SourceMapGenerator.prototype._validateMapping =
  41227. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  41228. aName) {
  41229. // When aOriginal is truthy but has empty values for .line and .column,
  41230. // it is most likely a programmer error. In this case we throw a very
  41231. // specific error message to try to guide them the right way.
  41232. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  41233. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  41234. throw new Error(
  41235. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  41236. 'the original mapping entirely and only map the generated position. If so, pass ' +
  41237. 'null for the original mapping instead of an object with empty or null values.'
  41238. );
  41239. }
  41240. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41241. && aGenerated.line > 0 && aGenerated.column >= 0
  41242. && !aOriginal && !aSource && !aName) {
  41243. // Case 1.
  41244. return;
  41245. }
  41246. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41247. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  41248. && aGenerated.line > 0 && aGenerated.column >= 0
  41249. && aOriginal.line > 0 && aOriginal.column >= 0
  41250. && aSource) {
  41251. // Cases 2 and 3.
  41252. return;
  41253. }
  41254. else {
  41255. throw new Error('Invalid mapping: ' + JSON.stringify({
  41256. generated: aGenerated,
  41257. source: aSource,
  41258. original: aOriginal,
  41259. name: aName
  41260. }));
  41261. }
  41262. };
  41263. /**
  41264. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  41265. * specified by the source map format.
  41266. */
  41267. SourceMapGenerator.prototype._serializeMappings =
  41268. function SourceMapGenerator_serializeMappings() {
  41269. var previousGeneratedColumn = 0;
  41270. var previousGeneratedLine = 1;
  41271. var previousOriginalColumn = 0;
  41272. var previousOriginalLine = 0;
  41273. var previousName = 0;
  41274. var previousSource = 0;
  41275. var result = '';
  41276. var next;
  41277. var mapping;
  41278. var nameIdx;
  41279. var sourceIdx;
  41280. var mappings = this._mappings.toArray();
  41281. for (var i = 0, len = mappings.length; i < len; i++) {
  41282. mapping = mappings[i];
  41283. next = '';
  41284. if (mapping.generatedLine !== previousGeneratedLine) {
  41285. previousGeneratedColumn = 0;
  41286. while (mapping.generatedLine !== previousGeneratedLine) {
  41287. next += ';';
  41288. previousGeneratedLine++;
  41289. }
  41290. }
  41291. else {
  41292. if (i > 0) {
  41293. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  41294. continue;
  41295. }
  41296. next += ',';
  41297. }
  41298. }
  41299. next += base64VLQ.encode(mapping.generatedColumn
  41300. - previousGeneratedColumn);
  41301. previousGeneratedColumn = mapping.generatedColumn;
  41302. if (mapping.source != null) {
  41303. sourceIdx = this._sources.indexOf(mapping.source);
  41304. next += base64VLQ.encode(sourceIdx - previousSource);
  41305. previousSource = sourceIdx;
  41306. // lines are stored 0-based in SourceMap spec version 3
  41307. next += base64VLQ.encode(mapping.originalLine - 1
  41308. - previousOriginalLine);
  41309. previousOriginalLine = mapping.originalLine - 1;
  41310. next += base64VLQ.encode(mapping.originalColumn
  41311. - previousOriginalColumn);
  41312. previousOriginalColumn = mapping.originalColumn;
  41313. if (mapping.name != null) {
  41314. nameIdx = this._names.indexOf(mapping.name);
  41315. next += base64VLQ.encode(nameIdx - previousName);
  41316. previousName = nameIdx;
  41317. }
  41318. }
  41319. result += next;
  41320. }
  41321. return result;
  41322. };
  41323. SourceMapGenerator.prototype._generateSourcesContent =
  41324. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  41325. return aSources.map(function (source) {
  41326. if (!this._sourcesContents) {
  41327. return null;
  41328. }
  41329. if (aSourceRoot != null) {
  41330. source = util.relative(aSourceRoot, source);
  41331. }
  41332. var key = util.toSetString(source);
  41333. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  41334. ? this._sourcesContents[key]
  41335. : null;
  41336. }, this);
  41337. };
  41338. /**
  41339. * Externalize the source map.
  41340. */
  41341. SourceMapGenerator.prototype.toJSON =
  41342. function SourceMapGenerator_toJSON() {
  41343. var map = {
  41344. version: this._version,
  41345. sources: this._sources.toArray(),
  41346. names: this._names.toArray(),
  41347. mappings: this._serializeMappings()
  41348. };
  41349. if (this._file != null) {
  41350. map.file = this._file;
  41351. }
  41352. if (this._sourceRoot != null) {
  41353. map.sourceRoot = this._sourceRoot;
  41354. }
  41355. if (this._sourcesContents) {
  41356. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  41357. }
  41358. return map;
  41359. };
  41360. /**
  41361. * Render the source map being generated to a string.
  41362. */
  41363. SourceMapGenerator.prototype.toString =
  41364. function SourceMapGenerator_toString() {
  41365. return JSON.stringify(this.toJSON());
  41366. };
  41367. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
  41368. return sourceMapGenerator;
  41369. }
  41370. var sourceMapConsumer = {};
  41371. var binarySearch = {};
  41372. /* -*- Mode: js; js-indent-level: 2; -*- */
  41373. var hasRequiredBinarySearch;
  41374. function requireBinarySearch () {
  41375. if (hasRequiredBinarySearch) return binarySearch;
  41376. hasRequiredBinarySearch = 1;
  41377. (function (exports) {
  41378. /*
  41379. * Copyright 2011 Mozilla Foundation and contributors
  41380. * Licensed under the New BSD license. See LICENSE or:
  41381. * http://opensource.org/licenses/BSD-3-Clause
  41382. */
  41383. exports.GREATEST_LOWER_BOUND = 1;
  41384. exports.LEAST_UPPER_BOUND = 2;
  41385. /**
  41386. * Recursive implementation of binary search.
  41387. *
  41388. * @param aLow Indices here and lower do not contain the needle.
  41389. * @param aHigh Indices here and higher do not contain the needle.
  41390. * @param aNeedle The element being searched for.
  41391. * @param aHaystack The non-empty array being searched.
  41392. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  41393. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41394. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41395. * closest element that is smaller than or greater than the one we are
  41396. * searching for, respectively, if the exact element cannot be found.
  41397. */
  41398. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  41399. // This function terminates when one of the following is true:
  41400. //
  41401. // 1. We find the exact element we are looking for.
  41402. //
  41403. // 2. We did not find the exact element, but we can return the index of
  41404. // the next-closest element.
  41405. //
  41406. // 3. We did not find the exact element, and there is no next-closest
  41407. // element than the one we are searching for, so we return -1.
  41408. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  41409. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  41410. if (cmp === 0) {
  41411. // Found the element we are looking for.
  41412. return mid;
  41413. }
  41414. else if (cmp > 0) {
  41415. // Our needle is greater than aHaystack[mid].
  41416. if (aHigh - mid > 1) {
  41417. // The element is in the upper half.
  41418. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  41419. }
  41420. // The exact needle element was not found in this haystack. Determine if
  41421. // we are in termination case (3) or (2) and return the appropriate thing.
  41422. if (aBias == exports.LEAST_UPPER_BOUND) {
  41423. return aHigh < aHaystack.length ? aHigh : -1;
  41424. } else {
  41425. return mid;
  41426. }
  41427. }
  41428. else {
  41429. // Our needle is less than aHaystack[mid].
  41430. if (mid - aLow > 1) {
  41431. // The element is in the lower half.
  41432. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  41433. }
  41434. // we are in termination case (3) or (2) and return the appropriate thing.
  41435. if (aBias == exports.LEAST_UPPER_BOUND) {
  41436. return mid;
  41437. } else {
  41438. return aLow < 0 ? -1 : aLow;
  41439. }
  41440. }
  41441. }
  41442. /**
  41443. * This is an implementation of binary search which will always try and return
  41444. * the index of the closest element if there is no exact hit. This is because
  41445. * mappings between original and generated line/col pairs are single points,
  41446. * and there is an implicit region between each of them, so a miss just means
  41447. * that you aren't on the very start of a region.
  41448. *
  41449. * @param aNeedle The element you are looking for.
  41450. * @param aHaystack The array that is being searched.
  41451. * @param aCompare A function which takes the needle and an element in the
  41452. * array and returns -1, 0, or 1 depending on whether the needle is less
  41453. * than, equal to, or greater than the element, respectively.
  41454. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41455. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41456. * closest element that is smaller than or greater than the one we are
  41457. * searching for, respectively, if the exact element cannot be found.
  41458. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  41459. */
  41460. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  41461. if (aHaystack.length === 0) {
  41462. return -1;
  41463. }
  41464. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  41465. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  41466. if (index < 0) {
  41467. return -1;
  41468. }
  41469. // We have found either the exact element, or the next-closest element than
  41470. // the one we are searching for. However, there may be more than one such
  41471. // element. Make sure we always return the smallest of these.
  41472. while (index - 1 >= 0) {
  41473. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  41474. break;
  41475. }
  41476. --index;
  41477. }
  41478. return index;
  41479. };
  41480. } (binarySearch));
  41481. return binarySearch;
  41482. }
  41483. var quickSort = {};
  41484. /* -*- Mode: js; js-indent-level: 2; -*- */
  41485. var hasRequiredQuickSort;
  41486. function requireQuickSort () {
  41487. if (hasRequiredQuickSort) return quickSort;
  41488. hasRequiredQuickSort = 1;
  41489. /*
  41490. * Copyright 2011 Mozilla Foundation and contributors
  41491. * Licensed under the New BSD license. See LICENSE or:
  41492. * http://opensource.org/licenses/BSD-3-Clause
  41493. */
  41494. // It turns out that some (most?) JavaScript engines don't self-host
  41495. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  41496. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  41497. // custom comparator function, calling back and forth between the VM's C++ and
  41498. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  41499. // worse generated code for the comparator function than would be optimal. In
  41500. // fact, when sorting with a comparator, these costs outweigh the benefits of
  41501. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  41502. // a ~3500ms mean speed-up in `bench/bench.html`.
  41503. /**
  41504. * Swap the elements indexed by `x` and `y` in the array `ary`.
  41505. *
  41506. * @param {Array} ary
  41507. * The array.
  41508. * @param {Number} x
  41509. * The index of the first item.
  41510. * @param {Number} y
  41511. * The index of the second item.
  41512. */
  41513. function swap(ary, x, y) {
  41514. var temp = ary[x];
  41515. ary[x] = ary[y];
  41516. ary[y] = temp;
  41517. }
  41518. /**
  41519. * Returns a random integer within the range `low .. high` inclusive.
  41520. *
  41521. * @param {Number} low
  41522. * The lower bound on the range.
  41523. * @param {Number} high
  41524. * The upper bound on the range.
  41525. */
  41526. function randomIntInRange(low, high) {
  41527. return Math.round(low + (Math.random() * (high - low)));
  41528. }
  41529. /**
  41530. * The Quick Sort algorithm.
  41531. *
  41532. * @param {Array} ary
  41533. * An array to sort.
  41534. * @param {function} comparator
  41535. * Function to use to compare two items.
  41536. * @param {Number} p
  41537. * Start index of the array
  41538. * @param {Number} r
  41539. * End index of the array
  41540. */
  41541. function doQuickSort(ary, comparator, p, r) {
  41542. // If our lower bound is less than our upper bound, we (1) partition the
  41543. // array into two pieces and (2) recurse on each half. If it is not, this is
  41544. // the empty array and our base case.
  41545. if (p < r) {
  41546. // (1) Partitioning.
  41547. //
  41548. // The partitioning chooses a pivot between `p` and `r` and moves all
  41549. // elements that are less than or equal to the pivot to the before it, and
  41550. // all the elements that are greater than it after it. The effect is that
  41551. // once partition is done, the pivot is in the exact place it will be when
  41552. // the array is put in sorted order, and it will not need to be moved
  41553. // again. This runs in O(n) time.
  41554. // Always choose a random pivot so that an input array which is reverse
  41555. // sorted does not cause O(n^2) running time.
  41556. var pivotIndex = randomIntInRange(p, r);
  41557. var i = p - 1;
  41558. swap(ary, pivotIndex, r);
  41559. var pivot = ary[r];
  41560. // Immediately after `j` is incremented in this loop, the following hold
  41561. // true:
  41562. //
  41563. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  41564. //
  41565. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41566. for (var j = p; j < r; j++) {
  41567. if (comparator(ary[j], pivot) <= 0) {
  41568. i += 1;
  41569. swap(ary, i, j);
  41570. }
  41571. }
  41572. swap(ary, i + 1, j);
  41573. var q = i + 1;
  41574. // (2) Recurse on each half.
  41575. doQuickSort(ary, comparator, p, q - 1);
  41576. doQuickSort(ary, comparator, q + 1, r);
  41577. }
  41578. }
  41579. /**
  41580. * Sort the given array in-place with the given comparator function.
  41581. *
  41582. * @param {Array} ary
  41583. * An array to sort.
  41584. * @param {function} comparator
  41585. * Function to use to compare two items.
  41586. */
  41587. quickSort.quickSort = function (ary, comparator) {
  41588. doQuickSort(ary, comparator, 0, ary.length - 1);
  41589. };
  41590. return quickSort;
  41591. }
  41592. /* -*- Mode: js; js-indent-level: 2; -*- */
  41593. var hasRequiredSourceMapConsumer;
  41594. function requireSourceMapConsumer () {
  41595. if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
  41596. hasRequiredSourceMapConsumer = 1;
  41597. /*
  41598. * Copyright 2011 Mozilla Foundation and contributors
  41599. * Licensed under the New BSD license. See LICENSE or:
  41600. * http://opensource.org/licenses/BSD-3-Clause
  41601. */
  41602. var util = /*@__PURE__*/ requireUtil();
  41603. var binarySearch = /*@__PURE__*/ requireBinarySearch();
  41604. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41605. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41606. var quickSort = /*@__PURE__*/ requireQuickSort().quickSort;
  41607. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  41608. var sourceMap = aSourceMap;
  41609. if (typeof aSourceMap === 'string') {
  41610. sourceMap = util.parseSourceMapInput(aSourceMap);
  41611. }
  41612. return sourceMap.sections != null
  41613. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41614. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41615. }
  41616. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41617. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41618. };
  41619. /**
  41620. * The version of the source mapping spec that we are consuming.
  41621. */
  41622. SourceMapConsumer.prototype._version = 3;
  41623. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41624. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41625. // are lazily instantiated, accessed via the `_generatedMappings` and
  41626. // `_originalMappings` getters respectively, and we only parse the mappings
  41627. // and create these arrays once queried for a source location. We jump through
  41628. // these hoops because there can be many thousands of mappings, and parsing
  41629. // them is expensive, so we only want to do it if we must.
  41630. //
  41631. // Each object in the arrays is of the form:
  41632. //
  41633. // {
  41634. // generatedLine: The line number in the generated code,
  41635. // generatedColumn: The column number in the generated code,
  41636. // source: The path to the original source file that generated this
  41637. // chunk of code,
  41638. // originalLine: The line number in the original source that
  41639. // corresponds to this chunk of generated code,
  41640. // originalColumn: The column number in the original source that
  41641. // corresponds to this chunk of generated code,
  41642. // name: The name of the original symbol which generated this chunk of
  41643. // code.
  41644. // }
  41645. //
  41646. // All properties except for `generatedLine` and `generatedColumn` can be
  41647. // `null`.
  41648. //
  41649. // `_generatedMappings` is ordered by the generated positions.
  41650. //
  41651. // `_originalMappings` is ordered by the original positions.
  41652. SourceMapConsumer.prototype.__generatedMappings = null;
  41653. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  41654. configurable: true,
  41655. enumerable: true,
  41656. get: function () {
  41657. if (!this.__generatedMappings) {
  41658. this._parseMappings(this._mappings, this.sourceRoot);
  41659. }
  41660. return this.__generatedMappings;
  41661. }
  41662. });
  41663. SourceMapConsumer.prototype.__originalMappings = null;
  41664. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  41665. configurable: true,
  41666. enumerable: true,
  41667. get: function () {
  41668. if (!this.__originalMappings) {
  41669. this._parseMappings(this._mappings, this.sourceRoot);
  41670. }
  41671. return this.__originalMappings;
  41672. }
  41673. });
  41674. SourceMapConsumer.prototype._charIsMappingSeparator =
  41675. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  41676. var c = aStr.charAt(index);
  41677. return c === ";" || c === ",";
  41678. };
  41679. /**
  41680. * Parse the mappings in a string in to a data structure which we can easily
  41681. * query (the ordered arrays in the `this.__generatedMappings` and
  41682. * `this.__originalMappings` properties).
  41683. */
  41684. SourceMapConsumer.prototype._parseMappings =
  41685. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41686. throw new Error("Subclasses must implement _parseMappings");
  41687. };
  41688. SourceMapConsumer.GENERATED_ORDER = 1;
  41689. SourceMapConsumer.ORIGINAL_ORDER = 2;
  41690. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  41691. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  41692. /**
  41693. * Iterate over each mapping between an original source/line/column and a
  41694. * generated line/column in this source map.
  41695. *
  41696. * @param Function aCallback
  41697. * The function that is called with each mapping.
  41698. * @param Object aContext
  41699. * Optional. If specified, this object will be the value of `this` every
  41700. * time that `aCallback` is called.
  41701. * @param aOrder
  41702. * Either `SourceMapConsumer.GENERATED_ORDER` or
  41703. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  41704. * iterate over the mappings sorted by the generated file's line/column
  41705. * order or the original's source/line/column order, respectively. Defaults to
  41706. * `SourceMapConsumer.GENERATED_ORDER`.
  41707. */
  41708. SourceMapConsumer.prototype.eachMapping =
  41709. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  41710. var context = aContext || null;
  41711. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  41712. var mappings;
  41713. switch (order) {
  41714. case SourceMapConsumer.GENERATED_ORDER:
  41715. mappings = this._generatedMappings;
  41716. break;
  41717. case SourceMapConsumer.ORIGINAL_ORDER:
  41718. mappings = this._originalMappings;
  41719. break;
  41720. default:
  41721. throw new Error("Unknown order of iteration.");
  41722. }
  41723. var sourceRoot = this.sourceRoot;
  41724. mappings.map(function (mapping) {
  41725. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  41726. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  41727. return {
  41728. source: source,
  41729. generatedLine: mapping.generatedLine,
  41730. generatedColumn: mapping.generatedColumn,
  41731. originalLine: mapping.originalLine,
  41732. originalColumn: mapping.originalColumn,
  41733. name: mapping.name === null ? null : this._names.at(mapping.name)
  41734. };
  41735. }, this).forEach(aCallback, context);
  41736. };
  41737. /**
  41738. * Returns all generated line and column information for the original source,
  41739. * line, and column provided. If no column is provided, returns all mappings
  41740. * corresponding to a either the line we are searching for or the next
  41741. * closest line that has any mappings. Otherwise, returns all mappings
  41742. * corresponding to the given line and either the column we are searching for
  41743. * or the next closest column that has any offsets.
  41744. *
  41745. * The only argument is an object with the following properties:
  41746. *
  41747. * - source: The filename of the original source.
  41748. * - line: The line number in the original source. The line number is 1-based.
  41749. * - column: Optional. the column number in the original source.
  41750. * The column number is 0-based.
  41751. *
  41752. * and an array of objects is returned, each with the following properties:
  41753. *
  41754. * - line: The line number in the generated source, or null. The
  41755. * line number is 1-based.
  41756. * - column: The column number in the generated source, or null.
  41757. * The column number is 0-based.
  41758. */
  41759. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  41760. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  41761. var line = util.getArg(aArgs, 'line');
  41762. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  41763. // returns the index of the closest mapping less than the needle. By
  41764. // setting needle.originalColumn to 0, we thus find the last mapping for
  41765. // the given line, provided such a mapping exists.
  41766. var needle = {
  41767. source: util.getArg(aArgs, 'source'),
  41768. originalLine: line,
  41769. originalColumn: util.getArg(aArgs, 'column', 0)
  41770. };
  41771. needle.source = this._findSourceIndex(needle.source);
  41772. if (needle.source < 0) {
  41773. return [];
  41774. }
  41775. var mappings = [];
  41776. var index = this._findMapping(needle,
  41777. this._originalMappings,
  41778. "originalLine",
  41779. "originalColumn",
  41780. util.compareByOriginalPositions,
  41781. binarySearch.LEAST_UPPER_BOUND);
  41782. if (index >= 0) {
  41783. var mapping = this._originalMappings[index];
  41784. if (aArgs.column === undefined) {
  41785. var originalLine = mapping.originalLine;
  41786. // Iterate until either we run out of mappings, or we run into
  41787. // a mapping for a different line than the one we found. Since
  41788. // mappings are sorted, this is guaranteed to find all mappings for
  41789. // the line we found.
  41790. while (mapping && mapping.originalLine === originalLine) {
  41791. mappings.push({
  41792. line: util.getArg(mapping, 'generatedLine', null),
  41793. column: util.getArg(mapping, 'generatedColumn', null),
  41794. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  41795. });
  41796. mapping = this._originalMappings[++index];
  41797. }
  41798. } else {
  41799. var originalColumn = mapping.originalColumn;
  41800. // Iterate until either we run out of mappings, or we run into
  41801. // a mapping for a different line than the one we were searching for.
  41802. // Since mappings are sorted, this is guaranteed to find all mappings for
  41803. // the line we are searching for.
  41804. while (mapping &&
  41805. mapping.originalLine === line &&
  41806. mapping.originalColumn == originalColumn) {
  41807. mappings.push({
  41808. line: util.getArg(mapping, 'generatedLine', null),
  41809. column: util.getArg(mapping, 'generatedColumn', null),
  41810. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  41811. });
  41812. mapping = this._originalMappings[++index];
  41813. }
  41814. }
  41815. }
  41816. return mappings;
  41817. };
  41818. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
  41819. /**
  41820. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  41821. * query for information about the original file positions by giving it a file
  41822. * position in the generated source.
  41823. *
  41824. * The first parameter is the raw source map (either as a JSON string, or
  41825. * already parsed to an object). According to the spec, source maps have the
  41826. * following attributes:
  41827. *
  41828. * - version: Which version of the source map spec this map is following.
  41829. * - sources: An array of URLs to the original source files.
  41830. * - names: An array of identifiers which can be referrenced by individual mappings.
  41831. * - sourceRoot: Optional. The URL root from which all sources are relative.
  41832. * - sourcesContent: Optional. An array of contents of the original source files.
  41833. * - mappings: A string of base64 VLQs which contain the actual mappings.
  41834. * - file: Optional. The generated file this source map is associated with.
  41835. *
  41836. * Here is an example source map, taken from the source map spec[0]:
  41837. *
  41838. * {
  41839. * version : 3,
  41840. * file: "out.js",
  41841. * sourceRoot : "",
  41842. * sources: ["foo.js", "bar.js"],
  41843. * names: ["src", "maps", "are", "fun"],
  41844. * mappings: "AA,AB;;ABCDE;"
  41845. * }
  41846. *
  41847. * The second parameter, if given, is a string whose value is the URL
  41848. * at which the source map was found. This URL is used to compute the
  41849. * sources array.
  41850. *
  41851. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  41852. */
  41853. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41854. var sourceMap = aSourceMap;
  41855. if (typeof aSourceMap === 'string') {
  41856. sourceMap = util.parseSourceMapInput(aSourceMap);
  41857. }
  41858. var version = util.getArg(sourceMap, 'version');
  41859. var sources = util.getArg(sourceMap, 'sources');
  41860. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  41861. // requires the array) to play nice here.
  41862. var names = util.getArg(sourceMap, 'names', []);
  41863. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  41864. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  41865. var mappings = util.getArg(sourceMap, 'mappings');
  41866. var file = util.getArg(sourceMap, 'file', null);
  41867. // Once again, Sass deviates from the spec and supplies the version as a
  41868. // string rather than a number, so we use loose equality checking here.
  41869. if (version != this._version) {
  41870. throw new Error('Unsupported version: ' + version);
  41871. }
  41872. if (sourceRoot) {
  41873. sourceRoot = util.normalize(sourceRoot);
  41874. }
  41875. sources = sources
  41876. .map(String)
  41877. // Some source maps produce relative source paths like "./foo.js" instead of
  41878. // "foo.js". Normalize these first so that future comparisons will succeed.
  41879. // See bugzil.la/1090768.
  41880. .map(util.normalize)
  41881. // Always ensure that absolute sources are internally stored relative to
  41882. // the source root, if the source root is absolute. Not doing this would
  41883. // be particularly problematic when the source root is a prefix of the
  41884. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  41885. .map(function (source) {
  41886. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  41887. ? util.relative(sourceRoot, source)
  41888. : source;
  41889. });
  41890. // Pass `true` below to allow duplicate names and sources. While source maps
  41891. // are intended to be compressed and deduplicated, the TypeScript compiler
  41892. // sometimes generates source maps with duplicates in them. See Github issue
  41893. // #72 and bugzil.la/889492.
  41894. this._names = ArraySet.fromArray(names.map(String), true);
  41895. this._sources = ArraySet.fromArray(sources, true);
  41896. this._absoluteSources = this._sources.toArray().map(function (s) {
  41897. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  41898. });
  41899. this.sourceRoot = sourceRoot;
  41900. this.sourcesContent = sourcesContent;
  41901. this._mappings = mappings;
  41902. this._sourceMapURL = aSourceMapURL;
  41903. this.file = file;
  41904. }
  41905. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  41906. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  41907. /**
  41908. * Utility function to find the index of a source. Returns -1 if not
  41909. * found.
  41910. */
  41911. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  41912. var relativeSource = aSource;
  41913. if (this.sourceRoot != null) {
  41914. relativeSource = util.relative(this.sourceRoot, relativeSource);
  41915. }
  41916. if (this._sources.has(relativeSource)) {
  41917. return this._sources.indexOf(relativeSource);
  41918. }
  41919. // Maybe aSource is an absolute URL as returned by |sources|. In
  41920. // this case we can't simply undo the transform.
  41921. var i;
  41922. for (i = 0; i < this._absoluteSources.length; ++i) {
  41923. if (this._absoluteSources[i] == aSource) {
  41924. return i;
  41925. }
  41926. }
  41927. return -1;
  41928. };
  41929. /**
  41930. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  41931. *
  41932. * @param SourceMapGenerator aSourceMap
  41933. * The source map that will be consumed.
  41934. * @param String aSourceMapURL
  41935. * The URL at which the source map can be found (optional)
  41936. * @returns BasicSourceMapConsumer
  41937. */
  41938. BasicSourceMapConsumer.fromSourceMap =
  41939. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  41940. var smc = Object.create(BasicSourceMapConsumer.prototype);
  41941. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  41942. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  41943. smc.sourceRoot = aSourceMap._sourceRoot;
  41944. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  41945. smc.sourceRoot);
  41946. smc.file = aSourceMap._file;
  41947. smc._sourceMapURL = aSourceMapURL;
  41948. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  41949. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  41950. });
  41951. // Because we are modifying the entries (by converting string sources and
  41952. // names to indices into the sources and names ArraySets), we have to make
  41953. // a copy of the entry or else bad things happen. Shared mutable state
  41954. // strikes again! See github issue #191.
  41955. var generatedMappings = aSourceMap._mappings.toArray().slice();
  41956. var destGeneratedMappings = smc.__generatedMappings = [];
  41957. var destOriginalMappings = smc.__originalMappings = [];
  41958. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  41959. var srcMapping = generatedMappings[i];
  41960. var destMapping = new Mapping;
  41961. destMapping.generatedLine = srcMapping.generatedLine;
  41962. destMapping.generatedColumn = srcMapping.generatedColumn;
  41963. if (srcMapping.source) {
  41964. destMapping.source = sources.indexOf(srcMapping.source);
  41965. destMapping.originalLine = srcMapping.originalLine;
  41966. destMapping.originalColumn = srcMapping.originalColumn;
  41967. if (srcMapping.name) {
  41968. destMapping.name = names.indexOf(srcMapping.name);
  41969. }
  41970. destOriginalMappings.push(destMapping);
  41971. }
  41972. destGeneratedMappings.push(destMapping);
  41973. }
  41974. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  41975. return smc;
  41976. };
  41977. /**
  41978. * The version of the source mapping spec that we are consuming.
  41979. */
  41980. BasicSourceMapConsumer.prototype._version = 3;
  41981. /**
  41982. * The list of original sources.
  41983. */
  41984. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  41985. get: function () {
  41986. return this._absoluteSources.slice();
  41987. }
  41988. });
  41989. /**
  41990. * Provide the JIT with a nice shape / hidden class.
  41991. */
  41992. function Mapping() {
  41993. this.generatedLine = 0;
  41994. this.generatedColumn = 0;
  41995. this.source = null;
  41996. this.originalLine = null;
  41997. this.originalColumn = null;
  41998. this.name = null;
  41999. }
  42000. /**
  42001. * Parse the mappings in a string in to a data structure which we can easily
  42002. * query (the ordered arrays in the `this.__generatedMappings` and
  42003. * `this.__originalMappings` properties).
  42004. */
  42005. BasicSourceMapConsumer.prototype._parseMappings =
  42006. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42007. var generatedLine = 1;
  42008. var previousGeneratedColumn = 0;
  42009. var previousOriginalLine = 0;
  42010. var previousOriginalColumn = 0;
  42011. var previousSource = 0;
  42012. var previousName = 0;
  42013. var length = aStr.length;
  42014. var index = 0;
  42015. var cachedSegments = {};
  42016. var temp = {};
  42017. var originalMappings = [];
  42018. var generatedMappings = [];
  42019. var mapping, str, segment, end, value;
  42020. while (index < length) {
  42021. if (aStr.charAt(index) === ';') {
  42022. generatedLine++;
  42023. index++;
  42024. previousGeneratedColumn = 0;
  42025. }
  42026. else if (aStr.charAt(index) === ',') {
  42027. index++;
  42028. }
  42029. else {
  42030. mapping = new Mapping();
  42031. mapping.generatedLine = generatedLine;
  42032. // Because each offset is encoded relative to the previous one,
  42033. // many segments often have the same encoding. We can exploit this
  42034. // fact by caching the parsed variable length fields of each segment,
  42035. // allowing us to avoid a second parse if we encounter the same
  42036. // segment again.
  42037. for (end = index; end < length; end++) {
  42038. if (this._charIsMappingSeparator(aStr, end)) {
  42039. break;
  42040. }
  42041. }
  42042. str = aStr.slice(index, end);
  42043. segment = cachedSegments[str];
  42044. if (segment) {
  42045. index += str.length;
  42046. } else {
  42047. segment = [];
  42048. while (index < end) {
  42049. base64VLQ.decode(aStr, index, temp);
  42050. value = temp.value;
  42051. index = temp.rest;
  42052. segment.push(value);
  42053. }
  42054. if (segment.length === 2) {
  42055. throw new Error('Found a source, but no line and column');
  42056. }
  42057. if (segment.length === 3) {
  42058. throw new Error('Found a source and line, but no column');
  42059. }
  42060. cachedSegments[str] = segment;
  42061. }
  42062. // Generated column.
  42063. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  42064. previousGeneratedColumn = mapping.generatedColumn;
  42065. if (segment.length > 1) {
  42066. // Original source.
  42067. mapping.source = previousSource + segment[1];
  42068. previousSource += segment[1];
  42069. // Original line.
  42070. mapping.originalLine = previousOriginalLine + segment[2];
  42071. previousOriginalLine = mapping.originalLine;
  42072. // Lines are stored 0-based
  42073. mapping.originalLine += 1;
  42074. // Original column.
  42075. mapping.originalColumn = previousOriginalColumn + segment[3];
  42076. previousOriginalColumn = mapping.originalColumn;
  42077. if (segment.length > 4) {
  42078. // Original name.
  42079. mapping.name = previousName + segment[4];
  42080. previousName += segment[4];
  42081. }
  42082. }
  42083. generatedMappings.push(mapping);
  42084. if (typeof mapping.originalLine === 'number') {
  42085. originalMappings.push(mapping);
  42086. }
  42087. }
  42088. }
  42089. quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
  42090. this.__generatedMappings = generatedMappings;
  42091. quickSort(originalMappings, util.compareByOriginalPositions);
  42092. this.__originalMappings = originalMappings;
  42093. };
  42094. /**
  42095. * Find the mapping that best matches the hypothetical "needle" mapping that
  42096. * we are searching for in the given "haystack" of mappings.
  42097. */
  42098. BasicSourceMapConsumer.prototype._findMapping =
  42099. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  42100. aColumnName, aComparator, aBias) {
  42101. // To return the position we are searching for, we must first find the
  42102. // mapping for the given position and then return the opposite position it
  42103. // points to. Because the mappings are sorted, we can use binary search to
  42104. // find the best mapping.
  42105. if (aNeedle[aLineName] <= 0) {
  42106. throw new TypeError('Line must be greater than or equal to 1, got '
  42107. + aNeedle[aLineName]);
  42108. }
  42109. if (aNeedle[aColumnName] < 0) {
  42110. throw new TypeError('Column must be greater than or equal to 0, got '
  42111. + aNeedle[aColumnName]);
  42112. }
  42113. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  42114. };
  42115. /**
  42116. * Compute the last column for each generated mapping. The last column is
  42117. * inclusive.
  42118. */
  42119. BasicSourceMapConsumer.prototype.computeColumnSpans =
  42120. function SourceMapConsumer_computeColumnSpans() {
  42121. for (var index = 0; index < this._generatedMappings.length; ++index) {
  42122. var mapping = this._generatedMappings[index];
  42123. // Mappings do not contain a field for the last generated columnt. We
  42124. // can come up with an optimistic estimate, however, by assuming that
  42125. // mappings are contiguous (i.e. given two consecutive mappings, the
  42126. // first mapping ends where the second one starts).
  42127. if (index + 1 < this._generatedMappings.length) {
  42128. var nextMapping = this._generatedMappings[index + 1];
  42129. if (mapping.generatedLine === nextMapping.generatedLine) {
  42130. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  42131. continue;
  42132. }
  42133. }
  42134. // The last mapping for each line spans the entire line.
  42135. mapping.lastGeneratedColumn = Infinity;
  42136. }
  42137. };
  42138. /**
  42139. * Returns the original source, line, and column information for the generated
  42140. * source's line and column positions provided. The only argument is an object
  42141. * with the following properties:
  42142. *
  42143. * - line: The line number in the generated source. The line number
  42144. * is 1-based.
  42145. * - column: The column number in the generated source. The column
  42146. * number is 0-based.
  42147. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42148. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42149. * closest element that is smaller than or greater than the one we are
  42150. * searching for, respectively, if the exact element cannot be found.
  42151. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42152. *
  42153. * and an object is returned with the following properties:
  42154. *
  42155. * - source: The original source file, or null.
  42156. * - line: The line number in the original source, or null. The
  42157. * line number is 1-based.
  42158. * - column: The column number in the original source, or null. The
  42159. * column number is 0-based.
  42160. * - name: The original identifier, or null.
  42161. */
  42162. BasicSourceMapConsumer.prototype.originalPositionFor =
  42163. function SourceMapConsumer_originalPositionFor(aArgs) {
  42164. var needle = {
  42165. generatedLine: util.getArg(aArgs, 'line'),
  42166. generatedColumn: util.getArg(aArgs, 'column')
  42167. };
  42168. var index = this._findMapping(
  42169. needle,
  42170. this._generatedMappings,
  42171. "generatedLine",
  42172. "generatedColumn",
  42173. util.compareByGeneratedPositionsDeflated,
  42174. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42175. );
  42176. if (index >= 0) {
  42177. var mapping = this._generatedMappings[index];
  42178. if (mapping.generatedLine === needle.generatedLine) {
  42179. var source = util.getArg(mapping, 'source', null);
  42180. if (source !== null) {
  42181. source = this._sources.at(source);
  42182. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  42183. }
  42184. var name = util.getArg(mapping, 'name', null);
  42185. if (name !== null) {
  42186. name = this._names.at(name);
  42187. }
  42188. return {
  42189. source: source,
  42190. line: util.getArg(mapping, 'originalLine', null),
  42191. column: util.getArg(mapping, 'originalColumn', null),
  42192. name: name
  42193. };
  42194. }
  42195. }
  42196. return {
  42197. source: null,
  42198. line: null,
  42199. column: null,
  42200. name: null
  42201. };
  42202. };
  42203. /**
  42204. * Return true if we have the source content for every source in the source
  42205. * map, false otherwise.
  42206. */
  42207. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  42208. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  42209. if (!this.sourcesContent) {
  42210. return false;
  42211. }
  42212. return this.sourcesContent.length >= this._sources.size() &&
  42213. !this.sourcesContent.some(function (sc) { return sc == null; });
  42214. };
  42215. /**
  42216. * Returns the original source content. The only argument is the url of the
  42217. * original source file. Returns null if no original source content is
  42218. * available.
  42219. */
  42220. BasicSourceMapConsumer.prototype.sourceContentFor =
  42221. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42222. if (!this.sourcesContent) {
  42223. return null;
  42224. }
  42225. var index = this._findSourceIndex(aSource);
  42226. if (index >= 0) {
  42227. return this.sourcesContent[index];
  42228. }
  42229. var relativeSource = aSource;
  42230. if (this.sourceRoot != null) {
  42231. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42232. }
  42233. var url;
  42234. if (this.sourceRoot != null
  42235. && (url = util.urlParse(this.sourceRoot))) {
  42236. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  42237. // many users. We can help them out when they expect file:// URIs to
  42238. // behave like it would if they were running a local HTTP server. See
  42239. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  42240. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  42241. if (url.scheme == "file"
  42242. && this._sources.has(fileUriAbsPath)) {
  42243. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  42244. }
  42245. if ((!url.path || url.path == "/")
  42246. && this._sources.has("/" + relativeSource)) {
  42247. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  42248. }
  42249. }
  42250. // This function is used recursively from
  42251. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  42252. // don't want to throw if we can't find the source - we just want to
  42253. // return null, so we provide a flag to exit gracefully.
  42254. if (nullOnMissing) {
  42255. return null;
  42256. }
  42257. else {
  42258. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  42259. }
  42260. };
  42261. /**
  42262. * Returns the generated line and column information for the original source,
  42263. * line, and column positions provided. The only argument is an object with
  42264. * the following properties:
  42265. *
  42266. * - source: The filename of the original source.
  42267. * - line: The line number in the original source. The line number
  42268. * is 1-based.
  42269. * - column: The column number in the original source. The column
  42270. * number is 0-based.
  42271. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42272. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42273. * closest element that is smaller than or greater than the one we are
  42274. * searching for, respectively, if the exact element cannot be found.
  42275. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42276. *
  42277. * and an object is returned with the following properties:
  42278. *
  42279. * - line: The line number in the generated source, or null. The
  42280. * line number is 1-based.
  42281. * - column: The column number in the generated source, or null.
  42282. * The column number is 0-based.
  42283. */
  42284. BasicSourceMapConsumer.prototype.generatedPositionFor =
  42285. function SourceMapConsumer_generatedPositionFor(aArgs) {
  42286. var source = util.getArg(aArgs, 'source');
  42287. source = this._findSourceIndex(source);
  42288. if (source < 0) {
  42289. return {
  42290. line: null,
  42291. column: null,
  42292. lastColumn: null
  42293. };
  42294. }
  42295. var needle = {
  42296. source: source,
  42297. originalLine: util.getArg(aArgs, 'line'),
  42298. originalColumn: util.getArg(aArgs, 'column')
  42299. };
  42300. var index = this._findMapping(
  42301. needle,
  42302. this._originalMappings,
  42303. "originalLine",
  42304. "originalColumn",
  42305. util.compareByOriginalPositions,
  42306. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42307. );
  42308. if (index >= 0) {
  42309. var mapping = this._originalMappings[index];
  42310. if (mapping.source === needle.source) {
  42311. return {
  42312. line: util.getArg(mapping, 'generatedLine', null),
  42313. column: util.getArg(mapping, 'generatedColumn', null),
  42314. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42315. };
  42316. }
  42317. }
  42318. return {
  42319. line: null,
  42320. column: null,
  42321. lastColumn: null
  42322. };
  42323. };
  42324. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  42325. /**
  42326. * An IndexedSourceMapConsumer instance represents a parsed source map which
  42327. * we can query for information. It differs from BasicSourceMapConsumer in
  42328. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  42329. * input.
  42330. *
  42331. * The first parameter is a raw source map (either as a JSON string, or already
  42332. * parsed to an object). According to the spec for indexed source maps, they
  42333. * have the following attributes:
  42334. *
  42335. * - version: Which version of the source map spec this map is following.
  42336. * - file: Optional. The generated file this source map is associated with.
  42337. * - sections: A list of section definitions.
  42338. *
  42339. * Each value under the "sections" field has two fields:
  42340. * - offset: The offset into the original specified at which this section
  42341. * begins to apply, defined as an object with a "line" and "column"
  42342. * field.
  42343. * - map: A source map definition. This source map could also be indexed,
  42344. * but doesn't have to be.
  42345. *
  42346. * Instead of the "map" field, it's also possible to have a "url" field
  42347. * specifying a URL to retrieve a source map from, but that's currently
  42348. * unsupported.
  42349. *
  42350. * Here's an example source map, taken from the source map spec[0], but
  42351. * modified to omit a section which uses the "url" field.
  42352. *
  42353. * {
  42354. * version : 3,
  42355. * file: "app.js",
  42356. * sections: [{
  42357. * offset: {line:100, column:10},
  42358. * map: {
  42359. * version : 3,
  42360. * file: "section.js",
  42361. * sources: ["foo.js", "bar.js"],
  42362. * names: ["src", "maps", "are", "fun"],
  42363. * mappings: "AAAA,E;;ABCDE;"
  42364. * }
  42365. * }],
  42366. * }
  42367. *
  42368. * The second parameter, if given, is a string whose value is the URL
  42369. * at which the source map was found. This URL is used to compute the
  42370. * sources array.
  42371. *
  42372. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  42373. */
  42374. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42375. var sourceMap = aSourceMap;
  42376. if (typeof aSourceMap === 'string') {
  42377. sourceMap = util.parseSourceMapInput(aSourceMap);
  42378. }
  42379. var version = util.getArg(sourceMap, 'version');
  42380. var sections = util.getArg(sourceMap, 'sections');
  42381. if (version != this._version) {
  42382. throw new Error('Unsupported version: ' + version);
  42383. }
  42384. this._sources = new ArraySet();
  42385. this._names = new ArraySet();
  42386. var lastOffset = {
  42387. line: -1,
  42388. column: 0
  42389. };
  42390. this._sections = sections.map(function (s) {
  42391. if (s.url) {
  42392. // The url field will require support for asynchronicity.
  42393. // See https://github.com/mozilla/source-map/issues/16
  42394. throw new Error('Support for url field in sections not implemented.');
  42395. }
  42396. var offset = util.getArg(s, 'offset');
  42397. var offsetLine = util.getArg(offset, 'line');
  42398. var offsetColumn = util.getArg(offset, 'column');
  42399. if (offsetLine < lastOffset.line ||
  42400. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  42401. throw new Error('Section offsets must be ordered and non-overlapping.');
  42402. }
  42403. lastOffset = offset;
  42404. return {
  42405. generatedOffset: {
  42406. // The offset fields are 0-based, but we use 1-based indices when
  42407. // encoding/decoding from VLQ.
  42408. generatedLine: offsetLine + 1,
  42409. generatedColumn: offsetColumn + 1
  42410. },
  42411. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  42412. }
  42413. });
  42414. }
  42415. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42416. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  42417. /**
  42418. * The version of the source mapping spec that we are consuming.
  42419. */
  42420. IndexedSourceMapConsumer.prototype._version = 3;
  42421. /**
  42422. * The list of original sources.
  42423. */
  42424. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  42425. get: function () {
  42426. var sources = [];
  42427. for (var i = 0; i < this._sections.length; i++) {
  42428. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  42429. sources.push(this._sections[i].consumer.sources[j]);
  42430. }
  42431. }
  42432. return sources;
  42433. }
  42434. });
  42435. /**
  42436. * Returns the original source, line, and column information for the generated
  42437. * source's line and column positions provided. The only argument is an object
  42438. * with the following properties:
  42439. *
  42440. * - line: The line number in the generated source. The line number
  42441. * is 1-based.
  42442. * - column: The column number in the generated source. The column
  42443. * number is 0-based.
  42444. *
  42445. * and an object is returned with the following properties:
  42446. *
  42447. * - source: The original source file, or null.
  42448. * - line: The line number in the original source, or null. The
  42449. * line number is 1-based.
  42450. * - column: The column number in the original source, or null. The
  42451. * column number is 0-based.
  42452. * - name: The original identifier, or null.
  42453. */
  42454. IndexedSourceMapConsumer.prototype.originalPositionFor =
  42455. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  42456. var needle = {
  42457. generatedLine: util.getArg(aArgs, 'line'),
  42458. generatedColumn: util.getArg(aArgs, 'column')
  42459. };
  42460. // Find the section containing the generated position we're trying to map
  42461. // to an original position.
  42462. var sectionIndex = binarySearch.search(needle, this._sections,
  42463. function(needle, section) {
  42464. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  42465. if (cmp) {
  42466. return cmp;
  42467. }
  42468. return (needle.generatedColumn -
  42469. section.generatedOffset.generatedColumn);
  42470. });
  42471. var section = this._sections[sectionIndex];
  42472. if (!section) {
  42473. return {
  42474. source: null,
  42475. line: null,
  42476. column: null,
  42477. name: null
  42478. };
  42479. }
  42480. return section.consumer.originalPositionFor({
  42481. line: needle.generatedLine -
  42482. (section.generatedOffset.generatedLine - 1),
  42483. column: needle.generatedColumn -
  42484. (section.generatedOffset.generatedLine === needle.generatedLine
  42485. ? section.generatedOffset.generatedColumn - 1
  42486. : 0),
  42487. bias: aArgs.bias
  42488. });
  42489. };
  42490. /**
  42491. * Return true if we have the source content for every source in the source
  42492. * map, false otherwise.
  42493. */
  42494. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  42495. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  42496. return this._sections.every(function (s) {
  42497. return s.consumer.hasContentsOfAllSources();
  42498. });
  42499. };
  42500. /**
  42501. * Returns the original source content. The only argument is the url of the
  42502. * original source file. Returns null if no original source content is
  42503. * available.
  42504. */
  42505. IndexedSourceMapConsumer.prototype.sourceContentFor =
  42506. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42507. for (var i = 0; i < this._sections.length; i++) {
  42508. var section = this._sections[i];
  42509. var content = section.consumer.sourceContentFor(aSource, true);
  42510. if (content) {
  42511. return content;
  42512. }
  42513. }
  42514. if (nullOnMissing) {
  42515. return null;
  42516. }
  42517. else {
  42518. throw new Error('"' + aSource + '" is not in the SourceMap.');
  42519. }
  42520. };
  42521. /**
  42522. * Returns the generated line and column information for the original source,
  42523. * line, and column positions provided. The only argument is an object with
  42524. * the following properties:
  42525. *
  42526. * - source: The filename of the original source.
  42527. * - line: The line number in the original source. The line number
  42528. * is 1-based.
  42529. * - column: The column number in the original source. The column
  42530. * number is 0-based.
  42531. *
  42532. * and an object is returned with the following properties:
  42533. *
  42534. * - line: The line number in the generated source, or null. The
  42535. * line number is 1-based.
  42536. * - column: The column number in the generated source, or null.
  42537. * The column number is 0-based.
  42538. */
  42539. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  42540. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  42541. for (var i = 0; i < this._sections.length; i++) {
  42542. var section = this._sections[i];
  42543. // Only consider this section if the requested source is in the list of
  42544. // sources of the consumer.
  42545. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  42546. continue;
  42547. }
  42548. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  42549. if (generatedPosition) {
  42550. var ret = {
  42551. line: generatedPosition.line +
  42552. (section.generatedOffset.generatedLine - 1),
  42553. column: generatedPosition.column +
  42554. (section.generatedOffset.generatedLine === generatedPosition.line
  42555. ? section.generatedOffset.generatedColumn - 1
  42556. : 0)
  42557. };
  42558. return ret;
  42559. }
  42560. }
  42561. return {
  42562. line: null,
  42563. column: null
  42564. };
  42565. };
  42566. /**
  42567. * Parse the mappings in a string in to a data structure which we can easily
  42568. * query (the ordered arrays in the `this.__generatedMappings` and
  42569. * `this.__originalMappings` properties).
  42570. */
  42571. IndexedSourceMapConsumer.prototype._parseMappings =
  42572. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42573. this.__generatedMappings = [];
  42574. this.__originalMappings = [];
  42575. for (var i = 0; i < this._sections.length; i++) {
  42576. var section = this._sections[i];
  42577. var sectionMappings = section.consumer._generatedMappings;
  42578. for (var j = 0; j < sectionMappings.length; j++) {
  42579. var mapping = sectionMappings[j];
  42580. var source = section.consumer._sources.at(mapping.source);
  42581. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42582. this._sources.add(source);
  42583. source = this._sources.indexOf(source);
  42584. var name = null;
  42585. if (mapping.name) {
  42586. name = section.consumer._names.at(mapping.name);
  42587. this._names.add(name);
  42588. name = this._names.indexOf(name);
  42589. }
  42590. // The mappings coming from the consumer for the section have
  42591. // generated positions relative to the start of the section, so we
  42592. // need to offset them to be relative to the start of the concatenated
  42593. // generated file.
  42594. var adjustedMapping = {
  42595. source: source,
  42596. generatedLine: mapping.generatedLine +
  42597. (section.generatedOffset.generatedLine - 1),
  42598. generatedColumn: mapping.generatedColumn +
  42599. (section.generatedOffset.generatedLine === mapping.generatedLine
  42600. ? section.generatedOffset.generatedColumn - 1
  42601. : 0),
  42602. originalLine: mapping.originalLine,
  42603. originalColumn: mapping.originalColumn,
  42604. name: name
  42605. };
  42606. this.__generatedMappings.push(adjustedMapping);
  42607. if (typeof adjustedMapping.originalLine === 'number') {
  42608. this.__originalMappings.push(adjustedMapping);
  42609. }
  42610. }
  42611. }
  42612. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  42613. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  42614. };
  42615. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42616. return sourceMapConsumer;
  42617. }
  42618. var sourceNode = {};
  42619. /* -*- Mode: js; js-indent-level: 2; -*- */
  42620. var hasRequiredSourceNode;
  42621. function requireSourceNode () {
  42622. if (hasRequiredSourceNode) return sourceNode;
  42623. hasRequiredSourceNode = 1;
  42624. /*
  42625. * Copyright 2011 Mozilla Foundation and contributors
  42626. * Licensed under the New BSD license. See LICENSE or:
  42627. * http://opensource.org/licenses/BSD-3-Clause
  42628. */
  42629. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  42630. var util = /*@__PURE__*/ requireUtil();
  42631. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42632. // operating systems these days (capturing the result).
  42633. var REGEX_NEWLINE = /(\r?\n)/;
  42634. // Newline character code for charCodeAt() comparisons
  42635. var NEWLINE_CODE = 10;
  42636. // Private symbol for identifying `SourceNode`s when multiple versions of
  42637. // the source-map library are loaded. This MUST NOT CHANGE across
  42638. // versions!
  42639. var isSourceNode = "$$$isSourceNode$$$";
  42640. /**
  42641. * SourceNodes provide a way to abstract over interpolating/concatenating
  42642. * snippets of generated JavaScript source code while maintaining the line and
  42643. * column information associated with the original source code.
  42644. *
  42645. * @param aLine The original line number.
  42646. * @param aColumn The original column number.
  42647. * @param aSource The original source's filename.
  42648. * @param aChunks Optional. An array of strings which are snippets of
  42649. * generated JS, or other SourceNodes.
  42650. * @param aName The original identifier.
  42651. */
  42652. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42653. this.children = [];
  42654. this.sourceContents = {};
  42655. this.line = aLine == null ? null : aLine;
  42656. this.column = aColumn == null ? null : aColumn;
  42657. this.source = aSource == null ? null : aSource;
  42658. this.name = aName == null ? null : aName;
  42659. this[isSourceNode] = true;
  42660. if (aChunks != null) this.add(aChunks);
  42661. }
  42662. /**
  42663. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42664. *
  42665. * @param aGeneratedCode The generated code
  42666. * @param aSourceMapConsumer The SourceMap for the generated code
  42667. * @param aRelativePath Optional. The path that relative sources in the
  42668. * SourceMapConsumer should be relative to.
  42669. */
  42670. SourceNode.fromStringWithSourceMap =
  42671. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42672. // The SourceNode we want to fill with the generated code
  42673. // and the SourceMap
  42674. var node = new SourceNode();
  42675. // All even indices of this array are one line of the generated code,
  42676. // while all odd indices are the newlines between two adjacent lines
  42677. // (since `REGEX_NEWLINE` captures its match).
  42678. // Processed fragments are accessed by calling `shiftNextLine`.
  42679. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  42680. var remainingLinesIndex = 0;
  42681. var shiftNextLine = function() {
  42682. var lineContents = getNextLine();
  42683. // The last line of a file might not have a newline.
  42684. var newLine = getNextLine() || "";
  42685. return lineContents + newLine;
  42686. function getNextLine() {
  42687. return remainingLinesIndex < remainingLines.length ?
  42688. remainingLines[remainingLinesIndex++] : undefined;
  42689. }
  42690. };
  42691. // We need to remember the position of "remainingLines"
  42692. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  42693. // The generate SourceNodes we need a code range.
  42694. // To extract it current and last mapping is used.
  42695. // Here we store the last mapping.
  42696. var lastMapping = null;
  42697. aSourceMapConsumer.eachMapping(function (mapping) {
  42698. if (lastMapping !== null) {
  42699. // We add the code from "lastMapping" to "mapping":
  42700. // First check if there is a new line in between.
  42701. if (lastGeneratedLine < mapping.generatedLine) {
  42702. // Associate first line with "lastMapping"
  42703. addMappingWithCode(lastMapping, shiftNextLine());
  42704. lastGeneratedLine++;
  42705. lastGeneratedColumn = 0;
  42706. // The remaining code is added without mapping
  42707. } else {
  42708. // There is no new line in between.
  42709. // Associate the code between "lastGeneratedColumn" and
  42710. // "mapping.generatedColumn" with "lastMapping"
  42711. var nextLine = remainingLines[remainingLinesIndex] || '';
  42712. var code = nextLine.substr(0, mapping.generatedColumn -
  42713. lastGeneratedColumn);
  42714. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  42715. lastGeneratedColumn);
  42716. lastGeneratedColumn = mapping.generatedColumn;
  42717. addMappingWithCode(lastMapping, code);
  42718. // No more remaining code, continue
  42719. lastMapping = mapping;
  42720. return;
  42721. }
  42722. }
  42723. // We add the generated code until the first mapping
  42724. // to the SourceNode without any mapping.
  42725. // Each line is added as separate string.
  42726. while (lastGeneratedLine < mapping.generatedLine) {
  42727. node.add(shiftNextLine());
  42728. lastGeneratedLine++;
  42729. }
  42730. if (lastGeneratedColumn < mapping.generatedColumn) {
  42731. var nextLine = remainingLines[remainingLinesIndex] || '';
  42732. node.add(nextLine.substr(0, mapping.generatedColumn));
  42733. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  42734. lastGeneratedColumn = mapping.generatedColumn;
  42735. }
  42736. lastMapping = mapping;
  42737. }, this);
  42738. // We have processed all mappings.
  42739. if (remainingLinesIndex < remainingLines.length) {
  42740. if (lastMapping) {
  42741. // Associate the remaining code in the current line with "lastMapping"
  42742. addMappingWithCode(lastMapping, shiftNextLine());
  42743. }
  42744. // and add the remaining lines without any mapping
  42745. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  42746. }
  42747. // Copy sourcesContent into SourceNode
  42748. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  42749. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  42750. if (content != null) {
  42751. if (aRelativePath != null) {
  42752. sourceFile = util.join(aRelativePath, sourceFile);
  42753. }
  42754. node.setSourceContent(sourceFile, content);
  42755. }
  42756. });
  42757. return node;
  42758. function addMappingWithCode(mapping, code) {
  42759. if (mapping === null || mapping.source === undefined) {
  42760. node.add(code);
  42761. } else {
  42762. var source = aRelativePath
  42763. ? util.join(aRelativePath, mapping.source)
  42764. : mapping.source;
  42765. node.add(new SourceNode(mapping.originalLine,
  42766. mapping.originalColumn,
  42767. source,
  42768. code,
  42769. mapping.name));
  42770. }
  42771. }
  42772. };
  42773. /**
  42774. * Add a chunk of generated JS to this source node.
  42775. *
  42776. * @param aChunk A string snippet of generated JS code, another instance of
  42777. * SourceNode, or an array where each member is one of those things.
  42778. */
  42779. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  42780. if (Array.isArray(aChunk)) {
  42781. aChunk.forEach(function (chunk) {
  42782. this.add(chunk);
  42783. }, this);
  42784. }
  42785. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42786. if (aChunk) {
  42787. this.children.push(aChunk);
  42788. }
  42789. }
  42790. else {
  42791. throw new TypeError(
  42792. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42793. );
  42794. }
  42795. return this;
  42796. };
  42797. /**
  42798. * Add a chunk of generated JS to the beginning of this source node.
  42799. *
  42800. * @param aChunk A string snippet of generated JS code, another instance of
  42801. * SourceNode, or an array where each member is one of those things.
  42802. */
  42803. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  42804. if (Array.isArray(aChunk)) {
  42805. for (var i = aChunk.length-1; i >= 0; i--) {
  42806. this.prepend(aChunk[i]);
  42807. }
  42808. }
  42809. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42810. this.children.unshift(aChunk);
  42811. }
  42812. else {
  42813. throw new TypeError(
  42814. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42815. );
  42816. }
  42817. return this;
  42818. };
  42819. /**
  42820. * Walk over the tree of JS snippets in this node and its children. The
  42821. * walking function is called once for each snippet of JS and is passed that
  42822. * snippet and the its original associated source's line/column location.
  42823. *
  42824. * @param aFn The traversal function.
  42825. */
  42826. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  42827. var chunk;
  42828. for (var i = 0, len = this.children.length; i < len; i++) {
  42829. chunk = this.children[i];
  42830. if (chunk[isSourceNode]) {
  42831. chunk.walk(aFn);
  42832. }
  42833. else {
  42834. if (chunk !== '') {
  42835. aFn(chunk, { source: this.source,
  42836. line: this.line,
  42837. column: this.column,
  42838. name: this.name });
  42839. }
  42840. }
  42841. }
  42842. };
  42843. /**
  42844. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  42845. * each of `this.children`.
  42846. *
  42847. * @param aSep The separator.
  42848. */
  42849. SourceNode.prototype.join = function SourceNode_join(aSep) {
  42850. var newChildren;
  42851. var i;
  42852. var len = this.children.length;
  42853. if (len > 0) {
  42854. newChildren = [];
  42855. for (i = 0; i < len-1; i++) {
  42856. newChildren.push(this.children[i]);
  42857. newChildren.push(aSep);
  42858. }
  42859. newChildren.push(this.children[i]);
  42860. this.children = newChildren;
  42861. }
  42862. return this;
  42863. };
  42864. /**
  42865. * Call String.prototype.replace on the very right-most source snippet. Useful
  42866. * for trimming whitespace from the end of a source node, etc.
  42867. *
  42868. * @param aPattern The pattern to replace.
  42869. * @param aReplacement The thing to replace the pattern with.
  42870. */
  42871. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  42872. var lastChild = this.children[this.children.length - 1];
  42873. if (lastChild[isSourceNode]) {
  42874. lastChild.replaceRight(aPattern, aReplacement);
  42875. }
  42876. else if (typeof lastChild === 'string') {
  42877. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  42878. }
  42879. else {
  42880. this.children.push(''.replace(aPattern, aReplacement));
  42881. }
  42882. return this;
  42883. };
  42884. /**
  42885. * Set the source content for a source file. This will be added to the SourceMapGenerator
  42886. * in the sourcesContent field.
  42887. *
  42888. * @param aSourceFile The filename of the source file
  42889. * @param aSourceContent The content of the source file
  42890. */
  42891. SourceNode.prototype.setSourceContent =
  42892. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  42893. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  42894. };
  42895. /**
  42896. * Walk over the tree of SourceNodes. The walking function is called for each
  42897. * source file content and is passed the filename and source content.
  42898. *
  42899. * @param aFn The traversal function.
  42900. */
  42901. SourceNode.prototype.walkSourceContents =
  42902. function SourceNode_walkSourceContents(aFn) {
  42903. for (var i = 0, len = this.children.length; i < len; i++) {
  42904. if (this.children[i][isSourceNode]) {
  42905. this.children[i].walkSourceContents(aFn);
  42906. }
  42907. }
  42908. var sources = Object.keys(this.sourceContents);
  42909. for (var i = 0, len = sources.length; i < len; i++) {
  42910. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  42911. }
  42912. };
  42913. /**
  42914. * Return the string representation of this source node. Walks over the tree
  42915. * and concatenates all the various snippets together to one string.
  42916. */
  42917. SourceNode.prototype.toString = function SourceNode_toString() {
  42918. var str = "";
  42919. this.walk(function (chunk) {
  42920. str += chunk;
  42921. });
  42922. return str;
  42923. };
  42924. /**
  42925. * Returns the string representation of this source node along with a source
  42926. * map.
  42927. */
  42928. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  42929. var generated = {
  42930. code: "",
  42931. line: 1,
  42932. column: 0
  42933. };
  42934. var map = new SourceMapGenerator(aArgs);
  42935. var sourceMappingActive = false;
  42936. var lastOriginalSource = null;
  42937. var lastOriginalLine = null;
  42938. var lastOriginalColumn = null;
  42939. var lastOriginalName = null;
  42940. this.walk(function (chunk, original) {
  42941. generated.code += chunk;
  42942. if (original.source !== null
  42943. && original.line !== null
  42944. && original.column !== null) {
  42945. if(lastOriginalSource !== original.source
  42946. || lastOriginalLine !== original.line
  42947. || lastOriginalColumn !== original.column
  42948. || lastOriginalName !== original.name) {
  42949. map.addMapping({
  42950. source: original.source,
  42951. original: {
  42952. line: original.line,
  42953. column: original.column
  42954. },
  42955. generated: {
  42956. line: generated.line,
  42957. column: generated.column
  42958. },
  42959. name: original.name
  42960. });
  42961. }
  42962. lastOriginalSource = original.source;
  42963. lastOriginalLine = original.line;
  42964. lastOriginalColumn = original.column;
  42965. lastOriginalName = original.name;
  42966. sourceMappingActive = true;
  42967. } else if (sourceMappingActive) {
  42968. map.addMapping({
  42969. generated: {
  42970. line: generated.line,
  42971. column: generated.column
  42972. }
  42973. });
  42974. lastOriginalSource = null;
  42975. sourceMappingActive = false;
  42976. }
  42977. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  42978. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  42979. generated.line++;
  42980. generated.column = 0;
  42981. // Mappings end at eol
  42982. if (idx + 1 === length) {
  42983. lastOriginalSource = null;
  42984. sourceMappingActive = false;
  42985. } else if (sourceMappingActive) {
  42986. map.addMapping({
  42987. source: original.source,
  42988. original: {
  42989. line: original.line,
  42990. column: original.column
  42991. },
  42992. generated: {
  42993. line: generated.line,
  42994. column: generated.column
  42995. },
  42996. name: original.name
  42997. });
  42998. }
  42999. } else {
  43000. generated.column++;
  43001. }
  43002. }
  43003. });
  43004. this.walkSourceContents(function (sourceFile, sourceContent) {
  43005. map.setSourceContent(sourceFile, sourceContent);
  43006. });
  43007. return { code: generated.code, map: map };
  43008. };
  43009. sourceNode.SourceNode = SourceNode;
  43010. return sourceNode;
  43011. }
  43012. /*
  43013. * Copyright 2009-2011 Mozilla Foundation and contributors
  43014. * Licensed under the New BSD license. See LICENSE.txt or:
  43015. * http://opensource.org/licenses/BSD-3-Clause
  43016. */
  43017. var hasRequiredSourceMap;
  43018. function requireSourceMap () {
  43019. if (hasRequiredSourceMap) return sourceMap;
  43020. hasRequiredSourceMap = 1;
  43021. sourceMap.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  43022. sourceMap.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer().SourceMapConsumer;
  43023. sourceMap.SourceNode = /*@__PURE__*/ requireSourceNode().SourceNode;
  43024. return sourceMap;
  43025. }
  43026. var mergeSourceMap;
  43027. var hasRequiredMergeSourceMap;
  43028. function requireMergeSourceMap () {
  43029. if (hasRequiredMergeSourceMap) return mergeSourceMap;
  43030. hasRequiredMergeSourceMap = 1;
  43031. var sourceMap = /*@__PURE__*/ requireSourceMap();
  43032. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  43033. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  43034. mergeSourceMap = merge;
  43035. /**
  43036. * Merge old source map and new source map and return merged.
  43037. * If old or new source map value is falsy, return another one as it is.
  43038. *
  43039. * @param {object|string} [oldMap] old source map object
  43040. * @param {object|string} [newmap] new source map object
  43041. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  43042. */
  43043. function merge(oldMap, newMap) {
  43044. if (!oldMap) return newMap
  43045. if (!newMap) return oldMap
  43046. var oldMapConsumer = new SourceMapConsumer(oldMap);
  43047. var newMapConsumer = new SourceMapConsumer(newMap);
  43048. var mergedMapGenerator = new SourceMapGenerator();
  43049. // iterate on new map and overwrite original position of new map with one of old map
  43050. newMapConsumer.eachMapping(function(m) {
  43051. // pass when `originalLine` is null.
  43052. // It occurs in case that the node does not have origin in original code.
  43053. if (m.originalLine == null) return
  43054. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  43055. line: m.originalLine,
  43056. column: m.originalColumn
  43057. });
  43058. if (origPosInOldMap.source == null) return
  43059. mergedMapGenerator.addMapping({
  43060. original: {
  43061. line: origPosInOldMap.line,
  43062. column: origPosInOldMap.column
  43063. },
  43064. generated: {
  43065. line: m.generatedLine,
  43066. column: m.generatedColumn
  43067. },
  43068. source: origPosInOldMap.source,
  43069. name: origPosInOldMap.name
  43070. });
  43071. });
  43072. var consumers = [oldMapConsumer, newMapConsumer];
  43073. consumers.forEach(function(consumer) {
  43074. consumer.sources.forEach(function(sourceFile) {
  43075. mergedMapGenerator._sources.add(sourceFile);
  43076. var sourceContent = consumer.sourceContentFor(sourceFile);
  43077. if (sourceContent != null) {
  43078. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  43079. }
  43080. });
  43081. });
  43082. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  43083. mergedMapGenerator._file = oldMap.file;
  43084. return JSON.parse(mergedMapGenerator.toString())
  43085. }
  43086. return mergeSourceMap;
  43087. }
  43088. var mergeSourceMapExports = /*@__PURE__*/ requireMergeSourceMap();
  43089. var merge = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMapExports);
  43090. var __defProp$5 = Object.defineProperty;
  43091. var __defProps$4 = Object.defineProperties;
  43092. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  43093. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  43094. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  43095. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  43096. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43097. var __spreadValues$5 = (a, b) => {
  43098. for (var prop in b || (b = {}))
  43099. if (__hasOwnProp$5.call(b, prop))
  43100. __defNormalProp$5(a, prop, b[prop]);
  43101. if (__getOwnPropSymbols$5)
  43102. for (var prop of __getOwnPropSymbols$5(b)) {
  43103. if (__propIsEnum$5.call(b, prop))
  43104. __defNormalProp$5(a, prop, b[prop]);
  43105. }
  43106. return a;
  43107. };
  43108. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  43109. const scss = (source, map, options, load = require) => {
  43110. const nodeSass = load("sass");
  43111. const { compileString, renderSync } = nodeSass;
  43112. const data = getSource(source, options.filename, options.additionalData);
  43113. let css;
  43114. let dependencies;
  43115. let sourceMap;
  43116. try {
  43117. if (compileString) {
  43118. const { pathToFileURL, fileURLToPath } = load("url");
  43119. const result = compileString(data, __spreadProps$4(__spreadValues$5({}, options), {
  43120. url: pathToFileURL(options.filename),
  43121. sourceMap: !!map
  43122. }));
  43123. css = result.css;
  43124. dependencies = result.loadedUrls.map((url) => fileURLToPath(url));
  43125. sourceMap = map ? result.sourceMap : void 0;
  43126. } else {
  43127. const result = renderSync(__spreadProps$4(__spreadValues$5({}, options), {
  43128. data,
  43129. file: options.filename,
  43130. outFile: options.filename,
  43131. sourceMap: !!map
  43132. }));
  43133. css = result.css.toString();
  43134. dependencies = result.stats.includedFiles;
  43135. sourceMap = map ? JSON.parse(result.map.toString()) : void 0;
  43136. }
  43137. if (map) {
  43138. return {
  43139. code: css,
  43140. errors: [],
  43141. dependencies,
  43142. map: merge(map, sourceMap)
  43143. };
  43144. }
  43145. return { code: css, errors: [], dependencies };
  43146. } catch (e) {
  43147. return { code: "", errors: [e], dependencies: [] };
  43148. }
  43149. };
  43150. const sass = (source, map, options, load) => scss(
  43151. source,
  43152. map,
  43153. __spreadProps$4(__spreadValues$5({}, options), {
  43154. indentedSyntax: true
  43155. }),
  43156. load
  43157. );
  43158. const less = (source, map, options, load = require) => {
  43159. const nodeLess = load("less");
  43160. let result;
  43161. let error = null;
  43162. nodeLess.render(
  43163. getSource(source, options.filename, options.additionalData),
  43164. __spreadProps$4(__spreadValues$5({}, options), { syncImport: true }),
  43165. (err, output) => {
  43166. error = err;
  43167. result = output;
  43168. }
  43169. );
  43170. if (error) return { code: "", errors: [error], dependencies: [] };
  43171. const dependencies = result.imports;
  43172. if (map) {
  43173. return {
  43174. code: result.css.toString(),
  43175. map: merge(map, result.map),
  43176. errors: [],
  43177. dependencies
  43178. };
  43179. }
  43180. return {
  43181. code: result.css.toString(),
  43182. errors: [],
  43183. dependencies
  43184. };
  43185. };
  43186. const styl = (source, map, options, load = require) => {
  43187. const nodeStylus = load("stylus");
  43188. try {
  43189. const ref = nodeStylus(source, options);
  43190. if (map) ref.set("sourcemap", { inline: false, comment: false });
  43191. const result = ref.render();
  43192. const dependencies = ref.deps();
  43193. if (map) {
  43194. return {
  43195. code: result,
  43196. map: merge(map, ref.sourcemap),
  43197. errors: [],
  43198. dependencies
  43199. };
  43200. }
  43201. return { code: result, errors: [], dependencies };
  43202. } catch (e) {
  43203. return { code: "", errors: [e], dependencies: [] };
  43204. }
  43205. };
  43206. function getSource(source, filename, additionalData) {
  43207. if (!additionalData) return source;
  43208. if (isFunction$1(additionalData)) {
  43209. return additionalData(source, filename);
  43210. }
  43211. return additionalData + source;
  43212. }
  43213. const processors = {
  43214. less,
  43215. sass,
  43216. scss,
  43217. styl,
  43218. stylus: styl
  43219. };
  43220. var __defProp$4 = Object.defineProperty;
  43221. var __defProps$3 = Object.defineProperties;
  43222. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43223. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  43224. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  43225. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  43226. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43227. var __spreadValues$4 = (a, b) => {
  43228. for (var prop in b || (b = {}))
  43229. if (__hasOwnProp$4.call(b, prop))
  43230. __defNormalProp$4(a, prop, b[prop]);
  43231. if (__getOwnPropSymbols$4)
  43232. for (var prop of __getOwnPropSymbols$4(b)) {
  43233. if (__propIsEnum$4.call(b, prop))
  43234. __defNormalProp$4(a, prop, b[prop]);
  43235. }
  43236. return a;
  43237. };
  43238. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43239. function compileStyle(options) {
  43240. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43241. isAsync: false
  43242. }));
  43243. }
  43244. function compileStyleAsync(options) {
  43245. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43246. isAsync: true
  43247. }));
  43248. }
  43249. function doCompileStyle(options) {
  43250. const {
  43251. filename,
  43252. id,
  43253. scoped = false,
  43254. trim = true,
  43255. isProd = false,
  43256. modules = false,
  43257. modulesOptions = {},
  43258. preprocessLang,
  43259. postcssOptions,
  43260. postcssPlugins
  43261. } = options;
  43262. const preprocessor = preprocessLang && processors[preprocessLang];
  43263. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  43264. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  43265. const source = preProcessedSource ? preProcessedSource.code : options.source;
  43266. const shortId = id.replace(/^data-v-/, "");
  43267. const longId = `data-v-${shortId}`;
  43268. const plugins = (postcssPlugins || []).slice();
  43269. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  43270. if (trim) {
  43271. plugins.push(trimPlugin());
  43272. }
  43273. if (scoped) {
  43274. plugins.push(scopedPlugin(longId));
  43275. }
  43276. let cssModules;
  43277. if (modules) {
  43278. {
  43279. throw new Error(
  43280. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  43281. );
  43282. }
  43283. }
  43284. const postCSSOptions = __spreadProps$3(__spreadValues$4({}, postcssOptions), {
  43285. to: filename,
  43286. from: filename
  43287. });
  43288. if (map) {
  43289. postCSSOptions.map = {
  43290. inline: false,
  43291. annotation: false,
  43292. prev: map
  43293. };
  43294. }
  43295. let result;
  43296. let code;
  43297. let outMap;
  43298. const dependencies = new Set(
  43299. preProcessedSource ? preProcessedSource.dependencies : []
  43300. );
  43301. dependencies.delete(filename);
  43302. const errors = [];
  43303. if (preProcessedSource && preProcessedSource.errors.length) {
  43304. errors.push(...preProcessedSource.errors);
  43305. }
  43306. const recordPlainCssDependencies = (messages) => {
  43307. messages.forEach((msg) => {
  43308. if (msg.type === "dependency") {
  43309. dependencies.add(msg.file);
  43310. }
  43311. });
  43312. return dependencies;
  43313. };
  43314. try {
  43315. result = postcss(plugins).process(source, postCSSOptions);
  43316. if (options.isAsync) {
  43317. return result.then((result2) => ({
  43318. code: result2.css || "",
  43319. map: result2.map && result2.map.toJSON(),
  43320. errors,
  43321. modules: cssModules,
  43322. rawResult: result2,
  43323. dependencies: recordPlainCssDependencies(result2.messages)
  43324. })).catch((error) => ({
  43325. code: "",
  43326. map: void 0,
  43327. errors: [...errors, error],
  43328. rawResult: void 0,
  43329. dependencies
  43330. }));
  43331. }
  43332. recordPlainCssDependencies(result.messages);
  43333. code = result.css;
  43334. outMap = result.map;
  43335. } catch (e) {
  43336. errors.push(e);
  43337. }
  43338. return {
  43339. code: code || ``,
  43340. map: outMap && outMap.toJSON(),
  43341. errors,
  43342. rawResult: result,
  43343. dependencies
  43344. };
  43345. }
  43346. function preprocess(options, preprocessor) {
  43347. if (!options.preprocessCustomRequire) {
  43348. throw new Error(
  43349. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  43350. );
  43351. }
  43352. return preprocessor(
  43353. options.source,
  43354. options.inMap || options.map,
  43355. __spreadValues$4({
  43356. filename: options.filename
  43357. }, options.preprocessOptions),
  43358. options.preprocessCustomRequire
  43359. );
  43360. }
  43361. const UNKNOWN_TYPE = "Unknown";
  43362. function resolveObjectKey(node, computed) {
  43363. switch (node.type) {
  43364. case "StringLiteral":
  43365. case "NumericLiteral":
  43366. return String(node.value);
  43367. case "Identifier":
  43368. if (!computed) return node.name;
  43369. }
  43370. return void 0;
  43371. }
  43372. function concatStrings(strs) {
  43373. return strs.filter((s) => !!s).join(", ");
  43374. }
  43375. function isLiteralNode(node) {
  43376. return node.type.endsWith("Literal");
  43377. }
  43378. function isCallOf(node, test) {
  43379. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  43380. }
  43381. function toRuntimeTypeString(types) {
  43382. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  43383. }
  43384. function getImportedName(specifier) {
  43385. if (specifier.type === "ImportSpecifier")
  43386. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  43387. else if (specifier.type === "ImportNamespaceSpecifier") return "*";
  43388. return "default";
  43389. }
  43390. function getId(node) {
  43391. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  43392. }
  43393. const normalize = (path.posix || path).normalize;
  43394. const windowsSlashRE = /\\/g;
  43395. function normalizePath(p) {
  43396. return normalize(p.replace(windowsSlashRE, "/"));
  43397. }
  43398. const joinPaths = (path.posix || path).join;
  43399. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  43400. function getEscapedPropName(key) {
  43401. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  43402. }
  43403. function analyzeScriptBindings(ast) {
  43404. for (const node of ast) {
  43405. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  43406. return analyzeBindingsFromOptions(node.declaration);
  43407. }
  43408. }
  43409. return {};
  43410. }
  43411. function analyzeBindingsFromOptions(node) {
  43412. const bindings = {};
  43413. Object.defineProperty(bindings, "__isScriptSetup", {
  43414. enumerable: false,
  43415. value: false
  43416. });
  43417. for (const property of node.properties) {
  43418. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  43419. if (property.key.name === "props") {
  43420. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43421. bindings[key] = "props";
  43422. }
  43423. } else if (property.key.name === "inject") {
  43424. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43425. bindings[key] = "options";
  43426. }
  43427. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  43428. for (const key of getObjectExpressionKeys(property.value)) {
  43429. bindings[key] = "options";
  43430. }
  43431. }
  43432. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  43433. for (const bodyItem of property.body.body) {
  43434. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  43435. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  43436. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  43437. }
  43438. }
  43439. }
  43440. }
  43441. }
  43442. return bindings;
  43443. }
  43444. function getObjectExpressionKeys(node) {
  43445. const keys = [];
  43446. for (const prop of node.properties) {
  43447. if (prop.type === "SpreadElement") continue;
  43448. const key = resolveObjectKey(prop.key, prop.computed);
  43449. if (key) keys.push(String(key));
  43450. }
  43451. return keys;
  43452. }
  43453. function getArrayExpressionKeys(node) {
  43454. const keys = [];
  43455. for (const element of node.elements) {
  43456. if (element && element.type === "StringLiteral") {
  43457. keys.push(element.value);
  43458. }
  43459. }
  43460. return keys;
  43461. }
  43462. function getObjectOrArrayExpressionKeys(value) {
  43463. if (value.type === "ArrayExpression") {
  43464. return getArrayExpressionKeys(value);
  43465. }
  43466. if (value.type === "ObjectExpression") {
  43467. return getObjectExpressionKeys(value);
  43468. }
  43469. return [];
  43470. }
  43471. const comma = ','.charCodeAt(0);
  43472. const semicolon = ';'.charCodeAt(0);
  43473. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  43474. const intToChar = new Uint8Array(64); // 64 possible chars.
  43475. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  43476. for (let i = 0; i < chars.length; i++) {
  43477. const c = chars.charCodeAt(i);
  43478. intToChar[i] = c;
  43479. charToInt[c] = i;
  43480. }
  43481. function encodeInteger(builder, num, relative) {
  43482. let delta = num - relative;
  43483. delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
  43484. do {
  43485. let clamped = delta & 0b011111;
  43486. delta >>>= 5;
  43487. if (delta > 0)
  43488. clamped |= 0b100000;
  43489. builder.write(intToChar[clamped]);
  43490. } while (delta > 0);
  43491. return num;
  43492. }
  43493. const bufLength = 1024 * 16;
  43494. // Provide a fallback for older environments.
  43495. const td = typeof TextDecoder !== 'undefined'
  43496. ? /* #__PURE__ */ new TextDecoder()
  43497. : typeof Buffer !== 'undefined'
  43498. ? {
  43499. decode(buf) {
  43500. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  43501. return out.toString();
  43502. },
  43503. }
  43504. : {
  43505. decode(buf) {
  43506. let out = '';
  43507. for (let i = 0; i < buf.length; i++) {
  43508. out += String.fromCharCode(buf[i]);
  43509. }
  43510. return out;
  43511. },
  43512. };
  43513. class StringWriter {
  43514. constructor() {
  43515. this.pos = 0;
  43516. this.out = '';
  43517. this.buffer = new Uint8Array(bufLength);
  43518. }
  43519. write(v) {
  43520. const { buffer } = this;
  43521. buffer[this.pos++] = v;
  43522. if (this.pos === bufLength) {
  43523. this.out += td.decode(buffer);
  43524. this.pos = 0;
  43525. }
  43526. }
  43527. flush() {
  43528. const { buffer, out, pos } = this;
  43529. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  43530. }
  43531. }
  43532. function encode(decoded) {
  43533. const writer = new StringWriter();
  43534. let sourcesIndex = 0;
  43535. let sourceLine = 0;
  43536. let sourceColumn = 0;
  43537. let namesIndex = 0;
  43538. for (let i = 0; i < decoded.length; i++) {
  43539. const line = decoded[i];
  43540. if (i > 0)
  43541. writer.write(semicolon);
  43542. if (line.length === 0)
  43543. continue;
  43544. let genColumn = 0;
  43545. for (let j = 0; j < line.length; j++) {
  43546. const segment = line[j];
  43547. if (j > 0)
  43548. writer.write(comma);
  43549. genColumn = encodeInteger(writer, segment[0], genColumn);
  43550. if (segment.length === 1)
  43551. continue;
  43552. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  43553. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  43554. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  43555. if (segment.length === 4)
  43556. continue;
  43557. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  43558. }
  43559. }
  43560. return writer.flush();
  43561. }
  43562. class BitSet {
  43563. constructor(arg) {
  43564. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  43565. }
  43566. add(n) {
  43567. this.bits[n >> 5] |= 1 << (n & 31);
  43568. }
  43569. has(n) {
  43570. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  43571. }
  43572. }
  43573. class Chunk {
  43574. constructor(start, end, content) {
  43575. this.start = start;
  43576. this.end = end;
  43577. this.original = content;
  43578. this.intro = '';
  43579. this.outro = '';
  43580. this.content = content;
  43581. this.storeName = false;
  43582. this.edited = false;
  43583. {
  43584. this.previous = null;
  43585. this.next = null;
  43586. }
  43587. }
  43588. appendLeft(content) {
  43589. this.outro += content;
  43590. }
  43591. appendRight(content) {
  43592. this.intro = this.intro + content;
  43593. }
  43594. clone() {
  43595. const chunk = new Chunk(this.start, this.end, this.original);
  43596. chunk.intro = this.intro;
  43597. chunk.outro = this.outro;
  43598. chunk.content = this.content;
  43599. chunk.storeName = this.storeName;
  43600. chunk.edited = this.edited;
  43601. return chunk;
  43602. }
  43603. contains(index) {
  43604. return this.start < index && index < this.end;
  43605. }
  43606. eachNext(fn) {
  43607. let chunk = this;
  43608. while (chunk) {
  43609. fn(chunk);
  43610. chunk = chunk.next;
  43611. }
  43612. }
  43613. eachPrevious(fn) {
  43614. let chunk = this;
  43615. while (chunk) {
  43616. fn(chunk);
  43617. chunk = chunk.previous;
  43618. }
  43619. }
  43620. edit(content, storeName, contentOnly) {
  43621. this.content = content;
  43622. if (!contentOnly) {
  43623. this.intro = '';
  43624. this.outro = '';
  43625. }
  43626. this.storeName = storeName;
  43627. this.edited = true;
  43628. return this;
  43629. }
  43630. prependLeft(content) {
  43631. this.outro = content + this.outro;
  43632. }
  43633. prependRight(content) {
  43634. this.intro = content + this.intro;
  43635. }
  43636. reset() {
  43637. this.intro = '';
  43638. this.outro = '';
  43639. if (this.edited) {
  43640. this.content = this.original;
  43641. this.storeName = false;
  43642. this.edited = false;
  43643. }
  43644. }
  43645. split(index) {
  43646. const sliceIndex = index - this.start;
  43647. const originalBefore = this.original.slice(0, sliceIndex);
  43648. const originalAfter = this.original.slice(sliceIndex);
  43649. this.original = originalBefore;
  43650. const newChunk = new Chunk(index, this.end, originalAfter);
  43651. newChunk.outro = this.outro;
  43652. this.outro = '';
  43653. this.end = index;
  43654. if (this.edited) {
  43655. // after split we should save the edit content record into the correct chunk
  43656. // to make sure sourcemap correct
  43657. // For example:
  43658. // ' test'.trim()
  43659. // split -> ' ' + 'test'
  43660. // ✔️ edit -> '' + 'test'
  43661. // ✖️ edit -> 'test' + ''
  43662. // TODO is this block necessary?...
  43663. newChunk.edit('', false);
  43664. this.content = '';
  43665. } else {
  43666. this.content = originalBefore;
  43667. }
  43668. newChunk.next = this.next;
  43669. if (newChunk.next) newChunk.next.previous = newChunk;
  43670. newChunk.previous = this;
  43671. this.next = newChunk;
  43672. return newChunk;
  43673. }
  43674. toString() {
  43675. return this.intro + this.content + this.outro;
  43676. }
  43677. trimEnd(rx) {
  43678. this.outro = this.outro.replace(rx, '');
  43679. if (this.outro.length) return true;
  43680. const trimmed = this.content.replace(rx, '');
  43681. if (trimmed.length) {
  43682. if (trimmed !== this.content) {
  43683. this.split(this.start + trimmed.length).edit('', undefined, true);
  43684. if (this.edited) {
  43685. // save the change, if it has been edited
  43686. this.edit(trimmed, this.storeName, true);
  43687. }
  43688. }
  43689. return true;
  43690. } else {
  43691. this.edit('', undefined, true);
  43692. this.intro = this.intro.replace(rx, '');
  43693. if (this.intro.length) return true;
  43694. }
  43695. }
  43696. trimStart(rx) {
  43697. this.intro = this.intro.replace(rx, '');
  43698. if (this.intro.length) return true;
  43699. const trimmed = this.content.replace(rx, '');
  43700. if (trimmed.length) {
  43701. if (trimmed !== this.content) {
  43702. const newChunk = this.split(this.end - trimmed.length);
  43703. if (this.edited) {
  43704. // save the change, if it has been edited
  43705. newChunk.edit(trimmed, this.storeName, true);
  43706. }
  43707. this.edit('', undefined, true);
  43708. }
  43709. return true;
  43710. } else {
  43711. this.edit('', undefined, true);
  43712. this.outro = this.outro.replace(rx, '');
  43713. if (this.outro.length) return true;
  43714. }
  43715. }
  43716. }
  43717. function getBtoa() {
  43718. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  43719. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  43720. } else if (typeof Buffer === 'function') {
  43721. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  43722. } else {
  43723. return () => {
  43724. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  43725. };
  43726. }
  43727. }
  43728. const btoa = /*#__PURE__*/ getBtoa();
  43729. class SourceMap {
  43730. constructor(properties) {
  43731. this.version = 3;
  43732. this.file = properties.file;
  43733. this.sources = properties.sources;
  43734. this.sourcesContent = properties.sourcesContent;
  43735. this.names = properties.names;
  43736. this.mappings = encode(properties.mappings);
  43737. if (typeof properties.x_google_ignoreList !== 'undefined') {
  43738. this.x_google_ignoreList = properties.x_google_ignoreList;
  43739. }
  43740. if (typeof properties.debugId !== 'undefined') {
  43741. this.debugId = properties.debugId;
  43742. }
  43743. }
  43744. toString() {
  43745. return JSON.stringify(this);
  43746. }
  43747. toUrl() {
  43748. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  43749. }
  43750. }
  43751. function guessIndent(code) {
  43752. const lines = code.split('\n');
  43753. const tabbed = lines.filter((line) => /^\t+/.test(line));
  43754. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  43755. if (tabbed.length === 0 && spaced.length === 0) {
  43756. return null;
  43757. }
  43758. // More lines tabbed than spaced? Assume tabs, and
  43759. // default to tabs in the case of a tie (or nothing
  43760. // to go on)
  43761. if (tabbed.length >= spaced.length) {
  43762. return '\t';
  43763. }
  43764. // Otherwise, we need to guess the multiple
  43765. const min = spaced.reduce((previous, current) => {
  43766. const numSpaces = /^ +/.exec(current)[0].length;
  43767. return Math.min(numSpaces, previous);
  43768. }, Infinity);
  43769. return new Array(min + 1).join(' ');
  43770. }
  43771. function getRelativePath(from, to) {
  43772. const fromParts = from.split(/[/\\]/);
  43773. const toParts = to.split(/[/\\]/);
  43774. fromParts.pop(); // get dirname
  43775. while (fromParts[0] === toParts[0]) {
  43776. fromParts.shift();
  43777. toParts.shift();
  43778. }
  43779. if (fromParts.length) {
  43780. let i = fromParts.length;
  43781. while (i--) fromParts[i] = '..';
  43782. }
  43783. return fromParts.concat(toParts).join('/');
  43784. }
  43785. const toString = Object.prototype.toString;
  43786. function isObject(thing) {
  43787. return toString.call(thing) === '[object Object]';
  43788. }
  43789. function getLocator(source) {
  43790. const originalLines = source.split('\n');
  43791. const lineOffsets = [];
  43792. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  43793. lineOffsets.push(pos);
  43794. pos += originalLines[i].length + 1;
  43795. }
  43796. return function locate(index) {
  43797. let i = 0;
  43798. let j = lineOffsets.length;
  43799. while (i < j) {
  43800. const m = (i + j) >> 1;
  43801. if (index < lineOffsets[m]) {
  43802. j = m;
  43803. } else {
  43804. i = m + 1;
  43805. }
  43806. }
  43807. const line = i - 1;
  43808. const column = index - lineOffsets[line];
  43809. return { line, column };
  43810. };
  43811. }
  43812. const wordRegex = /\w/;
  43813. class Mappings {
  43814. constructor(hires) {
  43815. this.hires = hires;
  43816. this.generatedCodeLine = 0;
  43817. this.generatedCodeColumn = 0;
  43818. this.raw = [];
  43819. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  43820. this.pending = null;
  43821. }
  43822. addEdit(sourceIndex, content, loc, nameIndex) {
  43823. if (content.length) {
  43824. const contentLengthMinusOne = content.length - 1;
  43825. let contentLineEnd = content.indexOf('\n', 0);
  43826. let previousContentLineEnd = -1;
  43827. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  43828. // else code afterwards would fill one line too many
  43829. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  43830. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43831. if (nameIndex >= 0) {
  43832. segment.push(nameIndex);
  43833. }
  43834. this.rawSegments.push(segment);
  43835. this.generatedCodeLine += 1;
  43836. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43837. this.generatedCodeColumn = 0;
  43838. previousContentLineEnd = contentLineEnd;
  43839. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  43840. }
  43841. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43842. if (nameIndex >= 0) {
  43843. segment.push(nameIndex);
  43844. }
  43845. this.rawSegments.push(segment);
  43846. this.advance(content.slice(previousContentLineEnd + 1));
  43847. } else if (this.pending) {
  43848. this.rawSegments.push(this.pending);
  43849. this.advance(content);
  43850. }
  43851. this.pending = null;
  43852. }
  43853. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  43854. let originalCharIndex = chunk.start;
  43855. let first = true;
  43856. // when iterating each char, check if it's in a word boundary
  43857. let charInHiresBoundary = false;
  43858. while (originalCharIndex < chunk.end) {
  43859. if (original[originalCharIndex] === '\n') {
  43860. loc.line += 1;
  43861. loc.column = 0;
  43862. this.generatedCodeLine += 1;
  43863. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43864. this.generatedCodeColumn = 0;
  43865. first = true;
  43866. charInHiresBoundary = false;
  43867. } else {
  43868. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  43869. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43870. if (this.hires === 'boundary') {
  43871. // in hires "boundary", group segments per word boundary than per char
  43872. if (wordRegex.test(original[originalCharIndex])) {
  43873. // for first char in the boundary found, start the boundary by pushing a segment
  43874. if (!charInHiresBoundary) {
  43875. this.rawSegments.push(segment);
  43876. charInHiresBoundary = true;
  43877. }
  43878. } else {
  43879. // for non-word char, end the boundary by pushing a segment
  43880. this.rawSegments.push(segment);
  43881. charInHiresBoundary = false;
  43882. }
  43883. } else {
  43884. this.rawSegments.push(segment);
  43885. }
  43886. }
  43887. loc.column += 1;
  43888. this.generatedCodeColumn += 1;
  43889. first = false;
  43890. }
  43891. originalCharIndex += 1;
  43892. }
  43893. this.pending = null;
  43894. }
  43895. advance(str) {
  43896. if (!str) return;
  43897. const lines = str.split('\n');
  43898. if (lines.length > 1) {
  43899. for (let i = 0; i < lines.length - 1; i++) {
  43900. this.generatedCodeLine++;
  43901. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43902. }
  43903. this.generatedCodeColumn = 0;
  43904. }
  43905. this.generatedCodeColumn += lines[lines.length - 1].length;
  43906. }
  43907. }
  43908. const n = '\n';
  43909. const warned = {
  43910. insertLeft: false,
  43911. insertRight: false,
  43912. storeName: false,
  43913. };
  43914. class MagicString {
  43915. constructor(string, options = {}) {
  43916. const chunk = new Chunk(0, string.length, string);
  43917. Object.defineProperties(this, {
  43918. original: { writable: true, value: string },
  43919. outro: { writable: true, value: '' },
  43920. intro: { writable: true, value: '' },
  43921. firstChunk: { writable: true, value: chunk },
  43922. lastChunk: { writable: true, value: chunk },
  43923. lastSearchedChunk: { writable: true, value: chunk },
  43924. byStart: { writable: true, value: {} },
  43925. byEnd: { writable: true, value: {} },
  43926. filename: { writable: true, value: options.filename },
  43927. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  43928. sourcemapLocations: { writable: true, value: new BitSet() },
  43929. storedNames: { writable: true, value: {} },
  43930. indentStr: { writable: true, value: undefined },
  43931. ignoreList: { writable: true, value: options.ignoreList },
  43932. offset: { writable: true, value: options.offset || 0 },
  43933. });
  43934. this.byStart[0] = chunk;
  43935. this.byEnd[string.length] = chunk;
  43936. }
  43937. addSourcemapLocation(char) {
  43938. this.sourcemapLocations.add(char);
  43939. }
  43940. append(content) {
  43941. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  43942. this.outro += content;
  43943. return this;
  43944. }
  43945. appendLeft(index, content) {
  43946. index = index + this.offset;
  43947. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43948. this._split(index);
  43949. const chunk = this.byEnd[index];
  43950. if (chunk) {
  43951. chunk.appendLeft(content);
  43952. } else {
  43953. this.intro += content;
  43954. }
  43955. return this;
  43956. }
  43957. appendRight(index, content) {
  43958. index = index + this.offset;
  43959. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43960. this._split(index);
  43961. const chunk = this.byStart[index];
  43962. if (chunk) {
  43963. chunk.appendRight(content);
  43964. } else {
  43965. this.outro += content;
  43966. }
  43967. return this;
  43968. }
  43969. clone() {
  43970. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  43971. let originalChunk = this.firstChunk;
  43972. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  43973. while (originalChunk) {
  43974. cloned.byStart[clonedChunk.start] = clonedChunk;
  43975. cloned.byEnd[clonedChunk.end] = clonedChunk;
  43976. const nextOriginalChunk = originalChunk.next;
  43977. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  43978. if (nextClonedChunk) {
  43979. clonedChunk.next = nextClonedChunk;
  43980. nextClonedChunk.previous = clonedChunk;
  43981. clonedChunk = nextClonedChunk;
  43982. }
  43983. originalChunk = nextOriginalChunk;
  43984. }
  43985. cloned.lastChunk = clonedChunk;
  43986. if (this.indentExclusionRanges) {
  43987. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  43988. }
  43989. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  43990. cloned.intro = this.intro;
  43991. cloned.outro = this.outro;
  43992. return cloned;
  43993. }
  43994. generateDecodedMap(options) {
  43995. options = options || {};
  43996. const sourceIndex = 0;
  43997. const names = Object.keys(this.storedNames);
  43998. const mappings = new Mappings(options.hires);
  43999. const locate = getLocator(this.original);
  44000. if (this.intro) {
  44001. mappings.advance(this.intro);
  44002. }
  44003. this.firstChunk.eachNext((chunk) => {
  44004. const loc = locate(chunk.start);
  44005. if (chunk.intro.length) mappings.advance(chunk.intro);
  44006. if (chunk.edited) {
  44007. mappings.addEdit(
  44008. sourceIndex,
  44009. chunk.content,
  44010. loc,
  44011. chunk.storeName ? names.indexOf(chunk.original) : -1,
  44012. );
  44013. } else {
  44014. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  44015. }
  44016. if (chunk.outro.length) mappings.advance(chunk.outro);
  44017. });
  44018. return {
  44019. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  44020. sources: [
  44021. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  44022. ],
  44023. sourcesContent: options.includeContent ? [this.original] : undefined,
  44024. names,
  44025. mappings: mappings.raw,
  44026. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  44027. };
  44028. }
  44029. generateMap(options) {
  44030. return new SourceMap(this.generateDecodedMap(options));
  44031. }
  44032. _ensureindentStr() {
  44033. if (this.indentStr === undefined) {
  44034. this.indentStr = guessIndent(this.original);
  44035. }
  44036. }
  44037. _getRawIndentString() {
  44038. this._ensureindentStr();
  44039. return this.indentStr;
  44040. }
  44041. getIndentString() {
  44042. this._ensureindentStr();
  44043. return this.indentStr === null ? '\t' : this.indentStr;
  44044. }
  44045. indent(indentStr, options) {
  44046. const pattern = /^[^\r\n]/gm;
  44047. if (isObject(indentStr)) {
  44048. options = indentStr;
  44049. indentStr = undefined;
  44050. }
  44051. if (indentStr === undefined) {
  44052. this._ensureindentStr();
  44053. indentStr = this.indentStr || '\t';
  44054. }
  44055. if (indentStr === '') return this; // noop
  44056. options = options || {};
  44057. // Process exclusion ranges
  44058. const isExcluded = {};
  44059. if (options.exclude) {
  44060. const exclusions =
  44061. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  44062. exclusions.forEach((exclusion) => {
  44063. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  44064. isExcluded[i] = true;
  44065. }
  44066. });
  44067. }
  44068. let shouldIndentNextCharacter = options.indentStart !== false;
  44069. const replacer = (match) => {
  44070. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  44071. shouldIndentNextCharacter = true;
  44072. return match;
  44073. };
  44074. this.intro = this.intro.replace(pattern, replacer);
  44075. let charIndex = 0;
  44076. let chunk = this.firstChunk;
  44077. while (chunk) {
  44078. const end = chunk.end;
  44079. if (chunk.edited) {
  44080. if (!isExcluded[charIndex]) {
  44081. chunk.content = chunk.content.replace(pattern, replacer);
  44082. if (chunk.content.length) {
  44083. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  44084. }
  44085. }
  44086. } else {
  44087. charIndex = chunk.start;
  44088. while (charIndex < end) {
  44089. if (!isExcluded[charIndex]) {
  44090. const char = this.original[charIndex];
  44091. if (char === '\n') {
  44092. shouldIndentNextCharacter = true;
  44093. } else if (char !== '\r' && shouldIndentNextCharacter) {
  44094. shouldIndentNextCharacter = false;
  44095. if (charIndex === chunk.start) {
  44096. chunk.prependRight(indentStr);
  44097. } else {
  44098. this._splitChunk(chunk, charIndex);
  44099. chunk = chunk.next;
  44100. chunk.prependRight(indentStr);
  44101. }
  44102. }
  44103. }
  44104. charIndex += 1;
  44105. }
  44106. }
  44107. charIndex = chunk.end;
  44108. chunk = chunk.next;
  44109. }
  44110. this.outro = this.outro.replace(pattern, replacer);
  44111. return this;
  44112. }
  44113. insert() {
  44114. throw new Error(
  44115. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  44116. );
  44117. }
  44118. insertLeft(index, content) {
  44119. if (!warned.insertLeft) {
  44120. console.warn(
  44121. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  44122. );
  44123. warned.insertLeft = true;
  44124. }
  44125. return this.appendLeft(index, content);
  44126. }
  44127. insertRight(index, content) {
  44128. if (!warned.insertRight) {
  44129. console.warn(
  44130. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  44131. );
  44132. warned.insertRight = true;
  44133. }
  44134. return this.prependRight(index, content);
  44135. }
  44136. move(start, end, index) {
  44137. start = start + this.offset;
  44138. end = end + this.offset;
  44139. index = index + this.offset;
  44140. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  44141. this._split(start);
  44142. this._split(end);
  44143. this._split(index);
  44144. const first = this.byStart[start];
  44145. const last = this.byEnd[end];
  44146. const oldLeft = first.previous;
  44147. const oldRight = last.next;
  44148. const newRight = this.byStart[index];
  44149. if (!newRight && last === this.lastChunk) return this;
  44150. const newLeft = newRight ? newRight.previous : this.lastChunk;
  44151. if (oldLeft) oldLeft.next = oldRight;
  44152. if (oldRight) oldRight.previous = oldLeft;
  44153. if (newLeft) newLeft.next = first;
  44154. if (newRight) newRight.previous = last;
  44155. if (!first.previous) this.firstChunk = last.next;
  44156. if (!last.next) {
  44157. this.lastChunk = first.previous;
  44158. this.lastChunk.next = null;
  44159. }
  44160. first.previous = newLeft;
  44161. last.next = newRight || null;
  44162. if (!newLeft) this.firstChunk = first;
  44163. if (!newRight) this.lastChunk = last;
  44164. return this;
  44165. }
  44166. overwrite(start, end, content, options) {
  44167. options = options || {};
  44168. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  44169. }
  44170. update(start, end, content, options) {
  44171. start = start + this.offset;
  44172. end = end + this.offset;
  44173. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  44174. if (this.original.length !== 0) {
  44175. while (start < 0) start += this.original.length;
  44176. while (end < 0) end += this.original.length;
  44177. }
  44178. if (end > this.original.length) throw new Error('end is out of bounds');
  44179. if (start === end)
  44180. throw new Error(
  44181. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  44182. );
  44183. this._split(start);
  44184. this._split(end);
  44185. if (options === true) {
  44186. if (!warned.storeName) {
  44187. console.warn(
  44188. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  44189. );
  44190. warned.storeName = true;
  44191. }
  44192. options = { storeName: true };
  44193. }
  44194. const storeName = options !== undefined ? options.storeName : false;
  44195. const overwrite = options !== undefined ? options.overwrite : false;
  44196. if (storeName) {
  44197. const original = this.original.slice(start, end);
  44198. Object.defineProperty(this.storedNames, original, {
  44199. writable: true,
  44200. value: true,
  44201. enumerable: true,
  44202. });
  44203. }
  44204. const first = this.byStart[start];
  44205. const last = this.byEnd[end];
  44206. if (first) {
  44207. let chunk = first;
  44208. while (chunk !== last) {
  44209. if (chunk.next !== this.byStart[chunk.end]) {
  44210. throw new Error('Cannot overwrite across a split point');
  44211. }
  44212. chunk = chunk.next;
  44213. chunk.edit('', false);
  44214. }
  44215. first.edit(content, storeName, !overwrite);
  44216. } else {
  44217. // must be inserting at the end
  44218. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  44219. // TODO last chunk in the array may not be the last chunk, if it's moved...
  44220. last.next = newChunk;
  44221. newChunk.previous = last;
  44222. }
  44223. return this;
  44224. }
  44225. prepend(content) {
  44226. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44227. this.intro = content + this.intro;
  44228. return this;
  44229. }
  44230. prependLeft(index, content) {
  44231. index = index + this.offset;
  44232. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44233. this._split(index);
  44234. const chunk = this.byEnd[index];
  44235. if (chunk) {
  44236. chunk.prependLeft(content);
  44237. } else {
  44238. this.intro = content + this.intro;
  44239. }
  44240. return this;
  44241. }
  44242. prependRight(index, content) {
  44243. index = index + this.offset;
  44244. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44245. this._split(index);
  44246. const chunk = this.byStart[index];
  44247. if (chunk) {
  44248. chunk.prependRight(content);
  44249. } else {
  44250. this.outro = content + this.outro;
  44251. }
  44252. return this;
  44253. }
  44254. remove(start, end) {
  44255. start = start + this.offset;
  44256. end = end + this.offset;
  44257. if (this.original.length !== 0) {
  44258. while (start < 0) start += this.original.length;
  44259. while (end < 0) end += this.original.length;
  44260. }
  44261. if (start === end) return this;
  44262. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44263. if (start > end) throw new Error('end must be greater than start');
  44264. this._split(start);
  44265. this._split(end);
  44266. let chunk = this.byStart[start];
  44267. while (chunk) {
  44268. chunk.intro = '';
  44269. chunk.outro = '';
  44270. chunk.edit('');
  44271. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44272. }
  44273. return this;
  44274. }
  44275. reset(start, end) {
  44276. start = start + this.offset;
  44277. end = end + this.offset;
  44278. if (this.original.length !== 0) {
  44279. while (start < 0) start += this.original.length;
  44280. while (end < 0) end += this.original.length;
  44281. }
  44282. if (start === end) return this;
  44283. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44284. if (start > end) throw new Error('end must be greater than start');
  44285. this._split(start);
  44286. this._split(end);
  44287. let chunk = this.byStart[start];
  44288. while (chunk) {
  44289. chunk.reset();
  44290. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44291. }
  44292. return this;
  44293. }
  44294. lastChar() {
  44295. if (this.outro.length) return this.outro[this.outro.length - 1];
  44296. let chunk = this.lastChunk;
  44297. do {
  44298. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  44299. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  44300. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  44301. } while ((chunk = chunk.previous));
  44302. if (this.intro.length) return this.intro[this.intro.length - 1];
  44303. return '';
  44304. }
  44305. lastLine() {
  44306. let lineIndex = this.outro.lastIndexOf(n);
  44307. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  44308. let lineStr = this.outro;
  44309. let chunk = this.lastChunk;
  44310. do {
  44311. if (chunk.outro.length > 0) {
  44312. lineIndex = chunk.outro.lastIndexOf(n);
  44313. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  44314. lineStr = chunk.outro + lineStr;
  44315. }
  44316. if (chunk.content.length > 0) {
  44317. lineIndex = chunk.content.lastIndexOf(n);
  44318. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  44319. lineStr = chunk.content + lineStr;
  44320. }
  44321. if (chunk.intro.length > 0) {
  44322. lineIndex = chunk.intro.lastIndexOf(n);
  44323. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  44324. lineStr = chunk.intro + lineStr;
  44325. }
  44326. } while ((chunk = chunk.previous));
  44327. lineIndex = this.intro.lastIndexOf(n);
  44328. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  44329. return this.intro + lineStr;
  44330. }
  44331. slice(start = 0, end = this.original.length - this.offset) {
  44332. start = start + this.offset;
  44333. end = end + this.offset;
  44334. if (this.original.length !== 0) {
  44335. while (start < 0) start += this.original.length;
  44336. while (end < 0) end += this.original.length;
  44337. }
  44338. let result = '';
  44339. // find start chunk
  44340. let chunk = this.firstChunk;
  44341. while (chunk && (chunk.start > start || chunk.end <= start)) {
  44342. // found end chunk before start
  44343. if (chunk.start < end && chunk.end >= end) {
  44344. return result;
  44345. }
  44346. chunk = chunk.next;
  44347. }
  44348. if (chunk && chunk.edited && chunk.start !== start)
  44349. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  44350. const startChunk = chunk;
  44351. while (chunk) {
  44352. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  44353. result += chunk.intro;
  44354. }
  44355. const containsEnd = chunk.start < end && chunk.end >= end;
  44356. if (containsEnd && chunk.edited && chunk.end !== end)
  44357. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  44358. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  44359. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  44360. result += chunk.content.slice(sliceStart, sliceEnd);
  44361. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  44362. result += chunk.outro;
  44363. }
  44364. if (containsEnd) {
  44365. break;
  44366. }
  44367. chunk = chunk.next;
  44368. }
  44369. return result;
  44370. }
  44371. // TODO deprecate this? not really very useful
  44372. snip(start, end) {
  44373. const clone = this.clone();
  44374. clone.remove(0, start);
  44375. clone.remove(end, clone.original.length);
  44376. return clone;
  44377. }
  44378. _split(index) {
  44379. if (this.byStart[index] || this.byEnd[index]) return;
  44380. let chunk = this.lastSearchedChunk;
  44381. const searchForward = index > chunk.end;
  44382. while (chunk) {
  44383. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  44384. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  44385. }
  44386. }
  44387. _splitChunk(chunk, index) {
  44388. if (chunk.edited && chunk.content.length) {
  44389. // zero-length edited chunks are a special case (overlapping replacements)
  44390. const loc = getLocator(this.original)(index);
  44391. throw new Error(
  44392. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  44393. );
  44394. }
  44395. const newChunk = chunk.split(index);
  44396. this.byEnd[index] = chunk;
  44397. this.byStart[index] = newChunk;
  44398. this.byEnd[newChunk.end] = newChunk;
  44399. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  44400. this.lastSearchedChunk = chunk;
  44401. return true;
  44402. }
  44403. toString() {
  44404. let str = this.intro;
  44405. let chunk = this.firstChunk;
  44406. while (chunk) {
  44407. str += chunk.toString();
  44408. chunk = chunk.next;
  44409. }
  44410. return str + this.outro;
  44411. }
  44412. isEmpty() {
  44413. let chunk = this.firstChunk;
  44414. do {
  44415. if (
  44416. (chunk.intro.length && chunk.intro.trim()) ||
  44417. (chunk.content.length && chunk.content.trim()) ||
  44418. (chunk.outro.length && chunk.outro.trim())
  44419. )
  44420. return false;
  44421. } while ((chunk = chunk.next));
  44422. return true;
  44423. }
  44424. length() {
  44425. let chunk = this.firstChunk;
  44426. let length = 0;
  44427. do {
  44428. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  44429. } while ((chunk = chunk.next));
  44430. return length;
  44431. }
  44432. trimLines() {
  44433. return this.trim('[\\r\\n]');
  44434. }
  44435. trim(charType) {
  44436. return this.trimStart(charType).trimEnd(charType);
  44437. }
  44438. trimEndAborted(charType) {
  44439. const rx = new RegExp((charType || '\\s') + '+$');
  44440. this.outro = this.outro.replace(rx, '');
  44441. if (this.outro.length) return true;
  44442. let chunk = this.lastChunk;
  44443. do {
  44444. const end = chunk.end;
  44445. const aborted = chunk.trimEnd(rx);
  44446. // if chunk was trimmed, we have a new lastChunk
  44447. if (chunk.end !== end) {
  44448. if (this.lastChunk === chunk) {
  44449. this.lastChunk = chunk.next;
  44450. }
  44451. this.byEnd[chunk.end] = chunk;
  44452. this.byStart[chunk.next.start] = chunk.next;
  44453. this.byEnd[chunk.next.end] = chunk.next;
  44454. }
  44455. if (aborted) return true;
  44456. chunk = chunk.previous;
  44457. } while (chunk);
  44458. return false;
  44459. }
  44460. trimEnd(charType) {
  44461. this.trimEndAborted(charType);
  44462. return this;
  44463. }
  44464. trimStartAborted(charType) {
  44465. const rx = new RegExp('^' + (charType || '\\s') + '+');
  44466. this.intro = this.intro.replace(rx, '');
  44467. if (this.intro.length) return true;
  44468. let chunk = this.firstChunk;
  44469. do {
  44470. const end = chunk.end;
  44471. const aborted = chunk.trimStart(rx);
  44472. if (chunk.end !== end) {
  44473. // special case...
  44474. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  44475. this.byEnd[chunk.end] = chunk;
  44476. this.byStart[chunk.next.start] = chunk.next;
  44477. this.byEnd[chunk.next.end] = chunk.next;
  44478. }
  44479. if (aborted) return true;
  44480. chunk = chunk.next;
  44481. } while (chunk);
  44482. return false;
  44483. }
  44484. trimStart(charType) {
  44485. this.trimStartAborted(charType);
  44486. return this;
  44487. }
  44488. hasChanged() {
  44489. return this.original !== this.toString();
  44490. }
  44491. _replaceRegexp(searchValue, replacement) {
  44492. function getReplacement(match, str) {
  44493. if (typeof replacement === 'string') {
  44494. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  44495. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  44496. if (i === '$') return '$';
  44497. if (i === '&') return match[0];
  44498. const num = +i;
  44499. if (num < match.length) return match[+i];
  44500. return `$${i}`;
  44501. });
  44502. } else {
  44503. return replacement(...match, match.index, str, match.groups);
  44504. }
  44505. }
  44506. function matchAll(re, str) {
  44507. let match;
  44508. const matches = [];
  44509. while ((match = re.exec(str))) {
  44510. matches.push(match);
  44511. }
  44512. return matches;
  44513. }
  44514. if (searchValue.global) {
  44515. const matches = matchAll(searchValue, this.original);
  44516. matches.forEach((match) => {
  44517. if (match.index != null) {
  44518. const replacement = getReplacement(match, this.original);
  44519. if (replacement !== match[0]) {
  44520. this.overwrite(match.index, match.index + match[0].length, replacement);
  44521. }
  44522. }
  44523. });
  44524. } else {
  44525. const match = this.original.match(searchValue);
  44526. if (match && match.index != null) {
  44527. const replacement = getReplacement(match, this.original);
  44528. if (replacement !== match[0]) {
  44529. this.overwrite(match.index, match.index + match[0].length, replacement);
  44530. }
  44531. }
  44532. }
  44533. return this;
  44534. }
  44535. _replaceString(string, replacement) {
  44536. const { original } = this;
  44537. const index = original.indexOf(string);
  44538. if (index !== -1) {
  44539. this.overwrite(index, index + string.length, replacement);
  44540. }
  44541. return this;
  44542. }
  44543. replace(searchValue, replacement) {
  44544. if (typeof searchValue === 'string') {
  44545. return this._replaceString(searchValue, replacement);
  44546. }
  44547. return this._replaceRegexp(searchValue, replacement);
  44548. }
  44549. _replaceAllString(string, replacement) {
  44550. const { original } = this;
  44551. const stringLength = string.length;
  44552. for (
  44553. let index = original.indexOf(string);
  44554. index !== -1;
  44555. index = original.indexOf(string, index + stringLength)
  44556. ) {
  44557. const previous = original.slice(index, index + stringLength);
  44558. if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
  44559. }
  44560. return this;
  44561. }
  44562. replaceAll(searchValue, replacement) {
  44563. if (typeof searchValue === 'string') {
  44564. return this._replaceAllString(searchValue, replacement);
  44565. }
  44566. if (!searchValue.global) {
  44567. throw new TypeError(
  44568. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  44569. );
  44570. }
  44571. return this._replaceRegexp(searchValue, replacement);
  44572. }
  44573. }
  44574. var _a, _b;
  44575. class ScriptCompileContext {
  44576. constructor(descriptor, options) {
  44577. this.descriptor = descriptor;
  44578. this.options = options;
  44579. this.isCE = false;
  44580. this.source = this.descriptor.source;
  44581. this.filename = this.descriptor.filename;
  44582. this.s = new MagicString(this.source);
  44583. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44584. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44585. this.userImports = /* @__PURE__ */ Object.create(null);
  44586. // macros presence check
  44587. this.hasDefinePropsCall = false;
  44588. this.hasDefineEmitCall = false;
  44589. this.hasDefineExposeCall = false;
  44590. this.hasDefaultExportName = false;
  44591. this.hasDefaultExportRender = false;
  44592. this.hasDefineOptionsCall = false;
  44593. this.hasDefineSlotsCall = false;
  44594. this.hasDefineModelCall = false;
  44595. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44596. // defineModel
  44597. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44598. // codegen
  44599. this.bindingMetadata = {};
  44600. this.helperImports = /* @__PURE__ */ new Set();
  44601. const { script, scriptSetup } = descriptor;
  44602. const scriptLang = script && script.lang;
  44603. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44604. this.isJS = scriptLang === "js" || scriptLang === "jsx" || scriptSetupLang === "js" || scriptSetupLang === "jsx";
  44605. this.isTS = scriptLang === "ts" || scriptLang === "tsx" || scriptSetupLang === "ts" || scriptSetupLang === "tsx";
  44606. const customElement = options.customElement;
  44607. const filename = this.descriptor.filename;
  44608. if (customElement) {
  44609. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44610. }
  44611. const plugins = resolveParserPlugins(
  44612. scriptLang || scriptSetupLang,
  44613. options.babelParserPlugins
  44614. );
  44615. function parse(input, offset) {
  44616. try {
  44617. return libExports.parse(input, {
  44618. plugins,
  44619. sourceType: "module"
  44620. }).program;
  44621. } catch (e) {
  44622. e.message = `[vue/compiler-sfc] ${e.message}
  44623. ${descriptor.filename}
  44624. ${generateCodeFrame(
  44625. descriptor.source,
  44626. e.pos + offset,
  44627. e.pos + offset + 1
  44628. )}`;
  44629. throw e;
  44630. }
  44631. }
  44632. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44633. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44634. }
  44635. helper(key) {
  44636. this.helperImports.add(key);
  44637. return `_${key}`;
  44638. }
  44639. getString(node, scriptSetup = true) {
  44640. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44641. return block.content.slice(node.start, node.end);
  44642. }
  44643. warn(msg, node, scope) {
  44644. warn(generateError(msg, node, this, scope));
  44645. }
  44646. error(msg, node, scope) {
  44647. throw new Error(
  44648. `[@vue/compiler-sfc] ${generateError(msg, node, this, scope)}`
  44649. );
  44650. }
  44651. }
  44652. function generateError(msg, node, ctx, scope) {
  44653. const offset = scope ? scope.offset : ctx.startOffset;
  44654. return `${msg}
  44655. ${(scope || ctx.descriptor).filename}
  44656. ${generateCodeFrame(
  44657. (scope || ctx.descriptor).source,
  44658. node.start + offset,
  44659. node.end + offset
  44660. )}`;
  44661. }
  44662. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44663. const plugins = [];
  44664. if (!userPlugins || !userPlugins.some(
  44665. (p) => p === "importAssertions" || p === "importAttributes" || isArray$3(p) && p[0] === "importAttributes"
  44666. )) {
  44667. plugins.push("importAttributes");
  44668. }
  44669. if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
  44670. plugins.push("jsx");
  44671. } else if (userPlugins) {
  44672. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44673. }
  44674. if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "mtsx") {
  44675. plugins.push(["typescript", { dts }], "explicitResourceManagement");
  44676. if (!userPlugins || !userPlugins.includes("decorators")) {
  44677. plugins.push("decorators-legacy");
  44678. }
  44679. }
  44680. if (userPlugins) {
  44681. plugins.push(...userPlugins);
  44682. }
  44683. return plugins;
  44684. }
  44685. function rewriteDefault(input, as, parserPlugins) {
  44686. const ast = libExports.parse(input, {
  44687. sourceType: "module",
  44688. plugins: resolveParserPlugins("js", parserPlugins)
  44689. }).program.body;
  44690. const s = new MagicString(input);
  44691. rewriteDefaultAST(ast, s, as);
  44692. return s.toString();
  44693. }
  44694. function rewriteDefaultAST(ast, s, as) {
  44695. if (!hasDefaultExport(ast)) {
  44696. s.append(`
  44697. const ${as} = {}`);
  44698. return;
  44699. }
  44700. ast.forEach((node) => {
  44701. if (node.type === "ExportDefaultDeclaration") {
  44702. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  44703. const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44704. s.overwrite(start, node.declaration.id.start, ` class `);
  44705. s.append(`
  44706. const ${as} = ${node.declaration.id.name}`);
  44707. } else {
  44708. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44709. }
  44710. } else if (node.type === "ExportNamedDeclaration") {
  44711. for (const specifier of node.specifiers) {
  44712. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44713. if (node.source) {
  44714. if (specifier.local.name === "default") {
  44715. s.prepend(
  44716. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44717. `
  44718. );
  44719. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44720. s.remove(specifier.start, end2);
  44721. s.append(`
  44722. const ${as} = __VUE_DEFAULT__`);
  44723. continue;
  44724. } else {
  44725. s.prepend(
  44726. `import { ${s.slice(
  44727. specifier.local.start,
  44728. specifier.local.end
  44729. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44730. `
  44731. );
  44732. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  44733. s.remove(specifier.start, end2);
  44734. s.append(`
  44735. const ${as} = __VUE_DEFAULT__`);
  44736. continue;
  44737. }
  44738. }
  44739. const end = specifierEnd(s, specifier.end, node.end);
  44740. s.remove(specifier.start, end);
  44741. s.append(`
  44742. const ${as} = ${specifier.local.name}`);
  44743. }
  44744. }
  44745. }
  44746. });
  44747. }
  44748. function hasDefaultExport(ast) {
  44749. for (const stmt of ast) {
  44750. if (stmt.type === "ExportDefaultDeclaration") {
  44751. return true;
  44752. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  44753. (spec) => spec.exported.name === "default"
  44754. )) {
  44755. return true;
  44756. }
  44757. }
  44758. return false;
  44759. }
  44760. function specifierEnd(s, end, nodeEnd) {
  44761. let hasCommas = false;
  44762. let oldEnd = end;
  44763. while (end < nodeEnd) {
  44764. if (/\s/.test(s.slice(end, end + 1))) {
  44765. end++;
  44766. } else if (s.slice(end, end + 1) === ",") {
  44767. end++;
  44768. hasCommas = true;
  44769. break;
  44770. } else if (s.slice(end, end + 1) === "}") {
  44771. break;
  44772. }
  44773. }
  44774. return hasCommas ? end : oldEnd;
  44775. }
  44776. var __defProp$3 = Object.defineProperty;
  44777. var __defProps$2 = Object.defineProperties;
  44778. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  44779. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  44780. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  44781. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  44782. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44783. var __spreadValues$3 = (a, b) => {
  44784. for (var prop in b || (b = {}))
  44785. if (__hasOwnProp$3.call(b, prop))
  44786. __defNormalProp$3(a, prop, b[prop]);
  44787. if (__getOwnPropSymbols$3)
  44788. for (var prop of __getOwnPropSymbols$3(b)) {
  44789. if (__propIsEnum$3.call(b, prop))
  44790. __defNormalProp$3(a, prop, b[prop]);
  44791. }
  44792. return a;
  44793. };
  44794. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  44795. const normalScriptDefaultVar = `__default__`;
  44796. function processNormalScript(ctx, scopeId) {
  44797. var _a;
  44798. const script = ctx.descriptor.script;
  44799. if (script.lang && !ctx.isJS && !ctx.isTS) {
  44800. return script;
  44801. }
  44802. try {
  44803. let content = script.content;
  44804. let map = script.map;
  44805. const scriptAst = ctx.scriptAst;
  44806. const bindings = analyzeScriptBindings(scriptAst.body);
  44807. const { cssVars } = ctx.descriptor;
  44808. const { genDefaultAs, isProd } = ctx.options;
  44809. if (cssVars.length || genDefaultAs) {
  44810. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  44811. const s = new MagicString(content);
  44812. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  44813. content = s.toString();
  44814. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  44815. content += genNormalScriptCssVarsCode(
  44816. cssVars,
  44817. bindings,
  44818. scopeId,
  44819. !!isProd,
  44820. defaultVar
  44821. );
  44822. }
  44823. if (!genDefaultAs) {
  44824. content += `
  44825. export default ${defaultVar}`;
  44826. }
  44827. }
  44828. return __spreadProps$2(__spreadValues$3({}, script), {
  44829. content,
  44830. map,
  44831. bindings,
  44832. scriptAst: scriptAst.body
  44833. });
  44834. } catch (e) {
  44835. return script;
  44836. }
  44837. }
  44838. var __defProp$2 = Object.defineProperty;
  44839. var __defProps$1 = Object.defineProperties;
  44840. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  44841. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  44842. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  44843. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  44844. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44845. var __spreadValues$2 = (a, b) => {
  44846. for (var prop in b || (b = {}))
  44847. if (__hasOwnProp$2.call(b, prop))
  44848. __defNormalProp$2(a, prop, b[prop]);
  44849. if (__getOwnPropSymbols$2)
  44850. for (var prop of __getOwnPropSymbols$2(b)) {
  44851. if (__propIsEnum$2.call(b, prop))
  44852. __defNormalProp$2(a, prop, b[prop]);
  44853. }
  44854. return a;
  44855. };
  44856. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  44857. class TypeScope {
  44858. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  44859. this.filename = filename;
  44860. this.source = source;
  44861. this.offset = offset;
  44862. this.imports = imports;
  44863. this.types = types;
  44864. this.declares = declares;
  44865. this.isGenericScope = false;
  44866. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  44867. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  44868. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  44869. }
  44870. }
  44871. function resolveTypeElements(ctx, node, scope, typeParameters) {
  44872. const canCache = !typeParameters;
  44873. if (canCache && node._resolvedElements) {
  44874. return node._resolvedElements;
  44875. }
  44876. const resolved = innerResolveTypeElements(
  44877. ctx,
  44878. node,
  44879. node._ownerScope || scope || ctxToScope(ctx),
  44880. typeParameters
  44881. );
  44882. return canCache ? node._resolvedElements = resolved : resolved;
  44883. }
  44884. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  44885. var _a, _b;
  44886. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  44887. return { props: {} };
  44888. }
  44889. switch (node.type) {
  44890. case "TSTypeLiteral":
  44891. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  44892. case "TSInterfaceDeclaration":
  44893. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  44894. case "TSTypeAliasDeclaration":
  44895. case "TSTypeAnnotation":
  44896. case "TSParenthesizedType":
  44897. return resolveTypeElements(
  44898. ctx,
  44899. node.typeAnnotation,
  44900. scope,
  44901. typeParameters
  44902. );
  44903. case "TSFunctionType": {
  44904. return { props: {}, calls: [node] };
  44905. }
  44906. case "TSUnionType":
  44907. case "TSIntersectionType":
  44908. return mergeElements(
  44909. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  44910. node.type
  44911. );
  44912. case "TSMappedType":
  44913. return resolveMappedType(ctx, node, scope, typeParameters);
  44914. case "TSIndexedAccessType": {
  44915. const types = resolveIndexType(ctx, node, scope);
  44916. return mergeElements(
  44917. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  44918. "TSUnionType"
  44919. );
  44920. }
  44921. case "TSExpressionWithTypeArguments":
  44922. // referenced by interface extends
  44923. case "TSTypeReference": {
  44924. const typeName = getReferenceName(node);
  44925. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  44926. return resolveExtractPropTypes(
  44927. resolveTypeElements(
  44928. ctx,
  44929. node.typeParameters.params[0],
  44930. scope,
  44931. typeParameters
  44932. ),
  44933. scope
  44934. );
  44935. }
  44936. const resolved = resolveTypeReference(ctx, node, scope);
  44937. if (resolved) {
  44938. let typeParams;
  44939. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  44940. typeParams = /* @__PURE__ */ Object.create(null);
  44941. resolved.typeParameters.params.forEach((p, i) => {
  44942. let param = typeParameters && typeParameters[p.name];
  44943. if (!param) param = node.typeParameters.params[i];
  44944. typeParams[p.name] = param;
  44945. });
  44946. }
  44947. return resolveTypeElements(
  44948. ctx,
  44949. resolved,
  44950. resolved._ownerScope,
  44951. typeParams
  44952. );
  44953. } else {
  44954. if (typeof typeName === "string") {
  44955. if (typeParameters && typeParameters[typeName]) {
  44956. return resolveTypeElements(
  44957. ctx,
  44958. typeParameters[typeName],
  44959. scope,
  44960. typeParameters
  44961. );
  44962. }
  44963. if (
  44964. // @ts-expect-error
  44965. SupportedBuiltinsSet.has(typeName)
  44966. ) {
  44967. return resolveBuiltin(
  44968. ctx,
  44969. node,
  44970. typeName,
  44971. scope,
  44972. typeParameters
  44973. );
  44974. } else if (typeName === "ReturnType" && node.typeParameters) {
  44975. const ret = resolveReturnType(
  44976. ctx,
  44977. node.typeParameters.params[0],
  44978. scope
  44979. );
  44980. if (ret) {
  44981. return resolveTypeElements(ctx, ret, scope);
  44982. }
  44983. }
  44984. }
  44985. return ctx.error(
  44986. `Unresolvable type reference or unsupported built-in utility type`,
  44987. node,
  44988. scope
  44989. );
  44990. }
  44991. }
  44992. case "TSImportType": {
  44993. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  44994. return resolveExtractPropTypes(
  44995. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  44996. scope
  44997. );
  44998. }
  44999. const sourceScope = importSourceToScope(
  45000. ctx,
  45001. node.argument,
  45002. scope,
  45003. node.argument.value
  45004. );
  45005. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45006. if (resolved) {
  45007. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45008. }
  45009. break;
  45010. }
  45011. case "TSTypeQuery":
  45012. {
  45013. const resolved = resolveTypeReference(ctx, node, scope);
  45014. if (resolved) {
  45015. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45016. }
  45017. }
  45018. break;
  45019. }
  45020. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  45021. }
  45022. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  45023. const res = { props: {} };
  45024. for (const e of elements) {
  45025. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  45026. if (typeParameters) {
  45027. scope = createChildScope(scope);
  45028. scope.isGenericScope = true;
  45029. Object.assign(scope.types, typeParameters);
  45030. }
  45031. e._ownerScope = scope;
  45032. const name = getId(e.key);
  45033. if (name && !e.computed) {
  45034. res.props[name] = e;
  45035. } else if (e.key.type === "TemplateLiteral") {
  45036. for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
  45037. res.props[key] = e;
  45038. }
  45039. } else {
  45040. ctx.error(
  45041. `Unsupported computed key in type referenced by a macro`,
  45042. e.key,
  45043. scope
  45044. );
  45045. }
  45046. } else if (e.type === "TSCallSignatureDeclaration") {
  45047. (res.calls || (res.calls = [])).push(e);
  45048. }
  45049. }
  45050. return res;
  45051. }
  45052. function mergeElements(maps, type) {
  45053. if (maps.length === 1) return maps[0];
  45054. const res = { props: {} };
  45055. const { props: baseProps } = res;
  45056. for (const { props, calls } of maps) {
  45057. for (const key in props) {
  45058. if (!hasOwn(baseProps, key)) {
  45059. baseProps[key] = props[key];
  45060. } else {
  45061. baseProps[key] = createProperty(
  45062. baseProps[key].key,
  45063. {
  45064. type,
  45065. // @ts-expect-error
  45066. types: [baseProps[key], props[key]]
  45067. },
  45068. baseProps[key]._ownerScope,
  45069. baseProps[key].optional || props[key].optional
  45070. );
  45071. }
  45072. }
  45073. if (calls) {
  45074. (res.calls || (res.calls = [])).push(...calls);
  45075. }
  45076. }
  45077. return res;
  45078. }
  45079. function createProperty(key, typeAnnotation, scope, optional) {
  45080. return {
  45081. type: "TSPropertySignature",
  45082. key,
  45083. kind: "get",
  45084. optional,
  45085. typeAnnotation: {
  45086. type: "TSTypeAnnotation",
  45087. typeAnnotation
  45088. },
  45089. _ownerScope: scope
  45090. };
  45091. }
  45092. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  45093. const base = typeElementsToMap(
  45094. ctx,
  45095. node.body.body,
  45096. node._ownerScope,
  45097. typeParameters
  45098. );
  45099. if (node.extends) {
  45100. for (const ext of node.extends) {
  45101. try {
  45102. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  45103. for (const key in props) {
  45104. if (!hasOwn(base.props, key)) {
  45105. base.props[key] = props[key];
  45106. }
  45107. }
  45108. if (calls) {
  45109. ;
  45110. (base.calls || (base.calls = [])).push(...calls);
  45111. }
  45112. } catch (e) {
  45113. ctx.error(
  45114. `Failed to resolve extends base type.
  45115. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  45116. interface Props extends /* @vue-ignore */ Base {}
  45117. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  45118. ext,
  45119. scope
  45120. );
  45121. }
  45122. }
  45123. }
  45124. return base;
  45125. }
  45126. function resolveMappedType(ctx, node, scope, typeParameters) {
  45127. const res = { props: {} };
  45128. let keys;
  45129. if (node.nameType) {
  45130. const { name, constraint } = node.typeParameter;
  45131. scope = createChildScope(scope);
  45132. Object.assign(scope.types, __spreadProps$1(__spreadValues$2({}, typeParameters), { [name]: constraint }));
  45133. keys = resolveStringType(ctx, node.nameType, scope);
  45134. } else {
  45135. keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  45136. }
  45137. for (const key of keys) {
  45138. res.props[key] = createProperty(
  45139. {
  45140. type: "Identifier",
  45141. name: key
  45142. },
  45143. node.typeAnnotation,
  45144. scope,
  45145. !!node.optional
  45146. );
  45147. }
  45148. return res;
  45149. }
  45150. function resolveIndexType(ctx, node, scope) {
  45151. var _a, _b;
  45152. if (node.indexType.type === "TSNumberKeyword") {
  45153. return resolveArrayElementType(ctx, node.objectType, scope);
  45154. }
  45155. const { indexType, objectType } = node;
  45156. const types = [];
  45157. let keys;
  45158. let resolved;
  45159. if (indexType.type === "TSStringKeyword") {
  45160. resolved = resolveTypeElements(ctx, objectType, scope);
  45161. keys = Object.keys(resolved.props);
  45162. } else {
  45163. keys = resolveStringType(ctx, indexType, scope);
  45164. resolved = resolveTypeElements(ctx, objectType, scope);
  45165. }
  45166. for (const key of keys) {
  45167. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45168. if (targetType) {
  45169. targetType._ownerScope = resolved.props[key]._ownerScope;
  45170. types.push(targetType);
  45171. }
  45172. }
  45173. return types;
  45174. }
  45175. function resolveArrayElementType(ctx, node, scope) {
  45176. if (node.type === "TSArrayType") {
  45177. return [node.elementType];
  45178. }
  45179. if (node.type === "TSTupleType") {
  45180. return node.elementTypes.map(
  45181. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45182. );
  45183. }
  45184. if (node.type === "TSTypeReference") {
  45185. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45186. return node.typeParameters.params;
  45187. } else {
  45188. const resolved = resolveTypeReference(ctx, node, scope);
  45189. if (resolved) {
  45190. return resolveArrayElementType(ctx, resolved, scope);
  45191. }
  45192. }
  45193. }
  45194. return ctx.error(
  45195. "Failed to resolve element type from target type",
  45196. node,
  45197. scope
  45198. );
  45199. }
  45200. function resolveStringType(ctx, node, scope, typeParameters) {
  45201. switch (node.type) {
  45202. case "StringLiteral":
  45203. return [node.value];
  45204. case "TSLiteralType":
  45205. return resolveStringType(ctx, node.literal, scope, typeParameters);
  45206. case "TSUnionType":
  45207. return node.types.map((t) => resolveStringType(ctx, t, scope, typeParameters)).flat();
  45208. case "TemplateLiteral": {
  45209. return resolveTemplateKeys(ctx, node, scope);
  45210. }
  45211. case "TSTypeReference": {
  45212. const resolved = resolveTypeReference(ctx, node, scope);
  45213. if (resolved) {
  45214. return resolveStringType(ctx, resolved, scope, typeParameters);
  45215. }
  45216. if (node.typeName.type === "Identifier") {
  45217. const name = node.typeName.name;
  45218. if (typeParameters && typeParameters[name]) {
  45219. return resolveStringType(
  45220. ctx,
  45221. typeParameters[name],
  45222. scope,
  45223. typeParameters
  45224. );
  45225. }
  45226. const getParam = (index = 0) => resolveStringType(
  45227. ctx,
  45228. node.typeParameters.params[index],
  45229. scope,
  45230. typeParameters
  45231. );
  45232. switch (name) {
  45233. case "Extract":
  45234. return getParam(1);
  45235. case "Exclude": {
  45236. const excluded = getParam(1);
  45237. return getParam().filter((s) => !excluded.includes(s));
  45238. }
  45239. case "Uppercase":
  45240. return getParam().map((s) => s.toUpperCase());
  45241. case "Lowercase":
  45242. return getParam().map((s) => s.toLowerCase());
  45243. case "Capitalize":
  45244. return getParam().map(capitalize);
  45245. case "Uncapitalize":
  45246. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45247. default:
  45248. ctx.error(
  45249. "Unsupported type when resolving index type",
  45250. node.typeName,
  45251. scope
  45252. );
  45253. }
  45254. }
  45255. }
  45256. }
  45257. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45258. }
  45259. function resolveTemplateKeys(ctx, node, scope) {
  45260. if (!node.expressions.length) {
  45261. return [node.quasis[0].value.raw];
  45262. }
  45263. const res = [];
  45264. const e = node.expressions[0];
  45265. const q = node.quasis[0];
  45266. const leading = q ? q.value.raw : ``;
  45267. const resolved = resolveStringType(ctx, e, scope);
  45268. const restResolved = resolveTemplateKeys(
  45269. ctx,
  45270. __spreadProps$1(__spreadValues$2({}, node), {
  45271. expressions: node.expressions.slice(1),
  45272. quasis: q ? node.quasis.slice(1) : node.quasis
  45273. }),
  45274. scope
  45275. );
  45276. for (const r of resolved) {
  45277. for (const rr of restResolved) {
  45278. res.push(leading + r + rr);
  45279. }
  45280. }
  45281. return res;
  45282. }
  45283. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45284. "Partial",
  45285. "Required",
  45286. "Readonly",
  45287. "Pick",
  45288. "Omit"
  45289. ]);
  45290. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45291. const t = resolveTypeElements(
  45292. ctx,
  45293. node.typeParameters.params[0],
  45294. scope,
  45295. typeParameters
  45296. );
  45297. switch (name) {
  45298. case "Partial": {
  45299. const res2 = { props: {}, calls: t.calls };
  45300. Object.keys(t.props).forEach((key) => {
  45301. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: true });
  45302. });
  45303. return res2;
  45304. }
  45305. case "Required": {
  45306. const res2 = { props: {}, calls: t.calls };
  45307. Object.keys(t.props).forEach((key) => {
  45308. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: false });
  45309. });
  45310. return res2;
  45311. }
  45312. case "Readonly":
  45313. return t;
  45314. case "Pick": {
  45315. const picked = resolveStringType(
  45316. ctx,
  45317. node.typeParameters.params[1],
  45318. scope,
  45319. typeParameters
  45320. );
  45321. const res2 = { props: {}, calls: t.calls };
  45322. for (const key of picked) {
  45323. res2.props[key] = t.props[key];
  45324. }
  45325. return res2;
  45326. }
  45327. case "Omit":
  45328. const omitted = resolveStringType(
  45329. ctx,
  45330. node.typeParameters.params[1],
  45331. scope,
  45332. typeParameters
  45333. );
  45334. const res = { props: {}, calls: t.calls };
  45335. for (const key in t.props) {
  45336. if (!omitted.includes(key)) {
  45337. res.props[key] = t.props[key];
  45338. }
  45339. }
  45340. return res;
  45341. }
  45342. }
  45343. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45344. const canCache = !(scope == null ? void 0 : scope.isGenericScope);
  45345. if (canCache && node._resolvedReference) {
  45346. return node._resolvedReference;
  45347. }
  45348. const resolved = innerResolveTypeReference(
  45349. ctx,
  45350. scope || ctxToScope(ctx),
  45351. name || getReferenceName(node),
  45352. node,
  45353. onlyExported
  45354. );
  45355. return canCache ? node._resolvedReference = resolved : resolved;
  45356. }
  45357. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45358. if (typeof name === "string") {
  45359. if (scope.imports[name]) {
  45360. return resolveTypeFromImport(ctx, node, name, scope);
  45361. } else {
  45362. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45363. if (lookupSource[name]) {
  45364. return lookupSource[name];
  45365. } else {
  45366. const globalScopes = resolveGlobalScope(ctx);
  45367. if (globalScopes) {
  45368. for (const s of globalScopes) {
  45369. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45370. if (src[name]) {
  45371. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45372. return src[name];
  45373. }
  45374. }
  45375. }
  45376. }
  45377. }
  45378. } else {
  45379. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45380. if (ns) {
  45381. if (ns.type !== "TSModuleDeclaration") {
  45382. ns = ns._ns;
  45383. }
  45384. if (ns) {
  45385. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45386. return innerResolveTypeReference(
  45387. ctx,
  45388. childScope,
  45389. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45390. node,
  45391. !ns.declare
  45392. );
  45393. }
  45394. }
  45395. }
  45396. }
  45397. function getReferenceName(node) {
  45398. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45399. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45400. return ref.name;
  45401. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45402. return qualifiedNameToPath(ref);
  45403. } else {
  45404. return "default";
  45405. }
  45406. }
  45407. function qualifiedNameToPath(node) {
  45408. if (node.type === "Identifier") {
  45409. return [node.name];
  45410. } else {
  45411. return [...qualifiedNameToPath(node.left), node.right.name];
  45412. }
  45413. }
  45414. function resolveGlobalScope(ctx) {
  45415. if (ctx.options.globalTypeFiles) {
  45416. const fs = resolveFS(ctx);
  45417. if (!fs) {
  45418. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45419. }
  45420. return ctx.options.globalTypeFiles.map(
  45421. (file) => fileToScope(ctx, normalizePath(file), true)
  45422. );
  45423. }
  45424. }
  45425. let ts;
  45426. let loadTS;
  45427. function registerTS(_loadTS) {
  45428. loadTS = () => {
  45429. try {
  45430. return _loadTS();
  45431. } catch (err) {
  45432. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45433. throw new Error(
  45434. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "typescript" is installed as a project dependency.'
  45435. );
  45436. } else {
  45437. throw new Error(
  45438. "Failed to load TypeScript for resolving imported types."
  45439. );
  45440. }
  45441. }
  45442. };
  45443. }
  45444. function resolveFS(ctx) {
  45445. if (ctx.fs) {
  45446. return ctx.fs;
  45447. }
  45448. if (!ts && loadTS) {
  45449. ts = loadTS();
  45450. }
  45451. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45452. if (!fs) {
  45453. return;
  45454. }
  45455. return ctx.fs = {
  45456. fileExists(file) {
  45457. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45458. file = file.replace(/\.ts$/, "");
  45459. }
  45460. return fs.fileExists(file);
  45461. },
  45462. readFile(file) {
  45463. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45464. file = file.replace(/\.ts$/, "");
  45465. }
  45466. return fs.readFile(file);
  45467. },
  45468. realpath: fs.realpath
  45469. };
  45470. }
  45471. function resolveTypeFromImport(ctx, node, name, scope) {
  45472. const { source, imported } = scope.imports[name];
  45473. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45474. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45475. }
  45476. function importSourceToScope(ctx, node, scope, source) {
  45477. let fs;
  45478. try {
  45479. fs = resolveFS(ctx);
  45480. } catch (err) {
  45481. return ctx.error(err.message, node, scope);
  45482. }
  45483. if (!fs) {
  45484. return ctx.error(
  45485. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45486. node,
  45487. scope
  45488. );
  45489. }
  45490. let resolved = scope.resolvedImportSources[source];
  45491. if (!resolved) {
  45492. if (source.startsWith("..")) {
  45493. const osSpecificJoinFn = joinPaths;
  45494. const filename = osSpecificJoinFn(dirname(scope.filename), source);
  45495. resolved = resolveExt(filename, fs);
  45496. } else if (source[0] === ".") {
  45497. const filename = joinPaths(dirname(scope.filename), source);
  45498. resolved = resolveExt(filename, fs);
  45499. } else {
  45500. {
  45501. return ctx.error(
  45502. `Type import from non-relative sources is not supported in the browser build.`,
  45503. node,
  45504. scope
  45505. );
  45506. }
  45507. }
  45508. if (resolved) {
  45509. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45510. }
  45511. }
  45512. if (resolved) {
  45513. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45514. return fileToScope(ctx, resolved);
  45515. } else {
  45516. return ctx.error(
  45517. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45518. node,
  45519. scope
  45520. );
  45521. }
  45522. }
  45523. function resolveExt(filename, fs) {
  45524. filename = filename.replace(/\.js$/, "");
  45525. const tryResolve = (filename2) => {
  45526. if (fs.fileExists(filename2)) return filename2;
  45527. };
  45528. return tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.tsx`)) || tryResolve(joinPaths(filename, `index.d.ts`));
  45529. }
  45530. const tsConfigCache = createCache();
  45531. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45532. const fileToScopeCache = createCache();
  45533. function invalidateTypeCache(filename) {
  45534. filename = normalizePath(filename);
  45535. fileToScopeCache.delete(filename);
  45536. tsConfigCache.delete(filename);
  45537. const affectedConfig = tsConfigRefMap.get(filename);
  45538. if (affectedConfig) tsConfigCache.delete(affectedConfig);
  45539. }
  45540. function fileToScope(ctx, filename, asGlobal = false) {
  45541. const cached = fileToScopeCache.get(filename);
  45542. if (cached) {
  45543. return cached;
  45544. }
  45545. const fs = resolveFS(ctx);
  45546. const source = fs.readFile(filename) || "";
  45547. const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
  45548. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45549. recordTypes(ctx, body, scope, asGlobal);
  45550. fileToScopeCache.set(filename, scope);
  45551. return scope;
  45552. }
  45553. function parseFile(filename, content, fs, parserPlugins) {
  45554. const ext = extname(filename);
  45555. if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
  45556. return libExports.parse(content, {
  45557. plugins: resolveParserPlugins(
  45558. ext.slice(1),
  45559. parserPlugins,
  45560. /\.d\.m?ts$/.test(filename)
  45561. ),
  45562. sourceType: "module"
  45563. }).program.body;
  45564. }
  45565. const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
  45566. const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
  45567. const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
  45568. if (hasArbitraryTypeDeclaration) {
  45569. return libExports.parse(fs.readFile(arbitraryTypeSource), {
  45570. plugins: resolveParserPlugins("ts", parserPlugins, true),
  45571. sourceType: "module"
  45572. }).program.body;
  45573. }
  45574. if (ext === ".vue") {
  45575. const {
  45576. descriptor: { script, scriptSetup }
  45577. } = parse$2(content);
  45578. if (!script && !scriptSetup) {
  45579. return [];
  45580. }
  45581. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45582. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45583. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45584. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45585. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45586. if (secondBlock) {
  45587. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45588. }
  45589. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45590. return libExports.parse(scriptContent, {
  45591. plugins: resolveParserPlugins(lang, parserPlugins),
  45592. sourceType: "module"
  45593. }).program.body;
  45594. }
  45595. return [];
  45596. }
  45597. function ctxToScope(ctx) {
  45598. if (ctx.scope) {
  45599. return ctx.scope;
  45600. }
  45601. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45602. const scope = new TypeScope(
  45603. ctx.filename,
  45604. ctx.source,
  45605. "startOffset" in ctx ? ctx.startOffset : 0,
  45606. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45607. );
  45608. recordTypes(ctx, body, scope);
  45609. return ctx.scope = scope;
  45610. }
  45611. function moduleDeclToScope(ctx, node, parentScope) {
  45612. if (node._resolvedChildScope) {
  45613. return node._resolvedChildScope;
  45614. }
  45615. const scope = createChildScope(parentScope);
  45616. if (node.body.type === "TSModuleDeclaration") {
  45617. const decl = node.body;
  45618. decl._ownerScope = scope;
  45619. const id = getId(decl.id);
  45620. scope.types[id] = scope.exportedTypes[id] = decl;
  45621. } else {
  45622. recordTypes(ctx, node.body.body, scope);
  45623. }
  45624. return node._resolvedChildScope = scope;
  45625. }
  45626. function createChildScope(parentScope) {
  45627. return new TypeScope(
  45628. parentScope.filename,
  45629. parentScope.source,
  45630. parentScope.offset,
  45631. Object.create(parentScope.imports),
  45632. Object.create(parentScope.types),
  45633. Object.create(parentScope.declares)
  45634. );
  45635. }
  45636. const importExportRE = /^Import|^Export/;
  45637. function recordTypes(ctx, body, scope, asGlobal = false) {
  45638. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45639. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45640. for (const stmt of body) {
  45641. if (asGlobal) {
  45642. if (isAmbient) {
  45643. if (stmt.declare) {
  45644. recordType(stmt, types, declares);
  45645. }
  45646. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45647. for (const s of stmt.body.body) {
  45648. recordType(s, types, declares);
  45649. }
  45650. }
  45651. } else {
  45652. recordType(stmt, types, declares);
  45653. }
  45654. }
  45655. if (!asGlobal) {
  45656. for (const stmt of body) {
  45657. if (stmt.type === "ExportNamedDeclaration") {
  45658. if (stmt.declaration) {
  45659. recordType(stmt.declaration, types, declares);
  45660. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45661. } else {
  45662. for (const spec of stmt.specifiers) {
  45663. if (spec.type === "ExportSpecifier") {
  45664. const local = spec.local.name;
  45665. const exported = getId(spec.exported);
  45666. if (stmt.source) {
  45667. imports[exported] = {
  45668. source: stmt.source.value,
  45669. imported: local
  45670. };
  45671. exportedTypes[exported] = {
  45672. type: "TSTypeReference",
  45673. typeName: {
  45674. type: "Identifier",
  45675. name: local
  45676. },
  45677. _ownerScope: scope
  45678. };
  45679. } else if (types[local]) {
  45680. exportedTypes[exported] = types[local];
  45681. }
  45682. }
  45683. }
  45684. }
  45685. } else if (stmt.type === "ExportAllDeclaration") {
  45686. const sourceScope = importSourceToScope(
  45687. ctx,
  45688. stmt.source,
  45689. scope,
  45690. stmt.source.value
  45691. );
  45692. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45693. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45694. if (stmt.declaration.type !== "Identifier") {
  45695. recordType(stmt.declaration, types, declares, "default");
  45696. recordType(
  45697. stmt.declaration,
  45698. exportedTypes,
  45699. exportedDeclares,
  45700. "default"
  45701. );
  45702. } else if (types[stmt.declaration.name]) {
  45703. exportedTypes["default"] = types[stmt.declaration.name];
  45704. }
  45705. }
  45706. }
  45707. }
  45708. for (const key of Object.keys(types)) {
  45709. const node = types[key];
  45710. node._ownerScope = scope;
  45711. if (node._ns) node._ns._ownerScope = scope;
  45712. }
  45713. for (const key of Object.keys(declares)) {
  45714. declares[key]._ownerScope = scope;
  45715. }
  45716. }
  45717. function recordType(node, types, declares, overwriteId) {
  45718. switch (node.type) {
  45719. case "TSInterfaceDeclaration":
  45720. case "TSEnumDeclaration":
  45721. case "TSModuleDeclaration": {
  45722. const id = overwriteId || getId(node.id);
  45723. let existing = types[id];
  45724. if (existing) {
  45725. if (node.type === "TSModuleDeclaration") {
  45726. if (existing.type === "TSModuleDeclaration") {
  45727. mergeNamespaces(existing, node);
  45728. } else {
  45729. attachNamespace(existing, node);
  45730. }
  45731. break;
  45732. }
  45733. if (existing.type === "TSModuleDeclaration") {
  45734. types[id] = node;
  45735. attachNamespace(node, existing);
  45736. break;
  45737. }
  45738. if (existing.type !== node.type) {
  45739. break;
  45740. }
  45741. if (node.type === "TSInterfaceDeclaration") {
  45742. existing.body.body.push(...node.body.body);
  45743. } else {
  45744. existing.members.push(...node.members);
  45745. }
  45746. } else {
  45747. types[id] = node;
  45748. }
  45749. break;
  45750. }
  45751. case "ClassDeclaration":
  45752. if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
  45753. break;
  45754. case "TSTypeAliasDeclaration":
  45755. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  45756. break;
  45757. case "TSDeclareFunction":
  45758. if (node.id) declares[node.id.name] = node;
  45759. break;
  45760. case "VariableDeclaration": {
  45761. if (node.declare) {
  45762. for (const decl of node.declarations) {
  45763. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  45764. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  45765. }
  45766. }
  45767. }
  45768. break;
  45769. }
  45770. }
  45771. }
  45772. function mergeNamespaces(to, from) {
  45773. const toBody = to.body;
  45774. const fromBody = from.body;
  45775. if (toBody.type === "TSModuleDeclaration") {
  45776. if (fromBody.type === "TSModuleDeclaration") {
  45777. mergeNamespaces(toBody, fromBody);
  45778. } else {
  45779. fromBody.body.push({
  45780. type: "ExportNamedDeclaration",
  45781. declaration: toBody,
  45782. exportKind: "type",
  45783. specifiers: []
  45784. });
  45785. }
  45786. } else if (fromBody.type === "TSModuleDeclaration") {
  45787. toBody.body.push({
  45788. type: "ExportNamedDeclaration",
  45789. declaration: fromBody,
  45790. exportKind: "type",
  45791. specifiers: []
  45792. });
  45793. } else {
  45794. toBody.body.push(...fromBody.body);
  45795. }
  45796. }
  45797. function attachNamespace(to, ns) {
  45798. if (!to._ns) {
  45799. to._ns = ns;
  45800. } else {
  45801. mergeNamespaces(to._ns, ns);
  45802. }
  45803. }
  45804. function recordImports(body) {
  45805. const imports = /* @__PURE__ */ Object.create(null);
  45806. for (const s of body) {
  45807. recordImport(s, imports);
  45808. }
  45809. return imports;
  45810. }
  45811. function recordImport(node, imports) {
  45812. if (node.type !== "ImportDeclaration") {
  45813. return;
  45814. }
  45815. for (const s of node.specifiers) {
  45816. imports[s.local.name] = {
  45817. imported: getImportedName(s),
  45818. source: node.source.value
  45819. };
  45820. }
  45821. }
  45822. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
  45823. try {
  45824. switch (node.type) {
  45825. case "TSStringKeyword":
  45826. return ["String"];
  45827. case "TSNumberKeyword":
  45828. return ["Number"];
  45829. case "TSBooleanKeyword":
  45830. return ["Boolean"];
  45831. case "TSObjectKeyword":
  45832. return ["Object"];
  45833. case "TSNullKeyword":
  45834. return ["null"];
  45835. case "TSTypeLiteral":
  45836. case "TSInterfaceDeclaration": {
  45837. const types = /* @__PURE__ */ new Set();
  45838. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  45839. for (const m of members) {
  45840. if (isKeyOf) {
  45841. if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
  45842. types.add("Number");
  45843. } else if (m.type === "TSIndexSignature") {
  45844. const annotation = m.parameters[0].typeAnnotation;
  45845. if (annotation && annotation.type !== "Noop") {
  45846. const type = inferRuntimeType(
  45847. ctx,
  45848. annotation.typeAnnotation,
  45849. scope
  45850. )[0];
  45851. if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
  45852. types.add(type);
  45853. }
  45854. } else {
  45855. types.add("String");
  45856. }
  45857. } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  45858. types.add("Function");
  45859. } else {
  45860. types.add("Object");
  45861. }
  45862. }
  45863. return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
  45864. }
  45865. case "TSPropertySignature":
  45866. if (node.typeAnnotation) {
  45867. return inferRuntimeType(
  45868. ctx,
  45869. node.typeAnnotation.typeAnnotation,
  45870. scope
  45871. );
  45872. }
  45873. break;
  45874. case "TSMethodSignature":
  45875. case "TSFunctionType":
  45876. return ["Function"];
  45877. case "TSArrayType":
  45878. case "TSTupleType":
  45879. return ["Array"];
  45880. case "TSLiteralType":
  45881. switch (node.literal.type) {
  45882. case "StringLiteral":
  45883. return ["String"];
  45884. case "BooleanLiteral":
  45885. return ["Boolean"];
  45886. case "NumericLiteral":
  45887. case "BigIntLiteral":
  45888. return ["Number"];
  45889. default:
  45890. return [UNKNOWN_TYPE];
  45891. }
  45892. case "TSTypeReference": {
  45893. const resolved = resolveTypeReference(ctx, node, scope);
  45894. if (resolved) {
  45895. if (resolved.type === "TSTypeAliasDeclaration") {
  45896. if (resolved.typeAnnotation.type === "TSFunctionType") {
  45897. return ["Function"];
  45898. }
  45899. if (node.typeParameters) {
  45900. const typeParams = /* @__PURE__ */ Object.create(null);
  45901. if (resolved.typeParameters) {
  45902. resolved.typeParameters.params.forEach((p, i) => {
  45903. typeParams[p.name] = node.typeParameters.params[i];
  45904. });
  45905. }
  45906. return inferRuntimeType(
  45907. ctx,
  45908. resolved.typeAnnotation,
  45909. resolved._ownerScope,
  45910. isKeyOf,
  45911. typeParams
  45912. );
  45913. }
  45914. }
  45915. return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
  45916. }
  45917. if (node.typeName.type === "Identifier") {
  45918. if (typeParameters && typeParameters[node.typeName.name]) {
  45919. return inferRuntimeType(
  45920. ctx,
  45921. typeParameters[node.typeName.name],
  45922. scope,
  45923. isKeyOf,
  45924. typeParameters
  45925. );
  45926. }
  45927. if (isKeyOf) {
  45928. switch (node.typeName.name) {
  45929. case "String":
  45930. case "Array":
  45931. case "ArrayLike":
  45932. case "Parameters":
  45933. case "ConstructorParameters":
  45934. case "ReadonlyArray":
  45935. return ["String", "Number"];
  45936. // TS built-in utility types
  45937. case "Record":
  45938. case "Partial":
  45939. case "Required":
  45940. case "Readonly":
  45941. if (node.typeParameters && node.typeParameters.params[0]) {
  45942. return inferRuntimeType(
  45943. ctx,
  45944. node.typeParameters.params[0],
  45945. scope,
  45946. true
  45947. );
  45948. }
  45949. break;
  45950. case "Pick":
  45951. case "Extract":
  45952. if (node.typeParameters && node.typeParameters.params[1]) {
  45953. return inferRuntimeType(
  45954. ctx,
  45955. node.typeParameters.params[1],
  45956. scope
  45957. );
  45958. }
  45959. break;
  45960. case "Function":
  45961. case "Object":
  45962. case "Set":
  45963. case "Map":
  45964. case "WeakSet":
  45965. case "WeakMap":
  45966. case "Date":
  45967. case "Promise":
  45968. case "Error":
  45969. case "Uppercase":
  45970. case "Lowercase":
  45971. case "Capitalize":
  45972. case "Uncapitalize":
  45973. case "ReadonlyMap":
  45974. case "ReadonlySet":
  45975. return ["String"];
  45976. }
  45977. } else {
  45978. switch (node.typeName.name) {
  45979. case "Array":
  45980. case "Function":
  45981. case "Object":
  45982. case "Set":
  45983. case "Map":
  45984. case "WeakSet":
  45985. case "WeakMap":
  45986. case "Date":
  45987. case "Promise":
  45988. case "Error":
  45989. return [node.typeName.name];
  45990. // TS built-in utility types
  45991. // https://www.typescriptlang.org/docs/handbook/utility-types.html
  45992. case "Partial":
  45993. case "Required":
  45994. case "Readonly":
  45995. case "Record":
  45996. case "Pick":
  45997. case "Omit":
  45998. case "InstanceType":
  45999. return ["Object"];
  46000. case "Uppercase":
  46001. case "Lowercase":
  46002. case "Capitalize":
  46003. case "Uncapitalize":
  46004. return ["String"];
  46005. case "Parameters":
  46006. case "ConstructorParameters":
  46007. case "ReadonlyArray":
  46008. return ["Array"];
  46009. case "ReadonlyMap":
  46010. return ["Map"];
  46011. case "ReadonlySet":
  46012. return ["Set"];
  46013. case "NonNullable":
  46014. if (node.typeParameters && node.typeParameters.params[0]) {
  46015. return inferRuntimeType(
  46016. ctx,
  46017. node.typeParameters.params[0],
  46018. scope
  46019. ).filter((t) => t !== "null");
  46020. }
  46021. break;
  46022. case "Extract":
  46023. if (node.typeParameters && node.typeParameters.params[1]) {
  46024. return inferRuntimeType(
  46025. ctx,
  46026. node.typeParameters.params[1],
  46027. scope
  46028. );
  46029. }
  46030. break;
  46031. case "Exclude":
  46032. case "OmitThisParameter":
  46033. if (node.typeParameters && node.typeParameters.params[0]) {
  46034. return inferRuntimeType(
  46035. ctx,
  46036. node.typeParameters.params[0],
  46037. scope
  46038. );
  46039. }
  46040. break;
  46041. }
  46042. }
  46043. }
  46044. break;
  46045. }
  46046. case "TSParenthesizedType":
  46047. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  46048. case "TSUnionType":
  46049. return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
  46050. case "TSIntersectionType": {
  46051. return flattenTypes(
  46052. ctx,
  46053. node.types,
  46054. scope,
  46055. isKeyOf,
  46056. typeParameters
  46057. ).filter((t) => t !== UNKNOWN_TYPE);
  46058. }
  46059. case "TSEnumDeclaration":
  46060. return inferEnumType(node);
  46061. case "TSSymbolKeyword":
  46062. return ["Symbol"];
  46063. case "TSIndexedAccessType": {
  46064. const types = resolveIndexType(ctx, node, scope);
  46065. return flattenTypes(ctx, types, scope, isKeyOf);
  46066. }
  46067. case "ClassDeclaration":
  46068. return ["Object"];
  46069. case "TSImportType": {
  46070. const sourceScope = importSourceToScope(
  46071. ctx,
  46072. node.argument,
  46073. scope,
  46074. node.argument.value
  46075. );
  46076. const resolved = resolveTypeReference(ctx, node, sourceScope);
  46077. if (resolved) {
  46078. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  46079. }
  46080. break;
  46081. }
  46082. case "TSTypeQuery": {
  46083. const id = node.exprName;
  46084. if (id.type === "Identifier") {
  46085. const matched = scope.declares[id.name];
  46086. if (matched) {
  46087. return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
  46088. }
  46089. }
  46090. break;
  46091. }
  46092. // e.g. readonly
  46093. case "TSTypeOperator": {
  46094. return inferRuntimeType(
  46095. ctx,
  46096. node.typeAnnotation,
  46097. scope,
  46098. node.operator === "keyof"
  46099. );
  46100. }
  46101. case "TSAnyKeyword": {
  46102. if (isKeyOf) {
  46103. return ["String", "Number", "Symbol"];
  46104. }
  46105. break;
  46106. }
  46107. }
  46108. } catch (e) {
  46109. }
  46110. return [UNKNOWN_TYPE];
  46111. }
  46112. function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
  46113. if (types.length === 1) {
  46114. return inferRuntimeType(ctx, types[0], scope, isKeyOf, typeParameters);
  46115. }
  46116. return [
  46117. ...new Set(
  46118. [].concat(
  46119. ...types.map(
  46120. (t) => inferRuntimeType(ctx, t, scope, isKeyOf, typeParameters)
  46121. )
  46122. )
  46123. )
  46124. ];
  46125. }
  46126. function inferEnumType(node) {
  46127. const types = /* @__PURE__ */ new Set();
  46128. for (const m of node.members) {
  46129. if (m.initializer) {
  46130. switch (m.initializer.type) {
  46131. case "StringLiteral":
  46132. types.add("String");
  46133. break;
  46134. case "NumericLiteral":
  46135. types.add("Number");
  46136. break;
  46137. }
  46138. }
  46139. }
  46140. return types.size ? [...types] : ["Number"];
  46141. }
  46142. function resolveExtractPropTypes({ props }, scope) {
  46143. const res = { props: {} };
  46144. for (const key in props) {
  46145. const raw = props[key];
  46146. res.props[key] = reverseInferType(
  46147. raw.key,
  46148. raw.typeAnnotation.typeAnnotation,
  46149. scope
  46150. );
  46151. }
  46152. return res;
  46153. }
  46154. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  46155. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  46156. const typeType = findStaticPropertyType(node, "type");
  46157. if (typeType) {
  46158. const requiredType = findStaticPropertyType(node, "required");
  46159. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  46160. return reverseInferType(key, typeType, scope, optional2, false);
  46161. }
  46162. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  46163. if (node.typeName.name.endsWith("Constructor")) {
  46164. return createProperty(
  46165. key,
  46166. ctorToType(node.typeName.name),
  46167. scope,
  46168. optional
  46169. );
  46170. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  46171. return createProperty(key, node.typeParameters.params[0], scope, optional);
  46172. }
  46173. }
  46174. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  46175. for (const t of node.typeParameters.params) {
  46176. const inferred = reverseInferType(key, t, scope, optional);
  46177. if (inferred) return inferred;
  46178. }
  46179. }
  46180. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  46181. }
  46182. function ctorToType(ctorType) {
  46183. const ctor = ctorType.slice(0, -11);
  46184. switch (ctor) {
  46185. case "String":
  46186. case "Number":
  46187. case "Boolean":
  46188. return { type: `TS${ctor}Keyword` };
  46189. case "Array":
  46190. case "Function":
  46191. case "Object":
  46192. case "Set":
  46193. case "Map":
  46194. case "WeakSet":
  46195. case "WeakMap":
  46196. case "Date":
  46197. case "Promise":
  46198. return {
  46199. type: "TSTypeReference",
  46200. typeName: { type: "Identifier", name: ctor }
  46201. };
  46202. }
  46203. return { type: `TSNullKeyword` };
  46204. }
  46205. function findStaticPropertyType(node, key) {
  46206. const prop = node.members.find(
  46207. (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
  46208. );
  46209. return prop && prop.typeAnnotation.typeAnnotation;
  46210. }
  46211. function resolveReturnType(ctx, arg, scope) {
  46212. var _a;
  46213. let resolved = arg;
  46214. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  46215. resolved = resolveTypeReference(ctx, arg, scope);
  46216. }
  46217. if (!resolved) return;
  46218. if (resolved.type === "TSFunctionType") {
  46219. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  46220. }
  46221. if (resolved.type === "TSDeclareFunction") {
  46222. return resolved.returnType;
  46223. }
  46224. }
  46225. function resolveUnionType(ctx, node, scope) {
  46226. if (node.type === "TSTypeReference") {
  46227. const resolved = resolveTypeReference(ctx, node, scope);
  46228. if (resolved) node = resolved;
  46229. }
  46230. let types;
  46231. if (node.type === "TSUnionType") {
  46232. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  46233. } else {
  46234. types = [node];
  46235. }
  46236. return types;
  46237. }
  46238. const DEFINE_MODEL = "defineModel";
  46239. function processDefineModel(ctx, node, declId) {
  46240. if (!isCallOf(node, DEFINE_MODEL)) {
  46241. return false;
  46242. }
  46243. ctx.hasDefineModelCall = true;
  46244. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  46245. let modelName;
  46246. let options;
  46247. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  46248. const hasName = arg0 && arg0.type === "StringLiteral";
  46249. if (hasName) {
  46250. modelName = arg0.value;
  46251. options = node.arguments[1];
  46252. } else {
  46253. modelName = "modelValue";
  46254. options = arg0;
  46255. }
  46256. if (ctx.modelDecls[modelName]) {
  46257. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  46258. }
  46259. let optionsString = options && ctx.getString(options);
  46260. let optionsRemoved = !options;
  46261. const runtimeOptionNodes = [];
  46262. if (options && options.type === "ObjectExpression" && !options.properties.some((p) => p.type === "SpreadElement" || p.computed)) {
  46263. let removed = 0;
  46264. for (let i = options.properties.length - 1; i >= 0; i--) {
  46265. const p = options.properties[i];
  46266. const next = options.properties[i + 1];
  46267. const start = p.start;
  46268. const end = next ? next.start : options.end - 1;
  46269. 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"))) {
  46270. optionsString = optionsString.slice(0, start - options.start) + optionsString.slice(end - options.start);
  46271. } else {
  46272. removed++;
  46273. ctx.s.remove(ctx.startOffset + start, ctx.startOffset + end);
  46274. runtimeOptionNodes.push(p);
  46275. }
  46276. }
  46277. if (removed === options.properties.length) {
  46278. optionsRemoved = true;
  46279. ctx.s.remove(
  46280. ctx.startOffset + (hasName ? arg0.end : options.start),
  46281. ctx.startOffset + options.end
  46282. );
  46283. }
  46284. }
  46285. ctx.modelDecls[modelName] = {
  46286. type,
  46287. options: optionsString,
  46288. runtimeOptionNodes,
  46289. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  46290. };
  46291. ctx.bindingMetadata[modelName] = "props";
  46292. ctx.s.overwrite(
  46293. ctx.startOffset + node.callee.start,
  46294. ctx.startOffset + node.callee.end,
  46295. ctx.helper("useModel")
  46296. );
  46297. ctx.s.appendLeft(
  46298. ctx.startOffset + (node.arguments.length ? node.arguments[0].start : node.end - 1),
  46299. `__props, ` + (hasName ? `` : `${JSON.stringify(modelName)}${optionsRemoved ? `` : `, `}`)
  46300. );
  46301. return true;
  46302. }
  46303. function genModelProps(ctx) {
  46304. if (!ctx.hasDefineModelCall) return;
  46305. const isProd = !!ctx.options.isProd;
  46306. let modelPropsDecl = "";
  46307. for (const [name, { type, options: runtimeOptions }] of Object.entries(
  46308. ctx.modelDecls
  46309. )) {
  46310. let skipCheck = false;
  46311. let codegenOptions = ``;
  46312. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46313. if (runtimeTypes) {
  46314. const hasBoolean = runtimeTypes.includes("Boolean");
  46315. const hasFunction = runtimeTypes.includes("Function");
  46316. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46317. if (hasUnknownType) {
  46318. if (hasBoolean || hasFunction) {
  46319. runtimeTypes = runtimeTypes.filter((t) => t !== UNKNOWN_TYPE);
  46320. skipCheck = true;
  46321. } else {
  46322. runtimeTypes = ["null"];
  46323. }
  46324. }
  46325. if (!isProd) {
  46326. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}` + (skipCheck ? ", skipCheck: true" : "");
  46327. } else if (hasBoolean || runtimeOptions && hasFunction) {
  46328. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}`;
  46329. } else ;
  46330. }
  46331. let decl;
  46332. if (codegenOptions && runtimeOptions) {
  46333. decl = ctx.isTS ? `{ ${codegenOptions}, ...${runtimeOptions} }` : `Object.assign({ ${codegenOptions} }, ${runtimeOptions})`;
  46334. } else if (codegenOptions) {
  46335. decl = `{ ${codegenOptions} }`;
  46336. } else if (runtimeOptions) {
  46337. decl = runtimeOptions;
  46338. } else {
  46339. decl = `{}`;
  46340. }
  46341. modelPropsDecl += `
  46342. ${JSON.stringify(name)}: ${decl},`;
  46343. const modifierPropName = JSON.stringify(
  46344. name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
  46345. );
  46346. modelPropsDecl += `
  46347. ${modifierPropName}: {},`;
  46348. }
  46349. return `{${modelPropsDecl}
  46350. }`;
  46351. }
  46352. const DEFINE_PROPS = "defineProps";
  46353. const WITH_DEFAULTS = "withDefaults";
  46354. function processDefineProps(ctx, node, declId, isWithDefaults = false) {
  46355. if (!isCallOf(node, DEFINE_PROPS)) {
  46356. return processWithDefaults(ctx, node, declId);
  46357. }
  46358. if (ctx.hasDefinePropsCall) {
  46359. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46360. }
  46361. ctx.hasDefinePropsCall = true;
  46362. ctx.propsRuntimeDecl = node.arguments[0];
  46363. if (ctx.propsRuntimeDecl) {
  46364. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46365. if (!(key in ctx.bindingMetadata)) {
  46366. ctx.bindingMetadata[key] = "props";
  46367. }
  46368. }
  46369. }
  46370. if (node.typeParameters) {
  46371. if (ctx.propsRuntimeDecl) {
  46372. ctx.error(
  46373. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46374. node
  46375. );
  46376. }
  46377. ctx.propsTypeDecl = node.typeParameters.params[0];
  46378. }
  46379. if (!isWithDefaults && declId && declId.type === "ObjectPattern") {
  46380. processPropsDestructure(ctx, declId);
  46381. }
  46382. ctx.propsCall = node;
  46383. ctx.propsDecl = declId;
  46384. return true;
  46385. }
  46386. function processWithDefaults(ctx, node, declId) {
  46387. if (!isCallOf(node, WITH_DEFAULTS)) {
  46388. return false;
  46389. }
  46390. if (!processDefineProps(
  46391. ctx,
  46392. node.arguments[0],
  46393. declId,
  46394. true
  46395. )) {
  46396. ctx.error(
  46397. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46398. node.arguments[0] || node
  46399. );
  46400. }
  46401. if (ctx.propsRuntimeDecl) {
  46402. ctx.error(
  46403. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46404. node
  46405. );
  46406. }
  46407. if (declId && declId.type === "ObjectPattern") {
  46408. ctx.warn(
  46409. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46410. Reactive destructure will be disabled when using withDefaults().
  46411. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `,
  46412. node.callee
  46413. );
  46414. }
  46415. ctx.propsRuntimeDefaults = node.arguments[1];
  46416. if (!ctx.propsRuntimeDefaults) {
  46417. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46418. }
  46419. ctx.propsCall = node;
  46420. return true;
  46421. }
  46422. function genRuntimeProps(ctx) {
  46423. let propsDecls;
  46424. if (ctx.propsRuntimeDecl) {
  46425. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46426. if (ctx.propsDestructureDecl) {
  46427. const defaults = [];
  46428. for (const key in ctx.propsDestructuredBindings) {
  46429. const d = genDestructuredDefaultValue(ctx, key);
  46430. const finalKey = getEscapedPropName(key);
  46431. if (d)
  46432. defaults.push(
  46433. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46434. );
  46435. }
  46436. if (defaults.length) {
  46437. propsDecls = `/*@__PURE__*/${ctx.helper(
  46438. `mergeDefaults`
  46439. )}(${propsDecls}, {
  46440. ${defaults.join(",\n ")}
  46441. })`;
  46442. }
  46443. }
  46444. } else if (ctx.propsTypeDecl) {
  46445. propsDecls = extractRuntimeProps(ctx);
  46446. }
  46447. const modelsDecls = genModelProps(ctx);
  46448. if (propsDecls && modelsDecls) {
  46449. return `/*@__PURE__*/${ctx.helper(
  46450. "mergeModels"
  46451. )}(${propsDecls}, ${modelsDecls})`;
  46452. } else {
  46453. return modelsDecls || propsDecls;
  46454. }
  46455. }
  46456. function extractRuntimeProps(ctx) {
  46457. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46458. if (!props.length) {
  46459. return;
  46460. }
  46461. const propStrings = [];
  46462. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46463. for (const prop of props) {
  46464. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46465. if ("bindingMetadata" in ctx && !(prop.key in ctx.bindingMetadata)) {
  46466. ctx.bindingMetadata[prop.key] = "props";
  46467. }
  46468. }
  46469. let propsDecls = `{
  46470. ${propStrings.join(",\n ")}
  46471. }`;
  46472. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46473. propsDecls = `/*@__PURE__*/${ctx.helper(
  46474. "mergeDefaults"
  46475. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46476. }
  46477. return propsDecls;
  46478. }
  46479. function resolveRuntimePropsFromType(ctx, node) {
  46480. const props = [];
  46481. const elements = resolveTypeElements(ctx, node);
  46482. for (const key in elements.props) {
  46483. const e = elements.props[key];
  46484. let type = inferRuntimeType(ctx, e);
  46485. let skipCheck = false;
  46486. if (type.includes(UNKNOWN_TYPE)) {
  46487. if (type.includes("Boolean") || type.includes("Function")) {
  46488. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46489. skipCheck = true;
  46490. } else {
  46491. type = ["null"];
  46492. }
  46493. }
  46494. props.push({
  46495. key,
  46496. required: !e.optional,
  46497. type: type || [`null`],
  46498. skipCheck
  46499. });
  46500. }
  46501. return props;
  46502. }
  46503. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46504. let defaultString;
  46505. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46506. if (destructured) {
  46507. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46508. } else if (hasStaticDefaults) {
  46509. const prop = ctx.propsRuntimeDefaults.properties.find(
  46510. (node) => {
  46511. if (node.type === "SpreadElement") return false;
  46512. return resolveObjectKey(node.key, node.computed) === key;
  46513. }
  46514. );
  46515. if (prop) {
  46516. if (prop.type === "ObjectProperty") {
  46517. defaultString = `default: ${ctx.getString(prop.value)}`;
  46518. } else {
  46519. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
  46520. }
  46521. }
  46522. }
  46523. const finalKey = getEscapedPropName(key);
  46524. if (!ctx.options.isProd) {
  46525. return `${finalKey}: { ${concatStrings([
  46526. `type: ${toRuntimeTypeString(type)}`,
  46527. `required: ${required}`,
  46528. skipCheck && "skipCheck: true",
  46529. defaultString
  46530. ])} }`;
  46531. } else if (type.some(
  46532. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46533. )) {
  46534. return `${finalKey}: { ${concatStrings([
  46535. `type: ${toRuntimeTypeString(type)}`,
  46536. defaultString
  46537. ])} }`;
  46538. } else {
  46539. if (ctx.isCE) {
  46540. if (defaultString) {
  46541. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46542. type
  46543. )} }`}`;
  46544. } else {
  46545. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46546. }
  46547. }
  46548. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46549. }
  46550. }
  46551. function hasStaticWithDefaults(ctx) {
  46552. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46553. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46554. ));
  46555. }
  46556. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46557. const destructured = ctx.propsDestructuredBindings[key];
  46558. const defaultVal = destructured && destructured.default;
  46559. if (defaultVal) {
  46560. const value = ctx.getString(defaultVal);
  46561. const unwrapped = unwrapTSNode(defaultVal);
  46562. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46563. const valueType = inferValueType(unwrapped);
  46564. if (valueType && !inferredType.includes(valueType)) {
  46565. ctx.error(
  46566. `Default value of prop "${key}" does not match declared type.`,
  46567. unwrapped
  46568. );
  46569. }
  46570. }
  46571. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46572. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46573. return {
  46574. valueString: needFactoryWrap ? `() => (${value})` : value,
  46575. needSkipFactory
  46576. };
  46577. }
  46578. }
  46579. function inferValueType(node) {
  46580. switch (node.type) {
  46581. case "StringLiteral":
  46582. return "String";
  46583. case "NumericLiteral":
  46584. return "Number";
  46585. case "BooleanLiteral":
  46586. return "Boolean";
  46587. case "ObjectExpression":
  46588. return "Object";
  46589. case "ArrayExpression":
  46590. return "Array";
  46591. case "FunctionExpression":
  46592. case "ArrowFunctionExpression":
  46593. return "Function";
  46594. }
  46595. }
  46596. function processPropsDestructure(ctx, declId) {
  46597. if (ctx.options.propsDestructure === "error") {
  46598. ctx.error(`Props destructure is explicitly prohibited via config.`, declId);
  46599. } else if (ctx.options.propsDestructure === false) {
  46600. return;
  46601. }
  46602. ctx.propsDestructureDecl = declId;
  46603. const registerBinding = (key, local, defaultValue) => {
  46604. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  46605. if (local !== key) {
  46606. ctx.bindingMetadata[local] = "props-aliased";
  46607. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  46608. }
  46609. };
  46610. for (const prop of declId.properties) {
  46611. if (prop.type === "ObjectProperty") {
  46612. const propKey = resolveObjectKey(prop.key, prop.computed);
  46613. if (!propKey) {
  46614. ctx.error(
  46615. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  46616. prop.key
  46617. );
  46618. }
  46619. if (prop.value.type === "AssignmentPattern") {
  46620. const { left, right } = prop.value;
  46621. if (left.type !== "Identifier") {
  46622. ctx.error(
  46623. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46624. left
  46625. );
  46626. }
  46627. registerBinding(propKey, left.name, right);
  46628. } else if (prop.value.type === "Identifier") {
  46629. registerBinding(propKey, prop.value.name);
  46630. } else {
  46631. ctx.error(
  46632. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46633. prop.value
  46634. );
  46635. }
  46636. } else {
  46637. ctx.propsDestructureRestId = prop.argument.name;
  46638. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  46639. }
  46640. }
  46641. }
  46642. function transformDestructuredProps(ctx, vueImportAliases) {
  46643. if (ctx.options.propsDestructure === false) {
  46644. return;
  46645. }
  46646. const rootScope = /* @__PURE__ */ Object.create(null);
  46647. const scopeStack = [rootScope];
  46648. let currentScope = rootScope;
  46649. const excludedIds = /* @__PURE__ */ new WeakSet();
  46650. const parentStack = [];
  46651. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  46652. for (const key in ctx.propsDestructuredBindings) {
  46653. const { local } = ctx.propsDestructuredBindings[key];
  46654. rootScope[local] = true;
  46655. propsLocalToPublicMap[local] = key;
  46656. }
  46657. function pushScope() {
  46658. scopeStack.push(currentScope = Object.create(currentScope));
  46659. }
  46660. function popScope() {
  46661. scopeStack.pop();
  46662. currentScope = scopeStack[scopeStack.length - 1] || null;
  46663. }
  46664. function registerLocalBinding(id) {
  46665. excludedIds.add(id);
  46666. if (currentScope) {
  46667. currentScope[id.name] = false;
  46668. } else {
  46669. ctx.error(
  46670. "registerBinding called without active scope, something is wrong.",
  46671. id
  46672. );
  46673. }
  46674. }
  46675. function walkScope(node, isRoot = false) {
  46676. for (const stmt of node.body) {
  46677. if (stmt.type === "VariableDeclaration") {
  46678. walkVariableDeclaration(stmt, isRoot);
  46679. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  46680. if (stmt.declare || !stmt.id) continue;
  46681. registerLocalBinding(stmt.id);
  46682. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  46683. walkVariableDeclaration(stmt.left);
  46684. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  46685. walkVariableDeclaration(stmt.declaration, isRoot);
  46686. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  46687. walkVariableDeclaration(stmt.body, isRoot);
  46688. }
  46689. }
  46690. }
  46691. function walkVariableDeclaration(stmt, isRoot = false) {
  46692. if (stmt.declare) {
  46693. return;
  46694. }
  46695. for (const decl of stmt.declarations) {
  46696. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  46697. for (const id of extractIdentifiers$1(decl.id)) {
  46698. if (isDefineProps) {
  46699. excludedIds.add(id);
  46700. } else {
  46701. registerLocalBinding(id);
  46702. }
  46703. }
  46704. }
  46705. }
  46706. function rewriteId(id, parent, parentStack2) {
  46707. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  46708. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  46709. }
  46710. if (isStaticProperty(parent) && parent.shorthand) {
  46711. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  46712. ctx.s.appendLeft(
  46713. id.end + ctx.startOffset,
  46714. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  46715. );
  46716. }
  46717. } else {
  46718. ctx.s.overwrite(
  46719. id.start + ctx.startOffset,
  46720. id.end + ctx.startOffset,
  46721. genPropsAccessExp(propsLocalToPublicMap[id.name])
  46722. );
  46723. }
  46724. }
  46725. function checkUsage(node, method, alias = method) {
  46726. if (isCallOf(node, alias)) {
  46727. const arg = unwrapTSNode(node.arguments[0]);
  46728. if (arg.type === "Identifier" && currentScope[arg.name]) {
  46729. ctx.error(
  46730. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  46731. arg
  46732. );
  46733. }
  46734. }
  46735. }
  46736. const ast = ctx.scriptSetupAst;
  46737. walkScope(ast, true);
  46738. walk$2(ast, {
  46739. enter(node, parent) {
  46740. parent && parentStack.push(parent);
  46741. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  46742. return this.skip();
  46743. }
  46744. checkUsage(node, "watch", vueImportAliases.watch);
  46745. checkUsage(node, "toRef", vueImportAliases.toRef);
  46746. if (isFunctionType(node)) {
  46747. pushScope();
  46748. walkFunctionParams(node, registerLocalBinding);
  46749. if (node.body.type === "BlockStatement") {
  46750. walkScope(node.body);
  46751. }
  46752. return;
  46753. }
  46754. if (node.type === "CatchClause") {
  46755. pushScope();
  46756. if (node.param && node.param.type === "Identifier") {
  46757. registerLocalBinding(node.param);
  46758. }
  46759. walkScope(node.body);
  46760. return;
  46761. }
  46762. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  46763. pushScope();
  46764. walkScope(node);
  46765. return;
  46766. }
  46767. if (node.type === "Identifier") {
  46768. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  46769. if (currentScope[node.name]) {
  46770. rewriteId(node, parent, parentStack);
  46771. }
  46772. }
  46773. }
  46774. },
  46775. leave(node, parent) {
  46776. parent && parentStack.pop();
  46777. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node) || node.type === "CatchClause") {
  46778. popScope();
  46779. }
  46780. }
  46781. });
  46782. }
  46783. const DEFINE_EMITS = "defineEmits";
  46784. function processDefineEmits(ctx, node, declId) {
  46785. if (!isCallOf(node, DEFINE_EMITS)) {
  46786. return false;
  46787. }
  46788. if (ctx.hasDefineEmitCall) {
  46789. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  46790. }
  46791. ctx.hasDefineEmitCall = true;
  46792. ctx.emitsRuntimeDecl = node.arguments[0];
  46793. if (node.typeParameters) {
  46794. if (ctx.emitsRuntimeDecl) {
  46795. ctx.error(
  46796. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46797. node
  46798. );
  46799. }
  46800. ctx.emitsTypeDecl = node.typeParameters.params[0];
  46801. }
  46802. ctx.emitDecl = declId;
  46803. return true;
  46804. }
  46805. function genRuntimeEmits(ctx) {
  46806. let emitsDecl = "";
  46807. if (ctx.emitsRuntimeDecl) {
  46808. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  46809. } else if (ctx.emitsTypeDecl) {
  46810. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  46811. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  46812. }
  46813. if (ctx.hasDefineModelCall) {
  46814. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  46815. emitsDecl = emitsDecl ? `/*@__PURE__*/${ctx.helper(
  46816. "mergeModels"
  46817. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  46818. }
  46819. return emitsDecl;
  46820. }
  46821. function extractRuntimeEmits(ctx) {
  46822. const emits = /* @__PURE__ */ new Set();
  46823. const node = ctx.emitsTypeDecl;
  46824. if (node.type === "TSFunctionType") {
  46825. extractEventNames(ctx, node.parameters[0], emits);
  46826. return emits;
  46827. }
  46828. const { props, calls } = resolveTypeElements(ctx, node);
  46829. let hasProperty = false;
  46830. for (const key in props) {
  46831. emits.add(key);
  46832. hasProperty = true;
  46833. }
  46834. if (calls) {
  46835. if (hasProperty) {
  46836. ctx.error(
  46837. `defineEmits() type cannot mixed call signature and property syntax.`,
  46838. node
  46839. );
  46840. }
  46841. for (const call of calls) {
  46842. extractEventNames(ctx, call.parameters[0], emits);
  46843. }
  46844. }
  46845. return emits;
  46846. }
  46847. function extractEventNames(ctx, eventName, emits) {
  46848. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  46849. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  46850. for (const type of types) {
  46851. if (type.type === "TSLiteralType") {
  46852. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  46853. emits.add(String(type.literal.value));
  46854. }
  46855. }
  46856. }
  46857. }
  46858. }
  46859. const DEFINE_EXPOSE = "defineExpose";
  46860. function processDefineExpose(ctx, node) {
  46861. if (isCallOf(node, DEFINE_EXPOSE)) {
  46862. if (ctx.hasDefineExposeCall) {
  46863. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  46864. }
  46865. ctx.hasDefineExposeCall = true;
  46866. return true;
  46867. }
  46868. return false;
  46869. }
  46870. const DEFINE_SLOTS = "defineSlots";
  46871. function processDefineSlots(ctx, node, declId) {
  46872. if (!isCallOf(node, DEFINE_SLOTS)) {
  46873. return false;
  46874. }
  46875. if (ctx.hasDefineSlotsCall) {
  46876. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  46877. }
  46878. ctx.hasDefineSlotsCall = true;
  46879. if (node.arguments.length > 0) {
  46880. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  46881. }
  46882. if (declId) {
  46883. ctx.s.overwrite(
  46884. ctx.startOffset + node.start,
  46885. ctx.startOffset + node.end,
  46886. `${ctx.helper("useSlots")}()`
  46887. );
  46888. }
  46889. return true;
  46890. }
  46891. const DEFINE_OPTIONS = "defineOptions";
  46892. function processDefineOptions(ctx, node) {
  46893. if (!isCallOf(node, DEFINE_OPTIONS)) {
  46894. return false;
  46895. }
  46896. if (ctx.hasDefineOptionsCall) {
  46897. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  46898. }
  46899. if (node.typeParameters) {
  46900. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  46901. }
  46902. if (!node.arguments[0]) return true;
  46903. ctx.hasDefineOptionsCall = true;
  46904. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  46905. let propsOption = void 0;
  46906. let emitsOption = void 0;
  46907. let exposeOption = void 0;
  46908. let slotsOption = void 0;
  46909. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  46910. for (const prop of ctx.optionsRuntimeDecl.properties) {
  46911. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  46912. switch (prop.key.name) {
  46913. case "props":
  46914. propsOption = prop;
  46915. break;
  46916. case "emits":
  46917. emitsOption = prop;
  46918. break;
  46919. case "expose":
  46920. exposeOption = prop;
  46921. break;
  46922. case "slots":
  46923. slotsOption = prop;
  46924. break;
  46925. }
  46926. }
  46927. }
  46928. }
  46929. if (propsOption) {
  46930. ctx.error(
  46931. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  46932. propsOption
  46933. );
  46934. }
  46935. if (emitsOption) {
  46936. ctx.error(
  46937. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  46938. emitsOption
  46939. );
  46940. }
  46941. if (exposeOption) {
  46942. ctx.error(
  46943. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  46944. exposeOption
  46945. );
  46946. }
  46947. if (slotsOption) {
  46948. ctx.error(
  46949. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  46950. slotsOption
  46951. );
  46952. }
  46953. return true;
  46954. }
  46955. function processAwait(ctx, node, needSemi, isStatement) {
  46956. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  46957. const startOffset = ctx.startOffset;
  46958. const argumentStr = ctx.descriptor.source.slice(
  46959. argumentStart + startOffset,
  46960. node.argument.end + startOffset
  46961. );
  46962. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  46963. ctx.s.overwrite(
  46964. node.start + startOffset,
  46965. argumentStart + startOffset,
  46966. `${needSemi ? `;` : ``}(
  46967. ([__temp,__restore] = ${ctx.helper(
  46968. `withAsyncContext`
  46969. )}(${containsNestedAwait ? `async ` : ``}() => `
  46970. );
  46971. ctx.s.appendLeft(
  46972. node.end + startOffset,
  46973. `)),
  46974. ${isStatement ? `` : `__temp = `}await __temp,
  46975. __restore()${isStatement ? `` : `,
  46976. __temp`}
  46977. )`
  46978. );
  46979. }
  46980. var __defProp$1 = Object.defineProperty;
  46981. var __defProps = Object.defineProperties;
  46982. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  46983. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  46984. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  46985. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  46986. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  46987. var __spreadValues$1 = (a, b) => {
  46988. for (var prop in b || (b = {}))
  46989. if (__hasOwnProp$1.call(b, prop))
  46990. __defNormalProp$1(a, prop, b[prop]);
  46991. if (__getOwnPropSymbols$1)
  46992. for (var prop of __getOwnPropSymbols$1(b)) {
  46993. if (__propIsEnum$1.call(b, prop))
  46994. __defNormalProp$1(a, prop, b[prop]);
  46995. }
  46996. return a;
  46997. };
  46998. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  46999. const MACROS = [
  47000. DEFINE_PROPS,
  47001. DEFINE_EMITS,
  47002. DEFINE_EXPOSE,
  47003. DEFINE_OPTIONS,
  47004. DEFINE_SLOTS,
  47005. DEFINE_MODEL,
  47006. WITH_DEFAULTS
  47007. ];
  47008. function compileScript(sfc, options) {
  47009. var _a, _b, _c;
  47010. if (!options.id) {
  47011. warnOnce$1(
  47012. `compileScript now requires passing the \`id\` option.
  47013. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  47014. );
  47015. }
  47016. const { script, scriptSetup, source, filename } = sfc;
  47017. const hoistStatic = options.hoistStatic !== false && !script;
  47018. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  47019. const scriptLang = script && script.lang;
  47020. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  47021. if (script && scriptSetup && scriptLang !== scriptSetupLang) {
  47022. throw new Error(
  47023. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  47024. );
  47025. }
  47026. const ctx = new ScriptCompileContext(sfc, options);
  47027. if (!scriptSetup) {
  47028. if (!script) {
  47029. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  47030. }
  47031. return processNormalScript(ctx, scopeId);
  47032. }
  47033. if (scriptSetupLang && !ctx.isJS && !ctx.isTS) {
  47034. return scriptSetup;
  47035. }
  47036. const scriptBindings = /* @__PURE__ */ Object.create(null);
  47037. const setupBindings = /* @__PURE__ */ Object.create(null);
  47038. let defaultExport;
  47039. let hasAwait = false;
  47040. let hasInlinedSsrRenderFn = false;
  47041. const startOffset = ctx.startOffset;
  47042. const endOffset = ctx.endOffset;
  47043. const scriptStartOffset = script && script.loc.start.offset;
  47044. const scriptEndOffset = script && script.loc.end.offset;
  47045. function hoistNode(node) {
  47046. const start = node.start + startOffset;
  47047. let end = node.end + startOffset;
  47048. if (node.trailingComments && node.trailingComments.length > 0) {
  47049. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  47050. end = lastCommentNode.end + startOffset;
  47051. }
  47052. while (end <= source.length) {
  47053. if (!/\s/.test(source.charAt(end))) {
  47054. break;
  47055. }
  47056. end++;
  47057. }
  47058. ctx.s.move(start, end, 0);
  47059. }
  47060. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  47061. let isUsedInTemplate = needTemplateUsageCheck;
  47062. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  47063. isUsedInTemplate = isImportUsed(local, sfc);
  47064. }
  47065. ctx.userImports[local] = {
  47066. isType,
  47067. imported,
  47068. local,
  47069. source: source2,
  47070. isFromSetup,
  47071. isUsedInTemplate
  47072. };
  47073. }
  47074. function checkInvalidScopeReference(node, method) {
  47075. if (!node) return;
  47076. walkIdentifiers(node, (id) => {
  47077. const binding = setupBindings[id.name];
  47078. if (binding && binding !== "literal-const") {
  47079. ctx.error(
  47080. `\`${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.`,
  47081. id
  47082. );
  47083. }
  47084. });
  47085. }
  47086. const scriptAst = ctx.scriptAst;
  47087. const scriptSetupAst = ctx.scriptSetupAst;
  47088. if (scriptAst) {
  47089. for (const node of scriptAst.body) {
  47090. if (node.type === "ImportDeclaration") {
  47091. for (const specifier of node.specifiers) {
  47092. const imported = getImportedName(specifier);
  47093. registerUserImport(
  47094. node.source.value,
  47095. specifier.local.name,
  47096. imported,
  47097. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47098. false,
  47099. !options.inlineTemplate
  47100. );
  47101. }
  47102. }
  47103. }
  47104. }
  47105. for (const node of scriptSetupAst.body) {
  47106. if (node.type === "ImportDeclaration") {
  47107. hoistNode(node);
  47108. let removed = 0;
  47109. const removeSpecifier = (i) => {
  47110. const removeLeft = i > removed;
  47111. removed++;
  47112. const current = node.specifiers[i];
  47113. const next = node.specifiers[i + 1];
  47114. ctx.s.remove(
  47115. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  47116. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  47117. );
  47118. };
  47119. for (let i = 0; i < node.specifiers.length; i++) {
  47120. const specifier = node.specifiers[i];
  47121. const local = specifier.local.name;
  47122. const imported = getImportedName(specifier);
  47123. const source2 = node.source.value;
  47124. const existing = ctx.userImports[local];
  47125. if (source2 === "vue" && MACROS.includes(imported)) {
  47126. if (local === imported) {
  47127. warnOnce$1(
  47128. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  47129. );
  47130. } else {
  47131. ctx.error(
  47132. `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
  47133. specifier
  47134. );
  47135. }
  47136. removeSpecifier(i);
  47137. } else if (existing) {
  47138. if (existing.source === source2 && existing.imported === imported) {
  47139. removeSpecifier(i);
  47140. } else {
  47141. ctx.error(
  47142. `different imports aliased to same local name.`,
  47143. specifier
  47144. );
  47145. }
  47146. } else {
  47147. registerUserImport(
  47148. source2,
  47149. local,
  47150. imported,
  47151. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47152. true,
  47153. !options.inlineTemplate
  47154. );
  47155. }
  47156. }
  47157. if (node.specifiers.length && removed === node.specifiers.length) {
  47158. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47159. }
  47160. }
  47161. }
  47162. const vueImportAliases = {};
  47163. for (const key in ctx.userImports) {
  47164. const { source: source2, imported, local } = ctx.userImports[key];
  47165. if (source2 === "vue") vueImportAliases[imported] = local;
  47166. }
  47167. if (script && scriptAst) {
  47168. for (const node of scriptAst.body) {
  47169. if (node.type === "ExportDefaultDeclaration") {
  47170. defaultExport = node;
  47171. let optionProperties;
  47172. if (defaultExport.declaration.type === "ObjectExpression") {
  47173. optionProperties = defaultExport.declaration.properties;
  47174. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  47175. optionProperties = defaultExport.declaration.arguments[0].properties;
  47176. }
  47177. if (optionProperties) {
  47178. for (const p of optionProperties) {
  47179. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  47180. ctx.hasDefaultExportName = true;
  47181. }
  47182. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  47183. ctx.hasDefaultExportRender = true;
  47184. }
  47185. }
  47186. }
  47187. const start = node.start + scriptStartOffset;
  47188. const end = node.declaration.start + scriptStartOffset;
  47189. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  47190. } else if (node.type === "ExportNamedDeclaration") {
  47191. const defaultSpecifier = node.specifiers.find(
  47192. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  47193. );
  47194. if (defaultSpecifier) {
  47195. defaultExport = node;
  47196. if (node.specifiers.length > 1) {
  47197. ctx.s.remove(
  47198. defaultSpecifier.start + scriptStartOffset,
  47199. defaultSpecifier.end + scriptStartOffset
  47200. );
  47201. } else {
  47202. ctx.s.remove(
  47203. node.start + scriptStartOffset,
  47204. node.end + scriptStartOffset
  47205. );
  47206. }
  47207. if (node.source) {
  47208. ctx.s.prepend(
  47209. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  47210. `
  47211. );
  47212. } else {
  47213. ctx.s.appendLeft(
  47214. scriptEndOffset,
  47215. `
  47216. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  47217. `
  47218. );
  47219. }
  47220. }
  47221. if (node.declaration) {
  47222. walkDeclaration(
  47223. "script",
  47224. node.declaration,
  47225. scriptBindings,
  47226. vueImportAliases,
  47227. hoistStatic
  47228. );
  47229. }
  47230. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47231. walkDeclaration(
  47232. "script",
  47233. node,
  47234. scriptBindings,
  47235. vueImportAliases,
  47236. hoistStatic
  47237. );
  47238. }
  47239. }
  47240. if (scriptStartOffset > startOffset) {
  47241. if (!/\n$/.test(script.content.trim())) {
  47242. ctx.s.appendLeft(scriptEndOffset, `
  47243. `);
  47244. }
  47245. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  47246. }
  47247. }
  47248. for (const node of scriptSetupAst.body) {
  47249. if (node.type === "ExpressionStatement") {
  47250. const expr = unwrapTSNode(node.expression);
  47251. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  47252. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47253. } else if (processDefineExpose(ctx, expr)) {
  47254. const callee = expr.callee;
  47255. ctx.s.overwrite(
  47256. callee.start + startOffset,
  47257. callee.end + startOffset,
  47258. "__expose"
  47259. );
  47260. } else {
  47261. processDefineModel(ctx, expr);
  47262. }
  47263. }
  47264. if (node.type === "VariableDeclaration" && !node.declare) {
  47265. const total = node.declarations.length;
  47266. let left = total;
  47267. let lastNonRemoved;
  47268. for (let i = 0; i < total; i++) {
  47269. const decl = node.declarations[i];
  47270. const init = decl.init && unwrapTSNode(decl.init);
  47271. if (init) {
  47272. if (processDefineOptions(ctx, init)) {
  47273. ctx.error(
  47274. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  47275. node
  47276. );
  47277. }
  47278. const isDefineProps = processDefineProps(ctx, init, decl.id);
  47279. if (ctx.propsDestructureRestId) {
  47280. setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
  47281. }
  47282. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  47283. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  47284. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  47285. if (left === 1) {
  47286. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47287. } else {
  47288. let start = decl.start + startOffset;
  47289. let end = decl.end + startOffset;
  47290. if (i === total - 1) {
  47291. start = node.declarations[lastNonRemoved].end + startOffset;
  47292. } else {
  47293. end = node.declarations[i + 1].start + startOffset;
  47294. }
  47295. ctx.s.remove(start, end);
  47296. left--;
  47297. }
  47298. } else if (isDefineEmits) {
  47299. ctx.s.overwrite(
  47300. startOffset + init.start,
  47301. startOffset + init.end,
  47302. "__emit"
  47303. );
  47304. } else {
  47305. lastNonRemoved = i;
  47306. }
  47307. }
  47308. }
  47309. }
  47310. let isAllLiteral = false;
  47311. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47312. isAllLiteral = walkDeclaration(
  47313. "scriptSetup",
  47314. node,
  47315. setupBindings,
  47316. vueImportAliases,
  47317. hoistStatic,
  47318. !!ctx.propsDestructureDecl
  47319. );
  47320. }
  47321. if (hoistStatic && isAllLiteral) {
  47322. hoistNode(node);
  47323. }
  47324. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  47325. const scope = [scriptSetupAst.body];
  47326. walk$2(node, {
  47327. enter(child, parent) {
  47328. if (isFunctionType(child)) {
  47329. this.skip();
  47330. }
  47331. if (child.type === "BlockStatement") {
  47332. scope.push(child.body);
  47333. }
  47334. if (child.type === "AwaitExpression") {
  47335. hasAwait = true;
  47336. const currentScope = scope[scope.length - 1];
  47337. const needsSemi = currentScope.some((n, i) => {
  47338. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47339. });
  47340. processAwait(
  47341. ctx,
  47342. child,
  47343. needsSemi,
  47344. parent.type === "ExpressionStatement"
  47345. );
  47346. }
  47347. },
  47348. exit(node2) {
  47349. if (node2.type === "BlockStatement") scope.pop();
  47350. }
  47351. });
  47352. }
  47353. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47354. ctx.error(
  47355. `<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.`,
  47356. node
  47357. );
  47358. }
  47359. if (ctx.isTS) {
  47360. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47361. if (node.type !== "TSEnumDeclaration") {
  47362. hoistNode(node);
  47363. }
  47364. }
  47365. }
  47366. }
  47367. if (ctx.propsDestructureDecl) {
  47368. transformDestructuredProps(ctx, vueImportAliases);
  47369. }
  47370. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47371. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47372. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47373. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47374. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47375. for (const { runtimeOptionNodes } of Object.values(ctx.modelDecls)) {
  47376. for (const node of runtimeOptionNodes) {
  47377. checkInvalidScopeReference(node, DEFINE_MODEL);
  47378. }
  47379. }
  47380. if (script) {
  47381. if (startOffset < scriptStartOffset) {
  47382. ctx.s.remove(0, startOffset);
  47383. ctx.s.remove(endOffset, scriptStartOffset);
  47384. ctx.s.remove(scriptEndOffset, source.length);
  47385. } else {
  47386. ctx.s.remove(0, scriptStartOffset);
  47387. ctx.s.remove(scriptEndOffset, startOffset);
  47388. ctx.s.remove(endOffset, source.length);
  47389. }
  47390. } else {
  47391. ctx.s.remove(0, startOffset);
  47392. ctx.s.remove(endOffset, source.length);
  47393. }
  47394. if (scriptAst) {
  47395. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47396. }
  47397. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47398. ctx.userImports
  47399. )) {
  47400. if (isType) continue;
  47401. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47402. }
  47403. for (const key in scriptBindings) {
  47404. ctx.bindingMetadata[key] = scriptBindings[key];
  47405. }
  47406. for (const key in setupBindings) {
  47407. ctx.bindingMetadata[key] = setupBindings[key];
  47408. }
  47409. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47410. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47411. ctx.helperImports.add(CSS_VARS_HELPER);
  47412. ctx.helperImports.add("unref");
  47413. ctx.s.prependLeft(
  47414. startOffset,
  47415. `
  47416. ${genCssVarsCode(
  47417. sfc.cssVars,
  47418. ctx.bindingMetadata,
  47419. scopeId,
  47420. !!options.isProd
  47421. )}
  47422. `
  47423. );
  47424. }
  47425. let args = `__props`;
  47426. if (ctx.propsTypeDecl) {
  47427. args += `: any`;
  47428. }
  47429. if (ctx.propsDecl) {
  47430. if (ctx.propsDestructureRestId) {
  47431. ctx.s.overwrite(
  47432. startOffset + ctx.propsCall.start,
  47433. startOffset + ctx.propsCall.end,
  47434. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47435. Object.keys(ctx.propsDestructuredBindings)
  47436. )})`
  47437. );
  47438. ctx.s.overwrite(
  47439. startOffset + ctx.propsDestructureDecl.start,
  47440. startOffset + ctx.propsDestructureDecl.end,
  47441. ctx.propsDestructureRestId
  47442. );
  47443. } else if (!ctx.propsDestructureDecl) {
  47444. ctx.s.overwrite(
  47445. startOffset + ctx.propsCall.start,
  47446. startOffset + ctx.propsCall.end,
  47447. "__props"
  47448. );
  47449. }
  47450. }
  47451. if (hasAwait) {
  47452. const any = ctx.isTS ? `: any` : ``;
  47453. ctx.s.prependLeft(startOffset, `
  47454. let __temp${any}, __restore${any}
  47455. `);
  47456. }
  47457. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47458. if (ctx.emitDecl) {
  47459. destructureElements.push(`emit: __emit`);
  47460. }
  47461. if (destructureElements.length) {
  47462. args += `, { ${destructureElements.join(", ")} }`;
  47463. }
  47464. let templateMap;
  47465. let returned;
  47466. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47467. const allBindings = __spreadValues$1(__spreadValues$1({}, scriptBindings), setupBindings);
  47468. for (const key in ctx.userImports) {
  47469. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47470. allBindings[key] = true;
  47471. }
  47472. }
  47473. returned = `{ `;
  47474. for (const key in allBindings) {
  47475. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47476. returned += `get ${key}() { return ${key} }, `;
  47477. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47478. const setArg = key === "v" ? `_v` : `v`;
  47479. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47480. } else {
  47481. returned += `${key}, `;
  47482. }
  47483. }
  47484. returned = returned.replace(/, $/, "") + ` }`;
  47485. } else {
  47486. if (sfc.template && !sfc.template.src) {
  47487. if (options.templateOptions && options.templateOptions.ssr) {
  47488. hasInlinedSsrRenderFn = true;
  47489. }
  47490. const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
  47491. filename,
  47492. ast: sfc.template.ast,
  47493. source: sfc.template.content,
  47494. inMap: sfc.template.map
  47495. }, options.templateOptions), {
  47496. id: scopeId,
  47497. scoped: sfc.styles.some((s) => s.scoped),
  47498. isProd: options.isProd,
  47499. ssrCssVars: sfc.cssVars,
  47500. compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47501. inline: true,
  47502. isTS: ctx.isTS,
  47503. bindingMetadata: ctx.bindingMetadata
  47504. })
  47505. }));
  47506. templateMap = map2;
  47507. if (tips.length) {
  47508. tips.forEach(warnOnce$1);
  47509. }
  47510. const err = errors[0];
  47511. if (typeof err === "string") {
  47512. throw new Error(err);
  47513. } else if (err) {
  47514. if (err.loc) {
  47515. err.message += `
  47516. ` + sfc.filename + "\n" + generateCodeFrame(
  47517. source,
  47518. err.loc.start.offset,
  47519. err.loc.end.offset
  47520. ) + `
  47521. `;
  47522. }
  47523. throw err;
  47524. }
  47525. if (preamble) {
  47526. ctx.s.prepend(preamble);
  47527. }
  47528. if (ast && ast.helpers.has(UNREF)) {
  47529. ctx.helperImports.delete("unref");
  47530. }
  47531. returned = code;
  47532. } else {
  47533. returned = `() => {}`;
  47534. }
  47535. }
  47536. if (!options.inlineTemplate && true) {
  47537. ctx.s.appendRight(
  47538. endOffset,
  47539. `
  47540. const __returned__ = ${returned}
  47541. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47542. return __returned__
  47543. }
  47544. `
  47545. );
  47546. } else {
  47547. ctx.s.appendRight(endOffset, `
  47548. return ${returned}
  47549. }
  47550. `);
  47551. }
  47552. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  47553. let runtimeOptions = ``;
  47554. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  47555. const match = filename.match(/([^/\\]+)\.\w+$/);
  47556. if (match) {
  47557. runtimeOptions += `
  47558. __name: '${match[1]}',`;
  47559. }
  47560. }
  47561. if (hasInlinedSsrRenderFn) {
  47562. runtimeOptions += `
  47563. __ssrInlineRender: true,`;
  47564. }
  47565. const propsDecl = genRuntimeProps(ctx);
  47566. if (propsDecl) runtimeOptions += `
  47567. props: ${propsDecl},`;
  47568. const emitsDecl = genRuntimeEmits(ctx);
  47569. if (emitsDecl) runtimeOptions += `
  47570. emits: ${emitsDecl},`;
  47571. let definedOptions = "";
  47572. if (ctx.optionsRuntimeDecl) {
  47573. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  47574. }
  47575. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  47576. `;
  47577. if (ctx.isTS) {
  47578. const def = (defaultExport ? `
  47579. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  47580. ...${definedOptions},` : "");
  47581. ctx.s.prependLeft(
  47582. startOffset,
  47583. `
  47584. ${genDefaultAs} /*@__PURE__*/${ctx.helper(
  47585. `defineComponent`
  47586. )}({${def}${runtimeOptions}
  47587. ${hasAwait ? `async ` : ``}setup(${args}) {
  47588. ${exposeCall}`
  47589. );
  47590. ctx.s.appendRight(endOffset, `})`);
  47591. } else {
  47592. if (defaultExport || definedOptions) {
  47593. ctx.s.prependLeft(
  47594. startOffset,
  47595. `
  47596. ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  47597. ${hasAwait ? `async ` : ``}setup(${args}) {
  47598. ${exposeCall}`
  47599. );
  47600. ctx.s.appendRight(endOffset, `})`);
  47601. } else {
  47602. ctx.s.prependLeft(
  47603. startOffset,
  47604. `
  47605. ${genDefaultAs} {${runtimeOptions}
  47606. ${hasAwait ? `async ` : ``}setup(${args}) {
  47607. ${exposeCall}`
  47608. );
  47609. ctx.s.appendRight(endOffset, `}`);
  47610. }
  47611. }
  47612. if (ctx.helperImports.size > 0) {
  47613. const runtimeModuleName = (_c = (_b = options.templateOptions) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.runtimeModuleName;
  47614. const importSrc = runtimeModuleName ? JSON.stringify(runtimeModuleName) : `'vue'`;
  47615. ctx.s.prepend(
  47616. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from ${importSrc}
  47617. `
  47618. );
  47619. }
  47620. const content = ctx.s.toString();
  47621. let map = options.sourceMap !== false ? ctx.s.generateMap({
  47622. source: filename,
  47623. hires: true,
  47624. includeContent: true
  47625. }) : void 0;
  47626. if (templateMap && map) {
  47627. const offset = content.indexOf(returned);
  47628. const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
  47629. map = mergeSourceMaps(map, templateMap, templateLineOffset);
  47630. }
  47631. return __spreadProps(__spreadValues$1({}, scriptSetup), {
  47632. bindings: ctx.bindingMetadata,
  47633. imports: ctx.userImports,
  47634. content,
  47635. map,
  47636. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  47637. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  47638. deps: ctx.deps ? [...ctx.deps] : void 0
  47639. });
  47640. }
  47641. function registerBinding(bindings, node, type) {
  47642. bindings[node.name] = type;
  47643. }
  47644. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
  47645. let isAllLiteral = false;
  47646. if (node.type === "VariableDeclaration") {
  47647. const isConst = node.kind === "const";
  47648. isAllLiteral = isConst && node.declarations.every(
  47649. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  47650. );
  47651. for (const { id, init: _init } of node.declarations) {
  47652. const init = _init && unwrapTSNode(_init);
  47653. const isConstMacroCall = isConst && isCallOf(
  47654. init,
  47655. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
  47656. );
  47657. if (id.type === "Identifier") {
  47658. let bindingType;
  47659. const userReactiveBinding = userImportAliases["reactive"];
  47660. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  47661. bindingType = "literal-const";
  47662. } else if (isCallOf(init, userReactiveBinding)) {
  47663. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  47664. } else if (
  47665. // if a declaration is a const literal, we can mark it so that
  47666. // the generated render fn code doesn't need to unref() it
  47667. isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
  47668. ) {
  47669. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  47670. } else if (isConst) {
  47671. if (isCallOf(
  47672. init,
  47673. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
  47674. )) {
  47675. bindingType = "setup-ref";
  47676. } else {
  47677. bindingType = "setup-maybe-ref";
  47678. }
  47679. } else {
  47680. bindingType = "setup-let";
  47681. }
  47682. registerBinding(bindings, id, bindingType);
  47683. } else {
  47684. if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
  47685. continue;
  47686. }
  47687. if (id.type === "ObjectPattern") {
  47688. walkObjectPattern(id, bindings, isConst, isConstMacroCall);
  47689. } else if (id.type === "ArrayPattern") {
  47690. walkArrayPattern(id, bindings, isConst, isConstMacroCall);
  47691. }
  47692. }
  47693. }
  47694. } else if (node.type === "TSEnumDeclaration") {
  47695. isAllLiteral = node.members.every(
  47696. (member) => !member.initializer || isStaticNode(member.initializer)
  47697. );
  47698. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  47699. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  47700. bindings[node.id.name] = "setup-const";
  47701. }
  47702. return isAllLiteral;
  47703. }
  47704. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  47705. for (const p of node.properties) {
  47706. if (p.type === "ObjectProperty") {
  47707. if (p.key.type === "Identifier" && p.key === p.value) {
  47708. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47709. registerBinding(bindings, p.key, type);
  47710. } else {
  47711. walkPattern(p.value, bindings, isConst, isDefineCall);
  47712. }
  47713. } else {
  47714. const type = isConst ? "setup-const" : "setup-let";
  47715. registerBinding(bindings, p.argument, type);
  47716. }
  47717. }
  47718. }
  47719. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  47720. for (const e of node.elements) {
  47721. e && walkPattern(e, bindings, isConst, isDefineCall);
  47722. }
  47723. }
  47724. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  47725. if (node.type === "Identifier") {
  47726. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47727. registerBinding(bindings, node, type);
  47728. } else if (node.type === "RestElement") {
  47729. const type = isConst ? "setup-const" : "setup-let";
  47730. registerBinding(bindings, node.argument, type);
  47731. } else if (node.type === "ObjectPattern") {
  47732. walkObjectPattern(node, bindings, isConst);
  47733. } else if (node.type === "ArrayPattern") {
  47734. walkArrayPattern(node, bindings, isConst);
  47735. } else if (node.type === "AssignmentPattern") {
  47736. if (node.left.type === "Identifier") {
  47737. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47738. registerBinding(bindings, node.left, type);
  47739. } else {
  47740. walkPattern(node.left, bindings, isConst);
  47741. }
  47742. }
  47743. }
  47744. function canNeverBeRef(node, userReactiveImport) {
  47745. if (isCallOf(node, userReactiveImport)) {
  47746. return true;
  47747. }
  47748. switch (node.type) {
  47749. case "UnaryExpression":
  47750. case "BinaryExpression":
  47751. case "ArrayExpression":
  47752. case "ObjectExpression":
  47753. case "FunctionExpression":
  47754. case "ArrowFunctionExpression":
  47755. case "UpdateExpression":
  47756. case "ClassExpression":
  47757. case "TaggedTemplateExpression":
  47758. return true;
  47759. case "SequenceExpression":
  47760. return canNeverBeRef(
  47761. node.expressions[node.expressions.length - 1],
  47762. userReactiveImport
  47763. );
  47764. default:
  47765. if (isLiteralNode(node)) {
  47766. return true;
  47767. }
  47768. return false;
  47769. }
  47770. }
  47771. function isStaticNode(node) {
  47772. node = unwrapTSNode(node);
  47773. switch (node.type) {
  47774. case "UnaryExpression":
  47775. return isStaticNode(node.argument);
  47776. case "LogicalExpression":
  47777. // 1 > 2
  47778. case "BinaryExpression":
  47779. return isStaticNode(node.left) && isStaticNode(node.right);
  47780. case "ConditionalExpression": {
  47781. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  47782. }
  47783. case "SequenceExpression":
  47784. // (1, 2)
  47785. case "TemplateLiteral":
  47786. return node.expressions.every((expr) => isStaticNode(expr));
  47787. case "ParenthesizedExpression":
  47788. return isStaticNode(node.expression);
  47789. case "StringLiteral":
  47790. case "NumericLiteral":
  47791. case "BooleanLiteral":
  47792. case "NullLiteral":
  47793. case "BigIntLiteral":
  47794. return true;
  47795. }
  47796. return false;
  47797. }
  47798. function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
  47799. const generator = new sourceMapExports.SourceMapGenerator();
  47800. const addMapping = (map, lineOffset = 0) => {
  47801. const consumer = new sourceMapExports.SourceMapConsumer(map);
  47802. consumer.sources.forEach((sourceFile) => {
  47803. generator._sources.add(sourceFile);
  47804. const sourceContent = consumer.sourceContentFor(sourceFile);
  47805. if (sourceContent != null) {
  47806. generator.setSourceContent(sourceFile, sourceContent);
  47807. }
  47808. });
  47809. consumer.eachMapping((m) => {
  47810. if (m.originalLine == null) return;
  47811. generator.addMapping({
  47812. generated: {
  47813. line: m.generatedLine + lineOffset,
  47814. column: m.generatedColumn
  47815. },
  47816. original: {
  47817. line: m.originalLine,
  47818. column: m.originalColumn
  47819. },
  47820. source: m.source,
  47821. name: m.name
  47822. });
  47823. });
  47824. };
  47825. addMapping(scriptMap);
  47826. addMapping(templateMap, templateLineOffset);
  47827. generator._sourceRoot = scriptMap.sourceRoot;
  47828. generator._file = scriptMap.file;
  47829. return generator.toJSON();
  47830. }
  47831. var __defProp = Object.defineProperty;
  47832. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  47833. var __hasOwnProp = Object.prototype.hasOwnProperty;
  47834. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  47835. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  47836. var __spreadValues = (a, b) => {
  47837. for (var prop in b || (b = {}))
  47838. if (__hasOwnProp.call(b, prop))
  47839. __defNormalProp(a, prop, b[prop]);
  47840. if (__getOwnPropSymbols)
  47841. for (var prop of __getOwnPropSymbols(b)) {
  47842. if (__propIsEnum.call(b, prop))
  47843. __defNormalProp(a, prop, b[prop]);
  47844. }
  47845. return a;
  47846. };
  47847. const version = "3.5.19";
  47848. const parseCache = parseCache$1;
  47849. const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
  47850. const walk = walk$2;
  47851. const shouldTransformRef = () => false;
  47852. var parse$4 = libExports.parse;
  47853. 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 };