compiler-sfc.esm-browser.js 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457
  1. /**
  2. * @vue/compiler-sfc v3.5.18
  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, _ref2;
  3198. this.castNodeTo(node, "ImportExpression");
  3199. node.source = node.arguments[0];
  3200. node.options = (_ref = node.arguments[1]) != null ? _ref : null;
  3201. node.attributes = (_ref2 = node.arguments[1]) != null ? _ref2 : null;
  3202. delete node.arguments;
  3203. delete node.callee;
  3204. } else if (node.type === "OptionalCallExpression") {
  3205. this.castNodeTo(node, "CallExpression");
  3206. } else {
  3207. node.optional = false;
  3208. }
  3209. return node;
  3210. }
  3211. toReferencedArguments(node) {
  3212. if (node.type === "ImportExpression") {
  3213. return;
  3214. }
  3215. super.toReferencedArguments(node);
  3216. }
  3217. parseExport(unfinished, decorators) {
  3218. const exportStartLoc = this.state.lastTokStartLoc;
  3219. const node = super.parseExport(unfinished, decorators);
  3220. switch (node.type) {
  3221. case "ExportAllDeclaration":
  3222. node.exported = null;
  3223. break;
  3224. case "ExportNamedDeclaration":
  3225. if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") {
  3226. this.castNodeTo(node, "ExportAllDeclaration");
  3227. node.exported = node.specifiers[0].exported;
  3228. delete node.specifiers;
  3229. }
  3230. case "ExportDefaultDeclaration":
  3231. {
  3232. var _declaration$decorato;
  3233. const {
  3234. declaration
  3235. } = node;
  3236. if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) {
  3237. this.resetStartLocation(node, exportStartLoc);
  3238. }
  3239. }
  3240. break;
  3241. }
  3242. return node;
  3243. }
  3244. stopParseSubscript(base, state) {
  3245. const node = super.stopParseSubscript(base, state);
  3246. if (state.optionalChainMember) {
  3247. return this.estreeParseChainExpression(node, base.loc.end);
  3248. }
  3249. return node;
  3250. }
  3251. parseMember(base, startLoc, state, computed, optional) {
  3252. const node = super.parseMember(base, startLoc, state, computed, optional);
  3253. if (node.type === "OptionalMemberExpression") {
  3254. this.castNodeTo(node, "MemberExpression");
  3255. } else {
  3256. node.optional = false;
  3257. }
  3258. return node;
  3259. }
  3260. isOptionalMemberExpression(node) {
  3261. if (node.type === "ChainExpression") {
  3262. return node.expression.type === "MemberExpression";
  3263. }
  3264. return super.isOptionalMemberExpression(node);
  3265. }
  3266. hasPropertyAsPrivateName(node) {
  3267. if (node.type === "ChainExpression") {
  3268. node = node.expression;
  3269. }
  3270. return super.hasPropertyAsPrivateName(node);
  3271. }
  3272. isObjectProperty(node) {
  3273. return node.type === "Property" && node.kind === "init" && !node.method;
  3274. }
  3275. isObjectMethod(node) {
  3276. return node.type === "Property" && (node.method || node.kind === "get" || node.kind === "set");
  3277. }
  3278. castNodeTo(node, type) {
  3279. const result = super.castNodeTo(node, type);
  3280. this.fillOptionalPropertiesForTSESLint(result);
  3281. return result;
  3282. }
  3283. cloneIdentifier(node) {
  3284. const cloned = super.cloneIdentifier(node);
  3285. this.fillOptionalPropertiesForTSESLint(cloned);
  3286. return cloned;
  3287. }
  3288. cloneStringLiteral(node) {
  3289. if (node.type === "Literal") {
  3290. return this.cloneEstreeStringLiteral(node);
  3291. }
  3292. return super.cloneStringLiteral(node);
  3293. }
  3294. finishNodeAt(node, type, endLoc) {
  3295. return toESTreeLocation(super.finishNodeAt(node, type, endLoc));
  3296. }
  3297. finishNode(node, type) {
  3298. const result = super.finishNode(node, type);
  3299. this.fillOptionalPropertiesForTSESLint(result);
  3300. return result;
  3301. }
  3302. resetStartLocation(node, startLoc) {
  3303. super.resetStartLocation(node, startLoc);
  3304. toESTreeLocation(node);
  3305. }
  3306. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  3307. super.resetEndLocation(node, endLoc);
  3308. toESTreeLocation(node);
  3309. }
  3310. };
  3311. class TokContext {
  3312. constructor(token, preserveSpace) {
  3313. this.token = void 0;
  3314. this.preserveSpace = void 0;
  3315. this.token = token;
  3316. this.preserveSpace = !!preserveSpace;
  3317. }
  3318. }
  3319. const types = {
  3320. brace: new TokContext("{"),
  3321. j_oTag: new TokContext("<tag"),
  3322. j_cTag: new TokContext("</tag"),
  3323. j_expr: new TokContext("<tag>...</tag>", true)
  3324. };
  3325. {
  3326. types.template = new TokContext("`", true);
  3327. }
  3328. const beforeExpr = true;
  3329. const startsExpr = true;
  3330. const isLoop = true;
  3331. const isAssign = true;
  3332. const prefix = true;
  3333. const postfix = true;
  3334. class ExportedTokenType {
  3335. constructor(label, conf = {}) {
  3336. this.label = void 0;
  3337. this.keyword = void 0;
  3338. this.beforeExpr = void 0;
  3339. this.startsExpr = void 0;
  3340. this.rightAssociative = void 0;
  3341. this.isLoop = void 0;
  3342. this.isAssign = void 0;
  3343. this.prefix = void 0;
  3344. this.postfix = void 0;
  3345. this.binop = void 0;
  3346. this.label = label;
  3347. this.keyword = conf.keyword;
  3348. this.beforeExpr = !!conf.beforeExpr;
  3349. this.startsExpr = !!conf.startsExpr;
  3350. this.rightAssociative = !!conf.rightAssociative;
  3351. this.isLoop = !!conf.isLoop;
  3352. this.isAssign = !!conf.isAssign;
  3353. this.prefix = !!conf.prefix;
  3354. this.postfix = !!conf.postfix;
  3355. this.binop = conf.binop != null ? conf.binop : null;
  3356. {
  3357. this.updateContext = null;
  3358. }
  3359. }
  3360. }
  3361. const keywords$1 = new Map();
  3362. function createKeyword(name, options = {}) {
  3363. options.keyword = name;
  3364. const token = createToken(name, options);
  3365. keywords$1.set(name, token);
  3366. return token;
  3367. }
  3368. function createBinop(name, binop) {
  3369. return createToken(name, {
  3370. beforeExpr,
  3371. binop
  3372. });
  3373. }
  3374. let tokenTypeCounter = -1;
  3375. const tokenTypes = [];
  3376. const tokenLabels = [];
  3377. const tokenBinops = [];
  3378. const tokenBeforeExprs = [];
  3379. const tokenStartsExprs = [];
  3380. const tokenPrefixes = [];
  3381. function createToken(name, options = {}) {
  3382. var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix;
  3383. ++tokenTypeCounter;
  3384. tokenLabels.push(name);
  3385. tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1);
  3386. tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false);
  3387. tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false);
  3388. tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false);
  3389. tokenTypes.push(new ExportedTokenType(name, options));
  3390. return tokenTypeCounter;
  3391. }
  3392. function createKeywordLike(name, options = {}) {
  3393. var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2;
  3394. ++tokenTypeCounter;
  3395. keywords$1.set(name, tokenTypeCounter);
  3396. tokenLabels.push(name);
  3397. tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1);
  3398. tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false);
  3399. tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false);
  3400. tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false);
  3401. tokenTypes.push(new ExportedTokenType("name", options));
  3402. return tokenTypeCounter;
  3403. }
  3404. const tt = {
  3405. bracketL: createToken("[", {
  3406. beforeExpr,
  3407. startsExpr
  3408. }),
  3409. bracketHashL: createToken("#[", {
  3410. beforeExpr,
  3411. startsExpr
  3412. }),
  3413. bracketBarL: createToken("[|", {
  3414. beforeExpr,
  3415. startsExpr
  3416. }),
  3417. bracketR: createToken("]"),
  3418. bracketBarR: createToken("|]"),
  3419. braceL: createToken("{", {
  3420. beforeExpr,
  3421. startsExpr
  3422. }),
  3423. braceBarL: createToken("{|", {
  3424. beforeExpr,
  3425. startsExpr
  3426. }),
  3427. braceHashL: createToken("#{", {
  3428. beforeExpr,
  3429. startsExpr
  3430. }),
  3431. braceR: createToken("}"),
  3432. braceBarR: createToken("|}"),
  3433. parenL: createToken("(", {
  3434. beforeExpr,
  3435. startsExpr
  3436. }),
  3437. parenR: createToken(")"),
  3438. comma: createToken(",", {
  3439. beforeExpr
  3440. }),
  3441. semi: createToken(";", {
  3442. beforeExpr
  3443. }),
  3444. colon: createToken(":", {
  3445. beforeExpr
  3446. }),
  3447. doubleColon: createToken("::", {
  3448. beforeExpr
  3449. }),
  3450. dot: createToken("."),
  3451. question: createToken("?", {
  3452. beforeExpr
  3453. }),
  3454. questionDot: createToken("?."),
  3455. arrow: createToken("=>", {
  3456. beforeExpr
  3457. }),
  3458. template: createToken("template"),
  3459. ellipsis: createToken("...", {
  3460. beforeExpr
  3461. }),
  3462. backQuote: createToken("`", {
  3463. startsExpr
  3464. }),
  3465. dollarBraceL: createToken("${", {
  3466. beforeExpr,
  3467. startsExpr
  3468. }),
  3469. templateTail: createToken("...`", {
  3470. startsExpr
  3471. }),
  3472. templateNonTail: createToken("...${", {
  3473. beforeExpr,
  3474. startsExpr
  3475. }),
  3476. at: createToken("@"),
  3477. hash: createToken("#", {
  3478. startsExpr
  3479. }),
  3480. interpreterDirective: createToken("#!..."),
  3481. eq: createToken("=", {
  3482. beforeExpr,
  3483. isAssign
  3484. }),
  3485. assign: createToken("_=", {
  3486. beforeExpr,
  3487. isAssign
  3488. }),
  3489. slashAssign: createToken("_=", {
  3490. beforeExpr,
  3491. isAssign
  3492. }),
  3493. xorAssign: createToken("_=", {
  3494. beforeExpr,
  3495. isAssign
  3496. }),
  3497. moduloAssign: createToken("_=", {
  3498. beforeExpr,
  3499. isAssign
  3500. }),
  3501. incDec: createToken("++/--", {
  3502. prefix,
  3503. postfix,
  3504. startsExpr
  3505. }),
  3506. bang: createToken("!", {
  3507. beforeExpr,
  3508. prefix,
  3509. startsExpr
  3510. }),
  3511. tilde: createToken("~", {
  3512. beforeExpr,
  3513. prefix,
  3514. startsExpr
  3515. }),
  3516. doubleCaret: createToken("^^", {
  3517. startsExpr
  3518. }),
  3519. doubleAt: createToken("@@", {
  3520. startsExpr
  3521. }),
  3522. pipeline: createBinop("|>", 0),
  3523. nullishCoalescing: createBinop("??", 1),
  3524. logicalOR: createBinop("||", 1),
  3525. logicalAND: createBinop("&&", 2),
  3526. bitwiseOR: createBinop("|", 3),
  3527. bitwiseXOR: createBinop("^", 4),
  3528. bitwiseAND: createBinop("&", 5),
  3529. equality: createBinop("==/!=/===/!==", 6),
  3530. lt: createBinop("</>/<=/>=", 7),
  3531. gt: createBinop("</>/<=/>=", 7),
  3532. relational: createBinop("</>/<=/>=", 7),
  3533. bitShift: createBinop("<</>>/>>>", 8),
  3534. bitShiftL: createBinop("<</>>/>>>", 8),
  3535. bitShiftR: createBinop("<</>>/>>>", 8),
  3536. plusMin: createToken("+/-", {
  3537. beforeExpr,
  3538. binop: 9,
  3539. prefix,
  3540. startsExpr
  3541. }),
  3542. modulo: createToken("%", {
  3543. binop: 10,
  3544. startsExpr
  3545. }),
  3546. star: createToken("*", {
  3547. binop: 10
  3548. }),
  3549. slash: createBinop("/", 10),
  3550. exponent: createToken("**", {
  3551. beforeExpr,
  3552. binop: 11,
  3553. rightAssociative: true
  3554. }),
  3555. _in: createKeyword("in", {
  3556. beforeExpr,
  3557. binop: 7
  3558. }),
  3559. _instanceof: createKeyword("instanceof", {
  3560. beforeExpr,
  3561. binop: 7
  3562. }),
  3563. _break: createKeyword("break"),
  3564. _case: createKeyword("case", {
  3565. beforeExpr
  3566. }),
  3567. _catch: createKeyword("catch"),
  3568. _continue: createKeyword("continue"),
  3569. _debugger: createKeyword("debugger"),
  3570. _default: createKeyword("default", {
  3571. beforeExpr
  3572. }),
  3573. _else: createKeyword("else", {
  3574. beforeExpr
  3575. }),
  3576. _finally: createKeyword("finally"),
  3577. _function: createKeyword("function", {
  3578. startsExpr
  3579. }),
  3580. _if: createKeyword("if"),
  3581. _return: createKeyword("return", {
  3582. beforeExpr
  3583. }),
  3584. _switch: createKeyword("switch"),
  3585. _throw: createKeyword("throw", {
  3586. beforeExpr,
  3587. prefix,
  3588. startsExpr
  3589. }),
  3590. _try: createKeyword("try"),
  3591. _var: createKeyword("var"),
  3592. _const: createKeyword("const"),
  3593. _with: createKeyword("with"),
  3594. _new: createKeyword("new", {
  3595. beforeExpr,
  3596. startsExpr
  3597. }),
  3598. _this: createKeyword("this", {
  3599. startsExpr
  3600. }),
  3601. _super: createKeyword("super", {
  3602. startsExpr
  3603. }),
  3604. _class: createKeyword("class", {
  3605. startsExpr
  3606. }),
  3607. _extends: createKeyword("extends", {
  3608. beforeExpr
  3609. }),
  3610. _export: createKeyword("export"),
  3611. _import: createKeyword("import", {
  3612. startsExpr
  3613. }),
  3614. _null: createKeyword("null", {
  3615. startsExpr
  3616. }),
  3617. _true: createKeyword("true", {
  3618. startsExpr
  3619. }),
  3620. _false: createKeyword("false", {
  3621. startsExpr
  3622. }),
  3623. _typeof: createKeyword("typeof", {
  3624. beforeExpr,
  3625. prefix,
  3626. startsExpr
  3627. }),
  3628. _void: createKeyword("void", {
  3629. beforeExpr,
  3630. prefix,
  3631. startsExpr
  3632. }),
  3633. _delete: createKeyword("delete", {
  3634. beforeExpr,
  3635. prefix,
  3636. startsExpr
  3637. }),
  3638. _do: createKeyword("do", {
  3639. isLoop,
  3640. beforeExpr
  3641. }),
  3642. _for: createKeyword("for", {
  3643. isLoop
  3644. }),
  3645. _while: createKeyword("while", {
  3646. isLoop
  3647. }),
  3648. _as: createKeywordLike("as", {
  3649. startsExpr
  3650. }),
  3651. _assert: createKeywordLike("assert", {
  3652. startsExpr
  3653. }),
  3654. _async: createKeywordLike("async", {
  3655. startsExpr
  3656. }),
  3657. _await: createKeywordLike("await", {
  3658. startsExpr
  3659. }),
  3660. _defer: createKeywordLike("defer", {
  3661. startsExpr
  3662. }),
  3663. _from: createKeywordLike("from", {
  3664. startsExpr
  3665. }),
  3666. _get: createKeywordLike("get", {
  3667. startsExpr
  3668. }),
  3669. _let: createKeywordLike("let", {
  3670. startsExpr
  3671. }),
  3672. _meta: createKeywordLike("meta", {
  3673. startsExpr
  3674. }),
  3675. _of: createKeywordLike("of", {
  3676. startsExpr
  3677. }),
  3678. _sent: createKeywordLike("sent", {
  3679. startsExpr
  3680. }),
  3681. _set: createKeywordLike("set", {
  3682. startsExpr
  3683. }),
  3684. _source: createKeywordLike("source", {
  3685. startsExpr
  3686. }),
  3687. _static: createKeywordLike("static", {
  3688. startsExpr
  3689. }),
  3690. _using: createKeywordLike("using", {
  3691. startsExpr
  3692. }),
  3693. _yield: createKeywordLike("yield", {
  3694. startsExpr
  3695. }),
  3696. _asserts: createKeywordLike("asserts", {
  3697. startsExpr
  3698. }),
  3699. _checks: createKeywordLike("checks", {
  3700. startsExpr
  3701. }),
  3702. _exports: createKeywordLike("exports", {
  3703. startsExpr
  3704. }),
  3705. _global: createKeywordLike("global", {
  3706. startsExpr
  3707. }),
  3708. _implements: createKeywordLike("implements", {
  3709. startsExpr
  3710. }),
  3711. _intrinsic: createKeywordLike("intrinsic", {
  3712. startsExpr
  3713. }),
  3714. _infer: createKeywordLike("infer", {
  3715. startsExpr
  3716. }),
  3717. _is: createKeywordLike("is", {
  3718. startsExpr
  3719. }),
  3720. _mixins: createKeywordLike("mixins", {
  3721. startsExpr
  3722. }),
  3723. _proto: createKeywordLike("proto", {
  3724. startsExpr
  3725. }),
  3726. _require: createKeywordLike("require", {
  3727. startsExpr
  3728. }),
  3729. _satisfies: createKeywordLike("satisfies", {
  3730. startsExpr
  3731. }),
  3732. _keyof: createKeywordLike("keyof", {
  3733. startsExpr
  3734. }),
  3735. _readonly: createKeywordLike("readonly", {
  3736. startsExpr
  3737. }),
  3738. _unique: createKeywordLike("unique", {
  3739. startsExpr
  3740. }),
  3741. _abstract: createKeywordLike("abstract", {
  3742. startsExpr
  3743. }),
  3744. _declare: createKeywordLike("declare", {
  3745. startsExpr
  3746. }),
  3747. _enum: createKeywordLike("enum", {
  3748. startsExpr
  3749. }),
  3750. _module: createKeywordLike("module", {
  3751. startsExpr
  3752. }),
  3753. _namespace: createKeywordLike("namespace", {
  3754. startsExpr
  3755. }),
  3756. _interface: createKeywordLike("interface", {
  3757. startsExpr
  3758. }),
  3759. _type: createKeywordLike("type", {
  3760. startsExpr
  3761. }),
  3762. _opaque: createKeywordLike("opaque", {
  3763. startsExpr
  3764. }),
  3765. name: createToken("name", {
  3766. startsExpr
  3767. }),
  3768. placeholder: createToken("%%", {
  3769. startsExpr
  3770. }),
  3771. string: createToken("string", {
  3772. startsExpr
  3773. }),
  3774. num: createToken("num", {
  3775. startsExpr
  3776. }),
  3777. bigint: createToken("bigint", {
  3778. startsExpr
  3779. }),
  3780. decimal: createToken("decimal", {
  3781. startsExpr
  3782. }),
  3783. regexp: createToken("regexp", {
  3784. startsExpr
  3785. }),
  3786. privateName: createToken("#name", {
  3787. startsExpr
  3788. }),
  3789. eof: createToken("eof"),
  3790. jsxName: createToken("jsxName"),
  3791. jsxText: createToken("jsxText", {
  3792. beforeExpr
  3793. }),
  3794. jsxTagStart: createToken("jsxTagStart", {
  3795. startsExpr
  3796. }),
  3797. jsxTagEnd: createToken("jsxTagEnd")
  3798. };
  3799. function tokenIsIdentifier(token) {
  3800. return token >= 93 && token <= 133;
  3801. }
  3802. function tokenKeywordOrIdentifierIsKeyword(token) {
  3803. return token <= 92;
  3804. }
  3805. function tokenIsKeywordOrIdentifier(token) {
  3806. return token >= 58 && token <= 133;
  3807. }
  3808. function tokenIsLiteralPropertyName(token) {
  3809. return token >= 58 && token <= 137;
  3810. }
  3811. function tokenComesBeforeExpression(token) {
  3812. return tokenBeforeExprs[token];
  3813. }
  3814. function tokenCanStartExpression(token) {
  3815. return tokenStartsExprs[token];
  3816. }
  3817. function tokenIsAssignment(token) {
  3818. return token >= 29 && token <= 33;
  3819. }
  3820. function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
  3821. return token >= 129 && token <= 131;
  3822. }
  3823. function tokenIsLoop(token) {
  3824. return token >= 90 && token <= 92;
  3825. }
  3826. function tokenIsKeyword(token) {
  3827. return token >= 58 && token <= 92;
  3828. }
  3829. function tokenIsOperator(token) {
  3830. return token >= 39 && token <= 59;
  3831. }
  3832. function tokenIsPostfix(token) {
  3833. return token === 34;
  3834. }
  3835. function tokenIsPrefix(token) {
  3836. return tokenPrefixes[token];
  3837. }
  3838. function tokenIsTSTypeOperator(token) {
  3839. return token >= 121 && token <= 123;
  3840. }
  3841. function tokenIsTSDeclarationStart(token) {
  3842. return token >= 124 && token <= 130;
  3843. }
  3844. function tokenLabelName(token) {
  3845. return tokenLabels[token];
  3846. }
  3847. function tokenOperatorPrecedence(token) {
  3848. return tokenBinops[token];
  3849. }
  3850. function tokenIsRightAssociative(token) {
  3851. return token === 57;
  3852. }
  3853. function tokenIsTemplate(token) {
  3854. return token >= 24 && token <= 25;
  3855. }
  3856. function getExportedToken(token) {
  3857. return tokenTypes[token];
  3858. }
  3859. {
  3860. tokenTypes[8].updateContext = context => {
  3861. context.pop();
  3862. };
  3863. tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => {
  3864. context.push(types.brace);
  3865. };
  3866. tokenTypes[22].updateContext = context => {
  3867. if (context[context.length - 1] === types.template) {
  3868. context.pop();
  3869. } else {
  3870. context.push(types.template);
  3871. }
  3872. };
  3873. tokenTypes[143].updateContext = context => {
  3874. context.push(types.j_expr, types.j_oTag);
  3875. };
  3876. }
  3877. 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";
  3878. 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";
  3879. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  3880. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  3881. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  3882. 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];
  3883. 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];
  3884. function isInAstralSet(code, set) {
  3885. let pos = 0x10000;
  3886. for (let i = 0, length = set.length; i < length; i += 2) {
  3887. pos += set[i];
  3888. if (pos > code) return false;
  3889. pos += set[i + 1];
  3890. if (pos >= code) return true;
  3891. }
  3892. return false;
  3893. }
  3894. function isIdentifierStart(code) {
  3895. if (code < 65) return code === 36;
  3896. if (code <= 90) return true;
  3897. if (code < 97) return code === 95;
  3898. if (code <= 122) return true;
  3899. if (code <= 0xffff) {
  3900. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  3901. }
  3902. return isInAstralSet(code, astralIdentifierStartCodes);
  3903. }
  3904. function isIdentifierChar(code) {
  3905. if (code < 48) return code === 36;
  3906. if (code < 58) return true;
  3907. if (code < 65) return false;
  3908. if (code <= 90) return true;
  3909. if (code < 97) return code === 95;
  3910. if (code <= 122) return true;
  3911. if (code <= 0xffff) {
  3912. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  3913. }
  3914. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  3915. }
  3916. const reservedWords = {
  3917. 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"],
  3918. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  3919. strictBind: ["eval", "arguments"]
  3920. };
  3921. const keywords = new Set(reservedWords.keyword);
  3922. const reservedWordsStrictSet = new Set(reservedWords.strict);
  3923. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  3924. function isReservedWord(word, inModule) {
  3925. return inModule && word === "await" || word === "enum";
  3926. }
  3927. function isStrictReservedWord(word, inModule) {
  3928. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  3929. }
  3930. function isStrictBindOnlyReservedWord(word) {
  3931. return reservedWordsStrictBindSet.has(word);
  3932. }
  3933. function isStrictBindReservedWord(word, inModule) {
  3934. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  3935. }
  3936. function isKeyword(word) {
  3937. return keywords.has(word);
  3938. }
  3939. function isIteratorStart(current, next, next2) {
  3940. return current === 64 && next === 64 && isIdentifierStart(next2);
  3941. }
  3942. 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"]);
  3943. function canBeReservedWord(word) {
  3944. return reservedWordLikeSet.has(word);
  3945. }
  3946. class Scope {
  3947. constructor(flags) {
  3948. this.flags = 0;
  3949. this.names = new Map();
  3950. this.firstLexicalName = "";
  3951. this.flags = flags;
  3952. }
  3953. }
  3954. class ScopeHandler {
  3955. constructor(parser, inModule) {
  3956. this.parser = void 0;
  3957. this.scopeStack = [];
  3958. this.inModule = void 0;
  3959. this.undefinedExports = new Map();
  3960. this.parser = parser;
  3961. this.inModule = inModule;
  3962. }
  3963. get inTopLevel() {
  3964. return (this.currentScope().flags & 1) > 0;
  3965. }
  3966. get inFunction() {
  3967. return (this.currentVarScopeFlags() & 2) > 0;
  3968. }
  3969. get allowSuper() {
  3970. return (this.currentThisScopeFlags() & 16) > 0;
  3971. }
  3972. get allowDirectSuper() {
  3973. return (this.currentThisScopeFlags() & 32) > 0;
  3974. }
  3975. get allowNewTarget() {
  3976. return (this.currentThisScopeFlags() & 512) > 0;
  3977. }
  3978. get inClass() {
  3979. return (this.currentThisScopeFlags() & 64) > 0;
  3980. }
  3981. get inClassAndNotInNonArrowFunction() {
  3982. const flags = this.currentThisScopeFlags();
  3983. return (flags & 64) > 0 && (flags & 2) === 0;
  3984. }
  3985. get inStaticBlock() {
  3986. for (let i = this.scopeStack.length - 1;; i--) {
  3987. const {
  3988. flags
  3989. } = this.scopeStack[i];
  3990. if (flags & 128) {
  3991. return true;
  3992. }
  3993. if (flags & (1667 | 64)) {
  3994. return false;
  3995. }
  3996. }
  3997. }
  3998. get inNonArrowFunction() {
  3999. return (this.currentThisScopeFlags() & 2) > 0;
  4000. }
  4001. get inBareCaseStatement() {
  4002. return (this.currentScope().flags & 256) > 0;
  4003. }
  4004. get treatFunctionsAsVar() {
  4005. return this.treatFunctionsAsVarInScope(this.currentScope());
  4006. }
  4007. createScope(flags) {
  4008. return new Scope(flags);
  4009. }
  4010. enter(flags) {
  4011. this.scopeStack.push(this.createScope(flags));
  4012. }
  4013. exit() {
  4014. const scope = this.scopeStack.pop();
  4015. return scope.flags;
  4016. }
  4017. treatFunctionsAsVarInScope(scope) {
  4018. return !!(scope.flags & (2 | 128) || !this.parser.inModule && scope.flags & 1);
  4019. }
  4020. declareName(name, bindingType, loc) {
  4021. let scope = this.currentScope();
  4022. if (bindingType & 8 || bindingType & 16) {
  4023. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4024. let type = scope.names.get(name) || 0;
  4025. if (bindingType & 16) {
  4026. type = type | 4;
  4027. } else {
  4028. if (!scope.firstLexicalName) {
  4029. scope.firstLexicalName = name;
  4030. }
  4031. type = type | 2;
  4032. }
  4033. scope.names.set(name, type);
  4034. if (bindingType & 8) {
  4035. this.maybeExportDefined(scope, name);
  4036. }
  4037. } else if (bindingType & 4) {
  4038. for (let i = this.scopeStack.length - 1; i >= 0; --i) {
  4039. scope = this.scopeStack[i];
  4040. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4041. scope.names.set(name, (scope.names.get(name) || 0) | 1);
  4042. this.maybeExportDefined(scope, name);
  4043. if (scope.flags & 1667) break;
  4044. }
  4045. }
  4046. if (this.parser.inModule && scope.flags & 1) {
  4047. this.undefinedExports.delete(name);
  4048. }
  4049. }
  4050. maybeExportDefined(scope, name) {
  4051. if (this.parser.inModule && scope.flags & 1) {
  4052. this.undefinedExports.delete(name);
  4053. }
  4054. }
  4055. checkRedeclarationInScope(scope, name, bindingType, loc) {
  4056. if (this.isRedeclaredInScope(scope, name, bindingType)) {
  4057. this.parser.raise(Errors.VarRedeclaration, loc, {
  4058. identifierName: name
  4059. });
  4060. }
  4061. }
  4062. isRedeclaredInScope(scope, name, bindingType) {
  4063. if (!(bindingType & 1)) return false;
  4064. if (bindingType & 8) {
  4065. return scope.names.has(name);
  4066. }
  4067. const type = scope.names.get(name);
  4068. if (bindingType & 16) {
  4069. return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope) && (type & 1) > 0;
  4070. }
  4071. return (type & 2) > 0 && !(scope.flags & 8 && scope.firstLexicalName === name) || !this.treatFunctionsAsVarInScope(scope) && (type & 4) > 0;
  4072. }
  4073. checkLocalExport(id) {
  4074. const {
  4075. name
  4076. } = id;
  4077. const topLevelScope = this.scopeStack[0];
  4078. if (!topLevelScope.names.has(name)) {
  4079. this.undefinedExports.set(name, id.loc.start);
  4080. }
  4081. }
  4082. currentScope() {
  4083. return this.scopeStack[this.scopeStack.length - 1];
  4084. }
  4085. currentVarScopeFlags() {
  4086. for (let i = this.scopeStack.length - 1;; i--) {
  4087. const {
  4088. flags
  4089. } = this.scopeStack[i];
  4090. if (flags & 1667) {
  4091. return flags;
  4092. }
  4093. }
  4094. }
  4095. currentThisScopeFlags() {
  4096. for (let i = this.scopeStack.length - 1;; i--) {
  4097. const {
  4098. flags
  4099. } = this.scopeStack[i];
  4100. if (flags & (1667 | 64) && !(flags & 4)) {
  4101. return flags;
  4102. }
  4103. }
  4104. }
  4105. }
  4106. class FlowScope extends Scope {
  4107. constructor(...args) {
  4108. super(...args);
  4109. this.declareFunctions = new Set();
  4110. }
  4111. }
  4112. class FlowScopeHandler extends ScopeHandler {
  4113. createScope(flags) {
  4114. return new FlowScope(flags);
  4115. }
  4116. declareName(name, bindingType, loc) {
  4117. const scope = this.currentScope();
  4118. if (bindingType & 2048) {
  4119. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  4120. this.maybeExportDefined(scope, name);
  4121. scope.declareFunctions.add(name);
  4122. return;
  4123. }
  4124. super.declareName(name, bindingType, loc);
  4125. }
  4126. isRedeclaredInScope(scope, name, bindingType) {
  4127. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  4128. if (bindingType & 2048 && !scope.declareFunctions.has(name)) {
  4129. const type = scope.names.get(name);
  4130. return (type & 4) > 0 || (type & 2) > 0;
  4131. }
  4132. return false;
  4133. }
  4134. checkLocalExport(id) {
  4135. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  4136. super.checkLocalExport(id);
  4137. }
  4138. }
  4139. }
  4140. const reservedTypes = new Set(["_", "any", "bool", "boolean", "empty", "extends", "false", "interface", "mixed", "null", "number", "static", "string", "true", "typeof", "void"]);
  4141. const FlowErrors = ParseErrorEnum`flow`({
  4142. AmbiguousConditionalArrow: "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.",
  4143. 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.",
  4144. AssignReservedType: ({
  4145. reservedType
  4146. }) => `Cannot overwrite reserved type ${reservedType}.`,
  4147. DeclareClassElement: "The `declare` modifier can only appear on class fields.",
  4148. DeclareClassFieldInitializer: "Initializers are not allowed in fields with the `declare` modifier.",
  4149. DuplicateDeclareModuleExports: "Duplicate `declare module.exports` statement.",
  4150. EnumBooleanMemberNotInitialized: ({
  4151. memberName,
  4152. enumName
  4153. }) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
  4154. EnumDuplicateMemberName: ({
  4155. memberName,
  4156. enumName
  4157. }) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
  4158. EnumInconsistentMemberValues: ({
  4159. enumName
  4160. }) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
  4161. EnumInvalidExplicitType: ({
  4162. invalidEnumType,
  4163. enumName
  4164. }) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4165. EnumInvalidExplicitTypeUnknownSupplied: ({
  4166. enumName
  4167. }) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
  4168. EnumInvalidMemberInitializerPrimaryType: ({
  4169. enumName,
  4170. memberName,
  4171. explicitType
  4172. }) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
  4173. EnumInvalidMemberInitializerSymbolType: ({
  4174. enumName,
  4175. memberName
  4176. }) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
  4177. EnumInvalidMemberInitializerUnknownType: ({
  4178. enumName,
  4179. memberName
  4180. }) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
  4181. EnumInvalidMemberName: ({
  4182. enumName,
  4183. memberName,
  4184. suggestion
  4185. }) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
  4186. EnumNumberMemberNotInitialized: ({
  4187. enumName,
  4188. memberName
  4189. }) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
  4190. EnumStringMemberInconsistentlyInitialized: ({
  4191. enumName
  4192. }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
  4193. GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.",
  4194. ImportReflectionHasImportType: "An `import module` declaration can not use `type` or `typeof` keyword.",
  4195. 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.",
  4196. InexactInsideExact: "Explicit inexact syntax cannot appear inside an explicit exact object type.",
  4197. InexactInsideNonObject: "Explicit inexact syntax cannot appear in class or interface definitions.",
  4198. InexactVariance: "Explicit inexact syntax cannot have variance.",
  4199. InvalidNonTypeImportInDeclareModule: "Imports within a `declare module` body must always be `import type` or `import typeof`.",
  4200. MissingTypeParamDefault: "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.",
  4201. NestedDeclareModule: "`declare module` cannot be used inside another `declare module`.",
  4202. NestedFlowComment: "Cannot have a flow comment inside another flow comment.",
  4203. PatternIsOptional: Object.assign({
  4204. message: "A binding pattern parameter cannot be optional in an implementation signature."
  4205. }, {
  4206. reasonCode: "OptionalBindingPattern"
  4207. }),
  4208. SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.",
  4209. SpreadVariance: "Spread properties cannot have variance.",
  4210. ThisParamAnnotationRequired: "A type annotation is required for the `this` parameter.",
  4211. ThisParamBannedInConstructor: "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.",
  4212. ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.",
  4213. ThisParamMustBeFirst: "The `this` parameter must be the first function parameter.",
  4214. ThisParamNoDefault: "The `this` parameter may not have a default value.",
  4215. TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  4216. TypeCastInPattern: "The type cast expression is expected to be wrapped with parenthesis.",
  4217. UnexpectedExplicitInexactInObject: "Explicit inexact syntax must appear at the end of an inexact object.",
  4218. UnexpectedReservedType: ({
  4219. reservedType
  4220. }) => `Unexpected reserved type ${reservedType}.`,
  4221. UnexpectedReservedUnderscore: "`_` is only allowed as a type argument to call or new.",
  4222. UnexpectedSpaceBetweenModuloChecks: "Spaces between `%` and `checks` are not allowed here.",
  4223. UnexpectedSpreadType: "Spread operator cannot appear in class or interface definitions.",
  4224. UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
  4225. UnexpectedTokenAfterTypeParameter: "Expected an arrow function after this type parameter declaration.",
  4226. UnexpectedTypeParameterBeforeAsyncArrowFunction: "Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.",
  4227. UnsupportedDeclareExportKind: ({
  4228. unsupportedExportKind,
  4229. suggestion
  4230. }) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
  4231. UnsupportedStatementInDeclareModule: "Only declares and type imports are allowed inside declare module.",
  4232. UnterminatedFlowComment: "Unterminated flow-comment."
  4233. });
  4234. function isEsModuleType(bodyElement) {
  4235. return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
  4236. }
  4237. function hasTypeImportKind(node) {
  4238. return node.importKind === "type" || node.importKind === "typeof";
  4239. }
  4240. const exportSuggestions = {
  4241. const: "declare export var",
  4242. let: "declare export var",
  4243. type: "export type",
  4244. interface: "export interface"
  4245. };
  4246. function partition(list, test) {
  4247. const list1 = [];
  4248. const list2 = [];
  4249. for (let i = 0; i < list.length; i++) {
  4250. (test(list[i], i, list) ? list1 : list2).push(list[i]);
  4251. }
  4252. return [list1, list2];
  4253. }
  4254. const FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
  4255. var flow = superClass => class FlowParserMixin extends superClass {
  4256. constructor(...args) {
  4257. super(...args);
  4258. this.flowPragma = undefined;
  4259. }
  4260. getScopeHandler() {
  4261. return FlowScopeHandler;
  4262. }
  4263. shouldParseTypes() {
  4264. return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
  4265. }
  4266. finishToken(type, val) {
  4267. if (type !== 134 && type !== 13 && type !== 28) {
  4268. if (this.flowPragma === undefined) {
  4269. this.flowPragma = null;
  4270. }
  4271. }
  4272. super.finishToken(type, val);
  4273. }
  4274. addComment(comment) {
  4275. if (this.flowPragma === undefined) {
  4276. const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
  4277. if (!matches) ;else if (matches[1] === "flow") {
  4278. this.flowPragma = "flow";
  4279. } else if (matches[1] === "noflow") {
  4280. this.flowPragma = "noflow";
  4281. } else {
  4282. throw new Error("Unexpected flow pragma");
  4283. }
  4284. }
  4285. super.addComment(comment);
  4286. }
  4287. flowParseTypeInitialiser(tok) {
  4288. const oldInType = this.state.inType;
  4289. this.state.inType = true;
  4290. this.expect(tok || 14);
  4291. const type = this.flowParseType();
  4292. this.state.inType = oldInType;
  4293. return type;
  4294. }
  4295. flowParsePredicate() {
  4296. const node = this.startNode();
  4297. const moduloLoc = this.state.startLoc;
  4298. this.next();
  4299. this.expectContextual(110);
  4300. if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
  4301. this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
  4302. }
  4303. if (this.eat(10)) {
  4304. node.value = super.parseExpression();
  4305. this.expect(11);
  4306. return this.finishNode(node, "DeclaredPredicate");
  4307. } else {
  4308. return this.finishNode(node, "InferredPredicate");
  4309. }
  4310. }
  4311. flowParseTypeAndPredicateInitialiser() {
  4312. const oldInType = this.state.inType;
  4313. this.state.inType = true;
  4314. this.expect(14);
  4315. let type = null;
  4316. let predicate = null;
  4317. if (this.match(54)) {
  4318. this.state.inType = oldInType;
  4319. predicate = this.flowParsePredicate();
  4320. } else {
  4321. type = this.flowParseType();
  4322. this.state.inType = oldInType;
  4323. if (this.match(54)) {
  4324. predicate = this.flowParsePredicate();
  4325. }
  4326. }
  4327. return [type, predicate];
  4328. }
  4329. flowParseDeclareClass(node) {
  4330. this.next();
  4331. this.flowParseInterfaceish(node, true);
  4332. return this.finishNode(node, "DeclareClass");
  4333. }
  4334. flowParseDeclareFunction(node) {
  4335. this.next();
  4336. const id = node.id = this.parseIdentifier();
  4337. const typeNode = this.startNode();
  4338. const typeContainer = this.startNode();
  4339. if (this.match(47)) {
  4340. typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
  4341. } else {
  4342. typeNode.typeParameters = null;
  4343. }
  4344. this.expect(10);
  4345. const tmp = this.flowParseFunctionTypeParams();
  4346. typeNode.params = tmp.params;
  4347. typeNode.rest = tmp.rest;
  4348. typeNode.this = tmp._this;
  4349. this.expect(11);
  4350. [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  4351. typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
  4352. id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
  4353. this.resetEndLocation(id);
  4354. this.semicolon();
  4355. this.scope.declareName(node.id.name, 2048, node.id.loc.start);
  4356. return this.finishNode(node, "DeclareFunction");
  4357. }
  4358. flowParseDeclare(node, insideModule) {
  4359. if (this.match(80)) {
  4360. return this.flowParseDeclareClass(node);
  4361. } else if (this.match(68)) {
  4362. return this.flowParseDeclareFunction(node);
  4363. } else if (this.match(74)) {
  4364. return this.flowParseDeclareVariable(node);
  4365. } else if (this.eatContextual(127)) {
  4366. if (this.match(16)) {
  4367. return this.flowParseDeclareModuleExports(node);
  4368. } else {
  4369. if (insideModule) {
  4370. this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
  4371. }
  4372. return this.flowParseDeclareModule(node);
  4373. }
  4374. } else if (this.isContextual(130)) {
  4375. return this.flowParseDeclareTypeAlias(node);
  4376. } else if (this.isContextual(131)) {
  4377. return this.flowParseDeclareOpaqueType(node);
  4378. } else if (this.isContextual(129)) {
  4379. return this.flowParseDeclareInterface(node);
  4380. } else if (this.match(82)) {
  4381. return this.flowParseDeclareExportDeclaration(node, insideModule);
  4382. } else {
  4383. this.unexpected();
  4384. }
  4385. }
  4386. flowParseDeclareVariable(node) {
  4387. this.next();
  4388. node.id = this.flowParseTypeAnnotatableIdentifier(true);
  4389. this.scope.declareName(node.id.name, 5, node.id.loc.start);
  4390. this.semicolon();
  4391. return this.finishNode(node, "DeclareVariable");
  4392. }
  4393. flowParseDeclareModule(node) {
  4394. this.scope.enter(0);
  4395. if (this.match(134)) {
  4396. node.id = super.parseExprAtom();
  4397. } else {
  4398. node.id = this.parseIdentifier();
  4399. }
  4400. const bodyNode = node.body = this.startNode();
  4401. const body = bodyNode.body = [];
  4402. this.expect(5);
  4403. while (!this.match(8)) {
  4404. let bodyNode = this.startNode();
  4405. if (this.match(83)) {
  4406. this.next();
  4407. if (!this.isContextual(130) && !this.match(87)) {
  4408. this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
  4409. }
  4410. super.parseImport(bodyNode);
  4411. } else {
  4412. this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
  4413. bodyNode = this.flowParseDeclare(bodyNode, true);
  4414. }
  4415. body.push(bodyNode);
  4416. }
  4417. this.scope.exit();
  4418. this.expect(8);
  4419. this.finishNode(bodyNode, "BlockStatement");
  4420. let kind = null;
  4421. let hasModuleExport = false;
  4422. body.forEach(bodyElement => {
  4423. if (isEsModuleType(bodyElement)) {
  4424. if (kind === "CommonJS") {
  4425. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4426. }
  4427. kind = "ES";
  4428. } else if (bodyElement.type === "DeclareModuleExports") {
  4429. if (hasModuleExport) {
  4430. this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
  4431. }
  4432. if (kind === "ES") {
  4433. this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
  4434. }
  4435. kind = "CommonJS";
  4436. hasModuleExport = true;
  4437. }
  4438. });
  4439. node.kind = kind || "CommonJS";
  4440. return this.finishNode(node, "DeclareModule");
  4441. }
  4442. flowParseDeclareExportDeclaration(node, insideModule) {
  4443. this.expect(82);
  4444. if (this.eat(65)) {
  4445. if (this.match(68) || this.match(80)) {
  4446. node.declaration = this.flowParseDeclare(this.startNode());
  4447. } else {
  4448. node.declaration = this.flowParseType();
  4449. this.semicolon();
  4450. }
  4451. node.default = true;
  4452. return this.finishNode(node, "DeclareExportDeclaration");
  4453. } else {
  4454. if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
  4455. const label = this.state.value;
  4456. throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
  4457. unsupportedExportKind: label,
  4458. suggestion: exportSuggestions[label]
  4459. });
  4460. }
  4461. if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
  4462. node.declaration = this.flowParseDeclare(this.startNode());
  4463. node.default = false;
  4464. return this.finishNode(node, "DeclareExportDeclaration");
  4465. } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
  4466. node = this.parseExport(node, null);
  4467. if (node.type === "ExportNamedDeclaration") {
  4468. node.default = false;
  4469. delete node.exportKind;
  4470. return this.castNodeTo(node, "DeclareExportDeclaration");
  4471. } else {
  4472. return this.castNodeTo(node, "DeclareExportAllDeclaration");
  4473. }
  4474. }
  4475. }
  4476. this.unexpected();
  4477. }
  4478. flowParseDeclareModuleExports(node) {
  4479. this.next();
  4480. this.expectContextual(111);
  4481. node.typeAnnotation = this.flowParseTypeAnnotation();
  4482. this.semicolon();
  4483. return this.finishNode(node, "DeclareModuleExports");
  4484. }
  4485. flowParseDeclareTypeAlias(node) {
  4486. this.next();
  4487. const finished = this.flowParseTypeAlias(node);
  4488. this.castNodeTo(finished, "DeclareTypeAlias");
  4489. return finished;
  4490. }
  4491. flowParseDeclareOpaqueType(node) {
  4492. this.next();
  4493. const finished = this.flowParseOpaqueType(node, true);
  4494. this.castNodeTo(finished, "DeclareOpaqueType");
  4495. return finished;
  4496. }
  4497. flowParseDeclareInterface(node) {
  4498. this.next();
  4499. this.flowParseInterfaceish(node, false);
  4500. return this.finishNode(node, "DeclareInterface");
  4501. }
  4502. flowParseInterfaceish(node, isClass) {
  4503. node.id = this.flowParseRestrictedIdentifier(!isClass, true);
  4504. this.scope.declareName(node.id.name, isClass ? 17 : 8201, node.id.loc.start);
  4505. if (this.match(47)) {
  4506. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4507. } else {
  4508. node.typeParameters = null;
  4509. }
  4510. node.extends = [];
  4511. if (this.eat(81)) {
  4512. do {
  4513. node.extends.push(this.flowParseInterfaceExtends());
  4514. } while (!isClass && this.eat(12));
  4515. }
  4516. if (isClass) {
  4517. node.implements = [];
  4518. node.mixins = [];
  4519. if (this.eatContextual(117)) {
  4520. do {
  4521. node.mixins.push(this.flowParseInterfaceExtends());
  4522. } while (this.eat(12));
  4523. }
  4524. if (this.eatContextual(113)) {
  4525. do {
  4526. node.implements.push(this.flowParseInterfaceExtends());
  4527. } while (this.eat(12));
  4528. }
  4529. }
  4530. node.body = this.flowParseObjectType({
  4531. allowStatic: isClass,
  4532. allowExact: false,
  4533. allowSpread: false,
  4534. allowProto: isClass,
  4535. allowInexact: false
  4536. });
  4537. }
  4538. flowParseInterfaceExtends() {
  4539. const node = this.startNode();
  4540. node.id = this.flowParseQualifiedTypeIdentifier();
  4541. if (this.match(47)) {
  4542. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4543. } else {
  4544. node.typeParameters = null;
  4545. }
  4546. return this.finishNode(node, "InterfaceExtends");
  4547. }
  4548. flowParseInterface(node) {
  4549. this.flowParseInterfaceish(node, false);
  4550. return this.finishNode(node, "InterfaceDeclaration");
  4551. }
  4552. checkNotUnderscore(word) {
  4553. if (word === "_") {
  4554. this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
  4555. }
  4556. }
  4557. checkReservedType(word, startLoc, declaration) {
  4558. if (!reservedTypes.has(word)) return;
  4559. this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
  4560. reservedType: word
  4561. });
  4562. }
  4563. flowParseRestrictedIdentifier(liberal, declaration) {
  4564. this.checkReservedType(this.state.value, this.state.startLoc, declaration);
  4565. return this.parseIdentifier(liberal);
  4566. }
  4567. flowParseTypeAlias(node) {
  4568. node.id = this.flowParseRestrictedIdentifier(false, true);
  4569. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4570. if (this.match(47)) {
  4571. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4572. } else {
  4573. node.typeParameters = null;
  4574. }
  4575. node.right = this.flowParseTypeInitialiser(29);
  4576. this.semicolon();
  4577. return this.finishNode(node, "TypeAlias");
  4578. }
  4579. flowParseOpaqueType(node, declare) {
  4580. this.expectContextual(130);
  4581. node.id = this.flowParseRestrictedIdentifier(true, true);
  4582. this.scope.declareName(node.id.name, 8201, node.id.loc.start);
  4583. if (this.match(47)) {
  4584. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4585. } else {
  4586. node.typeParameters = null;
  4587. }
  4588. node.supertype = null;
  4589. if (this.match(14)) {
  4590. node.supertype = this.flowParseTypeInitialiser(14);
  4591. }
  4592. node.impltype = null;
  4593. if (!declare) {
  4594. node.impltype = this.flowParseTypeInitialiser(29);
  4595. }
  4596. this.semicolon();
  4597. return this.finishNode(node, "OpaqueType");
  4598. }
  4599. flowParseTypeParameter(requireDefault = false) {
  4600. const nodeStartLoc = this.state.startLoc;
  4601. const node = this.startNode();
  4602. const variance = this.flowParseVariance();
  4603. const ident = this.flowParseTypeAnnotatableIdentifier();
  4604. node.name = ident.name;
  4605. node.variance = variance;
  4606. node.bound = ident.typeAnnotation;
  4607. if (this.match(29)) {
  4608. this.eat(29);
  4609. node.default = this.flowParseType();
  4610. } else {
  4611. if (requireDefault) {
  4612. this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
  4613. }
  4614. }
  4615. return this.finishNode(node, "TypeParameter");
  4616. }
  4617. flowParseTypeParameterDeclaration() {
  4618. const oldInType = this.state.inType;
  4619. const node = this.startNode();
  4620. node.params = [];
  4621. this.state.inType = true;
  4622. if (this.match(47) || this.match(143)) {
  4623. this.next();
  4624. } else {
  4625. this.unexpected();
  4626. }
  4627. let defaultRequired = false;
  4628. do {
  4629. const typeParameter = this.flowParseTypeParameter(defaultRequired);
  4630. node.params.push(typeParameter);
  4631. if (typeParameter.default) {
  4632. defaultRequired = true;
  4633. }
  4634. if (!this.match(48)) {
  4635. this.expect(12);
  4636. }
  4637. } while (!this.match(48));
  4638. this.expect(48);
  4639. this.state.inType = oldInType;
  4640. return this.finishNode(node, "TypeParameterDeclaration");
  4641. }
  4642. flowInTopLevelContext(cb) {
  4643. if (this.curContext() !== types.brace) {
  4644. const oldContext = this.state.context;
  4645. this.state.context = [oldContext[0]];
  4646. try {
  4647. return cb();
  4648. } finally {
  4649. this.state.context = oldContext;
  4650. }
  4651. } else {
  4652. return cb();
  4653. }
  4654. }
  4655. flowParseTypeParameterInstantiationInExpression() {
  4656. if (this.reScan_lt() !== 47) return;
  4657. return this.flowParseTypeParameterInstantiation();
  4658. }
  4659. flowParseTypeParameterInstantiation() {
  4660. const node = this.startNode();
  4661. const oldInType = this.state.inType;
  4662. this.state.inType = true;
  4663. node.params = [];
  4664. this.flowInTopLevelContext(() => {
  4665. this.expect(47);
  4666. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  4667. this.state.noAnonFunctionType = false;
  4668. while (!this.match(48)) {
  4669. node.params.push(this.flowParseType());
  4670. if (!this.match(48)) {
  4671. this.expect(12);
  4672. }
  4673. }
  4674. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  4675. });
  4676. this.state.inType = oldInType;
  4677. if (!this.state.inType && this.curContext() === types.brace) {
  4678. this.reScan_lt_gt();
  4679. }
  4680. this.expect(48);
  4681. return this.finishNode(node, "TypeParameterInstantiation");
  4682. }
  4683. flowParseTypeParameterInstantiationCallOrNew() {
  4684. if (this.reScan_lt() !== 47) return;
  4685. const node = this.startNode();
  4686. const oldInType = this.state.inType;
  4687. node.params = [];
  4688. this.state.inType = true;
  4689. this.expect(47);
  4690. while (!this.match(48)) {
  4691. node.params.push(this.flowParseTypeOrImplicitInstantiation());
  4692. if (!this.match(48)) {
  4693. this.expect(12);
  4694. }
  4695. }
  4696. this.expect(48);
  4697. this.state.inType = oldInType;
  4698. return this.finishNode(node, "TypeParameterInstantiation");
  4699. }
  4700. flowParseInterfaceType() {
  4701. const node = this.startNode();
  4702. this.expectContextual(129);
  4703. node.extends = [];
  4704. if (this.eat(81)) {
  4705. do {
  4706. node.extends.push(this.flowParseInterfaceExtends());
  4707. } while (this.eat(12));
  4708. }
  4709. node.body = this.flowParseObjectType({
  4710. allowStatic: false,
  4711. allowExact: false,
  4712. allowSpread: false,
  4713. allowProto: false,
  4714. allowInexact: false
  4715. });
  4716. return this.finishNode(node, "InterfaceTypeAnnotation");
  4717. }
  4718. flowParseObjectPropertyKey() {
  4719. return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
  4720. }
  4721. flowParseObjectTypeIndexer(node, isStatic, variance) {
  4722. node.static = isStatic;
  4723. if (this.lookahead().type === 14) {
  4724. node.id = this.flowParseObjectPropertyKey();
  4725. node.key = this.flowParseTypeInitialiser();
  4726. } else {
  4727. node.id = null;
  4728. node.key = this.flowParseType();
  4729. }
  4730. this.expect(3);
  4731. node.value = this.flowParseTypeInitialiser();
  4732. node.variance = variance;
  4733. return this.finishNode(node, "ObjectTypeIndexer");
  4734. }
  4735. flowParseObjectTypeInternalSlot(node, isStatic) {
  4736. node.static = isStatic;
  4737. node.id = this.flowParseObjectPropertyKey();
  4738. this.expect(3);
  4739. this.expect(3);
  4740. if (this.match(47) || this.match(10)) {
  4741. node.method = true;
  4742. node.optional = false;
  4743. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4744. } else {
  4745. node.method = false;
  4746. if (this.eat(17)) {
  4747. node.optional = true;
  4748. }
  4749. node.value = this.flowParseTypeInitialiser();
  4750. }
  4751. return this.finishNode(node, "ObjectTypeInternalSlot");
  4752. }
  4753. flowParseObjectTypeMethodish(node) {
  4754. node.params = [];
  4755. node.rest = null;
  4756. node.typeParameters = null;
  4757. node.this = null;
  4758. if (this.match(47)) {
  4759. node.typeParameters = this.flowParseTypeParameterDeclaration();
  4760. }
  4761. this.expect(10);
  4762. if (this.match(78)) {
  4763. node.this = this.flowParseFunctionTypeParam(true);
  4764. node.this.name = null;
  4765. if (!this.match(11)) {
  4766. this.expect(12);
  4767. }
  4768. }
  4769. while (!this.match(11) && !this.match(21)) {
  4770. node.params.push(this.flowParseFunctionTypeParam(false));
  4771. if (!this.match(11)) {
  4772. this.expect(12);
  4773. }
  4774. }
  4775. if (this.eat(21)) {
  4776. node.rest = this.flowParseFunctionTypeParam(false);
  4777. }
  4778. this.expect(11);
  4779. node.returnType = this.flowParseTypeInitialiser();
  4780. return this.finishNode(node, "FunctionTypeAnnotation");
  4781. }
  4782. flowParseObjectTypeCallProperty(node, isStatic) {
  4783. const valueNode = this.startNode();
  4784. node.static = isStatic;
  4785. node.value = this.flowParseObjectTypeMethodish(valueNode);
  4786. return this.finishNode(node, "ObjectTypeCallProperty");
  4787. }
  4788. flowParseObjectType({
  4789. allowStatic,
  4790. allowExact,
  4791. allowSpread,
  4792. allowProto,
  4793. allowInexact
  4794. }) {
  4795. const oldInType = this.state.inType;
  4796. this.state.inType = true;
  4797. const nodeStart = this.startNode();
  4798. nodeStart.callProperties = [];
  4799. nodeStart.properties = [];
  4800. nodeStart.indexers = [];
  4801. nodeStart.internalSlots = [];
  4802. let endDelim;
  4803. let exact;
  4804. let inexact = false;
  4805. if (allowExact && this.match(6)) {
  4806. this.expect(6);
  4807. endDelim = 9;
  4808. exact = true;
  4809. } else {
  4810. this.expect(5);
  4811. endDelim = 8;
  4812. exact = false;
  4813. }
  4814. nodeStart.exact = exact;
  4815. while (!this.match(endDelim)) {
  4816. let isStatic = false;
  4817. let protoStartLoc = null;
  4818. let inexactStartLoc = null;
  4819. const node = this.startNode();
  4820. if (allowProto && this.isContextual(118)) {
  4821. const lookahead = this.lookahead();
  4822. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4823. this.next();
  4824. protoStartLoc = this.state.startLoc;
  4825. allowStatic = false;
  4826. }
  4827. }
  4828. if (allowStatic && this.isContextual(106)) {
  4829. const lookahead = this.lookahead();
  4830. if (lookahead.type !== 14 && lookahead.type !== 17) {
  4831. this.next();
  4832. isStatic = true;
  4833. }
  4834. }
  4835. const variance = this.flowParseVariance();
  4836. if (this.eat(0)) {
  4837. if (protoStartLoc != null) {
  4838. this.unexpected(protoStartLoc);
  4839. }
  4840. if (this.eat(0)) {
  4841. if (variance) {
  4842. this.unexpected(variance.loc.start);
  4843. }
  4844. nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic));
  4845. } else {
  4846. nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic, variance));
  4847. }
  4848. } else if (this.match(10) || this.match(47)) {
  4849. if (protoStartLoc != null) {
  4850. this.unexpected(protoStartLoc);
  4851. }
  4852. if (variance) {
  4853. this.unexpected(variance.loc.start);
  4854. }
  4855. nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic));
  4856. } else {
  4857. let kind = "init";
  4858. if (this.isContextual(99) || this.isContextual(104)) {
  4859. const lookahead = this.lookahead();
  4860. if (tokenIsLiteralPropertyName(lookahead.type)) {
  4861. kind = this.state.value;
  4862. this.next();
  4863. }
  4864. }
  4865. const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact != null ? allowInexact : !exact);
  4866. if (propOrInexact === null) {
  4867. inexact = true;
  4868. inexactStartLoc = this.state.lastTokStartLoc;
  4869. } else {
  4870. nodeStart.properties.push(propOrInexact);
  4871. }
  4872. }
  4873. this.flowObjectTypeSemicolon();
  4874. if (inexactStartLoc && !this.match(8) && !this.match(9)) {
  4875. this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
  4876. }
  4877. }
  4878. this.expect(endDelim);
  4879. if (allowSpread) {
  4880. nodeStart.inexact = inexact;
  4881. }
  4882. const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
  4883. this.state.inType = oldInType;
  4884. return out;
  4885. }
  4886. flowParseObjectTypeProperty(node, isStatic, protoStartLoc, variance, kind, allowSpread, allowInexact) {
  4887. if (this.eat(21)) {
  4888. const isInexactToken = this.match(12) || this.match(13) || this.match(8) || this.match(9);
  4889. if (isInexactToken) {
  4890. if (!allowSpread) {
  4891. this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
  4892. } else if (!allowInexact) {
  4893. this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
  4894. }
  4895. if (variance) {
  4896. this.raise(FlowErrors.InexactVariance, variance);
  4897. }
  4898. return null;
  4899. }
  4900. if (!allowSpread) {
  4901. this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
  4902. }
  4903. if (protoStartLoc != null) {
  4904. this.unexpected(protoStartLoc);
  4905. }
  4906. if (variance) {
  4907. this.raise(FlowErrors.SpreadVariance, variance);
  4908. }
  4909. node.argument = this.flowParseType();
  4910. return this.finishNode(node, "ObjectTypeSpreadProperty");
  4911. } else {
  4912. node.key = this.flowParseObjectPropertyKey();
  4913. node.static = isStatic;
  4914. node.proto = protoStartLoc != null;
  4915. node.kind = kind;
  4916. let optional = false;
  4917. if (this.match(47) || this.match(10)) {
  4918. node.method = true;
  4919. if (protoStartLoc != null) {
  4920. this.unexpected(protoStartLoc);
  4921. }
  4922. if (variance) {
  4923. this.unexpected(variance.loc.start);
  4924. }
  4925. node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
  4926. if (kind === "get" || kind === "set") {
  4927. this.flowCheckGetterSetterParams(node);
  4928. }
  4929. if (!allowSpread && node.key.name === "constructor" && node.value.this) {
  4930. this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
  4931. }
  4932. } else {
  4933. if (kind !== "init") this.unexpected();
  4934. node.method = false;
  4935. if (this.eat(17)) {
  4936. optional = true;
  4937. }
  4938. node.value = this.flowParseTypeInitialiser();
  4939. node.variance = variance;
  4940. }
  4941. node.optional = optional;
  4942. return this.finishNode(node, "ObjectTypeProperty");
  4943. }
  4944. }
  4945. flowCheckGetterSetterParams(property) {
  4946. const paramCount = property.kind === "get" ? 0 : 1;
  4947. const length = property.value.params.length + (property.value.rest ? 1 : 0);
  4948. if (property.value.this) {
  4949. this.raise(property.kind === "get" ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
  4950. }
  4951. if (length !== paramCount) {
  4952. this.raise(property.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, property);
  4953. }
  4954. if (property.kind === "set" && property.value.rest) {
  4955. this.raise(Errors.BadSetterRestParameter, property);
  4956. }
  4957. }
  4958. flowObjectTypeSemicolon() {
  4959. if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
  4960. this.unexpected();
  4961. }
  4962. }
  4963. flowParseQualifiedTypeIdentifier(startLoc, id) {
  4964. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  4965. let node = id || this.flowParseRestrictedIdentifier(true);
  4966. while (this.eat(16)) {
  4967. const node2 = this.startNodeAt(startLoc);
  4968. node2.qualification = node;
  4969. node2.id = this.flowParseRestrictedIdentifier(true);
  4970. node = this.finishNode(node2, "QualifiedTypeIdentifier");
  4971. }
  4972. return node;
  4973. }
  4974. flowParseGenericType(startLoc, id) {
  4975. const node = this.startNodeAt(startLoc);
  4976. node.typeParameters = null;
  4977. node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
  4978. if (this.match(47)) {
  4979. node.typeParameters = this.flowParseTypeParameterInstantiation();
  4980. }
  4981. return this.finishNode(node, "GenericTypeAnnotation");
  4982. }
  4983. flowParseTypeofType() {
  4984. const node = this.startNode();
  4985. this.expect(87);
  4986. node.argument = this.flowParsePrimaryType();
  4987. return this.finishNode(node, "TypeofTypeAnnotation");
  4988. }
  4989. flowParseTupleType() {
  4990. const node = this.startNode();
  4991. node.types = [];
  4992. this.expect(0);
  4993. while (this.state.pos < this.length && !this.match(3)) {
  4994. node.types.push(this.flowParseType());
  4995. if (this.match(3)) break;
  4996. this.expect(12);
  4997. }
  4998. this.expect(3);
  4999. return this.finishNode(node, "TupleTypeAnnotation");
  5000. }
  5001. flowParseFunctionTypeParam(first) {
  5002. let name = null;
  5003. let optional = false;
  5004. let typeAnnotation = null;
  5005. const node = this.startNode();
  5006. const lh = this.lookahead();
  5007. const isThis = this.state.type === 78;
  5008. if (lh.type === 14 || lh.type === 17) {
  5009. if (isThis && !first) {
  5010. this.raise(FlowErrors.ThisParamMustBeFirst, node);
  5011. }
  5012. name = this.parseIdentifier(isThis);
  5013. if (this.eat(17)) {
  5014. optional = true;
  5015. if (isThis) {
  5016. this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
  5017. }
  5018. }
  5019. typeAnnotation = this.flowParseTypeInitialiser();
  5020. } else {
  5021. typeAnnotation = this.flowParseType();
  5022. }
  5023. node.name = name;
  5024. node.optional = optional;
  5025. node.typeAnnotation = typeAnnotation;
  5026. return this.finishNode(node, "FunctionTypeParam");
  5027. }
  5028. reinterpretTypeAsFunctionTypeParam(type) {
  5029. const node = this.startNodeAt(type.loc.start);
  5030. node.name = null;
  5031. node.optional = false;
  5032. node.typeAnnotation = type;
  5033. return this.finishNode(node, "FunctionTypeParam");
  5034. }
  5035. flowParseFunctionTypeParams(params = []) {
  5036. let rest = null;
  5037. let _this = null;
  5038. if (this.match(78)) {
  5039. _this = this.flowParseFunctionTypeParam(true);
  5040. _this.name = null;
  5041. if (!this.match(11)) {
  5042. this.expect(12);
  5043. }
  5044. }
  5045. while (!this.match(11) && !this.match(21)) {
  5046. params.push(this.flowParseFunctionTypeParam(false));
  5047. if (!this.match(11)) {
  5048. this.expect(12);
  5049. }
  5050. }
  5051. if (this.eat(21)) {
  5052. rest = this.flowParseFunctionTypeParam(false);
  5053. }
  5054. return {
  5055. params,
  5056. rest,
  5057. _this
  5058. };
  5059. }
  5060. flowIdentToTypeAnnotation(startLoc, node, id) {
  5061. switch (id.name) {
  5062. case "any":
  5063. return this.finishNode(node, "AnyTypeAnnotation");
  5064. case "bool":
  5065. case "boolean":
  5066. return this.finishNode(node, "BooleanTypeAnnotation");
  5067. case "mixed":
  5068. return this.finishNode(node, "MixedTypeAnnotation");
  5069. case "empty":
  5070. return this.finishNode(node, "EmptyTypeAnnotation");
  5071. case "number":
  5072. return this.finishNode(node, "NumberTypeAnnotation");
  5073. case "string":
  5074. return this.finishNode(node, "StringTypeAnnotation");
  5075. case "symbol":
  5076. return this.finishNode(node, "SymbolTypeAnnotation");
  5077. default:
  5078. this.checkNotUnderscore(id.name);
  5079. return this.flowParseGenericType(startLoc, id);
  5080. }
  5081. }
  5082. flowParsePrimaryType() {
  5083. const startLoc = this.state.startLoc;
  5084. const node = this.startNode();
  5085. let tmp;
  5086. let type;
  5087. let isGroupedType = false;
  5088. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5089. switch (this.state.type) {
  5090. case 5:
  5091. return this.flowParseObjectType({
  5092. allowStatic: false,
  5093. allowExact: false,
  5094. allowSpread: true,
  5095. allowProto: false,
  5096. allowInexact: true
  5097. });
  5098. case 6:
  5099. return this.flowParseObjectType({
  5100. allowStatic: false,
  5101. allowExact: true,
  5102. allowSpread: true,
  5103. allowProto: false,
  5104. allowInexact: false
  5105. });
  5106. case 0:
  5107. this.state.noAnonFunctionType = false;
  5108. type = this.flowParseTupleType();
  5109. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5110. return type;
  5111. case 47:
  5112. {
  5113. const node = this.startNode();
  5114. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5115. this.expect(10);
  5116. tmp = this.flowParseFunctionTypeParams();
  5117. node.params = tmp.params;
  5118. node.rest = tmp.rest;
  5119. node.this = tmp._this;
  5120. this.expect(11);
  5121. this.expect(19);
  5122. node.returnType = this.flowParseType();
  5123. return this.finishNode(node, "FunctionTypeAnnotation");
  5124. }
  5125. case 10:
  5126. {
  5127. const node = this.startNode();
  5128. this.next();
  5129. if (!this.match(11) && !this.match(21)) {
  5130. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  5131. const token = this.lookahead().type;
  5132. isGroupedType = token !== 17 && token !== 14;
  5133. } else {
  5134. isGroupedType = true;
  5135. }
  5136. }
  5137. if (isGroupedType) {
  5138. this.state.noAnonFunctionType = false;
  5139. type = this.flowParseType();
  5140. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5141. if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
  5142. this.expect(11);
  5143. return type;
  5144. } else {
  5145. this.eat(12);
  5146. }
  5147. }
  5148. if (type) {
  5149. tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
  5150. } else {
  5151. tmp = this.flowParseFunctionTypeParams();
  5152. }
  5153. node.params = tmp.params;
  5154. node.rest = tmp.rest;
  5155. node.this = tmp._this;
  5156. this.expect(11);
  5157. this.expect(19);
  5158. node.returnType = this.flowParseType();
  5159. node.typeParameters = null;
  5160. return this.finishNode(node, "FunctionTypeAnnotation");
  5161. }
  5162. case 134:
  5163. return this.parseLiteral(this.state.value, "StringLiteralTypeAnnotation");
  5164. case 85:
  5165. case 86:
  5166. node.value = this.match(85);
  5167. this.next();
  5168. return this.finishNode(node, "BooleanLiteralTypeAnnotation");
  5169. case 53:
  5170. if (this.state.value === "-") {
  5171. this.next();
  5172. if (this.match(135)) {
  5173. return this.parseLiteralAtNode(-this.state.value, "NumberLiteralTypeAnnotation", node);
  5174. }
  5175. if (this.match(136)) {
  5176. return this.parseLiteralAtNode(-this.state.value, "BigIntLiteralTypeAnnotation", node);
  5177. }
  5178. throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
  5179. }
  5180. this.unexpected();
  5181. return;
  5182. case 135:
  5183. return this.parseLiteral(this.state.value, "NumberLiteralTypeAnnotation");
  5184. case 136:
  5185. return this.parseLiteral(this.state.value, "BigIntLiteralTypeAnnotation");
  5186. case 88:
  5187. this.next();
  5188. return this.finishNode(node, "VoidTypeAnnotation");
  5189. case 84:
  5190. this.next();
  5191. return this.finishNode(node, "NullLiteralTypeAnnotation");
  5192. case 78:
  5193. this.next();
  5194. return this.finishNode(node, "ThisTypeAnnotation");
  5195. case 55:
  5196. this.next();
  5197. return this.finishNode(node, "ExistsTypeAnnotation");
  5198. case 87:
  5199. return this.flowParseTypeofType();
  5200. default:
  5201. if (tokenIsKeyword(this.state.type)) {
  5202. const label = tokenLabelName(this.state.type);
  5203. this.next();
  5204. return super.createIdentifier(node, label);
  5205. } else if (tokenIsIdentifier(this.state.type)) {
  5206. if (this.isContextual(129)) {
  5207. return this.flowParseInterfaceType();
  5208. }
  5209. return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
  5210. }
  5211. }
  5212. this.unexpected();
  5213. }
  5214. flowParsePostfixType() {
  5215. const startLoc = this.state.startLoc;
  5216. let type = this.flowParsePrimaryType();
  5217. let seenOptionalIndexedAccess = false;
  5218. while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
  5219. const node = this.startNodeAt(startLoc);
  5220. const optional = this.eat(18);
  5221. seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
  5222. this.expect(0);
  5223. if (!optional && this.match(3)) {
  5224. node.elementType = type;
  5225. this.next();
  5226. type = this.finishNode(node, "ArrayTypeAnnotation");
  5227. } else {
  5228. node.objectType = type;
  5229. node.indexType = this.flowParseType();
  5230. this.expect(3);
  5231. if (seenOptionalIndexedAccess) {
  5232. node.optional = optional;
  5233. type = this.finishNode(node, "OptionalIndexedAccessType");
  5234. } else {
  5235. type = this.finishNode(node, "IndexedAccessType");
  5236. }
  5237. }
  5238. }
  5239. return type;
  5240. }
  5241. flowParsePrefixType() {
  5242. const node = this.startNode();
  5243. if (this.eat(17)) {
  5244. node.typeAnnotation = this.flowParsePrefixType();
  5245. return this.finishNode(node, "NullableTypeAnnotation");
  5246. } else {
  5247. return this.flowParsePostfixType();
  5248. }
  5249. }
  5250. flowParseAnonFunctionWithoutParens() {
  5251. const param = this.flowParsePrefixType();
  5252. if (!this.state.noAnonFunctionType && this.eat(19)) {
  5253. const node = this.startNodeAt(param.loc.start);
  5254. node.params = [this.reinterpretTypeAsFunctionTypeParam(param)];
  5255. node.rest = null;
  5256. node.this = null;
  5257. node.returnType = this.flowParseType();
  5258. node.typeParameters = null;
  5259. return this.finishNode(node, "FunctionTypeAnnotation");
  5260. }
  5261. return param;
  5262. }
  5263. flowParseIntersectionType() {
  5264. const node = this.startNode();
  5265. this.eat(45);
  5266. const type = this.flowParseAnonFunctionWithoutParens();
  5267. node.types = [type];
  5268. while (this.eat(45)) {
  5269. node.types.push(this.flowParseAnonFunctionWithoutParens());
  5270. }
  5271. return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation");
  5272. }
  5273. flowParseUnionType() {
  5274. const node = this.startNode();
  5275. this.eat(43);
  5276. const type = this.flowParseIntersectionType();
  5277. node.types = [type];
  5278. while (this.eat(43)) {
  5279. node.types.push(this.flowParseIntersectionType());
  5280. }
  5281. return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation");
  5282. }
  5283. flowParseType() {
  5284. const oldInType = this.state.inType;
  5285. this.state.inType = true;
  5286. const type = this.flowParseUnionType();
  5287. this.state.inType = oldInType;
  5288. return type;
  5289. }
  5290. flowParseTypeOrImplicitInstantiation() {
  5291. if (this.state.type === 132 && this.state.value === "_") {
  5292. const startLoc = this.state.startLoc;
  5293. const node = this.parseIdentifier();
  5294. return this.flowParseGenericType(startLoc, node);
  5295. } else {
  5296. return this.flowParseType();
  5297. }
  5298. }
  5299. flowParseTypeAnnotation() {
  5300. const node = this.startNode();
  5301. node.typeAnnotation = this.flowParseTypeInitialiser();
  5302. return this.finishNode(node, "TypeAnnotation");
  5303. }
  5304. flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
  5305. const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
  5306. if (this.match(14)) {
  5307. ident.typeAnnotation = this.flowParseTypeAnnotation();
  5308. this.resetEndLocation(ident);
  5309. }
  5310. return ident;
  5311. }
  5312. typeCastToParameter(node) {
  5313. node.expression.typeAnnotation = node.typeAnnotation;
  5314. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  5315. return node.expression;
  5316. }
  5317. flowParseVariance() {
  5318. let variance = null;
  5319. if (this.match(53)) {
  5320. variance = this.startNode();
  5321. if (this.state.value === "+") {
  5322. variance.kind = "plus";
  5323. } else {
  5324. variance.kind = "minus";
  5325. }
  5326. this.next();
  5327. return this.finishNode(variance, "Variance");
  5328. }
  5329. return variance;
  5330. }
  5331. parseFunctionBody(node, allowExpressionBody, isMethod = false) {
  5332. if (allowExpressionBody) {
  5333. this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod));
  5334. return;
  5335. }
  5336. super.parseFunctionBody(node, false, isMethod);
  5337. }
  5338. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  5339. if (this.match(14)) {
  5340. const typeNode = this.startNode();
  5341. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  5342. node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, "TypeAnnotation") : null;
  5343. }
  5344. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  5345. }
  5346. parseStatementLike(flags) {
  5347. if (this.state.strict && this.isContextual(129)) {
  5348. const lookahead = this.lookahead();
  5349. if (tokenIsKeywordOrIdentifier(lookahead.type)) {
  5350. const node = this.startNode();
  5351. this.next();
  5352. return this.flowParseInterface(node);
  5353. }
  5354. } else if (this.isContextual(126)) {
  5355. const node = this.startNode();
  5356. this.next();
  5357. return this.flowParseEnumDeclaration(node);
  5358. }
  5359. const stmt = super.parseStatementLike(flags);
  5360. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) {
  5361. this.flowPragma = null;
  5362. }
  5363. return stmt;
  5364. }
  5365. parseExpressionStatement(node, expr, decorators) {
  5366. if (expr.type === "Identifier") {
  5367. if (expr.name === "declare") {
  5368. if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
  5369. return this.flowParseDeclare(node);
  5370. }
  5371. } else if (tokenIsIdentifier(this.state.type)) {
  5372. if (expr.name === "interface") {
  5373. return this.flowParseInterface(node);
  5374. } else if (expr.name === "type") {
  5375. return this.flowParseTypeAlias(node);
  5376. } else if (expr.name === "opaque") {
  5377. return this.flowParseOpaqueType(node, false);
  5378. }
  5379. }
  5380. }
  5381. return super.parseExpressionStatement(node, expr, decorators);
  5382. }
  5383. shouldParseExportDeclaration() {
  5384. const {
  5385. type
  5386. } = this.state;
  5387. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5388. return !this.state.containsEsc;
  5389. }
  5390. return super.shouldParseExportDeclaration();
  5391. }
  5392. isExportDefaultSpecifier() {
  5393. const {
  5394. type
  5395. } = this.state;
  5396. if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
  5397. return this.state.containsEsc;
  5398. }
  5399. return super.isExportDefaultSpecifier();
  5400. }
  5401. parseExportDefaultExpression() {
  5402. if (this.isContextual(126)) {
  5403. const node = this.startNode();
  5404. this.next();
  5405. return this.flowParseEnumDeclaration(node);
  5406. }
  5407. return super.parseExportDefaultExpression();
  5408. }
  5409. parseConditional(expr, startLoc, refExpressionErrors) {
  5410. if (!this.match(17)) return expr;
  5411. if (this.state.maybeInArrowParameters) {
  5412. const nextCh = this.lookaheadCharCode();
  5413. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  5414. this.setOptionalParametersError(refExpressionErrors);
  5415. return expr;
  5416. }
  5417. }
  5418. this.expect(17);
  5419. const state = this.state.clone();
  5420. const originalNoArrowAt = this.state.noArrowAt;
  5421. const node = this.startNodeAt(startLoc);
  5422. let {
  5423. consequent,
  5424. failed
  5425. } = this.tryParseConditionalConsequent();
  5426. let [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5427. if (failed || invalid.length > 0) {
  5428. const noArrowAt = [...originalNoArrowAt];
  5429. if (invalid.length > 0) {
  5430. this.state = state;
  5431. this.state.noArrowAt = noArrowAt;
  5432. for (let i = 0; i < invalid.length; i++) {
  5433. noArrowAt.push(invalid[i].start);
  5434. }
  5435. ({
  5436. consequent,
  5437. failed
  5438. } = this.tryParseConditionalConsequent());
  5439. [valid, invalid] = this.getArrowLikeExpressions(consequent);
  5440. }
  5441. if (failed && valid.length > 1) {
  5442. this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
  5443. }
  5444. if (failed && valid.length === 1) {
  5445. this.state = state;
  5446. noArrowAt.push(valid[0].start);
  5447. this.state.noArrowAt = noArrowAt;
  5448. ({
  5449. consequent,
  5450. failed
  5451. } = this.tryParseConditionalConsequent());
  5452. }
  5453. }
  5454. this.getArrowLikeExpressions(consequent, true);
  5455. this.state.noArrowAt = originalNoArrowAt;
  5456. this.expect(14);
  5457. node.test = expr;
  5458. node.consequent = consequent;
  5459. node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(undefined, undefined));
  5460. return this.finishNode(node, "ConditionalExpression");
  5461. }
  5462. tryParseConditionalConsequent() {
  5463. this.state.noArrowParamsConversionAt.push(this.state.start);
  5464. const consequent = this.parseMaybeAssignAllowIn();
  5465. const failed = !this.match(14);
  5466. this.state.noArrowParamsConversionAt.pop();
  5467. return {
  5468. consequent,
  5469. failed
  5470. };
  5471. }
  5472. getArrowLikeExpressions(node, disallowInvalid) {
  5473. const stack = [node];
  5474. const arrows = [];
  5475. while (stack.length !== 0) {
  5476. const node = stack.pop();
  5477. if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
  5478. if (node.typeParameters || !node.returnType) {
  5479. this.finishArrowValidation(node);
  5480. } else {
  5481. arrows.push(node);
  5482. }
  5483. stack.push(node.body);
  5484. } else if (node.type === "ConditionalExpression") {
  5485. stack.push(node.consequent);
  5486. stack.push(node.alternate);
  5487. }
  5488. }
  5489. if (disallowInvalid) {
  5490. arrows.forEach(node => this.finishArrowValidation(node));
  5491. return [arrows, []];
  5492. }
  5493. return partition(arrows, node => node.params.every(param => this.isAssignable(param, true)));
  5494. }
  5495. finishArrowValidation(node) {
  5496. var _node$extra;
  5497. this.toAssignableList(node.params, (_node$extra = node.extra) == null ? void 0 : _node$extra.trailingCommaLoc, false);
  5498. this.scope.enter(514 | 4);
  5499. super.checkParams(node, false, true);
  5500. this.scope.exit();
  5501. }
  5502. forwardNoArrowParamsConversionAt(node, parse) {
  5503. let result;
  5504. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  5505. this.state.noArrowParamsConversionAt.push(this.state.start);
  5506. result = parse();
  5507. this.state.noArrowParamsConversionAt.pop();
  5508. } else {
  5509. result = parse();
  5510. }
  5511. return result;
  5512. }
  5513. parseParenItem(node, startLoc) {
  5514. const newNode = super.parseParenItem(node, startLoc);
  5515. if (this.eat(17)) {
  5516. newNode.optional = true;
  5517. this.resetEndLocation(node);
  5518. }
  5519. if (this.match(14)) {
  5520. const typeCastNode = this.startNodeAt(startLoc);
  5521. typeCastNode.expression = newNode;
  5522. typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
  5523. return this.finishNode(typeCastNode, "TypeCastExpression");
  5524. }
  5525. return newNode;
  5526. }
  5527. assertModuleNodeAllowed(node) {
  5528. if (node.type === "ImportDeclaration" && (node.importKind === "type" || node.importKind === "typeof") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "ExportAllDeclaration" && node.exportKind === "type") {
  5529. return;
  5530. }
  5531. super.assertModuleNodeAllowed(node);
  5532. }
  5533. parseExportDeclaration(node) {
  5534. if (this.isContextual(130)) {
  5535. node.exportKind = "type";
  5536. const declarationNode = this.startNode();
  5537. this.next();
  5538. if (this.match(5)) {
  5539. node.specifiers = this.parseExportSpecifiers(true);
  5540. super.parseExportFrom(node);
  5541. return null;
  5542. } else {
  5543. return this.flowParseTypeAlias(declarationNode);
  5544. }
  5545. } else if (this.isContextual(131)) {
  5546. node.exportKind = "type";
  5547. const declarationNode = this.startNode();
  5548. this.next();
  5549. return this.flowParseOpaqueType(declarationNode, false);
  5550. } else if (this.isContextual(129)) {
  5551. node.exportKind = "type";
  5552. const declarationNode = this.startNode();
  5553. this.next();
  5554. return this.flowParseInterface(declarationNode);
  5555. } else if (this.isContextual(126)) {
  5556. node.exportKind = "value";
  5557. const declarationNode = this.startNode();
  5558. this.next();
  5559. return this.flowParseEnumDeclaration(declarationNode);
  5560. } else {
  5561. return super.parseExportDeclaration(node);
  5562. }
  5563. }
  5564. eatExportStar(node) {
  5565. if (super.eatExportStar(node)) return true;
  5566. if (this.isContextual(130) && this.lookahead().type === 55) {
  5567. node.exportKind = "type";
  5568. this.next();
  5569. this.next();
  5570. return true;
  5571. }
  5572. return false;
  5573. }
  5574. maybeParseExportNamespaceSpecifier(node) {
  5575. const {
  5576. startLoc
  5577. } = this.state;
  5578. const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
  5579. if (hasNamespace && node.exportKind === "type") {
  5580. this.unexpected(startLoc);
  5581. }
  5582. return hasNamespace;
  5583. }
  5584. parseClassId(node, isStatement, optionalId) {
  5585. super.parseClassId(node, isStatement, optionalId);
  5586. if (this.match(47)) {
  5587. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5588. }
  5589. }
  5590. parseClassMember(classBody, member, state) {
  5591. const {
  5592. startLoc
  5593. } = this.state;
  5594. if (this.isContextual(125)) {
  5595. if (super.parseClassMemberFromModifier(classBody, member)) {
  5596. return;
  5597. }
  5598. member.declare = true;
  5599. }
  5600. super.parseClassMember(classBody, member, state);
  5601. if (member.declare) {
  5602. if (member.type !== "ClassProperty" && member.type !== "ClassPrivateProperty" && member.type !== "PropertyDefinition") {
  5603. this.raise(FlowErrors.DeclareClassElement, startLoc);
  5604. } else if (member.value) {
  5605. this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
  5606. }
  5607. }
  5608. }
  5609. isIterator(word) {
  5610. return word === "iterator" || word === "asyncIterator";
  5611. }
  5612. readIterator() {
  5613. const word = super.readWord1();
  5614. const fullWord = "@@" + word;
  5615. if (!this.isIterator(word) || !this.state.inType) {
  5616. this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
  5617. identifierName: fullWord
  5618. });
  5619. }
  5620. this.finishToken(132, fullWord);
  5621. }
  5622. getTokenFromCode(code) {
  5623. const next = this.input.charCodeAt(this.state.pos + 1);
  5624. if (code === 123 && next === 124) {
  5625. this.finishOp(6, 2);
  5626. } else if (this.state.inType && (code === 62 || code === 60)) {
  5627. this.finishOp(code === 62 ? 48 : 47, 1);
  5628. } else if (this.state.inType && code === 63) {
  5629. if (next === 46) {
  5630. this.finishOp(18, 2);
  5631. } else {
  5632. this.finishOp(17, 1);
  5633. }
  5634. } else if (isIteratorStart(code, next, this.input.charCodeAt(this.state.pos + 2))) {
  5635. this.state.pos += 2;
  5636. this.readIterator();
  5637. } else {
  5638. super.getTokenFromCode(code);
  5639. }
  5640. }
  5641. isAssignable(node, isBinding) {
  5642. if (node.type === "TypeCastExpression") {
  5643. return this.isAssignable(node.expression, isBinding);
  5644. } else {
  5645. return super.isAssignable(node, isBinding);
  5646. }
  5647. }
  5648. toAssignable(node, isLHS = false) {
  5649. if (!isLHS && node.type === "AssignmentExpression" && node.left.type === "TypeCastExpression") {
  5650. node.left = this.typeCastToParameter(node.left);
  5651. }
  5652. super.toAssignable(node, isLHS);
  5653. }
  5654. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  5655. for (let i = 0; i < exprList.length; i++) {
  5656. const expr = exprList[i];
  5657. if ((expr == null ? void 0 : expr.type) === "TypeCastExpression") {
  5658. exprList[i] = this.typeCastToParameter(expr);
  5659. }
  5660. }
  5661. super.toAssignableList(exprList, trailingCommaLoc, isLHS);
  5662. }
  5663. toReferencedList(exprList, isParenthesizedExpr) {
  5664. for (let i = 0; i < exprList.length; i++) {
  5665. var _expr$extra;
  5666. const expr = exprList[i];
  5667. if (expr && expr.type === "TypeCastExpression" && !((_expr$extra = expr.extra) != null && _expr$extra.parenthesized) && (exprList.length > 1 || !isParenthesizedExpr)) {
  5668. this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
  5669. }
  5670. }
  5671. return exprList;
  5672. }
  5673. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  5674. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  5675. if (canBePattern && !this.state.maybeInArrowParameters) {
  5676. this.toReferencedList(node.elements);
  5677. }
  5678. return node;
  5679. }
  5680. isValidLVal(type, isParenthesized, binding) {
  5681. return type === "TypeCastExpression" || super.isValidLVal(type, isParenthesized, binding);
  5682. }
  5683. parseClassProperty(node) {
  5684. if (this.match(14)) {
  5685. node.typeAnnotation = this.flowParseTypeAnnotation();
  5686. }
  5687. return super.parseClassProperty(node);
  5688. }
  5689. parseClassPrivateProperty(node) {
  5690. if (this.match(14)) {
  5691. node.typeAnnotation = this.flowParseTypeAnnotation();
  5692. }
  5693. return super.parseClassPrivateProperty(node);
  5694. }
  5695. isClassMethod() {
  5696. return this.match(47) || super.isClassMethod();
  5697. }
  5698. isClassProperty() {
  5699. return this.match(14) || super.isClassProperty();
  5700. }
  5701. isNonstaticConstructor(method) {
  5702. return !this.match(14) && super.isNonstaticConstructor(method);
  5703. }
  5704. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  5705. if (method.variance) {
  5706. this.unexpected(method.variance.loc.start);
  5707. }
  5708. delete method.variance;
  5709. if (this.match(47)) {
  5710. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5711. }
  5712. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  5713. if (method.params && isConstructor) {
  5714. const params = method.params;
  5715. if (params.length > 0 && this.isThisParam(params[0])) {
  5716. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5717. }
  5718. } else if (method.type === "MethodDefinition" && isConstructor && method.value.params) {
  5719. const params = method.value.params;
  5720. if (params.length > 0 && this.isThisParam(params[0])) {
  5721. this.raise(FlowErrors.ThisParamBannedInConstructor, method);
  5722. }
  5723. }
  5724. }
  5725. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  5726. if (method.variance) {
  5727. this.unexpected(method.variance.loc.start);
  5728. }
  5729. delete method.variance;
  5730. if (this.match(47)) {
  5731. method.typeParameters = this.flowParseTypeParameterDeclaration();
  5732. }
  5733. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  5734. }
  5735. parseClassSuper(node) {
  5736. super.parseClassSuper(node);
  5737. if (node.superClass && (this.match(47) || this.match(51))) {
  5738. {
  5739. node.superTypeParameters = this.flowParseTypeParameterInstantiationInExpression();
  5740. }
  5741. }
  5742. if (this.isContextual(113)) {
  5743. this.next();
  5744. const implemented = node.implements = [];
  5745. do {
  5746. const node = this.startNode();
  5747. node.id = this.flowParseRestrictedIdentifier(true);
  5748. if (this.match(47)) {
  5749. node.typeParameters = this.flowParseTypeParameterInstantiation();
  5750. } else {
  5751. node.typeParameters = null;
  5752. }
  5753. implemented.push(this.finishNode(node, "ClassImplements"));
  5754. } while (this.eat(12));
  5755. }
  5756. }
  5757. checkGetterSetterParams(method) {
  5758. super.checkGetterSetterParams(method);
  5759. const params = this.getObjectOrClassMethodParams(method);
  5760. if (params.length > 0) {
  5761. const param = params[0];
  5762. if (this.isThisParam(param) && method.kind === "get") {
  5763. this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
  5764. } else if (this.isThisParam(param)) {
  5765. this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
  5766. }
  5767. }
  5768. }
  5769. parsePropertyNamePrefixOperator(node) {
  5770. node.variance = this.flowParseVariance();
  5771. }
  5772. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  5773. if (prop.variance) {
  5774. this.unexpected(prop.variance.loc.start);
  5775. }
  5776. delete prop.variance;
  5777. let typeParameters;
  5778. if (this.match(47) && !isAccessor) {
  5779. typeParameters = this.flowParseTypeParameterDeclaration();
  5780. if (!this.match(10)) this.unexpected();
  5781. }
  5782. const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  5783. if (typeParameters) {
  5784. (result.value || result).typeParameters = typeParameters;
  5785. }
  5786. return result;
  5787. }
  5788. parseFunctionParamType(param) {
  5789. if (this.eat(17)) {
  5790. if (param.type !== "Identifier") {
  5791. this.raise(FlowErrors.PatternIsOptional, param);
  5792. }
  5793. if (this.isThisParam(param)) {
  5794. this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
  5795. }
  5796. param.optional = true;
  5797. }
  5798. if (this.match(14)) {
  5799. param.typeAnnotation = this.flowParseTypeAnnotation();
  5800. } else if (this.isThisParam(param)) {
  5801. this.raise(FlowErrors.ThisParamAnnotationRequired, param);
  5802. }
  5803. if (this.match(29) && this.isThisParam(param)) {
  5804. this.raise(FlowErrors.ThisParamNoDefault, param);
  5805. }
  5806. this.resetEndLocation(param);
  5807. return param;
  5808. }
  5809. parseMaybeDefault(startLoc, left) {
  5810. const node = super.parseMaybeDefault(startLoc, left);
  5811. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  5812. this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
  5813. }
  5814. return node;
  5815. }
  5816. checkImportReflection(node) {
  5817. super.checkImportReflection(node);
  5818. if (node.module && node.importKind !== "value") {
  5819. this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  5820. }
  5821. }
  5822. parseImportSpecifierLocal(node, specifier, type) {
  5823. specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
  5824. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  5825. }
  5826. isPotentialImportPhase(isExport) {
  5827. if (super.isPotentialImportPhase(isExport)) return true;
  5828. if (this.isContextual(130)) {
  5829. if (!isExport) return true;
  5830. const ch = this.lookaheadCharCode();
  5831. return ch === 123 || ch === 42;
  5832. }
  5833. return !isExport && this.isContextual(87);
  5834. }
  5835. applyImportPhase(node, isExport, phase, loc) {
  5836. super.applyImportPhase(node, isExport, phase, loc);
  5837. if (isExport) {
  5838. if (!phase && this.match(65)) {
  5839. return;
  5840. }
  5841. node.exportKind = phase === "type" ? phase : "value";
  5842. } else {
  5843. if (phase === "type" && this.match(55)) this.unexpected();
  5844. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  5845. }
  5846. }
  5847. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  5848. const firstIdent = specifier.imported;
  5849. let specifierTypeKind = null;
  5850. if (firstIdent.type === "Identifier") {
  5851. if (firstIdent.name === "type") {
  5852. specifierTypeKind = "type";
  5853. } else if (firstIdent.name === "typeof") {
  5854. specifierTypeKind = "typeof";
  5855. }
  5856. }
  5857. let isBinding = false;
  5858. if (this.isContextual(93) && !this.isLookaheadContextual("as")) {
  5859. const as_ident = this.parseIdentifier(true);
  5860. if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
  5861. specifier.imported = as_ident;
  5862. specifier.importKind = specifierTypeKind;
  5863. specifier.local = this.cloneIdentifier(as_ident);
  5864. } else {
  5865. specifier.imported = firstIdent;
  5866. specifier.importKind = null;
  5867. specifier.local = this.parseIdentifier();
  5868. }
  5869. } else {
  5870. if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
  5871. specifier.imported = this.parseIdentifier(true);
  5872. specifier.importKind = specifierTypeKind;
  5873. } else {
  5874. if (importedIsString) {
  5875. throw this.raise(Errors.ImportBindingIsString, specifier, {
  5876. importName: firstIdent.value
  5877. });
  5878. }
  5879. specifier.imported = firstIdent;
  5880. specifier.importKind = null;
  5881. }
  5882. if (this.eatContextual(93)) {
  5883. specifier.local = this.parseIdentifier();
  5884. } else {
  5885. isBinding = true;
  5886. specifier.local = this.cloneIdentifier(specifier.imported);
  5887. }
  5888. }
  5889. const specifierIsTypeImport = hasTypeImportKind(specifier);
  5890. if (isInTypeOnlyImport && specifierIsTypeImport) {
  5891. this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
  5892. }
  5893. if (isInTypeOnlyImport || specifierIsTypeImport) {
  5894. this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
  5895. }
  5896. if (isBinding && !isInTypeOnlyImport && !specifierIsTypeImport) {
  5897. this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
  5898. }
  5899. return this.finishImportSpecifier(specifier, "ImportSpecifier");
  5900. }
  5901. parseBindingAtom() {
  5902. switch (this.state.type) {
  5903. case 78:
  5904. return this.parseIdentifier(true);
  5905. default:
  5906. return super.parseBindingAtom();
  5907. }
  5908. }
  5909. parseFunctionParams(node, isConstructor) {
  5910. const kind = node.kind;
  5911. if (kind !== "get" && kind !== "set" && this.match(47)) {
  5912. node.typeParameters = this.flowParseTypeParameterDeclaration();
  5913. }
  5914. super.parseFunctionParams(node, isConstructor);
  5915. }
  5916. parseVarId(decl, kind) {
  5917. super.parseVarId(decl, kind);
  5918. if (this.match(14)) {
  5919. decl.id.typeAnnotation = this.flowParseTypeAnnotation();
  5920. this.resetEndLocation(decl.id);
  5921. }
  5922. }
  5923. parseAsyncArrowFromCallExpression(node, call) {
  5924. if (this.match(14)) {
  5925. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5926. this.state.noAnonFunctionType = true;
  5927. node.returnType = this.flowParseTypeAnnotation();
  5928. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  5929. }
  5930. return super.parseAsyncArrowFromCallExpression(node, call);
  5931. }
  5932. shouldParseAsyncArrow() {
  5933. return this.match(14) || super.shouldParseAsyncArrow();
  5934. }
  5935. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  5936. var _jsx;
  5937. let state = null;
  5938. let jsx;
  5939. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  5940. state = this.state.clone();
  5941. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  5942. if (!jsx.error) return jsx.node;
  5943. const {
  5944. context
  5945. } = this.state;
  5946. const currentContext = context[context.length - 1];
  5947. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  5948. context.pop();
  5949. }
  5950. }
  5951. if ((_jsx = jsx) != null && _jsx.error || this.match(47)) {
  5952. var _jsx2, _jsx3;
  5953. state = state || this.state.clone();
  5954. let typeParameters;
  5955. const arrow = this.tryParse(abort => {
  5956. var _arrowExpression$extr;
  5957. typeParameters = this.flowParseTypeParameterDeclaration();
  5958. const arrowExpression = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
  5959. const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5960. this.resetStartLocationFromNode(result, typeParameters);
  5961. return result;
  5962. });
  5963. if ((_arrowExpression$extr = arrowExpression.extra) != null && _arrowExpression$extr.parenthesized) abort();
  5964. const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
  5965. if (expr.type !== "ArrowFunctionExpression") abort();
  5966. expr.typeParameters = typeParameters;
  5967. this.resetStartLocationFromNode(expr, typeParameters);
  5968. return arrowExpression;
  5969. }, state);
  5970. let arrowExpression = null;
  5971. if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === "ArrowFunctionExpression") {
  5972. if (!arrow.error && !arrow.aborted) {
  5973. if (arrow.node.async) {
  5974. this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
  5975. }
  5976. return arrow.node;
  5977. }
  5978. arrowExpression = arrow.node;
  5979. }
  5980. if ((_jsx2 = jsx) != null && _jsx2.node) {
  5981. this.state = jsx.failState;
  5982. return jsx.node;
  5983. }
  5984. if (arrowExpression) {
  5985. this.state = arrow.failState;
  5986. return arrowExpression;
  5987. }
  5988. if ((_jsx3 = jsx) != null && _jsx3.thrown) throw jsx.error;
  5989. if (arrow.thrown) throw arrow.error;
  5990. throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
  5991. }
  5992. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  5993. }
  5994. parseArrow(node) {
  5995. if (this.match(14)) {
  5996. const result = this.tryParse(() => {
  5997. const oldNoAnonFunctionType = this.state.noAnonFunctionType;
  5998. this.state.noAnonFunctionType = true;
  5999. const typeNode = this.startNode();
  6000. [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
  6001. this.state.noAnonFunctionType = oldNoAnonFunctionType;
  6002. if (this.canInsertSemicolon()) this.unexpected();
  6003. if (!this.match(19)) this.unexpected();
  6004. return typeNode;
  6005. });
  6006. if (result.thrown) return null;
  6007. if (result.error) this.state = result.failState;
  6008. node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, "TypeAnnotation") : null;
  6009. }
  6010. return super.parseArrow(node);
  6011. }
  6012. shouldParseArrow(params) {
  6013. return this.match(14) || super.shouldParseArrow(params);
  6014. }
  6015. setArrowFunctionParameters(node, params) {
  6016. if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  6017. node.params = params;
  6018. } else {
  6019. super.setArrowFunctionParameters(node, params);
  6020. }
  6021. }
  6022. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  6023. if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
  6024. return;
  6025. }
  6026. for (let i = 0; i < node.params.length; i++) {
  6027. if (this.isThisParam(node.params[i]) && i > 0) {
  6028. this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
  6029. }
  6030. }
  6031. super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
  6032. }
  6033. parseParenAndDistinguishExpression(canBeArrow) {
  6034. return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
  6035. }
  6036. parseSubscripts(base, startLoc, noCalls) {
  6037. if (base.type === "Identifier" && base.name === "async" && this.state.noArrowAt.includes(startLoc.index)) {
  6038. this.next();
  6039. const node = this.startNodeAt(startLoc);
  6040. node.callee = base;
  6041. node.arguments = super.parseCallExpressionArguments();
  6042. base = this.finishNode(node, "CallExpression");
  6043. } else if (base.type === "Identifier" && base.name === "async" && this.match(47)) {
  6044. const state = this.state.clone();
  6045. const arrow = this.tryParse(abort => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
  6046. if (!arrow.error && !arrow.aborted) return arrow.node;
  6047. const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
  6048. if (result.node && !result.error) return result.node;
  6049. if (arrow.node) {
  6050. this.state = arrow.failState;
  6051. return arrow.node;
  6052. }
  6053. if (result.node) {
  6054. this.state = result.failState;
  6055. return result.node;
  6056. }
  6057. throw arrow.error || result.error;
  6058. }
  6059. return super.parseSubscripts(base, startLoc, noCalls);
  6060. }
  6061. parseSubscript(base, startLoc, noCalls, subscriptState) {
  6062. if (this.match(18) && this.isLookaheadToken_lt()) {
  6063. subscriptState.optionalChainMember = true;
  6064. if (noCalls) {
  6065. subscriptState.stop = true;
  6066. return base;
  6067. }
  6068. this.next();
  6069. const node = this.startNodeAt(startLoc);
  6070. node.callee = base;
  6071. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6072. this.expect(10);
  6073. node.arguments = this.parseCallExpressionArguments();
  6074. node.optional = true;
  6075. return this.finishCallExpression(node, true);
  6076. } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
  6077. const node = this.startNodeAt(startLoc);
  6078. node.callee = base;
  6079. const result = this.tryParse(() => {
  6080. node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
  6081. this.expect(10);
  6082. node.arguments = super.parseCallExpressionArguments();
  6083. if (subscriptState.optionalChainMember) {
  6084. node.optional = false;
  6085. }
  6086. return this.finishCallExpression(node, subscriptState.optionalChainMember);
  6087. });
  6088. if (result.node) {
  6089. if (result.error) this.state = result.failState;
  6090. return result.node;
  6091. }
  6092. }
  6093. return super.parseSubscript(base, startLoc, noCalls, subscriptState);
  6094. }
  6095. parseNewCallee(node) {
  6096. super.parseNewCallee(node);
  6097. let targs = null;
  6098. if (this.shouldParseTypes() && this.match(47)) {
  6099. targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
  6100. }
  6101. node.typeArguments = targs;
  6102. }
  6103. parseAsyncArrowWithTypeParameters(startLoc) {
  6104. const node = this.startNodeAt(startLoc);
  6105. this.parseFunctionParams(node, false);
  6106. if (!this.parseArrow(node)) return;
  6107. return super.parseArrowExpression(node, undefined, true);
  6108. }
  6109. readToken_mult_modulo(code) {
  6110. const next = this.input.charCodeAt(this.state.pos + 1);
  6111. if (code === 42 && next === 47 && this.state.hasFlowComment) {
  6112. this.state.hasFlowComment = false;
  6113. this.state.pos += 2;
  6114. this.nextToken();
  6115. return;
  6116. }
  6117. super.readToken_mult_modulo(code);
  6118. }
  6119. readToken_pipe_amp(code) {
  6120. const next = this.input.charCodeAt(this.state.pos + 1);
  6121. if (code === 124 && next === 125) {
  6122. this.finishOp(9, 2);
  6123. return;
  6124. }
  6125. super.readToken_pipe_amp(code);
  6126. }
  6127. parseTopLevel(file, program) {
  6128. const fileNode = super.parseTopLevel(file, program);
  6129. if (this.state.hasFlowComment) {
  6130. this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
  6131. }
  6132. return fileNode;
  6133. }
  6134. skipBlockComment() {
  6135. if (this.hasPlugin("flowComments") && this.skipFlowComment()) {
  6136. if (this.state.hasFlowComment) {
  6137. throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
  6138. }
  6139. this.hasFlowCommentCompletion();
  6140. const commentSkip = this.skipFlowComment();
  6141. if (commentSkip) {
  6142. this.state.pos += commentSkip;
  6143. this.state.hasFlowComment = true;
  6144. }
  6145. return;
  6146. }
  6147. return super.skipBlockComment(this.state.hasFlowComment ? "*-/" : "*/");
  6148. }
  6149. skipFlowComment() {
  6150. const {
  6151. pos
  6152. } = this.state;
  6153. let shiftToFirstNonWhiteSpace = 2;
  6154. while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
  6155. shiftToFirstNonWhiteSpace++;
  6156. }
  6157. const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
  6158. const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
  6159. if (ch2 === 58 && ch3 === 58) {
  6160. return shiftToFirstNonWhiteSpace + 2;
  6161. }
  6162. if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === "flow-include") {
  6163. return shiftToFirstNonWhiteSpace + 12;
  6164. }
  6165. if (ch2 === 58 && ch3 !== 58) {
  6166. return shiftToFirstNonWhiteSpace;
  6167. }
  6168. return false;
  6169. }
  6170. hasFlowCommentCompletion() {
  6171. const end = this.input.indexOf("*/", this.state.pos);
  6172. if (end === -1) {
  6173. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  6174. }
  6175. }
  6176. flowEnumErrorBooleanMemberNotInitialized(loc, {
  6177. enumName,
  6178. memberName
  6179. }) {
  6180. this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
  6181. memberName,
  6182. enumName
  6183. });
  6184. }
  6185. flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
  6186. return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === "symbol" ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
  6187. }
  6188. flowEnumErrorNumberMemberNotInitialized(loc, details) {
  6189. this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
  6190. }
  6191. flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
  6192. this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
  6193. }
  6194. flowEnumMemberInit() {
  6195. const startLoc = this.state.startLoc;
  6196. const endOfInit = () => this.match(12) || this.match(8);
  6197. switch (this.state.type) {
  6198. case 135:
  6199. {
  6200. const literal = this.parseNumericLiteral(this.state.value);
  6201. if (endOfInit()) {
  6202. return {
  6203. type: "number",
  6204. loc: literal.loc.start,
  6205. value: literal
  6206. };
  6207. }
  6208. return {
  6209. type: "invalid",
  6210. loc: startLoc
  6211. };
  6212. }
  6213. case 134:
  6214. {
  6215. const literal = this.parseStringLiteral(this.state.value);
  6216. if (endOfInit()) {
  6217. return {
  6218. type: "string",
  6219. loc: literal.loc.start,
  6220. value: literal
  6221. };
  6222. }
  6223. return {
  6224. type: "invalid",
  6225. loc: startLoc
  6226. };
  6227. }
  6228. case 85:
  6229. case 86:
  6230. {
  6231. const literal = this.parseBooleanLiteral(this.match(85));
  6232. if (endOfInit()) {
  6233. return {
  6234. type: "boolean",
  6235. loc: literal.loc.start,
  6236. value: literal
  6237. };
  6238. }
  6239. return {
  6240. type: "invalid",
  6241. loc: startLoc
  6242. };
  6243. }
  6244. default:
  6245. return {
  6246. type: "invalid",
  6247. loc: startLoc
  6248. };
  6249. }
  6250. }
  6251. flowEnumMemberRaw() {
  6252. const loc = this.state.startLoc;
  6253. const id = this.parseIdentifier(true);
  6254. const init = this.eat(29) ? this.flowEnumMemberInit() : {
  6255. type: "none",
  6256. loc
  6257. };
  6258. return {
  6259. id,
  6260. init
  6261. };
  6262. }
  6263. flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
  6264. const {
  6265. explicitType
  6266. } = context;
  6267. if (explicitType === null) {
  6268. return;
  6269. }
  6270. if (explicitType !== expectedType) {
  6271. this.flowEnumErrorInvalidMemberInitializer(loc, context);
  6272. }
  6273. }
  6274. flowEnumMembers({
  6275. enumName,
  6276. explicitType
  6277. }) {
  6278. const seenNames = new Set();
  6279. const members = {
  6280. booleanMembers: [],
  6281. numberMembers: [],
  6282. stringMembers: [],
  6283. defaultedMembers: []
  6284. };
  6285. let hasUnknownMembers = false;
  6286. while (!this.match(8)) {
  6287. if (this.eat(21)) {
  6288. hasUnknownMembers = true;
  6289. break;
  6290. }
  6291. const memberNode = this.startNode();
  6292. const {
  6293. id,
  6294. init
  6295. } = this.flowEnumMemberRaw();
  6296. const memberName = id.name;
  6297. if (memberName === "") {
  6298. continue;
  6299. }
  6300. if (/^[a-z]/.test(memberName)) {
  6301. this.raise(FlowErrors.EnumInvalidMemberName, id, {
  6302. memberName,
  6303. suggestion: memberName[0].toUpperCase() + memberName.slice(1),
  6304. enumName
  6305. });
  6306. }
  6307. if (seenNames.has(memberName)) {
  6308. this.raise(FlowErrors.EnumDuplicateMemberName, id, {
  6309. memberName,
  6310. enumName
  6311. });
  6312. }
  6313. seenNames.add(memberName);
  6314. const context = {
  6315. enumName,
  6316. explicitType,
  6317. memberName
  6318. };
  6319. memberNode.id = id;
  6320. switch (init.type) {
  6321. case "boolean":
  6322. {
  6323. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "boolean");
  6324. memberNode.init = init.value;
  6325. members.booleanMembers.push(this.finishNode(memberNode, "EnumBooleanMember"));
  6326. break;
  6327. }
  6328. case "number":
  6329. {
  6330. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "number");
  6331. memberNode.init = init.value;
  6332. members.numberMembers.push(this.finishNode(memberNode, "EnumNumberMember"));
  6333. break;
  6334. }
  6335. case "string":
  6336. {
  6337. this.flowEnumCheckExplicitTypeMismatch(init.loc, context, "string");
  6338. memberNode.init = init.value;
  6339. members.stringMembers.push(this.finishNode(memberNode, "EnumStringMember"));
  6340. break;
  6341. }
  6342. case "invalid":
  6343. {
  6344. throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
  6345. }
  6346. case "none":
  6347. {
  6348. switch (explicitType) {
  6349. case "boolean":
  6350. this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
  6351. break;
  6352. case "number":
  6353. this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
  6354. break;
  6355. default:
  6356. members.defaultedMembers.push(this.finishNode(memberNode, "EnumDefaultedMember"));
  6357. }
  6358. }
  6359. }
  6360. if (!this.match(8)) {
  6361. this.expect(12);
  6362. }
  6363. }
  6364. return {
  6365. members,
  6366. hasUnknownMembers
  6367. };
  6368. }
  6369. flowEnumStringMembers(initializedMembers, defaultedMembers, {
  6370. enumName
  6371. }) {
  6372. if (initializedMembers.length === 0) {
  6373. return defaultedMembers;
  6374. } else if (defaultedMembers.length === 0) {
  6375. return initializedMembers;
  6376. } else if (defaultedMembers.length > initializedMembers.length) {
  6377. for (const member of initializedMembers) {
  6378. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6379. enumName
  6380. });
  6381. }
  6382. return defaultedMembers;
  6383. } else {
  6384. for (const member of defaultedMembers) {
  6385. this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
  6386. enumName
  6387. });
  6388. }
  6389. return initializedMembers;
  6390. }
  6391. }
  6392. flowEnumParseExplicitType({
  6393. enumName
  6394. }) {
  6395. if (!this.eatContextual(102)) return null;
  6396. if (!tokenIsIdentifier(this.state.type)) {
  6397. throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
  6398. enumName
  6399. });
  6400. }
  6401. const {
  6402. value
  6403. } = this.state;
  6404. this.next();
  6405. if (value !== "boolean" && value !== "number" && value !== "string" && value !== "symbol") {
  6406. this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
  6407. enumName,
  6408. invalidEnumType: value
  6409. });
  6410. }
  6411. return value;
  6412. }
  6413. flowEnumBody(node, id) {
  6414. const enumName = id.name;
  6415. const nameLoc = id.loc.start;
  6416. const explicitType = this.flowEnumParseExplicitType({
  6417. enumName
  6418. });
  6419. this.expect(5);
  6420. const {
  6421. members,
  6422. hasUnknownMembers
  6423. } = this.flowEnumMembers({
  6424. enumName,
  6425. explicitType
  6426. });
  6427. node.hasUnknownMembers = hasUnknownMembers;
  6428. switch (explicitType) {
  6429. case "boolean":
  6430. node.explicitType = true;
  6431. node.members = members.booleanMembers;
  6432. this.expect(8);
  6433. return this.finishNode(node, "EnumBooleanBody");
  6434. case "number":
  6435. node.explicitType = true;
  6436. node.members = members.numberMembers;
  6437. this.expect(8);
  6438. return this.finishNode(node, "EnumNumberBody");
  6439. case "string":
  6440. node.explicitType = true;
  6441. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6442. enumName
  6443. });
  6444. this.expect(8);
  6445. return this.finishNode(node, "EnumStringBody");
  6446. case "symbol":
  6447. node.members = members.defaultedMembers;
  6448. this.expect(8);
  6449. return this.finishNode(node, "EnumSymbolBody");
  6450. default:
  6451. {
  6452. const empty = () => {
  6453. node.members = [];
  6454. this.expect(8);
  6455. return this.finishNode(node, "EnumStringBody");
  6456. };
  6457. node.explicitType = false;
  6458. const boolsLen = members.booleanMembers.length;
  6459. const numsLen = members.numberMembers.length;
  6460. const strsLen = members.stringMembers.length;
  6461. const defaultedLen = members.defaultedMembers.length;
  6462. if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
  6463. return empty();
  6464. } else if (!boolsLen && !numsLen) {
  6465. node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
  6466. enumName
  6467. });
  6468. this.expect(8);
  6469. return this.finishNode(node, "EnumStringBody");
  6470. } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
  6471. for (const member of members.defaultedMembers) {
  6472. this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
  6473. enumName,
  6474. memberName: member.id.name
  6475. });
  6476. }
  6477. node.members = members.booleanMembers;
  6478. this.expect(8);
  6479. return this.finishNode(node, "EnumBooleanBody");
  6480. } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
  6481. for (const member of members.defaultedMembers) {
  6482. this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
  6483. enumName,
  6484. memberName: member.id.name
  6485. });
  6486. }
  6487. node.members = members.numberMembers;
  6488. this.expect(8);
  6489. return this.finishNode(node, "EnumNumberBody");
  6490. } else {
  6491. this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
  6492. enumName
  6493. });
  6494. return empty();
  6495. }
  6496. }
  6497. }
  6498. }
  6499. flowParseEnumDeclaration(node) {
  6500. const id = this.parseIdentifier();
  6501. node.id = id;
  6502. node.body = this.flowEnumBody(this.startNode(), id);
  6503. return this.finishNode(node, "EnumDeclaration");
  6504. }
  6505. jsxParseOpeningElementAfterName(node) {
  6506. if (this.shouldParseTypes()) {
  6507. if (this.match(47) || this.match(51)) {
  6508. node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
  6509. }
  6510. }
  6511. return super.jsxParseOpeningElementAfterName(node);
  6512. }
  6513. isLookaheadToken_lt() {
  6514. const next = this.nextTokenStart();
  6515. if (this.input.charCodeAt(next) === 60) {
  6516. const afterNext = this.input.charCodeAt(next + 1);
  6517. return afterNext !== 60 && afterNext !== 61;
  6518. }
  6519. return false;
  6520. }
  6521. reScan_lt_gt() {
  6522. const {
  6523. type
  6524. } = this.state;
  6525. if (type === 47) {
  6526. this.state.pos -= 1;
  6527. this.readToken_lt();
  6528. } else if (type === 48) {
  6529. this.state.pos -= 1;
  6530. this.readToken_gt();
  6531. }
  6532. }
  6533. reScan_lt() {
  6534. const {
  6535. type
  6536. } = this.state;
  6537. if (type === 51) {
  6538. this.state.pos -= 2;
  6539. this.finishOp(47, 1);
  6540. return 47;
  6541. }
  6542. return type;
  6543. }
  6544. maybeUnwrapTypeCastExpression(node) {
  6545. return node.type === "TypeCastExpression" ? node.expression : node;
  6546. }
  6547. };
  6548. const entities = {
  6549. __proto__: null,
  6550. quot: "\u0022",
  6551. amp: "&",
  6552. apos: "\u0027",
  6553. lt: "<",
  6554. gt: ">",
  6555. nbsp: "\u00A0",
  6556. iexcl: "\u00A1",
  6557. cent: "\u00A2",
  6558. pound: "\u00A3",
  6559. curren: "\u00A4",
  6560. yen: "\u00A5",
  6561. brvbar: "\u00A6",
  6562. sect: "\u00A7",
  6563. uml: "\u00A8",
  6564. copy: "\u00A9",
  6565. ordf: "\u00AA",
  6566. laquo: "\u00AB",
  6567. not: "\u00AC",
  6568. shy: "\u00AD",
  6569. reg: "\u00AE",
  6570. macr: "\u00AF",
  6571. deg: "\u00B0",
  6572. plusmn: "\u00B1",
  6573. sup2: "\u00B2",
  6574. sup3: "\u00B3",
  6575. acute: "\u00B4",
  6576. micro: "\u00B5",
  6577. para: "\u00B6",
  6578. middot: "\u00B7",
  6579. cedil: "\u00B8",
  6580. sup1: "\u00B9",
  6581. ordm: "\u00BA",
  6582. raquo: "\u00BB",
  6583. frac14: "\u00BC",
  6584. frac12: "\u00BD",
  6585. frac34: "\u00BE",
  6586. iquest: "\u00BF",
  6587. Agrave: "\u00C0",
  6588. Aacute: "\u00C1",
  6589. Acirc: "\u00C2",
  6590. Atilde: "\u00C3",
  6591. Auml: "\u00C4",
  6592. Aring: "\u00C5",
  6593. AElig: "\u00C6",
  6594. Ccedil: "\u00C7",
  6595. Egrave: "\u00C8",
  6596. Eacute: "\u00C9",
  6597. Ecirc: "\u00CA",
  6598. Euml: "\u00CB",
  6599. Igrave: "\u00CC",
  6600. Iacute: "\u00CD",
  6601. Icirc: "\u00CE",
  6602. Iuml: "\u00CF",
  6603. ETH: "\u00D0",
  6604. Ntilde: "\u00D1",
  6605. Ograve: "\u00D2",
  6606. Oacute: "\u00D3",
  6607. Ocirc: "\u00D4",
  6608. Otilde: "\u00D5",
  6609. Ouml: "\u00D6",
  6610. times: "\u00D7",
  6611. Oslash: "\u00D8",
  6612. Ugrave: "\u00D9",
  6613. Uacute: "\u00DA",
  6614. Ucirc: "\u00DB",
  6615. Uuml: "\u00DC",
  6616. Yacute: "\u00DD",
  6617. THORN: "\u00DE",
  6618. szlig: "\u00DF",
  6619. agrave: "\u00E0",
  6620. aacute: "\u00E1",
  6621. acirc: "\u00E2",
  6622. atilde: "\u00E3",
  6623. auml: "\u00E4",
  6624. aring: "\u00E5",
  6625. aelig: "\u00E6",
  6626. ccedil: "\u00E7",
  6627. egrave: "\u00E8",
  6628. eacute: "\u00E9",
  6629. ecirc: "\u00EA",
  6630. euml: "\u00EB",
  6631. igrave: "\u00EC",
  6632. iacute: "\u00ED",
  6633. icirc: "\u00EE",
  6634. iuml: "\u00EF",
  6635. eth: "\u00F0",
  6636. ntilde: "\u00F1",
  6637. ograve: "\u00F2",
  6638. oacute: "\u00F3",
  6639. ocirc: "\u00F4",
  6640. otilde: "\u00F5",
  6641. ouml: "\u00F6",
  6642. divide: "\u00F7",
  6643. oslash: "\u00F8",
  6644. ugrave: "\u00F9",
  6645. uacute: "\u00FA",
  6646. ucirc: "\u00FB",
  6647. uuml: "\u00FC",
  6648. yacute: "\u00FD",
  6649. thorn: "\u00FE",
  6650. yuml: "\u00FF",
  6651. OElig: "\u0152",
  6652. oelig: "\u0153",
  6653. Scaron: "\u0160",
  6654. scaron: "\u0161",
  6655. Yuml: "\u0178",
  6656. fnof: "\u0192",
  6657. circ: "\u02C6",
  6658. tilde: "\u02DC",
  6659. Alpha: "\u0391",
  6660. Beta: "\u0392",
  6661. Gamma: "\u0393",
  6662. Delta: "\u0394",
  6663. Epsilon: "\u0395",
  6664. Zeta: "\u0396",
  6665. Eta: "\u0397",
  6666. Theta: "\u0398",
  6667. Iota: "\u0399",
  6668. Kappa: "\u039A",
  6669. Lambda: "\u039B",
  6670. Mu: "\u039C",
  6671. Nu: "\u039D",
  6672. Xi: "\u039E",
  6673. Omicron: "\u039F",
  6674. Pi: "\u03A0",
  6675. Rho: "\u03A1",
  6676. Sigma: "\u03A3",
  6677. Tau: "\u03A4",
  6678. Upsilon: "\u03A5",
  6679. Phi: "\u03A6",
  6680. Chi: "\u03A7",
  6681. Psi: "\u03A8",
  6682. Omega: "\u03A9",
  6683. alpha: "\u03B1",
  6684. beta: "\u03B2",
  6685. gamma: "\u03B3",
  6686. delta: "\u03B4",
  6687. epsilon: "\u03B5",
  6688. zeta: "\u03B6",
  6689. eta: "\u03B7",
  6690. theta: "\u03B8",
  6691. iota: "\u03B9",
  6692. kappa: "\u03BA",
  6693. lambda: "\u03BB",
  6694. mu: "\u03BC",
  6695. nu: "\u03BD",
  6696. xi: "\u03BE",
  6697. omicron: "\u03BF",
  6698. pi: "\u03C0",
  6699. rho: "\u03C1",
  6700. sigmaf: "\u03C2",
  6701. sigma: "\u03C3",
  6702. tau: "\u03C4",
  6703. upsilon: "\u03C5",
  6704. phi: "\u03C6",
  6705. chi: "\u03C7",
  6706. psi: "\u03C8",
  6707. omega: "\u03C9",
  6708. thetasym: "\u03D1",
  6709. upsih: "\u03D2",
  6710. piv: "\u03D6",
  6711. ensp: "\u2002",
  6712. emsp: "\u2003",
  6713. thinsp: "\u2009",
  6714. zwnj: "\u200C",
  6715. zwj: "\u200D",
  6716. lrm: "\u200E",
  6717. rlm: "\u200F",
  6718. ndash: "\u2013",
  6719. mdash: "\u2014",
  6720. lsquo: "\u2018",
  6721. rsquo: "\u2019",
  6722. sbquo: "\u201A",
  6723. ldquo: "\u201C",
  6724. rdquo: "\u201D",
  6725. bdquo: "\u201E",
  6726. dagger: "\u2020",
  6727. Dagger: "\u2021",
  6728. bull: "\u2022",
  6729. hellip: "\u2026",
  6730. permil: "\u2030",
  6731. prime: "\u2032",
  6732. Prime: "\u2033",
  6733. lsaquo: "\u2039",
  6734. rsaquo: "\u203A",
  6735. oline: "\u203E",
  6736. frasl: "\u2044",
  6737. euro: "\u20AC",
  6738. image: "\u2111",
  6739. weierp: "\u2118",
  6740. real: "\u211C",
  6741. trade: "\u2122",
  6742. alefsym: "\u2135",
  6743. larr: "\u2190",
  6744. uarr: "\u2191",
  6745. rarr: "\u2192",
  6746. darr: "\u2193",
  6747. harr: "\u2194",
  6748. crarr: "\u21B5",
  6749. lArr: "\u21D0",
  6750. uArr: "\u21D1",
  6751. rArr: "\u21D2",
  6752. dArr: "\u21D3",
  6753. hArr: "\u21D4",
  6754. forall: "\u2200",
  6755. part: "\u2202",
  6756. exist: "\u2203",
  6757. empty: "\u2205",
  6758. nabla: "\u2207",
  6759. isin: "\u2208",
  6760. notin: "\u2209",
  6761. ni: "\u220B",
  6762. prod: "\u220F",
  6763. sum: "\u2211",
  6764. minus: "\u2212",
  6765. lowast: "\u2217",
  6766. radic: "\u221A",
  6767. prop: "\u221D",
  6768. infin: "\u221E",
  6769. ang: "\u2220",
  6770. and: "\u2227",
  6771. or: "\u2228",
  6772. cap: "\u2229",
  6773. cup: "\u222A",
  6774. int: "\u222B",
  6775. there4: "\u2234",
  6776. sim: "\u223C",
  6777. cong: "\u2245",
  6778. asymp: "\u2248",
  6779. ne: "\u2260",
  6780. equiv: "\u2261",
  6781. le: "\u2264",
  6782. ge: "\u2265",
  6783. sub: "\u2282",
  6784. sup: "\u2283",
  6785. nsub: "\u2284",
  6786. sube: "\u2286",
  6787. supe: "\u2287",
  6788. oplus: "\u2295",
  6789. otimes: "\u2297",
  6790. perp: "\u22A5",
  6791. sdot: "\u22C5",
  6792. lceil: "\u2308",
  6793. rceil: "\u2309",
  6794. lfloor: "\u230A",
  6795. rfloor: "\u230B",
  6796. lang: "\u2329",
  6797. rang: "\u232A",
  6798. loz: "\u25CA",
  6799. spades: "\u2660",
  6800. clubs: "\u2663",
  6801. hearts: "\u2665",
  6802. diams: "\u2666"
  6803. };
  6804. const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
  6805. const lineBreakG = new RegExp(lineBreak.source, "g");
  6806. function isNewLine(code) {
  6807. switch (code) {
  6808. case 10:
  6809. case 13:
  6810. case 8232:
  6811. case 8233:
  6812. return true;
  6813. default:
  6814. return false;
  6815. }
  6816. }
  6817. function hasNewLine(input, start, end) {
  6818. for (let i = start; i < end; i++) {
  6819. if (isNewLine(input.charCodeAt(i))) {
  6820. return true;
  6821. }
  6822. }
  6823. return false;
  6824. }
  6825. const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
  6826. const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/g;
  6827. function isWhitespace(code) {
  6828. switch (code) {
  6829. case 0x0009:
  6830. case 0x000b:
  6831. case 0x000c:
  6832. case 32:
  6833. case 160:
  6834. case 5760:
  6835. case 0x2000:
  6836. case 0x2001:
  6837. case 0x2002:
  6838. case 0x2003:
  6839. case 0x2004:
  6840. case 0x2005:
  6841. case 0x2006:
  6842. case 0x2007:
  6843. case 0x2008:
  6844. case 0x2009:
  6845. case 0x200a:
  6846. case 0x202f:
  6847. case 0x205f:
  6848. case 0x3000:
  6849. case 0xfeff:
  6850. return true;
  6851. default:
  6852. return false;
  6853. }
  6854. }
  6855. const JsxErrors = ParseErrorEnum`jsx`({
  6856. AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.",
  6857. MissingClosingTagElement: ({
  6858. openingTagName
  6859. }) => `Expected corresponding JSX closing tag for <${openingTagName}>.`,
  6860. MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.",
  6861. UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?",
  6862. UnexpectedToken: ({
  6863. unexpected,
  6864. HTMLEntity
  6865. }) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`,
  6866. UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.",
  6867. UnterminatedJsxContent: "Unterminated JSX contents.",
  6868. UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?"
  6869. });
  6870. function isFragment(object) {
  6871. return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false;
  6872. }
  6873. function getQualifiedJSXName(object) {
  6874. if (object.type === "JSXIdentifier") {
  6875. return object.name;
  6876. }
  6877. if (object.type === "JSXNamespacedName") {
  6878. return object.namespace.name + ":" + object.name.name;
  6879. }
  6880. if (object.type === "JSXMemberExpression") {
  6881. return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
  6882. }
  6883. throw new Error("Node had unexpected type: " + object.type);
  6884. }
  6885. var jsx = superClass => class JSXParserMixin extends superClass {
  6886. jsxReadToken() {
  6887. let out = "";
  6888. let chunkStart = this.state.pos;
  6889. for (;;) {
  6890. if (this.state.pos >= this.length) {
  6891. throw this.raise(JsxErrors.UnterminatedJsxContent, this.state.startLoc);
  6892. }
  6893. const ch = this.input.charCodeAt(this.state.pos);
  6894. switch (ch) {
  6895. case 60:
  6896. case 123:
  6897. if (this.state.pos === this.state.start) {
  6898. if (ch === 60 && this.state.canStartJSXElement) {
  6899. ++this.state.pos;
  6900. this.finishToken(143);
  6901. } else {
  6902. super.getTokenFromCode(ch);
  6903. }
  6904. return;
  6905. }
  6906. out += this.input.slice(chunkStart, this.state.pos);
  6907. this.finishToken(142, out);
  6908. return;
  6909. case 38:
  6910. out += this.input.slice(chunkStart, this.state.pos);
  6911. out += this.jsxReadEntity();
  6912. chunkStart = this.state.pos;
  6913. break;
  6914. case 62:
  6915. case 125:
  6916. default:
  6917. if (isNewLine(ch)) {
  6918. out += this.input.slice(chunkStart, this.state.pos);
  6919. out += this.jsxReadNewLine(true);
  6920. chunkStart = this.state.pos;
  6921. } else {
  6922. ++this.state.pos;
  6923. }
  6924. }
  6925. }
  6926. }
  6927. jsxReadNewLine(normalizeCRLF) {
  6928. const ch = this.input.charCodeAt(this.state.pos);
  6929. let out;
  6930. ++this.state.pos;
  6931. if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) {
  6932. ++this.state.pos;
  6933. out = normalizeCRLF ? "\n" : "\r\n";
  6934. } else {
  6935. out = String.fromCharCode(ch);
  6936. }
  6937. ++this.state.curLine;
  6938. this.state.lineStart = this.state.pos;
  6939. return out;
  6940. }
  6941. jsxReadString(quote) {
  6942. let out = "";
  6943. let chunkStart = ++this.state.pos;
  6944. for (;;) {
  6945. if (this.state.pos >= this.length) {
  6946. throw this.raise(Errors.UnterminatedString, this.state.startLoc);
  6947. }
  6948. const ch = this.input.charCodeAt(this.state.pos);
  6949. if (ch === quote) break;
  6950. if (ch === 38) {
  6951. out += this.input.slice(chunkStart, this.state.pos);
  6952. out += this.jsxReadEntity();
  6953. chunkStart = this.state.pos;
  6954. } else if (isNewLine(ch)) {
  6955. out += this.input.slice(chunkStart, this.state.pos);
  6956. out += this.jsxReadNewLine(false);
  6957. chunkStart = this.state.pos;
  6958. } else {
  6959. ++this.state.pos;
  6960. }
  6961. }
  6962. out += this.input.slice(chunkStart, this.state.pos++);
  6963. this.finishToken(134, out);
  6964. }
  6965. jsxReadEntity() {
  6966. const startPos = ++this.state.pos;
  6967. if (this.codePointAtPos(this.state.pos) === 35) {
  6968. ++this.state.pos;
  6969. let radix = 10;
  6970. if (this.codePointAtPos(this.state.pos) === 120) {
  6971. radix = 16;
  6972. ++this.state.pos;
  6973. }
  6974. const codePoint = this.readInt(radix, undefined, false, "bail");
  6975. if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) {
  6976. ++this.state.pos;
  6977. return String.fromCodePoint(codePoint);
  6978. }
  6979. } else {
  6980. let count = 0;
  6981. let semi = false;
  6982. while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) === 59)) {
  6983. ++this.state.pos;
  6984. }
  6985. if (semi) {
  6986. const desc = this.input.slice(startPos, this.state.pos);
  6987. const entity = entities[desc];
  6988. ++this.state.pos;
  6989. if (entity) {
  6990. return entity;
  6991. }
  6992. }
  6993. }
  6994. this.state.pos = startPos;
  6995. return "&";
  6996. }
  6997. jsxReadWord() {
  6998. let ch;
  6999. const start = this.state.pos;
  7000. do {
  7001. ch = this.input.charCodeAt(++this.state.pos);
  7002. } while (isIdentifierChar(ch) || ch === 45);
  7003. this.finishToken(141, this.input.slice(start, this.state.pos));
  7004. }
  7005. jsxParseIdentifier() {
  7006. const node = this.startNode();
  7007. if (this.match(141)) {
  7008. node.name = this.state.value;
  7009. } else if (tokenIsKeyword(this.state.type)) {
  7010. node.name = tokenLabelName(this.state.type);
  7011. } else {
  7012. this.unexpected();
  7013. }
  7014. this.next();
  7015. return this.finishNode(node, "JSXIdentifier");
  7016. }
  7017. jsxParseNamespacedName() {
  7018. const startLoc = this.state.startLoc;
  7019. const name = this.jsxParseIdentifier();
  7020. if (!this.eat(14)) return name;
  7021. const node = this.startNodeAt(startLoc);
  7022. node.namespace = name;
  7023. node.name = this.jsxParseIdentifier();
  7024. return this.finishNode(node, "JSXNamespacedName");
  7025. }
  7026. jsxParseElementName() {
  7027. const startLoc = this.state.startLoc;
  7028. let node = this.jsxParseNamespacedName();
  7029. if (node.type === "JSXNamespacedName") {
  7030. return node;
  7031. }
  7032. while (this.eat(16)) {
  7033. const newNode = this.startNodeAt(startLoc);
  7034. newNode.object = node;
  7035. newNode.property = this.jsxParseIdentifier();
  7036. node = this.finishNode(newNode, "JSXMemberExpression");
  7037. }
  7038. return node;
  7039. }
  7040. jsxParseAttributeValue() {
  7041. let node;
  7042. switch (this.state.type) {
  7043. case 5:
  7044. node = this.startNode();
  7045. this.setContext(types.brace);
  7046. this.next();
  7047. node = this.jsxParseExpressionContainer(node, types.j_oTag);
  7048. if (node.expression.type === "JSXEmptyExpression") {
  7049. this.raise(JsxErrors.AttributeIsEmpty, node);
  7050. }
  7051. return node;
  7052. case 143:
  7053. case 134:
  7054. return this.parseExprAtom();
  7055. default:
  7056. throw this.raise(JsxErrors.UnsupportedJsxValue, this.state.startLoc);
  7057. }
  7058. }
  7059. jsxParseEmptyExpression() {
  7060. const node = this.startNodeAt(this.state.lastTokEndLoc);
  7061. return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc);
  7062. }
  7063. jsxParseSpreadChild(node) {
  7064. this.next();
  7065. node.expression = this.parseExpression();
  7066. this.setContext(types.j_expr);
  7067. this.state.canStartJSXElement = true;
  7068. this.expect(8);
  7069. return this.finishNode(node, "JSXSpreadChild");
  7070. }
  7071. jsxParseExpressionContainer(node, previousContext) {
  7072. if (this.match(8)) {
  7073. node.expression = this.jsxParseEmptyExpression();
  7074. } else {
  7075. const expression = this.parseExpression();
  7076. node.expression = expression;
  7077. }
  7078. this.setContext(previousContext);
  7079. this.state.canStartJSXElement = true;
  7080. this.expect(8);
  7081. return this.finishNode(node, "JSXExpressionContainer");
  7082. }
  7083. jsxParseAttribute() {
  7084. const node = this.startNode();
  7085. if (this.match(5)) {
  7086. this.setContext(types.brace);
  7087. this.next();
  7088. this.expect(21);
  7089. node.argument = this.parseMaybeAssignAllowIn();
  7090. this.setContext(types.j_oTag);
  7091. this.state.canStartJSXElement = true;
  7092. this.expect(8);
  7093. return this.finishNode(node, "JSXSpreadAttribute");
  7094. }
  7095. node.name = this.jsxParseNamespacedName();
  7096. node.value = this.eat(29) ? this.jsxParseAttributeValue() : null;
  7097. return this.finishNode(node, "JSXAttribute");
  7098. }
  7099. jsxParseOpeningElementAt(startLoc) {
  7100. const node = this.startNodeAt(startLoc);
  7101. if (this.eat(144)) {
  7102. return this.finishNode(node, "JSXOpeningFragment");
  7103. }
  7104. node.name = this.jsxParseElementName();
  7105. return this.jsxParseOpeningElementAfterName(node);
  7106. }
  7107. jsxParseOpeningElementAfterName(node) {
  7108. const attributes = [];
  7109. while (!this.match(56) && !this.match(144)) {
  7110. attributes.push(this.jsxParseAttribute());
  7111. }
  7112. node.attributes = attributes;
  7113. node.selfClosing = this.eat(56);
  7114. this.expect(144);
  7115. return this.finishNode(node, "JSXOpeningElement");
  7116. }
  7117. jsxParseClosingElementAt(startLoc) {
  7118. const node = this.startNodeAt(startLoc);
  7119. if (this.eat(144)) {
  7120. return this.finishNode(node, "JSXClosingFragment");
  7121. }
  7122. node.name = this.jsxParseElementName();
  7123. this.expect(144);
  7124. return this.finishNode(node, "JSXClosingElement");
  7125. }
  7126. jsxParseElementAt(startLoc) {
  7127. const node = this.startNodeAt(startLoc);
  7128. const children = [];
  7129. const openingElement = this.jsxParseOpeningElementAt(startLoc);
  7130. let closingElement = null;
  7131. if (!openingElement.selfClosing) {
  7132. contents: for (;;) {
  7133. switch (this.state.type) {
  7134. case 143:
  7135. startLoc = this.state.startLoc;
  7136. this.next();
  7137. if (this.eat(56)) {
  7138. closingElement = this.jsxParseClosingElementAt(startLoc);
  7139. break contents;
  7140. }
  7141. children.push(this.jsxParseElementAt(startLoc));
  7142. break;
  7143. case 142:
  7144. children.push(this.parseLiteral(this.state.value, "JSXText"));
  7145. break;
  7146. case 5:
  7147. {
  7148. const node = this.startNode();
  7149. this.setContext(types.brace);
  7150. this.next();
  7151. if (this.match(21)) {
  7152. children.push(this.jsxParseSpreadChild(node));
  7153. } else {
  7154. children.push(this.jsxParseExpressionContainer(node, types.j_expr));
  7155. }
  7156. break;
  7157. }
  7158. default:
  7159. this.unexpected();
  7160. }
  7161. }
  7162. if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) {
  7163. this.raise(JsxErrors.MissingClosingTagFragment, closingElement);
  7164. } else if (!isFragment(openingElement) && isFragment(closingElement)) {
  7165. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  7166. openingTagName: getQualifiedJSXName(openingElement.name)
  7167. });
  7168. } else if (!isFragment(openingElement) && !isFragment(closingElement)) {
  7169. if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
  7170. this.raise(JsxErrors.MissingClosingTagElement, closingElement, {
  7171. openingTagName: getQualifiedJSXName(openingElement.name)
  7172. });
  7173. }
  7174. }
  7175. }
  7176. if (isFragment(openingElement)) {
  7177. node.openingFragment = openingElement;
  7178. node.closingFragment = closingElement;
  7179. } else {
  7180. node.openingElement = openingElement;
  7181. node.closingElement = closingElement;
  7182. }
  7183. node.children = children;
  7184. if (this.match(47)) {
  7185. throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, this.state.startLoc);
  7186. }
  7187. return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement");
  7188. }
  7189. jsxParseElement() {
  7190. const startLoc = this.state.startLoc;
  7191. this.next();
  7192. return this.jsxParseElementAt(startLoc);
  7193. }
  7194. setContext(newContext) {
  7195. const {
  7196. context
  7197. } = this.state;
  7198. context[context.length - 1] = newContext;
  7199. }
  7200. parseExprAtom(refExpressionErrors) {
  7201. if (this.match(143)) {
  7202. return this.jsxParseElement();
  7203. } else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) {
  7204. this.replaceToken(143);
  7205. return this.jsxParseElement();
  7206. } else {
  7207. return super.parseExprAtom(refExpressionErrors);
  7208. }
  7209. }
  7210. skipSpace() {
  7211. const curContext = this.curContext();
  7212. if (!curContext.preserveSpace) super.skipSpace();
  7213. }
  7214. getTokenFromCode(code) {
  7215. const context = this.curContext();
  7216. if (context === types.j_expr) {
  7217. this.jsxReadToken();
  7218. return;
  7219. }
  7220. if (context === types.j_oTag || context === types.j_cTag) {
  7221. if (isIdentifierStart(code)) {
  7222. this.jsxReadWord();
  7223. return;
  7224. }
  7225. if (code === 62) {
  7226. ++this.state.pos;
  7227. this.finishToken(144);
  7228. return;
  7229. }
  7230. if ((code === 34 || code === 39) && context === types.j_oTag) {
  7231. this.jsxReadString(code);
  7232. return;
  7233. }
  7234. }
  7235. if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) {
  7236. ++this.state.pos;
  7237. this.finishToken(143);
  7238. return;
  7239. }
  7240. super.getTokenFromCode(code);
  7241. }
  7242. updateContext(prevType) {
  7243. const {
  7244. context,
  7245. type
  7246. } = this.state;
  7247. if (type === 56 && prevType === 143) {
  7248. context.splice(-2, 2, types.j_cTag);
  7249. this.state.canStartJSXElement = false;
  7250. } else if (type === 143) {
  7251. context.push(types.j_oTag);
  7252. } else if (type === 144) {
  7253. const out = context[context.length - 1];
  7254. if (out === types.j_oTag && prevType === 56 || out === types.j_cTag) {
  7255. context.pop();
  7256. this.state.canStartJSXElement = context[context.length - 1] === types.j_expr;
  7257. } else {
  7258. this.setContext(types.j_expr);
  7259. this.state.canStartJSXElement = true;
  7260. }
  7261. } else {
  7262. this.state.canStartJSXElement = tokenComesBeforeExpression(type);
  7263. }
  7264. }
  7265. };
  7266. class TypeScriptScope extends Scope {
  7267. constructor(...args) {
  7268. super(...args);
  7269. this.tsNames = new Map();
  7270. }
  7271. }
  7272. class TypeScriptScopeHandler extends ScopeHandler {
  7273. constructor(...args) {
  7274. super(...args);
  7275. this.importsStack = [];
  7276. }
  7277. createScope(flags) {
  7278. this.importsStack.push(new Set());
  7279. return new TypeScriptScope(flags);
  7280. }
  7281. enter(flags) {
  7282. if (flags === 1024) {
  7283. this.importsStack.push(new Set());
  7284. }
  7285. super.enter(flags);
  7286. }
  7287. exit() {
  7288. const flags = super.exit();
  7289. if (flags === 1024) {
  7290. this.importsStack.pop();
  7291. }
  7292. return flags;
  7293. }
  7294. hasImport(name, allowShadow) {
  7295. const len = this.importsStack.length;
  7296. if (this.importsStack[len - 1].has(name)) {
  7297. return true;
  7298. }
  7299. if (!allowShadow && len > 1) {
  7300. for (let i = 0; i < len - 1; i++) {
  7301. if (this.importsStack[i].has(name)) return true;
  7302. }
  7303. }
  7304. return false;
  7305. }
  7306. declareName(name, bindingType, loc) {
  7307. if (bindingType & 4096) {
  7308. if (this.hasImport(name, true)) {
  7309. this.parser.raise(Errors.VarRedeclaration, loc, {
  7310. identifierName: name
  7311. });
  7312. }
  7313. this.importsStack[this.importsStack.length - 1].add(name);
  7314. return;
  7315. }
  7316. const scope = this.currentScope();
  7317. let type = scope.tsNames.get(name) || 0;
  7318. if (bindingType & 1024) {
  7319. this.maybeExportDefined(scope, name);
  7320. scope.tsNames.set(name, type | 16);
  7321. return;
  7322. }
  7323. super.declareName(name, bindingType, loc);
  7324. if (bindingType & 2) {
  7325. if (!(bindingType & 1)) {
  7326. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  7327. this.maybeExportDefined(scope, name);
  7328. }
  7329. type = type | 1;
  7330. }
  7331. if (bindingType & 256) {
  7332. type = type | 2;
  7333. }
  7334. if (bindingType & 512) {
  7335. type = type | 4;
  7336. }
  7337. if (bindingType & 128) {
  7338. type = type | 8;
  7339. }
  7340. if (type) scope.tsNames.set(name, type);
  7341. }
  7342. isRedeclaredInScope(scope, name, bindingType) {
  7343. const type = scope.tsNames.get(name);
  7344. if ((type & 2) > 0) {
  7345. if (bindingType & 256) {
  7346. const isConst = !!(bindingType & 512);
  7347. const wasConst = (type & 4) > 0;
  7348. return isConst !== wasConst;
  7349. }
  7350. return true;
  7351. }
  7352. if (bindingType & 128 && (type & 8) > 0) {
  7353. if (scope.names.get(name) & 2) {
  7354. return !!(bindingType & 1);
  7355. } else {
  7356. return false;
  7357. }
  7358. }
  7359. if (bindingType & 2 && (type & 1) > 0) {
  7360. return true;
  7361. }
  7362. return super.isRedeclaredInScope(scope, name, bindingType);
  7363. }
  7364. checkLocalExport(id) {
  7365. const {
  7366. name
  7367. } = id;
  7368. if (this.hasImport(name)) return;
  7369. const len = this.scopeStack.length;
  7370. for (let i = len - 1; i >= 0; i--) {
  7371. const scope = this.scopeStack[i];
  7372. const type = scope.tsNames.get(name);
  7373. if ((type & 1) > 0 || (type & 16) > 0) {
  7374. return;
  7375. }
  7376. }
  7377. super.checkLocalExport(id);
  7378. }
  7379. }
  7380. class ProductionParameterHandler {
  7381. constructor() {
  7382. this.stacks = [];
  7383. }
  7384. enter(flags) {
  7385. this.stacks.push(flags);
  7386. }
  7387. exit() {
  7388. this.stacks.pop();
  7389. }
  7390. currentFlags() {
  7391. return this.stacks[this.stacks.length - 1];
  7392. }
  7393. get hasAwait() {
  7394. return (this.currentFlags() & 2) > 0;
  7395. }
  7396. get hasYield() {
  7397. return (this.currentFlags() & 1) > 0;
  7398. }
  7399. get hasReturn() {
  7400. return (this.currentFlags() & 4) > 0;
  7401. }
  7402. get hasIn() {
  7403. return (this.currentFlags() & 8) > 0;
  7404. }
  7405. }
  7406. function functionFlags(isAsync, isGenerator) {
  7407. return (isAsync ? 2 : 0) | (isGenerator ? 1 : 0);
  7408. }
  7409. class BaseParser {
  7410. constructor() {
  7411. this.sawUnambiguousESM = false;
  7412. this.ambiguousScriptDifferentAst = false;
  7413. }
  7414. sourceToOffsetPos(sourcePos) {
  7415. return sourcePos + this.startIndex;
  7416. }
  7417. offsetToSourcePos(offsetPos) {
  7418. return offsetPos - this.startIndex;
  7419. }
  7420. hasPlugin(pluginConfig) {
  7421. if (typeof pluginConfig === "string") {
  7422. return this.plugins.has(pluginConfig);
  7423. } else {
  7424. const [pluginName, pluginOptions] = pluginConfig;
  7425. if (!this.hasPlugin(pluginName)) {
  7426. return false;
  7427. }
  7428. const actualOptions = this.plugins.get(pluginName);
  7429. for (const key of Object.keys(pluginOptions)) {
  7430. if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) {
  7431. return false;
  7432. }
  7433. }
  7434. return true;
  7435. }
  7436. }
  7437. getPluginOption(plugin, name) {
  7438. var _this$plugins$get;
  7439. return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
  7440. }
  7441. }
  7442. function setTrailingComments(node, comments) {
  7443. if (node.trailingComments === undefined) {
  7444. node.trailingComments = comments;
  7445. } else {
  7446. node.trailingComments.unshift(...comments);
  7447. }
  7448. }
  7449. function setLeadingComments(node, comments) {
  7450. if (node.leadingComments === undefined) {
  7451. node.leadingComments = comments;
  7452. } else {
  7453. node.leadingComments.unshift(...comments);
  7454. }
  7455. }
  7456. function setInnerComments(node, comments) {
  7457. if (node.innerComments === undefined) {
  7458. node.innerComments = comments;
  7459. } else {
  7460. node.innerComments.unshift(...comments);
  7461. }
  7462. }
  7463. function adjustInnerComments(node, elements, commentWS) {
  7464. let lastElement = null;
  7465. let i = elements.length;
  7466. while (lastElement === null && i > 0) {
  7467. lastElement = elements[--i];
  7468. }
  7469. if (lastElement === null || lastElement.start > commentWS.start) {
  7470. setInnerComments(node, commentWS.comments);
  7471. } else {
  7472. setTrailingComments(lastElement, commentWS.comments);
  7473. }
  7474. }
  7475. class CommentsParser extends BaseParser {
  7476. addComment(comment) {
  7477. if (this.filename) comment.loc.filename = this.filename;
  7478. const {
  7479. commentsLen
  7480. } = this.state;
  7481. if (this.comments.length !== commentsLen) {
  7482. this.comments.length = commentsLen;
  7483. }
  7484. this.comments.push(comment);
  7485. this.state.commentsLen++;
  7486. }
  7487. processComment(node) {
  7488. const {
  7489. commentStack
  7490. } = this.state;
  7491. const commentStackLength = commentStack.length;
  7492. if (commentStackLength === 0) return;
  7493. let i = commentStackLength - 1;
  7494. const lastCommentWS = commentStack[i];
  7495. if (lastCommentWS.start === node.end) {
  7496. lastCommentWS.leadingNode = node;
  7497. i--;
  7498. }
  7499. const {
  7500. start: nodeStart
  7501. } = node;
  7502. for (; i >= 0; i--) {
  7503. const commentWS = commentStack[i];
  7504. const commentEnd = commentWS.end;
  7505. if (commentEnd > nodeStart) {
  7506. commentWS.containingNode = node;
  7507. this.finalizeComment(commentWS);
  7508. commentStack.splice(i, 1);
  7509. } else {
  7510. if (commentEnd === nodeStart) {
  7511. commentWS.trailingNode = node;
  7512. }
  7513. break;
  7514. }
  7515. }
  7516. }
  7517. finalizeComment(commentWS) {
  7518. var _node$options;
  7519. const {
  7520. comments
  7521. } = commentWS;
  7522. if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) {
  7523. if (commentWS.leadingNode !== null) {
  7524. setTrailingComments(commentWS.leadingNode, comments);
  7525. }
  7526. if (commentWS.trailingNode !== null) {
  7527. setLeadingComments(commentWS.trailingNode, comments);
  7528. }
  7529. } else {
  7530. const {
  7531. containingNode: node,
  7532. start: commentStart
  7533. } = commentWS;
  7534. if (this.input.charCodeAt(this.offsetToSourcePos(commentStart) - 1) === 44) {
  7535. switch (node.type) {
  7536. case "ObjectExpression":
  7537. case "ObjectPattern":
  7538. case "RecordExpression":
  7539. adjustInnerComments(node, node.properties, commentWS);
  7540. break;
  7541. case "CallExpression":
  7542. case "OptionalCallExpression":
  7543. adjustInnerComments(node, node.arguments, commentWS);
  7544. break;
  7545. case "ImportExpression":
  7546. adjustInnerComments(node, [node.source, (_node$options = node.options) != null ? _node$options : null], commentWS);
  7547. break;
  7548. case "FunctionDeclaration":
  7549. case "FunctionExpression":
  7550. case "ArrowFunctionExpression":
  7551. case "ObjectMethod":
  7552. case "ClassMethod":
  7553. case "ClassPrivateMethod":
  7554. adjustInnerComments(node, node.params, commentWS);
  7555. break;
  7556. case "ArrayExpression":
  7557. case "ArrayPattern":
  7558. case "TupleExpression":
  7559. adjustInnerComments(node, node.elements, commentWS);
  7560. break;
  7561. case "ExportNamedDeclaration":
  7562. case "ImportDeclaration":
  7563. adjustInnerComments(node, node.specifiers, commentWS);
  7564. break;
  7565. case "TSEnumDeclaration":
  7566. {
  7567. adjustInnerComments(node, node.members, commentWS);
  7568. }
  7569. break;
  7570. case "TSEnumBody":
  7571. adjustInnerComments(node, node.members, commentWS);
  7572. break;
  7573. default:
  7574. {
  7575. setInnerComments(node, comments);
  7576. }
  7577. }
  7578. } else {
  7579. setInnerComments(node, comments);
  7580. }
  7581. }
  7582. }
  7583. finalizeRemainingComments() {
  7584. const {
  7585. commentStack
  7586. } = this.state;
  7587. for (let i = commentStack.length - 1; i >= 0; i--) {
  7588. this.finalizeComment(commentStack[i]);
  7589. }
  7590. this.state.commentStack = [];
  7591. }
  7592. resetPreviousNodeTrailingComments(node) {
  7593. const {
  7594. commentStack
  7595. } = this.state;
  7596. const {
  7597. length
  7598. } = commentStack;
  7599. if (length === 0) return;
  7600. const commentWS = commentStack[length - 1];
  7601. if (commentWS.leadingNode === node) {
  7602. commentWS.leadingNode = null;
  7603. }
  7604. }
  7605. takeSurroundingComments(node, start, end) {
  7606. const {
  7607. commentStack
  7608. } = this.state;
  7609. const commentStackLength = commentStack.length;
  7610. if (commentStackLength === 0) return;
  7611. let i = commentStackLength - 1;
  7612. for (; i >= 0; i--) {
  7613. const commentWS = commentStack[i];
  7614. const commentEnd = commentWS.end;
  7615. const commentStart = commentWS.start;
  7616. if (commentStart === end) {
  7617. commentWS.leadingNode = node;
  7618. } else if (commentEnd === start) {
  7619. commentWS.trailingNode = node;
  7620. } else if (commentEnd < start) {
  7621. break;
  7622. }
  7623. }
  7624. }
  7625. }
  7626. class State {
  7627. constructor() {
  7628. this.flags = 1024;
  7629. this.startIndex = void 0;
  7630. this.curLine = void 0;
  7631. this.lineStart = void 0;
  7632. this.startLoc = void 0;
  7633. this.endLoc = void 0;
  7634. this.errors = [];
  7635. this.potentialArrowAt = -1;
  7636. this.noArrowAt = [];
  7637. this.noArrowParamsConversionAt = [];
  7638. this.topicContext = {
  7639. maxNumOfResolvableTopics: 0,
  7640. maxTopicIndex: null
  7641. };
  7642. this.labels = [];
  7643. this.commentsLen = 0;
  7644. this.commentStack = [];
  7645. this.pos = 0;
  7646. this.type = 140;
  7647. this.value = null;
  7648. this.start = 0;
  7649. this.end = 0;
  7650. this.lastTokEndLoc = null;
  7651. this.lastTokStartLoc = null;
  7652. this.context = [types.brace];
  7653. this.firstInvalidTemplateEscapePos = null;
  7654. this.strictErrors = new Map();
  7655. this.tokensLength = 0;
  7656. }
  7657. get strict() {
  7658. return (this.flags & 1) > 0;
  7659. }
  7660. set strict(v) {
  7661. if (v) this.flags |= 1;else this.flags &= -2;
  7662. }
  7663. init({
  7664. strictMode,
  7665. sourceType,
  7666. startIndex,
  7667. startLine,
  7668. startColumn
  7669. }) {
  7670. this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module";
  7671. this.startIndex = startIndex;
  7672. this.curLine = startLine;
  7673. this.lineStart = -startColumn;
  7674. this.startLoc = this.endLoc = new Position(startLine, startColumn, startIndex);
  7675. }
  7676. get maybeInArrowParameters() {
  7677. return (this.flags & 2) > 0;
  7678. }
  7679. set maybeInArrowParameters(v) {
  7680. if (v) this.flags |= 2;else this.flags &= -3;
  7681. }
  7682. get inType() {
  7683. return (this.flags & 4) > 0;
  7684. }
  7685. set inType(v) {
  7686. if (v) this.flags |= 4;else this.flags &= -5;
  7687. }
  7688. get noAnonFunctionType() {
  7689. return (this.flags & 8) > 0;
  7690. }
  7691. set noAnonFunctionType(v) {
  7692. if (v) this.flags |= 8;else this.flags &= -9;
  7693. }
  7694. get hasFlowComment() {
  7695. return (this.flags & 16) > 0;
  7696. }
  7697. set hasFlowComment(v) {
  7698. if (v) this.flags |= 16;else this.flags &= -17;
  7699. }
  7700. get isAmbientContext() {
  7701. return (this.flags & 32) > 0;
  7702. }
  7703. set isAmbientContext(v) {
  7704. if (v) this.flags |= 32;else this.flags &= -33;
  7705. }
  7706. get inAbstractClass() {
  7707. return (this.flags & 64) > 0;
  7708. }
  7709. set inAbstractClass(v) {
  7710. if (v) this.flags |= 64;else this.flags &= -65;
  7711. }
  7712. get inDisallowConditionalTypesContext() {
  7713. return (this.flags & 128) > 0;
  7714. }
  7715. set inDisallowConditionalTypesContext(v) {
  7716. if (v) this.flags |= 128;else this.flags &= -129;
  7717. }
  7718. get soloAwait() {
  7719. return (this.flags & 256) > 0;
  7720. }
  7721. set soloAwait(v) {
  7722. if (v) this.flags |= 256;else this.flags &= -257;
  7723. }
  7724. get inFSharpPipelineDirectBody() {
  7725. return (this.flags & 512) > 0;
  7726. }
  7727. set inFSharpPipelineDirectBody(v) {
  7728. if (v) this.flags |= 512;else this.flags &= -513;
  7729. }
  7730. get canStartJSXElement() {
  7731. return (this.flags & 1024) > 0;
  7732. }
  7733. set canStartJSXElement(v) {
  7734. if (v) this.flags |= 1024;else this.flags &= -1025;
  7735. }
  7736. get containsEsc() {
  7737. return (this.flags & 2048) > 0;
  7738. }
  7739. set containsEsc(v) {
  7740. if (v) this.flags |= 2048;else this.flags &= -2049;
  7741. }
  7742. get hasTopLevelAwait() {
  7743. return (this.flags & 4096) > 0;
  7744. }
  7745. set hasTopLevelAwait(v) {
  7746. if (v) this.flags |= 4096;else this.flags &= -4097;
  7747. }
  7748. curPosition() {
  7749. return new Position(this.curLine, this.pos - this.lineStart, this.pos + this.startIndex);
  7750. }
  7751. clone() {
  7752. const state = new State();
  7753. state.flags = this.flags;
  7754. state.startIndex = this.startIndex;
  7755. state.curLine = this.curLine;
  7756. state.lineStart = this.lineStart;
  7757. state.startLoc = this.startLoc;
  7758. state.endLoc = this.endLoc;
  7759. state.errors = this.errors.slice();
  7760. state.potentialArrowAt = this.potentialArrowAt;
  7761. state.noArrowAt = this.noArrowAt.slice();
  7762. state.noArrowParamsConversionAt = this.noArrowParamsConversionAt.slice();
  7763. state.topicContext = this.topicContext;
  7764. state.labels = this.labels.slice();
  7765. state.commentsLen = this.commentsLen;
  7766. state.commentStack = this.commentStack.slice();
  7767. state.pos = this.pos;
  7768. state.type = this.type;
  7769. state.value = this.value;
  7770. state.start = this.start;
  7771. state.end = this.end;
  7772. state.lastTokEndLoc = this.lastTokEndLoc;
  7773. state.lastTokStartLoc = this.lastTokStartLoc;
  7774. state.context = this.context.slice();
  7775. state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos;
  7776. state.strictErrors = this.strictErrors;
  7777. state.tokensLength = this.tokensLength;
  7778. return state;
  7779. }
  7780. }
  7781. var _isDigit = function isDigit(code) {
  7782. return code >= 48 && code <= 57;
  7783. };
  7784. const forbiddenNumericSeparatorSiblings = {
  7785. decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
  7786. hex: new Set([46, 88, 95, 120])
  7787. };
  7788. const isAllowedNumericSeparatorSibling = {
  7789. bin: ch => ch === 48 || ch === 49,
  7790. oct: ch => ch >= 48 && ch <= 55,
  7791. dec: ch => ch >= 48 && ch <= 57,
  7792. hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
  7793. };
  7794. function readStringContents(type, input, pos, lineStart, curLine, errors) {
  7795. const initialPos = pos;
  7796. const initialLineStart = lineStart;
  7797. const initialCurLine = curLine;
  7798. let out = "";
  7799. let firstInvalidLoc = null;
  7800. let chunkStart = pos;
  7801. const {
  7802. length
  7803. } = input;
  7804. for (;;) {
  7805. if (pos >= length) {
  7806. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  7807. out += input.slice(chunkStart, pos);
  7808. break;
  7809. }
  7810. const ch = input.charCodeAt(pos);
  7811. if (isStringEnd(type, ch, input, pos)) {
  7812. out += input.slice(chunkStart, pos);
  7813. break;
  7814. }
  7815. if (ch === 92) {
  7816. out += input.slice(chunkStart, pos);
  7817. const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
  7818. if (res.ch === null && !firstInvalidLoc) {
  7819. firstInvalidLoc = {
  7820. pos,
  7821. lineStart,
  7822. curLine
  7823. };
  7824. } else {
  7825. out += res.ch;
  7826. }
  7827. ({
  7828. pos,
  7829. lineStart,
  7830. curLine
  7831. } = res);
  7832. chunkStart = pos;
  7833. } else if (ch === 8232 || ch === 8233) {
  7834. ++pos;
  7835. ++curLine;
  7836. lineStart = pos;
  7837. } else if (ch === 10 || ch === 13) {
  7838. if (type === "template") {
  7839. out += input.slice(chunkStart, pos) + "\n";
  7840. ++pos;
  7841. if (ch === 13 && input.charCodeAt(pos) === 10) {
  7842. ++pos;
  7843. }
  7844. ++curLine;
  7845. chunkStart = lineStart = pos;
  7846. } else {
  7847. errors.unterminated(initialPos, initialLineStart, initialCurLine);
  7848. }
  7849. } else {
  7850. ++pos;
  7851. }
  7852. }
  7853. return {
  7854. pos,
  7855. str: out,
  7856. firstInvalidLoc,
  7857. lineStart,
  7858. curLine,
  7859. containsInvalid: !!firstInvalidLoc
  7860. };
  7861. }
  7862. function isStringEnd(type, ch, input, pos) {
  7863. if (type === "template") {
  7864. return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
  7865. }
  7866. return ch === (type === "double" ? 34 : 39);
  7867. }
  7868. function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
  7869. const throwOnInvalid = !inTemplate;
  7870. pos++;
  7871. const res = ch => ({
  7872. pos,
  7873. ch,
  7874. lineStart,
  7875. curLine
  7876. });
  7877. const ch = input.charCodeAt(pos++);
  7878. switch (ch) {
  7879. case 110:
  7880. return res("\n");
  7881. case 114:
  7882. return res("\r");
  7883. case 120:
  7884. {
  7885. let code;
  7886. ({
  7887. code,
  7888. pos
  7889. } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
  7890. return res(code === null ? null : String.fromCharCode(code));
  7891. }
  7892. case 117:
  7893. {
  7894. let code;
  7895. ({
  7896. code,
  7897. pos
  7898. } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
  7899. return res(code === null ? null : String.fromCodePoint(code));
  7900. }
  7901. case 116:
  7902. return res("\t");
  7903. case 98:
  7904. return res("\b");
  7905. case 118:
  7906. return res("\u000b");
  7907. case 102:
  7908. return res("\f");
  7909. case 13:
  7910. if (input.charCodeAt(pos) === 10) {
  7911. ++pos;
  7912. }
  7913. case 10:
  7914. lineStart = pos;
  7915. ++curLine;
  7916. case 8232:
  7917. case 8233:
  7918. return res("");
  7919. case 56:
  7920. case 57:
  7921. if (inTemplate) {
  7922. return res(null);
  7923. } else {
  7924. errors.strictNumericEscape(pos - 1, lineStart, curLine);
  7925. }
  7926. default:
  7927. if (ch >= 48 && ch <= 55) {
  7928. const startPos = pos - 1;
  7929. const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2));
  7930. let octalStr = match[0];
  7931. let octal = parseInt(octalStr, 8);
  7932. if (octal > 255) {
  7933. octalStr = octalStr.slice(0, -1);
  7934. octal = parseInt(octalStr, 8);
  7935. }
  7936. pos += octalStr.length - 1;
  7937. const next = input.charCodeAt(pos);
  7938. if (octalStr !== "0" || next === 56 || next === 57) {
  7939. if (inTemplate) {
  7940. return res(null);
  7941. } else {
  7942. errors.strictNumericEscape(startPos, lineStart, curLine);
  7943. }
  7944. }
  7945. return res(String.fromCharCode(octal));
  7946. }
  7947. return res(String.fromCharCode(ch));
  7948. }
  7949. }
  7950. function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
  7951. const initialPos = pos;
  7952. let n;
  7953. ({
  7954. n,
  7955. pos
  7956. } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
  7957. if (n === null) {
  7958. if (throwOnInvalid) {
  7959. errors.invalidEscapeSequence(initialPos, lineStart, curLine);
  7960. } else {
  7961. pos = initialPos - 1;
  7962. }
  7963. }
  7964. return {
  7965. code: n,
  7966. pos
  7967. };
  7968. }
  7969. function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
  7970. const start = pos;
  7971. const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
  7972. const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
  7973. let invalid = false;
  7974. let total = 0;
  7975. for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
  7976. const code = input.charCodeAt(pos);
  7977. let val;
  7978. if (code === 95 && allowNumSeparator !== "bail") {
  7979. const prev = input.charCodeAt(pos - 1);
  7980. const next = input.charCodeAt(pos + 1);
  7981. if (!allowNumSeparator) {
  7982. if (bailOnError) return {
  7983. n: null,
  7984. pos
  7985. };
  7986. errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
  7987. } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
  7988. if (bailOnError) return {
  7989. n: null,
  7990. pos
  7991. };
  7992. errors.unexpectedNumericSeparator(pos, lineStart, curLine);
  7993. }
  7994. ++pos;
  7995. continue;
  7996. }
  7997. if (code >= 97) {
  7998. val = code - 97 + 10;
  7999. } else if (code >= 65) {
  8000. val = code - 65 + 10;
  8001. } else if (_isDigit(code)) {
  8002. val = code - 48;
  8003. } else {
  8004. val = Infinity;
  8005. }
  8006. if (val >= radix) {
  8007. if (val <= 9 && bailOnError) {
  8008. return {
  8009. n: null,
  8010. pos
  8011. };
  8012. } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
  8013. val = 0;
  8014. } else if (forceLen) {
  8015. val = 0;
  8016. invalid = true;
  8017. } else {
  8018. break;
  8019. }
  8020. }
  8021. ++pos;
  8022. total = total * radix + val;
  8023. }
  8024. if (pos === start || len != null && pos - start !== len || invalid) {
  8025. return {
  8026. n: null,
  8027. pos
  8028. };
  8029. }
  8030. return {
  8031. n: total,
  8032. pos
  8033. };
  8034. }
  8035. function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
  8036. const ch = input.charCodeAt(pos);
  8037. let code;
  8038. if (ch === 123) {
  8039. ++pos;
  8040. ({
  8041. code,
  8042. pos
  8043. } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
  8044. ++pos;
  8045. if (code !== null && code > 0x10ffff) {
  8046. if (throwOnInvalid) {
  8047. errors.invalidCodePoint(pos, lineStart, curLine);
  8048. } else {
  8049. return {
  8050. code: null,
  8051. pos
  8052. };
  8053. }
  8054. }
  8055. } else {
  8056. ({
  8057. code,
  8058. pos
  8059. } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
  8060. }
  8061. return {
  8062. code,
  8063. pos
  8064. };
  8065. }
  8066. function buildPosition(pos, lineStart, curLine) {
  8067. return new Position(curLine, pos - lineStart, pos);
  8068. }
  8069. const VALID_REGEX_FLAGS = new Set([103, 109, 115, 105, 121, 117, 100, 118]);
  8070. class Token {
  8071. constructor(state) {
  8072. const startIndex = state.startIndex || 0;
  8073. this.type = state.type;
  8074. this.value = state.value;
  8075. this.start = startIndex + state.start;
  8076. this.end = startIndex + state.end;
  8077. this.loc = new SourceLocation(state.startLoc, state.endLoc);
  8078. }
  8079. }
  8080. class Tokenizer extends CommentsParser {
  8081. constructor(options, input) {
  8082. super();
  8083. this.isLookahead = void 0;
  8084. this.tokens = [];
  8085. this.errorHandlers_readInt = {
  8086. invalidDigit: (pos, lineStart, curLine, radix) => {
  8087. if (!(this.optionFlags & 2048)) return false;
  8088. this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
  8089. radix
  8090. });
  8091. return true;
  8092. },
  8093. numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
  8094. unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
  8095. };
  8096. this.errorHandlers_readCodePoint = Object.assign({}, this.errorHandlers_readInt, {
  8097. invalidEscapeSequence: this.errorBuilder(Errors.InvalidEscapeSequence),
  8098. invalidCodePoint: this.errorBuilder(Errors.InvalidCodePoint)
  8099. });
  8100. this.errorHandlers_readStringContents_string = Object.assign({}, this.errorHandlers_readCodePoint, {
  8101. strictNumericEscape: (pos, lineStart, curLine) => {
  8102. this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
  8103. },
  8104. unterminated: (pos, lineStart, curLine) => {
  8105. throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
  8106. }
  8107. });
  8108. this.errorHandlers_readStringContents_template = Object.assign({}, this.errorHandlers_readCodePoint, {
  8109. strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
  8110. unterminated: (pos, lineStart, curLine) => {
  8111. throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
  8112. }
  8113. });
  8114. this.state = new State();
  8115. this.state.init(options);
  8116. this.input = input;
  8117. this.length = input.length;
  8118. this.comments = [];
  8119. this.isLookahead = false;
  8120. }
  8121. pushToken(token) {
  8122. this.tokens.length = this.state.tokensLength;
  8123. this.tokens.push(token);
  8124. ++this.state.tokensLength;
  8125. }
  8126. next() {
  8127. this.checkKeywordEscapes();
  8128. if (this.optionFlags & 256) {
  8129. this.pushToken(new Token(this.state));
  8130. }
  8131. this.state.lastTokEndLoc = this.state.endLoc;
  8132. this.state.lastTokStartLoc = this.state.startLoc;
  8133. this.nextToken();
  8134. }
  8135. eat(type) {
  8136. if (this.match(type)) {
  8137. this.next();
  8138. return true;
  8139. } else {
  8140. return false;
  8141. }
  8142. }
  8143. match(type) {
  8144. return this.state.type === type;
  8145. }
  8146. createLookaheadState(state) {
  8147. return {
  8148. pos: state.pos,
  8149. value: null,
  8150. type: state.type,
  8151. start: state.start,
  8152. end: state.end,
  8153. context: [this.curContext()],
  8154. inType: state.inType,
  8155. startLoc: state.startLoc,
  8156. lastTokEndLoc: state.lastTokEndLoc,
  8157. curLine: state.curLine,
  8158. lineStart: state.lineStart,
  8159. curPosition: state.curPosition
  8160. };
  8161. }
  8162. lookahead() {
  8163. const old = this.state;
  8164. this.state = this.createLookaheadState(old);
  8165. this.isLookahead = true;
  8166. this.nextToken();
  8167. this.isLookahead = false;
  8168. const curr = this.state;
  8169. this.state = old;
  8170. return curr;
  8171. }
  8172. nextTokenStart() {
  8173. return this.nextTokenStartSince(this.state.pos);
  8174. }
  8175. nextTokenStartSince(pos) {
  8176. skipWhiteSpace.lastIndex = pos;
  8177. return skipWhiteSpace.test(this.input) ? skipWhiteSpace.lastIndex : pos;
  8178. }
  8179. lookaheadCharCode() {
  8180. return this.lookaheadCharCodeSince(this.state.pos);
  8181. }
  8182. lookaheadCharCodeSince(pos) {
  8183. return this.input.charCodeAt(this.nextTokenStartSince(pos));
  8184. }
  8185. nextTokenInLineStart() {
  8186. return this.nextTokenInLineStartSince(this.state.pos);
  8187. }
  8188. nextTokenInLineStartSince(pos) {
  8189. skipWhiteSpaceInLine.lastIndex = pos;
  8190. return skipWhiteSpaceInLine.test(this.input) ? skipWhiteSpaceInLine.lastIndex : pos;
  8191. }
  8192. lookaheadInLineCharCode() {
  8193. return this.input.charCodeAt(this.nextTokenInLineStart());
  8194. }
  8195. codePointAtPos(pos) {
  8196. let cp = this.input.charCodeAt(pos);
  8197. if ((cp & 0xfc00) === 0xd800 && ++pos < this.input.length) {
  8198. const trail = this.input.charCodeAt(pos);
  8199. if ((trail & 0xfc00) === 0xdc00) {
  8200. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  8201. }
  8202. }
  8203. return cp;
  8204. }
  8205. setStrict(strict) {
  8206. this.state.strict = strict;
  8207. if (strict) {
  8208. this.state.strictErrors.forEach(([toParseError, at]) => this.raise(toParseError, at));
  8209. this.state.strictErrors.clear();
  8210. }
  8211. }
  8212. curContext() {
  8213. return this.state.context[this.state.context.length - 1];
  8214. }
  8215. nextToken() {
  8216. this.skipSpace();
  8217. this.state.start = this.state.pos;
  8218. if (!this.isLookahead) this.state.startLoc = this.state.curPosition();
  8219. if (this.state.pos >= this.length) {
  8220. this.finishToken(140);
  8221. return;
  8222. }
  8223. this.getTokenFromCode(this.codePointAtPos(this.state.pos));
  8224. }
  8225. skipBlockComment(commentEnd) {
  8226. let startLoc;
  8227. if (!this.isLookahead) startLoc = this.state.curPosition();
  8228. const start = this.state.pos;
  8229. const end = this.input.indexOf(commentEnd, start + 2);
  8230. if (end === -1) {
  8231. throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
  8232. }
  8233. this.state.pos = end + commentEnd.length;
  8234. lineBreakG.lastIndex = start + 2;
  8235. while (lineBreakG.test(this.input) && lineBreakG.lastIndex <= end) {
  8236. ++this.state.curLine;
  8237. this.state.lineStart = lineBreakG.lastIndex;
  8238. }
  8239. if (this.isLookahead) return;
  8240. const comment = {
  8241. type: "CommentBlock",
  8242. value: this.input.slice(start + 2, end),
  8243. start: this.sourceToOffsetPos(start),
  8244. end: this.sourceToOffsetPos(end + commentEnd.length),
  8245. loc: new SourceLocation(startLoc, this.state.curPosition())
  8246. };
  8247. if (this.optionFlags & 256) this.pushToken(comment);
  8248. return comment;
  8249. }
  8250. skipLineComment(startSkip) {
  8251. const start = this.state.pos;
  8252. let startLoc;
  8253. if (!this.isLookahead) startLoc = this.state.curPosition();
  8254. let ch = this.input.charCodeAt(this.state.pos += startSkip);
  8255. if (this.state.pos < this.length) {
  8256. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  8257. ch = this.input.charCodeAt(this.state.pos);
  8258. }
  8259. }
  8260. if (this.isLookahead) return;
  8261. const end = this.state.pos;
  8262. const value = this.input.slice(start + startSkip, end);
  8263. const comment = {
  8264. type: "CommentLine",
  8265. value,
  8266. start: this.sourceToOffsetPos(start),
  8267. end: this.sourceToOffsetPos(end),
  8268. loc: new SourceLocation(startLoc, this.state.curPosition())
  8269. };
  8270. if (this.optionFlags & 256) this.pushToken(comment);
  8271. return comment;
  8272. }
  8273. skipSpace() {
  8274. const spaceStart = this.state.pos;
  8275. const comments = this.optionFlags & 4096 ? [] : null;
  8276. loop: while (this.state.pos < this.length) {
  8277. const ch = this.input.charCodeAt(this.state.pos);
  8278. switch (ch) {
  8279. case 32:
  8280. case 160:
  8281. case 9:
  8282. ++this.state.pos;
  8283. break;
  8284. case 13:
  8285. if (this.input.charCodeAt(this.state.pos + 1) === 10) {
  8286. ++this.state.pos;
  8287. }
  8288. case 10:
  8289. case 8232:
  8290. case 8233:
  8291. ++this.state.pos;
  8292. ++this.state.curLine;
  8293. this.state.lineStart = this.state.pos;
  8294. break;
  8295. case 47:
  8296. switch (this.input.charCodeAt(this.state.pos + 1)) {
  8297. case 42:
  8298. {
  8299. const comment = this.skipBlockComment("*/");
  8300. if (comment !== undefined) {
  8301. this.addComment(comment);
  8302. comments == null || comments.push(comment);
  8303. }
  8304. break;
  8305. }
  8306. case 47:
  8307. {
  8308. const comment = this.skipLineComment(2);
  8309. if (comment !== undefined) {
  8310. this.addComment(comment);
  8311. comments == null || comments.push(comment);
  8312. }
  8313. break;
  8314. }
  8315. default:
  8316. break loop;
  8317. }
  8318. break;
  8319. default:
  8320. if (isWhitespace(ch)) {
  8321. ++this.state.pos;
  8322. } else if (ch === 45 && !this.inModule && this.optionFlags & 8192) {
  8323. const pos = this.state.pos;
  8324. if (this.input.charCodeAt(pos + 1) === 45 && this.input.charCodeAt(pos + 2) === 62 && (spaceStart === 0 || this.state.lineStart > spaceStart)) {
  8325. const comment = this.skipLineComment(3);
  8326. if (comment !== undefined) {
  8327. this.addComment(comment);
  8328. comments == null || comments.push(comment);
  8329. }
  8330. } else {
  8331. break loop;
  8332. }
  8333. } else if (ch === 60 && !this.inModule && this.optionFlags & 8192) {
  8334. const pos = this.state.pos;
  8335. if (this.input.charCodeAt(pos + 1) === 33 && this.input.charCodeAt(pos + 2) === 45 && this.input.charCodeAt(pos + 3) === 45) {
  8336. const comment = this.skipLineComment(4);
  8337. if (comment !== undefined) {
  8338. this.addComment(comment);
  8339. comments == null || comments.push(comment);
  8340. }
  8341. } else {
  8342. break loop;
  8343. }
  8344. } else {
  8345. break loop;
  8346. }
  8347. }
  8348. }
  8349. if ((comments == null ? void 0 : comments.length) > 0) {
  8350. const end = this.state.pos;
  8351. const commentWhitespace = {
  8352. start: this.sourceToOffsetPos(spaceStart),
  8353. end: this.sourceToOffsetPos(end),
  8354. comments,
  8355. leadingNode: null,
  8356. trailingNode: null,
  8357. containingNode: null
  8358. };
  8359. this.state.commentStack.push(commentWhitespace);
  8360. }
  8361. }
  8362. finishToken(type, val) {
  8363. this.state.end = this.state.pos;
  8364. this.state.endLoc = this.state.curPosition();
  8365. const prevType = this.state.type;
  8366. this.state.type = type;
  8367. this.state.value = val;
  8368. if (!this.isLookahead) {
  8369. this.updateContext(prevType);
  8370. }
  8371. }
  8372. replaceToken(type) {
  8373. this.state.type = type;
  8374. this.updateContext();
  8375. }
  8376. readToken_numberSign() {
  8377. if (this.state.pos === 0 && this.readToken_interpreter()) {
  8378. return;
  8379. }
  8380. const nextPos = this.state.pos + 1;
  8381. const next = this.codePointAtPos(nextPos);
  8382. if (next >= 48 && next <= 57) {
  8383. throw this.raise(Errors.UnexpectedDigitAfterHash, this.state.curPosition());
  8384. }
  8385. if (next === 123 || next === 91 && this.hasPlugin("recordAndTuple")) {
  8386. this.expectPlugin("recordAndTuple");
  8387. if (this.getPluginOption("recordAndTuple", "syntaxType") === "bar") {
  8388. throw this.raise(next === 123 ? Errors.RecordExpressionHashIncorrectStartSyntaxType : Errors.TupleExpressionHashIncorrectStartSyntaxType, this.state.curPosition());
  8389. }
  8390. this.state.pos += 2;
  8391. if (next === 123) {
  8392. this.finishToken(7);
  8393. } else {
  8394. this.finishToken(1);
  8395. }
  8396. } else if (isIdentifierStart(next)) {
  8397. ++this.state.pos;
  8398. this.finishToken(139, this.readWord1(next));
  8399. } else if (next === 92) {
  8400. ++this.state.pos;
  8401. this.finishToken(139, this.readWord1());
  8402. } else {
  8403. this.finishOp(27, 1);
  8404. }
  8405. }
  8406. readToken_dot() {
  8407. const next = this.input.charCodeAt(this.state.pos + 1);
  8408. if (next >= 48 && next <= 57) {
  8409. this.readNumber(true);
  8410. return;
  8411. }
  8412. if (next === 46 && this.input.charCodeAt(this.state.pos + 2) === 46) {
  8413. this.state.pos += 3;
  8414. this.finishToken(21);
  8415. } else {
  8416. ++this.state.pos;
  8417. this.finishToken(16);
  8418. }
  8419. }
  8420. readToken_slash() {
  8421. const next = this.input.charCodeAt(this.state.pos + 1);
  8422. if (next === 61) {
  8423. this.finishOp(31, 2);
  8424. } else {
  8425. this.finishOp(56, 1);
  8426. }
  8427. }
  8428. readToken_interpreter() {
  8429. if (this.state.pos !== 0 || this.length < 2) return false;
  8430. let ch = this.input.charCodeAt(this.state.pos + 1);
  8431. if (ch !== 33) return false;
  8432. const start = this.state.pos;
  8433. this.state.pos += 1;
  8434. while (!isNewLine(ch) && ++this.state.pos < this.length) {
  8435. ch = this.input.charCodeAt(this.state.pos);
  8436. }
  8437. const value = this.input.slice(start + 2, this.state.pos);
  8438. this.finishToken(28, value);
  8439. return true;
  8440. }
  8441. readToken_mult_modulo(code) {
  8442. let type = code === 42 ? 55 : 54;
  8443. let width = 1;
  8444. let next = this.input.charCodeAt(this.state.pos + 1);
  8445. if (code === 42 && next === 42) {
  8446. width++;
  8447. next = this.input.charCodeAt(this.state.pos + 2);
  8448. type = 57;
  8449. }
  8450. if (next === 61 && !this.state.inType) {
  8451. width++;
  8452. type = code === 37 ? 33 : 30;
  8453. }
  8454. this.finishOp(type, width);
  8455. }
  8456. readToken_pipe_amp(code) {
  8457. const next = this.input.charCodeAt(this.state.pos + 1);
  8458. if (next === code) {
  8459. if (this.input.charCodeAt(this.state.pos + 2) === 61) {
  8460. this.finishOp(30, 3);
  8461. } else {
  8462. this.finishOp(code === 124 ? 41 : 42, 2);
  8463. }
  8464. return;
  8465. }
  8466. if (code === 124) {
  8467. if (next === 62) {
  8468. this.finishOp(39, 2);
  8469. return;
  8470. }
  8471. if (this.hasPlugin("recordAndTuple") && next === 125) {
  8472. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8473. throw this.raise(Errors.RecordExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  8474. }
  8475. this.state.pos += 2;
  8476. this.finishToken(9);
  8477. return;
  8478. }
  8479. if (this.hasPlugin("recordAndTuple") && next === 93) {
  8480. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8481. throw this.raise(Errors.TupleExpressionBarIncorrectEndSyntaxType, this.state.curPosition());
  8482. }
  8483. this.state.pos += 2;
  8484. this.finishToken(4);
  8485. return;
  8486. }
  8487. }
  8488. if (next === 61) {
  8489. this.finishOp(30, 2);
  8490. return;
  8491. }
  8492. this.finishOp(code === 124 ? 43 : 45, 1);
  8493. }
  8494. readToken_caret() {
  8495. const next = this.input.charCodeAt(this.state.pos + 1);
  8496. if (next === 61 && !this.state.inType) {
  8497. this.finishOp(32, 2);
  8498. } else if (next === 94 && this.hasPlugin(["pipelineOperator", {
  8499. proposal: "hack",
  8500. topicToken: "^^"
  8501. }])) {
  8502. this.finishOp(37, 2);
  8503. const lookaheadCh = this.input.codePointAt(this.state.pos);
  8504. if (lookaheadCh === 94) {
  8505. this.unexpected();
  8506. }
  8507. } else {
  8508. this.finishOp(44, 1);
  8509. }
  8510. }
  8511. readToken_atSign() {
  8512. const next = this.input.charCodeAt(this.state.pos + 1);
  8513. if (next === 64 && this.hasPlugin(["pipelineOperator", {
  8514. proposal: "hack",
  8515. topicToken: "@@"
  8516. }])) {
  8517. this.finishOp(38, 2);
  8518. } else {
  8519. this.finishOp(26, 1);
  8520. }
  8521. }
  8522. readToken_plus_min(code) {
  8523. const next = this.input.charCodeAt(this.state.pos + 1);
  8524. if (next === code) {
  8525. this.finishOp(34, 2);
  8526. return;
  8527. }
  8528. if (next === 61) {
  8529. this.finishOp(30, 2);
  8530. } else {
  8531. this.finishOp(53, 1);
  8532. }
  8533. }
  8534. readToken_lt() {
  8535. const {
  8536. pos
  8537. } = this.state;
  8538. const next = this.input.charCodeAt(pos + 1);
  8539. if (next === 60) {
  8540. if (this.input.charCodeAt(pos + 2) === 61) {
  8541. this.finishOp(30, 3);
  8542. return;
  8543. }
  8544. this.finishOp(51, 2);
  8545. return;
  8546. }
  8547. if (next === 61) {
  8548. this.finishOp(49, 2);
  8549. return;
  8550. }
  8551. this.finishOp(47, 1);
  8552. }
  8553. readToken_gt() {
  8554. const {
  8555. pos
  8556. } = this.state;
  8557. const next = this.input.charCodeAt(pos + 1);
  8558. if (next === 62) {
  8559. const size = this.input.charCodeAt(pos + 2) === 62 ? 3 : 2;
  8560. if (this.input.charCodeAt(pos + size) === 61) {
  8561. this.finishOp(30, size + 1);
  8562. return;
  8563. }
  8564. this.finishOp(52, size);
  8565. return;
  8566. }
  8567. if (next === 61) {
  8568. this.finishOp(49, 2);
  8569. return;
  8570. }
  8571. this.finishOp(48, 1);
  8572. }
  8573. readToken_eq_excl(code) {
  8574. const next = this.input.charCodeAt(this.state.pos + 1);
  8575. if (next === 61) {
  8576. this.finishOp(46, this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2);
  8577. return;
  8578. }
  8579. if (code === 61 && next === 62) {
  8580. this.state.pos += 2;
  8581. this.finishToken(19);
  8582. return;
  8583. }
  8584. this.finishOp(code === 61 ? 29 : 35, 1);
  8585. }
  8586. readToken_question() {
  8587. const next = this.input.charCodeAt(this.state.pos + 1);
  8588. const next2 = this.input.charCodeAt(this.state.pos + 2);
  8589. if (next === 63) {
  8590. if (next2 === 61) {
  8591. this.finishOp(30, 3);
  8592. } else {
  8593. this.finishOp(40, 2);
  8594. }
  8595. } else if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
  8596. this.state.pos += 2;
  8597. this.finishToken(18);
  8598. } else {
  8599. ++this.state.pos;
  8600. this.finishToken(17);
  8601. }
  8602. }
  8603. getTokenFromCode(code) {
  8604. switch (code) {
  8605. case 46:
  8606. this.readToken_dot();
  8607. return;
  8608. case 40:
  8609. ++this.state.pos;
  8610. this.finishToken(10);
  8611. return;
  8612. case 41:
  8613. ++this.state.pos;
  8614. this.finishToken(11);
  8615. return;
  8616. case 59:
  8617. ++this.state.pos;
  8618. this.finishToken(13);
  8619. return;
  8620. case 44:
  8621. ++this.state.pos;
  8622. this.finishToken(12);
  8623. return;
  8624. case 91:
  8625. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  8626. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8627. throw this.raise(Errors.TupleExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  8628. }
  8629. this.state.pos += 2;
  8630. this.finishToken(2);
  8631. } else {
  8632. ++this.state.pos;
  8633. this.finishToken(0);
  8634. }
  8635. return;
  8636. case 93:
  8637. ++this.state.pos;
  8638. this.finishToken(3);
  8639. return;
  8640. case 123:
  8641. if (this.hasPlugin("recordAndTuple") && this.input.charCodeAt(this.state.pos + 1) === 124) {
  8642. if (this.getPluginOption("recordAndTuple", "syntaxType") !== "bar") {
  8643. throw this.raise(Errors.RecordExpressionBarIncorrectStartSyntaxType, this.state.curPosition());
  8644. }
  8645. this.state.pos += 2;
  8646. this.finishToken(6);
  8647. } else {
  8648. ++this.state.pos;
  8649. this.finishToken(5);
  8650. }
  8651. return;
  8652. case 125:
  8653. ++this.state.pos;
  8654. this.finishToken(8);
  8655. return;
  8656. case 58:
  8657. if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) {
  8658. this.finishOp(15, 2);
  8659. } else {
  8660. ++this.state.pos;
  8661. this.finishToken(14);
  8662. }
  8663. return;
  8664. case 63:
  8665. this.readToken_question();
  8666. return;
  8667. case 96:
  8668. this.readTemplateToken();
  8669. return;
  8670. case 48:
  8671. {
  8672. const next = this.input.charCodeAt(this.state.pos + 1);
  8673. if (next === 120 || next === 88) {
  8674. this.readRadixNumber(16);
  8675. return;
  8676. }
  8677. if (next === 111 || next === 79) {
  8678. this.readRadixNumber(8);
  8679. return;
  8680. }
  8681. if (next === 98 || next === 66) {
  8682. this.readRadixNumber(2);
  8683. return;
  8684. }
  8685. }
  8686. case 49:
  8687. case 50:
  8688. case 51:
  8689. case 52:
  8690. case 53:
  8691. case 54:
  8692. case 55:
  8693. case 56:
  8694. case 57:
  8695. this.readNumber(false);
  8696. return;
  8697. case 34:
  8698. case 39:
  8699. this.readString(code);
  8700. return;
  8701. case 47:
  8702. this.readToken_slash();
  8703. return;
  8704. case 37:
  8705. case 42:
  8706. this.readToken_mult_modulo(code);
  8707. return;
  8708. case 124:
  8709. case 38:
  8710. this.readToken_pipe_amp(code);
  8711. return;
  8712. case 94:
  8713. this.readToken_caret();
  8714. return;
  8715. case 43:
  8716. case 45:
  8717. this.readToken_plus_min(code);
  8718. return;
  8719. case 60:
  8720. this.readToken_lt();
  8721. return;
  8722. case 62:
  8723. this.readToken_gt();
  8724. return;
  8725. case 61:
  8726. case 33:
  8727. this.readToken_eq_excl(code);
  8728. return;
  8729. case 126:
  8730. this.finishOp(36, 1);
  8731. return;
  8732. case 64:
  8733. this.readToken_atSign();
  8734. return;
  8735. case 35:
  8736. this.readToken_numberSign();
  8737. return;
  8738. case 92:
  8739. this.readWord();
  8740. return;
  8741. default:
  8742. if (isIdentifierStart(code)) {
  8743. this.readWord(code);
  8744. return;
  8745. }
  8746. }
  8747. throw this.raise(Errors.InvalidOrUnexpectedToken, this.state.curPosition(), {
  8748. unexpected: String.fromCodePoint(code)
  8749. });
  8750. }
  8751. finishOp(type, size) {
  8752. const str = this.input.slice(this.state.pos, this.state.pos + size);
  8753. this.state.pos += size;
  8754. this.finishToken(type, str);
  8755. }
  8756. readRegexp() {
  8757. const startLoc = this.state.startLoc;
  8758. const start = this.state.start + 1;
  8759. let escaped, inClass;
  8760. let {
  8761. pos
  8762. } = this.state;
  8763. for (;; ++pos) {
  8764. if (pos >= this.length) {
  8765. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  8766. }
  8767. const ch = this.input.charCodeAt(pos);
  8768. if (isNewLine(ch)) {
  8769. throw this.raise(Errors.UnterminatedRegExp, createPositionWithColumnOffset(startLoc, 1));
  8770. }
  8771. if (escaped) {
  8772. escaped = false;
  8773. } else {
  8774. if (ch === 91) {
  8775. inClass = true;
  8776. } else if (ch === 93 && inClass) {
  8777. inClass = false;
  8778. } else if (ch === 47 && !inClass) {
  8779. break;
  8780. }
  8781. escaped = ch === 92;
  8782. }
  8783. }
  8784. const content = this.input.slice(start, pos);
  8785. ++pos;
  8786. let mods = "";
  8787. const nextPos = () => createPositionWithColumnOffset(startLoc, pos + 2 - start);
  8788. while (pos < this.length) {
  8789. const cp = this.codePointAtPos(pos);
  8790. const char = String.fromCharCode(cp);
  8791. if (VALID_REGEX_FLAGS.has(cp)) {
  8792. if (cp === 118) {
  8793. if (mods.includes("u")) {
  8794. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  8795. }
  8796. } else if (cp === 117) {
  8797. if (mods.includes("v")) {
  8798. this.raise(Errors.IncompatibleRegExpUVFlags, nextPos());
  8799. }
  8800. }
  8801. if (mods.includes(char)) {
  8802. this.raise(Errors.DuplicateRegExpFlags, nextPos());
  8803. }
  8804. } else if (isIdentifierChar(cp) || cp === 92) {
  8805. this.raise(Errors.MalformedRegExpFlags, nextPos());
  8806. } else {
  8807. break;
  8808. }
  8809. ++pos;
  8810. mods += char;
  8811. }
  8812. this.state.pos = pos;
  8813. this.finishToken(138, {
  8814. pattern: content,
  8815. flags: mods
  8816. });
  8817. }
  8818. readInt(radix, len, forceLen = false, allowNumSeparator = true) {
  8819. const {
  8820. n,
  8821. pos
  8822. } = readInt(this.input, this.state.pos, this.state.lineStart, this.state.curLine, radix, len, forceLen, allowNumSeparator, this.errorHandlers_readInt, false);
  8823. this.state.pos = pos;
  8824. return n;
  8825. }
  8826. readRadixNumber(radix) {
  8827. const start = this.state.pos;
  8828. const startLoc = this.state.curPosition();
  8829. let isBigInt = false;
  8830. this.state.pos += 2;
  8831. const val = this.readInt(radix);
  8832. if (val == null) {
  8833. this.raise(Errors.InvalidDigit, createPositionWithColumnOffset(startLoc, 2), {
  8834. radix
  8835. });
  8836. }
  8837. const next = this.input.charCodeAt(this.state.pos);
  8838. if (next === 110) {
  8839. ++this.state.pos;
  8840. isBigInt = true;
  8841. } else if (next === 109) {
  8842. throw this.raise(Errors.InvalidDecimal, startLoc);
  8843. }
  8844. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  8845. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  8846. }
  8847. if (isBigInt) {
  8848. const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
  8849. this.finishToken(136, str);
  8850. return;
  8851. }
  8852. this.finishToken(135, val);
  8853. }
  8854. readNumber(startsWithDot) {
  8855. const start = this.state.pos;
  8856. const startLoc = this.state.curPosition();
  8857. let isFloat = false;
  8858. let isBigInt = false;
  8859. let hasExponent = false;
  8860. let isOctal = false;
  8861. if (!startsWithDot && this.readInt(10) === null) {
  8862. this.raise(Errors.InvalidNumber, this.state.curPosition());
  8863. }
  8864. const hasLeadingZero = this.state.pos - start >= 2 && this.input.charCodeAt(start) === 48;
  8865. if (hasLeadingZero) {
  8866. const integer = this.input.slice(start, this.state.pos);
  8867. this.recordStrictModeErrors(Errors.StrictOctalLiteral, startLoc);
  8868. if (!this.state.strict) {
  8869. const underscorePos = integer.indexOf("_");
  8870. if (underscorePos > 0) {
  8871. this.raise(Errors.ZeroDigitNumericSeparator, createPositionWithColumnOffset(startLoc, underscorePos));
  8872. }
  8873. }
  8874. isOctal = hasLeadingZero && !/[89]/.test(integer);
  8875. }
  8876. let next = this.input.charCodeAt(this.state.pos);
  8877. if (next === 46 && !isOctal) {
  8878. ++this.state.pos;
  8879. this.readInt(10);
  8880. isFloat = true;
  8881. next = this.input.charCodeAt(this.state.pos);
  8882. }
  8883. if ((next === 69 || next === 101) && !isOctal) {
  8884. next = this.input.charCodeAt(++this.state.pos);
  8885. if (next === 43 || next === 45) {
  8886. ++this.state.pos;
  8887. }
  8888. if (this.readInt(10) === null) {
  8889. this.raise(Errors.InvalidOrMissingExponent, startLoc);
  8890. }
  8891. isFloat = true;
  8892. hasExponent = true;
  8893. next = this.input.charCodeAt(this.state.pos);
  8894. }
  8895. if (next === 110) {
  8896. if (isFloat || hasLeadingZero) {
  8897. this.raise(Errors.InvalidBigIntLiteral, startLoc);
  8898. }
  8899. ++this.state.pos;
  8900. isBigInt = true;
  8901. }
  8902. if (next === 109) {
  8903. this.expectPlugin("decimal", this.state.curPosition());
  8904. if (hasExponent || hasLeadingZero) {
  8905. this.raise(Errors.InvalidDecimal, startLoc);
  8906. }
  8907. ++this.state.pos;
  8908. var isDecimal = true;
  8909. }
  8910. if (isIdentifierStart(this.codePointAtPos(this.state.pos))) {
  8911. throw this.raise(Errors.NumberIdentifier, this.state.curPosition());
  8912. }
  8913. const str = this.input.slice(start, this.state.pos).replace(/[_mn]/g, "");
  8914. if (isBigInt) {
  8915. this.finishToken(136, str);
  8916. return;
  8917. }
  8918. if (isDecimal) {
  8919. this.finishToken(137, str);
  8920. return;
  8921. }
  8922. const val = isOctal ? parseInt(str, 8) : parseFloat(str);
  8923. this.finishToken(135, val);
  8924. }
  8925. readCodePoint(throwOnInvalid) {
  8926. const {
  8927. code,
  8928. pos
  8929. } = readCodePoint(this.input, this.state.pos, this.state.lineStart, this.state.curLine, throwOnInvalid, this.errorHandlers_readCodePoint);
  8930. this.state.pos = pos;
  8931. return code;
  8932. }
  8933. readString(quote) {
  8934. const {
  8935. str,
  8936. pos,
  8937. curLine,
  8938. lineStart
  8939. } = readStringContents(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
  8940. this.state.pos = pos + 1;
  8941. this.state.lineStart = lineStart;
  8942. this.state.curLine = curLine;
  8943. this.finishToken(134, str);
  8944. }
  8945. readTemplateContinuation() {
  8946. if (!this.match(8)) {
  8947. this.unexpected(null, 8);
  8948. }
  8949. this.state.pos--;
  8950. this.readTemplateToken();
  8951. }
  8952. readTemplateToken() {
  8953. const opening = this.input[this.state.pos];
  8954. const {
  8955. str,
  8956. firstInvalidLoc,
  8957. pos,
  8958. curLine,
  8959. lineStart
  8960. } = readStringContents("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
  8961. this.state.pos = pos + 1;
  8962. this.state.lineStart = lineStart;
  8963. this.state.curLine = curLine;
  8964. if (firstInvalidLoc) {
  8965. this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
  8966. }
  8967. if (this.input.codePointAt(pos) === 96) {
  8968. this.finishToken(24, firstInvalidLoc ? null : opening + str + "`");
  8969. } else {
  8970. this.state.pos++;
  8971. this.finishToken(25, firstInvalidLoc ? null : opening + str + "${");
  8972. }
  8973. }
  8974. recordStrictModeErrors(toParseError, at) {
  8975. const index = at.index;
  8976. if (this.state.strict && !this.state.strictErrors.has(index)) {
  8977. this.raise(toParseError, at);
  8978. } else {
  8979. this.state.strictErrors.set(index, [toParseError, at]);
  8980. }
  8981. }
  8982. readWord1(firstCode) {
  8983. this.state.containsEsc = false;
  8984. let word = "";
  8985. const start = this.state.pos;
  8986. let chunkStart = this.state.pos;
  8987. if (firstCode !== undefined) {
  8988. this.state.pos += firstCode <= 0xffff ? 1 : 2;
  8989. }
  8990. while (this.state.pos < this.length) {
  8991. const ch = this.codePointAtPos(this.state.pos);
  8992. if (isIdentifierChar(ch)) {
  8993. this.state.pos += ch <= 0xffff ? 1 : 2;
  8994. } else if (ch === 92) {
  8995. this.state.containsEsc = true;
  8996. word += this.input.slice(chunkStart, this.state.pos);
  8997. const escStart = this.state.curPosition();
  8998. const identifierCheck = this.state.pos === start ? isIdentifierStart : isIdentifierChar;
  8999. if (this.input.charCodeAt(++this.state.pos) !== 117) {
  9000. this.raise(Errors.MissingUnicodeEscape, this.state.curPosition());
  9001. chunkStart = this.state.pos - 1;
  9002. continue;
  9003. }
  9004. ++this.state.pos;
  9005. const esc = this.readCodePoint(true);
  9006. if (esc !== null) {
  9007. if (!identifierCheck(esc)) {
  9008. this.raise(Errors.EscapedCharNotAnIdentifier, escStart);
  9009. }
  9010. word += String.fromCodePoint(esc);
  9011. }
  9012. chunkStart = this.state.pos;
  9013. } else {
  9014. break;
  9015. }
  9016. }
  9017. return word + this.input.slice(chunkStart, this.state.pos);
  9018. }
  9019. readWord(firstCode) {
  9020. const word = this.readWord1(firstCode);
  9021. const type = keywords$1.get(word);
  9022. if (type !== undefined) {
  9023. this.finishToken(type, tokenLabelName(type));
  9024. } else {
  9025. this.finishToken(132, word);
  9026. }
  9027. }
  9028. checkKeywordEscapes() {
  9029. const {
  9030. type
  9031. } = this.state;
  9032. if (tokenIsKeyword(type) && this.state.containsEsc) {
  9033. this.raise(Errors.InvalidEscapedReservedWord, this.state.startLoc, {
  9034. reservedWord: tokenLabelName(type)
  9035. });
  9036. }
  9037. }
  9038. raise(toParseError, at, details = {}) {
  9039. const loc = at instanceof Position ? at : at.loc.start;
  9040. const error = toParseError(loc, details);
  9041. if (!(this.optionFlags & 2048)) throw error;
  9042. if (!this.isLookahead) this.state.errors.push(error);
  9043. return error;
  9044. }
  9045. raiseOverwrite(toParseError, at, details = {}) {
  9046. const loc = at instanceof Position ? at : at.loc.start;
  9047. const pos = loc.index;
  9048. const errors = this.state.errors;
  9049. for (let i = errors.length - 1; i >= 0; i--) {
  9050. const error = errors[i];
  9051. if (error.loc.index === pos) {
  9052. return errors[i] = toParseError(loc, details);
  9053. }
  9054. if (error.loc.index < pos) break;
  9055. }
  9056. return this.raise(toParseError, at, details);
  9057. }
  9058. updateContext(prevType) {}
  9059. unexpected(loc, type) {
  9060. throw this.raise(Errors.UnexpectedToken, loc != null ? loc : this.state.startLoc, {
  9061. expected: type ? tokenLabelName(type) : null
  9062. });
  9063. }
  9064. expectPlugin(pluginName, loc) {
  9065. if (this.hasPlugin(pluginName)) {
  9066. return true;
  9067. }
  9068. throw this.raise(Errors.MissingPlugin, loc != null ? loc : this.state.startLoc, {
  9069. missingPlugin: [pluginName]
  9070. });
  9071. }
  9072. expectOnePlugin(pluginNames) {
  9073. if (!pluginNames.some(name => this.hasPlugin(name))) {
  9074. throw this.raise(Errors.MissingOneOfPlugins, this.state.startLoc, {
  9075. missingPlugin: pluginNames
  9076. });
  9077. }
  9078. }
  9079. errorBuilder(error) {
  9080. return (pos, lineStart, curLine) => {
  9081. this.raise(error, buildPosition(pos, lineStart, curLine));
  9082. };
  9083. }
  9084. }
  9085. class ClassScope {
  9086. constructor() {
  9087. this.privateNames = new Set();
  9088. this.loneAccessors = new Map();
  9089. this.undefinedPrivateNames = new Map();
  9090. }
  9091. }
  9092. class ClassScopeHandler {
  9093. constructor(parser) {
  9094. this.parser = void 0;
  9095. this.stack = [];
  9096. this.undefinedPrivateNames = new Map();
  9097. this.parser = parser;
  9098. }
  9099. current() {
  9100. return this.stack[this.stack.length - 1];
  9101. }
  9102. enter() {
  9103. this.stack.push(new ClassScope());
  9104. }
  9105. exit() {
  9106. const oldClassScope = this.stack.pop();
  9107. const current = this.current();
  9108. for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
  9109. if (current) {
  9110. if (!current.undefinedPrivateNames.has(name)) {
  9111. current.undefinedPrivateNames.set(name, loc);
  9112. }
  9113. } else {
  9114. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  9115. identifierName: name
  9116. });
  9117. }
  9118. }
  9119. }
  9120. declarePrivateName(name, elementType, loc) {
  9121. const {
  9122. privateNames,
  9123. loneAccessors,
  9124. undefinedPrivateNames
  9125. } = this.current();
  9126. let redefined = privateNames.has(name);
  9127. if (elementType & 3) {
  9128. const accessor = redefined && loneAccessors.get(name);
  9129. if (accessor) {
  9130. const oldStatic = accessor & 4;
  9131. const newStatic = elementType & 4;
  9132. const oldKind = accessor & 3;
  9133. const newKind = elementType & 3;
  9134. redefined = oldKind === newKind || oldStatic !== newStatic;
  9135. if (!redefined) loneAccessors.delete(name);
  9136. } else if (!redefined) {
  9137. loneAccessors.set(name, elementType);
  9138. }
  9139. }
  9140. if (redefined) {
  9141. this.parser.raise(Errors.PrivateNameRedeclaration, loc, {
  9142. identifierName: name
  9143. });
  9144. }
  9145. privateNames.add(name);
  9146. undefinedPrivateNames.delete(name);
  9147. }
  9148. usePrivateName(name, loc) {
  9149. let classScope;
  9150. for (classScope of this.stack) {
  9151. if (classScope.privateNames.has(name)) return;
  9152. }
  9153. if (classScope) {
  9154. classScope.undefinedPrivateNames.set(name, loc);
  9155. } else {
  9156. this.parser.raise(Errors.InvalidPrivateFieldResolution, loc, {
  9157. identifierName: name
  9158. });
  9159. }
  9160. }
  9161. }
  9162. class ExpressionScope {
  9163. constructor(type = 0) {
  9164. this.type = type;
  9165. }
  9166. canBeArrowParameterDeclaration() {
  9167. return this.type === 2 || this.type === 1;
  9168. }
  9169. isCertainlyParameterDeclaration() {
  9170. return this.type === 3;
  9171. }
  9172. }
  9173. class ArrowHeadParsingScope extends ExpressionScope {
  9174. constructor(type) {
  9175. super(type);
  9176. this.declarationErrors = new Map();
  9177. }
  9178. recordDeclarationError(ParsingErrorClass, at) {
  9179. const index = at.index;
  9180. this.declarationErrors.set(index, [ParsingErrorClass, at]);
  9181. }
  9182. clearDeclarationError(index) {
  9183. this.declarationErrors.delete(index);
  9184. }
  9185. iterateErrors(iterator) {
  9186. this.declarationErrors.forEach(iterator);
  9187. }
  9188. }
  9189. class ExpressionScopeHandler {
  9190. constructor(parser) {
  9191. this.parser = void 0;
  9192. this.stack = [new ExpressionScope()];
  9193. this.parser = parser;
  9194. }
  9195. enter(scope) {
  9196. this.stack.push(scope);
  9197. }
  9198. exit() {
  9199. this.stack.pop();
  9200. }
  9201. recordParameterInitializerError(toParseError, node) {
  9202. const origin = node.loc.start;
  9203. const {
  9204. stack
  9205. } = this;
  9206. let i = stack.length - 1;
  9207. let scope = stack[i];
  9208. while (!scope.isCertainlyParameterDeclaration()) {
  9209. if (scope.canBeArrowParameterDeclaration()) {
  9210. scope.recordDeclarationError(toParseError, origin);
  9211. } else {
  9212. return;
  9213. }
  9214. scope = stack[--i];
  9215. }
  9216. this.parser.raise(toParseError, origin);
  9217. }
  9218. recordArrowParameterBindingError(error, node) {
  9219. const {
  9220. stack
  9221. } = this;
  9222. const scope = stack[stack.length - 1];
  9223. const origin = node.loc.start;
  9224. if (scope.isCertainlyParameterDeclaration()) {
  9225. this.parser.raise(error, origin);
  9226. } else if (scope.canBeArrowParameterDeclaration()) {
  9227. scope.recordDeclarationError(error, origin);
  9228. } else {
  9229. return;
  9230. }
  9231. }
  9232. recordAsyncArrowParametersError(at) {
  9233. const {
  9234. stack
  9235. } = this;
  9236. let i = stack.length - 1;
  9237. let scope = stack[i];
  9238. while (scope.canBeArrowParameterDeclaration()) {
  9239. if (scope.type === 2) {
  9240. scope.recordDeclarationError(Errors.AwaitBindingIdentifier, at);
  9241. }
  9242. scope = stack[--i];
  9243. }
  9244. }
  9245. validateAsPattern() {
  9246. const {
  9247. stack
  9248. } = this;
  9249. const currentScope = stack[stack.length - 1];
  9250. if (!currentScope.canBeArrowParameterDeclaration()) return;
  9251. currentScope.iterateErrors(([toParseError, loc]) => {
  9252. this.parser.raise(toParseError, loc);
  9253. let i = stack.length - 2;
  9254. let scope = stack[i];
  9255. while (scope.canBeArrowParameterDeclaration()) {
  9256. scope.clearDeclarationError(loc.index);
  9257. scope = stack[--i];
  9258. }
  9259. });
  9260. }
  9261. }
  9262. function newParameterDeclarationScope() {
  9263. return new ExpressionScope(3);
  9264. }
  9265. function newArrowHeadScope() {
  9266. return new ArrowHeadParsingScope(1);
  9267. }
  9268. function newAsyncArrowScope() {
  9269. return new ArrowHeadParsingScope(2);
  9270. }
  9271. function newExpressionScope() {
  9272. return new ExpressionScope();
  9273. }
  9274. class UtilParser extends Tokenizer {
  9275. addExtra(node, key, value, enumerable = true) {
  9276. if (!node) return;
  9277. let {
  9278. extra
  9279. } = node;
  9280. if (extra == null) {
  9281. extra = {};
  9282. node.extra = extra;
  9283. }
  9284. if (enumerable) {
  9285. extra[key] = value;
  9286. } else {
  9287. Object.defineProperty(extra, key, {
  9288. enumerable,
  9289. value
  9290. });
  9291. }
  9292. }
  9293. isContextual(token) {
  9294. return this.state.type === token && !this.state.containsEsc;
  9295. }
  9296. isUnparsedContextual(nameStart, name) {
  9297. if (this.input.startsWith(name, nameStart)) {
  9298. const nextCh = this.input.charCodeAt(nameStart + name.length);
  9299. return !(isIdentifierChar(nextCh) || (nextCh & 0xfc00) === 0xd800);
  9300. }
  9301. return false;
  9302. }
  9303. isLookaheadContextual(name) {
  9304. const next = this.nextTokenStart();
  9305. return this.isUnparsedContextual(next, name);
  9306. }
  9307. eatContextual(token) {
  9308. if (this.isContextual(token)) {
  9309. this.next();
  9310. return true;
  9311. }
  9312. return false;
  9313. }
  9314. expectContextual(token, toParseError) {
  9315. if (!this.eatContextual(token)) {
  9316. if (toParseError != null) {
  9317. throw this.raise(toParseError, this.state.startLoc);
  9318. }
  9319. this.unexpected(null, token);
  9320. }
  9321. }
  9322. canInsertSemicolon() {
  9323. return this.match(140) || this.match(8) || this.hasPrecedingLineBreak();
  9324. }
  9325. hasPrecedingLineBreak() {
  9326. return hasNewLine(this.input, this.offsetToSourcePos(this.state.lastTokEndLoc.index), this.state.start);
  9327. }
  9328. hasFollowingLineBreak() {
  9329. return hasNewLine(this.input, this.state.end, this.nextTokenStart());
  9330. }
  9331. isLineTerminator() {
  9332. return this.eat(13) || this.canInsertSemicolon();
  9333. }
  9334. semicolon(allowAsi = true) {
  9335. if (allowAsi ? this.isLineTerminator() : this.eat(13)) return;
  9336. this.raise(Errors.MissingSemicolon, this.state.lastTokEndLoc);
  9337. }
  9338. expect(type, loc) {
  9339. if (!this.eat(type)) {
  9340. this.unexpected(loc, type);
  9341. }
  9342. }
  9343. tryParse(fn, oldState = this.state.clone()) {
  9344. const abortSignal = {
  9345. node: null
  9346. };
  9347. try {
  9348. const node = fn((node = null) => {
  9349. abortSignal.node = node;
  9350. throw abortSignal;
  9351. });
  9352. if (this.state.errors.length > oldState.errors.length) {
  9353. const failState = this.state;
  9354. this.state = oldState;
  9355. this.state.tokensLength = failState.tokensLength;
  9356. return {
  9357. node,
  9358. error: failState.errors[oldState.errors.length],
  9359. thrown: false,
  9360. aborted: false,
  9361. failState
  9362. };
  9363. }
  9364. return {
  9365. node,
  9366. error: null,
  9367. thrown: false,
  9368. aborted: false,
  9369. failState: null
  9370. };
  9371. } catch (error) {
  9372. const failState = this.state;
  9373. this.state = oldState;
  9374. if (error instanceof SyntaxError) {
  9375. return {
  9376. node: null,
  9377. error,
  9378. thrown: true,
  9379. aborted: false,
  9380. failState
  9381. };
  9382. }
  9383. if (error === abortSignal) {
  9384. return {
  9385. node: abortSignal.node,
  9386. error: null,
  9387. thrown: false,
  9388. aborted: true,
  9389. failState
  9390. };
  9391. }
  9392. throw error;
  9393. }
  9394. }
  9395. checkExpressionErrors(refExpressionErrors, andThrow) {
  9396. if (!refExpressionErrors) return false;
  9397. const {
  9398. shorthandAssignLoc,
  9399. doubleProtoLoc,
  9400. privateKeyLoc,
  9401. optionalParametersLoc,
  9402. voidPatternLoc
  9403. } = refExpressionErrors;
  9404. const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc || !!voidPatternLoc;
  9405. if (!andThrow) {
  9406. return hasErrors;
  9407. }
  9408. if (shorthandAssignLoc != null) {
  9409. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  9410. }
  9411. if (doubleProtoLoc != null) {
  9412. this.raise(Errors.DuplicateProto, doubleProtoLoc);
  9413. }
  9414. if (privateKeyLoc != null) {
  9415. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  9416. }
  9417. if (optionalParametersLoc != null) {
  9418. this.unexpected(optionalParametersLoc);
  9419. }
  9420. if (voidPatternLoc != null) {
  9421. this.raise(Errors.InvalidCoverDiscardElement, voidPatternLoc);
  9422. }
  9423. }
  9424. isLiteralPropertyName() {
  9425. return tokenIsLiteralPropertyName(this.state.type);
  9426. }
  9427. isPrivateName(node) {
  9428. return node.type === "PrivateName";
  9429. }
  9430. getPrivateNameSV(node) {
  9431. return node.id.name;
  9432. }
  9433. hasPropertyAsPrivateName(node) {
  9434. return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property);
  9435. }
  9436. isObjectProperty(node) {
  9437. return node.type === "ObjectProperty";
  9438. }
  9439. isObjectMethod(node) {
  9440. return node.type === "ObjectMethod";
  9441. }
  9442. initializeScopes(inModule = this.options.sourceType === "module") {
  9443. const oldLabels = this.state.labels;
  9444. this.state.labels = [];
  9445. const oldExportedIdentifiers = this.exportedIdentifiers;
  9446. this.exportedIdentifiers = new Set();
  9447. const oldInModule = this.inModule;
  9448. this.inModule = inModule;
  9449. const oldScope = this.scope;
  9450. const ScopeHandler = this.getScopeHandler();
  9451. this.scope = new ScopeHandler(this, inModule);
  9452. const oldProdParam = this.prodParam;
  9453. this.prodParam = new ProductionParameterHandler();
  9454. const oldClassScope = this.classScope;
  9455. this.classScope = new ClassScopeHandler(this);
  9456. const oldExpressionScope = this.expressionScope;
  9457. this.expressionScope = new ExpressionScopeHandler(this);
  9458. return () => {
  9459. this.state.labels = oldLabels;
  9460. this.exportedIdentifiers = oldExportedIdentifiers;
  9461. this.inModule = oldInModule;
  9462. this.scope = oldScope;
  9463. this.prodParam = oldProdParam;
  9464. this.classScope = oldClassScope;
  9465. this.expressionScope = oldExpressionScope;
  9466. };
  9467. }
  9468. enterInitialScopes() {
  9469. let paramFlags = 0;
  9470. if (this.inModule || this.optionFlags & 1) {
  9471. paramFlags |= 2;
  9472. }
  9473. if (this.optionFlags & 32) {
  9474. paramFlags |= 1;
  9475. }
  9476. const isCommonJS = !this.inModule && this.options.sourceType === "commonjs";
  9477. if (isCommonJS || this.optionFlags & 2) {
  9478. paramFlags |= 4;
  9479. }
  9480. this.prodParam.enter(paramFlags);
  9481. let scopeFlags = isCommonJS ? 514 : 1;
  9482. if (this.optionFlags & 4) {
  9483. scopeFlags |= 512;
  9484. }
  9485. this.scope.enter(scopeFlags);
  9486. }
  9487. checkDestructuringPrivate(refExpressionErrors) {
  9488. const {
  9489. privateKeyLoc
  9490. } = refExpressionErrors;
  9491. if (privateKeyLoc !== null) {
  9492. this.expectPlugin("destructuringPrivate", privateKeyLoc);
  9493. }
  9494. }
  9495. }
  9496. class ExpressionErrors {
  9497. constructor() {
  9498. this.shorthandAssignLoc = null;
  9499. this.doubleProtoLoc = null;
  9500. this.privateKeyLoc = null;
  9501. this.optionalParametersLoc = null;
  9502. this.voidPatternLoc = null;
  9503. }
  9504. }
  9505. class Node {
  9506. constructor(parser, pos, loc) {
  9507. this.type = "";
  9508. this.start = pos;
  9509. this.end = 0;
  9510. this.loc = new SourceLocation(loc);
  9511. if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
  9512. if (parser != null && parser.filename) this.loc.filename = parser.filename;
  9513. }
  9514. }
  9515. const NodePrototype = Node.prototype;
  9516. {
  9517. NodePrototype.__clone = function () {
  9518. const newNode = new Node(undefined, this.start, this.loc.start);
  9519. const keys = Object.keys(this);
  9520. for (let i = 0, length = keys.length; i < length; i++) {
  9521. const key = keys[i];
  9522. if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") {
  9523. newNode[key] = this[key];
  9524. }
  9525. }
  9526. return newNode;
  9527. };
  9528. }
  9529. class NodeUtils extends UtilParser {
  9530. startNode() {
  9531. const loc = this.state.startLoc;
  9532. return new Node(this, loc.index, loc);
  9533. }
  9534. startNodeAt(loc) {
  9535. return new Node(this, loc.index, loc);
  9536. }
  9537. startNodeAtNode(type) {
  9538. return this.startNodeAt(type.loc.start);
  9539. }
  9540. finishNode(node, type) {
  9541. return this.finishNodeAt(node, type, this.state.lastTokEndLoc);
  9542. }
  9543. finishNodeAt(node, type, endLoc) {
  9544. node.type = type;
  9545. node.end = endLoc.index;
  9546. node.loc.end = endLoc;
  9547. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  9548. if (this.optionFlags & 4096) {
  9549. this.processComment(node);
  9550. }
  9551. return node;
  9552. }
  9553. resetStartLocation(node, startLoc) {
  9554. node.start = startLoc.index;
  9555. node.loc.start = startLoc;
  9556. if (this.optionFlags & 128) node.range[0] = startLoc.index;
  9557. }
  9558. resetEndLocation(node, endLoc = this.state.lastTokEndLoc) {
  9559. node.end = endLoc.index;
  9560. node.loc.end = endLoc;
  9561. if (this.optionFlags & 128) node.range[1] = endLoc.index;
  9562. }
  9563. resetStartLocationFromNode(node, locationNode) {
  9564. this.resetStartLocation(node, locationNode.loc.start);
  9565. }
  9566. castNodeTo(node, type) {
  9567. node.type = type;
  9568. return node;
  9569. }
  9570. cloneIdentifier(node) {
  9571. const {
  9572. type,
  9573. start,
  9574. end,
  9575. loc,
  9576. range,
  9577. name
  9578. } = node;
  9579. const cloned = Object.create(NodePrototype);
  9580. cloned.type = type;
  9581. cloned.start = start;
  9582. cloned.end = end;
  9583. cloned.loc = loc;
  9584. cloned.range = range;
  9585. cloned.name = name;
  9586. if (node.extra) cloned.extra = node.extra;
  9587. return cloned;
  9588. }
  9589. cloneStringLiteral(node) {
  9590. const {
  9591. type,
  9592. start,
  9593. end,
  9594. loc,
  9595. range,
  9596. extra
  9597. } = node;
  9598. const cloned = Object.create(NodePrototype);
  9599. cloned.type = type;
  9600. cloned.start = start;
  9601. cloned.end = end;
  9602. cloned.loc = loc;
  9603. cloned.range = range;
  9604. cloned.extra = extra;
  9605. cloned.value = node.value;
  9606. return cloned;
  9607. }
  9608. }
  9609. const unwrapParenthesizedExpression = node => {
  9610. return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node;
  9611. };
  9612. class LValParser extends NodeUtils {
  9613. toAssignable(node, isLHS = false) {
  9614. var _node$extra, _node$extra3;
  9615. let parenthesized = undefined;
  9616. if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) {
  9617. parenthesized = unwrapParenthesizedExpression(node);
  9618. if (isLHS) {
  9619. if (parenthesized.type === "Identifier") {
  9620. this.expressionScope.recordArrowParameterBindingError(Errors.InvalidParenthesizedAssignment, node);
  9621. } else if (parenthesized.type !== "MemberExpression" && !this.isOptionalMemberExpression(parenthesized)) {
  9622. this.raise(Errors.InvalidParenthesizedAssignment, node);
  9623. }
  9624. } else {
  9625. this.raise(Errors.InvalidParenthesizedAssignment, node);
  9626. }
  9627. }
  9628. switch (node.type) {
  9629. case "Identifier":
  9630. case "ObjectPattern":
  9631. case "ArrayPattern":
  9632. case "AssignmentPattern":
  9633. case "RestElement":
  9634. case "VoidPattern":
  9635. break;
  9636. case "ObjectExpression":
  9637. this.castNodeTo(node, "ObjectPattern");
  9638. for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) {
  9639. var _node$extra2;
  9640. const prop = node.properties[i];
  9641. const isLast = i === last;
  9642. this.toAssignableObjectExpressionProp(prop, isLast, isLHS);
  9643. if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) {
  9644. this.raise(Errors.RestTrailingComma, node.extra.trailingCommaLoc);
  9645. }
  9646. }
  9647. break;
  9648. case "ObjectProperty":
  9649. {
  9650. const {
  9651. key,
  9652. value
  9653. } = node;
  9654. if (this.isPrivateName(key)) {
  9655. this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start);
  9656. }
  9657. this.toAssignable(value, isLHS);
  9658. break;
  9659. }
  9660. case "SpreadElement":
  9661. {
  9662. throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller.");
  9663. }
  9664. case "ArrayExpression":
  9665. this.castNodeTo(node, "ArrayPattern");
  9666. this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS);
  9667. break;
  9668. case "AssignmentExpression":
  9669. if (node.operator !== "=") {
  9670. this.raise(Errors.MissingEqInAssignment, node.left.loc.end);
  9671. }
  9672. this.castNodeTo(node, "AssignmentPattern");
  9673. delete node.operator;
  9674. if (node.left.type === "VoidPattern") {
  9675. this.raise(Errors.VoidPatternInitializer, node.left);
  9676. }
  9677. this.toAssignable(node.left, isLHS);
  9678. break;
  9679. case "ParenthesizedExpression":
  9680. this.toAssignable(parenthesized, isLHS);
  9681. break;
  9682. }
  9683. }
  9684. toAssignableObjectExpressionProp(prop, isLast, isLHS) {
  9685. if (prop.type === "ObjectMethod") {
  9686. this.raise(prop.kind === "get" || prop.kind === "set" ? Errors.PatternHasAccessor : Errors.PatternHasMethod, prop.key);
  9687. } else if (prop.type === "SpreadElement") {
  9688. this.castNodeTo(prop, "RestElement");
  9689. const arg = prop.argument;
  9690. this.checkToRestConversion(arg, false);
  9691. this.toAssignable(arg, isLHS);
  9692. if (!isLast) {
  9693. this.raise(Errors.RestTrailingComma, prop);
  9694. }
  9695. } else {
  9696. this.toAssignable(prop, isLHS);
  9697. }
  9698. }
  9699. toAssignableList(exprList, trailingCommaLoc, isLHS) {
  9700. const end = exprList.length - 1;
  9701. for (let i = 0; i <= end; i++) {
  9702. const elt = exprList[i];
  9703. if (!elt) continue;
  9704. this.toAssignableListItem(exprList, i, isLHS);
  9705. if (elt.type === "RestElement") {
  9706. if (i < end) {
  9707. this.raise(Errors.RestTrailingComma, elt);
  9708. } else if (trailingCommaLoc) {
  9709. this.raise(Errors.RestTrailingComma, trailingCommaLoc);
  9710. }
  9711. }
  9712. }
  9713. }
  9714. toAssignableListItem(exprList, index, isLHS) {
  9715. const node = exprList[index];
  9716. if (node.type === "SpreadElement") {
  9717. this.castNodeTo(node, "RestElement");
  9718. const arg = node.argument;
  9719. this.checkToRestConversion(arg, true);
  9720. this.toAssignable(arg, isLHS);
  9721. } else {
  9722. this.toAssignable(node, isLHS);
  9723. }
  9724. }
  9725. isAssignable(node, isBinding) {
  9726. switch (node.type) {
  9727. case "Identifier":
  9728. case "ObjectPattern":
  9729. case "ArrayPattern":
  9730. case "AssignmentPattern":
  9731. case "RestElement":
  9732. case "VoidPattern":
  9733. return true;
  9734. case "ObjectExpression":
  9735. {
  9736. const last = node.properties.length - 1;
  9737. return node.properties.every((prop, i) => {
  9738. return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop);
  9739. });
  9740. }
  9741. case "ObjectProperty":
  9742. return this.isAssignable(node.value);
  9743. case "SpreadElement":
  9744. return this.isAssignable(node.argument);
  9745. case "ArrayExpression":
  9746. return node.elements.every(element => element === null || this.isAssignable(element));
  9747. case "AssignmentExpression":
  9748. return node.operator === "=";
  9749. case "ParenthesizedExpression":
  9750. return this.isAssignable(node.expression);
  9751. case "MemberExpression":
  9752. case "OptionalMemberExpression":
  9753. return !isBinding;
  9754. default:
  9755. return false;
  9756. }
  9757. }
  9758. toReferencedList(exprList, isParenthesizedExpr) {
  9759. return exprList;
  9760. }
  9761. toReferencedListDeep(exprList, isParenthesizedExpr) {
  9762. this.toReferencedList(exprList, isParenthesizedExpr);
  9763. for (const expr of exprList) {
  9764. if ((expr == null ? void 0 : expr.type) === "ArrayExpression") {
  9765. this.toReferencedListDeep(expr.elements);
  9766. }
  9767. }
  9768. }
  9769. parseSpread(refExpressionErrors) {
  9770. const node = this.startNode();
  9771. this.next();
  9772. node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined);
  9773. return this.finishNode(node, "SpreadElement");
  9774. }
  9775. parseRestBinding() {
  9776. const node = this.startNode();
  9777. this.next();
  9778. const argument = this.parseBindingAtom();
  9779. if (argument.type === "VoidPattern") {
  9780. this.raise(Errors.UnexpectedVoidPattern, argument);
  9781. }
  9782. node.argument = argument;
  9783. return this.finishNode(node, "RestElement");
  9784. }
  9785. parseBindingAtom() {
  9786. switch (this.state.type) {
  9787. case 0:
  9788. {
  9789. const node = this.startNode();
  9790. this.next();
  9791. node.elements = this.parseBindingList(3, 93, 1);
  9792. return this.finishNode(node, "ArrayPattern");
  9793. }
  9794. case 5:
  9795. return this.parseObjectLike(8, true);
  9796. case 88:
  9797. return this.parseVoidPattern(null);
  9798. }
  9799. return this.parseIdentifier();
  9800. }
  9801. parseBindingList(close, closeCharCode, flags) {
  9802. const allowEmpty = flags & 1;
  9803. const elts = [];
  9804. let first = true;
  9805. while (!this.eat(close)) {
  9806. if (first) {
  9807. first = false;
  9808. } else {
  9809. this.expect(12);
  9810. }
  9811. if (allowEmpty && this.match(12)) {
  9812. elts.push(null);
  9813. } else if (this.eat(close)) {
  9814. break;
  9815. } else if (this.match(21)) {
  9816. let rest = this.parseRestBinding();
  9817. if (this.hasPlugin("flow") || flags & 2) {
  9818. rest = this.parseFunctionParamType(rest);
  9819. }
  9820. elts.push(rest);
  9821. if (!this.checkCommaAfterRest(closeCharCode)) {
  9822. this.expect(close);
  9823. break;
  9824. }
  9825. } else {
  9826. const decorators = [];
  9827. if (flags & 2) {
  9828. if (this.match(26) && this.hasPlugin("decorators")) {
  9829. this.raise(Errors.UnsupportedParameterDecorator, this.state.startLoc);
  9830. }
  9831. while (this.match(26)) {
  9832. decorators.push(this.parseDecorator());
  9833. }
  9834. }
  9835. elts.push(this.parseBindingElement(flags, decorators));
  9836. }
  9837. }
  9838. return elts;
  9839. }
  9840. parseBindingRestProperty(prop) {
  9841. this.next();
  9842. if (this.hasPlugin("discardBinding") && this.match(88)) {
  9843. prop.argument = this.parseVoidPattern(null);
  9844. this.raise(Errors.UnexpectedVoidPattern, prop.argument);
  9845. } else {
  9846. prop.argument = this.parseIdentifier();
  9847. }
  9848. this.checkCommaAfterRest(125);
  9849. return this.finishNode(prop, "RestElement");
  9850. }
  9851. parseBindingProperty() {
  9852. const {
  9853. type,
  9854. startLoc
  9855. } = this.state;
  9856. if (type === 21) {
  9857. return this.parseBindingRestProperty(this.startNode());
  9858. }
  9859. const prop = this.startNode();
  9860. if (type === 139) {
  9861. this.expectPlugin("destructuringPrivate", startLoc);
  9862. this.classScope.usePrivateName(this.state.value, startLoc);
  9863. prop.key = this.parsePrivateName();
  9864. } else {
  9865. this.parsePropertyName(prop);
  9866. }
  9867. prop.method = false;
  9868. return this.parseObjPropValue(prop, startLoc, false, false, true, false);
  9869. }
  9870. parseBindingElement(flags, decorators) {
  9871. const left = this.parseMaybeDefault();
  9872. if (this.hasPlugin("flow") || flags & 2) {
  9873. this.parseFunctionParamType(left);
  9874. }
  9875. if (decorators.length) {
  9876. left.decorators = decorators;
  9877. this.resetStartLocationFromNode(left, decorators[0]);
  9878. }
  9879. const elt = this.parseMaybeDefault(left.loc.start, left);
  9880. return elt;
  9881. }
  9882. parseFunctionParamType(param) {
  9883. return param;
  9884. }
  9885. parseMaybeDefault(startLoc, left) {
  9886. startLoc != null ? startLoc : startLoc = this.state.startLoc;
  9887. left = left != null ? left : this.parseBindingAtom();
  9888. if (!this.eat(29)) return left;
  9889. const node = this.startNodeAt(startLoc);
  9890. if (left.type === "VoidPattern") {
  9891. this.raise(Errors.VoidPatternInitializer, left);
  9892. }
  9893. node.left = left;
  9894. node.right = this.parseMaybeAssignAllowIn();
  9895. return this.finishNode(node, "AssignmentPattern");
  9896. }
  9897. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  9898. switch (type) {
  9899. case "AssignmentPattern":
  9900. return "left";
  9901. case "RestElement":
  9902. return "argument";
  9903. case "ObjectProperty":
  9904. return "value";
  9905. case "ParenthesizedExpression":
  9906. return "expression";
  9907. case "ArrayPattern":
  9908. return "elements";
  9909. case "ObjectPattern":
  9910. return "properties";
  9911. case "VoidPattern":
  9912. return true;
  9913. }
  9914. return false;
  9915. }
  9916. isOptionalMemberExpression(expression) {
  9917. return expression.type === "OptionalMemberExpression";
  9918. }
  9919. checkLVal(expression, ancestor, binding = 64, checkClashes = false, strictModeChanged = false, hasParenthesizedAncestor = false) {
  9920. var _expression$extra;
  9921. const type = expression.type;
  9922. if (this.isObjectMethod(expression)) return;
  9923. const isOptionalMemberExpression = this.isOptionalMemberExpression(expression);
  9924. if (isOptionalMemberExpression || type === "MemberExpression") {
  9925. if (isOptionalMemberExpression) {
  9926. this.expectPlugin("optionalChainingAssign", expression.loc.start);
  9927. if (ancestor.type !== "AssignmentExpression") {
  9928. this.raise(Errors.InvalidLhsOptionalChaining, expression, {
  9929. ancestor
  9930. });
  9931. }
  9932. }
  9933. if (binding !== 64) {
  9934. this.raise(Errors.InvalidPropertyBindingPattern, expression);
  9935. }
  9936. return;
  9937. }
  9938. if (type === "Identifier") {
  9939. this.checkIdentifier(expression, binding, strictModeChanged);
  9940. const {
  9941. name
  9942. } = expression;
  9943. if (checkClashes) {
  9944. if (checkClashes.has(name)) {
  9945. this.raise(Errors.ParamDupe, expression);
  9946. } else {
  9947. checkClashes.add(name);
  9948. }
  9949. }
  9950. return;
  9951. } else if (type === "VoidPattern" && ancestor.type === "CatchClause") {
  9952. this.raise(Errors.VoidPatternCatchClauseParam, expression);
  9953. }
  9954. const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding);
  9955. if (validity === true) return;
  9956. if (validity === false) {
  9957. const ParseErrorClass = binding === 64 ? Errors.InvalidLhs : Errors.InvalidLhsBinding;
  9958. this.raise(ParseErrorClass, expression, {
  9959. ancestor
  9960. });
  9961. return;
  9962. }
  9963. let key, isParenthesizedExpression;
  9964. if (typeof validity === "string") {
  9965. key = validity;
  9966. isParenthesizedExpression = type === "ParenthesizedExpression";
  9967. } else {
  9968. [key, isParenthesizedExpression] = validity;
  9969. }
  9970. const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" ? {
  9971. type
  9972. } : ancestor;
  9973. const val = expression[key];
  9974. if (Array.isArray(val)) {
  9975. for (const child of val) {
  9976. if (child) {
  9977. this.checkLVal(child, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  9978. }
  9979. }
  9980. } else if (val) {
  9981. this.checkLVal(val, nextAncestor, binding, checkClashes, strictModeChanged, isParenthesizedExpression);
  9982. }
  9983. }
  9984. checkIdentifier(at, bindingType, strictModeChanged = false) {
  9985. if (this.state.strict && (strictModeChanged ? isStrictBindReservedWord(at.name, this.inModule) : isStrictBindOnlyReservedWord(at.name))) {
  9986. if (bindingType === 64) {
  9987. this.raise(Errors.StrictEvalArguments, at, {
  9988. referenceName: at.name
  9989. });
  9990. } else {
  9991. this.raise(Errors.StrictEvalArgumentsBinding, at, {
  9992. bindingName: at.name
  9993. });
  9994. }
  9995. }
  9996. if (bindingType & 8192 && at.name === "let") {
  9997. this.raise(Errors.LetInLexicalBinding, at);
  9998. }
  9999. if (!(bindingType & 64)) {
  10000. this.declareNameFromIdentifier(at, bindingType);
  10001. }
  10002. }
  10003. declareNameFromIdentifier(identifier, binding) {
  10004. this.scope.declareName(identifier.name, binding, identifier.loc.start);
  10005. }
  10006. checkToRestConversion(node, allowPattern) {
  10007. switch (node.type) {
  10008. case "ParenthesizedExpression":
  10009. this.checkToRestConversion(node.expression, allowPattern);
  10010. break;
  10011. case "Identifier":
  10012. case "MemberExpression":
  10013. break;
  10014. case "ArrayExpression":
  10015. case "ObjectExpression":
  10016. if (allowPattern) break;
  10017. default:
  10018. this.raise(Errors.InvalidRestAssignmentPattern, node);
  10019. }
  10020. }
  10021. checkCommaAfterRest(close) {
  10022. if (!this.match(12)) {
  10023. return false;
  10024. }
  10025. this.raise(this.lookaheadCharCode() === close ? Errors.RestTrailingComma : Errors.ElementAfterRest, this.state.startLoc);
  10026. return true;
  10027. }
  10028. }
  10029. function nonNull(x) {
  10030. if (x == null) {
  10031. throw new Error(`Unexpected ${x} value.`);
  10032. }
  10033. return x;
  10034. }
  10035. function assert(x) {
  10036. if (!x) {
  10037. throw new Error("Assert fail");
  10038. }
  10039. }
  10040. const TSErrors = ParseErrorEnum`typescript`({
  10041. AbstractMethodHasImplementation: ({
  10042. methodName
  10043. }) => `Method '${methodName}' cannot have an implementation because it is marked abstract.`,
  10044. AbstractPropertyHasInitializer: ({
  10045. propertyName
  10046. }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
  10047. AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.",
  10048. AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.",
  10049. AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.",
  10050. ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.",
  10051. ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.",
  10052. ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.",
  10053. ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.",
  10054. DeclareAccessor: ({
  10055. kind
  10056. }) => `'declare' is not allowed in ${kind}ters.`,
  10057. DeclareClassFieldHasInitializer: "Initializers are not allowed in ambient contexts.",
  10058. DeclareFunctionHasImplementation: "An implementation cannot be declared in ambient contexts.",
  10059. DuplicateAccessibilityModifier: ({
  10060. modifier
  10061. }) => `Accessibility modifier already seen: '${modifier}'.`,
  10062. DuplicateModifier: ({
  10063. modifier
  10064. }) => `Duplicate modifier: '${modifier}'.`,
  10065. EmptyHeritageClauseType: ({
  10066. token
  10067. }) => `'${token}' list cannot be empty.`,
  10068. EmptyTypeArguments: "Type argument list cannot be empty.",
  10069. EmptyTypeParameters: "Type parameter list cannot be empty.",
  10070. ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.",
  10071. ImportAliasHasImportType: "An import alias can not use 'import type'.",
  10072. ImportReflectionHasImportType: "An `import module` declaration can not use `type` modifier",
  10073. IncompatibleModifiers: ({
  10074. modifiers
  10075. }) => `'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
  10076. IndexSignatureHasAbstract: "Index signatures cannot have the 'abstract' modifier.",
  10077. IndexSignatureHasAccessibility: ({
  10078. modifier
  10079. }) => `Index signatures cannot have an accessibility modifier ('${modifier}').`,
  10080. IndexSignatureHasDeclare: "Index signatures cannot have the 'declare' modifier.",
  10081. IndexSignatureHasOverride: "'override' modifier cannot appear on an index signature.",
  10082. IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier.",
  10083. InitializerNotAllowedInAmbientContext: "Initializers are not allowed in ambient contexts.",
  10084. InvalidHeritageClauseType: ({
  10085. token
  10086. }) => `'${token}' list can only include identifiers or qualified-names with optional type arguments.`,
  10087. InvalidModifierOnAwaitUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on an await using declaration.`,
  10088. InvalidModifierOnTypeMember: ({
  10089. modifier
  10090. }) => `'${modifier}' modifier cannot appear on a type member.`,
  10091. InvalidModifierOnTypeParameter: ({
  10092. modifier
  10093. }) => `'${modifier}' modifier cannot appear on a type parameter.`,
  10094. InvalidModifierOnTypeParameterPositions: ({
  10095. modifier
  10096. }) => `'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
  10097. InvalidModifierOnUsingDeclaration: modifier => `'${modifier}' modifier cannot appear on a using declaration.`,
  10098. InvalidModifiersOrder: ({
  10099. orderedModifiers
  10100. }) => `'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
  10101. InvalidPropertyAccessAfterInstantiationExpression: "Invalid property access after an instantiation expression. " + "You can either wrap the instantiation expression in parentheses, or delete the type arguments.",
  10102. InvalidTupleMemberLabel: "Tuple members must be labeled with a simple identifier.",
  10103. MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
  10104. NonAbstractClassHasAbstractMethod: "Abstract methods can only appear within an abstract class.",
  10105. NonClassMethodPropertyHasAbstractModifier: "'abstract' modifier can only appear on a class, method, or property declaration.",
  10106. OptionalTypeBeforeRequired: "A required element cannot follow an optional element.",
  10107. OverrideNotInSubClass: "This member cannot have an 'override' modifier because its containing class does not extend another class.",
  10108. PatternIsOptional: "A binding pattern parameter cannot be optional in an implementation signature.",
  10109. PrivateElementHasAbstract: "Private elements cannot have the 'abstract' modifier.",
  10110. PrivateElementHasAccessibility: ({
  10111. modifier
  10112. }) => `Private elements cannot have an accessibility modifier ('${modifier}').`,
  10113. ReadonlyForMethodSignature: "'readonly' modifier can only appear on a property declaration or index signature.",
  10114. ReservedArrowTypeParam: "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.",
  10115. ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.",
  10116. SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.",
  10117. SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.",
  10118. SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.",
  10119. SingleTypeParameterWithoutTrailingComma: ({
  10120. typeParameterName
  10121. }) => `Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
  10122. StaticBlockCannotHaveModifier: "Static class blocks cannot have any modifier.",
  10123. 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?`).",
  10124. TypeAnnotationAfterAssign: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.",
  10125. TypeImportCannotSpecifyDefaultAndNamed: "A type-only import can specify a default import or named bindings, but not both.",
  10126. TypeModifierIsUsedInTypeExports: "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.",
  10127. TypeModifierIsUsedInTypeImports: "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.",
  10128. UnexpectedParameterModifier: "A parameter property is only allowed in a constructor implementation.",
  10129. UnexpectedReadonly: "'readonly' type modifier is only permitted on array and tuple literal types.",
  10130. UnexpectedTypeAnnotation: "Did not expect a type annotation here.",
  10131. UnexpectedTypeCastInParameter: "Unexpected type cast in parameter position.",
  10132. UnsupportedImportTypeArgument: "Argument in a type import must be a string literal.",
  10133. UnsupportedParameterPropertyKind: "A parameter property may not be declared using a binding pattern.",
  10134. UnsupportedSignatureParameterKind: ({
  10135. type
  10136. }) => `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`,
  10137. UsingDeclarationInAmbientContext: kind => `'${kind}' declarations are not allowed in ambient contexts.`
  10138. });
  10139. function keywordTypeFromName(value) {
  10140. switch (value) {
  10141. case "any":
  10142. return "TSAnyKeyword";
  10143. case "boolean":
  10144. return "TSBooleanKeyword";
  10145. case "bigint":
  10146. return "TSBigIntKeyword";
  10147. case "never":
  10148. return "TSNeverKeyword";
  10149. case "number":
  10150. return "TSNumberKeyword";
  10151. case "object":
  10152. return "TSObjectKeyword";
  10153. case "string":
  10154. return "TSStringKeyword";
  10155. case "symbol":
  10156. return "TSSymbolKeyword";
  10157. case "undefined":
  10158. return "TSUndefinedKeyword";
  10159. case "unknown":
  10160. return "TSUnknownKeyword";
  10161. default:
  10162. return undefined;
  10163. }
  10164. }
  10165. function tsIsAccessModifier(modifier) {
  10166. return modifier === "private" || modifier === "public" || modifier === "protected";
  10167. }
  10168. function tsIsVarianceAnnotations(modifier) {
  10169. return modifier === "in" || modifier === "out";
  10170. }
  10171. var typescript = superClass => class TypeScriptParserMixin extends superClass {
  10172. constructor(...args) {
  10173. super(...args);
  10174. this.tsParseInOutModifiers = this.tsParseModifiers.bind(this, {
  10175. allowedModifiers: ["in", "out"],
  10176. disallowedModifiers: ["const", "public", "private", "protected", "readonly", "declare", "abstract", "override"],
  10177. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  10178. });
  10179. this.tsParseConstModifier = this.tsParseModifiers.bind(this, {
  10180. allowedModifiers: ["const"],
  10181. disallowedModifiers: ["in", "out"],
  10182. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  10183. });
  10184. this.tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, {
  10185. allowedModifiers: ["in", "out", "const"],
  10186. disallowedModifiers: ["public", "private", "protected", "readonly", "declare", "abstract", "override"],
  10187. errorTemplate: TSErrors.InvalidModifierOnTypeParameter
  10188. });
  10189. }
  10190. getScopeHandler() {
  10191. return TypeScriptScopeHandler;
  10192. }
  10193. tsIsIdentifier() {
  10194. return tokenIsIdentifier(this.state.type);
  10195. }
  10196. tsTokenCanFollowModifier() {
  10197. return this.match(0) || this.match(5) || this.match(55) || this.match(21) || this.match(139) || this.isLiteralPropertyName();
  10198. }
  10199. tsNextTokenOnSameLineAndCanFollowModifier() {
  10200. this.next();
  10201. if (this.hasPrecedingLineBreak()) {
  10202. return false;
  10203. }
  10204. return this.tsTokenCanFollowModifier();
  10205. }
  10206. tsNextTokenCanFollowModifier() {
  10207. if (this.match(106)) {
  10208. this.next();
  10209. return this.tsTokenCanFollowModifier();
  10210. }
  10211. return this.tsNextTokenOnSameLineAndCanFollowModifier();
  10212. }
  10213. tsParseModifier(allowedModifiers, stopOnStartOfClassStaticBlock, hasSeenStaticModifier) {
  10214. if (!tokenIsIdentifier(this.state.type) && this.state.type !== 58 && this.state.type !== 75) {
  10215. return undefined;
  10216. }
  10217. const modifier = this.state.value;
  10218. if (allowedModifiers.includes(modifier)) {
  10219. if (hasSeenStaticModifier && this.match(106)) {
  10220. return undefined;
  10221. }
  10222. if (stopOnStartOfClassStaticBlock && this.tsIsStartOfStaticBlocks()) {
  10223. return undefined;
  10224. }
  10225. if (this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this))) {
  10226. return modifier;
  10227. }
  10228. }
  10229. return undefined;
  10230. }
  10231. tsParseModifiers({
  10232. allowedModifiers,
  10233. disallowedModifiers,
  10234. stopOnStartOfClassStaticBlock,
  10235. errorTemplate = TSErrors.InvalidModifierOnTypeMember
  10236. }, modified) {
  10237. const enforceOrder = (loc, modifier, before, after) => {
  10238. if (modifier === before && modified[after]) {
  10239. this.raise(TSErrors.InvalidModifiersOrder, loc, {
  10240. orderedModifiers: [before, after]
  10241. });
  10242. }
  10243. };
  10244. const incompatible = (loc, modifier, mod1, mod2) => {
  10245. if (modified[mod1] && modifier === mod2 || modified[mod2] && modifier === mod1) {
  10246. this.raise(TSErrors.IncompatibleModifiers, loc, {
  10247. modifiers: [mod1, mod2]
  10248. });
  10249. }
  10250. };
  10251. for (;;) {
  10252. const {
  10253. startLoc
  10254. } = this.state;
  10255. const modifier = this.tsParseModifier(allowedModifiers.concat(disallowedModifiers != null ? disallowedModifiers : []), stopOnStartOfClassStaticBlock, modified.static);
  10256. if (!modifier) break;
  10257. if (tsIsAccessModifier(modifier)) {
  10258. if (modified.accessibility) {
  10259. this.raise(TSErrors.DuplicateAccessibilityModifier, startLoc, {
  10260. modifier
  10261. });
  10262. } else {
  10263. enforceOrder(startLoc, modifier, modifier, "override");
  10264. enforceOrder(startLoc, modifier, modifier, "static");
  10265. enforceOrder(startLoc, modifier, modifier, "readonly");
  10266. modified.accessibility = modifier;
  10267. }
  10268. } else if (tsIsVarianceAnnotations(modifier)) {
  10269. if (modified[modifier]) {
  10270. this.raise(TSErrors.DuplicateModifier, startLoc, {
  10271. modifier
  10272. });
  10273. }
  10274. modified[modifier] = true;
  10275. enforceOrder(startLoc, modifier, "in", "out");
  10276. } else {
  10277. if (hasOwnProperty.call(modified, modifier)) {
  10278. this.raise(TSErrors.DuplicateModifier, startLoc, {
  10279. modifier
  10280. });
  10281. } else {
  10282. enforceOrder(startLoc, modifier, "static", "readonly");
  10283. enforceOrder(startLoc, modifier, "static", "override");
  10284. enforceOrder(startLoc, modifier, "override", "readonly");
  10285. enforceOrder(startLoc, modifier, "abstract", "override");
  10286. incompatible(startLoc, modifier, "declare", "override");
  10287. incompatible(startLoc, modifier, "static", "abstract");
  10288. }
  10289. modified[modifier] = true;
  10290. }
  10291. if (disallowedModifiers != null && disallowedModifiers.includes(modifier)) {
  10292. this.raise(errorTemplate, startLoc, {
  10293. modifier
  10294. });
  10295. }
  10296. }
  10297. }
  10298. tsIsListTerminator(kind) {
  10299. switch (kind) {
  10300. case "EnumMembers":
  10301. case "TypeMembers":
  10302. return this.match(8);
  10303. case "HeritageClauseElement":
  10304. return this.match(5);
  10305. case "TupleElementTypes":
  10306. return this.match(3);
  10307. case "TypeParametersOrArguments":
  10308. return this.match(48);
  10309. }
  10310. }
  10311. tsParseList(kind, parseElement) {
  10312. const result = [];
  10313. while (!this.tsIsListTerminator(kind)) {
  10314. result.push(parseElement());
  10315. }
  10316. return result;
  10317. }
  10318. tsParseDelimitedList(kind, parseElement, refTrailingCommaPos) {
  10319. return nonNull(this.tsParseDelimitedListWorker(kind, parseElement, true, refTrailingCommaPos));
  10320. }
  10321. tsParseDelimitedListWorker(kind, parseElement, expectSuccess, refTrailingCommaPos) {
  10322. const result = [];
  10323. let trailingCommaPos = -1;
  10324. for (;;) {
  10325. if (this.tsIsListTerminator(kind)) {
  10326. break;
  10327. }
  10328. trailingCommaPos = -1;
  10329. const element = parseElement();
  10330. if (element == null) {
  10331. return undefined;
  10332. }
  10333. result.push(element);
  10334. if (this.eat(12)) {
  10335. trailingCommaPos = this.state.lastTokStartLoc.index;
  10336. continue;
  10337. }
  10338. if (this.tsIsListTerminator(kind)) {
  10339. break;
  10340. }
  10341. if (expectSuccess) {
  10342. this.expect(12);
  10343. }
  10344. return undefined;
  10345. }
  10346. if (refTrailingCommaPos) {
  10347. refTrailingCommaPos.value = trailingCommaPos;
  10348. }
  10349. return result;
  10350. }
  10351. tsParseBracketedList(kind, parseElement, bracket, skipFirstToken, refTrailingCommaPos) {
  10352. if (!skipFirstToken) {
  10353. if (bracket) {
  10354. this.expect(0);
  10355. } else {
  10356. this.expect(47);
  10357. }
  10358. }
  10359. const result = this.tsParseDelimitedList(kind, parseElement, refTrailingCommaPos);
  10360. if (bracket) {
  10361. this.expect(3);
  10362. } else {
  10363. this.expect(48);
  10364. }
  10365. return result;
  10366. }
  10367. tsParseImportType() {
  10368. const node = this.startNode();
  10369. this.expect(83);
  10370. this.expect(10);
  10371. if (!this.match(134)) {
  10372. this.raise(TSErrors.UnsupportedImportTypeArgument, this.state.startLoc);
  10373. {
  10374. node.argument = super.parseExprAtom();
  10375. }
  10376. } else {
  10377. {
  10378. node.argument = this.parseStringLiteral(this.state.value);
  10379. }
  10380. }
  10381. if (this.eat(12)) {
  10382. node.options = this.tsParseImportTypeOptions();
  10383. } else {
  10384. node.options = null;
  10385. }
  10386. this.expect(11);
  10387. if (this.eat(16)) {
  10388. node.qualifier = this.tsParseEntityName(1 | 2);
  10389. }
  10390. if (this.match(47)) {
  10391. {
  10392. node.typeParameters = this.tsParseTypeArguments();
  10393. }
  10394. }
  10395. return this.finishNode(node, "TSImportType");
  10396. }
  10397. tsParseImportTypeOptions() {
  10398. const node = this.startNode();
  10399. this.expect(5);
  10400. const withProperty = this.startNode();
  10401. if (this.isContextual(76)) {
  10402. withProperty.method = false;
  10403. withProperty.key = this.parseIdentifier(true);
  10404. withProperty.computed = false;
  10405. withProperty.shorthand = false;
  10406. } else {
  10407. this.unexpected(null, 76);
  10408. }
  10409. this.expect(14);
  10410. withProperty.value = this.tsParseImportTypeWithPropertyValue();
  10411. node.properties = [this.finishObjectProperty(withProperty)];
  10412. this.expect(8);
  10413. return this.finishNode(node, "ObjectExpression");
  10414. }
  10415. tsParseImportTypeWithPropertyValue() {
  10416. const node = this.startNode();
  10417. const properties = [];
  10418. this.expect(5);
  10419. while (!this.match(8)) {
  10420. const type = this.state.type;
  10421. if (tokenIsIdentifier(type) || type === 134) {
  10422. properties.push(super.parsePropertyDefinition(null));
  10423. } else {
  10424. this.unexpected();
  10425. }
  10426. this.eat(12);
  10427. }
  10428. node.properties = properties;
  10429. this.next();
  10430. return this.finishNode(node, "ObjectExpression");
  10431. }
  10432. tsParseEntityName(flags) {
  10433. let entity;
  10434. if (flags & 1 && this.match(78)) {
  10435. if (flags & 2) {
  10436. entity = this.parseIdentifier(true);
  10437. } else {
  10438. const node = this.startNode();
  10439. this.next();
  10440. entity = this.finishNode(node, "ThisExpression");
  10441. }
  10442. } else {
  10443. entity = this.parseIdentifier(!!(flags & 1));
  10444. }
  10445. while (this.eat(16)) {
  10446. const node = this.startNodeAtNode(entity);
  10447. node.left = entity;
  10448. node.right = this.parseIdentifier(!!(flags & 1));
  10449. entity = this.finishNode(node, "TSQualifiedName");
  10450. }
  10451. return entity;
  10452. }
  10453. tsParseTypeReference() {
  10454. const node = this.startNode();
  10455. node.typeName = this.tsParseEntityName(1);
  10456. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  10457. {
  10458. node.typeParameters = this.tsParseTypeArguments();
  10459. }
  10460. }
  10461. return this.finishNode(node, "TSTypeReference");
  10462. }
  10463. tsParseThisTypePredicate(lhs) {
  10464. this.next();
  10465. const node = this.startNodeAtNode(lhs);
  10466. node.parameterName = lhs;
  10467. node.typeAnnotation = this.tsParseTypeAnnotation(false);
  10468. node.asserts = false;
  10469. return this.finishNode(node, "TSTypePredicate");
  10470. }
  10471. tsParseThisTypeNode() {
  10472. const node = this.startNode();
  10473. this.next();
  10474. return this.finishNode(node, "TSThisType");
  10475. }
  10476. tsParseTypeQuery() {
  10477. const node = this.startNode();
  10478. this.expect(87);
  10479. if (this.match(83)) {
  10480. node.exprName = this.tsParseImportType();
  10481. } else {
  10482. {
  10483. node.exprName = this.tsParseEntityName(1 | 2);
  10484. }
  10485. }
  10486. if (!this.hasPrecedingLineBreak() && this.match(47)) {
  10487. {
  10488. node.typeParameters = this.tsParseTypeArguments();
  10489. }
  10490. }
  10491. return this.finishNode(node, "TSTypeQuery");
  10492. }
  10493. tsParseTypeParameter(parseModifiers) {
  10494. const node = this.startNode();
  10495. parseModifiers(node);
  10496. node.name = this.tsParseTypeParameterName();
  10497. node.constraint = this.tsEatThenParseType(81);
  10498. node.default = this.tsEatThenParseType(29);
  10499. return this.finishNode(node, "TSTypeParameter");
  10500. }
  10501. tsTryParseTypeParameters(parseModifiers) {
  10502. if (this.match(47)) {
  10503. return this.tsParseTypeParameters(parseModifiers);
  10504. }
  10505. }
  10506. tsParseTypeParameters(parseModifiers) {
  10507. const node = this.startNode();
  10508. if (this.match(47) || this.match(143)) {
  10509. this.next();
  10510. } else {
  10511. this.unexpected();
  10512. }
  10513. const refTrailingCommaPos = {
  10514. value: -1
  10515. };
  10516. node.params = this.tsParseBracketedList("TypeParametersOrArguments", this.tsParseTypeParameter.bind(this, parseModifiers), false, true, refTrailingCommaPos);
  10517. if (node.params.length === 0) {
  10518. this.raise(TSErrors.EmptyTypeParameters, node);
  10519. }
  10520. if (refTrailingCommaPos.value !== -1) {
  10521. this.addExtra(node, "trailingComma", refTrailingCommaPos.value);
  10522. }
  10523. return this.finishNode(node, "TSTypeParameterDeclaration");
  10524. }
  10525. tsFillSignature(returnToken, signature) {
  10526. const returnTokenRequired = returnToken === 19;
  10527. const paramsKey = "parameters";
  10528. const returnTypeKey = "typeAnnotation";
  10529. signature.typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  10530. this.expect(10);
  10531. signature[paramsKey] = this.tsParseBindingListForSignature();
  10532. if (returnTokenRequired) {
  10533. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  10534. } else if (this.match(returnToken)) {
  10535. signature[returnTypeKey] = this.tsParseTypeOrTypePredicateAnnotation(returnToken);
  10536. }
  10537. }
  10538. tsParseBindingListForSignature() {
  10539. const list = super.parseBindingList(11, 41, 2);
  10540. for (const pattern of list) {
  10541. const {
  10542. type
  10543. } = pattern;
  10544. if (type === "AssignmentPattern" || type === "TSParameterProperty") {
  10545. this.raise(TSErrors.UnsupportedSignatureParameterKind, pattern, {
  10546. type
  10547. });
  10548. }
  10549. }
  10550. return list;
  10551. }
  10552. tsParseTypeMemberSemicolon() {
  10553. if (!this.eat(12) && !this.isLineTerminator()) {
  10554. this.expect(13);
  10555. }
  10556. }
  10557. tsParseSignatureMember(kind, node) {
  10558. this.tsFillSignature(14, node);
  10559. this.tsParseTypeMemberSemicolon();
  10560. return this.finishNode(node, kind);
  10561. }
  10562. tsIsUnambiguouslyIndexSignature() {
  10563. this.next();
  10564. if (tokenIsIdentifier(this.state.type)) {
  10565. this.next();
  10566. return this.match(14);
  10567. }
  10568. return false;
  10569. }
  10570. tsTryParseIndexSignature(node) {
  10571. if (!(this.match(0) && this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)))) {
  10572. return;
  10573. }
  10574. this.expect(0);
  10575. const id = this.parseIdentifier();
  10576. id.typeAnnotation = this.tsParseTypeAnnotation();
  10577. this.resetEndLocation(id);
  10578. this.expect(3);
  10579. node.parameters = [id];
  10580. const type = this.tsTryParseTypeAnnotation();
  10581. if (type) node.typeAnnotation = type;
  10582. this.tsParseTypeMemberSemicolon();
  10583. return this.finishNode(node, "TSIndexSignature");
  10584. }
  10585. tsParsePropertyOrMethodSignature(node, readonly) {
  10586. if (this.eat(17)) node.optional = true;
  10587. if (this.match(10) || this.match(47)) {
  10588. if (readonly) {
  10589. this.raise(TSErrors.ReadonlyForMethodSignature, node);
  10590. }
  10591. const method = node;
  10592. if (method.kind && this.match(47)) {
  10593. this.raise(TSErrors.AccessorCannotHaveTypeParameters, this.state.curPosition());
  10594. }
  10595. this.tsFillSignature(14, method);
  10596. this.tsParseTypeMemberSemicolon();
  10597. const paramsKey = "parameters";
  10598. const returnTypeKey = "typeAnnotation";
  10599. if (method.kind === "get") {
  10600. if (method[paramsKey].length > 0) {
  10601. this.raise(Errors.BadGetterArity, this.state.curPosition());
  10602. if (this.isThisParam(method[paramsKey][0])) {
  10603. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  10604. }
  10605. }
  10606. } else if (method.kind === "set") {
  10607. if (method[paramsKey].length !== 1) {
  10608. this.raise(Errors.BadSetterArity, this.state.curPosition());
  10609. } else {
  10610. const firstParameter = method[paramsKey][0];
  10611. if (this.isThisParam(firstParameter)) {
  10612. this.raise(TSErrors.AccessorCannotDeclareThisParameter, this.state.curPosition());
  10613. }
  10614. if (firstParameter.type === "Identifier" && firstParameter.optional) {
  10615. this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, this.state.curPosition());
  10616. }
  10617. if (firstParameter.type === "RestElement") {
  10618. this.raise(TSErrors.SetAccessorCannotHaveRestParameter, this.state.curPosition());
  10619. }
  10620. }
  10621. if (method[returnTypeKey]) {
  10622. this.raise(TSErrors.SetAccessorCannotHaveReturnType, method[returnTypeKey]);
  10623. }
  10624. } else {
  10625. method.kind = "method";
  10626. }
  10627. return this.finishNode(method, "TSMethodSignature");
  10628. } else {
  10629. const property = node;
  10630. if (readonly) property.readonly = true;
  10631. const type = this.tsTryParseTypeAnnotation();
  10632. if (type) property.typeAnnotation = type;
  10633. this.tsParseTypeMemberSemicolon();
  10634. return this.finishNode(property, "TSPropertySignature");
  10635. }
  10636. }
  10637. tsParseTypeMember() {
  10638. const node = this.startNode();
  10639. if (this.match(10) || this.match(47)) {
  10640. return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
  10641. }
  10642. if (this.match(77)) {
  10643. const id = this.startNode();
  10644. this.next();
  10645. if (this.match(10) || this.match(47)) {
  10646. return this.tsParseSignatureMember("TSConstructSignatureDeclaration", node);
  10647. } else {
  10648. node.key = this.createIdentifier(id, "new");
  10649. return this.tsParsePropertyOrMethodSignature(node, false);
  10650. }
  10651. }
  10652. this.tsParseModifiers({
  10653. allowedModifiers: ["readonly"],
  10654. disallowedModifiers: ["declare", "abstract", "private", "protected", "public", "static", "override"]
  10655. }, node);
  10656. const idx = this.tsTryParseIndexSignature(node);
  10657. if (idx) {
  10658. return idx;
  10659. }
  10660. super.parsePropertyName(node);
  10661. if (!node.computed && node.key.type === "Identifier" && (node.key.name === "get" || node.key.name === "set") && this.tsTokenCanFollowModifier()) {
  10662. node.kind = node.key.name;
  10663. super.parsePropertyName(node);
  10664. if (!this.match(10) && !this.match(47)) {
  10665. this.unexpected(null, 10);
  10666. }
  10667. }
  10668. return this.tsParsePropertyOrMethodSignature(node, !!node.readonly);
  10669. }
  10670. tsParseTypeLiteral() {
  10671. const node = this.startNode();
  10672. node.members = this.tsParseObjectTypeMembers();
  10673. return this.finishNode(node, "TSTypeLiteral");
  10674. }
  10675. tsParseObjectTypeMembers() {
  10676. this.expect(5);
  10677. const members = this.tsParseList("TypeMembers", this.tsParseTypeMember.bind(this));
  10678. this.expect(8);
  10679. return members;
  10680. }
  10681. tsIsStartOfMappedType() {
  10682. this.next();
  10683. if (this.eat(53)) {
  10684. return this.isContextual(122);
  10685. }
  10686. if (this.isContextual(122)) {
  10687. this.next();
  10688. }
  10689. if (!this.match(0)) {
  10690. return false;
  10691. }
  10692. this.next();
  10693. if (!this.tsIsIdentifier()) {
  10694. return false;
  10695. }
  10696. this.next();
  10697. return this.match(58);
  10698. }
  10699. tsParseMappedType() {
  10700. const node = this.startNode();
  10701. this.expect(5);
  10702. if (this.match(53)) {
  10703. node.readonly = this.state.value;
  10704. this.next();
  10705. this.expectContextual(122);
  10706. } else if (this.eatContextual(122)) {
  10707. node.readonly = true;
  10708. }
  10709. this.expect(0);
  10710. {
  10711. const typeParameter = this.startNode();
  10712. typeParameter.name = this.tsParseTypeParameterName();
  10713. typeParameter.constraint = this.tsExpectThenParseType(58);
  10714. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  10715. }
  10716. node.nameType = this.eatContextual(93) ? this.tsParseType() : null;
  10717. this.expect(3);
  10718. if (this.match(53)) {
  10719. node.optional = this.state.value;
  10720. this.next();
  10721. this.expect(17);
  10722. } else if (this.eat(17)) {
  10723. node.optional = true;
  10724. }
  10725. node.typeAnnotation = this.tsTryParseType();
  10726. this.semicolon();
  10727. this.expect(8);
  10728. return this.finishNode(node, "TSMappedType");
  10729. }
  10730. tsParseTupleType() {
  10731. const node = this.startNode();
  10732. node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
  10733. let seenOptionalElement = false;
  10734. node.elementTypes.forEach(elementNode => {
  10735. const {
  10736. type
  10737. } = elementNode;
  10738. if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode.optional)) {
  10739. this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode);
  10740. }
  10741. seenOptionalElement || (seenOptionalElement = type === "TSNamedTupleMember" && elementNode.optional || type === "TSOptionalType");
  10742. });
  10743. return this.finishNode(node, "TSTupleType");
  10744. }
  10745. tsParseTupleElementType() {
  10746. const restStartLoc = this.state.startLoc;
  10747. const rest = this.eat(21);
  10748. const {
  10749. startLoc
  10750. } = this.state;
  10751. let labeled;
  10752. let label;
  10753. let optional;
  10754. let type;
  10755. const isWord = tokenIsKeywordOrIdentifier(this.state.type);
  10756. const chAfterWord = isWord ? this.lookaheadCharCode() : null;
  10757. if (chAfterWord === 58) {
  10758. labeled = true;
  10759. optional = false;
  10760. label = this.parseIdentifier(true);
  10761. this.expect(14);
  10762. type = this.tsParseType();
  10763. } else if (chAfterWord === 63) {
  10764. optional = true;
  10765. const wordName = this.state.value;
  10766. const typeOrLabel = this.tsParseNonArrayType();
  10767. if (this.lookaheadCharCode() === 58) {
  10768. labeled = true;
  10769. label = this.createIdentifier(this.startNodeAt(startLoc), wordName);
  10770. this.expect(17);
  10771. this.expect(14);
  10772. type = this.tsParseType();
  10773. } else {
  10774. labeled = false;
  10775. type = typeOrLabel;
  10776. this.expect(17);
  10777. }
  10778. } else {
  10779. type = this.tsParseType();
  10780. optional = this.eat(17);
  10781. labeled = this.eat(14);
  10782. }
  10783. if (labeled) {
  10784. let labeledNode;
  10785. if (label) {
  10786. labeledNode = this.startNodeAt(startLoc);
  10787. labeledNode.optional = optional;
  10788. labeledNode.label = label;
  10789. labeledNode.elementType = type;
  10790. if (this.eat(17)) {
  10791. labeledNode.optional = true;
  10792. this.raise(TSErrors.TupleOptionalAfterType, this.state.lastTokStartLoc);
  10793. }
  10794. } else {
  10795. labeledNode = this.startNodeAt(startLoc);
  10796. labeledNode.optional = optional;
  10797. this.raise(TSErrors.InvalidTupleMemberLabel, type);
  10798. labeledNode.label = type;
  10799. labeledNode.elementType = this.tsParseType();
  10800. }
  10801. type = this.finishNode(labeledNode, "TSNamedTupleMember");
  10802. } else if (optional) {
  10803. const optionalTypeNode = this.startNodeAt(startLoc);
  10804. optionalTypeNode.typeAnnotation = type;
  10805. type = this.finishNode(optionalTypeNode, "TSOptionalType");
  10806. }
  10807. if (rest) {
  10808. const restNode = this.startNodeAt(restStartLoc);
  10809. restNode.typeAnnotation = type;
  10810. type = this.finishNode(restNode, "TSRestType");
  10811. }
  10812. return type;
  10813. }
  10814. tsParseParenthesizedType() {
  10815. const node = this.startNode();
  10816. this.expect(10);
  10817. node.typeAnnotation = this.tsParseType();
  10818. this.expect(11);
  10819. return this.finishNode(node, "TSParenthesizedType");
  10820. }
  10821. tsParseFunctionOrConstructorType(type, abstract) {
  10822. const node = this.startNode();
  10823. if (type === "TSConstructorType") {
  10824. node.abstract = !!abstract;
  10825. if (abstract) this.next();
  10826. this.next();
  10827. }
  10828. this.tsInAllowConditionalTypesContext(() => this.tsFillSignature(19, node));
  10829. return this.finishNode(node, type);
  10830. }
  10831. tsParseLiteralTypeNode() {
  10832. const node = this.startNode();
  10833. switch (this.state.type) {
  10834. case 135:
  10835. case 136:
  10836. case 134:
  10837. case 85:
  10838. case 86:
  10839. node.literal = super.parseExprAtom();
  10840. break;
  10841. default:
  10842. this.unexpected();
  10843. }
  10844. return this.finishNode(node, "TSLiteralType");
  10845. }
  10846. tsParseTemplateLiteralType() {
  10847. {
  10848. const node = this.startNode();
  10849. node.literal = super.parseTemplate(false);
  10850. return this.finishNode(node, "TSLiteralType");
  10851. }
  10852. }
  10853. parseTemplateSubstitution() {
  10854. if (this.state.inType) return this.tsParseType();
  10855. return super.parseTemplateSubstitution();
  10856. }
  10857. tsParseThisTypeOrThisTypePredicate() {
  10858. const thisKeyword = this.tsParseThisTypeNode();
  10859. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  10860. return this.tsParseThisTypePredicate(thisKeyword);
  10861. } else {
  10862. return thisKeyword;
  10863. }
  10864. }
  10865. tsParseNonArrayType() {
  10866. switch (this.state.type) {
  10867. case 134:
  10868. case 135:
  10869. case 136:
  10870. case 85:
  10871. case 86:
  10872. return this.tsParseLiteralTypeNode();
  10873. case 53:
  10874. if (this.state.value === "-") {
  10875. const node = this.startNode();
  10876. const nextToken = this.lookahead();
  10877. if (nextToken.type !== 135 && nextToken.type !== 136) {
  10878. this.unexpected();
  10879. }
  10880. node.literal = this.parseMaybeUnary();
  10881. return this.finishNode(node, "TSLiteralType");
  10882. }
  10883. break;
  10884. case 78:
  10885. return this.tsParseThisTypeOrThisTypePredicate();
  10886. case 87:
  10887. return this.tsParseTypeQuery();
  10888. case 83:
  10889. return this.tsParseImportType();
  10890. case 5:
  10891. return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) ? this.tsParseMappedType() : this.tsParseTypeLiteral();
  10892. case 0:
  10893. return this.tsParseTupleType();
  10894. case 10:
  10895. return this.tsParseParenthesizedType();
  10896. case 25:
  10897. case 24:
  10898. return this.tsParseTemplateLiteralType();
  10899. default:
  10900. {
  10901. const {
  10902. type
  10903. } = this.state;
  10904. if (tokenIsIdentifier(type) || type === 88 || type === 84) {
  10905. const nodeType = type === 88 ? "TSVoidKeyword" : type === 84 ? "TSNullKeyword" : keywordTypeFromName(this.state.value);
  10906. if (nodeType !== undefined && this.lookaheadCharCode() !== 46) {
  10907. const node = this.startNode();
  10908. this.next();
  10909. return this.finishNode(node, nodeType);
  10910. }
  10911. return this.tsParseTypeReference();
  10912. }
  10913. }
  10914. }
  10915. this.unexpected();
  10916. }
  10917. tsParseArrayTypeOrHigher() {
  10918. const {
  10919. startLoc
  10920. } = this.state;
  10921. let type = this.tsParseNonArrayType();
  10922. while (!this.hasPrecedingLineBreak() && this.eat(0)) {
  10923. if (this.match(3)) {
  10924. const node = this.startNodeAt(startLoc);
  10925. node.elementType = type;
  10926. this.expect(3);
  10927. type = this.finishNode(node, "TSArrayType");
  10928. } else {
  10929. const node = this.startNodeAt(startLoc);
  10930. node.objectType = type;
  10931. node.indexType = this.tsParseType();
  10932. this.expect(3);
  10933. type = this.finishNode(node, "TSIndexedAccessType");
  10934. }
  10935. }
  10936. return type;
  10937. }
  10938. tsParseTypeOperator() {
  10939. const node = this.startNode();
  10940. const operator = this.state.value;
  10941. this.next();
  10942. node.operator = operator;
  10943. node.typeAnnotation = this.tsParseTypeOperatorOrHigher();
  10944. if (operator === "readonly") {
  10945. this.tsCheckTypeAnnotationForReadOnly(node);
  10946. }
  10947. return this.finishNode(node, "TSTypeOperator");
  10948. }
  10949. tsCheckTypeAnnotationForReadOnly(node) {
  10950. switch (node.typeAnnotation.type) {
  10951. case "TSTupleType":
  10952. case "TSArrayType":
  10953. return;
  10954. default:
  10955. this.raise(TSErrors.UnexpectedReadonly, node);
  10956. }
  10957. }
  10958. tsParseInferType() {
  10959. const node = this.startNode();
  10960. this.expectContextual(115);
  10961. const typeParameter = this.startNode();
  10962. typeParameter.name = this.tsParseTypeParameterName();
  10963. typeParameter.constraint = this.tsTryParse(() => this.tsParseConstraintForInferType());
  10964. node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
  10965. return this.finishNode(node, "TSInferType");
  10966. }
  10967. tsParseConstraintForInferType() {
  10968. if (this.eat(81)) {
  10969. const constraint = this.tsInDisallowConditionalTypesContext(() => this.tsParseType());
  10970. if (this.state.inDisallowConditionalTypesContext || !this.match(17)) {
  10971. return constraint;
  10972. }
  10973. }
  10974. }
  10975. tsParseTypeOperatorOrHigher() {
  10976. const isTypeOperator = tokenIsTSTypeOperator(this.state.type) && !this.state.containsEsc;
  10977. return isTypeOperator ? this.tsParseTypeOperator() : this.isContextual(115) ? this.tsParseInferType() : this.tsInAllowConditionalTypesContext(() => this.tsParseArrayTypeOrHigher());
  10978. }
  10979. tsParseUnionOrIntersectionType(kind, parseConstituentType, operator) {
  10980. const node = this.startNode();
  10981. const hasLeadingOperator = this.eat(operator);
  10982. const types = [];
  10983. do {
  10984. types.push(parseConstituentType());
  10985. } while (this.eat(operator));
  10986. if (types.length === 1 && !hasLeadingOperator) {
  10987. return types[0];
  10988. }
  10989. node.types = types;
  10990. return this.finishNode(node, kind);
  10991. }
  10992. tsParseIntersectionTypeOrHigher() {
  10993. return this.tsParseUnionOrIntersectionType("TSIntersectionType", this.tsParseTypeOperatorOrHigher.bind(this), 45);
  10994. }
  10995. tsParseUnionTypeOrHigher() {
  10996. return this.tsParseUnionOrIntersectionType("TSUnionType", this.tsParseIntersectionTypeOrHigher.bind(this), 43);
  10997. }
  10998. tsIsStartOfFunctionType() {
  10999. if (this.match(47)) {
  11000. return true;
  11001. }
  11002. return this.match(10) && this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this));
  11003. }
  11004. tsSkipParameterStart() {
  11005. if (tokenIsIdentifier(this.state.type) || this.match(78)) {
  11006. this.next();
  11007. return true;
  11008. }
  11009. if (this.match(5)) {
  11010. const {
  11011. errors
  11012. } = this.state;
  11013. const previousErrorCount = errors.length;
  11014. try {
  11015. this.parseObjectLike(8, true);
  11016. return errors.length === previousErrorCount;
  11017. } catch (_unused) {
  11018. return false;
  11019. }
  11020. }
  11021. if (this.match(0)) {
  11022. this.next();
  11023. const {
  11024. errors
  11025. } = this.state;
  11026. const previousErrorCount = errors.length;
  11027. try {
  11028. super.parseBindingList(3, 93, 1);
  11029. return errors.length === previousErrorCount;
  11030. } catch (_unused2) {
  11031. return false;
  11032. }
  11033. }
  11034. return false;
  11035. }
  11036. tsIsUnambiguouslyStartOfFunctionType() {
  11037. this.next();
  11038. if (this.match(11) || this.match(21)) {
  11039. return true;
  11040. }
  11041. if (this.tsSkipParameterStart()) {
  11042. if (this.match(14) || this.match(12) || this.match(17) || this.match(29)) {
  11043. return true;
  11044. }
  11045. if (this.match(11)) {
  11046. this.next();
  11047. if (this.match(19)) {
  11048. return true;
  11049. }
  11050. }
  11051. }
  11052. return false;
  11053. }
  11054. tsParseTypeOrTypePredicateAnnotation(returnToken) {
  11055. return this.tsInType(() => {
  11056. const t = this.startNode();
  11057. this.expect(returnToken);
  11058. const node = this.startNode();
  11059. const asserts = !!this.tsTryParse(this.tsParseTypePredicateAsserts.bind(this));
  11060. if (asserts && this.match(78)) {
  11061. let thisTypePredicate = this.tsParseThisTypeOrThisTypePredicate();
  11062. if (thisTypePredicate.type === "TSThisType") {
  11063. node.parameterName = thisTypePredicate;
  11064. node.asserts = true;
  11065. node.typeAnnotation = null;
  11066. thisTypePredicate = this.finishNode(node, "TSTypePredicate");
  11067. } else {
  11068. this.resetStartLocationFromNode(thisTypePredicate, node);
  11069. thisTypePredicate.asserts = true;
  11070. }
  11071. t.typeAnnotation = thisTypePredicate;
  11072. return this.finishNode(t, "TSTypeAnnotation");
  11073. }
  11074. const typePredicateVariable = this.tsIsIdentifier() && this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));
  11075. if (!typePredicateVariable) {
  11076. if (!asserts) {
  11077. return this.tsParseTypeAnnotation(false, t);
  11078. }
  11079. node.parameterName = this.parseIdentifier();
  11080. node.asserts = asserts;
  11081. node.typeAnnotation = null;
  11082. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  11083. return this.finishNode(t, "TSTypeAnnotation");
  11084. }
  11085. const type = this.tsParseTypeAnnotation(false);
  11086. node.parameterName = typePredicateVariable;
  11087. node.typeAnnotation = type;
  11088. node.asserts = asserts;
  11089. t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
  11090. return this.finishNode(t, "TSTypeAnnotation");
  11091. });
  11092. }
  11093. tsTryParseTypeOrTypePredicateAnnotation() {
  11094. if (this.match(14)) {
  11095. return this.tsParseTypeOrTypePredicateAnnotation(14);
  11096. }
  11097. }
  11098. tsTryParseTypeAnnotation() {
  11099. if (this.match(14)) {
  11100. return this.tsParseTypeAnnotation();
  11101. }
  11102. }
  11103. tsTryParseType() {
  11104. return this.tsEatThenParseType(14);
  11105. }
  11106. tsParseTypePredicatePrefix() {
  11107. const id = this.parseIdentifier();
  11108. if (this.isContextual(116) && !this.hasPrecedingLineBreak()) {
  11109. this.next();
  11110. return id;
  11111. }
  11112. }
  11113. tsParseTypePredicateAsserts() {
  11114. if (this.state.type !== 109) {
  11115. return false;
  11116. }
  11117. const containsEsc = this.state.containsEsc;
  11118. this.next();
  11119. if (!tokenIsIdentifier(this.state.type) && !this.match(78)) {
  11120. return false;
  11121. }
  11122. if (containsEsc) {
  11123. this.raise(Errors.InvalidEscapedReservedWord, this.state.lastTokStartLoc, {
  11124. reservedWord: "asserts"
  11125. });
  11126. }
  11127. return true;
  11128. }
  11129. tsParseTypeAnnotation(eatColon = true, t = this.startNode()) {
  11130. this.tsInType(() => {
  11131. if (eatColon) this.expect(14);
  11132. t.typeAnnotation = this.tsParseType();
  11133. });
  11134. return this.finishNode(t, "TSTypeAnnotation");
  11135. }
  11136. tsParseType() {
  11137. assert(this.state.inType);
  11138. const type = this.tsParseNonConditionalType();
  11139. if (this.state.inDisallowConditionalTypesContext || this.hasPrecedingLineBreak() || !this.eat(81)) {
  11140. return type;
  11141. }
  11142. const node = this.startNodeAtNode(type);
  11143. node.checkType = type;
  11144. node.extendsType = this.tsInDisallowConditionalTypesContext(() => this.tsParseNonConditionalType());
  11145. this.expect(17);
  11146. node.trueType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  11147. this.expect(14);
  11148. node.falseType = this.tsInAllowConditionalTypesContext(() => this.tsParseType());
  11149. return this.finishNode(node, "TSConditionalType");
  11150. }
  11151. isAbstractConstructorSignature() {
  11152. return this.isContextual(124) && this.isLookaheadContextual("new");
  11153. }
  11154. tsParseNonConditionalType() {
  11155. if (this.tsIsStartOfFunctionType()) {
  11156. return this.tsParseFunctionOrConstructorType("TSFunctionType");
  11157. }
  11158. if (this.match(77)) {
  11159. return this.tsParseFunctionOrConstructorType("TSConstructorType");
  11160. } else if (this.isAbstractConstructorSignature()) {
  11161. return this.tsParseFunctionOrConstructorType("TSConstructorType", true);
  11162. }
  11163. return this.tsParseUnionTypeOrHigher();
  11164. }
  11165. tsParseTypeAssertion() {
  11166. if (this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  11167. this.raise(TSErrors.ReservedTypeAssertion, this.state.startLoc);
  11168. }
  11169. const node = this.startNode();
  11170. node.typeAnnotation = this.tsInType(() => {
  11171. this.next();
  11172. return this.match(75) ? this.tsParseTypeReference() : this.tsParseType();
  11173. });
  11174. this.expect(48);
  11175. node.expression = this.parseMaybeUnary();
  11176. return this.finishNode(node, "TSTypeAssertion");
  11177. }
  11178. tsParseHeritageClause(token) {
  11179. const originalStartLoc = this.state.startLoc;
  11180. const delimitedList = this.tsParseDelimitedList("HeritageClauseElement", () => {
  11181. {
  11182. const node = this.startNode();
  11183. node.expression = this.tsParseEntityName(1 | 2);
  11184. if (this.match(47)) {
  11185. node.typeParameters = this.tsParseTypeArguments();
  11186. }
  11187. return this.finishNode(node, "TSExpressionWithTypeArguments");
  11188. }
  11189. });
  11190. if (!delimitedList.length) {
  11191. this.raise(TSErrors.EmptyHeritageClauseType, originalStartLoc, {
  11192. token
  11193. });
  11194. }
  11195. return delimitedList;
  11196. }
  11197. tsParseInterfaceDeclaration(node, properties = {}) {
  11198. if (this.hasFollowingLineBreak()) return null;
  11199. this.expectContextual(129);
  11200. if (properties.declare) node.declare = true;
  11201. if (tokenIsIdentifier(this.state.type)) {
  11202. node.id = this.parseIdentifier();
  11203. this.checkIdentifier(node.id, 130);
  11204. } else {
  11205. node.id = null;
  11206. this.raise(TSErrors.MissingInterfaceName, this.state.startLoc);
  11207. }
  11208. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  11209. if (this.eat(81)) {
  11210. node.extends = this.tsParseHeritageClause("extends");
  11211. }
  11212. const body = this.startNode();
  11213. body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
  11214. node.body = this.finishNode(body, "TSInterfaceBody");
  11215. return this.finishNode(node, "TSInterfaceDeclaration");
  11216. }
  11217. tsParseTypeAliasDeclaration(node) {
  11218. node.id = this.parseIdentifier();
  11219. this.checkIdentifier(node.id, 2);
  11220. node.typeAnnotation = this.tsInType(() => {
  11221. node.typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutModifiers);
  11222. this.expect(29);
  11223. if (this.isContextual(114) && this.lookaheadCharCode() !== 46) {
  11224. const node = this.startNode();
  11225. this.next();
  11226. return this.finishNode(node, "TSIntrinsicKeyword");
  11227. }
  11228. return this.tsParseType();
  11229. });
  11230. this.semicolon();
  11231. return this.finishNode(node, "TSTypeAliasDeclaration");
  11232. }
  11233. tsInTopLevelContext(cb) {
  11234. if (this.curContext() !== types.brace) {
  11235. const oldContext = this.state.context;
  11236. this.state.context = [oldContext[0]];
  11237. try {
  11238. return cb();
  11239. } finally {
  11240. this.state.context = oldContext;
  11241. }
  11242. } else {
  11243. return cb();
  11244. }
  11245. }
  11246. tsInType(cb) {
  11247. const oldInType = this.state.inType;
  11248. this.state.inType = true;
  11249. try {
  11250. return cb();
  11251. } finally {
  11252. this.state.inType = oldInType;
  11253. }
  11254. }
  11255. tsInDisallowConditionalTypesContext(cb) {
  11256. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  11257. this.state.inDisallowConditionalTypesContext = true;
  11258. try {
  11259. return cb();
  11260. } finally {
  11261. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  11262. }
  11263. }
  11264. tsInAllowConditionalTypesContext(cb) {
  11265. const oldInDisallowConditionalTypesContext = this.state.inDisallowConditionalTypesContext;
  11266. this.state.inDisallowConditionalTypesContext = false;
  11267. try {
  11268. return cb();
  11269. } finally {
  11270. this.state.inDisallowConditionalTypesContext = oldInDisallowConditionalTypesContext;
  11271. }
  11272. }
  11273. tsEatThenParseType(token) {
  11274. if (this.match(token)) {
  11275. return this.tsNextThenParseType();
  11276. }
  11277. }
  11278. tsExpectThenParseType(token) {
  11279. return this.tsInType(() => {
  11280. this.expect(token);
  11281. return this.tsParseType();
  11282. });
  11283. }
  11284. tsNextThenParseType() {
  11285. return this.tsInType(() => {
  11286. this.next();
  11287. return this.tsParseType();
  11288. });
  11289. }
  11290. tsParseEnumMember() {
  11291. const node = this.startNode();
  11292. node.id = this.match(134) ? super.parseStringLiteral(this.state.value) : this.parseIdentifier(true);
  11293. if (this.eat(29)) {
  11294. node.initializer = super.parseMaybeAssignAllowIn();
  11295. }
  11296. return this.finishNode(node, "TSEnumMember");
  11297. }
  11298. tsParseEnumDeclaration(node, properties = {}) {
  11299. if (properties.const) node.const = true;
  11300. if (properties.declare) node.declare = true;
  11301. this.expectContextual(126);
  11302. node.id = this.parseIdentifier();
  11303. this.checkIdentifier(node.id, node.const ? 8971 : 8459);
  11304. {
  11305. this.expect(5);
  11306. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  11307. this.expect(8);
  11308. }
  11309. return this.finishNode(node, "TSEnumDeclaration");
  11310. }
  11311. tsParseEnumBody() {
  11312. const node = this.startNode();
  11313. this.expect(5);
  11314. node.members = this.tsParseDelimitedList("EnumMembers", this.tsParseEnumMember.bind(this));
  11315. this.expect(8);
  11316. return this.finishNode(node, "TSEnumBody");
  11317. }
  11318. tsParseModuleBlock() {
  11319. const node = this.startNode();
  11320. this.scope.enter(0);
  11321. this.expect(5);
  11322. super.parseBlockOrModuleBlockBody(node.body = [], undefined, true, 8);
  11323. this.scope.exit();
  11324. return this.finishNode(node, "TSModuleBlock");
  11325. }
  11326. tsParseModuleOrNamespaceDeclaration(node, nested = false) {
  11327. node.id = this.parseIdentifier();
  11328. if (!nested) {
  11329. this.checkIdentifier(node.id, 1024);
  11330. }
  11331. if (this.eat(16)) {
  11332. const inner = this.startNode();
  11333. this.tsParseModuleOrNamespaceDeclaration(inner, true);
  11334. node.body = inner;
  11335. } else {
  11336. this.scope.enter(1024);
  11337. this.prodParam.enter(0);
  11338. node.body = this.tsParseModuleBlock();
  11339. this.prodParam.exit();
  11340. this.scope.exit();
  11341. }
  11342. return this.finishNode(node, "TSModuleDeclaration");
  11343. }
  11344. tsParseAmbientExternalModuleDeclaration(node) {
  11345. if (this.isContextual(112)) {
  11346. node.kind = "global";
  11347. {
  11348. node.global = true;
  11349. }
  11350. node.id = this.parseIdentifier();
  11351. } else if (this.match(134)) {
  11352. node.kind = "module";
  11353. node.id = super.parseStringLiteral(this.state.value);
  11354. } else {
  11355. this.unexpected();
  11356. }
  11357. if (this.match(5)) {
  11358. this.scope.enter(1024);
  11359. this.prodParam.enter(0);
  11360. node.body = this.tsParseModuleBlock();
  11361. this.prodParam.exit();
  11362. this.scope.exit();
  11363. } else {
  11364. this.semicolon();
  11365. }
  11366. return this.finishNode(node, "TSModuleDeclaration");
  11367. }
  11368. tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier, isExport) {
  11369. {
  11370. node.isExport = isExport || false;
  11371. }
  11372. node.id = maybeDefaultIdentifier || this.parseIdentifier();
  11373. this.checkIdentifier(node.id, 4096);
  11374. this.expect(29);
  11375. const moduleReference = this.tsParseModuleReference();
  11376. if (node.importKind === "type" && moduleReference.type !== "TSExternalModuleReference") {
  11377. this.raise(TSErrors.ImportAliasHasImportType, moduleReference);
  11378. }
  11379. node.moduleReference = moduleReference;
  11380. this.semicolon();
  11381. return this.finishNode(node, "TSImportEqualsDeclaration");
  11382. }
  11383. tsIsExternalModuleReference() {
  11384. return this.isContextual(119) && this.lookaheadCharCode() === 40;
  11385. }
  11386. tsParseModuleReference() {
  11387. return this.tsIsExternalModuleReference() ? this.tsParseExternalModuleReference() : this.tsParseEntityName(0);
  11388. }
  11389. tsParseExternalModuleReference() {
  11390. const node = this.startNode();
  11391. this.expectContextual(119);
  11392. this.expect(10);
  11393. if (!this.match(134)) {
  11394. this.unexpected();
  11395. }
  11396. node.expression = super.parseExprAtom();
  11397. this.expect(11);
  11398. this.sawUnambiguousESM = true;
  11399. return this.finishNode(node, "TSExternalModuleReference");
  11400. }
  11401. tsLookAhead(f) {
  11402. const state = this.state.clone();
  11403. const res = f();
  11404. this.state = state;
  11405. return res;
  11406. }
  11407. tsTryParseAndCatch(f) {
  11408. const result = this.tryParse(abort => f() || abort());
  11409. if (result.aborted || !result.node) return;
  11410. if (result.error) this.state = result.failState;
  11411. return result.node;
  11412. }
  11413. tsTryParse(f) {
  11414. const state = this.state.clone();
  11415. const result = f();
  11416. if (result !== undefined && result !== false) {
  11417. return result;
  11418. }
  11419. this.state = state;
  11420. }
  11421. tsTryParseDeclare(node) {
  11422. if (this.isLineTerminator()) {
  11423. return;
  11424. }
  11425. const startType = this.state.type;
  11426. return this.tsInAmbientContext(() => {
  11427. switch (startType) {
  11428. case 68:
  11429. node.declare = true;
  11430. return super.parseFunctionStatement(node, false, false);
  11431. case 80:
  11432. node.declare = true;
  11433. return this.parseClass(node, true, false);
  11434. case 126:
  11435. return this.tsParseEnumDeclaration(node, {
  11436. declare: true
  11437. });
  11438. case 112:
  11439. return this.tsParseAmbientExternalModuleDeclaration(node);
  11440. case 100:
  11441. if (this.state.containsEsc) {
  11442. return;
  11443. }
  11444. case 75:
  11445. case 74:
  11446. if (!this.match(75) || !this.isLookaheadContextual("enum")) {
  11447. node.declare = true;
  11448. return this.parseVarStatement(node, this.state.value, true);
  11449. }
  11450. this.expect(75);
  11451. return this.tsParseEnumDeclaration(node, {
  11452. const: true,
  11453. declare: true
  11454. });
  11455. case 107:
  11456. if (this.isUsing()) {
  11457. this.raise(TSErrors.InvalidModifierOnUsingDeclaration, this.state.startLoc, "declare");
  11458. node.declare = true;
  11459. return this.parseVarStatement(node, "using", true);
  11460. }
  11461. break;
  11462. case 96:
  11463. if (this.isAwaitUsing()) {
  11464. this.raise(TSErrors.InvalidModifierOnAwaitUsingDeclaration, this.state.startLoc, "declare");
  11465. node.declare = true;
  11466. this.next();
  11467. return this.parseVarStatement(node, "await using", true);
  11468. }
  11469. break;
  11470. case 129:
  11471. {
  11472. const result = this.tsParseInterfaceDeclaration(node, {
  11473. declare: true
  11474. });
  11475. if (result) return result;
  11476. }
  11477. default:
  11478. if (tokenIsIdentifier(startType)) {
  11479. return this.tsParseDeclaration(node, this.state.value, true, null);
  11480. }
  11481. }
  11482. });
  11483. }
  11484. tsTryParseExportDeclaration() {
  11485. return this.tsParseDeclaration(this.startNode(), this.state.value, true, null);
  11486. }
  11487. tsParseExpressionStatement(node, expr, decorators) {
  11488. switch (expr.name) {
  11489. case "declare":
  11490. {
  11491. const declaration = this.tsTryParseDeclare(node);
  11492. if (declaration) {
  11493. declaration.declare = true;
  11494. }
  11495. return declaration;
  11496. }
  11497. case "global":
  11498. if (this.match(5)) {
  11499. this.scope.enter(1024);
  11500. this.prodParam.enter(0);
  11501. const mod = node;
  11502. mod.kind = "global";
  11503. {
  11504. node.global = true;
  11505. }
  11506. mod.id = expr;
  11507. mod.body = this.tsParseModuleBlock();
  11508. this.scope.exit();
  11509. this.prodParam.exit();
  11510. return this.finishNode(mod, "TSModuleDeclaration");
  11511. }
  11512. break;
  11513. default:
  11514. return this.tsParseDeclaration(node, expr.name, false, decorators);
  11515. }
  11516. }
  11517. tsParseDeclaration(node, value, next, decorators) {
  11518. switch (value) {
  11519. case "abstract":
  11520. if (this.tsCheckLineTerminator(next) && (this.match(80) || tokenIsIdentifier(this.state.type))) {
  11521. return this.tsParseAbstractDeclaration(node, decorators);
  11522. }
  11523. break;
  11524. case "module":
  11525. if (this.tsCheckLineTerminator(next)) {
  11526. if (this.match(134)) {
  11527. return this.tsParseAmbientExternalModuleDeclaration(node);
  11528. } else if (tokenIsIdentifier(this.state.type)) {
  11529. node.kind = "module";
  11530. return this.tsParseModuleOrNamespaceDeclaration(node);
  11531. }
  11532. }
  11533. break;
  11534. case "namespace":
  11535. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  11536. node.kind = "namespace";
  11537. return this.tsParseModuleOrNamespaceDeclaration(node);
  11538. }
  11539. break;
  11540. case "type":
  11541. if (this.tsCheckLineTerminator(next) && tokenIsIdentifier(this.state.type)) {
  11542. return this.tsParseTypeAliasDeclaration(node);
  11543. }
  11544. break;
  11545. }
  11546. }
  11547. tsCheckLineTerminator(next) {
  11548. if (next) {
  11549. if (this.hasFollowingLineBreak()) return false;
  11550. this.next();
  11551. return true;
  11552. }
  11553. return !this.isLineTerminator();
  11554. }
  11555. tsTryParseGenericAsyncArrowFunction(startLoc) {
  11556. if (!this.match(47)) return;
  11557. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  11558. this.state.maybeInArrowParameters = true;
  11559. const res = this.tsTryParseAndCatch(() => {
  11560. const node = this.startNodeAt(startLoc);
  11561. node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  11562. super.parseFunctionParams(node);
  11563. node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation();
  11564. this.expect(19);
  11565. return node;
  11566. });
  11567. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  11568. if (!res) return;
  11569. return super.parseArrowExpression(res, null, true);
  11570. }
  11571. tsParseTypeArgumentsInExpression() {
  11572. if (this.reScan_lt() !== 47) return;
  11573. return this.tsParseTypeArguments();
  11574. }
  11575. tsParseTypeArguments() {
  11576. const node = this.startNode();
  11577. node.params = this.tsInType(() => this.tsInTopLevelContext(() => {
  11578. this.expect(47);
  11579. return this.tsParseDelimitedList("TypeParametersOrArguments", this.tsParseType.bind(this));
  11580. }));
  11581. if (node.params.length === 0) {
  11582. this.raise(TSErrors.EmptyTypeArguments, node);
  11583. } else if (!this.state.inType && this.curContext() === types.brace) {
  11584. this.reScan_lt_gt();
  11585. }
  11586. this.expect(48);
  11587. return this.finishNode(node, "TSTypeParameterInstantiation");
  11588. }
  11589. tsIsDeclarationStart() {
  11590. return tokenIsTSDeclarationStart(this.state.type);
  11591. }
  11592. isExportDefaultSpecifier() {
  11593. if (this.tsIsDeclarationStart()) return false;
  11594. return super.isExportDefaultSpecifier();
  11595. }
  11596. parseBindingElement(flags, decorators) {
  11597. const startLoc = decorators.length ? decorators[0].loc.start : this.state.startLoc;
  11598. const modified = {};
  11599. this.tsParseModifiers({
  11600. allowedModifiers: ["public", "private", "protected", "override", "readonly"]
  11601. }, modified);
  11602. const accessibility = modified.accessibility;
  11603. const override = modified.override;
  11604. const readonly = modified.readonly;
  11605. if (!(flags & 4) && (accessibility || readonly || override)) {
  11606. this.raise(TSErrors.UnexpectedParameterModifier, startLoc);
  11607. }
  11608. const left = this.parseMaybeDefault();
  11609. if (flags & 2) {
  11610. this.parseFunctionParamType(left);
  11611. }
  11612. const elt = this.parseMaybeDefault(left.loc.start, left);
  11613. if (accessibility || readonly || override) {
  11614. const pp = this.startNodeAt(startLoc);
  11615. if (decorators.length) {
  11616. pp.decorators = decorators;
  11617. }
  11618. if (accessibility) pp.accessibility = accessibility;
  11619. if (readonly) pp.readonly = readonly;
  11620. if (override) pp.override = override;
  11621. if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") {
  11622. this.raise(TSErrors.UnsupportedParameterPropertyKind, pp);
  11623. }
  11624. pp.parameter = elt;
  11625. return this.finishNode(pp, "TSParameterProperty");
  11626. }
  11627. if (decorators.length) {
  11628. left.decorators = decorators;
  11629. }
  11630. return elt;
  11631. }
  11632. isSimpleParameter(node) {
  11633. return node.type === "TSParameterProperty" && super.isSimpleParameter(node.parameter) || super.isSimpleParameter(node);
  11634. }
  11635. tsDisallowOptionalPattern(node) {
  11636. for (const param of node.params) {
  11637. if (param.type !== "Identifier" && param.optional && !this.state.isAmbientContext) {
  11638. this.raise(TSErrors.PatternIsOptional, param);
  11639. }
  11640. }
  11641. }
  11642. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  11643. super.setArrowFunctionParameters(node, params, trailingCommaLoc);
  11644. this.tsDisallowOptionalPattern(node);
  11645. }
  11646. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  11647. if (this.match(14)) {
  11648. node.returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  11649. }
  11650. const bodilessType = type === "FunctionDeclaration" ? "TSDeclareFunction" : type === "ClassMethod" || type === "ClassPrivateMethod" ? "TSDeclareMethod" : undefined;
  11651. if (bodilessType && !this.match(5) && this.isLineTerminator()) {
  11652. return this.finishNode(node, bodilessType);
  11653. }
  11654. if (bodilessType === "TSDeclareFunction" && this.state.isAmbientContext) {
  11655. this.raise(TSErrors.DeclareFunctionHasImplementation, node);
  11656. if (node.declare) {
  11657. return super.parseFunctionBodyAndFinish(node, bodilessType, isMethod);
  11658. }
  11659. }
  11660. this.tsDisallowOptionalPattern(node);
  11661. return super.parseFunctionBodyAndFinish(node, type, isMethod);
  11662. }
  11663. registerFunctionStatementId(node) {
  11664. if (!node.body && node.id) {
  11665. this.checkIdentifier(node.id, 1024);
  11666. } else {
  11667. super.registerFunctionStatementId(node);
  11668. }
  11669. }
  11670. tsCheckForInvalidTypeCasts(items) {
  11671. items.forEach(node => {
  11672. if ((node == null ? void 0 : node.type) === "TSTypeCastExpression") {
  11673. this.raise(TSErrors.UnexpectedTypeAnnotation, node.typeAnnotation);
  11674. }
  11675. });
  11676. }
  11677. toReferencedList(exprList, isInParens) {
  11678. this.tsCheckForInvalidTypeCasts(exprList);
  11679. return exprList;
  11680. }
  11681. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  11682. const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
  11683. if (node.type === "ArrayExpression") {
  11684. this.tsCheckForInvalidTypeCasts(node.elements);
  11685. }
  11686. return node;
  11687. }
  11688. parseSubscript(base, startLoc, noCalls, state) {
  11689. if (!this.hasPrecedingLineBreak() && this.match(35)) {
  11690. this.state.canStartJSXElement = false;
  11691. this.next();
  11692. const nonNullExpression = this.startNodeAt(startLoc);
  11693. nonNullExpression.expression = base;
  11694. return this.finishNode(nonNullExpression, "TSNonNullExpression");
  11695. }
  11696. let isOptionalCall = false;
  11697. if (this.match(18) && this.lookaheadCharCode() === 60) {
  11698. if (noCalls) {
  11699. state.stop = true;
  11700. return base;
  11701. }
  11702. state.optionalChainMember = isOptionalCall = true;
  11703. this.next();
  11704. }
  11705. if (this.match(47) || this.match(51)) {
  11706. let missingParenErrorLoc;
  11707. const result = this.tsTryParseAndCatch(() => {
  11708. if (!noCalls && this.atPossibleAsyncArrow(base)) {
  11709. const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
  11710. if (asyncArrowFn) {
  11711. return asyncArrowFn;
  11712. }
  11713. }
  11714. const typeArguments = this.tsParseTypeArgumentsInExpression();
  11715. if (!typeArguments) return;
  11716. if (isOptionalCall && !this.match(10)) {
  11717. missingParenErrorLoc = this.state.curPosition();
  11718. return;
  11719. }
  11720. if (tokenIsTemplate(this.state.type)) {
  11721. const result = super.parseTaggedTemplateExpression(base, startLoc, state);
  11722. {
  11723. result.typeParameters = typeArguments;
  11724. }
  11725. return result;
  11726. }
  11727. if (!noCalls && this.eat(10)) {
  11728. const node = this.startNodeAt(startLoc);
  11729. node.callee = base;
  11730. node.arguments = this.parseCallExpressionArguments();
  11731. this.tsCheckForInvalidTypeCasts(node.arguments);
  11732. {
  11733. node.typeParameters = typeArguments;
  11734. }
  11735. if (state.optionalChainMember) {
  11736. node.optional = isOptionalCall;
  11737. }
  11738. return this.finishCallExpression(node, state.optionalChainMember);
  11739. }
  11740. const tokenType = this.state.type;
  11741. if (tokenType === 48 || tokenType === 52 || tokenType !== 10 && tokenCanStartExpression(tokenType) && !this.hasPrecedingLineBreak()) {
  11742. return;
  11743. }
  11744. const node = this.startNodeAt(startLoc);
  11745. node.expression = base;
  11746. {
  11747. node.typeParameters = typeArguments;
  11748. }
  11749. return this.finishNode(node, "TSInstantiationExpression");
  11750. });
  11751. if (missingParenErrorLoc) {
  11752. this.unexpected(missingParenErrorLoc, 10);
  11753. }
  11754. if (result) {
  11755. if (result.type === "TSInstantiationExpression") {
  11756. if (this.match(16) || this.match(18) && this.lookaheadCharCode() !== 40) {
  11757. this.raise(TSErrors.InvalidPropertyAccessAfterInstantiationExpression, this.state.startLoc);
  11758. }
  11759. if (!this.match(16) && !this.match(18)) {
  11760. result.expression = super.stopParseSubscript(base, state);
  11761. }
  11762. }
  11763. return result;
  11764. }
  11765. }
  11766. return super.parseSubscript(base, startLoc, noCalls, state);
  11767. }
  11768. parseNewCallee(node) {
  11769. var _callee$extra;
  11770. super.parseNewCallee(node);
  11771. const {
  11772. callee
  11773. } = node;
  11774. if (callee.type === "TSInstantiationExpression" && !((_callee$extra = callee.extra) != null && _callee$extra.parenthesized)) {
  11775. {
  11776. node.typeParameters = callee.typeParameters;
  11777. }
  11778. node.callee = callee.expression;
  11779. }
  11780. }
  11781. parseExprOp(left, leftStartLoc, minPrec) {
  11782. let isSatisfies;
  11783. if (tokenOperatorPrecedence(58) > minPrec && !this.hasPrecedingLineBreak() && (this.isContextual(93) || (isSatisfies = this.isContextual(120)))) {
  11784. const node = this.startNodeAt(leftStartLoc);
  11785. node.expression = left;
  11786. node.typeAnnotation = this.tsInType(() => {
  11787. this.next();
  11788. if (this.match(75)) {
  11789. if (isSatisfies) {
  11790. this.raise(Errors.UnexpectedKeyword, this.state.startLoc, {
  11791. keyword: "const"
  11792. });
  11793. }
  11794. return this.tsParseTypeReference();
  11795. }
  11796. return this.tsParseType();
  11797. });
  11798. this.finishNode(node, isSatisfies ? "TSSatisfiesExpression" : "TSAsExpression");
  11799. this.reScan_lt_gt();
  11800. return this.parseExprOp(node, leftStartLoc, minPrec);
  11801. }
  11802. return super.parseExprOp(left, leftStartLoc, minPrec);
  11803. }
  11804. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  11805. if (!this.state.isAmbientContext) {
  11806. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  11807. }
  11808. }
  11809. checkImportReflection(node) {
  11810. super.checkImportReflection(node);
  11811. if (node.module && node.importKind !== "value") {
  11812. this.raise(TSErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
  11813. }
  11814. }
  11815. checkDuplicateExports() {}
  11816. isPotentialImportPhase(isExport) {
  11817. if (super.isPotentialImportPhase(isExport)) return true;
  11818. if (this.isContextual(130)) {
  11819. const ch = this.lookaheadCharCode();
  11820. return isExport ? ch === 123 || ch === 42 : ch !== 61;
  11821. }
  11822. return !isExport && this.isContextual(87);
  11823. }
  11824. applyImportPhase(node, isExport, phase, loc) {
  11825. super.applyImportPhase(node, isExport, phase, loc);
  11826. if (isExport) {
  11827. node.exportKind = phase === "type" ? "type" : "value";
  11828. } else {
  11829. node.importKind = phase === "type" || phase === "typeof" ? phase : "value";
  11830. }
  11831. }
  11832. parseImport(node) {
  11833. if (this.match(134)) {
  11834. node.importKind = "value";
  11835. return super.parseImport(node);
  11836. }
  11837. let importNode;
  11838. if (tokenIsIdentifier(this.state.type) && this.lookaheadCharCode() === 61) {
  11839. node.importKind = "value";
  11840. return this.tsParseImportEqualsDeclaration(node);
  11841. } else if (this.isContextual(130)) {
  11842. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, false);
  11843. if (this.lookaheadCharCode() === 61) {
  11844. return this.tsParseImportEqualsDeclaration(node, maybeDefaultIdentifier);
  11845. } else {
  11846. importNode = super.parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier);
  11847. }
  11848. } else {
  11849. importNode = super.parseImport(node);
  11850. }
  11851. if (importNode.importKind === "type" && importNode.specifiers.length > 1 && importNode.specifiers[0].type === "ImportDefaultSpecifier") {
  11852. this.raise(TSErrors.TypeImportCannotSpecifyDefaultAndNamed, importNode);
  11853. }
  11854. return importNode;
  11855. }
  11856. parseExport(node, decorators) {
  11857. if (this.match(83)) {
  11858. const nodeImportEquals = node;
  11859. this.next();
  11860. let maybeDefaultIdentifier = null;
  11861. if (this.isContextual(130) && this.isPotentialImportPhase(false)) {
  11862. maybeDefaultIdentifier = this.parseMaybeImportPhase(nodeImportEquals, false);
  11863. } else {
  11864. nodeImportEquals.importKind = "value";
  11865. }
  11866. const declaration = this.tsParseImportEqualsDeclaration(nodeImportEquals, maybeDefaultIdentifier, true);
  11867. {
  11868. return declaration;
  11869. }
  11870. } else if (this.eat(29)) {
  11871. const assign = node;
  11872. assign.expression = super.parseExpression();
  11873. this.semicolon();
  11874. this.sawUnambiguousESM = true;
  11875. return this.finishNode(assign, "TSExportAssignment");
  11876. } else if (this.eatContextual(93)) {
  11877. const decl = node;
  11878. this.expectContextual(128);
  11879. decl.id = this.parseIdentifier();
  11880. this.semicolon();
  11881. return this.finishNode(decl, "TSNamespaceExportDeclaration");
  11882. } else {
  11883. return super.parseExport(node, decorators);
  11884. }
  11885. }
  11886. isAbstractClass() {
  11887. return this.isContextual(124) && this.isLookaheadContextual("class");
  11888. }
  11889. parseExportDefaultExpression() {
  11890. if (this.isAbstractClass()) {
  11891. const cls = this.startNode();
  11892. this.next();
  11893. cls.abstract = true;
  11894. return this.parseClass(cls, true, true);
  11895. }
  11896. if (this.match(129)) {
  11897. const result = this.tsParseInterfaceDeclaration(this.startNode());
  11898. if (result) return result;
  11899. }
  11900. return super.parseExportDefaultExpression();
  11901. }
  11902. parseVarStatement(node, kind, allowMissingInitializer = false) {
  11903. const {
  11904. isAmbientContext
  11905. } = this.state;
  11906. const declaration = super.parseVarStatement(node, kind, allowMissingInitializer || isAmbientContext);
  11907. if (!isAmbientContext) return declaration;
  11908. if (!node.declare && (kind === "using" || kind === "await using")) {
  11909. this.raiseOverwrite(TSErrors.UsingDeclarationInAmbientContext, node, kind);
  11910. return declaration;
  11911. }
  11912. for (const {
  11913. id,
  11914. init
  11915. } of declaration.declarations) {
  11916. if (!init) continue;
  11917. if (kind === "var" || kind === "let" || !!id.typeAnnotation) {
  11918. this.raise(TSErrors.InitializerNotAllowedInAmbientContext, init);
  11919. } else if (!isValidAmbientConstInitializer(init, this.hasPlugin("estree"))) {
  11920. this.raise(TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, init);
  11921. }
  11922. }
  11923. return declaration;
  11924. }
  11925. parseStatementContent(flags, decorators) {
  11926. if (this.match(75) && this.isLookaheadContextual("enum")) {
  11927. const node = this.startNode();
  11928. this.expect(75);
  11929. return this.tsParseEnumDeclaration(node, {
  11930. const: true
  11931. });
  11932. }
  11933. if (this.isContextual(126)) {
  11934. return this.tsParseEnumDeclaration(this.startNode());
  11935. }
  11936. if (this.isContextual(129)) {
  11937. const result = this.tsParseInterfaceDeclaration(this.startNode());
  11938. if (result) return result;
  11939. }
  11940. return super.parseStatementContent(flags, decorators);
  11941. }
  11942. parseAccessModifier() {
  11943. return this.tsParseModifier(["public", "protected", "private"]);
  11944. }
  11945. tsHasSomeModifiers(member, modifiers) {
  11946. return modifiers.some(modifier => {
  11947. if (tsIsAccessModifier(modifier)) {
  11948. return member.accessibility === modifier;
  11949. }
  11950. return !!member[modifier];
  11951. });
  11952. }
  11953. tsIsStartOfStaticBlocks() {
  11954. return this.isContextual(106) && this.lookaheadCharCode() === 123;
  11955. }
  11956. parseClassMember(classBody, member, state) {
  11957. const modifiers = ["declare", "private", "public", "protected", "override", "abstract", "readonly", "static"];
  11958. this.tsParseModifiers({
  11959. allowedModifiers: modifiers,
  11960. disallowedModifiers: ["in", "out"],
  11961. stopOnStartOfClassStaticBlock: true,
  11962. errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions
  11963. }, member);
  11964. const callParseClassMemberWithIsStatic = () => {
  11965. if (this.tsIsStartOfStaticBlocks()) {
  11966. this.next();
  11967. this.next();
  11968. if (this.tsHasSomeModifiers(member, modifiers)) {
  11969. this.raise(TSErrors.StaticBlockCannotHaveModifier, this.state.curPosition());
  11970. }
  11971. super.parseClassStaticBlock(classBody, member);
  11972. } else {
  11973. this.parseClassMemberWithIsStatic(classBody, member, state, !!member.static);
  11974. }
  11975. };
  11976. if (member.declare) {
  11977. this.tsInAmbientContext(callParseClassMemberWithIsStatic);
  11978. } else {
  11979. callParseClassMemberWithIsStatic();
  11980. }
  11981. }
  11982. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  11983. const idx = this.tsTryParseIndexSignature(member);
  11984. if (idx) {
  11985. classBody.body.push(idx);
  11986. if (member.abstract) {
  11987. this.raise(TSErrors.IndexSignatureHasAbstract, member);
  11988. }
  11989. if (member.accessibility) {
  11990. this.raise(TSErrors.IndexSignatureHasAccessibility, member, {
  11991. modifier: member.accessibility
  11992. });
  11993. }
  11994. if (member.declare) {
  11995. this.raise(TSErrors.IndexSignatureHasDeclare, member);
  11996. }
  11997. if (member.override) {
  11998. this.raise(TSErrors.IndexSignatureHasOverride, member);
  11999. }
  12000. return;
  12001. }
  12002. if (!this.state.inAbstractClass && member.abstract) {
  12003. this.raise(TSErrors.NonAbstractClassHasAbstractMethod, member);
  12004. }
  12005. if (member.override) {
  12006. if (!state.hadSuperClass) {
  12007. this.raise(TSErrors.OverrideNotInSubClass, member);
  12008. }
  12009. }
  12010. super.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  12011. }
  12012. parsePostMemberNameModifiers(methodOrProp) {
  12013. const optional = this.eat(17);
  12014. if (optional) methodOrProp.optional = true;
  12015. if (methodOrProp.readonly && this.match(10)) {
  12016. this.raise(TSErrors.ClassMethodHasReadonly, methodOrProp);
  12017. }
  12018. if (methodOrProp.declare && this.match(10)) {
  12019. this.raise(TSErrors.ClassMethodHasDeclare, methodOrProp);
  12020. }
  12021. }
  12022. parseExpressionStatement(node, expr, decorators) {
  12023. const decl = expr.type === "Identifier" ? this.tsParseExpressionStatement(node, expr, decorators) : undefined;
  12024. return decl || super.parseExpressionStatement(node, expr, decorators);
  12025. }
  12026. shouldParseExportDeclaration() {
  12027. if (this.tsIsDeclarationStart()) return true;
  12028. return super.shouldParseExportDeclaration();
  12029. }
  12030. parseConditional(expr, startLoc, refExpressionErrors) {
  12031. if (!this.match(17)) return expr;
  12032. if (this.state.maybeInArrowParameters) {
  12033. const nextCh = this.lookaheadCharCode();
  12034. if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
  12035. this.setOptionalParametersError(refExpressionErrors);
  12036. return expr;
  12037. }
  12038. }
  12039. return super.parseConditional(expr, startLoc, refExpressionErrors);
  12040. }
  12041. parseParenItem(node, startLoc) {
  12042. const newNode = super.parseParenItem(node, startLoc);
  12043. if (this.eat(17)) {
  12044. newNode.optional = true;
  12045. this.resetEndLocation(node);
  12046. }
  12047. if (this.match(14)) {
  12048. const typeCastNode = this.startNodeAt(startLoc);
  12049. typeCastNode.expression = node;
  12050. typeCastNode.typeAnnotation = this.tsParseTypeAnnotation();
  12051. return this.finishNode(typeCastNode, "TSTypeCastExpression");
  12052. }
  12053. return node;
  12054. }
  12055. parseExportDeclaration(node) {
  12056. if (!this.state.isAmbientContext && this.isContextual(125)) {
  12057. return this.tsInAmbientContext(() => this.parseExportDeclaration(node));
  12058. }
  12059. const startLoc = this.state.startLoc;
  12060. const isDeclare = this.eatContextual(125);
  12061. if (isDeclare && (this.isContextual(125) || !this.shouldParseExportDeclaration())) {
  12062. throw this.raise(TSErrors.ExpectedAmbientAfterExportDeclare, this.state.startLoc);
  12063. }
  12064. const isIdentifier = tokenIsIdentifier(this.state.type);
  12065. const declaration = isIdentifier && this.tsTryParseExportDeclaration() || super.parseExportDeclaration(node);
  12066. if (!declaration) return null;
  12067. if (declaration.type === "TSInterfaceDeclaration" || declaration.type === "TSTypeAliasDeclaration" || isDeclare) {
  12068. node.exportKind = "type";
  12069. }
  12070. if (isDeclare && declaration.type !== "TSImportEqualsDeclaration") {
  12071. this.resetStartLocation(declaration, startLoc);
  12072. declaration.declare = true;
  12073. }
  12074. return declaration;
  12075. }
  12076. parseClassId(node, isStatement, optionalId, bindingType) {
  12077. if ((!isStatement || optionalId) && this.isContextual(113)) {
  12078. return;
  12079. }
  12080. super.parseClassId(node, isStatement, optionalId, node.declare ? 1024 : 8331);
  12081. const typeParameters = this.tsTryParseTypeParameters(this.tsParseInOutConstModifiers);
  12082. if (typeParameters) node.typeParameters = typeParameters;
  12083. }
  12084. parseClassPropertyAnnotation(node) {
  12085. if (!node.optional) {
  12086. if (this.eat(35)) {
  12087. node.definite = true;
  12088. } else if (this.eat(17)) {
  12089. node.optional = true;
  12090. }
  12091. }
  12092. const type = this.tsTryParseTypeAnnotation();
  12093. if (type) node.typeAnnotation = type;
  12094. }
  12095. parseClassProperty(node) {
  12096. this.parseClassPropertyAnnotation(node);
  12097. if (this.state.isAmbientContext && !(node.readonly && !node.typeAnnotation) && this.match(29)) {
  12098. this.raise(TSErrors.DeclareClassFieldHasInitializer, this.state.startLoc);
  12099. }
  12100. if (node.abstract && this.match(29)) {
  12101. const {
  12102. key
  12103. } = node;
  12104. this.raise(TSErrors.AbstractPropertyHasInitializer, this.state.startLoc, {
  12105. propertyName: key.type === "Identifier" && !node.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  12106. });
  12107. }
  12108. return super.parseClassProperty(node);
  12109. }
  12110. parseClassPrivateProperty(node) {
  12111. if (node.abstract) {
  12112. this.raise(TSErrors.PrivateElementHasAbstract, node);
  12113. }
  12114. if (node.accessibility) {
  12115. this.raise(TSErrors.PrivateElementHasAccessibility, node, {
  12116. modifier: node.accessibility
  12117. });
  12118. }
  12119. this.parseClassPropertyAnnotation(node);
  12120. return super.parseClassPrivateProperty(node);
  12121. }
  12122. parseClassAccessorProperty(node) {
  12123. this.parseClassPropertyAnnotation(node);
  12124. if (node.optional) {
  12125. this.raise(TSErrors.AccessorCannotBeOptional, node);
  12126. }
  12127. return super.parseClassAccessorProperty(node);
  12128. }
  12129. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  12130. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12131. if (typeParameters && isConstructor) {
  12132. this.raise(TSErrors.ConstructorHasTypeParameters, typeParameters);
  12133. }
  12134. const {
  12135. declare = false,
  12136. kind
  12137. } = method;
  12138. if (declare && (kind === "get" || kind === "set")) {
  12139. this.raise(TSErrors.DeclareAccessor, method, {
  12140. kind
  12141. });
  12142. }
  12143. if (typeParameters) method.typeParameters = typeParameters;
  12144. super.pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
  12145. }
  12146. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  12147. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12148. if (typeParameters) method.typeParameters = typeParameters;
  12149. super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync);
  12150. }
  12151. declareClassPrivateMethodInScope(node, kind) {
  12152. if (node.type === "TSDeclareMethod") return;
  12153. if (node.type === "MethodDefinition" && node.value.body == null) {
  12154. return;
  12155. }
  12156. super.declareClassPrivateMethodInScope(node, kind);
  12157. }
  12158. parseClassSuper(node) {
  12159. super.parseClassSuper(node);
  12160. if (node.superClass && (this.match(47) || this.match(51))) {
  12161. {
  12162. node.superTypeParameters = this.tsParseTypeArgumentsInExpression();
  12163. }
  12164. }
  12165. if (this.eatContextual(113)) {
  12166. node.implements = this.tsParseHeritageClause("implements");
  12167. }
  12168. }
  12169. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  12170. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12171. if (typeParameters) prop.typeParameters = typeParameters;
  12172. return super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors);
  12173. }
  12174. parseFunctionParams(node, isConstructor) {
  12175. const typeParameters = this.tsTryParseTypeParameters(this.tsParseConstModifier);
  12176. if (typeParameters) node.typeParameters = typeParameters;
  12177. super.parseFunctionParams(node, isConstructor);
  12178. }
  12179. parseVarId(decl, kind) {
  12180. super.parseVarId(decl, kind);
  12181. if (decl.id.type === "Identifier" && !this.hasPrecedingLineBreak() && this.eat(35)) {
  12182. decl.definite = true;
  12183. }
  12184. const type = this.tsTryParseTypeAnnotation();
  12185. if (type) {
  12186. decl.id.typeAnnotation = type;
  12187. this.resetEndLocation(decl.id);
  12188. }
  12189. }
  12190. parseAsyncArrowFromCallExpression(node, call) {
  12191. if (this.match(14)) {
  12192. node.returnType = this.tsParseTypeAnnotation();
  12193. }
  12194. return super.parseAsyncArrowFromCallExpression(node, call);
  12195. }
  12196. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  12197. var _jsx, _jsx2, _typeCast, _jsx3, _typeCast2;
  12198. let state;
  12199. let jsx;
  12200. let typeCast;
  12201. if (this.hasPlugin("jsx") && (this.match(143) || this.match(47))) {
  12202. state = this.state.clone();
  12203. jsx = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  12204. if (!jsx.error) return jsx.node;
  12205. const {
  12206. context
  12207. } = this.state;
  12208. const currentContext = context[context.length - 1];
  12209. if (currentContext === types.j_oTag || currentContext === types.j_expr) {
  12210. context.pop();
  12211. }
  12212. }
  12213. if (!((_jsx = jsx) != null && _jsx.error) && !this.match(47)) {
  12214. return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  12215. }
  12216. if (!state || state === this.state) state = this.state.clone();
  12217. let typeParameters;
  12218. const arrow = this.tryParse(abort => {
  12219. var _expr$extra, _typeParameters;
  12220. typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier);
  12221. const expr = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
  12222. if (expr.type !== "ArrowFunctionExpression" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  12223. abort();
  12224. }
  12225. if (((_typeParameters = typeParameters) == null ? void 0 : _typeParameters.params.length) !== 0) {
  12226. this.resetStartLocationFromNode(expr, typeParameters);
  12227. }
  12228. expr.typeParameters = typeParameters;
  12229. return expr;
  12230. }, state);
  12231. if (!arrow.error && !arrow.aborted) {
  12232. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  12233. return arrow.node;
  12234. }
  12235. if (!jsx) {
  12236. assert(!this.hasPlugin("jsx"));
  12237. typeCast = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
  12238. if (!typeCast.error) return typeCast.node;
  12239. }
  12240. if ((_jsx2 = jsx) != null && _jsx2.node) {
  12241. this.state = jsx.failState;
  12242. return jsx.node;
  12243. }
  12244. if (arrow.node) {
  12245. this.state = arrow.failState;
  12246. if (typeParameters) this.reportReservedArrowTypeParam(typeParameters);
  12247. return arrow.node;
  12248. }
  12249. if ((_typeCast = typeCast) != null && _typeCast.node) {
  12250. this.state = typeCast.failState;
  12251. return typeCast.node;
  12252. }
  12253. throw ((_jsx3 = jsx) == null ? void 0 : _jsx3.error) || arrow.error || ((_typeCast2 = typeCast) == null ? void 0 : _typeCast2.error);
  12254. }
  12255. reportReservedArrowTypeParam(node) {
  12256. var _node$extra2;
  12257. if (node.params.length === 1 && !node.params[0].constraint && !((_node$extra2 = node.extra) != null && _node$extra2.trailingComma) && this.getPluginOption("typescript", "disallowAmbiguousJSXLike")) {
  12258. this.raise(TSErrors.ReservedArrowTypeParam, node);
  12259. }
  12260. }
  12261. parseMaybeUnary(refExpressionErrors, sawUnary) {
  12262. if (!this.hasPlugin("jsx") && this.match(47)) {
  12263. return this.tsParseTypeAssertion();
  12264. }
  12265. return super.parseMaybeUnary(refExpressionErrors, sawUnary);
  12266. }
  12267. parseArrow(node) {
  12268. if (this.match(14)) {
  12269. const result = this.tryParse(abort => {
  12270. const returnType = this.tsParseTypeOrTypePredicateAnnotation(14);
  12271. if (this.canInsertSemicolon() || !this.match(19)) abort();
  12272. return returnType;
  12273. });
  12274. if (result.aborted) return;
  12275. if (!result.thrown) {
  12276. if (result.error) this.state = result.failState;
  12277. node.returnType = result.node;
  12278. }
  12279. }
  12280. return super.parseArrow(node);
  12281. }
  12282. parseFunctionParamType(param) {
  12283. if (this.eat(17)) {
  12284. param.optional = true;
  12285. }
  12286. const type = this.tsTryParseTypeAnnotation();
  12287. if (type) param.typeAnnotation = type;
  12288. this.resetEndLocation(param);
  12289. return param;
  12290. }
  12291. isAssignable(node, isBinding) {
  12292. switch (node.type) {
  12293. case "TSTypeCastExpression":
  12294. return this.isAssignable(node.expression, isBinding);
  12295. case "TSParameterProperty":
  12296. return true;
  12297. default:
  12298. return super.isAssignable(node, isBinding);
  12299. }
  12300. }
  12301. toAssignable(node, isLHS = false) {
  12302. switch (node.type) {
  12303. case "ParenthesizedExpression":
  12304. this.toAssignableParenthesizedExpression(node, isLHS);
  12305. break;
  12306. case "TSAsExpression":
  12307. case "TSSatisfiesExpression":
  12308. case "TSNonNullExpression":
  12309. case "TSTypeAssertion":
  12310. if (isLHS) {
  12311. this.expressionScope.recordArrowParameterBindingError(TSErrors.UnexpectedTypeCastInParameter, node);
  12312. } else {
  12313. this.raise(TSErrors.UnexpectedTypeCastInParameter, node);
  12314. }
  12315. this.toAssignable(node.expression, isLHS);
  12316. break;
  12317. case "AssignmentExpression":
  12318. if (!isLHS && node.left.type === "TSTypeCastExpression") {
  12319. node.left = this.typeCastToParameter(node.left);
  12320. }
  12321. default:
  12322. super.toAssignable(node, isLHS);
  12323. }
  12324. }
  12325. toAssignableParenthesizedExpression(node, isLHS) {
  12326. switch (node.expression.type) {
  12327. case "TSAsExpression":
  12328. case "TSSatisfiesExpression":
  12329. case "TSNonNullExpression":
  12330. case "TSTypeAssertion":
  12331. case "ParenthesizedExpression":
  12332. this.toAssignable(node.expression, isLHS);
  12333. break;
  12334. default:
  12335. super.toAssignable(node, isLHS);
  12336. }
  12337. }
  12338. checkToRestConversion(node, allowPattern) {
  12339. switch (node.type) {
  12340. case "TSAsExpression":
  12341. case "TSSatisfiesExpression":
  12342. case "TSTypeAssertion":
  12343. case "TSNonNullExpression":
  12344. this.checkToRestConversion(node.expression, false);
  12345. break;
  12346. default:
  12347. super.checkToRestConversion(node, allowPattern);
  12348. }
  12349. }
  12350. isValidLVal(type, isUnparenthesizedInAssign, binding) {
  12351. switch (type) {
  12352. case "TSTypeCastExpression":
  12353. return true;
  12354. case "TSParameterProperty":
  12355. return "parameter";
  12356. case "TSNonNullExpression":
  12357. return "expression";
  12358. case "TSAsExpression":
  12359. case "TSSatisfiesExpression":
  12360. case "TSTypeAssertion":
  12361. return (binding !== 64 || !isUnparenthesizedInAssign) && ["expression", true];
  12362. default:
  12363. return super.isValidLVal(type, isUnparenthesizedInAssign, binding);
  12364. }
  12365. }
  12366. parseBindingAtom() {
  12367. if (this.state.type === 78) {
  12368. return this.parseIdentifier(true);
  12369. }
  12370. return super.parseBindingAtom();
  12371. }
  12372. parseMaybeDecoratorArguments(expr, startLoc) {
  12373. if (this.match(47) || this.match(51)) {
  12374. const typeArguments = this.tsParseTypeArgumentsInExpression();
  12375. if (this.match(10)) {
  12376. const call = super.parseMaybeDecoratorArguments(expr, startLoc);
  12377. {
  12378. call.typeParameters = typeArguments;
  12379. }
  12380. return call;
  12381. }
  12382. this.unexpected(null, 10);
  12383. }
  12384. return super.parseMaybeDecoratorArguments(expr, startLoc);
  12385. }
  12386. checkCommaAfterRest(close) {
  12387. if (this.state.isAmbientContext && this.match(12) && this.lookaheadCharCode() === close) {
  12388. this.next();
  12389. return false;
  12390. }
  12391. return super.checkCommaAfterRest(close);
  12392. }
  12393. isClassMethod() {
  12394. return this.match(47) || super.isClassMethod();
  12395. }
  12396. isClassProperty() {
  12397. return this.match(35) || this.match(14) || super.isClassProperty();
  12398. }
  12399. parseMaybeDefault(startLoc, left) {
  12400. const node = super.parseMaybeDefault(startLoc, left);
  12401. if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
  12402. this.raise(TSErrors.TypeAnnotationAfterAssign, node.typeAnnotation);
  12403. }
  12404. return node;
  12405. }
  12406. getTokenFromCode(code) {
  12407. if (this.state.inType) {
  12408. if (code === 62) {
  12409. this.finishOp(48, 1);
  12410. return;
  12411. }
  12412. if (code === 60) {
  12413. this.finishOp(47, 1);
  12414. return;
  12415. }
  12416. }
  12417. super.getTokenFromCode(code);
  12418. }
  12419. reScan_lt_gt() {
  12420. const {
  12421. type
  12422. } = this.state;
  12423. if (type === 47) {
  12424. this.state.pos -= 1;
  12425. this.readToken_lt();
  12426. } else if (type === 48) {
  12427. this.state.pos -= 1;
  12428. this.readToken_gt();
  12429. }
  12430. }
  12431. reScan_lt() {
  12432. const {
  12433. type
  12434. } = this.state;
  12435. if (type === 51) {
  12436. this.state.pos -= 2;
  12437. this.finishOp(47, 1);
  12438. return 47;
  12439. }
  12440. return type;
  12441. }
  12442. toAssignableListItem(exprList, index, isLHS) {
  12443. const node = exprList[index];
  12444. if (node.type === "TSTypeCastExpression") {
  12445. exprList[index] = this.typeCastToParameter(node);
  12446. }
  12447. super.toAssignableListItem(exprList, index, isLHS);
  12448. }
  12449. typeCastToParameter(node) {
  12450. node.expression.typeAnnotation = node.typeAnnotation;
  12451. this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
  12452. return node.expression;
  12453. }
  12454. shouldParseArrow(params) {
  12455. if (this.match(14)) {
  12456. return params.every(expr => this.isAssignable(expr, true));
  12457. }
  12458. return super.shouldParseArrow(params);
  12459. }
  12460. shouldParseAsyncArrow() {
  12461. return this.match(14) || super.shouldParseAsyncArrow();
  12462. }
  12463. canHaveLeadingDecorator() {
  12464. return super.canHaveLeadingDecorator() || this.isAbstractClass();
  12465. }
  12466. jsxParseOpeningElementAfterName(node) {
  12467. if (this.match(47) || this.match(51)) {
  12468. const typeArguments = this.tsTryParseAndCatch(() => this.tsParseTypeArgumentsInExpression());
  12469. if (typeArguments) {
  12470. {
  12471. node.typeParameters = typeArguments;
  12472. }
  12473. }
  12474. }
  12475. return super.jsxParseOpeningElementAfterName(node);
  12476. }
  12477. getGetterSetterExpectedParamCount(method) {
  12478. const baseCount = super.getGetterSetterExpectedParamCount(method);
  12479. const params = this.getObjectOrClassMethodParams(method);
  12480. const firstParam = params[0];
  12481. const hasContextParam = firstParam && this.isThisParam(firstParam);
  12482. return hasContextParam ? baseCount + 1 : baseCount;
  12483. }
  12484. parseCatchClauseParam() {
  12485. const param = super.parseCatchClauseParam();
  12486. const type = this.tsTryParseTypeAnnotation();
  12487. if (type) {
  12488. param.typeAnnotation = type;
  12489. this.resetEndLocation(param);
  12490. }
  12491. return param;
  12492. }
  12493. tsInAmbientContext(cb) {
  12494. const {
  12495. isAmbientContext: oldIsAmbientContext,
  12496. strict: oldStrict
  12497. } = this.state;
  12498. this.state.isAmbientContext = true;
  12499. this.state.strict = false;
  12500. try {
  12501. return cb();
  12502. } finally {
  12503. this.state.isAmbientContext = oldIsAmbientContext;
  12504. this.state.strict = oldStrict;
  12505. }
  12506. }
  12507. parseClass(node, isStatement, optionalId) {
  12508. const oldInAbstractClass = this.state.inAbstractClass;
  12509. this.state.inAbstractClass = !!node.abstract;
  12510. try {
  12511. return super.parseClass(node, isStatement, optionalId);
  12512. } finally {
  12513. this.state.inAbstractClass = oldInAbstractClass;
  12514. }
  12515. }
  12516. tsParseAbstractDeclaration(node, decorators) {
  12517. if (this.match(80)) {
  12518. node.abstract = true;
  12519. return this.maybeTakeDecorators(decorators, this.parseClass(node, true, false));
  12520. } else if (this.isContextual(129)) {
  12521. if (!this.hasFollowingLineBreak()) {
  12522. node.abstract = true;
  12523. this.raise(TSErrors.NonClassMethodPropertyHasAbstractModifier, node);
  12524. return this.tsParseInterfaceDeclaration(node);
  12525. }
  12526. } else {
  12527. this.unexpected(null, 80);
  12528. }
  12529. }
  12530. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope) {
  12531. const method = super.parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope);
  12532. if (method.abstract || method.type === "TSAbstractMethodDefinition") {
  12533. const hasEstreePlugin = this.hasPlugin("estree");
  12534. const methodFn = hasEstreePlugin ? method.value : method;
  12535. if (methodFn.body) {
  12536. const {
  12537. key
  12538. } = method;
  12539. this.raise(TSErrors.AbstractMethodHasImplementation, method, {
  12540. methodName: key.type === "Identifier" && !method.computed ? key.name : `[${this.input.slice(this.offsetToSourcePos(key.start), this.offsetToSourcePos(key.end))}]`
  12541. });
  12542. }
  12543. }
  12544. return method;
  12545. }
  12546. tsParseTypeParameterName() {
  12547. const typeName = this.parseIdentifier();
  12548. return typeName.name;
  12549. }
  12550. shouldParseAsAmbientContext() {
  12551. return !!this.getPluginOption("typescript", "dts");
  12552. }
  12553. parse() {
  12554. if (this.shouldParseAsAmbientContext()) {
  12555. this.state.isAmbientContext = true;
  12556. }
  12557. return super.parse();
  12558. }
  12559. getExpression() {
  12560. if (this.shouldParseAsAmbientContext()) {
  12561. this.state.isAmbientContext = true;
  12562. }
  12563. return super.getExpression();
  12564. }
  12565. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  12566. if (!isString && isMaybeTypeOnly) {
  12567. this.parseTypeOnlyImportExportSpecifier(node, false, isInTypeExport);
  12568. return this.finishNode(node, "ExportSpecifier");
  12569. }
  12570. node.exportKind = "value";
  12571. return super.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly);
  12572. }
  12573. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  12574. if (!importedIsString && isMaybeTypeOnly) {
  12575. this.parseTypeOnlyImportExportSpecifier(specifier, true, isInTypeOnlyImport);
  12576. return this.finishNode(specifier, "ImportSpecifier");
  12577. }
  12578. specifier.importKind = "value";
  12579. return super.parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, isInTypeOnlyImport ? 4098 : 4096);
  12580. }
  12581. parseTypeOnlyImportExportSpecifier(node, isImport, isInTypeOnlyImportExport) {
  12582. const leftOfAsKey = isImport ? "imported" : "local";
  12583. const rightOfAsKey = isImport ? "local" : "exported";
  12584. let leftOfAs = node[leftOfAsKey];
  12585. let rightOfAs;
  12586. let hasTypeSpecifier = false;
  12587. let canParseAsKeyword = true;
  12588. const loc = leftOfAs.loc.start;
  12589. if (this.isContextual(93)) {
  12590. const firstAs = this.parseIdentifier();
  12591. if (this.isContextual(93)) {
  12592. const secondAs = this.parseIdentifier();
  12593. if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12594. hasTypeSpecifier = true;
  12595. leftOfAs = firstAs;
  12596. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12597. canParseAsKeyword = false;
  12598. } else {
  12599. rightOfAs = secondAs;
  12600. canParseAsKeyword = false;
  12601. }
  12602. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12603. canParseAsKeyword = false;
  12604. rightOfAs = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12605. } else {
  12606. hasTypeSpecifier = true;
  12607. leftOfAs = firstAs;
  12608. }
  12609. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  12610. hasTypeSpecifier = true;
  12611. if (isImport) {
  12612. leftOfAs = this.parseIdentifier(true);
  12613. if (!this.isContextual(93)) {
  12614. this.checkReservedWord(leftOfAs.name, leftOfAs.loc.start, true, true);
  12615. }
  12616. } else {
  12617. leftOfAs = this.parseModuleExportName();
  12618. }
  12619. }
  12620. if (hasTypeSpecifier && isInTypeOnlyImportExport) {
  12621. this.raise(isImport ? TSErrors.TypeModifierIsUsedInTypeImports : TSErrors.TypeModifierIsUsedInTypeExports, loc);
  12622. }
  12623. node[leftOfAsKey] = leftOfAs;
  12624. node[rightOfAsKey] = rightOfAs;
  12625. const kindKey = isImport ? "importKind" : "exportKind";
  12626. node[kindKey] = hasTypeSpecifier ? "type" : "value";
  12627. if (canParseAsKeyword && this.eatContextual(93)) {
  12628. node[rightOfAsKey] = isImport ? this.parseIdentifier() : this.parseModuleExportName();
  12629. }
  12630. if (!node[rightOfAsKey]) {
  12631. node[rightOfAsKey] = this.cloneIdentifier(node[leftOfAsKey]);
  12632. }
  12633. if (isImport) {
  12634. this.checkIdentifier(node[rightOfAsKey], hasTypeSpecifier ? 4098 : 4096);
  12635. }
  12636. }
  12637. fillOptionalPropertiesForTSESLint(node) {
  12638. 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;
  12639. switch (node.type) {
  12640. case "ExpressionStatement":
  12641. (_node$directive = node.directive) != null ? _node$directive : node.directive = undefined;
  12642. return;
  12643. case "RestElement":
  12644. node.value = undefined;
  12645. case "Identifier":
  12646. case "ArrayPattern":
  12647. case "AssignmentPattern":
  12648. case "ObjectPattern":
  12649. (_node$decorators = node.decorators) != null ? _node$decorators : node.decorators = [];
  12650. (_node$optional = node.optional) != null ? _node$optional : node.optional = false;
  12651. (_node$typeAnnotation = node.typeAnnotation) != null ? _node$typeAnnotation : node.typeAnnotation = undefined;
  12652. return;
  12653. case "TSParameterProperty":
  12654. (_node$accessibility = node.accessibility) != null ? _node$accessibility : node.accessibility = undefined;
  12655. (_node$decorators2 = node.decorators) != null ? _node$decorators2 : node.decorators = [];
  12656. (_node$override = node.override) != null ? _node$override : node.override = false;
  12657. (_node$readonly = node.readonly) != null ? _node$readonly : node.readonly = false;
  12658. (_node$static = node.static) != null ? _node$static : node.static = false;
  12659. return;
  12660. case "TSEmptyBodyFunctionExpression":
  12661. node.body = null;
  12662. case "TSDeclareFunction":
  12663. case "FunctionDeclaration":
  12664. case "FunctionExpression":
  12665. case "ClassMethod":
  12666. case "ClassPrivateMethod":
  12667. (_node$declare = node.declare) != null ? _node$declare : node.declare = false;
  12668. (_node$returnType = node.returnType) != null ? _node$returnType : node.returnType = undefined;
  12669. (_node$typeParameters = node.typeParameters) != null ? _node$typeParameters : node.typeParameters = undefined;
  12670. return;
  12671. case "Property":
  12672. (_node$optional2 = node.optional) != null ? _node$optional2 : node.optional = false;
  12673. return;
  12674. case "TSMethodSignature":
  12675. case "TSPropertySignature":
  12676. (_node$optional3 = node.optional) != null ? _node$optional3 : node.optional = false;
  12677. case "TSIndexSignature":
  12678. (_node$accessibility2 = node.accessibility) != null ? _node$accessibility2 : node.accessibility = undefined;
  12679. (_node$readonly2 = node.readonly) != null ? _node$readonly2 : node.readonly = false;
  12680. (_node$static2 = node.static) != null ? _node$static2 : node.static = false;
  12681. return;
  12682. case "TSAbstractPropertyDefinition":
  12683. case "PropertyDefinition":
  12684. case "TSAbstractAccessorProperty":
  12685. case "AccessorProperty":
  12686. (_node$declare2 = node.declare) != null ? _node$declare2 : node.declare = false;
  12687. (_node$definite = node.definite) != null ? _node$definite : node.definite = false;
  12688. (_node$readonly3 = node.readonly) != null ? _node$readonly3 : node.readonly = false;
  12689. (_node$typeAnnotation2 = node.typeAnnotation) != null ? _node$typeAnnotation2 : node.typeAnnotation = undefined;
  12690. case "TSAbstractMethodDefinition":
  12691. case "MethodDefinition":
  12692. (_node$accessibility3 = node.accessibility) != null ? _node$accessibility3 : node.accessibility = undefined;
  12693. (_node$decorators3 = node.decorators) != null ? _node$decorators3 : node.decorators = [];
  12694. (_node$override2 = node.override) != null ? _node$override2 : node.override = false;
  12695. (_node$optional4 = node.optional) != null ? _node$optional4 : node.optional = false;
  12696. return;
  12697. case "ClassExpression":
  12698. (_node$id = node.id) != null ? _node$id : node.id = null;
  12699. case "ClassDeclaration":
  12700. (_node$abstract = node.abstract) != null ? _node$abstract : node.abstract = false;
  12701. (_node$declare3 = node.declare) != null ? _node$declare3 : node.declare = false;
  12702. (_node$decorators4 = node.decorators) != null ? _node$decorators4 : node.decorators = [];
  12703. (_node$implements = node.implements) != null ? _node$implements : node.implements = [];
  12704. (_node$superTypeArgume = node.superTypeArguments) != null ? _node$superTypeArgume : node.superTypeArguments = undefined;
  12705. (_node$typeParameters2 = node.typeParameters) != null ? _node$typeParameters2 : node.typeParameters = undefined;
  12706. return;
  12707. case "TSTypeAliasDeclaration":
  12708. case "VariableDeclaration":
  12709. (_node$declare4 = node.declare) != null ? _node$declare4 : node.declare = false;
  12710. return;
  12711. case "VariableDeclarator":
  12712. (_node$definite2 = node.definite) != null ? _node$definite2 : node.definite = false;
  12713. return;
  12714. case "TSEnumDeclaration":
  12715. (_node$const = node.const) != null ? _node$const : node.const = false;
  12716. (_node$declare5 = node.declare) != null ? _node$declare5 : node.declare = false;
  12717. return;
  12718. case "TSEnumMember":
  12719. (_node$computed = node.computed) != null ? _node$computed : node.computed = false;
  12720. return;
  12721. case "TSImportType":
  12722. (_node$qualifier = node.qualifier) != null ? _node$qualifier : node.qualifier = null;
  12723. (_node$options = node.options) != null ? _node$options : node.options = null;
  12724. return;
  12725. case "TSInterfaceDeclaration":
  12726. (_node$declare6 = node.declare) != null ? _node$declare6 : node.declare = false;
  12727. (_node$extends = node.extends) != null ? _node$extends : node.extends = [];
  12728. return;
  12729. case "TSModuleDeclaration":
  12730. (_node$declare7 = node.declare) != null ? _node$declare7 : node.declare = false;
  12731. (_node$global = node.global) != null ? _node$global : node.global = node.kind === "global";
  12732. return;
  12733. case "TSTypeParameter":
  12734. (_node$const2 = node.const) != null ? _node$const2 : node.const = false;
  12735. (_node$in = node.in) != null ? _node$in : node.in = false;
  12736. (_node$out = node.out) != null ? _node$out : node.out = false;
  12737. return;
  12738. }
  12739. }
  12740. };
  12741. function isPossiblyLiteralEnum(expression) {
  12742. if (expression.type !== "MemberExpression") return false;
  12743. const {
  12744. computed,
  12745. property
  12746. } = expression;
  12747. if (computed && property.type !== "StringLiteral" && (property.type !== "TemplateLiteral" || property.expressions.length > 0)) {
  12748. return false;
  12749. }
  12750. return isUncomputedMemberExpressionChain(expression.object);
  12751. }
  12752. function isValidAmbientConstInitializer(expression, estree) {
  12753. var _expression$extra;
  12754. const {
  12755. type
  12756. } = expression;
  12757. if ((_expression$extra = expression.extra) != null && _expression$extra.parenthesized) {
  12758. return false;
  12759. }
  12760. if (estree) {
  12761. if (type === "Literal") {
  12762. const {
  12763. value
  12764. } = expression;
  12765. if (typeof value === "string" || typeof value === "boolean") {
  12766. return true;
  12767. }
  12768. }
  12769. } else {
  12770. if (type === "StringLiteral" || type === "BooleanLiteral") {
  12771. return true;
  12772. }
  12773. }
  12774. if (isNumber(expression, estree) || isNegativeNumber(expression, estree)) {
  12775. return true;
  12776. }
  12777. if (type === "TemplateLiteral" && expression.expressions.length === 0) {
  12778. return true;
  12779. }
  12780. if (isPossiblyLiteralEnum(expression)) {
  12781. return true;
  12782. }
  12783. return false;
  12784. }
  12785. function isNumber(expression, estree) {
  12786. if (estree) {
  12787. return expression.type === "Literal" && (typeof expression.value === "number" || "bigint" in expression);
  12788. }
  12789. return expression.type === "NumericLiteral" || expression.type === "BigIntLiteral";
  12790. }
  12791. function isNegativeNumber(expression, estree) {
  12792. if (expression.type === "UnaryExpression") {
  12793. const {
  12794. operator,
  12795. argument
  12796. } = expression;
  12797. if (operator === "-" && isNumber(argument, estree)) {
  12798. return true;
  12799. }
  12800. }
  12801. return false;
  12802. }
  12803. function isUncomputedMemberExpressionChain(expression) {
  12804. if (expression.type === "Identifier") return true;
  12805. if (expression.type !== "MemberExpression" || expression.computed) {
  12806. return false;
  12807. }
  12808. return isUncomputedMemberExpressionChain(expression.object);
  12809. }
  12810. const PlaceholderErrors = ParseErrorEnum`placeholders`({
  12811. ClassNameIsRequired: "A class name is required.",
  12812. UnexpectedSpace: "Unexpected space in placeholder."
  12813. });
  12814. var placeholders = superClass => class PlaceholdersParserMixin extends superClass {
  12815. parsePlaceholder(expectedNode) {
  12816. if (this.match(133)) {
  12817. const node = this.startNode();
  12818. this.next();
  12819. this.assertNoSpace();
  12820. node.name = super.parseIdentifier(true);
  12821. this.assertNoSpace();
  12822. this.expect(133);
  12823. return this.finishPlaceholder(node, expectedNode);
  12824. }
  12825. }
  12826. finishPlaceholder(node, expectedNode) {
  12827. let placeholder = node;
  12828. if (!placeholder.expectedNode || !placeholder.type) {
  12829. placeholder = this.finishNode(placeholder, "Placeholder");
  12830. }
  12831. placeholder.expectedNode = expectedNode;
  12832. return placeholder;
  12833. }
  12834. getTokenFromCode(code) {
  12835. if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) {
  12836. this.finishOp(133, 2);
  12837. } else {
  12838. super.getTokenFromCode(code);
  12839. }
  12840. }
  12841. parseExprAtom(refExpressionErrors) {
  12842. return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors);
  12843. }
  12844. parseIdentifier(liberal) {
  12845. return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal);
  12846. }
  12847. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  12848. if (word !== undefined) {
  12849. super.checkReservedWord(word, startLoc, checkKeywords, isBinding);
  12850. }
  12851. }
  12852. cloneIdentifier(node) {
  12853. const cloned = super.cloneIdentifier(node);
  12854. if (cloned.type === "Placeholder") {
  12855. cloned.expectedNode = node.expectedNode;
  12856. }
  12857. return cloned;
  12858. }
  12859. cloneStringLiteral(node) {
  12860. if (node.type === "Placeholder") {
  12861. return this.cloneIdentifier(node);
  12862. }
  12863. return super.cloneStringLiteral(node);
  12864. }
  12865. parseBindingAtom() {
  12866. return this.parsePlaceholder("Pattern") || super.parseBindingAtom();
  12867. }
  12868. isValidLVal(type, isParenthesized, binding) {
  12869. return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding);
  12870. }
  12871. toAssignable(node, isLHS) {
  12872. if (node && node.type === "Placeholder" && node.expectedNode === "Expression") {
  12873. node.expectedNode = "Pattern";
  12874. } else {
  12875. super.toAssignable(node, isLHS);
  12876. }
  12877. }
  12878. chStartsBindingIdentifier(ch, pos) {
  12879. if (super.chStartsBindingIdentifier(ch, pos)) {
  12880. return true;
  12881. }
  12882. const next = this.nextTokenStart();
  12883. if (this.input.charCodeAt(next) === 37 && this.input.charCodeAt(next + 1) === 37) {
  12884. return true;
  12885. }
  12886. return false;
  12887. }
  12888. verifyBreakContinue(node, isBreak) {
  12889. if (node.label && node.label.type === "Placeholder") return;
  12890. super.verifyBreakContinue(node, isBreak);
  12891. }
  12892. parseExpressionStatement(node, expr) {
  12893. var _expr$extra;
  12894. if (expr.type !== "Placeholder" || (_expr$extra = expr.extra) != null && _expr$extra.parenthesized) {
  12895. return super.parseExpressionStatement(node, expr);
  12896. }
  12897. if (this.match(14)) {
  12898. const stmt = node;
  12899. stmt.label = this.finishPlaceholder(expr, "Identifier");
  12900. this.next();
  12901. stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration();
  12902. return this.finishNode(stmt, "LabeledStatement");
  12903. }
  12904. this.semicolon();
  12905. const stmtPlaceholder = node;
  12906. stmtPlaceholder.name = expr.name;
  12907. return this.finishPlaceholder(stmtPlaceholder, "Statement");
  12908. }
  12909. parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) {
  12910. return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse);
  12911. }
  12912. parseFunctionId(requireId) {
  12913. return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId);
  12914. }
  12915. parseClass(node, isStatement, optionalId) {
  12916. const type = isStatement ? "ClassDeclaration" : "ClassExpression";
  12917. this.next();
  12918. const oldStrict = this.state.strict;
  12919. const placeholder = this.parsePlaceholder("Identifier");
  12920. if (placeholder) {
  12921. if (this.match(81) || this.match(133) || this.match(5)) {
  12922. node.id = placeholder;
  12923. } else if (optionalId || !isStatement) {
  12924. node.id = null;
  12925. node.body = this.finishPlaceholder(placeholder, "ClassBody");
  12926. return this.finishNode(node, type);
  12927. } else {
  12928. throw this.raise(PlaceholderErrors.ClassNameIsRequired, this.state.startLoc);
  12929. }
  12930. } else {
  12931. this.parseClassId(node, isStatement, optionalId);
  12932. }
  12933. super.parseClassSuper(node);
  12934. node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict);
  12935. return this.finishNode(node, type);
  12936. }
  12937. parseExport(node, decorators) {
  12938. const placeholder = this.parsePlaceholder("Identifier");
  12939. if (!placeholder) return super.parseExport(node, decorators);
  12940. const node2 = node;
  12941. if (!this.isContextual(98) && !this.match(12)) {
  12942. node2.specifiers = [];
  12943. node2.source = null;
  12944. node2.declaration = this.finishPlaceholder(placeholder, "Declaration");
  12945. return this.finishNode(node2, "ExportNamedDeclaration");
  12946. }
  12947. this.expectPlugin("exportDefaultFrom");
  12948. const specifier = this.startNode();
  12949. specifier.exported = placeholder;
  12950. node2.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  12951. return super.parseExport(node2, decorators);
  12952. }
  12953. isExportDefaultSpecifier() {
  12954. if (this.match(65)) {
  12955. const next = this.nextTokenStart();
  12956. if (this.isUnparsedContextual(next, "from")) {
  12957. if (this.input.startsWith(tokenLabelName(133), this.nextTokenStartSince(next + 4))) {
  12958. return true;
  12959. }
  12960. }
  12961. }
  12962. return super.isExportDefaultSpecifier();
  12963. }
  12964. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  12965. var _specifiers;
  12966. if ((_specifiers = node.specifiers) != null && _specifiers.length) {
  12967. return true;
  12968. }
  12969. return super.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  12970. }
  12971. checkExport(node) {
  12972. const {
  12973. specifiers
  12974. } = node;
  12975. if (specifiers != null && specifiers.length) {
  12976. node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder");
  12977. }
  12978. super.checkExport(node);
  12979. node.specifiers = specifiers;
  12980. }
  12981. parseImport(node) {
  12982. const placeholder = this.parsePlaceholder("Identifier");
  12983. if (!placeholder) return super.parseImport(node);
  12984. node.specifiers = [];
  12985. if (!this.isContextual(98) && !this.match(12)) {
  12986. node.source = this.finishPlaceholder(placeholder, "StringLiteral");
  12987. this.semicolon();
  12988. return this.finishNode(node, "ImportDeclaration");
  12989. }
  12990. const specifier = this.startNodeAtNode(placeholder);
  12991. specifier.local = placeholder;
  12992. node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier"));
  12993. if (this.eat(12)) {
  12994. const hasStarImport = this.maybeParseStarImportSpecifier(node);
  12995. if (!hasStarImport) this.parseNamedImportSpecifiers(node);
  12996. }
  12997. this.expectContextual(98);
  12998. node.source = this.parseImportSource();
  12999. this.semicolon();
  13000. return this.finishNode(node, "ImportDeclaration");
  13001. }
  13002. parseImportSource() {
  13003. return this.parsePlaceholder("StringLiteral") || super.parseImportSource();
  13004. }
  13005. assertNoSpace() {
  13006. if (this.state.start > this.offsetToSourcePos(this.state.lastTokEndLoc.index)) {
  13007. this.raise(PlaceholderErrors.UnexpectedSpace, this.state.lastTokEndLoc);
  13008. }
  13009. }
  13010. };
  13011. var v8intrinsic = superClass => class V8IntrinsicMixin extends superClass {
  13012. parseV8Intrinsic() {
  13013. if (this.match(54)) {
  13014. const v8IntrinsicStartLoc = this.state.startLoc;
  13015. const node = this.startNode();
  13016. this.next();
  13017. if (tokenIsIdentifier(this.state.type)) {
  13018. const name = this.parseIdentifierName();
  13019. const identifier = this.createIdentifier(node, name);
  13020. this.castNodeTo(identifier, "V8IntrinsicIdentifier");
  13021. if (this.match(10)) {
  13022. return identifier;
  13023. }
  13024. }
  13025. this.unexpected(v8IntrinsicStartLoc);
  13026. }
  13027. }
  13028. parseExprAtom(refExpressionErrors) {
  13029. return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
  13030. }
  13031. };
  13032. const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
  13033. const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
  13034. function validatePlugins(pluginsMap) {
  13035. if (pluginsMap.has("decorators")) {
  13036. if (pluginsMap.has("decorators-legacy")) {
  13037. throw new Error("Cannot use the decorators and decorators-legacy plugin together");
  13038. }
  13039. const decoratorsBeforeExport = pluginsMap.get("decorators").decoratorsBeforeExport;
  13040. if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
  13041. throw new Error("'decoratorsBeforeExport' must be a boolean, if specified.");
  13042. }
  13043. const allowCallParenthesized = pluginsMap.get("decorators").allowCallParenthesized;
  13044. if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
  13045. throw new Error("'allowCallParenthesized' must be a boolean.");
  13046. }
  13047. }
  13048. if (pluginsMap.has("flow") && pluginsMap.has("typescript")) {
  13049. throw new Error("Cannot combine flow and typescript plugins.");
  13050. }
  13051. if (pluginsMap.has("placeholders") && pluginsMap.has("v8intrinsic")) {
  13052. throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
  13053. }
  13054. if (pluginsMap.has("pipelineOperator")) {
  13055. var _pluginsMap$get2;
  13056. const proposal = pluginsMap.get("pipelineOperator").proposal;
  13057. if (!PIPELINE_PROPOSALS.includes(proposal)) {
  13058. const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", ");
  13059. throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
  13060. }
  13061. if (proposal === "hack") {
  13062. if (pluginsMap.has("placeholders")) {
  13063. throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
  13064. }
  13065. if (pluginsMap.has("v8intrinsic")) {
  13066. throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
  13067. }
  13068. const topicToken = pluginsMap.get("pipelineOperator").topicToken;
  13069. if (!TOPIC_TOKENS.includes(topicToken)) {
  13070. const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", ");
  13071. throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
  13072. }
  13073. {
  13074. var _pluginsMap$get;
  13075. if (topicToken === "#" && ((_pluginsMap$get = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get.syntaxType) === "hash") {
  13076. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "hack", topicToken: "#" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  13077. }
  13078. }
  13079. } else if (proposal === "smart" && ((_pluginsMap$get2 = pluginsMap.get("recordAndTuple")) == null ? void 0 : _pluginsMap$get2.syntaxType) === "hash") {
  13080. throw new Error(`Plugin conflict between \`["pipelineOperator", { proposal: "smart" }]\` and \`${JSON.stringify(["recordAndTuple", pluginsMap.get("recordAndTuple")])}\`.`);
  13081. }
  13082. }
  13083. if (pluginsMap.has("moduleAttributes")) {
  13084. {
  13085. if (pluginsMap.has("deprecatedImportAssert") || pluginsMap.has("importAssertions")) {
  13086. throw new Error("Cannot combine importAssertions, deprecatedImportAssert and moduleAttributes plugins.");
  13087. }
  13088. const moduleAttributesVersionPluginOption = pluginsMap.get("moduleAttributes").version;
  13089. if (moduleAttributesVersionPluginOption !== "may-2020") {
  13090. throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'.");
  13091. }
  13092. }
  13093. }
  13094. if (pluginsMap.has("importAssertions")) {
  13095. if (pluginsMap.has("deprecatedImportAssert")) {
  13096. throw new Error("Cannot combine importAssertions and deprecatedImportAssert plugins.");
  13097. }
  13098. }
  13099. if (!pluginsMap.has("deprecatedImportAssert") && pluginsMap.has("importAttributes") && pluginsMap.get("importAttributes").deprecatedAssertSyntax) {
  13100. {
  13101. pluginsMap.set("deprecatedImportAssert", {});
  13102. }
  13103. }
  13104. if (pluginsMap.has("recordAndTuple")) {
  13105. {
  13106. const syntaxType = pluginsMap.get("recordAndTuple").syntaxType;
  13107. if (syntaxType != null) {
  13108. const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
  13109. if (!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(syntaxType)) {
  13110. throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", "));
  13111. }
  13112. }
  13113. }
  13114. }
  13115. if (pluginsMap.has("asyncDoExpressions") && !pluginsMap.has("doExpressions")) {
  13116. const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
  13117. error.missingPlugins = "doExpressions";
  13118. throw error;
  13119. }
  13120. if (pluginsMap.has("optionalChainingAssign") && pluginsMap.get("optionalChainingAssign").version !== "2023-07") {
  13121. throw new Error("The 'optionalChainingAssign' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is '2023-07'.");
  13122. }
  13123. if (pluginsMap.has("discardBinding") && pluginsMap.get("discardBinding").syntaxType !== "void") {
  13124. throw new Error("The 'discardBinding' plugin requires a 'syntaxType' option. Currently the only supported value is 'void'.");
  13125. }
  13126. }
  13127. const mixinPlugins = {
  13128. estree,
  13129. jsx,
  13130. flow,
  13131. typescript,
  13132. v8intrinsic,
  13133. placeholders
  13134. };
  13135. const mixinPluginNames = Object.keys(mixinPlugins);
  13136. class ExpressionParser extends LValParser {
  13137. checkProto(prop, isRecord, sawProto, refExpressionErrors) {
  13138. if (prop.type === "SpreadElement" || this.isObjectMethod(prop) || prop.computed || prop.shorthand) {
  13139. return sawProto;
  13140. }
  13141. const key = prop.key;
  13142. const name = key.type === "Identifier" ? key.name : key.value;
  13143. if (name === "__proto__") {
  13144. if (isRecord) {
  13145. this.raise(Errors.RecordNoProto, key);
  13146. return true;
  13147. }
  13148. if (sawProto) {
  13149. if (refExpressionErrors) {
  13150. if (refExpressionErrors.doubleProtoLoc === null) {
  13151. refExpressionErrors.doubleProtoLoc = key.loc.start;
  13152. }
  13153. } else {
  13154. this.raise(Errors.DuplicateProto, key);
  13155. }
  13156. }
  13157. return true;
  13158. }
  13159. return sawProto;
  13160. }
  13161. shouldExitDescending(expr, potentialArrowAt) {
  13162. return expr.type === "ArrowFunctionExpression" && this.offsetToSourcePos(expr.start) === potentialArrowAt;
  13163. }
  13164. getExpression() {
  13165. this.enterInitialScopes();
  13166. this.nextToken();
  13167. if (this.match(140)) {
  13168. throw this.raise(Errors.ParseExpressionEmptyInput, this.state.startLoc);
  13169. }
  13170. const expr = this.parseExpression();
  13171. if (!this.match(140)) {
  13172. throw this.raise(Errors.ParseExpressionExpectsEOF, this.state.startLoc, {
  13173. unexpected: this.input.codePointAt(this.state.start)
  13174. });
  13175. }
  13176. this.finalizeRemainingComments();
  13177. expr.comments = this.comments;
  13178. expr.errors = this.state.errors;
  13179. if (this.optionFlags & 256) {
  13180. expr.tokens = this.tokens;
  13181. }
  13182. return expr;
  13183. }
  13184. parseExpression(disallowIn, refExpressionErrors) {
  13185. if (disallowIn) {
  13186. return this.disallowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  13187. }
  13188. return this.allowInAnd(() => this.parseExpressionBase(refExpressionErrors));
  13189. }
  13190. parseExpressionBase(refExpressionErrors) {
  13191. const startLoc = this.state.startLoc;
  13192. const expr = this.parseMaybeAssign(refExpressionErrors);
  13193. if (this.match(12)) {
  13194. const node = this.startNodeAt(startLoc);
  13195. node.expressions = [expr];
  13196. while (this.eat(12)) {
  13197. node.expressions.push(this.parseMaybeAssign(refExpressionErrors));
  13198. }
  13199. this.toReferencedList(node.expressions);
  13200. return this.finishNode(node, "SequenceExpression");
  13201. }
  13202. return expr;
  13203. }
  13204. parseMaybeAssignDisallowIn(refExpressionErrors, afterLeftParse) {
  13205. return this.disallowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  13206. }
  13207. parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse) {
  13208. return this.allowInAnd(() => this.parseMaybeAssign(refExpressionErrors, afterLeftParse));
  13209. }
  13210. setOptionalParametersError(refExpressionErrors) {
  13211. refExpressionErrors.optionalParametersLoc = this.state.startLoc;
  13212. }
  13213. parseMaybeAssign(refExpressionErrors, afterLeftParse) {
  13214. const startLoc = this.state.startLoc;
  13215. const isYield = this.isContextual(108);
  13216. if (isYield) {
  13217. if (this.prodParam.hasYield) {
  13218. this.next();
  13219. let left = this.parseYield(startLoc);
  13220. if (afterLeftParse) {
  13221. left = afterLeftParse.call(this, left, startLoc);
  13222. }
  13223. return left;
  13224. }
  13225. }
  13226. let ownExpressionErrors;
  13227. if (refExpressionErrors) {
  13228. ownExpressionErrors = false;
  13229. } else {
  13230. refExpressionErrors = new ExpressionErrors();
  13231. ownExpressionErrors = true;
  13232. }
  13233. const {
  13234. type
  13235. } = this.state;
  13236. if (type === 10 || tokenIsIdentifier(type)) {
  13237. this.state.potentialArrowAt = this.state.start;
  13238. }
  13239. let left = this.parseMaybeConditional(refExpressionErrors);
  13240. if (afterLeftParse) {
  13241. left = afterLeftParse.call(this, left, startLoc);
  13242. }
  13243. if (tokenIsAssignment(this.state.type)) {
  13244. const node = this.startNodeAt(startLoc);
  13245. const operator = this.state.value;
  13246. node.operator = operator;
  13247. if (this.match(29)) {
  13248. this.toAssignable(left, true);
  13249. node.left = left;
  13250. const startIndex = startLoc.index;
  13251. if (refExpressionErrors.doubleProtoLoc != null && refExpressionErrors.doubleProtoLoc.index >= startIndex) {
  13252. refExpressionErrors.doubleProtoLoc = null;
  13253. }
  13254. if (refExpressionErrors.shorthandAssignLoc != null && refExpressionErrors.shorthandAssignLoc.index >= startIndex) {
  13255. refExpressionErrors.shorthandAssignLoc = null;
  13256. }
  13257. if (refExpressionErrors.privateKeyLoc != null && refExpressionErrors.privateKeyLoc.index >= startIndex) {
  13258. this.checkDestructuringPrivate(refExpressionErrors);
  13259. refExpressionErrors.privateKeyLoc = null;
  13260. }
  13261. if (refExpressionErrors.voidPatternLoc != null && refExpressionErrors.voidPatternLoc.index >= startIndex) {
  13262. refExpressionErrors.voidPatternLoc = null;
  13263. }
  13264. } else {
  13265. node.left = left;
  13266. }
  13267. this.next();
  13268. node.right = this.parseMaybeAssign();
  13269. this.checkLVal(left, this.finishNode(node, "AssignmentExpression"));
  13270. return node;
  13271. } else if (ownExpressionErrors) {
  13272. this.checkExpressionErrors(refExpressionErrors, true);
  13273. }
  13274. if (isYield) {
  13275. const {
  13276. type
  13277. } = this.state;
  13278. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  13279. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  13280. this.raiseOverwrite(Errors.YieldNotInGeneratorFunction, startLoc);
  13281. return this.parseYield(startLoc);
  13282. }
  13283. }
  13284. return left;
  13285. }
  13286. parseMaybeConditional(refExpressionErrors) {
  13287. const startLoc = this.state.startLoc;
  13288. const potentialArrowAt = this.state.potentialArrowAt;
  13289. const expr = this.parseExprOps(refExpressionErrors);
  13290. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13291. return expr;
  13292. }
  13293. return this.parseConditional(expr, startLoc, refExpressionErrors);
  13294. }
  13295. parseConditional(expr, startLoc, refExpressionErrors) {
  13296. if (this.eat(17)) {
  13297. const node = this.startNodeAt(startLoc);
  13298. node.test = expr;
  13299. node.consequent = this.parseMaybeAssignAllowIn();
  13300. this.expect(14);
  13301. node.alternate = this.parseMaybeAssign();
  13302. return this.finishNode(node, "ConditionalExpression");
  13303. }
  13304. return expr;
  13305. }
  13306. parseMaybeUnaryOrPrivate(refExpressionErrors) {
  13307. return this.match(139) ? this.parsePrivateName() : this.parseMaybeUnary(refExpressionErrors);
  13308. }
  13309. parseExprOps(refExpressionErrors) {
  13310. const startLoc = this.state.startLoc;
  13311. const potentialArrowAt = this.state.potentialArrowAt;
  13312. const expr = this.parseMaybeUnaryOrPrivate(refExpressionErrors);
  13313. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13314. return expr;
  13315. }
  13316. return this.parseExprOp(expr, startLoc, -1);
  13317. }
  13318. parseExprOp(left, leftStartLoc, minPrec) {
  13319. if (this.isPrivateName(left)) {
  13320. const value = this.getPrivateNameSV(left);
  13321. if (minPrec >= tokenOperatorPrecedence(58) || !this.prodParam.hasIn || !this.match(58)) {
  13322. this.raise(Errors.PrivateInExpectedIn, left, {
  13323. identifierName: value
  13324. });
  13325. }
  13326. this.classScope.usePrivateName(value, left.loc.start);
  13327. }
  13328. const op = this.state.type;
  13329. if (tokenIsOperator(op) && (this.prodParam.hasIn || !this.match(58))) {
  13330. let prec = tokenOperatorPrecedence(op);
  13331. if (prec > minPrec) {
  13332. if (op === 39) {
  13333. this.expectPlugin("pipelineOperator");
  13334. if (this.state.inFSharpPipelineDirectBody) {
  13335. return left;
  13336. }
  13337. this.checkPipelineAtInfixOperator(left, leftStartLoc);
  13338. }
  13339. const node = this.startNodeAt(leftStartLoc);
  13340. node.left = left;
  13341. node.operator = this.state.value;
  13342. const logical = op === 41 || op === 42;
  13343. const coalesce = op === 40;
  13344. if (coalesce) {
  13345. prec = tokenOperatorPrecedence(42);
  13346. }
  13347. this.next();
  13348. if (op === 39 && this.hasPlugin(["pipelineOperator", {
  13349. proposal: "minimal"
  13350. }])) {
  13351. if (this.state.type === 96 && this.prodParam.hasAwait) {
  13352. throw this.raise(Errors.UnexpectedAwaitAfterPipelineBody, this.state.startLoc);
  13353. }
  13354. }
  13355. node.right = this.parseExprOpRightExpr(op, prec);
  13356. const finishedNode = this.finishNode(node, logical || coalesce ? "LogicalExpression" : "BinaryExpression");
  13357. const nextOp = this.state.type;
  13358. if (coalesce && (nextOp === 41 || nextOp === 42) || logical && nextOp === 40) {
  13359. throw this.raise(Errors.MixingCoalesceWithLogical, this.state.startLoc);
  13360. }
  13361. return this.parseExprOp(finishedNode, leftStartLoc, minPrec);
  13362. }
  13363. }
  13364. return left;
  13365. }
  13366. parseExprOpRightExpr(op, prec) {
  13367. const startLoc = this.state.startLoc;
  13368. switch (op) {
  13369. case 39:
  13370. switch (this.getPluginOption("pipelineOperator", "proposal")) {
  13371. case "hack":
  13372. return this.withTopicBindingContext(() => {
  13373. return this.parseHackPipeBody();
  13374. });
  13375. case "fsharp":
  13376. return this.withSoloAwaitPermittingContext(() => {
  13377. return this.parseFSharpPipelineBody(prec);
  13378. });
  13379. }
  13380. if (this.getPluginOption("pipelineOperator", "proposal") === "smart") {
  13381. return this.withTopicBindingContext(() => {
  13382. if (this.prodParam.hasYield && this.isContextual(108)) {
  13383. throw this.raise(Errors.PipeBodyIsTighter, this.state.startLoc);
  13384. }
  13385. return this.parseSmartPipelineBodyInStyle(this.parseExprOpBaseRightExpr(op, prec), startLoc);
  13386. });
  13387. }
  13388. default:
  13389. return this.parseExprOpBaseRightExpr(op, prec);
  13390. }
  13391. }
  13392. parseExprOpBaseRightExpr(op, prec) {
  13393. const startLoc = this.state.startLoc;
  13394. return this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, tokenIsRightAssociative(op) ? prec - 1 : prec);
  13395. }
  13396. parseHackPipeBody() {
  13397. var _body$extra;
  13398. const {
  13399. startLoc
  13400. } = this.state;
  13401. const body = this.parseMaybeAssign();
  13402. const requiredParentheses = UnparenthesizedPipeBodyDescriptions.has(body.type);
  13403. if (requiredParentheses && !((_body$extra = body.extra) != null && _body$extra.parenthesized)) {
  13404. this.raise(Errors.PipeUnparenthesizedBody, startLoc, {
  13405. type: body.type
  13406. });
  13407. }
  13408. if (!this.topicReferenceWasUsedInCurrentContext()) {
  13409. this.raise(Errors.PipeTopicUnused, startLoc);
  13410. }
  13411. return body;
  13412. }
  13413. checkExponentialAfterUnary(node) {
  13414. if (this.match(57)) {
  13415. this.raise(Errors.UnexpectedTokenUnaryExponentiation, node.argument);
  13416. }
  13417. }
  13418. parseMaybeUnary(refExpressionErrors, sawUnary) {
  13419. const startLoc = this.state.startLoc;
  13420. const isAwait = this.isContextual(96);
  13421. if (isAwait && this.recordAwaitIfAllowed()) {
  13422. this.next();
  13423. const expr = this.parseAwait(startLoc);
  13424. if (!sawUnary) this.checkExponentialAfterUnary(expr);
  13425. return expr;
  13426. }
  13427. const update = this.match(34);
  13428. const node = this.startNode();
  13429. if (tokenIsPrefix(this.state.type)) {
  13430. node.operator = this.state.value;
  13431. node.prefix = true;
  13432. if (this.match(72)) {
  13433. this.expectPlugin("throwExpressions");
  13434. }
  13435. const isDelete = this.match(89);
  13436. this.next();
  13437. node.argument = this.parseMaybeUnary(null, true);
  13438. this.checkExpressionErrors(refExpressionErrors, true);
  13439. if (this.state.strict && isDelete) {
  13440. const arg = node.argument;
  13441. if (arg.type === "Identifier") {
  13442. this.raise(Errors.StrictDelete, node);
  13443. } else if (this.hasPropertyAsPrivateName(arg)) {
  13444. this.raise(Errors.DeletePrivateField, node);
  13445. }
  13446. }
  13447. if (!update) {
  13448. if (!sawUnary) {
  13449. this.checkExponentialAfterUnary(node);
  13450. }
  13451. return this.finishNode(node, "UnaryExpression");
  13452. }
  13453. }
  13454. const expr = this.parseUpdate(node, update, refExpressionErrors);
  13455. if (isAwait) {
  13456. const {
  13457. type
  13458. } = this.state;
  13459. const startsExpr = this.hasPlugin("v8intrinsic") ? tokenCanStartExpression(type) : tokenCanStartExpression(type) && !this.match(54);
  13460. if (startsExpr && !this.isAmbiguousPrefixOrIdentifier()) {
  13461. this.raiseOverwrite(Errors.AwaitNotInAsyncContext, startLoc);
  13462. return this.parseAwait(startLoc);
  13463. }
  13464. }
  13465. return expr;
  13466. }
  13467. parseUpdate(node, update, refExpressionErrors) {
  13468. if (update) {
  13469. const updateExpressionNode = node;
  13470. this.checkLVal(updateExpressionNode.argument, this.finishNode(updateExpressionNode, "UpdateExpression"));
  13471. return node;
  13472. }
  13473. const startLoc = this.state.startLoc;
  13474. let expr = this.parseExprSubscripts(refExpressionErrors);
  13475. if (this.checkExpressionErrors(refExpressionErrors, false)) return expr;
  13476. while (tokenIsPostfix(this.state.type) && !this.canInsertSemicolon()) {
  13477. const node = this.startNodeAt(startLoc);
  13478. node.operator = this.state.value;
  13479. node.prefix = false;
  13480. node.argument = expr;
  13481. this.next();
  13482. this.checkLVal(expr, expr = this.finishNode(node, "UpdateExpression"));
  13483. }
  13484. return expr;
  13485. }
  13486. parseExprSubscripts(refExpressionErrors) {
  13487. const startLoc = this.state.startLoc;
  13488. const potentialArrowAt = this.state.potentialArrowAt;
  13489. const expr = this.parseExprAtom(refExpressionErrors);
  13490. if (this.shouldExitDescending(expr, potentialArrowAt)) {
  13491. return expr;
  13492. }
  13493. return this.parseSubscripts(expr, startLoc);
  13494. }
  13495. parseSubscripts(base, startLoc, noCalls) {
  13496. const state = {
  13497. optionalChainMember: false,
  13498. maybeAsyncArrow: this.atPossibleAsyncArrow(base),
  13499. stop: false
  13500. };
  13501. do {
  13502. base = this.parseSubscript(base, startLoc, noCalls, state);
  13503. state.maybeAsyncArrow = false;
  13504. } while (!state.stop);
  13505. return base;
  13506. }
  13507. parseSubscript(base, startLoc, noCalls, state) {
  13508. const {
  13509. type
  13510. } = this.state;
  13511. if (!noCalls && type === 15) {
  13512. return this.parseBind(base, startLoc, noCalls, state);
  13513. } else if (tokenIsTemplate(type)) {
  13514. return this.parseTaggedTemplateExpression(base, startLoc, state);
  13515. }
  13516. let optional = false;
  13517. if (type === 18) {
  13518. if (noCalls) {
  13519. this.raise(Errors.OptionalChainingNoNew, this.state.startLoc);
  13520. if (this.lookaheadCharCode() === 40) {
  13521. return this.stopParseSubscript(base, state);
  13522. }
  13523. }
  13524. state.optionalChainMember = optional = true;
  13525. this.next();
  13526. }
  13527. if (!noCalls && this.match(10)) {
  13528. return this.parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional);
  13529. } else {
  13530. const computed = this.eat(0);
  13531. if (computed || optional || this.eat(16)) {
  13532. return this.parseMember(base, startLoc, state, computed, optional);
  13533. } else {
  13534. return this.stopParseSubscript(base, state);
  13535. }
  13536. }
  13537. }
  13538. stopParseSubscript(base, state) {
  13539. state.stop = true;
  13540. return base;
  13541. }
  13542. parseMember(base, startLoc, state, computed, optional) {
  13543. const node = this.startNodeAt(startLoc);
  13544. node.object = base;
  13545. node.computed = computed;
  13546. if (computed) {
  13547. node.property = this.parseExpression();
  13548. this.expect(3);
  13549. } else if (this.match(139)) {
  13550. if (base.type === "Super") {
  13551. this.raise(Errors.SuperPrivateField, startLoc);
  13552. }
  13553. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  13554. node.property = this.parsePrivateName();
  13555. } else {
  13556. node.property = this.parseIdentifier(true);
  13557. }
  13558. if (state.optionalChainMember) {
  13559. node.optional = optional;
  13560. return this.finishNode(node, "OptionalMemberExpression");
  13561. } else {
  13562. return this.finishNode(node, "MemberExpression");
  13563. }
  13564. }
  13565. parseBind(base, startLoc, noCalls, state) {
  13566. const node = this.startNodeAt(startLoc);
  13567. node.object = base;
  13568. this.next();
  13569. node.callee = this.parseNoCallExpr();
  13570. state.stop = true;
  13571. return this.parseSubscripts(this.finishNode(node, "BindExpression"), startLoc, noCalls);
  13572. }
  13573. parseCoverCallAndAsyncArrowHead(base, startLoc, state, optional) {
  13574. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  13575. let refExpressionErrors = null;
  13576. this.state.maybeInArrowParameters = true;
  13577. this.next();
  13578. const node = this.startNodeAt(startLoc);
  13579. node.callee = base;
  13580. const {
  13581. maybeAsyncArrow,
  13582. optionalChainMember
  13583. } = state;
  13584. if (maybeAsyncArrow) {
  13585. this.expressionScope.enter(newAsyncArrowScope());
  13586. refExpressionErrors = new ExpressionErrors();
  13587. }
  13588. if (optionalChainMember) {
  13589. node.optional = optional;
  13590. }
  13591. if (optional) {
  13592. node.arguments = this.parseCallExpressionArguments();
  13593. } else {
  13594. node.arguments = this.parseCallExpressionArguments(base.type !== "Super", node, refExpressionErrors);
  13595. }
  13596. let finishedNode = this.finishCallExpression(node, optionalChainMember);
  13597. if (maybeAsyncArrow && this.shouldParseAsyncArrow() && !optional) {
  13598. state.stop = true;
  13599. this.checkDestructuringPrivate(refExpressionErrors);
  13600. this.expressionScope.validateAsPattern();
  13601. this.expressionScope.exit();
  13602. finishedNode = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startLoc), finishedNode);
  13603. } else {
  13604. if (maybeAsyncArrow) {
  13605. this.checkExpressionErrors(refExpressionErrors, true);
  13606. this.expressionScope.exit();
  13607. }
  13608. this.toReferencedArguments(finishedNode);
  13609. }
  13610. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  13611. return finishedNode;
  13612. }
  13613. toReferencedArguments(node, isParenthesizedExpr) {
  13614. this.toReferencedListDeep(node.arguments, isParenthesizedExpr);
  13615. }
  13616. parseTaggedTemplateExpression(base, startLoc, state) {
  13617. const node = this.startNodeAt(startLoc);
  13618. node.tag = base;
  13619. node.quasi = this.parseTemplate(true);
  13620. if (state.optionalChainMember) {
  13621. this.raise(Errors.OptionalChainingNoTemplate, startLoc);
  13622. }
  13623. return this.finishNode(node, "TaggedTemplateExpression");
  13624. }
  13625. atPossibleAsyncArrow(base) {
  13626. 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;
  13627. }
  13628. finishCallExpression(node, optional) {
  13629. if (node.callee.type === "Import") {
  13630. if (node.arguments.length === 0 || node.arguments.length > 2) {
  13631. this.raise(Errors.ImportCallArity, node);
  13632. } else {
  13633. for (const arg of node.arguments) {
  13634. if (arg.type === "SpreadElement") {
  13635. this.raise(Errors.ImportCallSpreadArgument, arg);
  13636. }
  13637. }
  13638. }
  13639. }
  13640. return this.finishNode(node, optional ? "OptionalCallExpression" : "CallExpression");
  13641. }
  13642. parseCallExpressionArguments(allowPlaceholder, nodeForExtra, refExpressionErrors) {
  13643. const elts = [];
  13644. let first = true;
  13645. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  13646. this.state.inFSharpPipelineDirectBody = false;
  13647. while (!this.eat(11)) {
  13648. if (first) {
  13649. first = false;
  13650. } else {
  13651. this.expect(12);
  13652. if (this.match(11)) {
  13653. if (nodeForExtra) {
  13654. this.addTrailingCommaExtraToNode(nodeForExtra);
  13655. }
  13656. this.next();
  13657. break;
  13658. }
  13659. }
  13660. elts.push(this.parseExprListItem(11, false, refExpressionErrors, allowPlaceholder));
  13661. }
  13662. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  13663. return elts;
  13664. }
  13665. shouldParseAsyncArrow() {
  13666. return this.match(19) && !this.canInsertSemicolon();
  13667. }
  13668. parseAsyncArrowFromCallExpression(node, call) {
  13669. var _call$extra;
  13670. this.resetPreviousNodeTrailingComments(call);
  13671. this.expect(19);
  13672. this.parseArrowExpression(node, call.arguments, true, (_call$extra = call.extra) == null ? void 0 : _call$extra.trailingCommaLoc);
  13673. if (call.innerComments) {
  13674. setInnerComments(node, call.innerComments);
  13675. }
  13676. if (call.callee.trailingComments) {
  13677. setInnerComments(node, call.callee.trailingComments);
  13678. }
  13679. return node;
  13680. }
  13681. parseNoCallExpr() {
  13682. const startLoc = this.state.startLoc;
  13683. return this.parseSubscripts(this.parseExprAtom(), startLoc, true);
  13684. }
  13685. parseExprAtom(refExpressionErrors) {
  13686. let node;
  13687. let decorators = null;
  13688. const {
  13689. type
  13690. } = this.state;
  13691. switch (type) {
  13692. case 79:
  13693. return this.parseSuper();
  13694. case 83:
  13695. node = this.startNode();
  13696. this.next();
  13697. if (this.match(16)) {
  13698. return this.parseImportMetaPropertyOrPhaseCall(node);
  13699. }
  13700. if (this.match(10)) {
  13701. if (this.optionFlags & 512) {
  13702. return this.parseImportCall(node);
  13703. } else {
  13704. return this.finishNode(node, "Import");
  13705. }
  13706. } else {
  13707. this.raise(Errors.UnsupportedImport, this.state.lastTokStartLoc);
  13708. return this.finishNode(node, "Import");
  13709. }
  13710. case 78:
  13711. node = this.startNode();
  13712. this.next();
  13713. return this.finishNode(node, "ThisExpression");
  13714. case 90:
  13715. {
  13716. return this.parseDo(this.startNode(), false);
  13717. }
  13718. case 56:
  13719. case 31:
  13720. {
  13721. this.readRegexp();
  13722. return this.parseRegExpLiteral(this.state.value);
  13723. }
  13724. case 135:
  13725. return this.parseNumericLiteral(this.state.value);
  13726. case 136:
  13727. return this.parseBigIntLiteral(this.state.value);
  13728. case 134:
  13729. return this.parseStringLiteral(this.state.value);
  13730. case 84:
  13731. return this.parseNullLiteral();
  13732. case 85:
  13733. return this.parseBooleanLiteral(true);
  13734. case 86:
  13735. return this.parseBooleanLiteral(false);
  13736. case 10:
  13737. {
  13738. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  13739. return this.parseParenAndDistinguishExpression(canBeArrow);
  13740. }
  13741. case 0:
  13742. {
  13743. return this.parseArrayLike(3, true, false, refExpressionErrors);
  13744. }
  13745. case 5:
  13746. {
  13747. return this.parseObjectLike(8, false, false, refExpressionErrors);
  13748. }
  13749. case 68:
  13750. return this.parseFunctionOrFunctionSent();
  13751. case 26:
  13752. decorators = this.parseDecorators();
  13753. case 80:
  13754. return this.parseClass(this.maybeTakeDecorators(decorators, this.startNode()), false);
  13755. case 77:
  13756. return this.parseNewOrNewTarget();
  13757. case 25:
  13758. case 24:
  13759. return this.parseTemplate(false);
  13760. case 15:
  13761. {
  13762. node = this.startNode();
  13763. this.next();
  13764. node.object = null;
  13765. const callee = node.callee = this.parseNoCallExpr();
  13766. if (callee.type === "MemberExpression") {
  13767. return this.finishNode(node, "BindExpression");
  13768. } else {
  13769. throw this.raise(Errors.UnsupportedBind, callee);
  13770. }
  13771. }
  13772. case 139:
  13773. {
  13774. this.raise(Errors.PrivateInExpectedIn, this.state.startLoc, {
  13775. identifierName: this.state.value
  13776. });
  13777. return this.parsePrivateName();
  13778. }
  13779. case 33:
  13780. {
  13781. return this.parseTopicReferenceThenEqualsSign(54, "%");
  13782. }
  13783. case 32:
  13784. {
  13785. return this.parseTopicReferenceThenEqualsSign(44, "^");
  13786. }
  13787. case 37:
  13788. case 38:
  13789. {
  13790. return this.parseTopicReference("hack");
  13791. }
  13792. case 44:
  13793. case 54:
  13794. case 27:
  13795. {
  13796. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  13797. if (pipeProposal) {
  13798. return this.parseTopicReference(pipeProposal);
  13799. }
  13800. this.unexpected();
  13801. break;
  13802. }
  13803. case 47:
  13804. {
  13805. const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
  13806. if (isIdentifierStart(lookaheadCh) || lookaheadCh === 62) {
  13807. this.expectOnePlugin(["jsx", "flow", "typescript"]);
  13808. } else {
  13809. this.unexpected();
  13810. }
  13811. break;
  13812. }
  13813. default:
  13814. {
  13815. if (type === 137) {
  13816. return this.parseDecimalLiteral(this.state.value);
  13817. } else if (type === 2 || type === 1) {
  13818. return this.parseArrayLike(this.state.type === 2 ? 4 : 3, false, true);
  13819. } else if (type === 6 || type === 7) {
  13820. return this.parseObjectLike(this.state.type === 6 ? 9 : 8, false, true);
  13821. }
  13822. }
  13823. if (tokenIsIdentifier(type)) {
  13824. if (this.isContextual(127) && this.lookaheadInLineCharCode() === 123) {
  13825. return this.parseModuleExpression();
  13826. }
  13827. const canBeArrow = this.state.potentialArrowAt === this.state.start;
  13828. const containsEsc = this.state.containsEsc;
  13829. const id = this.parseIdentifier();
  13830. if (!containsEsc && id.name === "async" && !this.canInsertSemicolon()) {
  13831. const {
  13832. type
  13833. } = this.state;
  13834. if (type === 68) {
  13835. this.resetPreviousNodeTrailingComments(id);
  13836. this.next();
  13837. return this.parseAsyncFunctionExpression(this.startNodeAtNode(id));
  13838. } else if (tokenIsIdentifier(type)) {
  13839. if (this.lookaheadCharCode() === 61) {
  13840. return this.parseAsyncArrowUnaryFunction(this.startNodeAtNode(id));
  13841. } else {
  13842. return id;
  13843. }
  13844. } else if (type === 90) {
  13845. this.resetPreviousNodeTrailingComments(id);
  13846. return this.parseDo(this.startNodeAtNode(id), true);
  13847. }
  13848. }
  13849. if (canBeArrow && this.match(19) && !this.canInsertSemicolon()) {
  13850. this.next();
  13851. return this.parseArrowExpression(this.startNodeAtNode(id), [id], false);
  13852. }
  13853. return id;
  13854. } else {
  13855. this.unexpected();
  13856. }
  13857. }
  13858. }
  13859. parseTopicReferenceThenEqualsSign(topicTokenType, topicTokenValue) {
  13860. const pipeProposal = this.getPluginOption("pipelineOperator", "proposal");
  13861. if (pipeProposal) {
  13862. this.state.type = topicTokenType;
  13863. this.state.value = topicTokenValue;
  13864. this.state.pos--;
  13865. this.state.end--;
  13866. this.state.endLoc = createPositionWithColumnOffset(this.state.endLoc, -1);
  13867. return this.parseTopicReference(pipeProposal);
  13868. } else {
  13869. this.unexpected();
  13870. }
  13871. }
  13872. parseTopicReference(pipeProposal) {
  13873. const node = this.startNode();
  13874. const startLoc = this.state.startLoc;
  13875. const tokenType = this.state.type;
  13876. this.next();
  13877. return this.finishTopicReference(node, startLoc, pipeProposal, tokenType);
  13878. }
  13879. finishTopicReference(node, startLoc, pipeProposal, tokenType) {
  13880. if (this.testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType)) {
  13881. if (pipeProposal === "hack") {
  13882. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  13883. this.raise(Errors.PipeTopicUnbound, startLoc);
  13884. }
  13885. this.registerTopicReference();
  13886. return this.finishNode(node, "TopicReference");
  13887. } else {
  13888. if (!this.topicReferenceIsAllowedInCurrentContext()) {
  13889. this.raise(Errors.PrimaryTopicNotAllowed, startLoc);
  13890. }
  13891. this.registerTopicReference();
  13892. return this.finishNode(node, "PipelinePrimaryTopicReference");
  13893. }
  13894. } else {
  13895. throw this.raise(Errors.PipeTopicUnconfiguredToken, startLoc, {
  13896. token: tokenLabelName(tokenType)
  13897. });
  13898. }
  13899. }
  13900. testTopicReferenceConfiguration(pipeProposal, startLoc, tokenType) {
  13901. switch (pipeProposal) {
  13902. case "hack":
  13903. {
  13904. return this.hasPlugin(["pipelineOperator", {
  13905. topicToken: tokenLabelName(tokenType)
  13906. }]);
  13907. }
  13908. case "smart":
  13909. return tokenType === 27;
  13910. default:
  13911. throw this.raise(Errors.PipeTopicRequiresHackPipes, startLoc);
  13912. }
  13913. }
  13914. parseAsyncArrowUnaryFunction(node) {
  13915. this.prodParam.enter(functionFlags(true, this.prodParam.hasYield));
  13916. const params = [this.parseIdentifier()];
  13917. this.prodParam.exit();
  13918. if (this.hasPrecedingLineBreak()) {
  13919. this.raise(Errors.LineTerminatorBeforeArrow, this.state.curPosition());
  13920. }
  13921. this.expect(19);
  13922. return this.parseArrowExpression(node, params, true);
  13923. }
  13924. parseDo(node, isAsync) {
  13925. this.expectPlugin("doExpressions");
  13926. if (isAsync) {
  13927. this.expectPlugin("asyncDoExpressions");
  13928. }
  13929. node.async = isAsync;
  13930. this.next();
  13931. const oldLabels = this.state.labels;
  13932. this.state.labels = [];
  13933. if (isAsync) {
  13934. this.prodParam.enter(2);
  13935. node.body = this.parseBlock();
  13936. this.prodParam.exit();
  13937. } else {
  13938. node.body = this.parseBlock();
  13939. }
  13940. this.state.labels = oldLabels;
  13941. return this.finishNode(node, "DoExpression");
  13942. }
  13943. parseSuper() {
  13944. const node = this.startNode();
  13945. this.next();
  13946. if (this.match(10) && !this.scope.allowDirectSuper && !(this.optionFlags & 16)) {
  13947. this.raise(Errors.SuperNotAllowed, node);
  13948. } else if (!this.scope.allowSuper && !(this.optionFlags & 16)) {
  13949. this.raise(Errors.UnexpectedSuper, node);
  13950. }
  13951. if (!this.match(10) && !this.match(0) && !this.match(16)) {
  13952. this.raise(Errors.UnsupportedSuper, node);
  13953. }
  13954. return this.finishNode(node, "Super");
  13955. }
  13956. parsePrivateName() {
  13957. const node = this.startNode();
  13958. const id = this.startNodeAt(createPositionWithColumnOffset(this.state.startLoc, 1));
  13959. const name = this.state.value;
  13960. this.next();
  13961. node.id = this.createIdentifier(id, name);
  13962. return this.finishNode(node, "PrivateName");
  13963. }
  13964. parseFunctionOrFunctionSent() {
  13965. const node = this.startNode();
  13966. this.next();
  13967. if (this.prodParam.hasYield && this.match(16)) {
  13968. const meta = this.createIdentifier(this.startNodeAtNode(node), "function");
  13969. this.next();
  13970. if (this.match(103)) {
  13971. this.expectPlugin("functionSent");
  13972. } else if (!this.hasPlugin("functionSent")) {
  13973. this.unexpected();
  13974. }
  13975. return this.parseMetaProperty(node, meta, "sent");
  13976. }
  13977. return this.parseFunction(node);
  13978. }
  13979. parseMetaProperty(node, meta, propertyName) {
  13980. node.meta = meta;
  13981. const containsEsc = this.state.containsEsc;
  13982. node.property = this.parseIdentifier(true);
  13983. if (node.property.name !== propertyName || containsEsc) {
  13984. this.raise(Errors.UnsupportedMetaProperty, node.property, {
  13985. target: meta.name,
  13986. onlyValidPropertyName: propertyName
  13987. });
  13988. }
  13989. return this.finishNode(node, "MetaProperty");
  13990. }
  13991. parseImportMetaPropertyOrPhaseCall(node) {
  13992. this.next();
  13993. if (this.isContextual(105) || this.isContextual(97)) {
  13994. const isSource = this.isContextual(105);
  13995. this.expectPlugin(isSource ? "sourcePhaseImports" : "deferredImportEvaluation");
  13996. this.next();
  13997. node.phase = isSource ? "source" : "defer";
  13998. return this.parseImportCall(node);
  13999. } else {
  14000. const id = this.createIdentifierAt(this.startNodeAtNode(node), "import", this.state.lastTokStartLoc);
  14001. if (this.isContextual(101)) {
  14002. if (!this.inModule) {
  14003. this.raise(Errors.ImportMetaOutsideModule, id);
  14004. }
  14005. this.sawUnambiguousESM = true;
  14006. }
  14007. return this.parseMetaProperty(node, id, "meta");
  14008. }
  14009. }
  14010. parseLiteralAtNode(value, type, node) {
  14011. this.addExtra(node, "rawValue", value);
  14012. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  14013. node.value = value;
  14014. this.next();
  14015. return this.finishNode(node, type);
  14016. }
  14017. parseLiteral(value, type) {
  14018. const node = this.startNode();
  14019. return this.parseLiteralAtNode(value, type, node);
  14020. }
  14021. parseStringLiteral(value) {
  14022. return this.parseLiteral(value, "StringLiteral");
  14023. }
  14024. parseNumericLiteral(value) {
  14025. return this.parseLiteral(value, "NumericLiteral");
  14026. }
  14027. parseBigIntLiteral(value) {
  14028. {
  14029. return this.parseLiteral(value, "BigIntLiteral");
  14030. }
  14031. }
  14032. parseDecimalLiteral(value) {
  14033. return this.parseLiteral(value, "DecimalLiteral");
  14034. }
  14035. parseRegExpLiteral(value) {
  14036. const node = this.startNode();
  14037. this.addExtra(node, "raw", this.input.slice(this.offsetToSourcePos(node.start), this.state.end));
  14038. node.pattern = value.pattern;
  14039. node.flags = value.flags;
  14040. this.next();
  14041. return this.finishNode(node, "RegExpLiteral");
  14042. }
  14043. parseBooleanLiteral(value) {
  14044. const node = this.startNode();
  14045. node.value = value;
  14046. this.next();
  14047. return this.finishNode(node, "BooleanLiteral");
  14048. }
  14049. parseNullLiteral() {
  14050. const node = this.startNode();
  14051. this.next();
  14052. return this.finishNode(node, "NullLiteral");
  14053. }
  14054. parseParenAndDistinguishExpression(canBeArrow) {
  14055. const startLoc = this.state.startLoc;
  14056. let val;
  14057. this.next();
  14058. this.expressionScope.enter(newArrowHeadScope());
  14059. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  14060. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14061. this.state.maybeInArrowParameters = true;
  14062. this.state.inFSharpPipelineDirectBody = false;
  14063. const innerStartLoc = this.state.startLoc;
  14064. const exprList = [];
  14065. const refExpressionErrors = new ExpressionErrors();
  14066. let first = true;
  14067. let spreadStartLoc;
  14068. let optionalCommaStartLoc;
  14069. while (!this.match(11)) {
  14070. if (first) {
  14071. first = false;
  14072. } else {
  14073. this.expect(12, refExpressionErrors.optionalParametersLoc === null ? null : refExpressionErrors.optionalParametersLoc);
  14074. if (this.match(11)) {
  14075. optionalCommaStartLoc = this.state.startLoc;
  14076. break;
  14077. }
  14078. }
  14079. if (this.match(21)) {
  14080. const spreadNodeStartLoc = this.state.startLoc;
  14081. spreadStartLoc = this.state.startLoc;
  14082. exprList.push(this.parseParenItem(this.parseRestBinding(), spreadNodeStartLoc));
  14083. if (!this.checkCommaAfterRest(41)) {
  14084. break;
  14085. }
  14086. } else {
  14087. exprList.push(this.parseMaybeAssignAllowInOrVoidPattern(11, refExpressionErrors, this.parseParenItem));
  14088. }
  14089. }
  14090. const innerEndLoc = this.state.lastTokEndLoc;
  14091. this.expect(11);
  14092. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  14093. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14094. let arrowNode = this.startNodeAt(startLoc);
  14095. if (canBeArrow && this.shouldParseArrow(exprList) && (arrowNode = this.parseArrow(arrowNode))) {
  14096. this.checkDestructuringPrivate(refExpressionErrors);
  14097. this.expressionScope.validateAsPattern();
  14098. this.expressionScope.exit();
  14099. this.parseArrowExpression(arrowNode, exprList, false);
  14100. return arrowNode;
  14101. }
  14102. this.expressionScope.exit();
  14103. if (!exprList.length) {
  14104. this.unexpected(this.state.lastTokStartLoc);
  14105. }
  14106. if (optionalCommaStartLoc) this.unexpected(optionalCommaStartLoc);
  14107. if (spreadStartLoc) this.unexpected(spreadStartLoc);
  14108. this.checkExpressionErrors(refExpressionErrors, true);
  14109. this.toReferencedListDeep(exprList, true);
  14110. if (exprList.length > 1) {
  14111. val = this.startNodeAt(innerStartLoc);
  14112. val.expressions = exprList;
  14113. this.finishNode(val, "SequenceExpression");
  14114. this.resetEndLocation(val, innerEndLoc);
  14115. } else {
  14116. val = exprList[0];
  14117. }
  14118. return this.wrapParenthesis(startLoc, val);
  14119. }
  14120. wrapParenthesis(startLoc, expression) {
  14121. if (!(this.optionFlags & 1024)) {
  14122. this.addExtra(expression, "parenthesized", true);
  14123. this.addExtra(expression, "parenStart", startLoc.index);
  14124. this.takeSurroundingComments(expression, startLoc.index, this.state.lastTokEndLoc.index);
  14125. return expression;
  14126. }
  14127. const parenExpression = this.startNodeAt(startLoc);
  14128. parenExpression.expression = expression;
  14129. return this.finishNode(parenExpression, "ParenthesizedExpression");
  14130. }
  14131. shouldParseArrow(params) {
  14132. return !this.canInsertSemicolon();
  14133. }
  14134. parseArrow(node) {
  14135. if (this.eat(19)) {
  14136. return node;
  14137. }
  14138. }
  14139. parseParenItem(node, startLoc) {
  14140. return node;
  14141. }
  14142. parseNewOrNewTarget() {
  14143. const node = this.startNode();
  14144. this.next();
  14145. if (this.match(16)) {
  14146. const meta = this.createIdentifier(this.startNodeAtNode(node), "new");
  14147. this.next();
  14148. const metaProp = this.parseMetaProperty(node, meta, "target");
  14149. if (!this.scope.allowNewTarget) {
  14150. this.raise(Errors.UnexpectedNewTarget, metaProp);
  14151. }
  14152. return metaProp;
  14153. }
  14154. return this.parseNew(node);
  14155. }
  14156. parseNew(node) {
  14157. this.parseNewCallee(node);
  14158. if (this.eat(10)) {
  14159. const args = this.parseExprList(11);
  14160. this.toReferencedList(args);
  14161. node.arguments = args;
  14162. } else {
  14163. node.arguments = [];
  14164. }
  14165. return this.finishNode(node, "NewExpression");
  14166. }
  14167. parseNewCallee(node) {
  14168. const isImport = this.match(83);
  14169. const callee = this.parseNoCallExpr();
  14170. node.callee = callee;
  14171. if (isImport && (callee.type === "Import" || callee.type === "ImportExpression")) {
  14172. this.raise(Errors.ImportCallNotNewExpression, callee);
  14173. }
  14174. }
  14175. parseTemplateElement(isTagged) {
  14176. const {
  14177. start,
  14178. startLoc,
  14179. end,
  14180. value
  14181. } = this.state;
  14182. const elemStart = start + 1;
  14183. const elem = this.startNodeAt(createPositionWithColumnOffset(startLoc, 1));
  14184. if (value === null) {
  14185. if (!isTagged) {
  14186. this.raise(Errors.InvalidEscapeSequenceTemplate, createPositionWithColumnOffset(this.state.firstInvalidTemplateEscapePos, 1));
  14187. }
  14188. }
  14189. const isTail = this.match(24);
  14190. const endOffset = isTail ? -1 : -2;
  14191. const elemEnd = end + endOffset;
  14192. elem.value = {
  14193. raw: this.input.slice(elemStart, elemEnd).replace(/\r\n?/g, "\n"),
  14194. cooked: value === null ? null : value.slice(1, endOffset)
  14195. };
  14196. elem.tail = isTail;
  14197. this.next();
  14198. const finishedNode = this.finishNode(elem, "TemplateElement");
  14199. this.resetEndLocation(finishedNode, createPositionWithColumnOffset(this.state.lastTokEndLoc, endOffset));
  14200. return finishedNode;
  14201. }
  14202. parseTemplate(isTagged) {
  14203. const node = this.startNode();
  14204. let curElt = this.parseTemplateElement(isTagged);
  14205. const quasis = [curElt];
  14206. const substitutions = [];
  14207. while (!curElt.tail) {
  14208. substitutions.push(this.parseTemplateSubstitution());
  14209. this.readTemplateContinuation();
  14210. quasis.push(curElt = this.parseTemplateElement(isTagged));
  14211. }
  14212. node.expressions = substitutions;
  14213. node.quasis = quasis;
  14214. return this.finishNode(node, "TemplateLiteral");
  14215. }
  14216. parseTemplateSubstitution() {
  14217. return this.parseExpression();
  14218. }
  14219. parseObjectLike(close, isPattern, isRecord, refExpressionErrors) {
  14220. if (isRecord) {
  14221. this.expectPlugin("recordAndTuple");
  14222. }
  14223. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14224. this.state.inFSharpPipelineDirectBody = false;
  14225. let sawProto = false;
  14226. let first = true;
  14227. const node = this.startNode();
  14228. node.properties = [];
  14229. this.next();
  14230. while (!this.match(close)) {
  14231. if (first) {
  14232. first = false;
  14233. } else {
  14234. this.expect(12);
  14235. if (this.match(close)) {
  14236. this.addTrailingCommaExtraToNode(node);
  14237. break;
  14238. }
  14239. }
  14240. let prop;
  14241. if (isPattern) {
  14242. prop = this.parseBindingProperty();
  14243. } else {
  14244. prop = this.parsePropertyDefinition(refExpressionErrors);
  14245. sawProto = this.checkProto(prop, isRecord, sawProto, refExpressionErrors);
  14246. }
  14247. if (isRecord && !this.isObjectProperty(prop) && prop.type !== "SpreadElement") {
  14248. this.raise(Errors.InvalidRecordProperty, prop);
  14249. }
  14250. {
  14251. if (prop.shorthand) {
  14252. this.addExtra(prop, "shorthand", true);
  14253. }
  14254. }
  14255. node.properties.push(prop);
  14256. }
  14257. this.next();
  14258. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14259. let type = "ObjectExpression";
  14260. if (isPattern) {
  14261. type = "ObjectPattern";
  14262. } else if (isRecord) {
  14263. type = "RecordExpression";
  14264. }
  14265. return this.finishNode(node, type);
  14266. }
  14267. addTrailingCommaExtraToNode(node) {
  14268. this.addExtra(node, "trailingComma", this.state.lastTokStartLoc.index);
  14269. this.addExtra(node, "trailingCommaLoc", this.state.lastTokStartLoc, false);
  14270. }
  14271. maybeAsyncOrAccessorProp(prop) {
  14272. return !prop.computed && prop.key.type === "Identifier" && (this.isLiteralPropertyName() || this.match(0) || this.match(55));
  14273. }
  14274. parsePropertyDefinition(refExpressionErrors) {
  14275. let decorators = [];
  14276. if (this.match(26)) {
  14277. if (this.hasPlugin("decorators")) {
  14278. this.raise(Errors.UnsupportedPropertyDecorator, this.state.startLoc);
  14279. }
  14280. while (this.match(26)) {
  14281. decorators.push(this.parseDecorator());
  14282. }
  14283. }
  14284. const prop = this.startNode();
  14285. let isAsync = false;
  14286. let isAccessor = false;
  14287. let startLoc;
  14288. if (this.match(21)) {
  14289. if (decorators.length) this.unexpected();
  14290. return this.parseSpread();
  14291. }
  14292. if (decorators.length) {
  14293. prop.decorators = decorators;
  14294. decorators = [];
  14295. }
  14296. prop.method = false;
  14297. if (refExpressionErrors) {
  14298. startLoc = this.state.startLoc;
  14299. }
  14300. let isGenerator = this.eat(55);
  14301. this.parsePropertyNamePrefixOperator(prop);
  14302. const containsEsc = this.state.containsEsc;
  14303. this.parsePropertyName(prop, refExpressionErrors);
  14304. if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
  14305. const {
  14306. key
  14307. } = prop;
  14308. const keyName = key.name;
  14309. if (keyName === "async" && !this.hasPrecedingLineBreak()) {
  14310. isAsync = true;
  14311. this.resetPreviousNodeTrailingComments(key);
  14312. isGenerator = this.eat(55);
  14313. this.parsePropertyName(prop);
  14314. }
  14315. if (keyName === "get" || keyName === "set") {
  14316. isAccessor = true;
  14317. this.resetPreviousNodeTrailingComments(key);
  14318. prop.kind = keyName;
  14319. if (this.match(55)) {
  14320. isGenerator = true;
  14321. this.raise(Errors.AccessorIsGenerator, this.state.curPosition(), {
  14322. kind: keyName
  14323. });
  14324. this.next();
  14325. }
  14326. this.parsePropertyName(prop);
  14327. }
  14328. }
  14329. return this.parseObjPropValue(prop, startLoc, isGenerator, isAsync, false, isAccessor, refExpressionErrors);
  14330. }
  14331. getGetterSetterExpectedParamCount(method) {
  14332. return method.kind === "get" ? 0 : 1;
  14333. }
  14334. getObjectOrClassMethodParams(method) {
  14335. return method.params;
  14336. }
  14337. checkGetterSetterParams(method) {
  14338. var _params;
  14339. const paramCount = this.getGetterSetterExpectedParamCount(method);
  14340. const params = this.getObjectOrClassMethodParams(method);
  14341. if (params.length !== paramCount) {
  14342. this.raise(method.kind === "get" ? Errors.BadGetterArity : Errors.BadSetterArity, method);
  14343. }
  14344. if (method.kind === "set" && ((_params = params[params.length - 1]) == null ? void 0 : _params.type) === "RestElement") {
  14345. this.raise(Errors.BadSetterRestParameter, method);
  14346. }
  14347. }
  14348. parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) {
  14349. if (isAccessor) {
  14350. const finishedProp = this.parseMethod(prop, isGenerator, false, false, false, "ObjectMethod");
  14351. this.checkGetterSetterParams(finishedProp);
  14352. return finishedProp;
  14353. }
  14354. if (isAsync || isGenerator || this.match(10)) {
  14355. if (isPattern) this.unexpected();
  14356. prop.kind = "method";
  14357. prop.method = true;
  14358. return this.parseMethod(prop, isGenerator, isAsync, false, false, "ObjectMethod");
  14359. }
  14360. }
  14361. parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) {
  14362. prop.shorthand = false;
  14363. if (this.eat(14)) {
  14364. prop.value = isPattern ? this.parseMaybeDefault(this.state.startLoc) : this.parseMaybeAssignAllowInOrVoidPattern(8, refExpressionErrors);
  14365. return this.finishObjectProperty(prop);
  14366. }
  14367. if (!prop.computed && prop.key.type === "Identifier") {
  14368. this.checkReservedWord(prop.key.name, prop.key.loc.start, true, false);
  14369. if (isPattern) {
  14370. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  14371. } else if (this.match(29)) {
  14372. const shorthandAssignLoc = this.state.startLoc;
  14373. if (refExpressionErrors != null) {
  14374. if (refExpressionErrors.shorthandAssignLoc === null) {
  14375. refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
  14376. }
  14377. } else {
  14378. this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
  14379. }
  14380. prop.value = this.parseMaybeDefault(startLoc, this.cloneIdentifier(prop.key));
  14381. } else {
  14382. prop.value = this.cloneIdentifier(prop.key);
  14383. }
  14384. prop.shorthand = true;
  14385. return this.finishObjectProperty(prop);
  14386. }
  14387. }
  14388. finishObjectProperty(node) {
  14389. return this.finishNode(node, "ObjectProperty");
  14390. }
  14391. parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern, isAccessor, refExpressionErrors) {
  14392. const node = this.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) || this.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors);
  14393. if (!node) this.unexpected();
  14394. return node;
  14395. }
  14396. parsePropertyName(prop, refExpressionErrors) {
  14397. if (this.eat(0)) {
  14398. prop.computed = true;
  14399. prop.key = this.parseMaybeAssignAllowIn();
  14400. this.expect(3);
  14401. } else {
  14402. const {
  14403. type,
  14404. value
  14405. } = this.state;
  14406. let key;
  14407. if (tokenIsKeywordOrIdentifier(type)) {
  14408. key = this.parseIdentifier(true);
  14409. } else {
  14410. switch (type) {
  14411. case 135:
  14412. key = this.parseNumericLiteral(value);
  14413. break;
  14414. case 134:
  14415. key = this.parseStringLiteral(value);
  14416. break;
  14417. case 136:
  14418. key = this.parseBigIntLiteral(value);
  14419. break;
  14420. case 139:
  14421. {
  14422. const privateKeyLoc = this.state.startLoc;
  14423. if (refExpressionErrors != null) {
  14424. if (refExpressionErrors.privateKeyLoc === null) {
  14425. refExpressionErrors.privateKeyLoc = privateKeyLoc;
  14426. }
  14427. } else {
  14428. this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
  14429. }
  14430. key = this.parsePrivateName();
  14431. break;
  14432. }
  14433. default:
  14434. if (type === 137) {
  14435. key = this.parseDecimalLiteral(value);
  14436. break;
  14437. }
  14438. this.unexpected();
  14439. }
  14440. }
  14441. prop.key = key;
  14442. if (type !== 139) {
  14443. prop.computed = false;
  14444. }
  14445. }
  14446. }
  14447. initFunction(node, isAsync) {
  14448. node.id = null;
  14449. node.generator = false;
  14450. node.async = isAsync;
  14451. }
  14452. parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) {
  14453. this.initFunction(node, isAsync);
  14454. node.generator = isGenerator;
  14455. this.scope.enter(514 | 16 | (inClassScope ? 576 : 0) | (allowDirectSuper ? 32 : 0));
  14456. this.prodParam.enter(functionFlags(isAsync, node.generator));
  14457. this.parseFunctionParams(node, isConstructor);
  14458. const finishedNode = this.parseFunctionBodyAndFinish(node, type, true);
  14459. this.prodParam.exit();
  14460. this.scope.exit();
  14461. return finishedNode;
  14462. }
  14463. parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
  14464. if (isTuple) {
  14465. this.expectPlugin("recordAndTuple");
  14466. }
  14467. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14468. this.state.inFSharpPipelineDirectBody = false;
  14469. const node = this.startNode();
  14470. this.next();
  14471. node.elements = this.parseExprList(close, !isTuple, refExpressionErrors, node);
  14472. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14473. return this.finishNode(node, isTuple ? "TupleExpression" : "ArrayExpression");
  14474. }
  14475. parseArrowExpression(node, params, isAsync, trailingCommaLoc) {
  14476. this.scope.enter(514 | 4);
  14477. let flags = functionFlags(isAsync, false);
  14478. if (!this.match(5) && this.prodParam.hasIn) {
  14479. flags |= 8;
  14480. }
  14481. this.prodParam.enter(flags);
  14482. this.initFunction(node, isAsync);
  14483. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  14484. if (params) {
  14485. this.state.maybeInArrowParameters = true;
  14486. this.setArrowFunctionParameters(node, params, trailingCommaLoc);
  14487. }
  14488. this.state.maybeInArrowParameters = false;
  14489. this.parseFunctionBody(node, true);
  14490. this.prodParam.exit();
  14491. this.scope.exit();
  14492. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  14493. return this.finishNode(node, "ArrowFunctionExpression");
  14494. }
  14495. setArrowFunctionParameters(node, params, trailingCommaLoc) {
  14496. this.toAssignableList(params, trailingCommaLoc, false);
  14497. node.params = params;
  14498. }
  14499. parseFunctionBodyAndFinish(node, type, isMethod = false) {
  14500. this.parseFunctionBody(node, false, isMethod);
  14501. return this.finishNode(node, type);
  14502. }
  14503. parseFunctionBody(node, allowExpression, isMethod = false) {
  14504. const isExpression = allowExpression && !this.match(5);
  14505. this.expressionScope.enter(newExpressionScope());
  14506. if (isExpression) {
  14507. node.body = this.parseMaybeAssign();
  14508. this.checkParams(node, false, allowExpression, false);
  14509. } else {
  14510. const oldStrict = this.state.strict;
  14511. const oldLabels = this.state.labels;
  14512. this.state.labels = [];
  14513. this.prodParam.enter(this.prodParam.currentFlags() | 4);
  14514. node.body = this.parseBlock(true, false, hasStrictModeDirective => {
  14515. const nonSimple = !this.isSimpleParamList(node.params);
  14516. if (hasStrictModeDirective && nonSimple) {
  14517. this.raise(Errors.IllegalLanguageModeDirective, (node.kind === "method" || node.kind === "constructor") && !!node.key ? node.key.loc.end : node);
  14518. }
  14519. const strictModeChanged = !oldStrict && this.state.strict;
  14520. this.checkParams(node, !this.state.strict && !allowExpression && !isMethod && !nonSimple, allowExpression, strictModeChanged);
  14521. if (this.state.strict && node.id) {
  14522. this.checkIdentifier(node.id, 65, strictModeChanged);
  14523. }
  14524. });
  14525. this.prodParam.exit();
  14526. this.state.labels = oldLabels;
  14527. }
  14528. this.expressionScope.exit();
  14529. }
  14530. isSimpleParameter(node) {
  14531. return node.type === "Identifier";
  14532. }
  14533. isSimpleParamList(params) {
  14534. for (let i = 0, len = params.length; i < len; i++) {
  14535. if (!this.isSimpleParameter(params[i])) return false;
  14536. }
  14537. return true;
  14538. }
  14539. checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
  14540. const checkClashes = !allowDuplicates && new Set();
  14541. const formalParameters = {
  14542. type: "FormalParameters"
  14543. };
  14544. for (const param of node.params) {
  14545. this.checkLVal(param, formalParameters, 5, checkClashes, strictModeChanged);
  14546. }
  14547. }
  14548. parseExprList(close, allowEmpty, refExpressionErrors, nodeForExtra) {
  14549. const elts = [];
  14550. let first = true;
  14551. while (!this.eat(close)) {
  14552. if (first) {
  14553. first = false;
  14554. } else {
  14555. this.expect(12);
  14556. if (this.match(close)) {
  14557. if (nodeForExtra) {
  14558. this.addTrailingCommaExtraToNode(nodeForExtra);
  14559. }
  14560. this.next();
  14561. break;
  14562. }
  14563. }
  14564. elts.push(this.parseExprListItem(close, allowEmpty, refExpressionErrors));
  14565. }
  14566. return elts;
  14567. }
  14568. parseExprListItem(close, allowEmpty, refExpressionErrors, allowPlaceholder) {
  14569. let elt;
  14570. if (this.match(12)) {
  14571. if (!allowEmpty) {
  14572. this.raise(Errors.UnexpectedToken, this.state.curPosition(), {
  14573. unexpected: ","
  14574. });
  14575. }
  14576. elt = null;
  14577. } else if (this.match(21)) {
  14578. const spreadNodeStartLoc = this.state.startLoc;
  14579. elt = this.parseParenItem(this.parseSpread(refExpressionErrors), spreadNodeStartLoc);
  14580. } else if (this.match(17)) {
  14581. this.expectPlugin("partialApplication");
  14582. if (!allowPlaceholder) {
  14583. this.raise(Errors.UnexpectedArgumentPlaceholder, this.state.startLoc);
  14584. }
  14585. const node = this.startNode();
  14586. this.next();
  14587. elt = this.finishNode(node, "ArgumentPlaceholder");
  14588. } else {
  14589. elt = this.parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, this.parseParenItem);
  14590. }
  14591. return elt;
  14592. }
  14593. parseIdentifier(liberal) {
  14594. const node = this.startNode();
  14595. const name = this.parseIdentifierName(liberal);
  14596. return this.createIdentifier(node, name);
  14597. }
  14598. createIdentifier(node, name) {
  14599. node.name = name;
  14600. node.loc.identifierName = name;
  14601. return this.finishNode(node, "Identifier");
  14602. }
  14603. createIdentifierAt(node, name, endLoc) {
  14604. node.name = name;
  14605. node.loc.identifierName = name;
  14606. return this.finishNodeAt(node, "Identifier", endLoc);
  14607. }
  14608. parseIdentifierName(liberal) {
  14609. let name;
  14610. const {
  14611. startLoc,
  14612. type
  14613. } = this.state;
  14614. if (tokenIsKeywordOrIdentifier(type)) {
  14615. name = this.state.value;
  14616. } else {
  14617. this.unexpected();
  14618. }
  14619. const tokenIsKeyword = tokenKeywordOrIdentifierIsKeyword(type);
  14620. if (liberal) {
  14621. if (tokenIsKeyword) {
  14622. this.replaceToken(132);
  14623. }
  14624. } else {
  14625. this.checkReservedWord(name, startLoc, tokenIsKeyword, false);
  14626. }
  14627. this.next();
  14628. return name;
  14629. }
  14630. checkReservedWord(word, startLoc, checkKeywords, isBinding) {
  14631. if (word.length > 10) {
  14632. return;
  14633. }
  14634. if (!canBeReservedWord(word)) {
  14635. return;
  14636. }
  14637. if (checkKeywords && isKeyword(word)) {
  14638. this.raise(Errors.UnexpectedKeyword, startLoc, {
  14639. keyword: word
  14640. });
  14641. return;
  14642. }
  14643. const reservedTest = !this.state.strict ? isReservedWord : isBinding ? isStrictBindReservedWord : isStrictReservedWord;
  14644. if (reservedTest(word, this.inModule)) {
  14645. this.raise(Errors.UnexpectedReservedWord, startLoc, {
  14646. reservedWord: word
  14647. });
  14648. return;
  14649. } else if (word === "yield") {
  14650. if (this.prodParam.hasYield) {
  14651. this.raise(Errors.YieldBindingIdentifier, startLoc);
  14652. return;
  14653. }
  14654. } else if (word === "await") {
  14655. if (this.prodParam.hasAwait) {
  14656. this.raise(Errors.AwaitBindingIdentifier, startLoc);
  14657. return;
  14658. }
  14659. if (this.scope.inStaticBlock) {
  14660. this.raise(Errors.AwaitBindingIdentifierInStaticBlock, startLoc);
  14661. return;
  14662. }
  14663. this.expressionScope.recordAsyncArrowParametersError(startLoc);
  14664. } else if (word === "arguments") {
  14665. if (this.scope.inClassAndNotInNonArrowFunction) {
  14666. this.raise(Errors.ArgumentsInClass, startLoc);
  14667. return;
  14668. }
  14669. }
  14670. }
  14671. recordAwaitIfAllowed() {
  14672. const isAwaitAllowed = this.prodParam.hasAwait;
  14673. if (isAwaitAllowed && !this.scope.inFunction) {
  14674. this.state.hasTopLevelAwait = true;
  14675. }
  14676. return isAwaitAllowed;
  14677. }
  14678. parseAwait(startLoc) {
  14679. const node = this.startNodeAt(startLoc);
  14680. this.expressionScope.recordParameterInitializerError(Errors.AwaitExpressionFormalParameter, node);
  14681. if (this.eat(55)) {
  14682. this.raise(Errors.ObsoleteAwaitStar, node);
  14683. }
  14684. if (!this.scope.inFunction && !(this.optionFlags & 1)) {
  14685. if (this.isAmbiguousPrefixOrIdentifier()) {
  14686. this.ambiguousScriptDifferentAst = true;
  14687. } else {
  14688. this.sawUnambiguousESM = true;
  14689. }
  14690. }
  14691. if (!this.state.soloAwait) {
  14692. node.argument = this.parseMaybeUnary(null, true);
  14693. }
  14694. return this.finishNode(node, "AwaitExpression");
  14695. }
  14696. isAmbiguousPrefixOrIdentifier() {
  14697. if (this.hasPrecedingLineBreak()) return true;
  14698. const {
  14699. type
  14700. } = this.state;
  14701. return type === 53 || type === 10 || type === 0 || tokenIsTemplate(type) || type === 102 && !this.state.containsEsc || type === 138 || type === 56 || this.hasPlugin("v8intrinsic") && type === 54;
  14702. }
  14703. parseYield(startLoc) {
  14704. const node = this.startNodeAt(startLoc);
  14705. this.expressionScope.recordParameterInitializerError(Errors.YieldInParameter, node);
  14706. let delegating = false;
  14707. let argument = null;
  14708. if (!this.hasPrecedingLineBreak()) {
  14709. delegating = this.eat(55);
  14710. switch (this.state.type) {
  14711. case 13:
  14712. case 140:
  14713. case 8:
  14714. case 11:
  14715. case 3:
  14716. case 9:
  14717. case 14:
  14718. case 12:
  14719. if (!delegating) break;
  14720. default:
  14721. argument = this.parseMaybeAssign();
  14722. }
  14723. }
  14724. node.delegate = delegating;
  14725. node.argument = argument;
  14726. return this.finishNode(node, "YieldExpression");
  14727. }
  14728. parseImportCall(node) {
  14729. this.next();
  14730. node.source = this.parseMaybeAssignAllowIn();
  14731. node.options = null;
  14732. if (this.eat(12)) {
  14733. if (!this.match(11)) {
  14734. node.options = this.parseMaybeAssignAllowIn();
  14735. if (this.eat(12)) {
  14736. this.addTrailingCommaExtraToNode(node.options);
  14737. if (!this.match(11)) {
  14738. do {
  14739. this.parseMaybeAssignAllowIn();
  14740. } while (this.eat(12) && !this.match(11));
  14741. this.raise(Errors.ImportCallArity, node);
  14742. }
  14743. }
  14744. } else {
  14745. this.addTrailingCommaExtraToNode(node.source);
  14746. }
  14747. }
  14748. this.expect(11);
  14749. return this.finishNode(node, "ImportExpression");
  14750. }
  14751. checkPipelineAtInfixOperator(left, leftStartLoc) {
  14752. if (this.hasPlugin(["pipelineOperator", {
  14753. proposal: "smart"
  14754. }])) {
  14755. if (left.type === "SequenceExpression") {
  14756. this.raise(Errors.PipelineHeadSequenceExpression, leftStartLoc);
  14757. }
  14758. }
  14759. }
  14760. parseSmartPipelineBodyInStyle(childExpr, startLoc) {
  14761. if (this.isSimpleReference(childExpr)) {
  14762. const bodyNode = this.startNodeAt(startLoc);
  14763. bodyNode.callee = childExpr;
  14764. return this.finishNode(bodyNode, "PipelineBareFunction");
  14765. } else {
  14766. const bodyNode = this.startNodeAt(startLoc);
  14767. this.checkSmartPipeTopicBodyEarlyErrors(startLoc);
  14768. bodyNode.expression = childExpr;
  14769. return this.finishNode(bodyNode, "PipelineTopicExpression");
  14770. }
  14771. }
  14772. isSimpleReference(expression) {
  14773. switch (expression.type) {
  14774. case "MemberExpression":
  14775. return !expression.computed && this.isSimpleReference(expression.object);
  14776. case "Identifier":
  14777. return true;
  14778. default:
  14779. return false;
  14780. }
  14781. }
  14782. checkSmartPipeTopicBodyEarlyErrors(startLoc) {
  14783. if (this.match(19)) {
  14784. throw this.raise(Errors.PipelineBodyNoArrow, this.state.startLoc);
  14785. }
  14786. if (!this.topicReferenceWasUsedInCurrentContext()) {
  14787. this.raise(Errors.PipelineTopicUnused, startLoc);
  14788. }
  14789. }
  14790. withTopicBindingContext(callback) {
  14791. const outerContextTopicState = this.state.topicContext;
  14792. this.state.topicContext = {
  14793. maxNumOfResolvableTopics: 1,
  14794. maxTopicIndex: null
  14795. };
  14796. try {
  14797. return callback();
  14798. } finally {
  14799. this.state.topicContext = outerContextTopicState;
  14800. }
  14801. }
  14802. withSmartMixTopicForbiddingContext(callback) {
  14803. if (this.hasPlugin(["pipelineOperator", {
  14804. proposal: "smart"
  14805. }])) {
  14806. const outerContextTopicState = this.state.topicContext;
  14807. this.state.topicContext = {
  14808. maxNumOfResolvableTopics: 0,
  14809. maxTopicIndex: null
  14810. };
  14811. try {
  14812. return callback();
  14813. } finally {
  14814. this.state.topicContext = outerContextTopicState;
  14815. }
  14816. } else {
  14817. return callback();
  14818. }
  14819. }
  14820. withSoloAwaitPermittingContext(callback) {
  14821. const outerContextSoloAwaitState = this.state.soloAwait;
  14822. this.state.soloAwait = true;
  14823. try {
  14824. return callback();
  14825. } finally {
  14826. this.state.soloAwait = outerContextSoloAwaitState;
  14827. }
  14828. }
  14829. allowInAnd(callback) {
  14830. const flags = this.prodParam.currentFlags();
  14831. const prodParamToSet = 8 & ~flags;
  14832. if (prodParamToSet) {
  14833. this.prodParam.enter(flags | 8);
  14834. try {
  14835. return callback();
  14836. } finally {
  14837. this.prodParam.exit();
  14838. }
  14839. }
  14840. return callback();
  14841. }
  14842. disallowInAnd(callback) {
  14843. const flags = this.prodParam.currentFlags();
  14844. const prodParamToClear = 8 & flags;
  14845. if (prodParamToClear) {
  14846. this.prodParam.enter(flags & -9);
  14847. try {
  14848. return callback();
  14849. } finally {
  14850. this.prodParam.exit();
  14851. }
  14852. }
  14853. return callback();
  14854. }
  14855. registerTopicReference() {
  14856. this.state.topicContext.maxTopicIndex = 0;
  14857. }
  14858. topicReferenceIsAllowedInCurrentContext() {
  14859. return this.state.topicContext.maxNumOfResolvableTopics >= 1;
  14860. }
  14861. topicReferenceWasUsedInCurrentContext() {
  14862. return this.state.topicContext.maxTopicIndex != null && this.state.topicContext.maxTopicIndex >= 0;
  14863. }
  14864. parseFSharpPipelineBody(prec) {
  14865. const startLoc = this.state.startLoc;
  14866. this.state.potentialArrowAt = this.state.start;
  14867. const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
  14868. this.state.inFSharpPipelineDirectBody = true;
  14869. const ret = this.parseExprOp(this.parseMaybeUnaryOrPrivate(), startLoc, prec);
  14870. this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
  14871. return ret;
  14872. }
  14873. parseModuleExpression() {
  14874. this.expectPlugin("moduleBlocks");
  14875. const node = this.startNode();
  14876. this.next();
  14877. if (!this.match(5)) {
  14878. this.unexpected(null, 5);
  14879. }
  14880. const program = this.startNodeAt(this.state.endLoc);
  14881. this.next();
  14882. const revertScopes = this.initializeScopes(true);
  14883. this.enterInitialScopes();
  14884. try {
  14885. node.body = this.parseProgram(program, 8, "module");
  14886. } finally {
  14887. revertScopes();
  14888. }
  14889. return this.finishNode(node, "ModuleExpression");
  14890. }
  14891. parseVoidPattern(refExpressionErrors) {
  14892. this.expectPlugin("discardBinding");
  14893. const node = this.startNode();
  14894. if (refExpressionErrors != null) {
  14895. refExpressionErrors.voidPatternLoc = this.state.startLoc;
  14896. }
  14897. this.next();
  14898. return this.finishNode(node, "VoidPattern");
  14899. }
  14900. parseMaybeAssignAllowInOrVoidPattern(close, refExpressionErrors, afterLeftParse) {
  14901. if (refExpressionErrors != null && this.match(88)) {
  14902. const nextCode = this.lookaheadCharCode();
  14903. if (nextCode === 44 || nextCode === (close === 3 ? 93 : close === 8 ? 125 : 41) || nextCode === 61) {
  14904. return this.parseMaybeDefault(this.state.startLoc, this.parseVoidPattern(refExpressionErrors));
  14905. }
  14906. }
  14907. return this.parseMaybeAssignAllowIn(refExpressionErrors, afterLeftParse);
  14908. }
  14909. parsePropertyNamePrefixOperator(prop) {}
  14910. }
  14911. const loopLabel = {
  14912. kind: 1
  14913. },
  14914. switchLabel = {
  14915. kind: 2
  14916. };
  14917. const loneSurrogate = /[\uD800-\uDFFF]/u;
  14918. const keywordRelationalOperator = /in(?:stanceof)?/y;
  14919. function babel7CompatTokens(tokens, input, startIndex) {
  14920. for (let i = 0; i < tokens.length; i++) {
  14921. const token = tokens[i];
  14922. const {
  14923. type
  14924. } = token;
  14925. if (typeof type === "number") {
  14926. {
  14927. if (type === 139) {
  14928. const {
  14929. loc,
  14930. start,
  14931. value,
  14932. end
  14933. } = token;
  14934. const hashEndPos = start + 1;
  14935. const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
  14936. tokens.splice(i, 1, new Token({
  14937. type: getExportedToken(27),
  14938. value: "#",
  14939. start: start,
  14940. end: hashEndPos,
  14941. startLoc: loc.start,
  14942. endLoc: hashEndLoc
  14943. }), new Token({
  14944. type: getExportedToken(132),
  14945. value: value,
  14946. start: hashEndPos,
  14947. end: end,
  14948. startLoc: hashEndLoc,
  14949. endLoc: loc.end
  14950. }));
  14951. i++;
  14952. continue;
  14953. }
  14954. if (tokenIsTemplate(type)) {
  14955. const {
  14956. loc,
  14957. start,
  14958. value,
  14959. end
  14960. } = token;
  14961. const backquoteEnd = start + 1;
  14962. const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
  14963. let startToken;
  14964. if (input.charCodeAt(start - startIndex) === 96) {
  14965. startToken = new Token({
  14966. type: getExportedToken(22),
  14967. value: "`",
  14968. start: start,
  14969. end: backquoteEnd,
  14970. startLoc: loc.start,
  14971. endLoc: backquoteEndLoc
  14972. });
  14973. } else {
  14974. startToken = new Token({
  14975. type: getExportedToken(8),
  14976. value: "}",
  14977. start: start,
  14978. end: backquoteEnd,
  14979. startLoc: loc.start,
  14980. endLoc: backquoteEndLoc
  14981. });
  14982. }
  14983. let templateValue, templateElementEnd, templateElementEndLoc, endToken;
  14984. if (type === 24) {
  14985. templateElementEnd = end - 1;
  14986. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
  14987. templateValue = value === null ? null : value.slice(1, -1);
  14988. endToken = new Token({
  14989. type: getExportedToken(22),
  14990. value: "`",
  14991. start: templateElementEnd,
  14992. end: end,
  14993. startLoc: templateElementEndLoc,
  14994. endLoc: loc.end
  14995. });
  14996. } else {
  14997. templateElementEnd = end - 2;
  14998. templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
  14999. templateValue = value === null ? null : value.slice(1, -2);
  15000. endToken = new Token({
  15001. type: getExportedToken(23),
  15002. value: "${",
  15003. start: templateElementEnd,
  15004. end: end,
  15005. startLoc: templateElementEndLoc,
  15006. endLoc: loc.end
  15007. });
  15008. }
  15009. tokens.splice(i, 1, startToken, new Token({
  15010. type: getExportedToken(20),
  15011. value: templateValue,
  15012. start: backquoteEnd,
  15013. end: templateElementEnd,
  15014. startLoc: backquoteEndLoc,
  15015. endLoc: templateElementEndLoc
  15016. }), endToken);
  15017. i += 2;
  15018. continue;
  15019. }
  15020. }
  15021. token.type = getExportedToken(type);
  15022. }
  15023. }
  15024. return tokens;
  15025. }
  15026. class StatementParser extends ExpressionParser {
  15027. parseTopLevel(file, program) {
  15028. file.program = this.parseProgram(program, 140, this.options.sourceType === "module" ? "module" : "script");
  15029. file.comments = this.comments;
  15030. if (this.optionFlags & 256) {
  15031. file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
  15032. }
  15033. return this.finishNode(file, "File");
  15034. }
  15035. parseProgram(program, end, sourceType) {
  15036. program.sourceType = sourceType;
  15037. program.interpreter = this.parseInterpreterDirective();
  15038. this.parseBlockBody(program, true, true, end);
  15039. if (this.inModule) {
  15040. if (!(this.optionFlags & 64) && this.scope.undefinedExports.size > 0) {
  15041. for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
  15042. this.raise(Errors.ModuleExportUndefined, at, {
  15043. localName
  15044. });
  15045. }
  15046. }
  15047. this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
  15048. }
  15049. let finishedProgram;
  15050. if (end === 140) {
  15051. finishedProgram = this.finishNode(program, "Program");
  15052. } else {
  15053. finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
  15054. }
  15055. return finishedProgram;
  15056. }
  15057. stmtToDirective(stmt) {
  15058. const directive = this.castNodeTo(stmt, "Directive");
  15059. const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
  15060. const expressionValue = directiveLiteral.value;
  15061. const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
  15062. const val = directiveLiteral.value = raw.slice(1, -1);
  15063. this.addExtra(directiveLiteral, "raw", raw);
  15064. this.addExtra(directiveLiteral, "rawValue", val);
  15065. this.addExtra(directiveLiteral, "expressionValue", expressionValue);
  15066. directive.value = directiveLiteral;
  15067. delete stmt.expression;
  15068. return directive;
  15069. }
  15070. parseInterpreterDirective() {
  15071. if (!this.match(28)) {
  15072. return null;
  15073. }
  15074. const node = this.startNode();
  15075. node.value = this.state.value;
  15076. this.next();
  15077. return this.finishNode(node, "InterpreterDirective");
  15078. }
  15079. isLet() {
  15080. if (!this.isContextual(100)) {
  15081. return false;
  15082. }
  15083. return this.hasFollowingBindingAtom();
  15084. }
  15085. isUsing() {
  15086. if (!this.isContextual(107)) {
  15087. return false;
  15088. }
  15089. const next = this.nextTokenInLineStart();
  15090. const nextCh = this.codePointAtPos(next);
  15091. return this.chStartsBindingIdentifier(nextCh, next);
  15092. }
  15093. isForUsing() {
  15094. if (!this.isContextual(107)) {
  15095. return false;
  15096. }
  15097. const next = this.nextTokenInLineStart();
  15098. const nextCh = this.codePointAtPos(next);
  15099. if (this.isUnparsedContextual(next, "of")) {
  15100. const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
  15101. if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
  15102. return false;
  15103. }
  15104. }
  15105. if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
  15106. return true;
  15107. }
  15108. return false;
  15109. }
  15110. isAwaitUsing() {
  15111. if (!this.isContextual(96)) {
  15112. return false;
  15113. }
  15114. let next = this.nextTokenInLineStart();
  15115. if (this.isUnparsedContextual(next, "using")) {
  15116. next = this.nextTokenInLineStartSince(next + 5);
  15117. const nextCh = this.codePointAtPos(next);
  15118. if (this.chStartsBindingIdentifier(nextCh, next)) {
  15119. return true;
  15120. }
  15121. }
  15122. return false;
  15123. }
  15124. chStartsBindingIdentifier(ch, pos) {
  15125. if (isIdentifierStart(ch)) {
  15126. keywordRelationalOperator.lastIndex = pos;
  15127. if (keywordRelationalOperator.test(this.input)) {
  15128. const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
  15129. if (!isIdentifierChar(endCh) && endCh !== 92) {
  15130. return false;
  15131. }
  15132. }
  15133. return true;
  15134. } else if (ch === 92) {
  15135. return true;
  15136. } else {
  15137. return false;
  15138. }
  15139. }
  15140. chStartsBindingPattern(ch) {
  15141. return ch === 91 || ch === 123;
  15142. }
  15143. hasFollowingBindingAtom() {
  15144. const next = this.nextTokenStart();
  15145. const nextCh = this.codePointAtPos(next);
  15146. return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
  15147. }
  15148. hasInLineFollowingBindingIdentifierOrBrace() {
  15149. const next = this.nextTokenInLineStart();
  15150. const nextCh = this.codePointAtPos(next);
  15151. return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
  15152. }
  15153. allowsUsing() {
  15154. return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
  15155. }
  15156. parseModuleItem() {
  15157. return this.parseStatementLike(1 | 2 | 4 | 8);
  15158. }
  15159. parseStatementListItem() {
  15160. return this.parseStatementLike(2 | 4 | (!this.options.annexB || this.state.strict ? 0 : 8));
  15161. }
  15162. parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
  15163. let flags = 0;
  15164. if (this.options.annexB && !this.state.strict) {
  15165. flags |= 4;
  15166. if (allowLabeledFunction) {
  15167. flags |= 8;
  15168. }
  15169. }
  15170. return this.parseStatementLike(flags);
  15171. }
  15172. parseStatement() {
  15173. return this.parseStatementLike(0);
  15174. }
  15175. parseStatementLike(flags) {
  15176. let decorators = null;
  15177. if (this.match(26)) {
  15178. decorators = this.parseDecorators(true);
  15179. }
  15180. return this.parseStatementContent(flags, decorators);
  15181. }
  15182. parseStatementContent(flags, decorators) {
  15183. const startType = this.state.type;
  15184. const node = this.startNode();
  15185. const allowDeclaration = !!(flags & 2);
  15186. const allowFunctionDeclaration = !!(flags & 4);
  15187. const topLevel = flags & 1;
  15188. switch (startType) {
  15189. case 60:
  15190. return this.parseBreakContinueStatement(node, true);
  15191. case 63:
  15192. return this.parseBreakContinueStatement(node, false);
  15193. case 64:
  15194. return this.parseDebuggerStatement(node);
  15195. case 90:
  15196. return this.parseDoWhileStatement(node);
  15197. case 91:
  15198. return this.parseForStatement(node);
  15199. case 68:
  15200. if (this.lookaheadCharCode() === 46) break;
  15201. if (!allowFunctionDeclaration) {
  15202. this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
  15203. }
  15204. return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
  15205. case 80:
  15206. if (!allowDeclaration) this.unexpected();
  15207. return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
  15208. case 69:
  15209. return this.parseIfStatement(node);
  15210. case 70:
  15211. return this.parseReturnStatement(node);
  15212. case 71:
  15213. return this.parseSwitchStatement(node);
  15214. case 72:
  15215. return this.parseThrowStatement(node);
  15216. case 73:
  15217. return this.parseTryStatement(node);
  15218. case 96:
  15219. if (this.isAwaitUsing()) {
  15220. if (!this.allowsUsing()) {
  15221. this.raise(Errors.UnexpectedUsingDeclaration, node);
  15222. } else if (!allowDeclaration) {
  15223. this.raise(Errors.UnexpectedLexicalDeclaration, node);
  15224. } else if (!this.recordAwaitIfAllowed()) {
  15225. this.raise(Errors.AwaitUsingNotInAsyncContext, node);
  15226. }
  15227. this.next();
  15228. return this.parseVarStatement(node, "await using");
  15229. }
  15230. break;
  15231. case 107:
  15232. if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
  15233. break;
  15234. }
  15235. if (!this.allowsUsing()) {
  15236. this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
  15237. } else if (!allowDeclaration) {
  15238. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  15239. }
  15240. return this.parseVarStatement(node, "using");
  15241. case 100:
  15242. {
  15243. if (this.state.containsEsc) {
  15244. break;
  15245. }
  15246. const next = this.nextTokenStart();
  15247. const nextCh = this.codePointAtPos(next);
  15248. if (nextCh !== 91) {
  15249. if (!allowDeclaration && this.hasFollowingLineBreak()) break;
  15250. if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
  15251. break;
  15252. }
  15253. }
  15254. }
  15255. case 75:
  15256. {
  15257. if (!allowDeclaration) {
  15258. this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
  15259. }
  15260. }
  15261. case 74:
  15262. {
  15263. const kind = this.state.value;
  15264. return this.parseVarStatement(node, kind);
  15265. }
  15266. case 92:
  15267. return this.parseWhileStatement(node);
  15268. case 76:
  15269. return this.parseWithStatement(node);
  15270. case 5:
  15271. return this.parseBlock();
  15272. case 13:
  15273. return this.parseEmptyStatement(node);
  15274. case 83:
  15275. {
  15276. const nextTokenCharCode = this.lookaheadCharCode();
  15277. if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
  15278. break;
  15279. }
  15280. }
  15281. case 82:
  15282. {
  15283. if (!(this.optionFlags & 8) && !topLevel) {
  15284. this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
  15285. }
  15286. this.next();
  15287. let result;
  15288. if (startType === 83) {
  15289. result = this.parseImport(node);
  15290. } else {
  15291. result = this.parseExport(node, decorators);
  15292. }
  15293. this.assertModuleNodeAllowed(result);
  15294. return result;
  15295. }
  15296. default:
  15297. {
  15298. if (this.isAsyncFunction()) {
  15299. if (!allowDeclaration) {
  15300. this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
  15301. }
  15302. this.next();
  15303. return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
  15304. }
  15305. }
  15306. }
  15307. const maybeName = this.state.value;
  15308. const expr = this.parseExpression();
  15309. if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(14)) {
  15310. return this.parseLabeledStatement(node, maybeName, expr, flags);
  15311. } else {
  15312. return this.parseExpressionStatement(node, expr, decorators);
  15313. }
  15314. }
  15315. assertModuleNodeAllowed(node) {
  15316. if (!(this.optionFlags & 8) && !this.inModule) {
  15317. this.raise(Errors.ImportOutsideModule, node);
  15318. }
  15319. }
  15320. decoratorsEnabledBeforeExport() {
  15321. if (this.hasPlugin("decorators-legacy")) return true;
  15322. return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
  15323. }
  15324. maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
  15325. if (maybeDecorators) {
  15326. var _classNode$decorators;
  15327. if ((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length) {
  15328. if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
  15329. this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
  15330. }
  15331. classNode.decorators.unshift(...maybeDecorators);
  15332. } else {
  15333. classNode.decorators = maybeDecorators;
  15334. }
  15335. this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
  15336. if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
  15337. }
  15338. return classNode;
  15339. }
  15340. canHaveLeadingDecorator() {
  15341. return this.match(80);
  15342. }
  15343. parseDecorators(allowExport) {
  15344. const decorators = [];
  15345. do {
  15346. decorators.push(this.parseDecorator());
  15347. } while (this.match(26));
  15348. if (this.match(82)) {
  15349. if (!allowExport) {
  15350. this.unexpected();
  15351. }
  15352. if (!this.decoratorsEnabledBeforeExport()) {
  15353. this.raise(Errors.DecoratorExportClass, this.state.startLoc);
  15354. }
  15355. } else if (!this.canHaveLeadingDecorator()) {
  15356. throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
  15357. }
  15358. return decorators;
  15359. }
  15360. parseDecorator() {
  15361. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  15362. const node = this.startNode();
  15363. this.next();
  15364. if (this.hasPlugin("decorators")) {
  15365. const startLoc = this.state.startLoc;
  15366. let expr;
  15367. if (this.match(10)) {
  15368. const startLoc = this.state.startLoc;
  15369. this.next();
  15370. expr = this.parseExpression();
  15371. this.expect(11);
  15372. expr = this.wrapParenthesis(startLoc, expr);
  15373. const paramsStartLoc = this.state.startLoc;
  15374. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  15375. if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
  15376. this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
  15377. }
  15378. } else {
  15379. expr = this.parseIdentifier(false);
  15380. while (this.eat(16)) {
  15381. const node = this.startNodeAt(startLoc);
  15382. node.object = expr;
  15383. if (this.match(139)) {
  15384. this.classScope.usePrivateName(this.state.value, this.state.startLoc);
  15385. node.property = this.parsePrivateName();
  15386. } else {
  15387. node.property = this.parseIdentifier(true);
  15388. }
  15389. node.computed = false;
  15390. expr = this.finishNode(node, "MemberExpression");
  15391. }
  15392. node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
  15393. }
  15394. } else {
  15395. node.expression = this.parseExprSubscripts();
  15396. }
  15397. return this.finishNode(node, "Decorator");
  15398. }
  15399. parseMaybeDecoratorArguments(expr, startLoc) {
  15400. if (this.eat(10)) {
  15401. const node = this.startNodeAt(startLoc);
  15402. node.callee = expr;
  15403. node.arguments = this.parseCallExpressionArguments();
  15404. this.toReferencedList(node.arguments);
  15405. return this.finishNode(node, "CallExpression");
  15406. }
  15407. return expr;
  15408. }
  15409. parseBreakContinueStatement(node, isBreak) {
  15410. this.next();
  15411. if (this.isLineTerminator()) {
  15412. node.label = null;
  15413. } else {
  15414. node.label = this.parseIdentifier();
  15415. this.semicolon();
  15416. }
  15417. this.verifyBreakContinue(node, isBreak);
  15418. return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
  15419. }
  15420. verifyBreakContinue(node, isBreak) {
  15421. let i;
  15422. for (i = 0; i < this.state.labels.length; ++i) {
  15423. const lab = this.state.labels[i];
  15424. if (node.label == null || lab.name === node.label.name) {
  15425. if (lab.kind != null && (isBreak || lab.kind === 1)) {
  15426. break;
  15427. }
  15428. if (node.label && isBreak) break;
  15429. }
  15430. }
  15431. if (i === this.state.labels.length) {
  15432. const type = isBreak ? "BreakStatement" : "ContinueStatement";
  15433. this.raise(Errors.IllegalBreakContinue, node, {
  15434. type
  15435. });
  15436. }
  15437. }
  15438. parseDebuggerStatement(node) {
  15439. this.next();
  15440. this.semicolon();
  15441. return this.finishNode(node, "DebuggerStatement");
  15442. }
  15443. parseHeaderExpression() {
  15444. this.expect(10);
  15445. const val = this.parseExpression();
  15446. this.expect(11);
  15447. return val;
  15448. }
  15449. parseDoWhileStatement(node) {
  15450. this.next();
  15451. this.state.labels.push(loopLabel);
  15452. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15453. this.state.labels.pop();
  15454. this.expect(92);
  15455. node.test = this.parseHeaderExpression();
  15456. this.eat(13);
  15457. return this.finishNode(node, "DoWhileStatement");
  15458. }
  15459. parseForStatement(node) {
  15460. this.next();
  15461. this.state.labels.push(loopLabel);
  15462. let awaitAt = null;
  15463. if (this.isContextual(96) && this.recordAwaitIfAllowed()) {
  15464. awaitAt = this.state.startLoc;
  15465. this.next();
  15466. }
  15467. this.scope.enter(0);
  15468. this.expect(10);
  15469. if (this.match(13)) {
  15470. if (awaitAt !== null) {
  15471. this.unexpected(awaitAt);
  15472. }
  15473. return this.parseFor(node, null);
  15474. }
  15475. const startsWithLet = this.isContextual(100);
  15476. {
  15477. const startsWithAwaitUsing = this.isAwaitUsing();
  15478. const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
  15479. const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
  15480. if (this.match(74) || this.match(75) || isLetOrUsing) {
  15481. const initNode = this.startNode();
  15482. let kind;
  15483. if (startsWithAwaitUsing) {
  15484. kind = "await using";
  15485. if (!this.recordAwaitIfAllowed()) {
  15486. this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
  15487. }
  15488. this.next();
  15489. } else {
  15490. kind = this.state.value;
  15491. }
  15492. this.next();
  15493. this.parseVar(initNode, true, kind);
  15494. const init = this.finishNode(initNode, "VariableDeclaration");
  15495. const isForIn = this.match(58);
  15496. if (isForIn && starsWithUsingDeclaration) {
  15497. this.raise(Errors.ForInUsing, init);
  15498. }
  15499. if ((isForIn || this.isContextual(102)) && init.declarations.length === 1) {
  15500. return this.parseForIn(node, init, awaitAt);
  15501. }
  15502. if (awaitAt !== null) {
  15503. this.unexpected(awaitAt);
  15504. }
  15505. return this.parseFor(node, init);
  15506. }
  15507. }
  15508. const startsWithAsync = this.isContextual(95);
  15509. const refExpressionErrors = new ExpressionErrors();
  15510. const init = this.parseExpression(true, refExpressionErrors);
  15511. const isForOf = this.isContextual(102);
  15512. if (isForOf) {
  15513. if (startsWithLet) {
  15514. this.raise(Errors.ForOfLet, init);
  15515. }
  15516. if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
  15517. this.raise(Errors.ForOfAsync, init);
  15518. }
  15519. }
  15520. if (isForOf || this.match(58)) {
  15521. this.checkDestructuringPrivate(refExpressionErrors);
  15522. this.toAssignable(init, true);
  15523. const type = isForOf ? "ForOfStatement" : "ForInStatement";
  15524. this.checkLVal(init, {
  15525. type
  15526. });
  15527. return this.parseForIn(node, init, awaitAt);
  15528. } else {
  15529. this.checkExpressionErrors(refExpressionErrors, true);
  15530. }
  15531. if (awaitAt !== null) {
  15532. this.unexpected(awaitAt);
  15533. }
  15534. return this.parseFor(node, init);
  15535. }
  15536. parseFunctionStatement(node, isAsync, isHangingDeclaration) {
  15537. this.next();
  15538. return this.parseFunction(node, 1 | (isHangingDeclaration ? 2 : 0) | (isAsync ? 8 : 0));
  15539. }
  15540. parseIfStatement(node) {
  15541. this.next();
  15542. node.test = this.parseHeaderExpression();
  15543. node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
  15544. node.alternate = this.eat(66) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
  15545. return this.finishNode(node, "IfStatement");
  15546. }
  15547. parseReturnStatement(node) {
  15548. if (!this.prodParam.hasReturn) {
  15549. this.raise(Errors.IllegalReturn, this.state.startLoc);
  15550. }
  15551. this.next();
  15552. if (this.isLineTerminator()) {
  15553. node.argument = null;
  15554. } else {
  15555. node.argument = this.parseExpression();
  15556. this.semicolon();
  15557. }
  15558. return this.finishNode(node, "ReturnStatement");
  15559. }
  15560. parseSwitchStatement(node) {
  15561. this.next();
  15562. node.discriminant = this.parseHeaderExpression();
  15563. const cases = node.cases = [];
  15564. this.expect(5);
  15565. this.state.labels.push(switchLabel);
  15566. this.scope.enter(256);
  15567. let cur;
  15568. for (let sawDefault; !this.match(8);) {
  15569. if (this.match(61) || this.match(65)) {
  15570. const isCase = this.match(61);
  15571. if (cur) this.finishNode(cur, "SwitchCase");
  15572. cases.push(cur = this.startNode());
  15573. cur.consequent = [];
  15574. this.next();
  15575. if (isCase) {
  15576. cur.test = this.parseExpression();
  15577. } else {
  15578. if (sawDefault) {
  15579. this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
  15580. }
  15581. sawDefault = true;
  15582. cur.test = null;
  15583. }
  15584. this.expect(14);
  15585. } else {
  15586. if (cur) {
  15587. cur.consequent.push(this.parseStatementListItem());
  15588. } else {
  15589. this.unexpected();
  15590. }
  15591. }
  15592. }
  15593. this.scope.exit();
  15594. if (cur) this.finishNode(cur, "SwitchCase");
  15595. this.next();
  15596. this.state.labels.pop();
  15597. return this.finishNode(node, "SwitchStatement");
  15598. }
  15599. parseThrowStatement(node) {
  15600. this.next();
  15601. if (this.hasPrecedingLineBreak()) {
  15602. this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
  15603. }
  15604. node.argument = this.parseExpression();
  15605. this.semicolon();
  15606. return this.finishNode(node, "ThrowStatement");
  15607. }
  15608. parseCatchClauseParam() {
  15609. const param = this.parseBindingAtom();
  15610. this.scope.enter(this.options.annexB && param.type === "Identifier" ? 8 : 0);
  15611. this.checkLVal(param, {
  15612. type: "CatchClause"
  15613. }, 9);
  15614. return param;
  15615. }
  15616. parseTryStatement(node) {
  15617. this.next();
  15618. node.block = this.parseBlock();
  15619. node.handler = null;
  15620. if (this.match(62)) {
  15621. const clause = this.startNode();
  15622. this.next();
  15623. if (this.match(10)) {
  15624. this.expect(10);
  15625. clause.param = this.parseCatchClauseParam();
  15626. this.expect(11);
  15627. } else {
  15628. clause.param = null;
  15629. this.scope.enter(0);
  15630. }
  15631. clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
  15632. this.scope.exit();
  15633. node.handler = this.finishNode(clause, "CatchClause");
  15634. }
  15635. node.finalizer = this.eat(67) ? this.parseBlock() : null;
  15636. if (!node.handler && !node.finalizer) {
  15637. this.raise(Errors.NoCatchOrFinally, node);
  15638. }
  15639. return this.finishNode(node, "TryStatement");
  15640. }
  15641. parseVarStatement(node, kind, allowMissingInitializer = false) {
  15642. this.next();
  15643. this.parseVar(node, false, kind, allowMissingInitializer);
  15644. this.semicolon();
  15645. return this.finishNode(node, "VariableDeclaration");
  15646. }
  15647. parseWhileStatement(node) {
  15648. this.next();
  15649. node.test = this.parseHeaderExpression();
  15650. this.state.labels.push(loopLabel);
  15651. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15652. this.state.labels.pop();
  15653. return this.finishNode(node, "WhileStatement");
  15654. }
  15655. parseWithStatement(node) {
  15656. if (this.state.strict) {
  15657. this.raise(Errors.StrictWith, this.state.startLoc);
  15658. }
  15659. this.next();
  15660. node.object = this.parseHeaderExpression();
  15661. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15662. return this.finishNode(node, "WithStatement");
  15663. }
  15664. parseEmptyStatement(node) {
  15665. this.next();
  15666. return this.finishNode(node, "EmptyStatement");
  15667. }
  15668. parseLabeledStatement(node, maybeName, expr, flags) {
  15669. for (const label of this.state.labels) {
  15670. if (label.name === maybeName) {
  15671. this.raise(Errors.LabelRedeclaration, expr, {
  15672. labelName: maybeName
  15673. });
  15674. }
  15675. }
  15676. const kind = tokenIsLoop(this.state.type) ? 1 : this.match(71) ? 2 : null;
  15677. for (let i = this.state.labels.length - 1; i >= 0; i--) {
  15678. const label = this.state.labels[i];
  15679. if (label.statementStart === node.start) {
  15680. label.statementStart = this.sourceToOffsetPos(this.state.start);
  15681. label.kind = kind;
  15682. } else {
  15683. break;
  15684. }
  15685. }
  15686. this.state.labels.push({
  15687. name: maybeName,
  15688. kind: kind,
  15689. statementStart: this.sourceToOffsetPos(this.state.start)
  15690. });
  15691. node.body = flags & 8 ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
  15692. this.state.labels.pop();
  15693. node.label = expr;
  15694. return this.finishNode(node, "LabeledStatement");
  15695. }
  15696. parseExpressionStatement(node, expr, decorators) {
  15697. node.expression = expr;
  15698. this.semicolon();
  15699. return this.finishNode(node, "ExpressionStatement");
  15700. }
  15701. parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
  15702. const node = this.startNode();
  15703. if (allowDirectives) {
  15704. this.state.strictErrors.clear();
  15705. }
  15706. this.expect(5);
  15707. if (createNewLexicalScope) {
  15708. this.scope.enter(0);
  15709. }
  15710. this.parseBlockBody(node, allowDirectives, false, 8, afterBlockParse);
  15711. if (createNewLexicalScope) {
  15712. this.scope.exit();
  15713. }
  15714. return this.finishNode(node, "BlockStatement");
  15715. }
  15716. isValidDirective(stmt) {
  15717. return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
  15718. }
  15719. parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
  15720. const body = node.body = [];
  15721. const directives = node.directives = [];
  15722. this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end, afterBlockParse);
  15723. }
  15724. parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
  15725. const oldStrict = this.state.strict;
  15726. let hasStrictModeDirective = false;
  15727. let parsedNonDirective = false;
  15728. while (!this.match(end)) {
  15729. const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
  15730. if (directives && !parsedNonDirective) {
  15731. if (this.isValidDirective(stmt)) {
  15732. const directive = this.stmtToDirective(stmt);
  15733. directives.push(directive);
  15734. if (!hasStrictModeDirective && directive.value.value === "use strict") {
  15735. hasStrictModeDirective = true;
  15736. this.setStrict(true);
  15737. }
  15738. continue;
  15739. }
  15740. parsedNonDirective = true;
  15741. this.state.strictErrors.clear();
  15742. }
  15743. body.push(stmt);
  15744. }
  15745. afterBlockParse == null || afterBlockParse.call(this, hasStrictModeDirective);
  15746. if (!oldStrict) {
  15747. this.setStrict(false);
  15748. }
  15749. this.next();
  15750. }
  15751. parseFor(node, init) {
  15752. node.init = init;
  15753. this.semicolon(false);
  15754. node.test = this.match(13) ? null : this.parseExpression();
  15755. this.semicolon(false);
  15756. node.update = this.match(11) ? null : this.parseExpression();
  15757. this.expect(11);
  15758. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15759. this.scope.exit();
  15760. this.state.labels.pop();
  15761. return this.finishNode(node, "ForStatement");
  15762. }
  15763. parseForIn(node, init, awaitAt) {
  15764. const isForIn = this.match(58);
  15765. this.next();
  15766. if (isForIn) {
  15767. if (awaitAt !== null) this.unexpected(awaitAt);
  15768. } else {
  15769. node.await = awaitAt !== null;
  15770. }
  15771. 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")) {
  15772. this.raise(Errors.ForInOfLoopInitializer, init, {
  15773. type: isForIn ? "ForInStatement" : "ForOfStatement"
  15774. });
  15775. }
  15776. if (init.type === "AssignmentPattern") {
  15777. this.raise(Errors.InvalidLhs, init, {
  15778. ancestor: {
  15779. type: "ForStatement"
  15780. }
  15781. });
  15782. }
  15783. node.left = init;
  15784. node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
  15785. this.expect(11);
  15786. node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
  15787. this.scope.exit();
  15788. this.state.labels.pop();
  15789. return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
  15790. }
  15791. parseVar(node, isFor, kind, allowMissingInitializer = false) {
  15792. const declarations = node.declarations = [];
  15793. node.kind = kind;
  15794. for (;;) {
  15795. const decl = this.startNode();
  15796. this.parseVarId(decl, kind);
  15797. decl.init = !this.eat(29) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
  15798. if (decl.init === null && !allowMissingInitializer) {
  15799. if (decl.id.type !== "Identifier" && !(isFor && (this.match(58) || this.isContextual(102)))) {
  15800. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  15801. kind: "destructuring"
  15802. });
  15803. } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(58) || this.isContextual(102))) {
  15804. this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
  15805. kind
  15806. });
  15807. }
  15808. }
  15809. declarations.push(this.finishNode(decl, "VariableDeclarator"));
  15810. if (!this.eat(12)) break;
  15811. }
  15812. return node;
  15813. }
  15814. parseVarId(decl, kind) {
  15815. const id = this.parseBindingAtom();
  15816. if (kind === "using" || kind === "await using") {
  15817. if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
  15818. this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
  15819. }
  15820. } else {
  15821. if (id.type === "VoidPattern") {
  15822. this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
  15823. }
  15824. }
  15825. this.checkLVal(id, {
  15826. type: "VariableDeclarator"
  15827. }, kind === "var" ? 5 : 8201);
  15828. decl.id = id;
  15829. }
  15830. parseAsyncFunctionExpression(node) {
  15831. return this.parseFunction(node, 8);
  15832. }
  15833. parseFunction(node, flags = 0) {
  15834. const hangingDeclaration = flags & 2;
  15835. const isDeclaration = !!(flags & 1);
  15836. const requireId = isDeclaration && !(flags & 4);
  15837. const isAsync = !!(flags & 8);
  15838. this.initFunction(node, isAsync);
  15839. if (this.match(55)) {
  15840. if (hangingDeclaration) {
  15841. this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
  15842. }
  15843. this.next();
  15844. node.generator = true;
  15845. }
  15846. if (isDeclaration) {
  15847. node.id = this.parseFunctionId(requireId);
  15848. }
  15849. const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
  15850. this.state.maybeInArrowParameters = false;
  15851. this.scope.enter(514);
  15852. this.prodParam.enter(functionFlags(isAsync, node.generator));
  15853. if (!isDeclaration) {
  15854. node.id = this.parseFunctionId();
  15855. }
  15856. this.parseFunctionParams(node, false);
  15857. this.withSmartMixTopicForbiddingContext(() => {
  15858. this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
  15859. });
  15860. this.prodParam.exit();
  15861. this.scope.exit();
  15862. if (isDeclaration && !hangingDeclaration) {
  15863. this.registerFunctionStatementId(node);
  15864. }
  15865. this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
  15866. return node;
  15867. }
  15868. parseFunctionId(requireId) {
  15869. return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
  15870. }
  15871. parseFunctionParams(node, isConstructor) {
  15872. this.expect(10);
  15873. this.expressionScope.enter(newParameterDeclarationScope());
  15874. node.params = this.parseBindingList(11, 41, 2 | (isConstructor ? 4 : 0));
  15875. this.expressionScope.exit();
  15876. }
  15877. registerFunctionStatementId(node) {
  15878. if (!node.id) return;
  15879. 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);
  15880. }
  15881. parseClass(node, isStatement, optionalId) {
  15882. this.next();
  15883. const oldStrict = this.state.strict;
  15884. this.state.strict = true;
  15885. this.parseClassId(node, isStatement, optionalId);
  15886. this.parseClassSuper(node);
  15887. node.body = this.parseClassBody(!!node.superClass, oldStrict);
  15888. return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
  15889. }
  15890. isClassProperty() {
  15891. return this.match(29) || this.match(13) || this.match(8);
  15892. }
  15893. isClassMethod() {
  15894. return this.match(10);
  15895. }
  15896. nameIsConstructor(key) {
  15897. return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
  15898. }
  15899. isNonstaticConstructor(method) {
  15900. return !method.computed && !method.static && this.nameIsConstructor(method.key);
  15901. }
  15902. parseClassBody(hadSuperClass, oldStrict) {
  15903. this.classScope.enter();
  15904. const state = {
  15905. hadConstructor: false,
  15906. hadSuperClass
  15907. };
  15908. let decorators = [];
  15909. const classBody = this.startNode();
  15910. classBody.body = [];
  15911. this.expect(5);
  15912. this.withSmartMixTopicForbiddingContext(() => {
  15913. while (!this.match(8)) {
  15914. if (this.eat(13)) {
  15915. if (decorators.length > 0) {
  15916. throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
  15917. }
  15918. continue;
  15919. }
  15920. if (this.match(26)) {
  15921. decorators.push(this.parseDecorator());
  15922. continue;
  15923. }
  15924. const member = this.startNode();
  15925. if (decorators.length) {
  15926. member.decorators = decorators;
  15927. this.resetStartLocationFromNode(member, decorators[0]);
  15928. decorators = [];
  15929. }
  15930. this.parseClassMember(classBody, member, state);
  15931. if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
  15932. this.raise(Errors.DecoratorConstructor, member);
  15933. }
  15934. }
  15935. });
  15936. this.state.strict = oldStrict;
  15937. this.next();
  15938. if (decorators.length) {
  15939. throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
  15940. }
  15941. this.classScope.exit();
  15942. return this.finishNode(classBody, "ClassBody");
  15943. }
  15944. parseClassMemberFromModifier(classBody, member) {
  15945. const key = this.parseIdentifier(true);
  15946. if (this.isClassMethod()) {
  15947. const method = member;
  15948. method.kind = "method";
  15949. method.computed = false;
  15950. method.key = key;
  15951. method.static = false;
  15952. this.pushClassMethod(classBody, method, false, false, false, false);
  15953. return true;
  15954. } else if (this.isClassProperty()) {
  15955. const prop = member;
  15956. prop.computed = false;
  15957. prop.key = key;
  15958. prop.static = false;
  15959. classBody.body.push(this.parseClassProperty(prop));
  15960. return true;
  15961. }
  15962. this.resetPreviousNodeTrailingComments(key);
  15963. return false;
  15964. }
  15965. parseClassMember(classBody, member, state) {
  15966. const isStatic = this.isContextual(106);
  15967. if (isStatic) {
  15968. if (this.parseClassMemberFromModifier(classBody, member)) {
  15969. return;
  15970. }
  15971. if (this.eat(5)) {
  15972. this.parseClassStaticBlock(classBody, member);
  15973. return;
  15974. }
  15975. }
  15976. this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
  15977. }
  15978. parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
  15979. const publicMethod = member;
  15980. const privateMethod = member;
  15981. const publicProp = member;
  15982. const privateProp = member;
  15983. const accessorProp = member;
  15984. const method = publicMethod;
  15985. const publicMember = publicMethod;
  15986. member.static = isStatic;
  15987. this.parsePropertyNamePrefixOperator(member);
  15988. if (this.eat(55)) {
  15989. method.kind = "method";
  15990. const isPrivateName = this.match(139);
  15991. this.parseClassElementName(method);
  15992. this.parsePostMemberNameModifiers(method);
  15993. if (isPrivateName) {
  15994. this.pushClassPrivateMethod(classBody, privateMethod, true, false);
  15995. return;
  15996. }
  15997. if (this.isNonstaticConstructor(publicMethod)) {
  15998. this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
  15999. }
  16000. this.pushClassMethod(classBody, publicMethod, true, false, false, false);
  16001. return;
  16002. }
  16003. const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
  16004. const key = this.parseClassElementName(member);
  16005. const maybeContextualKw = isContextual ? key.name : null;
  16006. const isPrivate = this.isPrivateName(key);
  16007. const maybeQuestionTokenStartLoc = this.state.startLoc;
  16008. this.parsePostMemberNameModifiers(publicMember);
  16009. if (this.isClassMethod()) {
  16010. method.kind = "method";
  16011. if (isPrivate) {
  16012. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  16013. return;
  16014. }
  16015. const isConstructor = this.isNonstaticConstructor(publicMethod);
  16016. let allowsDirectSuper = false;
  16017. if (isConstructor) {
  16018. publicMethod.kind = "constructor";
  16019. if (state.hadConstructor && !this.hasPlugin("typescript")) {
  16020. this.raise(Errors.DuplicateConstructor, key);
  16021. }
  16022. if (isConstructor && this.hasPlugin("typescript") && member.override) {
  16023. this.raise(Errors.OverrideOnConstructor, key);
  16024. }
  16025. state.hadConstructor = true;
  16026. allowsDirectSuper = state.hadSuperClass;
  16027. }
  16028. this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
  16029. } else if (this.isClassProperty()) {
  16030. if (isPrivate) {
  16031. this.pushClassPrivateProperty(classBody, privateProp);
  16032. } else {
  16033. this.pushClassProperty(classBody, publicProp);
  16034. }
  16035. } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
  16036. this.resetPreviousNodeTrailingComments(key);
  16037. const isGenerator = this.eat(55);
  16038. if (publicMember.optional) {
  16039. this.unexpected(maybeQuestionTokenStartLoc);
  16040. }
  16041. method.kind = "method";
  16042. const isPrivate = this.match(139);
  16043. this.parseClassElementName(method);
  16044. this.parsePostMemberNameModifiers(publicMember);
  16045. if (isPrivate) {
  16046. this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
  16047. } else {
  16048. if (this.isNonstaticConstructor(publicMethod)) {
  16049. this.raise(Errors.ConstructorIsAsync, publicMethod.key);
  16050. }
  16051. this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
  16052. }
  16053. } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(55) && this.isLineTerminator())) {
  16054. this.resetPreviousNodeTrailingComments(key);
  16055. method.kind = maybeContextualKw;
  16056. const isPrivate = this.match(139);
  16057. this.parseClassElementName(publicMethod);
  16058. if (isPrivate) {
  16059. this.pushClassPrivateMethod(classBody, privateMethod, false, false);
  16060. } else {
  16061. if (this.isNonstaticConstructor(publicMethod)) {
  16062. this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
  16063. }
  16064. this.pushClassMethod(classBody, publicMethod, false, false, false, false);
  16065. }
  16066. this.checkGetterSetterParams(publicMethod);
  16067. } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
  16068. this.expectPlugin("decoratorAutoAccessors");
  16069. this.resetPreviousNodeTrailingComments(key);
  16070. const isPrivate = this.match(139);
  16071. this.parseClassElementName(publicProp);
  16072. this.pushClassAccessorProperty(classBody, accessorProp, isPrivate);
  16073. } else if (this.isLineTerminator()) {
  16074. if (isPrivate) {
  16075. this.pushClassPrivateProperty(classBody, privateProp);
  16076. } else {
  16077. this.pushClassProperty(classBody, publicProp);
  16078. }
  16079. } else {
  16080. this.unexpected();
  16081. }
  16082. }
  16083. parseClassElementName(member) {
  16084. const {
  16085. type,
  16086. value
  16087. } = this.state;
  16088. if ((type === 132 || type === 134) && member.static && value === "prototype") {
  16089. this.raise(Errors.StaticPrototype, this.state.startLoc);
  16090. }
  16091. if (type === 139) {
  16092. if (value === "constructor") {
  16093. this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
  16094. }
  16095. const key = this.parsePrivateName();
  16096. member.key = key;
  16097. return key;
  16098. }
  16099. this.parsePropertyName(member);
  16100. return member.key;
  16101. }
  16102. parseClassStaticBlock(classBody, member) {
  16103. var _member$decorators;
  16104. this.scope.enter(576 | 128 | 16);
  16105. const oldLabels = this.state.labels;
  16106. this.state.labels = [];
  16107. this.prodParam.enter(0);
  16108. const body = member.body = [];
  16109. this.parseBlockOrModuleBlockBody(body, undefined, false, 8);
  16110. this.prodParam.exit();
  16111. this.scope.exit();
  16112. this.state.labels = oldLabels;
  16113. classBody.body.push(this.finishNode(member, "StaticBlock"));
  16114. if ((_member$decorators = member.decorators) != null && _member$decorators.length) {
  16115. this.raise(Errors.DecoratorStaticBlock, member);
  16116. }
  16117. }
  16118. pushClassProperty(classBody, prop) {
  16119. if (!prop.computed && this.nameIsConstructor(prop.key)) {
  16120. this.raise(Errors.ConstructorClassField, prop.key);
  16121. }
  16122. classBody.body.push(this.parseClassProperty(prop));
  16123. }
  16124. pushClassPrivateProperty(classBody, prop) {
  16125. const node = this.parseClassPrivateProperty(prop);
  16126. classBody.body.push(node);
  16127. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  16128. }
  16129. pushClassAccessorProperty(classBody, prop, isPrivate) {
  16130. if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
  16131. this.raise(Errors.ConstructorClassField, prop.key);
  16132. }
  16133. const node = this.parseClassAccessorProperty(prop);
  16134. classBody.body.push(node);
  16135. if (isPrivate) {
  16136. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), 0, node.key.loc.start);
  16137. }
  16138. }
  16139. pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
  16140. classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
  16141. }
  16142. pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
  16143. const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
  16144. classBody.body.push(node);
  16145. const kind = node.kind === "get" ? node.static ? 6 : 2 : node.kind === "set" ? node.static ? 5 : 1 : 0;
  16146. this.declareClassPrivateMethodInScope(node, kind);
  16147. }
  16148. declareClassPrivateMethodInScope(node, kind) {
  16149. this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
  16150. }
  16151. parsePostMemberNameModifiers(methodOrProp) {}
  16152. parseClassPrivateProperty(node) {
  16153. this.parseInitializer(node);
  16154. this.semicolon();
  16155. return this.finishNode(node, "ClassPrivateProperty");
  16156. }
  16157. parseClassProperty(node) {
  16158. this.parseInitializer(node);
  16159. this.semicolon();
  16160. return this.finishNode(node, "ClassProperty");
  16161. }
  16162. parseClassAccessorProperty(node) {
  16163. this.parseInitializer(node);
  16164. this.semicolon();
  16165. return this.finishNode(node, "ClassAccessorProperty");
  16166. }
  16167. parseInitializer(node) {
  16168. this.scope.enter(576 | 16);
  16169. this.expressionScope.enter(newExpressionScope());
  16170. this.prodParam.enter(0);
  16171. node.value = this.eat(29) ? this.parseMaybeAssignAllowIn() : null;
  16172. this.expressionScope.exit();
  16173. this.prodParam.exit();
  16174. this.scope.exit();
  16175. }
  16176. parseClassId(node, isStatement, optionalId, bindingType = 8331) {
  16177. if (tokenIsIdentifier(this.state.type)) {
  16178. node.id = this.parseIdentifier();
  16179. if (isStatement) {
  16180. this.declareNameFromIdentifier(node.id, bindingType);
  16181. }
  16182. } else {
  16183. if (optionalId || !isStatement) {
  16184. node.id = null;
  16185. } else {
  16186. throw this.raise(Errors.MissingClassName, this.state.startLoc);
  16187. }
  16188. }
  16189. }
  16190. parseClassSuper(node) {
  16191. node.superClass = this.eat(81) ? this.parseExprSubscripts() : null;
  16192. }
  16193. parseExport(node, decorators) {
  16194. const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
  16195. const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
  16196. const parseAfterDefault = !hasDefault || this.eat(12);
  16197. const hasStar = parseAfterDefault && this.eatExportStar(node);
  16198. const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
  16199. const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(12));
  16200. const isFromRequired = hasDefault || hasStar;
  16201. if (hasStar && !hasNamespace) {
  16202. if (hasDefault) this.unexpected();
  16203. if (decorators) {
  16204. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16205. }
  16206. this.parseExportFrom(node, true);
  16207. this.sawUnambiguousESM = true;
  16208. return this.finishNode(node, "ExportAllDeclaration");
  16209. }
  16210. const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
  16211. if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
  16212. this.unexpected(null, 5);
  16213. }
  16214. if (hasNamespace && parseAfterNamespace) {
  16215. this.unexpected(null, 98);
  16216. }
  16217. let hasDeclaration;
  16218. if (isFromRequired || hasSpecifiers) {
  16219. hasDeclaration = false;
  16220. if (decorators) {
  16221. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16222. }
  16223. this.parseExportFrom(node, isFromRequired);
  16224. } else {
  16225. hasDeclaration = this.maybeParseExportDeclaration(node);
  16226. }
  16227. if (isFromRequired || hasSpecifiers || hasDeclaration) {
  16228. var _node2$declaration;
  16229. const node2 = node;
  16230. this.checkExport(node2, true, false, !!node2.source);
  16231. if (((_node2$declaration = node2.declaration) == null ? void 0 : _node2$declaration.type) === "ClassDeclaration") {
  16232. this.maybeTakeDecorators(decorators, node2.declaration, node2);
  16233. } else if (decorators) {
  16234. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16235. }
  16236. this.sawUnambiguousESM = true;
  16237. return this.finishNode(node2, "ExportNamedDeclaration");
  16238. }
  16239. if (this.eat(65)) {
  16240. const node2 = node;
  16241. const decl = this.parseExportDefaultExpression();
  16242. node2.declaration = decl;
  16243. if (decl.type === "ClassDeclaration") {
  16244. this.maybeTakeDecorators(decorators, decl, node2);
  16245. } else if (decorators) {
  16246. throw this.raise(Errors.UnsupportedDecoratorExport, node);
  16247. }
  16248. this.checkExport(node2, true, true);
  16249. this.sawUnambiguousESM = true;
  16250. return this.finishNode(node2, "ExportDefaultDeclaration");
  16251. }
  16252. this.unexpected(null, 5);
  16253. }
  16254. eatExportStar(node) {
  16255. return this.eat(55);
  16256. }
  16257. maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
  16258. if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
  16259. this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier == null ? void 0 : maybeDefaultIdentifier.loc.start);
  16260. const id = maybeDefaultIdentifier || this.parseIdentifier(true);
  16261. const specifier = this.startNodeAtNode(id);
  16262. specifier.exported = id;
  16263. node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
  16264. return true;
  16265. }
  16266. return false;
  16267. }
  16268. maybeParseExportNamespaceSpecifier(node) {
  16269. if (this.isContextual(93)) {
  16270. var _ref, _ref$specifiers;
  16271. (_ref$specifiers = (_ref = node).specifiers) != null ? _ref$specifiers : _ref.specifiers = [];
  16272. const specifier = this.startNodeAt(this.state.lastTokStartLoc);
  16273. this.next();
  16274. specifier.exported = this.parseModuleExportName();
  16275. node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
  16276. return true;
  16277. }
  16278. return false;
  16279. }
  16280. maybeParseExportNamedSpecifiers(node) {
  16281. if (this.match(5)) {
  16282. const node2 = node;
  16283. if (!node2.specifiers) node2.specifiers = [];
  16284. const isTypeExport = node2.exportKind === "type";
  16285. node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
  16286. node2.source = null;
  16287. if (this.hasPlugin("importAssertions")) {
  16288. node2.assertions = [];
  16289. } else {
  16290. node2.attributes = [];
  16291. }
  16292. node2.declaration = null;
  16293. return true;
  16294. }
  16295. return false;
  16296. }
  16297. maybeParseExportDeclaration(node) {
  16298. if (this.shouldParseExportDeclaration()) {
  16299. node.specifiers = [];
  16300. node.source = null;
  16301. if (this.hasPlugin("importAssertions")) {
  16302. node.assertions = [];
  16303. } else {
  16304. node.attributes = [];
  16305. }
  16306. node.declaration = this.parseExportDeclaration(node);
  16307. return true;
  16308. }
  16309. return false;
  16310. }
  16311. isAsyncFunction() {
  16312. if (!this.isContextual(95)) return false;
  16313. const next = this.nextTokenInLineStart();
  16314. return this.isUnparsedContextual(next, "function");
  16315. }
  16316. parseExportDefaultExpression() {
  16317. const expr = this.startNode();
  16318. if (this.match(68)) {
  16319. this.next();
  16320. return this.parseFunction(expr, 1 | 4);
  16321. } else if (this.isAsyncFunction()) {
  16322. this.next();
  16323. this.next();
  16324. return this.parseFunction(expr, 1 | 4 | 8);
  16325. }
  16326. if (this.match(80)) {
  16327. return this.parseClass(expr, true, true);
  16328. }
  16329. if (this.match(26)) {
  16330. if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  16331. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  16332. }
  16333. return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
  16334. }
  16335. if (this.match(75) || this.match(74) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
  16336. throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
  16337. }
  16338. const res = this.parseMaybeAssignAllowIn();
  16339. this.semicolon();
  16340. return res;
  16341. }
  16342. parseExportDeclaration(node) {
  16343. if (this.match(80)) {
  16344. const node = this.parseClass(this.startNode(), true, false);
  16345. return node;
  16346. }
  16347. return this.parseStatementListItem();
  16348. }
  16349. isExportDefaultSpecifier() {
  16350. const {
  16351. type
  16352. } = this.state;
  16353. if (tokenIsIdentifier(type)) {
  16354. if (type === 95 && !this.state.containsEsc || type === 100) {
  16355. return false;
  16356. }
  16357. if ((type === 130 || type === 129) && !this.state.containsEsc) {
  16358. const next = this.nextTokenStart();
  16359. const nextChar = this.input.charCodeAt(next);
  16360. if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next) && !this.input.startsWith("from", next)) {
  16361. this.expectOnePlugin(["flow", "typescript"]);
  16362. return false;
  16363. }
  16364. }
  16365. } else if (!this.match(65)) {
  16366. return false;
  16367. }
  16368. const next = this.nextTokenStart();
  16369. const hasFrom = this.isUnparsedContextual(next, "from");
  16370. if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
  16371. return true;
  16372. }
  16373. if (this.match(65) && hasFrom) {
  16374. const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
  16375. return nextAfterFrom === 34 || nextAfterFrom === 39;
  16376. }
  16377. return false;
  16378. }
  16379. parseExportFrom(node, expect) {
  16380. if (this.eatContextual(98)) {
  16381. node.source = this.parseImportSource();
  16382. this.checkExport(node);
  16383. this.maybeParseImportAttributes(node);
  16384. this.checkJSONModuleImport(node);
  16385. } else if (expect) {
  16386. this.unexpected();
  16387. }
  16388. this.semicolon();
  16389. }
  16390. shouldParseExportDeclaration() {
  16391. const {
  16392. type
  16393. } = this.state;
  16394. if (type === 26) {
  16395. this.expectOnePlugin(["decorators", "decorators-legacy"]);
  16396. if (this.hasPlugin("decorators")) {
  16397. if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
  16398. this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
  16399. }
  16400. return true;
  16401. }
  16402. }
  16403. if (this.isUsing()) {
  16404. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  16405. return true;
  16406. }
  16407. if (this.isAwaitUsing()) {
  16408. this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
  16409. return true;
  16410. }
  16411. return type === 74 || type === 75 || type === 68 || type === 80 || this.isLet() || this.isAsyncFunction();
  16412. }
  16413. checkExport(node, checkNames, isDefault, isFrom) {
  16414. if (checkNames) {
  16415. var _node$specifiers;
  16416. if (isDefault) {
  16417. this.checkDuplicateExports(node, "default");
  16418. if (this.hasPlugin("exportDefaultFrom")) {
  16419. var _declaration$extra;
  16420. const declaration = node.declaration;
  16421. if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !((_declaration$extra = declaration.extra) != null && _declaration$extra.parenthesized)) {
  16422. this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
  16423. }
  16424. }
  16425. } else if ((_node$specifiers = node.specifiers) != null && _node$specifiers.length) {
  16426. for (const specifier of node.specifiers) {
  16427. const {
  16428. exported
  16429. } = specifier;
  16430. const exportName = exported.type === "Identifier" ? exported.name : exported.value;
  16431. this.checkDuplicateExports(specifier, exportName);
  16432. if (!isFrom && specifier.local) {
  16433. const {
  16434. local
  16435. } = specifier;
  16436. if (local.type !== "Identifier") {
  16437. this.raise(Errors.ExportBindingIsString, specifier, {
  16438. localName: local.value,
  16439. exportName
  16440. });
  16441. } else {
  16442. this.checkReservedWord(local.name, local.loc.start, true, false);
  16443. this.scope.checkLocalExport(local);
  16444. }
  16445. }
  16446. }
  16447. } else if (node.declaration) {
  16448. const decl = node.declaration;
  16449. if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
  16450. const {
  16451. id
  16452. } = decl;
  16453. if (!id) throw new Error("Assertion failure");
  16454. this.checkDuplicateExports(node, id.name);
  16455. } else if (decl.type === "VariableDeclaration") {
  16456. for (const declaration of decl.declarations) {
  16457. this.checkDeclaration(declaration.id);
  16458. }
  16459. }
  16460. }
  16461. }
  16462. }
  16463. checkDeclaration(node) {
  16464. if (node.type === "Identifier") {
  16465. this.checkDuplicateExports(node, node.name);
  16466. } else if (node.type === "ObjectPattern") {
  16467. for (const prop of node.properties) {
  16468. this.checkDeclaration(prop);
  16469. }
  16470. } else if (node.type === "ArrayPattern") {
  16471. for (const elem of node.elements) {
  16472. if (elem) {
  16473. this.checkDeclaration(elem);
  16474. }
  16475. }
  16476. } else if (node.type === "ObjectProperty") {
  16477. this.checkDeclaration(node.value);
  16478. } else if (node.type === "RestElement") {
  16479. this.checkDeclaration(node.argument);
  16480. } else if (node.type === "AssignmentPattern") {
  16481. this.checkDeclaration(node.left);
  16482. }
  16483. }
  16484. checkDuplicateExports(node, exportName) {
  16485. if (this.exportedIdentifiers.has(exportName)) {
  16486. if (exportName === "default") {
  16487. this.raise(Errors.DuplicateDefaultExport, node);
  16488. } else {
  16489. this.raise(Errors.DuplicateExport, node, {
  16490. exportName
  16491. });
  16492. }
  16493. }
  16494. this.exportedIdentifiers.add(exportName);
  16495. }
  16496. parseExportSpecifiers(isInTypeExport) {
  16497. const nodes = [];
  16498. let first = true;
  16499. this.expect(5);
  16500. while (!this.eat(8)) {
  16501. if (first) {
  16502. first = false;
  16503. } else {
  16504. this.expect(12);
  16505. if (this.eat(8)) break;
  16506. }
  16507. const isMaybeTypeOnly = this.isContextual(130);
  16508. const isString = this.match(134);
  16509. const node = this.startNode();
  16510. node.local = this.parseModuleExportName();
  16511. nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
  16512. }
  16513. return nodes;
  16514. }
  16515. parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
  16516. if (this.eatContextual(93)) {
  16517. node.exported = this.parseModuleExportName();
  16518. } else if (isString) {
  16519. node.exported = this.cloneStringLiteral(node.local);
  16520. } else if (!node.exported) {
  16521. node.exported = this.cloneIdentifier(node.local);
  16522. }
  16523. return this.finishNode(node, "ExportSpecifier");
  16524. }
  16525. parseModuleExportName() {
  16526. if (this.match(134)) {
  16527. const result = this.parseStringLiteral(this.state.value);
  16528. const surrogate = loneSurrogate.exec(result.value);
  16529. if (surrogate) {
  16530. this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
  16531. surrogateCharCode: surrogate[0].charCodeAt(0)
  16532. });
  16533. }
  16534. return result;
  16535. }
  16536. return this.parseIdentifier(true);
  16537. }
  16538. isJSONModuleImport(node) {
  16539. if (node.assertions != null) {
  16540. return node.assertions.some(({
  16541. key,
  16542. value
  16543. }) => {
  16544. return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
  16545. });
  16546. }
  16547. return false;
  16548. }
  16549. checkImportReflection(node) {
  16550. const {
  16551. specifiers
  16552. } = node;
  16553. const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
  16554. if (node.phase === "source") {
  16555. if (singleBindingType !== "ImportDefaultSpecifier") {
  16556. this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
  16557. }
  16558. } else if (node.phase === "defer") {
  16559. if (singleBindingType !== "ImportNamespaceSpecifier") {
  16560. this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
  16561. }
  16562. } else if (node.module) {
  16563. var _node$assertions;
  16564. if (singleBindingType !== "ImportDefaultSpecifier") {
  16565. this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
  16566. }
  16567. if (((_node$assertions = node.assertions) == null ? void 0 : _node$assertions.length) > 0) {
  16568. this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
  16569. }
  16570. }
  16571. }
  16572. checkJSONModuleImport(node) {
  16573. if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
  16574. const {
  16575. specifiers
  16576. } = node;
  16577. if (specifiers != null) {
  16578. const nonDefaultNamedSpecifier = specifiers.find(specifier => {
  16579. let imported;
  16580. if (specifier.type === "ExportSpecifier") {
  16581. imported = specifier.local;
  16582. } else if (specifier.type === "ImportSpecifier") {
  16583. imported = specifier.imported;
  16584. }
  16585. if (imported !== undefined) {
  16586. return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
  16587. }
  16588. });
  16589. if (nonDefaultNamedSpecifier !== undefined) {
  16590. this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
  16591. }
  16592. }
  16593. }
  16594. }
  16595. isPotentialImportPhase(isExport) {
  16596. if (isExport) return false;
  16597. return this.isContextual(105) || this.isContextual(97) || this.isContextual(127);
  16598. }
  16599. applyImportPhase(node, isExport, phase, loc) {
  16600. if (isExport) {
  16601. return;
  16602. }
  16603. if (phase === "module") {
  16604. this.expectPlugin("importReflection", loc);
  16605. node.module = true;
  16606. } else if (this.hasPlugin("importReflection")) {
  16607. node.module = false;
  16608. }
  16609. if (phase === "source") {
  16610. this.expectPlugin("sourcePhaseImports", loc);
  16611. node.phase = "source";
  16612. } else if (phase === "defer") {
  16613. this.expectPlugin("deferredImportEvaluation", loc);
  16614. node.phase = "defer";
  16615. } else if (this.hasPlugin("sourcePhaseImports")) {
  16616. node.phase = null;
  16617. }
  16618. }
  16619. parseMaybeImportPhase(node, isExport) {
  16620. if (!this.isPotentialImportPhase(isExport)) {
  16621. this.applyImportPhase(node, isExport, null);
  16622. return null;
  16623. }
  16624. const phaseIdentifier = this.startNode();
  16625. const phaseIdentifierName = this.parseIdentifierName(true);
  16626. const {
  16627. type
  16628. } = this.state;
  16629. const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  16630. if (isImportPhase) {
  16631. this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
  16632. return null;
  16633. } else {
  16634. this.applyImportPhase(node, isExport, null);
  16635. return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
  16636. }
  16637. }
  16638. isPrecedingIdImportPhase(phase) {
  16639. const {
  16640. type
  16641. } = this.state;
  16642. return tokenIsIdentifier(type) ? type !== 98 || this.lookaheadCharCode() === 102 : type !== 12;
  16643. }
  16644. parseImport(node) {
  16645. if (this.match(134)) {
  16646. return this.parseImportSourceAndAttributes(node);
  16647. }
  16648. return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
  16649. }
  16650. parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
  16651. node.specifiers = [];
  16652. const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
  16653. const parseNext = !hasDefault || this.eat(12);
  16654. const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
  16655. if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
  16656. this.expectContextual(98);
  16657. return this.parseImportSourceAndAttributes(node);
  16658. }
  16659. parseImportSourceAndAttributes(node) {
  16660. var _node$specifiers2;
  16661. (_node$specifiers2 = node.specifiers) != null ? _node$specifiers2 : node.specifiers = [];
  16662. node.source = this.parseImportSource();
  16663. this.maybeParseImportAttributes(node);
  16664. this.checkImportReflection(node);
  16665. this.checkJSONModuleImport(node);
  16666. this.semicolon();
  16667. this.sawUnambiguousESM = true;
  16668. return this.finishNode(node, "ImportDeclaration");
  16669. }
  16670. parseImportSource() {
  16671. if (!this.match(134)) this.unexpected();
  16672. return this.parseExprAtom();
  16673. }
  16674. parseImportSpecifierLocal(node, specifier, type) {
  16675. specifier.local = this.parseIdentifier();
  16676. node.specifiers.push(this.finishImportSpecifier(specifier, type));
  16677. }
  16678. finishImportSpecifier(specifier, type, bindingType = 8201) {
  16679. this.checkLVal(specifier.local, {
  16680. type
  16681. }, bindingType);
  16682. return this.finishNode(specifier, type);
  16683. }
  16684. parseImportAttributes() {
  16685. this.expect(5);
  16686. const attrs = [];
  16687. const attrNames = new Set();
  16688. do {
  16689. if (this.match(8)) {
  16690. break;
  16691. }
  16692. const node = this.startNode();
  16693. const keyName = this.state.value;
  16694. if (attrNames.has(keyName)) {
  16695. this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
  16696. key: keyName
  16697. });
  16698. }
  16699. attrNames.add(keyName);
  16700. if (this.match(134)) {
  16701. node.key = this.parseStringLiteral(keyName);
  16702. } else {
  16703. node.key = this.parseIdentifier(true);
  16704. }
  16705. this.expect(14);
  16706. if (!this.match(134)) {
  16707. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  16708. }
  16709. node.value = this.parseStringLiteral(this.state.value);
  16710. attrs.push(this.finishNode(node, "ImportAttribute"));
  16711. } while (this.eat(12));
  16712. this.expect(8);
  16713. return attrs;
  16714. }
  16715. parseModuleAttributes() {
  16716. const attrs = [];
  16717. const attributes = new Set();
  16718. do {
  16719. const node = this.startNode();
  16720. node.key = this.parseIdentifier(true);
  16721. if (node.key.name !== "type") {
  16722. this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
  16723. }
  16724. if (attributes.has(node.key.name)) {
  16725. this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
  16726. key: node.key.name
  16727. });
  16728. }
  16729. attributes.add(node.key.name);
  16730. this.expect(14);
  16731. if (!this.match(134)) {
  16732. throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
  16733. }
  16734. node.value = this.parseStringLiteral(this.state.value);
  16735. attrs.push(this.finishNode(node, "ImportAttribute"));
  16736. } while (this.eat(12));
  16737. return attrs;
  16738. }
  16739. maybeParseImportAttributes(node) {
  16740. let attributes;
  16741. {
  16742. var useWith = false;
  16743. }
  16744. if (this.match(76)) {
  16745. if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
  16746. return;
  16747. }
  16748. this.next();
  16749. if (this.hasPlugin("moduleAttributes")) {
  16750. attributes = this.parseModuleAttributes();
  16751. this.addExtra(node, "deprecatedWithLegacySyntax", true);
  16752. } else {
  16753. attributes = this.parseImportAttributes();
  16754. }
  16755. {
  16756. useWith = true;
  16757. }
  16758. } else if (this.isContextual(94) && !this.hasPrecedingLineBreak()) {
  16759. if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
  16760. this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
  16761. }
  16762. if (!this.hasPlugin("importAssertions")) {
  16763. this.addExtra(node, "deprecatedAssertSyntax", true);
  16764. }
  16765. this.next();
  16766. attributes = this.parseImportAttributes();
  16767. } else {
  16768. attributes = [];
  16769. }
  16770. if (!useWith && this.hasPlugin("importAssertions")) {
  16771. node.assertions = attributes;
  16772. } else {
  16773. node.attributes = attributes;
  16774. }
  16775. }
  16776. maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
  16777. if (maybeDefaultIdentifier) {
  16778. const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
  16779. specifier.local = maybeDefaultIdentifier;
  16780. node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
  16781. return true;
  16782. } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
  16783. this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
  16784. return true;
  16785. }
  16786. return false;
  16787. }
  16788. maybeParseStarImportSpecifier(node) {
  16789. if (this.match(55)) {
  16790. const specifier = this.startNode();
  16791. this.next();
  16792. this.expectContextual(93);
  16793. this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
  16794. return true;
  16795. }
  16796. return false;
  16797. }
  16798. parseNamedImportSpecifiers(node) {
  16799. let first = true;
  16800. this.expect(5);
  16801. while (!this.eat(8)) {
  16802. if (first) {
  16803. first = false;
  16804. } else {
  16805. if (this.eat(14)) {
  16806. throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
  16807. }
  16808. this.expect(12);
  16809. if (this.eat(8)) break;
  16810. }
  16811. const specifier = this.startNode();
  16812. const importedIsString = this.match(134);
  16813. const isMaybeTypeOnly = this.isContextual(130);
  16814. specifier.imported = this.parseModuleExportName();
  16815. const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, undefined);
  16816. node.specifiers.push(importSpecifier);
  16817. }
  16818. }
  16819. parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
  16820. if (this.eatContextual(93)) {
  16821. specifier.local = this.parseIdentifier();
  16822. } else {
  16823. const {
  16824. imported
  16825. } = specifier;
  16826. if (importedIsString) {
  16827. throw this.raise(Errors.ImportBindingIsString, specifier, {
  16828. importName: imported.value
  16829. });
  16830. }
  16831. this.checkReservedWord(imported.name, specifier.loc.start, true, true);
  16832. if (!specifier.local) {
  16833. specifier.local = this.cloneIdentifier(imported);
  16834. }
  16835. }
  16836. return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
  16837. }
  16838. isThisParam(param) {
  16839. return param.type === "Identifier" && param.name === "this";
  16840. }
  16841. }
  16842. class Parser extends StatementParser {
  16843. constructor(options, input, pluginsMap) {
  16844. options = getOptions(options);
  16845. super(options, input);
  16846. this.options = options;
  16847. this.initializeScopes();
  16848. this.plugins = pluginsMap;
  16849. this.filename = options.sourceFilename;
  16850. this.startIndex = options.startIndex;
  16851. let optionFlags = 0;
  16852. if (options.allowAwaitOutsideFunction) {
  16853. optionFlags |= 1;
  16854. }
  16855. if (options.allowReturnOutsideFunction) {
  16856. optionFlags |= 2;
  16857. }
  16858. if (options.allowImportExportEverywhere) {
  16859. optionFlags |= 8;
  16860. }
  16861. if (options.allowSuperOutsideMethod) {
  16862. optionFlags |= 16;
  16863. }
  16864. if (options.allowUndeclaredExports) {
  16865. optionFlags |= 64;
  16866. }
  16867. if (options.allowNewTargetOutsideFunction) {
  16868. optionFlags |= 4;
  16869. }
  16870. if (options.allowYieldOutsideFunction) {
  16871. optionFlags |= 32;
  16872. }
  16873. if (options.ranges) {
  16874. optionFlags |= 128;
  16875. }
  16876. if (options.tokens) {
  16877. optionFlags |= 256;
  16878. }
  16879. if (options.createImportExpressions) {
  16880. optionFlags |= 512;
  16881. }
  16882. if (options.createParenthesizedExpressions) {
  16883. optionFlags |= 1024;
  16884. }
  16885. if (options.errorRecovery) {
  16886. optionFlags |= 2048;
  16887. }
  16888. if (options.attachComment) {
  16889. optionFlags |= 4096;
  16890. }
  16891. if (options.annexB) {
  16892. optionFlags |= 8192;
  16893. }
  16894. this.optionFlags = optionFlags;
  16895. }
  16896. getScopeHandler() {
  16897. return ScopeHandler;
  16898. }
  16899. parse() {
  16900. this.enterInitialScopes();
  16901. const file = this.startNode();
  16902. const program = this.startNode();
  16903. this.nextToken();
  16904. file.errors = null;
  16905. this.parseTopLevel(file, program);
  16906. file.errors = this.state.errors;
  16907. file.comments.length = this.state.commentsLen;
  16908. return file;
  16909. }
  16910. }
  16911. function parse(input, options) {
  16912. var _options;
  16913. if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
  16914. options = Object.assign({}, options);
  16915. try {
  16916. options.sourceType = "module";
  16917. const parser = getParser(options, input);
  16918. const ast = parser.parse();
  16919. if (parser.sawUnambiguousESM) {
  16920. return ast;
  16921. }
  16922. if (parser.ambiguousScriptDifferentAst) {
  16923. try {
  16924. options.sourceType = "script";
  16925. return getParser(options, input).parse();
  16926. } catch (_unused) {}
  16927. } else {
  16928. ast.program.sourceType = "script";
  16929. }
  16930. return ast;
  16931. } catch (moduleError) {
  16932. try {
  16933. options.sourceType = "script";
  16934. return getParser(options, input).parse();
  16935. } catch (_unused2) {}
  16936. throw moduleError;
  16937. }
  16938. } else {
  16939. return getParser(options, input).parse();
  16940. }
  16941. }
  16942. function parseExpression(input, options) {
  16943. const parser = getParser(options, input);
  16944. if (parser.options.strictMode) {
  16945. parser.state.strict = true;
  16946. }
  16947. return parser.getExpression();
  16948. }
  16949. function generateExportedTokenTypes(internalTokenTypes) {
  16950. const tokenTypes = {};
  16951. for (const typeName of Object.keys(internalTokenTypes)) {
  16952. tokenTypes[typeName] = getExportedToken(internalTokenTypes[typeName]);
  16953. }
  16954. return tokenTypes;
  16955. }
  16956. const tokTypes = generateExportedTokenTypes(tt);
  16957. function getParser(options, input) {
  16958. let cls = Parser;
  16959. const pluginsMap = new Map();
  16960. if (options != null && options.plugins) {
  16961. for (const plugin of options.plugins) {
  16962. let name, opts;
  16963. if (typeof plugin === "string") {
  16964. name = plugin;
  16965. } else {
  16966. [name, opts] = plugin;
  16967. }
  16968. if (!pluginsMap.has(name)) {
  16969. pluginsMap.set(name, opts || {});
  16970. }
  16971. }
  16972. validatePlugins(pluginsMap);
  16973. cls = getParserClass(pluginsMap);
  16974. }
  16975. return new cls(options, input, pluginsMap);
  16976. }
  16977. const parserClassCache = new Map();
  16978. function getParserClass(pluginsMap) {
  16979. const pluginList = [];
  16980. for (const name of mixinPluginNames) {
  16981. if (pluginsMap.has(name)) {
  16982. pluginList.push(name);
  16983. }
  16984. }
  16985. const key = pluginList.join("|");
  16986. let cls = parserClassCache.get(key);
  16987. if (!cls) {
  16988. cls = Parser;
  16989. for (const plugin of pluginList) {
  16990. cls = mixinPlugins[plugin](cls);
  16991. }
  16992. parserClassCache.set(key, cls);
  16993. }
  16994. return cls;
  16995. }
  16996. lib.parse = parse;
  16997. lib.parseExpression = parseExpression;
  16998. lib.tokTypes = tokTypes;
  16999. return lib;
  17000. }
  17001. var libExports = /*@__PURE__*/ requireLib();
  17002. // @ts-check
  17003. /** @typedef { import('estree').BaseNode} BaseNode */
  17004. /** @typedef {{
  17005. skip: () => void;
  17006. remove: () => void;
  17007. replace: (node: BaseNode) => void;
  17008. }} WalkerContext */
  17009. class WalkerBase {
  17010. constructor() {
  17011. /** @type {boolean} */
  17012. this.should_skip = false;
  17013. /** @type {boolean} */
  17014. this.should_remove = false;
  17015. /** @type {BaseNode | null} */
  17016. this.replacement = null;
  17017. /** @type {WalkerContext} */
  17018. this.context = {
  17019. skip: () => (this.should_skip = true),
  17020. remove: () => (this.should_remove = true),
  17021. replace: (node) => (this.replacement = node)
  17022. };
  17023. }
  17024. /**
  17025. *
  17026. * @param {any} parent
  17027. * @param {string} prop
  17028. * @param {number} index
  17029. * @param {BaseNode} node
  17030. */
  17031. replace(parent, prop, index, node) {
  17032. if (parent) {
  17033. if (index !== null) {
  17034. parent[prop][index] = node;
  17035. } else {
  17036. parent[prop] = node;
  17037. }
  17038. }
  17039. }
  17040. /**
  17041. *
  17042. * @param {any} parent
  17043. * @param {string} prop
  17044. * @param {number} index
  17045. */
  17046. remove(parent, prop, index) {
  17047. if (parent) {
  17048. if (index !== null) {
  17049. parent[prop].splice(index, 1);
  17050. } else {
  17051. delete parent[prop];
  17052. }
  17053. }
  17054. }
  17055. }
  17056. // @ts-check
  17057. /** @typedef { import('estree').BaseNode} BaseNode */
  17058. /** @typedef { import('./walker.js').WalkerContext} WalkerContext */
  17059. /** @typedef {(
  17060. * this: WalkerContext,
  17061. * node: BaseNode,
  17062. * parent: BaseNode,
  17063. * key: string,
  17064. * index: number
  17065. * ) => void} SyncHandler */
  17066. class SyncWalker extends WalkerBase {
  17067. /**
  17068. *
  17069. * @param {SyncHandler} enter
  17070. * @param {SyncHandler} leave
  17071. */
  17072. constructor(enter, leave) {
  17073. super();
  17074. /** @type {SyncHandler} */
  17075. this.enter = enter;
  17076. /** @type {SyncHandler} */
  17077. this.leave = leave;
  17078. }
  17079. /**
  17080. *
  17081. * @param {BaseNode} node
  17082. * @param {BaseNode} parent
  17083. * @param {string} [prop]
  17084. * @param {number} [index]
  17085. * @returns {BaseNode}
  17086. */
  17087. visit(node, parent, prop, index) {
  17088. if (node) {
  17089. if (this.enter) {
  17090. const _should_skip = this.should_skip;
  17091. const _should_remove = this.should_remove;
  17092. const _replacement = this.replacement;
  17093. this.should_skip = false;
  17094. this.should_remove = false;
  17095. this.replacement = null;
  17096. this.enter.call(this.context, node, parent, prop, index);
  17097. if (this.replacement) {
  17098. node = this.replacement;
  17099. this.replace(parent, prop, index, node);
  17100. }
  17101. if (this.should_remove) {
  17102. this.remove(parent, prop, index);
  17103. }
  17104. const skipped = this.should_skip;
  17105. const removed = this.should_remove;
  17106. this.should_skip = _should_skip;
  17107. this.should_remove = _should_remove;
  17108. this.replacement = _replacement;
  17109. if (skipped) return node;
  17110. if (removed) return null;
  17111. }
  17112. for (const key in node) {
  17113. const value = node[key];
  17114. if (typeof value !== "object") {
  17115. continue;
  17116. } else if (Array.isArray(value)) {
  17117. for (let i = 0; i < value.length; i += 1) {
  17118. if (value[i] !== null && typeof value[i].type === 'string') {
  17119. if (!this.visit(value[i], node, key, i)) {
  17120. // removed
  17121. i--;
  17122. }
  17123. }
  17124. }
  17125. } else if (value !== null && typeof value.type === "string") {
  17126. this.visit(value, node, key, null);
  17127. }
  17128. }
  17129. if (this.leave) {
  17130. const _replacement = this.replacement;
  17131. const _should_remove = this.should_remove;
  17132. this.replacement = null;
  17133. this.should_remove = false;
  17134. this.leave.call(this.context, node, parent, prop, index);
  17135. if (this.replacement) {
  17136. node = this.replacement;
  17137. this.replace(parent, prop, index, node);
  17138. }
  17139. if (this.should_remove) {
  17140. this.remove(parent, prop, index);
  17141. }
  17142. const removed = this.should_remove;
  17143. this.replacement = _replacement;
  17144. this.should_remove = _should_remove;
  17145. if (removed) return null;
  17146. }
  17147. }
  17148. return node;
  17149. }
  17150. }
  17151. // @ts-check
  17152. /** @typedef { import('estree').BaseNode} BaseNode */
  17153. /** @typedef { import('./sync.js').SyncHandler} SyncHandler */
  17154. /** @typedef { import('./async.js').AsyncHandler} AsyncHandler */
  17155. /**
  17156. *
  17157. * @param {BaseNode} ast
  17158. * @param {{
  17159. * enter?: SyncHandler
  17160. * leave?: SyncHandler
  17161. * }} walker
  17162. * @returns {BaseNode}
  17163. */
  17164. function walk$2(ast, { enter, leave }) {
  17165. const instance = new SyncWalker(enter, leave);
  17166. return instance.visit(ast, null);
  17167. }
  17168. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  17169. const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
  17170. walk$2(root, {
  17171. enter(node, parent) {
  17172. parent && parentStack.push(parent);
  17173. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  17174. return this.skip();
  17175. }
  17176. if (node.type === "Identifier") {
  17177. const isLocal = !!knownIds[node.name];
  17178. const isRefed = isReferencedIdentifier(node, parent, parentStack);
  17179. if (includeAll || isRefed && !isLocal) {
  17180. onIdentifier(node, parent, parentStack, isRefed, isLocal);
  17181. }
  17182. } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
  17183. (parent == null ? void 0 : parent.type) === "ObjectPattern") {
  17184. node.inPattern = true;
  17185. } else if (isFunctionType(node)) {
  17186. if (node.scopeIds) {
  17187. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  17188. } else {
  17189. walkFunctionParams(
  17190. node,
  17191. (id) => markScopeIdentifier(node, id, knownIds)
  17192. );
  17193. }
  17194. } else if (node.type === "BlockStatement") {
  17195. if (node.scopeIds) {
  17196. node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
  17197. } else {
  17198. walkBlockDeclarations(
  17199. node,
  17200. (id) => markScopeIdentifier(node, id, knownIds)
  17201. );
  17202. }
  17203. } else if (node.type === "CatchClause" && node.param) {
  17204. for (const id of extractIdentifiers$1(node.param)) {
  17205. markScopeIdentifier(node, id, knownIds);
  17206. }
  17207. } else if (isForStatement(node)) {
  17208. walkForStatement(
  17209. node,
  17210. false,
  17211. (id) => markScopeIdentifier(node, id, knownIds)
  17212. );
  17213. }
  17214. },
  17215. leave(node, parent) {
  17216. parent && parentStack.pop();
  17217. if (node !== rootExp && node.scopeIds) {
  17218. for (const id of node.scopeIds) {
  17219. knownIds[id]--;
  17220. if (knownIds[id] === 0) {
  17221. delete knownIds[id];
  17222. }
  17223. }
  17224. }
  17225. }
  17226. });
  17227. }
  17228. function isReferencedIdentifier(id, parent, parentStack) {
  17229. if (!parent) {
  17230. return true;
  17231. }
  17232. if (id.name === "arguments") {
  17233. return false;
  17234. }
  17235. if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
  17236. return true;
  17237. }
  17238. switch (parent.type) {
  17239. case "AssignmentExpression":
  17240. case "AssignmentPattern":
  17241. return true;
  17242. case "ObjectProperty":
  17243. return parent.key !== id && isInDestructureAssignment(parent, parentStack);
  17244. case "ArrayPattern":
  17245. return isInDestructureAssignment(parent, parentStack);
  17246. }
  17247. return false;
  17248. }
  17249. function isInDestructureAssignment(parent, parentStack) {
  17250. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  17251. let i = parentStack.length;
  17252. while (i--) {
  17253. const p = parentStack[i];
  17254. if (p.type === "AssignmentExpression") {
  17255. return true;
  17256. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  17257. break;
  17258. }
  17259. }
  17260. }
  17261. return false;
  17262. }
  17263. function isInNewExpression(parentStack) {
  17264. let i = parentStack.length;
  17265. while (i--) {
  17266. const p = parentStack[i];
  17267. if (p.type === "NewExpression") {
  17268. return true;
  17269. } else if (p.type !== "MemberExpression") {
  17270. break;
  17271. }
  17272. }
  17273. return false;
  17274. }
  17275. function walkFunctionParams(node, onIdent) {
  17276. for (const p of node.params) {
  17277. for (const id of extractIdentifiers$1(p)) {
  17278. onIdent(id);
  17279. }
  17280. }
  17281. }
  17282. function walkBlockDeclarations(block, onIdent) {
  17283. for (const stmt of block.body) {
  17284. if (stmt.type === "VariableDeclaration") {
  17285. if (stmt.declare) continue;
  17286. for (const decl of stmt.declarations) {
  17287. for (const id of extractIdentifiers$1(decl.id)) {
  17288. onIdent(id);
  17289. }
  17290. }
  17291. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  17292. if (stmt.declare || !stmt.id) continue;
  17293. onIdent(stmt.id);
  17294. } else if (isForStatement(stmt)) {
  17295. walkForStatement(stmt, true, onIdent);
  17296. }
  17297. }
  17298. }
  17299. function isForStatement(stmt) {
  17300. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  17301. }
  17302. function walkForStatement(stmt, isVar, onIdent) {
  17303. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  17304. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  17305. for (const decl of variable.declarations) {
  17306. for (const id of extractIdentifiers$1(decl.id)) {
  17307. onIdent(id);
  17308. }
  17309. }
  17310. }
  17311. }
  17312. function extractIdentifiers$1(param, nodes = []) {
  17313. switch (param.type) {
  17314. case "Identifier":
  17315. nodes.push(param);
  17316. break;
  17317. case "MemberExpression":
  17318. let object = param;
  17319. while (object.type === "MemberExpression") {
  17320. object = object.object;
  17321. }
  17322. nodes.push(object);
  17323. break;
  17324. case "ObjectPattern":
  17325. for (const prop of param.properties) {
  17326. if (prop.type === "RestElement") {
  17327. extractIdentifiers$1(prop.argument, nodes);
  17328. } else {
  17329. extractIdentifiers$1(prop.value, nodes);
  17330. }
  17331. }
  17332. break;
  17333. case "ArrayPattern":
  17334. param.elements.forEach((element) => {
  17335. if (element) extractIdentifiers$1(element, nodes);
  17336. });
  17337. break;
  17338. case "RestElement":
  17339. extractIdentifiers$1(param.argument, nodes);
  17340. break;
  17341. case "AssignmentPattern":
  17342. extractIdentifiers$1(param.left, nodes);
  17343. break;
  17344. }
  17345. return nodes;
  17346. }
  17347. function markKnownIds(name, knownIds) {
  17348. if (name in knownIds) {
  17349. knownIds[name]++;
  17350. } else {
  17351. knownIds[name] = 1;
  17352. }
  17353. }
  17354. function markScopeIdentifier(node, child, knownIds) {
  17355. const { name } = child;
  17356. if (node.scopeIds && node.scopeIds.has(name)) {
  17357. return;
  17358. }
  17359. markKnownIds(name, knownIds);
  17360. (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
  17361. }
  17362. const isFunctionType = (node) => {
  17363. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  17364. };
  17365. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  17366. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  17367. function isReferenced(node, parent, grandparent) {
  17368. switch (parent.type) {
  17369. // yes: PARENT[NODE]
  17370. // yes: NODE.child
  17371. // no: parent.NODE
  17372. case "MemberExpression":
  17373. case "OptionalMemberExpression":
  17374. if (parent.property === node) {
  17375. return !!parent.computed;
  17376. }
  17377. return parent.object === node;
  17378. case "JSXMemberExpression":
  17379. return parent.object === node;
  17380. // no: let NODE = init;
  17381. // yes: let id = NODE;
  17382. case "VariableDeclarator":
  17383. return parent.init === node;
  17384. // yes: () => NODE
  17385. // no: (NODE) => {}
  17386. case "ArrowFunctionExpression":
  17387. return parent.body === node;
  17388. // no: class { #NODE; }
  17389. // no: class { get #NODE() {} }
  17390. // no: class { #NODE() {} }
  17391. // no: class { fn() { return this.#NODE; } }
  17392. case "PrivateName":
  17393. return false;
  17394. // no: class { NODE() {} }
  17395. // yes: class { [NODE]() {} }
  17396. // no: class { foo(NODE) {} }
  17397. case "ClassMethod":
  17398. case "ClassPrivateMethod":
  17399. case "ObjectMethod":
  17400. if (parent.key === node) {
  17401. return !!parent.computed;
  17402. }
  17403. return false;
  17404. // yes: { [NODE]: "" }
  17405. // no: { NODE: "" }
  17406. // depends: { NODE }
  17407. // depends: { key: NODE }
  17408. case "ObjectProperty":
  17409. if (parent.key === node) {
  17410. return !!parent.computed;
  17411. }
  17412. return !grandparent || grandparent.type !== "ObjectPattern";
  17413. // no: class { NODE = value; }
  17414. // yes: class { [NODE] = value; }
  17415. // yes: class { key = NODE; }
  17416. case "ClassProperty":
  17417. if (parent.key === node) {
  17418. return !!parent.computed;
  17419. }
  17420. return true;
  17421. case "ClassPrivateProperty":
  17422. return parent.key !== node;
  17423. // no: class NODE {}
  17424. // yes: class Foo extends NODE {}
  17425. case "ClassDeclaration":
  17426. case "ClassExpression":
  17427. return parent.superClass === node;
  17428. // yes: left = NODE;
  17429. // no: NODE = right;
  17430. case "AssignmentExpression":
  17431. return parent.right === node;
  17432. // no: [NODE = foo] = [];
  17433. // yes: [foo = NODE] = [];
  17434. case "AssignmentPattern":
  17435. return parent.right === node;
  17436. // no: NODE: for (;;) {}
  17437. case "LabeledStatement":
  17438. return false;
  17439. // no: try {} catch (NODE) {}
  17440. case "CatchClause":
  17441. return false;
  17442. // no: function foo(...NODE) {}
  17443. case "RestElement":
  17444. return false;
  17445. case "BreakStatement":
  17446. case "ContinueStatement":
  17447. return false;
  17448. // no: function NODE() {}
  17449. // no: function foo(NODE) {}
  17450. case "FunctionDeclaration":
  17451. case "FunctionExpression":
  17452. return false;
  17453. // no: export NODE from "foo";
  17454. // no: export * as NODE from "foo";
  17455. case "ExportNamespaceSpecifier":
  17456. case "ExportDefaultSpecifier":
  17457. return false;
  17458. // no: export { foo as NODE };
  17459. // yes: export { NODE as foo };
  17460. // no: export { NODE as foo } from "foo";
  17461. case "ExportSpecifier":
  17462. if (grandparent == null ? void 0 : grandparent.source) {
  17463. return false;
  17464. }
  17465. return parent.local === node;
  17466. // no: import NODE from "foo";
  17467. // no: import * as NODE from "foo";
  17468. // no: import { NODE as foo } from "foo";
  17469. // no: import { foo as NODE } from "foo";
  17470. // no: import NODE from "bar";
  17471. case "ImportDefaultSpecifier":
  17472. case "ImportNamespaceSpecifier":
  17473. case "ImportSpecifier":
  17474. return false;
  17475. // no: import "foo" assert { NODE: "json" }
  17476. case "ImportAttribute":
  17477. return false;
  17478. // no: <div NODE="foo" />
  17479. case "JSXAttribute":
  17480. return false;
  17481. // no: [NODE] = [];
  17482. // no: ({ NODE }) = [];
  17483. case "ObjectPattern":
  17484. case "ArrayPattern":
  17485. return false;
  17486. // no: new.NODE
  17487. // no: NODE.target
  17488. case "MetaProperty":
  17489. return false;
  17490. // yes: type X = { someProperty: NODE }
  17491. // no: type X = { NODE: OtherType }
  17492. case "ObjectTypeProperty":
  17493. return parent.key !== node;
  17494. // yes: enum X { Foo = NODE }
  17495. // no: enum X { NODE }
  17496. case "TSEnumMember":
  17497. return parent.id !== node;
  17498. // yes: { [NODE]: value }
  17499. // no: { NODE: value }
  17500. case "TSPropertySignature":
  17501. if (parent.key === node) {
  17502. return !!parent.computed;
  17503. }
  17504. return true;
  17505. }
  17506. return true;
  17507. }
  17508. const TS_NODE_TYPES = [
  17509. "TSAsExpression",
  17510. // foo as number
  17511. "TSTypeAssertion",
  17512. // (<number>foo)
  17513. "TSNonNullExpression",
  17514. // foo!
  17515. "TSInstantiationExpression",
  17516. // foo<string>
  17517. "TSSatisfiesExpression"
  17518. // foo satisfies T
  17519. ];
  17520. function unwrapTSNode(node) {
  17521. if (TS_NODE_TYPES.includes(node.type)) {
  17522. return unwrapTSNode(node.expression);
  17523. } else {
  17524. return node;
  17525. }
  17526. }
  17527. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  17528. function isCoreComponent(tag) {
  17529. switch (tag) {
  17530. case "Teleport":
  17531. case "teleport":
  17532. return TELEPORT;
  17533. case "Suspense":
  17534. case "suspense":
  17535. return SUSPENSE;
  17536. case "KeepAlive":
  17537. case "keep-alive":
  17538. return KEEP_ALIVE;
  17539. case "BaseTransition":
  17540. case "base-transition":
  17541. return BASE_TRANSITION;
  17542. }
  17543. }
  17544. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  17545. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  17546. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  17547. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  17548. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  17549. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  17550. const isMemberExpressionBrowser = (exp) => {
  17551. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  17552. let state = 0 /* inMemberExp */;
  17553. let stateStack = [];
  17554. let currentOpenBracketCount = 0;
  17555. let currentOpenParensCount = 0;
  17556. let currentStringType = null;
  17557. for (let i = 0; i < path.length; i++) {
  17558. const char = path.charAt(i);
  17559. switch (state) {
  17560. case 0 /* inMemberExp */:
  17561. if (char === "[") {
  17562. stateStack.push(state);
  17563. state = 1 /* inBrackets */;
  17564. currentOpenBracketCount++;
  17565. } else if (char === "(") {
  17566. stateStack.push(state);
  17567. state = 2 /* inParens */;
  17568. currentOpenParensCount++;
  17569. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  17570. return false;
  17571. }
  17572. break;
  17573. case 1 /* inBrackets */:
  17574. if (char === `'` || char === `"` || char === "`") {
  17575. stateStack.push(state);
  17576. state = 3 /* inString */;
  17577. currentStringType = char;
  17578. } else if (char === `[`) {
  17579. currentOpenBracketCount++;
  17580. } else if (char === `]`) {
  17581. if (!--currentOpenBracketCount) {
  17582. state = stateStack.pop();
  17583. }
  17584. }
  17585. break;
  17586. case 2 /* inParens */:
  17587. if (char === `'` || char === `"` || char === "`") {
  17588. stateStack.push(state);
  17589. state = 3 /* inString */;
  17590. currentStringType = char;
  17591. } else if (char === `(`) {
  17592. currentOpenParensCount++;
  17593. } else if (char === `)`) {
  17594. if (i === path.length - 1) {
  17595. return false;
  17596. }
  17597. if (!--currentOpenParensCount) {
  17598. state = stateStack.pop();
  17599. }
  17600. }
  17601. break;
  17602. case 3 /* inString */:
  17603. if (char === currentStringType) {
  17604. state = stateStack.pop();
  17605. currentStringType = null;
  17606. }
  17607. break;
  17608. }
  17609. }
  17610. return !currentOpenBracketCount && !currentOpenParensCount;
  17611. };
  17612. const isMemberExpressionNode = (exp, context) => {
  17613. try {
  17614. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  17615. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  17616. });
  17617. ret = unwrapTSNode(ret);
  17618. return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
  17619. } catch (e) {
  17620. return false;
  17621. }
  17622. };
  17623. const isMemberExpression = isMemberExpressionNode;
  17624. const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  17625. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  17626. const isFnExpressionNode = (exp, context) => {
  17627. try {
  17628. let ret = exp.ast || libExports.parseExpression(getExpSource(exp), {
  17629. plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
  17630. });
  17631. if (ret.type === "Program") {
  17632. ret = ret.body[0];
  17633. if (ret.type === "ExpressionStatement") {
  17634. ret = ret.expression;
  17635. }
  17636. }
  17637. ret = unwrapTSNode(ret);
  17638. return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
  17639. } catch (e) {
  17640. return false;
  17641. }
  17642. };
  17643. const isFnExpression = isFnExpressionNode;
  17644. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  17645. return advancePositionWithMutation(
  17646. {
  17647. offset: pos.offset,
  17648. line: pos.line,
  17649. column: pos.column
  17650. },
  17651. source,
  17652. numberOfCharacters
  17653. );
  17654. }
  17655. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  17656. let linesCount = 0;
  17657. let lastNewLinePos = -1;
  17658. for (let i = 0; i < numberOfCharacters; i++) {
  17659. if (source.charCodeAt(i) === 10) {
  17660. linesCount++;
  17661. lastNewLinePos = i;
  17662. }
  17663. }
  17664. pos.offset += numberOfCharacters;
  17665. pos.line += linesCount;
  17666. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  17667. return pos;
  17668. }
  17669. function assert(condition, msg) {
  17670. if (!condition) {
  17671. throw new Error(msg || `unexpected compiler condition`);
  17672. }
  17673. }
  17674. function findDir(node, name, allowEmpty = false) {
  17675. for (let i = 0; i < node.props.length; i++) {
  17676. const p = node.props[i];
  17677. if (p.type === 7 && (allowEmpty || p.exp) && (isString$1(name) ? p.name === name : name.test(p.name))) {
  17678. return p;
  17679. }
  17680. }
  17681. }
  17682. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  17683. for (let i = 0; i < node.props.length; i++) {
  17684. const p = node.props[i];
  17685. if (p.type === 6) {
  17686. if (dynamicOnly) continue;
  17687. if (p.name === name && (p.value || allowEmpty)) {
  17688. return p;
  17689. }
  17690. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  17691. return p;
  17692. }
  17693. }
  17694. }
  17695. function isStaticArgOf(arg, name) {
  17696. return !!(arg && isStaticExp(arg) && arg.content === name);
  17697. }
  17698. function hasDynamicKeyVBind(node) {
  17699. return node.props.some(
  17700. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  17701. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  17702. !p.arg.isStatic)
  17703. // v-bind:[foo]
  17704. );
  17705. }
  17706. function isText$1(node) {
  17707. return node.type === 5 || node.type === 2;
  17708. }
  17709. function isVPre(p) {
  17710. return p.type === 7 && p.name === "pre";
  17711. }
  17712. function isVSlot(p) {
  17713. return p.type === 7 && p.name === "slot";
  17714. }
  17715. function isTemplateNode(node) {
  17716. return node.type === 1 && node.tagType === 3;
  17717. }
  17718. function isSlotOutlet(node) {
  17719. return node.type === 1 && node.tagType === 2;
  17720. }
  17721. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  17722. function getUnnormalizedProps(props, callPath = []) {
  17723. if (props && !isString$1(props) && props.type === 14) {
  17724. const callee = props.callee;
  17725. if (!isString$1(callee) && propsHelperSet.has(callee)) {
  17726. return getUnnormalizedProps(
  17727. props.arguments[0],
  17728. callPath.concat(props)
  17729. );
  17730. }
  17731. }
  17732. return [props, callPath];
  17733. }
  17734. function injectProp(node, prop, context) {
  17735. let propsWithInjection;
  17736. let props = node.type === 13 ? node.props : node.arguments[2];
  17737. let callPath = [];
  17738. let parentCall;
  17739. if (props && !isString$1(props) && props.type === 14) {
  17740. const ret = getUnnormalizedProps(props);
  17741. props = ret[0];
  17742. callPath = ret[1];
  17743. parentCall = callPath[callPath.length - 1];
  17744. }
  17745. if (props == null || isString$1(props)) {
  17746. propsWithInjection = createObjectExpression([prop]);
  17747. } else if (props.type === 14) {
  17748. const first = props.arguments[0];
  17749. if (!isString$1(first) && first.type === 15) {
  17750. if (!hasProp(prop, first)) {
  17751. first.properties.unshift(prop);
  17752. }
  17753. } else {
  17754. if (props.callee === TO_HANDLERS) {
  17755. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  17756. createObjectExpression([prop]),
  17757. props
  17758. ]);
  17759. } else {
  17760. props.arguments.unshift(createObjectExpression([prop]));
  17761. }
  17762. }
  17763. !propsWithInjection && (propsWithInjection = props);
  17764. } else if (props.type === 15) {
  17765. if (!hasProp(prop, props)) {
  17766. props.properties.unshift(prop);
  17767. }
  17768. propsWithInjection = props;
  17769. } else {
  17770. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  17771. createObjectExpression([prop]),
  17772. props
  17773. ]);
  17774. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  17775. parentCall = callPath[callPath.length - 2];
  17776. }
  17777. }
  17778. if (node.type === 13) {
  17779. if (parentCall) {
  17780. parentCall.arguments[0] = propsWithInjection;
  17781. } else {
  17782. node.props = propsWithInjection;
  17783. }
  17784. } else {
  17785. if (parentCall) {
  17786. parentCall.arguments[0] = propsWithInjection;
  17787. } else {
  17788. node.arguments[2] = propsWithInjection;
  17789. }
  17790. }
  17791. }
  17792. function hasProp(prop, props) {
  17793. let result = false;
  17794. if (prop.key.type === 4) {
  17795. const propKeyName = prop.key.content;
  17796. result = props.properties.some(
  17797. (p) => p.key.type === 4 && p.key.content === propKeyName
  17798. );
  17799. }
  17800. return result;
  17801. }
  17802. function toValidAssetId(name, type) {
  17803. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  17804. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  17805. })}`;
  17806. }
  17807. function hasScopeRef(node, ids) {
  17808. if (!node || Object.keys(ids).length === 0) {
  17809. return false;
  17810. }
  17811. switch (node.type) {
  17812. case 1:
  17813. for (let i = 0; i < node.props.length; i++) {
  17814. const p = node.props[i];
  17815. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  17816. return true;
  17817. }
  17818. }
  17819. return node.children.some((c) => hasScopeRef(c, ids));
  17820. case 11:
  17821. if (hasScopeRef(node.source, ids)) {
  17822. return true;
  17823. }
  17824. return node.children.some((c) => hasScopeRef(c, ids));
  17825. case 9:
  17826. return node.branches.some((b) => hasScopeRef(b, ids));
  17827. case 10:
  17828. if (hasScopeRef(node.condition, ids)) {
  17829. return true;
  17830. }
  17831. return node.children.some((c) => hasScopeRef(c, ids));
  17832. case 4:
  17833. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  17834. case 8:
  17835. return node.children.some((c) => isObject$2(c) && hasScopeRef(c, ids));
  17836. case 5:
  17837. case 12:
  17838. return hasScopeRef(node.content, ids);
  17839. case 2:
  17840. case 3:
  17841. case 20:
  17842. return false;
  17843. default:
  17844. return false;
  17845. }
  17846. }
  17847. function getMemoedVNodeCall(node) {
  17848. if (node.type === 14 && node.callee === WITH_MEMO) {
  17849. return node.arguments[1].returns;
  17850. } else {
  17851. return node;
  17852. }
  17853. }
  17854. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  17855. const defaultParserOptions = {
  17856. parseMode: "base",
  17857. ns: 0,
  17858. delimiters: [`{{`, `}}`],
  17859. getNamespace: () => 0,
  17860. isVoidTag: NO,
  17861. isPreTag: NO,
  17862. isIgnoreNewlineTag: NO,
  17863. isCustomElement: NO,
  17864. onError: defaultOnError,
  17865. onWarn: defaultOnWarn,
  17866. comments: true,
  17867. prefixIdentifiers: false
  17868. };
  17869. let currentOptions = defaultParserOptions;
  17870. let currentRoot = null;
  17871. let currentInput = "";
  17872. let currentOpenTag = null;
  17873. let currentProp = null;
  17874. let currentAttrValue = "";
  17875. let currentAttrStartIndex = -1;
  17876. let currentAttrEndIndex = -1;
  17877. let inPre = 0;
  17878. let inVPre = false;
  17879. let currentVPreBoundary = null;
  17880. const stack = [];
  17881. const tokenizer = new Tokenizer(stack, {
  17882. onerr: emitError,
  17883. ontext(start, end) {
  17884. onText(getSlice(start, end), start, end);
  17885. },
  17886. ontextentity(char, start, end) {
  17887. onText(char, start, end);
  17888. },
  17889. oninterpolation(start, end) {
  17890. if (inVPre) {
  17891. return onText(getSlice(start, end), start, end);
  17892. }
  17893. let innerStart = start + tokenizer.delimiterOpen.length;
  17894. let innerEnd = end - tokenizer.delimiterClose.length;
  17895. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  17896. innerStart++;
  17897. }
  17898. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  17899. innerEnd--;
  17900. }
  17901. let exp = getSlice(innerStart, innerEnd);
  17902. if (exp.includes("&")) {
  17903. {
  17904. exp = decodeHTML(exp);
  17905. }
  17906. }
  17907. addNode({
  17908. type: 5,
  17909. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  17910. loc: getLoc(start, end)
  17911. });
  17912. },
  17913. onopentagname(start, end) {
  17914. const name = getSlice(start, end);
  17915. currentOpenTag = {
  17916. type: 1,
  17917. tag: name,
  17918. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  17919. tagType: 0,
  17920. // will be refined on tag close
  17921. props: [],
  17922. children: [],
  17923. loc: getLoc(start - 1, end),
  17924. codegenNode: void 0
  17925. };
  17926. },
  17927. onopentagend(end) {
  17928. endOpenTag(end);
  17929. },
  17930. onclosetag(start, end) {
  17931. const name = getSlice(start, end);
  17932. if (!currentOptions.isVoidTag(name)) {
  17933. let found = false;
  17934. for (let i = 0; i < stack.length; i++) {
  17935. const e = stack[i];
  17936. if (e.tag.toLowerCase() === name.toLowerCase()) {
  17937. found = true;
  17938. if (i > 0) {
  17939. emitError(24, stack[0].loc.start.offset);
  17940. }
  17941. for (let j = 0; j <= i; j++) {
  17942. const el = stack.shift();
  17943. onCloseTag(el, end, j < i);
  17944. }
  17945. break;
  17946. }
  17947. }
  17948. if (!found) {
  17949. emitError(23, backTrack(start, 60));
  17950. }
  17951. }
  17952. },
  17953. onselfclosingtag(end) {
  17954. const name = currentOpenTag.tag;
  17955. currentOpenTag.isSelfClosing = true;
  17956. endOpenTag(end);
  17957. if (stack[0] && stack[0].tag === name) {
  17958. onCloseTag(stack.shift(), end);
  17959. }
  17960. },
  17961. onattribname(start, end) {
  17962. currentProp = {
  17963. type: 6,
  17964. name: getSlice(start, end),
  17965. nameLoc: getLoc(start, end),
  17966. value: void 0,
  17967. loc: getLoc(start)
  17968. };
  17969. },
  17970. ondirname(start, end) {
  17971. const raw = getSlice(start, end);
  17972. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  17973. if (!inVPre && name === "") {
  17974. emitError(26, start);
  17975. }
  17976. if (inVPre || name === "") {
  17977. currentProp = {
  17978. type: 6,
  17979. name: raw,
  17980. nameLoc: getLoc(start, end),
  17981. value: void 0,
  17982. loc: getLoc(start)
  17983. };
  17984. } else {
  17985. currentProp = {
  17986. type: 7,
  17987. name,
  17988. rawName: raw,
  17989. exp: void 0,
  17990. arg: void 0,
  17991. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  17992. loc: getLoc(start)
  17993. };
  17994. if (name === "pre") {
  17995. inVPre = tokenizer.inVPre = true;
  17996. currentVPreBoundary = currentOpenTag;
  17997. const props = currentOpenTag.props;
  17998. for (let i = 0; i < props.length; i++) {
  17999. if (props[i].type === 7) {
  18000. props[i] = dirToAttr(props[i]);
  18001. }
  18002. }
  18003. }
  18004. }
  18005. },
  18006. ondirarg(start, end) {
  18007. if (start === end) return;
  18008. const arg = getSlice(start, end);
  18009. if (inVPre && !isVPre(currentProp)) {
  18010. currentProp.name += arg;
  18011. setLocEnd(currentProp.nameLoc, end);
  18012. } else {
  18013. const isStatic = arg[0] !== `[`;
  18014. currentProp.arg = createExp(
  18015. isStatic ? arg : arg.slice(1, -1),
  18016. isStatic,
  18017. getLoc(start, end),
  18018. isStatic ? 3 : 0
  18019. );
  18020. }
  18021. },
  18022. ondirmodifier(start, end) {
  18023. const mod = getSlice(start, end);
  18024. if (inVPre && !isVPre(currentProp)) {
  18025. currentProp.name += "." + mod;
  18026. setLocEnd(currentProp.nameLoc, end);
  18027. } else if (currentProp.name === "slot") {
  18028. const arg = currentProp.arg;
  18029. if (arg) {
  18030. arg.content += "." + mod;
  18031. setLocEnd(arg.loc, end);
  18032. }
  18033. } else {
  18034. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  18035. currentProp.modifiers.push(exp);
  18036. }
  18037. },
  18038. onattribdata(start, end) {
  18039. currentAttrValue += getSlice(start, end);
  18040. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  18041. currentAttrEndIndex = end;
  18042. },
  18043. onattribentity(char, start, end) {
  18044. currentAttrValue += char;
  18045. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  18046. currentAttrEndIndex = end;
  18047. },
  18048. onattribnameend(end) {
  18049. const start = currentProp.loc.start.offset;
  18050. const name = getSlice(start, end);
  18051. if (currentProp.type === 7) {
  18052. currentProp.rawName = name;
  18053. }
  18054. if (currentOpenTag.props.some(
  18055. (p) => (p.type === 7 ? p.rawName : p.name) === name
  18056. )) {
  18057. emitError(2, start);
  18058. }
  18059. },
  18060. onattribend(quote, end) {
  18061. if (currentOpenTag && currentProp) {
  18062. setLocEnd(currentProp.loc, end);
  18063. if (quote !== 0) {
  18064. if (currentProp.type === 6) {
  18065. if (currentProp.name === "class") {
  18066. currentAttrValue = condense(currentAttrValue).trim();
  18067. }
  18068. if (quote === 1 && !currentAttrValue) {
  18069. emitError(13, end);
  18070. }
  18071. currentProp.value = {
  18072. type: 2,
  18073. content: currentAttrValue,
  18074. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  18075. };
  18076. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  18077. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  18078. }
  18079. } else {
  18080. let expParseMode = 0 /* Normal */;
  18081. {
  18082. if (currentProp.name === "for") {
  18083. expParseMode = 3 /* Skip */;
  18084. } else if (currentProp.name === "slot") {
  18085. expParseMode = 1 /* Params */;
  18086. } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
  18087. expParseMode = 2 /* Statements */;
  18088. }
  18089. }
  18090. currentProp.exp = createExp(
  18091. currentAttrValue,
  18092. false,
  18093. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  18094. 0,
  18095. expParseMode
  18096. );
  18097. if (currentProp.name === "for") {
  18098. currentProp.forParseResult = parseForExpression(currentProp.exp);
  18099. }
  18100. }
  18101. }
  18102. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  18103. currentOpenTag.props.push(currentProp);
  18104. }
  18105. }
  18106. currentAttrValue = "";
  18107. currentAttrStartIndex = currentAttrEndIndex = -1;
  18108. },
  18109. oncomment(start, end) {
  18110. if (currentOptions.comments) {
  18111. addNode({
  18112. type: 3,
  18113. content: getSlice(start, end),
  18114. loc: getLoc(start - 4, end + 3)
  18115. });
  18116. }
  18117. },
  18118. onend() {
  18119. const end = currentInput.length;
  18120. if (tokenizer.state !== 1) {
  18121. switch (tokenizer.state) {
  18122. case 5:
  18123. case 8:
  18124. emitError(5, end);
  18125. break;
  18126. case 3:
  18127. case 4:
  18128. emitError(
  18129. 25,
  18130. tokenizer.sectionStart
  18131. );
  18132. break;
  18133. case 28:
  18134. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  18135. emitError(6, end);
  18136. } else {
  18137. emitError(7, end);
  18138. }
  18139. break;
  18140. case 6:
  18141. case 7:
  18142. case 9:
  18143. case 11:
  18144. case 12:
  18145. case 13:
  18146. case 14:
  18147. case 15:
  18148. case 16:
  18149. case 17:
  18150. case 18:
  18151. case 19:
  18152. // "
  18153. case 20:
  18154. // '
  18155. case 21:
  18156. emitError(9, end);
  18157. break;
  18158. }
  18159. }
  18160. for (let index = 0; index < stack.length; index++) {
  18161. onCloseTag(stack[index], end - 1);
  18162. emitError(24, stack[index].loc.start.offset);
  18163. }
  18164. },
  18165. oncdata(start, end) {
  18166. if (stack[0].ns !== 0) {
  18167. onText(getSlice(start, end), start, end);
  18168. } else {
  18169. emitError(1, start - 9);
  18170. }
  18171. },
  18172. onprocessinginstruction(start) {
  18173. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  18174. emitError(
  18175. 21,
  18176. start - 1
  18177. );
  18178. }
  18179. }
  18180. });
  18181. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  18182. const stripParensRE = /^\(|\)$/g;
  18183. function parseForExpression(input) {
  18184. const loc = input.loc;
  18185. const exp = input.content;
  18186. const inMatch = exp.match(forAliasRE);
  18187. if (!inMatch) return;
  18188. const [, LHS, RHS] = inMatch;
  18189. const createAliasExpression = (content, offset, asParam = false) => {
  18190. const start = loc.start.offset + offset;
  18191. const end = start + content.length;
  18192. return createExp(
  18193. content,
  18194. false,
  18195. getLoc(start, end),
  18196. 0,
  18197. asParam ? 1 /* Params */ : 0 /* Normal */
  18198. );
  18199. };
  18200. const result = {
  18201. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  18202. value: void 0,
  18203. key: void 0,
  18204. index: void 0,
  18205. finalized: false
  18206. };
  18207. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  18208. const trimmedOffset = LHS.indexOf(valueContent);
  18209. const iteratorMatch = valueContent.match(forIteratorRE);
  18210. if (iteratorMatch) {
  18211. valueContent = valueContent.replace(forIteratorRE, "").trim();
  18212. const keyContent = iteratorMatch[1].trim();
  18213. let keyOffset;
  18214. if (keyContent) {
  18215. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  18216. result.key = createAliasExpression(keyContent, keyOffset, true);
  18217. }
  18218. if (iteratorMatch[2]) {
  18219. const indexContent = iteratorMatch[2].trim();
  18220. if (indexContent) {
  18221. result.index = createAliasExpression(
  18222. indexContent,
  18223. exp.indexOf(
  18224. indexContent,
  18225. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  18226. ),
  18227. true
  18228. );
  18229. }
  18230. }
  18231. }
  18232. if (valueContent) {
  18233. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  18234. }
  18235. return result;
  18236. }
  18237. function getSlice(start, end) {
  18238. return currentInput.slice(start, end);
  18239. }
  18240. function endOpenTag(end) {
  18241. if (tokenizer.inSFCRoot) {
  18242. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  18243. }
  18244. addNode(currentOpenTag);
  18245. const { tag, ns } = currentOpenTag;
  18246. if (ns === 0 && currentOptions.isPreTag(tag)) {
  18247. inPre++;
  18248. }
  18249. if (currentOptions.isVoidTag(tag)) {
  18250. onCloseTag(currentOpenTag, end);
  18251. } else {
  18252. stack.unshift(currentOpenTag);
  18253. if (ns === 1 || ns === 2) {
  18254. tokenizer.inXML = true;
  18255. }
  18256. }
  18257. currentOpenTag = null;
  18258. }
  18259. function onText(content, start, end) {
  18260. const parent = stack[0] || currentRoot;
  18261. const lastNode = parent.children[parent.children.length - 1];
  18262. if (lastNode && lastNode.type === 2) {
  18263. lastNode.content += content;
  18264. setLocEnd(lastNode.loc, end);
  18265. } else {
  18266. parent.children.push({
  18267. type: 2,
  18268. content,
  18269. loc: getLoc(start, end)
  18270. });
  18271. }
  18272. }
  18273. function onCloseTag(el, end, isImplied = false) {
  18274. if (isImplied) {
  18275. setLocEnd(el.loc, backTrack(end, 60));
  18276. } else {
  18277. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  18278. }
  18279. if (tokenizer.inSFCRoot) {
  18280. if (el.children.length) {
  18281. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  18282. } else {
  18283. el.innerLoc.end = extend({}, el.innerLoc.start);
  18284. }
  18285. el.innerLoc.source = getSlice(
  18286. el.innerLoc.start.offset,
  18287. el.innerLoc.end.offset
  18288. );
  18289. }
  18290. const { tag, ns, children } = el;
  18291. if (!inVPre) {
  18292. if (tag === "slot") {
  18293. el.tagType = 2;
  18294. } else if (isFragmentTemplate(el)) {
  18295. el.tagType = 3;
  18296. } else if (isComponent(el)) {
  18297. el.tagType = 1;
  18298. }
  18299. }
  18300. if (!tokenizer.inRCDATA) {
  18301. el.children = condenseWhitespace(children);
  18302. }
  18303. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  18304. const first = children[0];
  18305. if (first && first.type === 2) {
  18306. first.content = first.content.replace(/^\r?\n/, "");
  18307. }
  18308. }
  18309. if (ns === 0 && currentOptions.isPreTag(tag)) {
  18310. inPre--;
  18311. }
  18312. if (currentVPreBoundary === el) {
  18313. inVPre = tokenizer.inVPre = false;
  18314. currentVPreBoundary = null;
  18315. }
  18316. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  18317. tokenizer.inXML = false;
  18318. }
  18319. }
  18320. function lookAhead(index, c) {
  18321. let i = index;
  18322. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  18323. return i;
  18324. }
  18325. function backTrack(index, c) {
  18326. let i = index;
  18327. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  18328. return i;
  18329. }
  18330. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  18331. function isFragmentTemplate({ tag, props }) {
  18332. if (tag === "template") {
  18333. for (let i = 0; i < props.length; i++) {
  18334. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  18335. return true;
  18336. }
  18337. }
  18338. }
  18339. return false;
  18340. }
  18341. function isComponent({ tag, props }) {
  18342. if (currentOptions.isCustomElement(tag)) {
  18343. return false;
  18344. }
  18345. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  18346. return true;
  18347. }
  18348. for (let i = 0; i < props.length; i++) {
  18349. const p = props[i];
  18350. if (p.type === 6) {
  18351. if (p.name === "is" && p.value) {
  18352. if (p.value.content.startsWith("vue:")) {
  18353. return true;
  18354. }
  18355. }
  18356. }
  18357. }
  18358. return false;
  18359. }
  18360. function isUpperCase(c) {
  18361. return c > 64 && c < 91;
  18362. }
  18363. const windowsNewlineRE = /\r\n/g;
  18364. function condenseWhitespace(nodes) {
  18365. const shouldCondense = currentOptions.whitespace !== "preserve";
  18366. let removedWhitespace = false;
  18367. for (let i = 0; i < nodes.length; i++) {
  18368. const node = nodes[i];
  18369. if (node.type === 2) {
  18370. if (!inPre) {
  18371. if (isAllWhitespace(node.content)) {
  18372. const prev = nodes[i - 1] && nodes[i - 1].type;
  18373. const next = nodes[i + 1] && nodes[i + 1].type;
  18374. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  18375. removedWhitespace = true;
  18376. nodes[i] = null;
  18377. } else {
  18378. node.content = " ";
  18379. }
  18380. } else if (shouldCondense) {
  18381. node.content = condense(node.content);
  18382. }
  18383. } else {
  18384. node.content = node.content.replace(windowsNewlineRE, "\n");
  18385. }
  18386. }
  18387. }
  18388. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  18389. }
  18390. function isAllWhitespace(str) {
  18391. for (let i = 0; i < str.length; i++) {
  18392. if (!isWhitespace(str.charCodeAt(i))) {
  18393. return false;
  18394. }
  18395. }
  18396. return true;
  18397. }
  18398. function hasNewlineChar(str) {
  18399. for (let i = 0; i < str.length; i++) {
  18400. const c = str.charCodeAt(i);
  18401. if (c === 10 || c === 13) {
  18402. return true;
  18403. }
  18404. }
  18405. return false;
  18406. }
  18407. function condense(str) {
  18408. let ret = "";
  18409. let prevCharIsWhitespace = false;
  18410. for (let i = 0; i < str.length; i++) {
  18411. if (isWhitespace(str.charCodeAt(i))) {
  18412. if (!prevCharIsWhitespace) {
  18413. ret += " ";
  18414. prevCharIsWhitespace = true;
  18415. }
  18416. } else {
  18417. ret += str[i];
  18418. prevCharIsWhitespace = false;
  18419. }
  18420. }
  18421. return ret;
  18422. }
  18423. function addNode(node) {
  18424. (stack[0] || currentRoot).children.push(node);
  18425. }
  18426. function getLoc(start, end) {
  18427. return {
  18428. start: tokenizer.getPos(start),
  18429. // @ts-expect-error allow late attachment
  18430. end: end == null ? end : tokenizer.getPos(end),
  18431. // @ts-expect-error allow late attachment
  18432. source: end == null ? end : getSlice(start, end)
  18433. };
  18434. }
  18435. function cloneLoc(loc) {
  18436. return getLoc(loc.start.offset, loc.end.offset);
  18437. }
  18438. function setLocEnd(loc, end) {
  18439. loc.end = tokenizer.getPos(end);
  18440. loc.source = getSlice(loc.start.offset, end);
  18441. }
  18442. function dirToAttr(dir) {
  18443. const attr = {
  18444. type: 6,
  18445. name: dir.rawName,
  18446. nameLoc: getLoc(
  18447. dir.loc.start.offset,
  18448. dir.loc.start.offset + dir.rawName.length
  18449. ),
  18450. value: void 0,
  18451. loc: dir.loc
  18452. };
  18453. if (dir.exp) {
  18454. const loc = dir.exp.loc;
  18455. if (loc.end.offset < dir.loc.end.offset) {
  18456. loc.start.offset--;
  18457. loc.start.column--;
  18458. loc.end.offset++;
  18459. loc.end.column++;
  18460. }
  18461. attr.value = {
  18462. type: 2,
  18463. content: dir.exp.content,
  18464. loc
  18465. };
  18466. }
  18467. return attr;
  18468. }
  18469. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  18470. const exp = createSimpleExpression(content, isStatic, loc, constType);
  18471. if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
  18472. if (isSimpleIdentifier(content)) {
  18473. exp.ast = null;
  18474. return exp;
  18475. }
  18476. try {
  18477. const plugins = currentOptions.expressionPlugins;
  18478. const options = {
  18479. plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
  18480. };
  18481. if (parseMode === 2 /* Statements */) {
  18482. exp.ast = libExports.parse(` ${content} `, options).program;
  18483. } else if (parseMode === 1 /* Params */) {
  18484. exp.ast = libExports.parseExpression(`(${content})=>{}`, options);
  18485. } else {
  18486. exp.ast = libExports.parseExpression(`(${content})`, options);
  18487. }
  18488. } catch (e) {
  18489. exp.ast = false;
  18490. emitError(45, loc.start.offset, e.message);
  18491. }
  18492. }
  18493. return exp;
  18494. }
  18495. function emitError(code, index, message) {
  18496. currentOptions.onError(
  18497. createCompilerError(code, getLoc(index, index), void 0, message)
  18498. );
  18499. }
  18500. function reset() {
  18501. tokenizer.reset();
  18502. currentOpenTag = null;
  18503. currentProp = null;
  18504. currentAttrValue = "";
  18505. currentAttrStartIndex = -1;
  18506. currentAttrEndIndex = -1;
  18507. stack.length = 0;
  18508. }
  18509. function baseParse(input, options) {
  18510. reset();
  18511. currentInput = input;
  18512. currentOptions = extend({}, defaultParserOptions);
  18513. if (options) {
  18514. let key;
  18515. for (key in options) {
  18516. if (options[key] != null) {
  18517. currentOptions[key] = options[key];
  18518. }
  18519. }
  18520. }
  18521. {
  18522. if (currentOptions.decodeEntities) {
  18523. console.warn(
  18524. `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
  18525. );
  18526. }
  18527. }
  18528. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  18529. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  18530. const delimiters = options && options.delimiters;
  18531. if (delimiters) {
  18532. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  18533. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  18534. }
  18535. const root = currentRoot = createRoot([], input);
  18536. tokenizer.parse(currentInput);
  18537. root.loc = getLoc(0, input.length);
  18538. root.children = condenseWhitespace(root.children);
  18539. currentRoot = null;
  18540. return root;
  18541. }
  18542. function cacheStatic(root, context) {
  18543. walk$1(
  18544. root,
  18545. void 0,
  18546. context,
  18547. // Root node is unfortunately non-hoistable due to potential parent
  18548. // fallthrough attributes.
  18549. !!getSingleElementRoot(root)
  18550. );
  18551. }
  18552. function getSingleElementRoot(root) {
  18553. const children = root.children.filter((x) => x.type !== 3);
  18554. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  18555. }
  18556. function walk$1(node, parent, context, doNotHoistNode = false, inFor = false) {
  18557. const { children } = node;
  18558. const toCache = [];
  18559. for (let i = 0; i < children.length; i++) {
  18560. const child = children[i];
  18561. if (child.type === 1 && child.tagType === 0) {
  18562. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  18563. if (constantType > 0) {
  18564. if (constantType >= 2) {
  18565. child.codegenNode.patchFlag = -1;
  18566. toCache.push(child);
  18567. continue;
  18568. }
  18569. } else {
  18570. const codegenNode = child.codegenNode;
  18571. if (codegenNode.type === 13) {
  18572. const flag = codegenNode.patchFlag;
  18573. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  18574. const props = getNodeProps(child);
  18575. if (props) {
  18576. codegenNode.props = context.hoist(props);
  18577. }
  18578. }
  18579. if (codegenNode.dynamicProps) {
  18580. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  18581. }
  18582. }
  18583. }
  18584. } else if (child.type === 12) {
  18585. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  18586. if (constantType >= 2) {
  18587. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  18588. child.codegenNode.arguments.push(
  18589. -1 + (` /* ${PatchFlagNames[-1]} */` )
  18590. );
  18591. }
  18592. toCache.push(child);
  18593. continue;
  18594. }
  18595. }
  18596. if (child.type === 1) {
  18597. const isComponent = child.tagType === 1;
  18598. if (isComponent) {
  18599. context.scopes.vSlot++;
  18600. }
  18601. walk$1(child, node, context, false, inFor);
  18602. if (isComponent) {
  18603. context.scopes.vSlot--;
  18604. }
  18605. } else if (child.type === 11) {
  18606. walk$1(child, node, context, child.children.length === 1, true);
  18607. } else if (child.type === 9) {
  18608. for (let i2 = 0; i2 < child.branches.length; i2++) {
  18609. walk$1(
  18610. child.branches[i2],
  18611. node,
  18612. context,
  18613. child.branches[i2].children.length === 1,
  18614. inFor
  18615. );
  18616. }
  18617. }
  18618. }
  18619. let cachedAsArray = false;
  18620. const slotCacheKeys = [];
  18621. if (toCache.length === children.length && node.type === 1) {
  18622. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray$3(node.codegenNode.children)) {
  18623. node.codegenNode.children = getCacheExpression(
  18624. createArrayExpression(node.codegenNode.children)
  18625. );
  18626. cachedAsArray = true;
  18627. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray$3(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  18628. const slot = getSlotNode(node.codegenNode, "default");
  18629. if (slot) {
  18630. slotCacheKeys.push(context.cached.length);
  18631. slot.returns = getCacheExpression(
  18632. createArrayExpression(slot.returns)
  18633. );
  18634. cachedAsArray = true;
  18635. }
  18636. } 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) {
  18637. const slotName = findDir(node, "slot", true);
  18638. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  18639. if (slot) {
  18640. slotCacheKeys.push(context.cached.length);
  18641. slot.returns = getCacheExpression(
  18642. createArrayExpression(slot.returns)
  18643. );
  18644. cachedAsArray = true;
  18645. }
  18646. }
  18647. }
  18648. if (!cachedAsArray) {
  18649. for (const child of toCache) {
  18650. slotCacheKeys.push(context.cached.length);
  18651. child.codegenNode = context.cache(child.codegenNode);
  18652. }
  18653. }
  18654. if (slotCacheKeys.length && node.type === 1 && node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray$3(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  18655. node.codegenNode.children.properties.push(
  18656. createObjectProperty(
  18657. `__`,
  18658. createSimpleExpression(JSON.stringify(slotCacheKeys), false)
  18659. )
  18660. );
  18661. }
  18662. function getCacheExpression(value) {
  18663. const exp = context.cache(value);
  18664. if (inFor && context.hmr) {
  18665. exp.needArraySpread = true;
  18666. }
  18667. return exp;
  18668. }
  18669. function getSlotNode(node2, name) {
  18670. if (node2.children && !isArray$3(node2.children) && node2.children.type === 15) {
  18671. const slot = node2.children.properties.find(
  18672. (p) => p.key === name || p.key.content === name
  18673. );
  18674. return slot && slot.value;
  18675. }
  18676. }
  18677. if (toCache.length && context.transformHoist) {
  18678. context.transformHoist(children, context, node);
  18679. }
  18680. }
  18681. function getConstantType(node, context) {
  18682. const { constantCache } = context;
  18683. switch (node.type) {
  18684. case 1:
  18685. if (node.tagType !== 0) {
  18686. return 0;
  18687. }
  18688. const cached = constantCache.get(node);
  18689. if (cached !== void 0) {
  18690. return cached;
  18691. }
  18692. const codegenNode = node.codegenNode;
  18693. if (codegenNode.type !== 13) {
  18694. return 0;
  18695. }
  18696. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  18697. return 0;
  18698. }
  18699. if (codegenNode.patchFlag === void 0) {
  18700. let returnType2 = 3;
  18701. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  18702. if (generatedPropsType === 0) {
  18703. constantCache.set(node, 0);
  18704. return 0;
  18705. }
  18706. if (generatedPropsType < returnType2) {
  18707. returnType2 = generatedPropsType;
  18708. }
  18709. for (let i = 0; i < node.children.length; i++) {
  18710. const childType = getConstantType(node.children[i], context);
  18711. if (childType === 0) {
  18712. constantCache.set(node, 0);
  18713. return 0;
  18714. }
  18715. if (childType < returnType2) {
  18716. returnType2 = childType;
  18717. }
  18718. }
  18719. if (returnType2 > 1) {
  18720. for (let i = 0; i < node.props.length; i++) {
  18721. const p = node.props[i];
  18722. if (p.type === 7 && p.name === "bind" && p.exp) {
  18723. const expType = getConstantType(p.exp, context);
  18724. if (expType === 0) {
  18725. constantCache.set(node, 0);
  18726. return 0;
  18727. }
  18728. if (expType < returnType2) {
  18729. returnType2 = expType;
  18730. }
  18731. }
  18732. }
  18733. }
  18734. if (codegenNode.isBlock) {
  18735. for (let i = 0; i < node.props.length; i++) {
  18736. const p = node.props[i];
  18737. if (p.type === 7) {
  18738. constantCache.set(node, 0);
  18739. return 0;
  18740. }
  18741. }
  18742. context.removeHelper(OPEN_BLOCK);
  18743. context.removeHelper(
  18744. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  18745. );
  18746. codegenNode.isBlock = false;
  18747. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  18748. }
  18749. constantCache.set(node, returnType2);
  18750. return returnType2;
  18751. } else {
  18752. constantCache.set(node, 0);
  18753. return 0;
  18754. }
  18755. case 2:
  18756. case 3:
  18757. return 3;
  18758. case 9:
  18759. case 11:
  18760. case 10:
  18761. return 0;
  18762. case 5:
  18763. case 12:
  18764. return getConstantType(node.content, context);
  18765. case 4:
  18766. return node.constType;
  18767. case 8:
  18768. let returnType = 3;
  18769. for (let i = 0; i < node.children.length; i++) {
  18770. const child = node.children[i];
  18771. if (isString$1(child) || isSymbol$1(child)) {
  18772. continue;
  18773. }
  18774. const childType = getConstantType(child, context);
  18775. if (childType === 0) {
  18776. return 0;
  18777. } else if (childType < returnType) {
  18778. returnType = childType;
  18779. }
  18780. }
  18781. return returnType;
  18782. case 20:
  18783. return 2;
  18784. default:
  18785. return 0;
  18786. }
  18787. }
  18788. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  18789. NORMALIZE_CLASS,
  18790. NORMALIZE_STYLE,
  18791. NORMALIZE_PROPS,
  18792. GUARD_REACTIVE_PROPS
  18793. ]);
  18794. function getConstantTypeOfHelperCall(value, context) {
  18795. if (value.type === 14 && !isString$1(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  18796. const arg = value.arguments[0];
  18797. if (arg.type === 4) {
  18798. return getConstantType(arg, context);
  18799. } else if (arg.type === 14) {
  18800. return getConstantTypeOfHelperCall(arg, context);
  18801. }
  18802. }
  18803. return 0;
  18804. }
  18805. function getGeneratedPropsConstantType(node, context) {
  18806. let returnType = 3;
  18807. const props = getNodeProps(node);
  18808. if (props && props.type === 15) {
  18809. const { properties } = props;
  18810. for (let i = 0; i < properties.length; i++) {
  18811. const { key, value } = properties[i];
  18812. const keyType = getConstantType(key, context);
  18813. if (keyType === 0) {
  18814. return keyType;
  18815. }
  18816. if (keyType < returnType) {
  18817. returnType = keyType;
  18818. }
  18819. let valueType;
  18820. if (value.type === 4) {
  18821. valueType = getConstantType(value, context);
  18822. } else if (value.type === 14) {
  18823. valueType = getConstantTypeOfHelperCall(value, context);
  18824. } else {
  18825. valueType = 0;
  18826. }
  18827. if (valueType === 0) {
  18828. return valueType;
  18829. }
  18830. if (valueType < returnType) {
  18831. returnType = valueType;
  18832. }
  18833. }
  18834. }
  18835. return returnType;
  18836. }
  18837. function getNodeProps(node) {
  18838. const codegenNode = node.codegenNode;
  18839. if (codegenNode.type === 13) {
  18840. return codegenNode.props;
  18841. }
  18842. }
  18843. function createTransformContext(root, {
  18844. filename = "",
  18845. prefixIdentifiers = false,
  18846. hoistStatic = false,
  18847. hmr = false,
  18848. cacheHandlers = false,
  18849. nodeTransforms = [],
  18850. directiveTransforms = {},
  18851. transformHoist = null,
  18852. isBuiltInComponent = NOOP,
  18853. isCustomElement = NOOP,
  18854. expressionPlugins = [],
  18855. scopeId = null,
  18856. slotted = true,
  18857. ssr = false,
  18858. inSSR = false,
  18859. ssrCssVars = ``,
  18860. bindingMetadata = EMPTY_OBJ,
  18861. inline = false,
  18862. isTS = false,
  18863. onError = defaultOnError,
  18864. onWarn = defaultOnWarn,
  18865. compatConfig
  18866. }) {
  18867. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  18868. const context = {
  18869. // options
  18870. filename,
  18871. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  18872. prefixIdentifiers,
  18873. hoistStatic,
  18874. hmr,
  18875. cacheHandlers,
  18876. nodeTransforms,
  18877. directiveTransforms,
  18878. transformHoist,
  18879. isBuiltInComponent,
  18880. isCustomElement,
  18881. expressionPlugins,
  18882. scopeId,
  18883. slotted,
  18884. ssr,
  18885. inSSR,
  18886. ssrCssVars,
  18887. bindingMetadata,
  18888. inline,
  18889. isTS,
  18890. onError,
  18891. onWarn,
  18892. compatConfig,
  18893. // state
  18894. root,
  18895. helpers: /* @__PURE__ */ new Map(),
  18896. components: /* @__PURE__ */ new Set(),
  18897. directives: /* @__PURE__ */ new Set(),
  18898. hoists: [],
  18899. imports: [],
  18900. cached: [],
  18901. constantCache: /* @__PURE__ */ new WeakMap(),
  18902. temps: 0,
  18903. identifiers: /* @__PURE__ */ Object.create(null),
  18904. scopes: {
  18905. vFor: 0,
  18906. vSlot: 0,
  18907. vPre: 0,
  18908. vOnce: 0
  18909. },
  18910. parent: null,
  18911. grandParent: null,
  18912. currentNode: root,
  18913. childIndex: 0,
  18914. inVOnce: false,
  18915. // methods
  18916. helper(name) {
  18917. const count = context.helpers.get(name) || 0;
  18918. context.helpers.set(name, count + 1);
  18919. return name;
  18920. },
  18921. removeHelper(name) {
  18922. const count = context.helpers.get(name);
  18923. if (count) {
  18924. const currentCount = count - 1;
  18925. if (!currentCount) {
  18926. context.helpers.delete(name);
  18927. } else {
  18928. context.helpers.set(name, currentCount);
  18929. }
  18930. }
  18931. },
  18932. helperString(name) {
  18933. return `_${helperNameMap[context.helper(name)]}`;
  18934. },
  18935. replaceNode(node) {
  18936. {
  18937. if (!context.currentNode) {
  18938. throw new Error(`Node being replaced is already removed.`);
  18939. }
  18940. if (!context.parent) {
  18941. throw new Error(`Cannot replace root node.`);
  18942. }
  18943. }
  18944. context.parent.children[context.childIndex] = context.currentNode = node;
  18945. },
  18946. removeNode(node) {
  18947. if (!context.parent) {
  18948. throw new Error(`Cannot remove root node.`);
  18949. }
  18950. const list = context.parent.children;
  18951. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  18952. if (removalIndex < 0) {
  18953. throw new Error(`node being removed is not a child of current parent`);
  18954. }
  18955. if (!node || node === context.currentNode) {
  18956. context.currentNode = null;
  18957. context.onNodeRemoved();
  18958. } else {
  18959. if (context.childIndex > removalIndex) {
  18960. context.childIndex--;
  18961. context.onNodeRemoved();
  18962. }
  18963. }
  18964. context.parent.children.splice(removalIndex, 1);
  18965. },
  18966. onNodeRemoved: NOOP,
  18967. addIdentifiers(exp) {
  18968. {
  18969. if (isString$1(exp)) {
  18970. addId(exp);
  18971. } else if (exp.identifiers) {
  18972. exp.identifiers.forEach(addId);
  18973. } else if (exp.type === 4) {
  18974. addId(exp.content);
  18975. }
  18976. }
  18977. },
  18978. removeIdentifiers(exp) {
  18979. {
  18980. if (isString$1(exp)) {
  18981. removeId(exp);
  18982. } else if (exp.identifiers) {
  18983. exp.identifiers.forEach(removeId);
  18984. } else if (exp.type === 4) {
  18985. removeId(exp.content);
  18986. }
  18987. }
  18988. },
  18989. hoist(exp) {
  18990. if (isString$1(exp)) exp = createSimpleExpression(exp);
  18991. context.hoists.push(exp);
  18992. const identifier = createSimpleExpression(
  18993. `_hoisted_${context.hoists.length}`,
  18994. false,
  18995. exp.loc,
  18996. 2
  18997. );
  18998. identifier.hoisted = exp;
  18999. return identifier;
  19000. },
  19001. cache(exp, isVNode = false, inVOnce = false) {
  19002. const cacheExp = createCacheExpression(
  19003. context.cached.length,
  19004. exp,
  19005. isVNode,
  19006. inVOnce
  19007. );
  19008. context.cached.push(cacheExp);
  19009. return cacheExp;
  19010. }
  19011. };
  19012. function addId(id) {
  19013. const { identifiers } = context;
  19014. if (identifiers[id] === void 0) {
  19015. identifiers[id] = 0;
  19016. }
  19017. identifiers[id]++;
  19018. }
  19019. function removeId(id) {
  19020. context.identifiers[id]--;
  19021. }
  19022. return context;
  19023. }
  19024. function transform(root, options) {
  19025. const context = createTransformContext(root, options);
  19026. traverseNode(root, context);
  19027. if (options.hoistStatic) {
  19028. cacheStatic(root, context);
  19029. }
  19030. if (!options.ssr) {
  19031. createRootCodegen(root, context);
  19032. }
  19033. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  19034. root.components = [...context.components];
  19035. root.directives = [...context.directives];
  19036. root.imports = context.imports;
  19037. root.hoists = context.hoists;
  19038. root.temps = context.temps;
  19039. root.cached = context.cached;
  19040. root.transformed = true;
  19041. }
  19042. function createRootCodegen(root, context) {
  19043. const { helper } = context;
  19044. const { children } = root;
  19045. if (children.length === 1) {
  19046. const singleElementRootChild = getSingleElementRoot(root);
  19047. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  19048. const codegenNode = singleElementRootChild.codegenNode;
  19049. if (codegenNode.type === 13) {
  19050. convertToBlock(codegenNode, context);
  19051. }
  19052. root.codegenNode = codegenNode;
  19053. } else {
  19054. root.codegenNode = children[0];
  19055. }
  19056. } else if (children.length > 1) {
  19057. let patchFlag = 64;
  19058. if (children.filter((c) => c.type !== 3).length === 1) {
  19059. patchFlag |= 2048;
  19060. }
  19061. root.codegenNode = createVNodeCall(
  19062. context,
  19063. helper(FRAGMENT),
  19064. void 0,
  19065. root.children,
  19066. patchFlag,
  19067. void 0,
  19068. void 0,
  19069. true,
  19070. void 0,
  19071. false
  19072. );
  19073. } else ;
  19074. }
  19075. function traverseChildren(parent, context) {
  19076. let i = 0;
  19077. const nodeRemoved = () => {
  19078. i--;
  19079. };
  19080. for (; i < parent.children.length; i++) {
  19081. const child = parent.children[i];
  19082. if (isString$1(child)) continue;
  19083. context.grandParent = context.parent;
  19084. context.parent = parent;
  19085. context.childIndex = i;
  19086. context.onNodeRemoved = nodeRemoved;
  19087. traverseNode(child, context);
  19088. }
  19089. }
  19090. function traverseNode(node, context) {
  19091. context.currentNode = node;
  19092. const { nodeTransforms } = context;
  19093. const exitFns = [];
  19094. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  19095. const onExit = nodeTransforms[i2](node, context);
  19096. if (onExit) {
  19097. if (isArray$3(onExit)) {
  19098. exitFns.push(...onExit);
  19099. } else {
  19100. exitFns.push(onExit);
  19101. }
  19102. }
  19103. if (!context.currentNode) {
  19104. return;
  19105. } else {
  19106. node = context.currentNode;
  19107. }
  19108. }
  19109. switch (node.type) {
  19110. case 3:
  19111. if (!context.ssr) {
  19112. context.helper(CREATE_COMMENT);
  19113. }
  19114. break;
  19115. case 5:
  19116. if (!context.ssr) {
  19117. context.helper(TO_DISPLAY_STRING);
  19118. }
  19119. break;
  19120. // for container types, further traverse downwards
  19121. case 9:
  19122. for (let i2 = 0; i2 < node.branches.length; i2++) {
  19123. traverseNode(node.branches[i2], context);
  19124. }
  19125. break;
  19126. case 10:
  19127. case 11:
  19128. case 1:
  19129. case 0:
  19130. traverseChildren(node, context);
  19131. break;
  19132. }
  19133. context.currentNode = node;
  19134. let i = exitFns.length;
  19135. while (i--) {
  19136. exitFns[i]();
  19137. }
  19138. }
  19139. function createStructuralDirectiveTransform(name, fn) {
  19140. const matches = isString$1(name) ? (n) => n === name : (n) => name.test(n);
  19141. return (node, context) => {
  19142. if (node.type === 1) {
  19143. const { props } = node;
  19144. if (node.tagType === 3 && props.some(isVSlot)) {
  19145. return;
  19146. }
  19147. const exitFns = [];
  19148. for (let i = 0; i < props.length; i++) {
  19149. const prop = props[i];
  19150. if (prop.type === 7 && matches(prop.name)) {
  19151. props.splice(i, 1);
  19152. i--;
  19153. const onExit = fn(node, prop, context);
  19154. if (onExit) exitFns.push(onExit);
  19155. }
  19156. }
  19157. return exitFns;
  19158. }
  19159. };
  19160. }
  19161. var sourceMap$1 = {};
  19162. var sourceMapGenerator$1 = {};
  19163. var base64Vlq$1 = {};
  19164. var base64$1 = {};
  19165. /* -*- Mode: js; js-indent-level: 2; -*- */
  19166. var hasRequiredBase64$1;
  19167. function requireBase64$1 () {
  19168. if (hasRequiredBase64$1) return base64$1;
  19169. hasRequiredBase64$1 = 1;
  19170. /*
  19171. * Copyright 2011 Mozilla Foundation and contributors
  19172. * Licensed under the New BSD license. See LICENSE or:
  19173. * http://opensource.org/licenses/BSD-3-Clause
  19174. */
  19175. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  19176. /**
  19177. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  19178. */
  19179. base64$1.encode = function (number) {
  19180. if (0 <= number && number < intToCharMap.length) {
  19181. return intToCharMap[number];
  19182. }
  19183. throw new TypeError("Must be between 0 and 63: " + number);
  19184. };
  19185. /**
  19186. * Decode a single base 64 character code digit to an integer. Returns -1 on
  19187. * failure.
  19188. */
  19189. base64$1.decode = function (charCode) {
  19190. var bigA = 65; // 'A'
  19191. var bigZ = 90; // 'Z'
  19192. var littleA = 97; // 'a'
  19193. var littleZ = 122; // 'z'
  19194. var zero = 48; // '0'
  19195. var nine = 57; // '9'
  19196. var plus = 43; // '+'
  19197. var slash = 47; // '/'
  19198. var littleOffset = 26;
  19199. var numberOffset = 52;
  19200. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  19201. if (bigA <= charCode && charCode <= bigZ) {
  19202. return (charCode - bigA);
  19203. }
  19204. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  19205. if (littleA <= charCode && charCode <= littleZ) {
  19206. return (charCode - littleA + littleOffset);
  19207. }
  19208. // 52 - 61: 0123456789
  19209. if (zero <= charCode && charCode <= nine) {
  19210. return (charCode - zero + numberOffset);
  19211. }
  19212. // 62: +
  19213. if (charCode == plus) {
  19214. return 62;
  19215. }
  19216. // 63: /
  19217. if (charCode == slash) {
  19218. return 63;
  19219. }
  19220. // Invalid base64 digit.
  19221. return -1;
  19222. };
  19223. return base64$1;
  19224. }
  19225. /* -*- Mode: js; js-indent-level: 2; -*- */
  19226. var hasRequiredBase64Vlq$1;
  19227. function requireBase64Vlq$1 () {
  19228. if (hasRequiredBase64Vlq$1) return base64Vlq$1;
  19229. hasRequiredBase64Vlq$1 = 1;
  19230. /*
  19231. * Copyright 2011 Mozilla Foundation and contributors
  19232. * Licensed under the New BSD license. See LICENSE or:
  19233. * http://opensource.org/licenses/BSD-3-Clause
  19234. *
  19235. * Based on the Base 64 VLQ implementation in Closure Compiler:
  19236. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  19237. *
  19238. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  19239. * Redistribution and use in source and binary forms, with or without
  19240. * modification, are permitted provided that the following conditions are
  19241. * met:
  19242. *
  19243. * * Redistributions of source code must retain the above copyright
  19244. * notice, this list of conditions and the following disclaimer.
  19245. * * Redistributions in binary form must reproduce the above
  19246. * copyright notice, this list of conditions and the following
  19247. * disclaimer in the documentation and/or other materials provided
  19248. * with the distribution.
  19249. * * Neither the name of Google Inc. nor the names of its
  19250. * contributors may be used to endorse or promote products derived
  19251. * from this software without specific prior written permission.
  19252. *
  19253. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19254. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19255. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19256. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19257. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19258. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19259. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19260. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19261. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19262. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19263. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19264. */
  19265. var base64 = /*@__PURE__*/ requireBase64$1();
  19266. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  19267. // length quantities we use in the source map spec, the first bit is the sign,
  19268. // the next four bits are the actual value, and the 6th bit is the
  19269. // continuation bit. The continuation bit tells us whether there are more
  19270. // digits in this value following this digit.
  19271. //
  19272. // Continuation
  19273. // | Sign
  19274. // | |
  19275. // V V
  19276. // 101011
  19277. var VLQ_BASE_SHIFT = 5;
  19278. // binary: 100000
  19279. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  19280. // binary: 011111
  19281. var VLQ_BASE_MASK = VLQ_BASE - 1;
  19282. // binary: 100000
  19283. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  19284. /**
  19285. * Converts from a two-complement value to a value where the sign bit is
  19286. * placed in the least significant bit. For example, as decimals:
  19287. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  19288. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  19289. */
  19290. function toVLQSigned(aValue) {
  19291. return aValue < 0
  19292. ? ((-aValue) << 1) + 1
  19293. : (aValue << 1) + 0;
  19294. }
  19295. /**
  19296. * Converts to a two-complement value from a value where the sign bit is
  19297. * placed in the least significant bit. For example, as decimals:
  19298. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  19299. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  19300. */
  19301. function fromVLQSigned(aValue) {
  19302. var isNegative = (aValue & 1) === 1;
  19303. var shifted = aValue >> 1;
  19304. return isNegative
  19305. ? -shifted
  19306. : shifted;
  19307. }
  19308. /**
  19309. * Returns the base 64 VLQ encoded value.
  19310. */
  19311. base64Vlq$1.encode = function base64VLQ_encode(aValue) {
  19312. var encoded = "";
  19313. var digit;
  19314. var vlq = toVLQSigned(aValue);
  19315. do {
  19316. digit = vlq & VLQ_BASE_MASK;
  19317. vlq >>>= VLQ_BASE_SHIFT;
  19318. if (vlq > 0) {
  19319. // There are still more digits in this value, so we must make sure the
  19320. // continuation bit is marked.
  19321. digit |= VLQ_CONTINUATION_BIT;
  19322. }
  19323. encoded += base64.encode(digit);
  19324. } while (vlq > 0);
  19325. return encoded;
  19326. };
  19327. /**
  19328. * Decodes the next base 64 VLQ value from the given string and returns the
  19329. * value and the rest of the string via the out parameter.
  19330. */
  19331. base64Vlq$1.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  19332. var strLen = aStr.length;
  19333. var result = 0;
  19334. var shift = 0;
  19335. var continuation, digit;
  19336. do {
  19337. if (aIndex >= strLen) {
  19338. throw new Error("Expected more digits in base 64 VLQ value.");
  19339. }
  19340. digit = base64.decode(aStr.charCodeAt(aIndex++));
  19341. if (digit === -1) {
  19342. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  19343. }
  19344. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  19345. digit &= VLQ_BASE_MASK;
  19346. result = result + (digit << shift);
  19347. shift += VLQ_BASE_SHIFT;
  19348. } while (continuation);
  19349. aOutParam.value = fromVLQSigned(result);
  19350. aOutParam.rest = aIndex;
  19351. };
  19352. return base64Vlq$1;
  19353. }
  19354. var util$2 = {};
  19355. /* -*- Mode: js; js-indent-level: 2; -*- */
  19356. var hasRequiredUtil$2;
  19357. function requireUtil$2 () {
  19358. if (hasRequiredUtil$2) return util$2;
  19359. hasRequiredUtil$2 = 1;
  19360. (function (exports) {
  19361. /*
  19362. * Copyright 2011 Mozilla Foundation and contributors
  19363. * Licensed under the New BSD license. See LICENSE or:
  19364. * http://opensource.org/licenses/BSD-3-Clause
  19365. */
  19366. /**
  19367. * This is a helper function for getting values from parameter/options
  19368. * objects.
  19369. *
  19370. * @param args The object we are extracting values from
  19371. * @param name The name of the property we are getting.
  19372. * @param defaultValue An optional value to return if the property is missing
  19373. * from the object. If this is not specified and the property is missing, an
  19374. * error will be thrown.
  19375. */
  19376. function getArg(aArgs, aName, aDefaultValue) {
  19377. if (aName in aArgs) {
  19378. return aArgs[aName];
  19379. } else if (arguments.length === 3) {
  19380. return aDefaultValue;
  19381. } else {
  19382. throw new Error('"' + aName + '" is a required argument.');
  19383. }
  19384. }
  19385. exports.getArg = getArg;
  19386. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  19387. var dataUrlRegexp = /^data:.+\,.+$/;
  19388. function urlParse(aUrl) {
  19389. var match = aUrl.match(urlRegexp);
  19390. if (!match) {
  19391. return null;
  19392. }
  19393. return {
  19394. scheme: match[1],
  19395. auth: match[2],
  19396. host: match[3],
  19397. port: match[4],
  19398. path: match[5]
  19399. };
  19400. }
  19401. exports.urlParse = urlParse;
  19402. function urlGenerate(aParsedUrl) {
  19403. var url = '';
  19404. if (aParsedUrl.scheme) {
  19405. url += aParsedUrl.scheme + ':';
  19406. }
  19407. url += '//';
  19408. if (aParsedUrl.auth) {
  19409. url += aParsedUrl.auth + '@';
  19410. }
  19411. if (aParsedUrl.host) {
  19412. url += aParsedUrl.host;
  19413. }
  19414. if (aParsedUrl.port) {
  19415. url += ":" + aParsedUrl.port;
  19416. }
  19417. if (aParsedUrl.path) {
  19418. url += aParsedUrl.path;
  19419. }
  19420. return url;
  19421. }
  19422. exports.urlGenerate = urlGenerate;
  19423. var MAX_CACHED_INPUTS = 32;
  19424. /**
  19425. * Takes some function `f(input) -> result` and returns a memoized version of
  19426. * `f`.
  19427. *
  19428. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  19429. * memoization is a dumb-simple, linear least-recently-used cache.
  19430. */
  19431. function lruMemoize(f) {
  19432. var cache = [];
  19433. return function(input) {
  19434. for (var i = 0; i < cache.length; i++) {
  19435. if (cache[i].input === input) {
  19436. var temp = cache[0];
  19437. cache[0] = cache[i];
  19438. cache[i] = temp;
  19439. return cache[0].result;
  19440. }
  19441. }
  19442. var result = f(input);
  19443. cache.unshift({
  19444. input,
  19445. result,
  19446. });
  19447. if (cache.length > MAX_CACHED_INPUTS) {
  19448. cache.pop();
  19449. }
  19450. return result;
  19451. };
  19452. }
  19453. /**
  19454. * Normalizes a path, or the path portion of a URL:
  19455. *
  19456. * - Replaces consecutive slashes with one slash.
  19457. * - Removes unnecessary '.' parts.
  19458. * - Removes unnecessary '<dir>/..' parts.
  19459. *
  19460. * Based on code in the Node.js 'path' core module.
  19461. *
  19462. * @param aPath The path or url to normalize.
  19463. */
  19464. var normalize = lruMemoize(function normalize(aPath) {
  19465. var path = aPath;
  19466. var url = urlParse(aPath);
  19467. if (url) {
  19468. if (!url.path) {
  19469. return aPath;
  19470. }
  19471. path = url.path;
  19472. }
  19473. var isAbsolute = exports.isAbsolute(path);
  19474. // Split the path into parts between `/` characters. This is much faster than
  19475. // using `.split(/\/+/g)`.
  19476. var parts = [];
  19477. var start = 0;
  19478. var i = 0;
  19479. while (true) {
  19480. start = i;
  19481. i = path.indexOf("/", start);
  19482. if (i === -1) {
  19483. parts.push(path.slice(start));
  19484. break;
  19485. } else {
  19486. parts.push(path.slice(start, i));
  19487. while (i < path.length && path[i] === "/") {
  19488. i++;
  19489. }
  19490. }
  19491. }
  19492. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  19493. part = parts[i];
  19494. if (part === '.') {
  19495. parts.splice(i, 1);
  19496. } else if (part === '..') {
  19497. up++;
  19498. } else if (up > 0) {
  19499. if (part === '') {
  19500. // The first part is blank if the path is absolute. Trying to go
  19501. // above the root is a no-op. Therefore we can remove all '..' parts
  19502. // directly after the root.
  19503. parts.splice(i + 1, up);
  19504. up = 0;
  19505. } else {
  19506. parts.splice(i, 2);
  19507. up--;
  19508. }
  19509. }
  19510. }
  19511. path = parts.join('/');
  19512. if (path === '') {
  19513. path = isAbsolute ? '/' : '.';
  19514. }
  19515. if (url) {
  19516. url.path = path;
  19517. return urlGenerate(url);
  19518. }
  19519. return path;
  19520. });
  19521. exports.normalize = normalize;
  19522. /**
  19523. * Joins two paths/URLs.
  19524. *
  19525. * @param aRoot The root path or URL.
  19526. * @param aPath The path or URL to be joined with the root.
  19527. *
  19528. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  19529. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  19530. * first.
  19531. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  19532. * is updated with the result and aRoot is returned. Otherwise the result
  19533. * is returned.
  19534. * - If aPath is absolute, the result is aPath.
  19535. * - Otherwise the two paths are joined with a slash.
  19536. * - Joining for example 'http://' and 'www.example.com' is also supported.
  19537. */
  19538. function join(aRoot, aPath) {
  19539. if (aRoot === "") {
  19540. aRoot = ".";
  19541. }
  19542. if (aPath === "") {
  19543. aPath = ".";
  19544. }
  19545. var aPathUrl = urlParse(aPath);
  19546. var aRootUrl = urlParse(aRoot);
  19547. if (aRootUrl) {
  19548. aRoot = aRootUrl.path || '/';
  19549. }
  19550. // `join(foo, '//www.example.org')`
  19551. if (aPathUrl && !aPathUrl.scheme) {
  19552. if (aRootUrl) {
  19553. aPathUrl.scheme = aRootUrl.scheme;
  19554. }
  19555. return urlGenerate(aPathUrl);
  19556. }
  19557. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  19558. return aPath;
  19559. }
  19560. // `join('http://', 'www.example.com')`
  19561. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  19562. aRootUrl.host = aPath;
  19563. return urlGenerate(aRootUrl);
  19564. }
  19565. var joined = aPath.charAt(0) === '/'
  19566. ? aPath
  19567. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  19568. if (aRootUrl) {
  19569. aRootUrl.path = joined;
  19570. return urlGenerate(aRootUrl);
  19571. }
  19572. return joined;
  19573. }
  19574. exports.join = join;
  19575. exports.isAbsolute = function (aPath) {
  19576. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  19577. };
  19578. /**
  19579. * Make a path relative to a URL or another path.
  19580. *
  19581. * @param aRoot The root path or URL.
  19582. * @param aPath The path or URL to be made relative to aRoot.
  19583. */
  19584. function relative(aRoot, aPath) {
  19585. if (aRoot === "") {
  19586. aRoot = ".";
  19587. }
  19588. aRoot = aRoot.replace(/\/$/, '');
  19589. // It is possible for the path to be above the root. In this case, simply
  19590. // checking whether the root is a prefix of the path won't work. Instead, we
  19591. // need to remove components from the root one by one, until either we find
  19592. // a prefix that fits, or we run out of components to remove.
  19593. var level = 0;
  19594. while (aPath.indexOf(aRoot + '/') !== 0) {
  19595. var index = aRoot.lastIndexOf("/");
  19596. if (index < 0) {
  19597. return aPath;
  19598. }
  19599. // If the only part of the root that is left is the scheme (i.e. http://,
  19600. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  19601. // have exhausted all components, so the path is not relative to the root.
  19602. aRoot = aRoot.slice(0, index);
  19603. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  19604. return aPath;
  19605. }
  19606. ++level;
  19607. }
  19608. // Make sure we add a "../" for each component we removed from the root.
  19609. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  19610. }
  19611. exports.relative = relative;
  19612. var supportsNullProto = (function () {
  19613. var obj = Object.create(null);
  19614. return !('__proto__' in obj);
  19615. }());
  19616. function identity (s) {
  19617. return s;
  19618. }
  19619. /**
  19620. * Because behavior goes wacky when you set `__proto__` on objects, we
  19621. * have to prefix all the strings in our set with an arbitrary character.
  19622. *
  19623. * See https://github.com/mozilla/source-map/pull/31 and
  19624. * https://github.com/mozilla/source-map/issues/30
  19625. *
  19626. * @param String aStr
  19627. */
  19628. function toSetString(aStr) {
  19629. if (isProtoString(aStr)) {
  19630. return '$' + aStr;
  19631. }
  19632. return aStr;
  19633. }
  19634. exports.toSetString = supportsNullProto ? identity : toSetString;
  19635. function fromSetString(aStr) {
  19636. if (isProtoString(aStr)) {
  19637. return aStr.slice(1);
  19638. }
  19639. return aStr;
  19640. }
  19641. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  19642. function isProtoString(s) {
  19643. if (!s) {
  19644. return false;
  19645. }
  19646. var length = s.length;
  19647. if (length < 9 /* "__proto__".length */) {
  19648. return false;
  19649. }
  19650. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  19651. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  19652. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  19653. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  19654. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  19655. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  19656. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  19657. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  19658. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  19659. return false;
  19660. }
  19661. for (var i = length - 10; i >= 0; i--) {
  19662. if (s.charCodeAt(i) !== 36 /* '$' */) {
  19663. return false;
  19664. }
  19665. }
  19666. return true;
  19667. }
  19668. /**
  19669. * Comparator between two mappings where the original positions are compared.
  19670. *
  19671. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  19672. * mappings with the same original source/line/column, but different generated
  19673. * line and column the same. Useful when searching for a mapping with a
  19674. * stubbed out mapping.
  19675. */
  19676. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  19677. var cmp = strcmp(mappingA.source, mappingB.source);
  19678. if (cmp !== 0) {
  19679. return cmp;
  19680. }
  19681. cmp = mappingA.originalLine - mappingB.originalLine;
  19682. if (cmp !== 0) {
  19683. return cmp;
  19684. }
  19685. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19686. if (cmp !== 0 || onlyCompareOriginal) {
  19687. return cmp;
  19688. }
  19689. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19690. if (cmp !== 0) {
  19691. return cmp;
  19692. }
  19693. cmp = mappingA.generatedLine - mappingB.generatedLine;
  19694. if (cmp !== 0) {
  19695. return cmp;
  19696. }
  19697. return strcmp(mappingA.name, mappingB.name);
  19698. }
  19699. exports.compareByOriginalPositions = compareByOriginalPositions;
  19700. function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
  19701. var cmp;
  19702. cmp = mappingA.originalLine - mappingB.originalLine;
  19703. if (cmp !== 0) {
  19704. return cmp;
  19705. }
  19706. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19707. if (cmp !== 0 || onlyCompareOriginal) {
  19708. return cmp;
  19709. }
  19710. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19711. if (cmp !== 0) {
  19712. return cmp;
  19713. }
  19714. cmp = mappingA.generatedLine - mappingB.generatedLine;
  19715. if (cmp !== 0) {
  19716. return cmp;
  19717. }
  19718. return strcmp(mappingA.name, mappingB.name);
  19719. }
  19720. exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
  19721. /**
  19722. * Comparator between two mappings with deflated source and name indices where
  19723. * the generated positions are compared.
  19724. *
  19725. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  19726. * mappings with the same generated line and column, but different
  19727. * source/name/original line and column the same. Useful when searching for a
  19728. * mapping with a stubbed out mapping.
  19729. */
  19730. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  19731. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  19732. if (cmp !== 0) {
  19733. return cmp;
  19734. }
  19735. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19736. if (cmp !== 0 || onlyCompareGenerated) {
  19737. return cmp;
  19738. }
  19739. cmp = strcmp(mappingA.source, mappingB.source);
  19740. if (cmp !== 0) {
  19741. return cmp;
  19742. }
  19743. cmp = mappingA.originalLine - mappingB.originalLine;
  19744. if (cmp !== 0) {
  19745. return cmp;
  19746. }
  19747. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19748. if (cmp !== 0) {
  19749. return cmp;
  19750. }
  19751. return strcmp(mappingA.name, mappingB.name);
  19752. }
  19753. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  19754. function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
  19755. var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19756. if (cmp !== 0 || onlyCompareGenerated) {
  19757. return cmp;
  19758. }
  19759. cmp = strcmp(mappingA.source, mappingB.source);
  19760. if (cmp !== 0) {
  19761. return cmp;
  19762. }
  19763. cmp = mappingA.originalLine - mappingB.originalLine;
  19764. if (cmp !== 0) {
  19765. return cmp;
  19766. }
  19767. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19768. if (cmp !== 0) {
  19769. return cmp;
  19770. }
  19771. return strcmp(mappingA.name, mappingB.name);
  19772. }
  19773. exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
  19774. function strcmp(aStr1, aStr2) {
  19775. if (aStr1 === aStr2) {
  19776. return 0;
  19777. }
  19778. if (aStr1 === null) {
  19779. return 1; // aStr2 !== null
  19780. }
  19781. if (aStr2 === null) {
  19782. return -1; // aStr1 !== null
  19783. }
  19784. if (aStr1 > aStr2) {
  19785. return 1;
  19786. }
  19787. return -1;
  19788. }
  19789. /**
  19790. * Comparator between two mappings with inflated source and name strings where
  19791. * the generated positions are compared.
  19792. */
  19793. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  19794. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  19795. if (cmp !== 0) {
  19796. return cmp;
  19797. }
  19798. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  19799. if (cmp !== 0) {
  19800. return cmp;
  19801. }
  19802. cmp = strcmp(mappingA.source, mappingB.source);
  19803. if (cmp !== 0) {
  19804. return cmp;
  19805. }
  19806. cmp = mappingA.originalLine - mappingB.originalLine;
  19807. if (cmp !== 0) {
  19808. return cmp;
  19809. }
  19810. cmp = mappingA.originalColumn - mappingB.originalColumn;
  19811. if (cmp !== 0) {
  19812. return cmp;
  19813. }
  19814. return strcmp(mappingA.name, mappingB.name);
  19815. }
  19816. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  19817. /**
  19818. * Strip any JSON XSSI avoidance prefix from the string (as documented
  19819. * in the source maps specification), and then parse the string as
  19820. * JSON.
  19821. */
  19822. function parseSourceMapInput(str) {
  19823. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  19824. }
  19825. exports.parseSourceMapInput = parseSourceMapInput;
  19826. /**
  19827. * Compute the URL of a source given the the source root, the source's
  19828. * URL, and the source map's URL.
  19829. */
  19830. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  19831. sourceURL = sourceURL || '';
  19832. if (sourceRoot) {
  19833. // This follows what Chrome does.
  19834. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  19835. sourceRoot += '/';
  19836. }
  19837. // The spec says:
  19838. // Line 4: An optional source root, useful for relocating source
  19839. // files on a server or removing repeated values in the
  19840. // “sources” entry. This value is prepended to the individual
  19841. // entries in the “source” field.
  19842. sourceURL = sourceRoot + sourceURL;
  19843. }
  19844. // Historically, SourceMapConsumer did not take the sourceMapURL as
  19845. // a parameter. This mode is still somewhat supported, which is why
  19846. // this code block is conditional. However, it's preferable to pass
  19847. // the source map URL to SourceMapConsumer, so that this function
  19848. // can implement the source URL resolution algorithm as outlined in
  19849. // the spec. This block is basically the equivalent of:
  19850. // new URL(sourceURL, sourceMapURL).toString()
  19851. // ... except it avoids using URL, which wasn't available in the
  19852. // older releases of node still supported by this library.
  19853. //
  19854. // The spec says:
  19855. // If the sources are not absolute URLs after prepending of the
  19856. // “sourceRoot”, the sources are resolved relative to the
  19857. // SourceMap (like resolving script src in a html document).
  19858. if (sourceMapURL) {
  19859. var parsed = urlParse(sourceMapURL);
  19860. if (!parsed) {
  19861. throw new Error("sourceMapURL could not be parsed");
  19862. }
  19863. if (parsed.path) {
  19864. // Strip the last path component, but keep the "/".
  19865. var index = parsed.path.lastIndexOf('/');
  19866. if (index >= 0) {
  19867. parsed.path = parsed.path.substring(0, index + 1);
  19868. }
  19869. }
  19870. sourceURL = join(urlGenerate(parsed), sourceURL);
  19871. }
  19872. return normalize(sourceURL);
  19873. }
  19874. exports.computeSourceURL = computeSourceURL;
  19875. } (util$2));
  19876. return util$2;
  19877. }
  19878. var arraySet$1 = {};
  19879. /* -*- Mode: js; js-indent-level: 2; -*- */
  19880. var hasRequiredArraySet$1;
  19881. function requireArraySet$1 () {
  19882. if (hasRequiredArraySet$1) return arraySet$1;
  19883. hasRequiredArraySet$1 = 1;
  19884. /*
  19885. * Copyright 2011 Mozilla Foundation and contributors
  19886. * Licensed under the New BSD license. See LICENSE or:
  19887. * http://opensource.org/licenses/BSD-3-Clause
  19888. */
  19889. var util = /*@__PURE__*/ requireUtil$2();
  19890. var has = Object.prototype.hasOwnProperty;
  19891. var hasNativeMap = typeof Map !== "undefined";
  19892. /**
  19893. * A data structure which is a combination of an array and a set. Adding a new
  19894. * member is O(1), testing for membership is O(1), and finding the index of an
  19895. * element is O(1). Removing elements from the set is not supported. Only
  19896. * strings are supported for membership.
  19897. */
  19898. function ArraySet() {
  19899. this._array = [];
  19900. this._set = hasNativeMap ? new Map() : Object.create(null);
  19901. }
  19902. /**
  19903. * Static method for creating ArraySet instances from an existing array.
  19904. */
  19905. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  19906. var set = new ArraySet();
  19907. for (var i = 0, len = aArray.length; i < len; i++) {
  19908. set.add(aArray[i], aAllowDuplicates);
  19909. }
  19910. return set;
  19911. };
  19912. /**
  19913. * Return how many unique items are in this ArraySet. If duplicates have been
  19914. * added, than those do not count towards the size.
  19915. *
  19916. * @returns Number
  19917. */
  19918. ArraySet.prototype.size = function ArraySet_size() {
  19919. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  19920. };
  19921. /**
  19922. * Add the given string to this set.
  19923. *
  19924. * @param String aStr
  19925. */
  19926. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  19927. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  19928. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  19929. var idx = this._array.length;
  19930. if (!isDuplicate || aAllowDuplicates) {
  19931. this._array.push(aStr);
  19932. }
  19933. if (!isDuplicate) {
  19934. if (hasNativeMap) {
  19935. this._set.set(aStr, idx);
  19936. } else {
  19937. this._set[sStr] = idx;
  19938. }
  19939. }
  19940. };
  19941. /**
  19942. * Is the given string a member of this set?
  19943. *
  19944. * @param String aStr
  19945. */
  19946. ArraySet.prototype.has = function ArraySet_has(aStr) {
  19947. if (hasNativeMap) {
  19948. return this._set.has(aStr);
  19949. } else {
  19950. var sStr = util.toSetString(aStr);
  19951. return has.call(this._set, sStr);
  19952. }
  19953. };
  19954. /**
  19955. * What is the index of the given string in the array?
  19956. *
  19957. * @param String aStr
  19958. */
  19959. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  19960. if (hasNativeMap) {
  19961. var idx = this._set.get(aStr);
  19962. if (idx >= 0) {
  19963. return idx;
  19964. }
  19965. } else {
  19966. var sStr = util.toSetString(aStr);
  19967. if (has.call(this._set, sStr)) {
  19968. return this._set[sStr];
  19969. }
  19970. }
  19971. throw new Error('"' + aStr + '" is not in the set.');
  19972. };
  19973. /**
  19974. * What is the element at the given index?
  19975. *
  19976. * @param Number aIdx
  19977. */
  19978. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  19979. if (aIdx >= 0 && aIdx < this._array.length) {
  19980. return this._array[aIdx];
  19981. }
  19982. throw new Error('No element indexed by ' + aIdx);
  19983. };
  19984. /**
  19985. * Returns the array representation of this set (which has the proper indices
  19986. * indicated by indexOf). Note that this is a copy of the internal array used
  19987. * for storing the members so that no one can mess with internal state.
  19988. */
  19989. ArraySet.prototype.toArray = function ArraySet_toArray() {
  19990. return this._array.slice();
  19991. };
  19992. arraySet$1.ArraySet = ArraySet;
  19993. return arraySet$1;
  19994. }
  19995. var mappingList$1 = {};
  19996. /* -*- Mode: js; js-indent-level: 2; -*- */
  19997. var hasRequiredMappingList$1;
  19998. function requireMappingList$1 () {
  19999. if (hasRequiredMappingList$1) return mappingList$1;
  20000. hasRequiredMappingList$1 = 1;
  20001. /*
  20002. * Copyright 2014 Mozilla Foundation and contributors
  20003. * Licensed under the New BSD license. See LICENSE or:
  20004. * http://opensource.org/licenses/BSD-3-Clause
  20005. */
  20006. var util = /*@__PURE__*/ requireUtil$2();
  20007. /**
  20008. * Determine whether mappingB is after mappingA with respect to generated
  20009. * position.
  20010. */
  20011. function generatedPositionAfter(mappingA, mappingB) {
  20012. // Optimized for most common case
  20013. var lineA = mappingA.generatedLine;
  20014. var lineB = mappingB.generatedLine;
  20015. var columnA = mappingA.generatedColumn;
  20016. var columnB = mappingB.generatedColumn;
  20017. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  20018. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  20019. }
  20020. /**
  20021. * A data structure to provide a sorted view of accumulated mappings in a
  20022. * performance conscious manner. It trades a neglibable overhead in general
  20023. * case for a large speedup in case of mappings being added in order.
  20024. */
  20025. function MappingList() {
  20026. this._array = [];
  20027. this._sorted = true;
  20028. // Serves as infimum
  20029. this._last = {generatedLine: -1, generatedColumn: 0};
  20030. }
  20031. /**
  20032. * Iterate through internal items. This method takes the same arguments that
  20033. * `Array.prototype.forEach` takes.
  20034. *
  20035. * NOTE: The order of the mappings is NOT guaranteed.
  20036. */
  20037. MappingList.prototype.unsortedForEach =
  20038. function MappingList_forEach(aCallback, aThisArg) {
  20039. this._array.forEach(aCallback, aThisArg);
  20040. };
  20041. /**
  20042. * Add the given source mapping.
  20043. *
  20044. * @param Object aMapping
  20045. */
  20046. MappingList.prototype.add = function MappingList_add(aMapping) {
  20047. if (generatedPositionAfter(this._last, aMapping)) {
  20048. this._last = aMapping;
  20049. this._array.push(aMapping);
  20050. } else {
  20051. this._sorted = false;
  20052. this._array.push(aMapping);
  20053. }
  20054. };
  20055. /**
  20056. * Returns the flat, sorted array of mappings. The mappings are sorted by
  20057. * generated position.
  20058. *
  20059. * WARNING: This method returns internal data without copying, for
  20060. * performance. The return value must NOT be mutated, and should be treated as
  20061. * an immutable borrow. If you want to take ownership, you must make your own
  20062. * copy.
  20063. */
  20064. MappingList.prototype.toArray = function MappingList_toArray() {
  20065. if (!this._sorted) {
  20066. this._array.sort(util.compareByGeneratedPositionsInflated);
  20067. this._sorted = true;
  20068. }
  20069. return this._array;
  20070. };
  20071. mappingList$1.MappingList = MappingList;
  20072. return mappingList$1;
  20073. }
  20074. /* -*- Mode: js; js-indent-level: 2; -*- */
  20075. var hasRequiredSourceMapGenerator$1;
  20076. function requireSourceMapGenerator$1 () {
  20077. if (hasRequiredSourceMapGenerator$1) return sourceMapGenerator$1;
  20078. hasRequiredSourceMapGenerator$1 = 1;
  20079. /*
  20080. * Copyright 2011 Mozilla Foundation and contributors
  20081. * Licensed under the New BSD license. See LICENSE or:
  20082. * http://opensource.org/licenses/BSD-3-Clause
  20083. */
  20084. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  20085. var util = /*@__PURE__*/ requireUtil$2();
  20086. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  20087. var MappingList = /*@__PURE__*/ requireMappingList$1().MappingList;
  20088. /**
  20089. * An instance of the SourceMapGenerator represents a source map which is
  20090. * being built incrementally. You may pass an object with the following
  20091. * properties:
  20092. *
  20093. * - file: The filename of the generated source.
  20094. * - sourceRoot: A root for all relative URLs in this source map.
  20095. */
  20096. function SourceMapGenerator(aArgs) {
  20097. if (!aArgs) {
  20098. aArgs = {};
  20099. }
  20100. this._file = util.getArg(aArgs, 'file', null);
  20101. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  20102. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  20103. this._ignoreInvalidMapping = util.getArg(aArgs, 'ignoreInvalidMapping', false);
  20104. this._sources = new ArraySet();
  20105. this._names = new ArraySet();
  20106. this._mappings = new MappingList();
  20107. this._sourcesContents = null;
  20108. }
  20109. SourceMapGenerator.prototype._version = 3;
  20110. /**
  20111. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  20112. *
  20113. * @param aSourceMapConsumer The SourceMap.
  20114. */
  20115. SourceMapGenerator.fromSourceMap =
  20116. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
  20117. var sourceRoot = aSourceMapConsumer.sourceRoot;
  20118. var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
  20119. file: aSourceMapConsumer.file,
  20120. sourceRoot: sourceRoot
  20121. }));
  20122. aSourceMapConsumer.eachMapping(function (mapping) {
  20123. var newMapping = {
  20124. generated: {
  20125. line: mapping.generatedLine,
  20126. column: mapping.generatedColumn
  20127. }
  20128. };
  20129. if (mapping.source != null) {
  20130. newMapping.source = mapping.source;
  20131. if (sourceRoot != null) {
  20132. newMapping.source = util.relative(sourceRoot, newMapping.source);
  20133. }
  20134. newMapping.original = {
  20135. line: mapping.originalLine,
  20136. column: mapping.originalColumn
  20137. };
  20138. if (mapping.name != null) {
  20139. newMapping.name = mapping.name;
  20140. }
  20141. }
  20142. generator.addMapping(newMapping);
  20143. });
  20144. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  20145. var sourceRelative = sourceFile;
  20146. if (sourceRoot !== null) {
  20147. sourceRelative = util.relative(sourceRoot, sourceFile);
  20148. }
  20149. if (!generator._sources.has(sourceRelative)) {
  20150. generator._sources.add(sourceRelative);
  20151. }
  20152. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  20153. if (content != null) {
  20154. generator.setSourceContent(sourceFile, content);
  20155. }
  20156. });
  20157. return generator;
  20158. };
  20159. /**
  20160. * Add a single mapping from original source line and column to the generated
  20161. * source's line and column for this source map being created. The mapping
  20162. * object should have the following properties:
  20163. *
  20164. * - generated: An object with the generated line and column positions.
  20165. * - original: An object with the original line and column positions.
  20166. * - source: The original source file (relative to the sourceRoot).
  20167. * - name: An optional original token name for this mapping.
  20168. */
  20169. SourceMapGenerator.prototype.addMapping =
  20170. function SourceMapGenerator_addMapping(aArgs) {
  20171. var generated = util.getArg(aArgs, 'generated');
  20172. var original = util.getArg(aArgs, 'original', null);
  20173. var source = util.getArg(aArgs, 'source', null);
  20174. var name = util.getArg(aArgs, 'name', null);
  20175. if (!this._skipValidation) {
  20176. if (this._validateMapping(generated, original, source, name) === false) {
  20177. return;
  20178. }
  20179. }
  20180. if (source != null) {
  20181. source = String(source);
  20182. if (!this._sources.has(source)) {
  20183. this._sources.add(source);
  20184. }
  20185. }
  20186. if (name != null) {
  20187. name = String(name);
  20188. if (!this._names.has(name)) {
  20189. this._names.add(name);
  20190. }
  20191. }
  20192. this._mappings.add({
  20193. generatedLine: generated.line,
  20194. generatedColumn: generated.column,
  20195. originalLine: original != null && original.line,
  20196. originalColumn: original != null && original.column,
  20197. source: source,
  20198. name: name
  20199. });
  20200. };
  20201. /**
  20202. * Set the source content for a source file.
  20203. */
  20204. SourceMapGenerator.prototype.setSourceContent =
  20205. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  20206. var source = aSourceFile;
  20207. if (this._sourceRoot != null) {
  20208. source = util.relative(this._sourceRoot, source);
  20209. }
  20210. if (aSourceContent != null) {
  20211. // Add the source content to the _sourcesContents map.
  20212. // Create a new _sourcesContents map if the property is null.
  20213. if (!this._sourcesContents) {
  20214. this._sourcesContents = Object.create(null);
  20215. }
  20216. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  20217. } else if (this._sourcesContents) {
  20218. // Remove the source file from the _sourcesContents map.
  20219. // If the _sourcesContents map is empty, set the property to null.
  20220. delete this._sourcesContents[util.toSetString(source)];
  20221. if (Object.keys(this._sourcesContents).length === 0) {
  20222. this._sourcesContents = null;
  20223. }
  20224. }
  20225. };
  20226. /**
  20227. * Applies the mappings of a sub-source-map for a specific source file to the
  20228. * source map being generated. Each mapping to the supplied source file is
  20229. * rewritten using the supplied source map. Note: The resolution for the
  20230. * resulting mappings is the minimium of this map and the supplied map.
  20231. *
  20232. * @param aSourceMapConsumer The source map to be applied.
  20233. * @param aSourceFile Optional. The filename of the source file.
  20234. * If omitted, SourceMapConsumer's file property will be used.
  20235. * @param aSourceMapPath Optional. The dirname of the path to the source map
  20236. * to be applied. If relative, it is relative to the SourceMapConsumer.
  20237. * This parameter is needed when the two source maps aren't in the same
  20238. * directory, and the source map to be applied contains relative source
  20239. * paths. If so, those relative source paths need to be rewritten
  20240. * relative to the SourceMapGenerator.
  20241. */
  20242. SourceMapGenerator.prototype.applySourceMap =
  20243. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  20244. var sourceFile = aSourceFile;
  20245. // If aSourceFile is omitted, we will use the file property of the SourceMap
  20246. if (aSourceFile == null) {
  20247. if (aSourceMapConsumer.file == null) {
  20248. throw new Error(
  20249. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  20250. 'or the source map\'s "file" property. Both were omitted.'
  20251. );
  20252. }
  20253. sourceFile = aSourceMapConsumer.file;
  20254. }
  20255. var sourceRoot = this._sourceRoot;
  20256. // Make "sourceFile" relative if an absolute Url is passed.
  20257. if (sourceRoot != null) {
  20258. sourceFile = util.relative(sourceRoot, sourceFile);
  20259. }
  20260. // Applying the SourceMap can add and remove items from the sources and
  20261. // the names array.
  20262. var newSources = new ArraySet();
  20263. var newNames = new ArraySet();
  20264. // Find mappings for the "sourceFile"
  20265. this._mappings.unsortedForEach(function (mapping) {
  20266. if (mapping.source === sourceFile && mapping.originalLine != null) {
  20267. // Check if it can be mapped by the source map, then update the mapping.
  20268. var original = aSourceMapConsumer.originalPositionFor({
  20269. line: mapping.originalLine,
  20270. column: mapping.originalColumn
  20271. });
  20272. if (original.source != null) {
  20273. // Copy mapping
  20274. mapping.source = original.source;
  20275. if (aSourceMapPath != null) {
  20276. mapping.source = util.join(aSourceMapPath, mapping.source);
  20277. }
  20278. if (sourceRoot != null) {
  20279. mapping.source = util.relative(sourceRoot, mapping.source);
  20280. }
  20281. mapping.originalLine = original.line;
  20282. mapping.originalColumn = original.column;
  20283. if (original.name != null) {
  20284. mapping.name = original.name;
  20285. }
  20286. }
  20287. }
  20288. var source = mapping.source;
  20289. if (source != null && !newSources.has(source)) {
  20290. newSources.add(source);
  20291. }
  20292. var name = mapping.name;
  20293. if (name != null && !newNames.has(name)) {
  20294. newNames.add(name);
  20295. }
  20296. }, this);
  20297. this._sources = newSources;
  20298. this._names = newNames;
  20299. // Copy sourcesContents of applied map.
  20300. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  20301. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  20302. if (content != null) {
  20303. if (aSourceMapPath != null) {
  20304. sourceFile = util.join(aSourceMapPath, sourceFile);
  20305. }
  20306. if (sourceRoot != null) {
  20307. sourceFile = util.relative(sourceRoot, sourceFile);
  20308. }
  20309. this.setSourceContent(sourceFile, content);
  20310. }
  20311. }, this);
  20312. };
  20313. /**
  20314. * A mapping can have one of the three levels of data:
  20315. *
  20316. * 1. Just the generated position.
  20317. * 2. The Generated position, original position, and original source.
  20318. * 3. Generated and original position, original source, as well as a name
  20319. * token.
  20320. *
  20321. * To maintain consistency, we validate that any new mapping being added falls
  20322. * in to one of these categories.
  20323. */
  20324. SourceMapGenerator.prototype._validateMapping =
  20325. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  20326. aName) {
  20327. // When aOriginal is truthy but has empty values for .line and .column,
  20328. // it is most likely a programmer error. In this case we throw a very
  20329. // specific error message to try to guide them the right way.
  20330. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  20331. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  20332. var message = 'original.line and original.column are not numbers -- you probably meant to omit ' +
  20333. 'the original mapping entirely and only map the generated position. If so, pass ' +
  20334. 'null for the original mapping instead of an object with empty or null values.';
  20335. if (this._ignoreInvalidMapping) {
  20336. if (typeof console !== 'undefined' && console.warn) {
  20337. console.warn(message);
  20338. }
  20339. return false;
  20340. } else {
  20341. throw new Error(message);
  20342. }
  20343. }
  20344. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  20345. && aGenerated.line > 0 && aGenerated.column >= 0
  20346. && !aOriginal && !aSource && !aName) {
  20347. // Case 1.
  20348. return;
  20349. }
  20350. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  20351. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  20352. && aGenerated.line > 0 && aGenerated.column >= 0
  20353. && aOriginal.line > 0 && aOriginal.column >= 0
  20354. && aSource) {
  20355. // Cases 2 and 3.
  20356. return;
  20357. }
  20358. else {
  20359. var message = 'Invalid mapping: ' + JSON.stringify({
  20360. generated: aGenerated,
  20361. source: aSource,
  20362. original: aOriginal,
  20363. name: aName
  20364. });
  20365. if (this._ignoreInvalidMapping) {
  20366. if (typeof console !== 'undefined' && console.warn) {
  20367. console.warn(message);
  20368. }
  20369. return false;
  20370. } else {
  20371. throw new Error(message)
  20372. }
  20373. }
  20374. };
  20375. /**
  20376. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  20377. * specified by the source map format.
  20378. */
  20379. SourceMapGenerator.prototype._serializeMappings =
  20380. function SourceMapGenerator_serializeMappings() {
  20381. var previousGeneratedColumn = 0;
  20382. var previousGeneratedLine = 1;
  20383. var previousOriginalColumn = 0;
  20384. var previousOriginalLine = 0;
  20385. var previousName = 0;
  20386. var previousSource = 0;
  20387. var result = '';
  20388. var next;
  20389. var mapping;
  20390. var nameIdx;
  20391. var sourceIdx;
  20392. var mappings = this._mappings.toArray();
  20393. for (var i = 0, len = mappings.length; i < len; i++) {
  20394. mapping = mappings[i];
  20395. next = '';
  20396. if (mapping.generatedLine !== previousGeneratedLine) {
  20397. previousGeneratedColumn = 0;
  20398. while (mapping.generatedLine !== previousGeneratedLine) {
  20399. next += ';';
  20400. previousGeneratedLine++;
  20401. }
  20402. }
  20403. else {
  20404. if (i > 0) {
  20405. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  20406. continue;
  20407. }
  20408. next += ',';
  20409. }
  20410. }
  20411. next += base64VLQ.encode(mapping.generatedColumn
  20412. - previousGeneratedColumn);
  20413. previousGeneratedColumn = mapping.generatedColumn;
  20414. if (mapping.source != null) {
  20415. sourceIdx = this._sources.indexOf(mapping.source);
  20416. next += base64VLQ.encode(sourceIdx - previousSource);
  20417. previousSource = sourceIdx;
  20418. // lines are stored 0-based in SourceMap spec version 3
  20419. next += base64VLQ.encode(mapping.originalLine - 1
  20420. - previousOriginalLine);
  20421. previousOriginalLine = mapping.originalLine - 1;
  20422. next += base64VLQ.encode(mapping.originalColumn
  20423. - previousOriginalColumn);
  20424. previousOriginalColumn = mapping.originalColumn;
  20425. if (mapping.name != null) {
  20426. nameIdx = this._names.indexOf(mapping.name);
  20427. next += base64VLQ.encode(nameIdx - previousName);
  20428. previousName = nameIdx;
  20429. }
  20430. }
  20431. result += next;
  20432. }
  20433. return result;
  20434. };
  20435. SourceMapGenerator.prototype._generateSourcesContent =
  20436. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  20437. return aSources.map(function (source) {
  20438. if (!this._sourcesContents) {
  20439. return null;
  20440. }
  20441. if (aSourceRoot != null) {
  20442. source = util.relative(aSourceRoot, source);
  20443. }
  20444. var key = util.toSetString(source);
  20445. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  20446. ? this._sourcesContents[key]
  20447. : null;
  20448. }, this);
  20449. };
  20450. /**
  20451. * Externalize the source map.
  20452. */
  20453. SourceMapGenerator.prototype.toJSON =
  20454. function SourceMapGenerator_toJSON() {
  20455. var map = {
  20456. version: this._version,
  20457. sources: this._sources.toArray(),
  20458. names: this._names.toArray(),
  20459. mappings: this._serializeMappings()
  20460. };
  20461. if (this._file != null) {
  20462. map.file = this._file;
  20463. }
  20464. if (this._sourceRoot != null) {
  20465. map.sourceRoot = this._sourceRoot;
  20466. }
  20467. if (this._sourcesContents) {
  20468. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  20469. }
  20470. return map;
  20471. };
  20472. /**
  20473. * Render the source map being generated to a string.
  20474. */
  20475. SourceMapGenerator.prototype.toString =
  20476. function SourceMapGenerator_toString() {
  20477. return JSON.stringify(this.toJSON());
  20478. };
  20479. sourceMapGenerator$1.SourceMapGenerator = SourceMapGenerator;
  20480. return sourceMapGenerator$1;
  20481. }
  20482. var sourceMapConsumer$1 = {};
  20483. var binarySearch$1 = {};
  20484. /* -*- Mode: js; js-indent-level: 2; -*- */
  20485. var hasRequiredBinarySearch$1;
  20486. function requireBinarySearch$1 () {
  20487. if (hasRequiredBinarySearch$1) return binarySearch$1;
  20488. hasRequiredBinarySearch$1 = 1;
  20489. (function (exports) {
  20490. /*
  20491. * Copyright 2011 Mozilla Foundation and contributors
  20492. * Licensed under the New BSD license. See LICENSE or:
  20493. * http://opensource.org/licenses/BSD-3-Clause
  20494. */
  20495. exports.GREATEST_LOWER_BOUND = 1;
  20496. exports.LEAST_UPPER_BOUND = 2;
  20497. /**
  20498. * Recursive implementation of binary search.
  20499. *
  20500. * @param aLow Indices here and lower do not contain the needle.
  20501. * @param aHigh Indices here and higher do not contain the needle.
  20502. * @param aNeedle The element being searched for.
  20503. * @param aHaystack The non-empty array being searched.
  20504. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  20505. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  20506. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  20507. * closest element that is smaller than or greater than the one we are
  20508. * searching for, respectively, if the exact element cannot be found.
  20509. */
  20510. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  20511. // This function terminates when one of the following is true:
  20512. //
  20513. // 1. We find the exact element we are looking for.
  20514. //
  20515. // 2. We did not find the exact element, but we can return the index of
  20516. // the next-closest element.
  20517. //
  20518. // 3. We did not find the exact element, and there is no next-closest
  20519. // element than the one we are searching for, so we return -1.
  20520. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  20521. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  20522. if (cmp === 0) {
  20523. // Found the element we are looking for.
  20524. return mid;
  20525. }
  20526. else if (cmp > 0) {
  20527. // Our needle is greater than aHaystack[mid].
  20528. if (aHigh - mid > 1) {
  20529. // The element is in the upper half.
  20530. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  20531. }
  20532. // The exact needle element was not found in this haystack. Determine if
  20533. // we are in termination case (3) or (2) and return the appropriate thing.
  20534. if (aBias == exports.LEAST_UPPER_BOUND) {
  20535. return aHigh < aHaystack.length ? aHigh : -1;
  20536. } else {
  20537. return mid;
  20538. }
  20539. }
  20540. else {
  20541. // Our needle is less than aHaystack[mid].
  20542. if (mid - aLow > 1) {
  20543. // The element is in the lower half.
  20544. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  20545. }
  20546. // we are in termination case (3) or (2) and return the appropriate thing.
  20547. if (aBias == exports.LEAST_UPPER_BOUND) {
  20548. return mid;
  20549. } else {
  20550. return aLow < 0 ? -1 : aLow;
  20551. }
  20552. }
  20553. }
  20554. /**
  20555. * This is an implementation of binary search which will always try and return
  20556. * the index of the closest element if there is no exact hit. This is because
  20557. * mappings between original and generated line/col pairs are single points,
  20558. * and there is an implicit region between each of them, so a miss just means
  20559. * that you aren't on the very start of a region.
  20560. *
  20561. * @param aNeedle The element you are looking for.
  20562. * @param aHaystack The array that is being searched.
  20563. * @param aCompare A function which takes the needle and an element in the
  20564. * array and returns -1, 0, or 1 depending on whether the needle is less
  20565. * than, equal to, or greater than the element, respectively.
  20566. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  20567. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  20568. * closest element that is smaller than or greater than the one we are
  20569. * searching for, respectively, if the exact element cannot be found.
  20570. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  20571. */
  20572. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  20573. if (aHaystack.length === 0) {
  20574. return -1;
  20575. }
  20576. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  20577. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  20578. if (index < 0) {
  20579. return -1;
  20580. }
  20581. // We have found either the exact element, or the next-closest element than
  20582. // the one we are searching for. However, there may be more than one such
  20583. // element. Make sure we always return the smallest of these.
  20584. while (index - 1 >= 0) {
  20585. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  20586. break;
  20587. }
  20588. --index;
  20589. }
  20590. return index;
  20591. };
  20592. } (binarySearch$1));
  20593. return binarySearch$1;
  20594. }
  20595. var quickSort$1 = {};
  20596. /* -*- Mode: js; js-indent-level: 2; -*- */
  20597. var hasRequiredQuickSort$1;
  20598. function requireQuickSort$1 () {
  20599. if (hasRequiredQuickSort$1) return quickSort$1;
  20600. hasRequiredQuickSort$1 = 1;
  20601. /*
  20602. * Copyright 2011 Mozilla Foundation and contributors
  20603. * Licensed under the New BSD license. See LICENSE or:
  20604. * http://opensource.org/licenses/BSD-3-Clause
  20605. */
  20606. // It turns out that some (most?) JavaScript engines don't self-host
  20607. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  20608. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  20609. // custom comparator function, calling back and forth between the VM's C++ and
  20610. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  20611. // worse generated code for the comparator function than would be optimal. In
  20612. // fact, when sorting with a comparator, these costs outweigh the benefits of
  20613. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  20614. // a ~3500ms mean speed-up in `bench/bench.html`.
  20615. function SortTemplate(comparator) {
  20616. /**
  20617. * Swap the elements indexed by `x` and `y` in the array `ary`.
  20618. *
  20619. * @param {Array} ary
  20620. * The array.
  20621. * @param {Number} x
  20622. * The index of the first item.
  20623. * @param {Number} y
  20624. * The index of the second item.
  20625. */
  20626. function swap(ary, x, y) {
  20627. var temp = ary[x];
  20628. ary[x] = ary[y];
  20629. ary[y] = temp;
  20630. }
  20631. /**
  20632. * Returns a random integer within the range `low .. high` inclusive.
  20633. *
  20634. * @param {Number} low
  20635. * The lower bound on the range.
  20636. * @param {Number} high
  20637. * The upper bound on the range.
  20638. */
  20639. function randomIntInRange(low, high) {
  20640. return Math.round(low + (Math.random() * (high - low)));
  20641. }
  20642. /**
  20643. * The Quick Sort algorithm.
  20644. *
  20645. * @param {Array} ary
  20646. * An array to sort.
  20647. * @param {function} comparator
  20648. * Function to use to compare two items.
  20649. * @param {Number} p
  20650. * Start index of the array
  20651. * @param {Number} r
  20652. * End index of the array
  20653. */
  20654. function doQuickSort(ary, comparator, p, r) {
  20655. // If our lower bound is less than our upper bound, we (1) partition the
  20656. // array into two pieces and (2) recurse on each half. If it is not, this is
  20657. // the empty array and our base case.
  20658. if (p < r) {
  20659. // (1) Partitioning.
  20660. //
  20661. // The partitioning chooses a pivot between `p` and `r` and moves all
  20662. // elements that are less than or equal to the pivot to the before it, and
  20663. // all the elements that are greater than it after it. The effect is that
  20664. // once partition is done, the pivot is in the exact place it will be when
  20665. // the array is put in sorted order, and it will not need to be moved
  20666. // again. This runs in O(n) time.
  20667. // Always choose a random pivot so that an input array which is reverse
  20668. // sorted does not cause O(n^2) running time.
  20669. var pivotIndex = randomIntInRange(p, r);
  20670. var i = p - 1;
  20671. swap(ary, pivotIndex, r);
  20672. var pivot = ary[r];
  20673. // Immediately after `j` is incremented in this loop, the following hold
  20674. // true:
  20675. //
  20676. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  20677. //
  20678. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  20679. for (var j = p; j < r; j++) {
  20680. if (comparator(ary[j], pivot, false) <= 0) {
  20681. i += 1;
  20682. swap(ary, i, j);
  20683. }
  20684. }
  20685. swap(ary, i + 1, j);
  20686. var q = i + 1;
  20687. // (2) Recurse on each half.
  20688. doQuickSort(ary, comparator, p, q - 1);
  20689. doQuickSort(ary, comparator, q + 1, r);
  20690. }
  20691. }
  20692. return doQuickSort;
  20693. }
  20694. function cloneSort(comparator) {
  20695. let template = SortTemplate.toString();
  20696. let templateFn = new Function(`return ${template}`)();
  20697. return templateFn(comparator);
  20698. }
  20699. /**
  20700. * Sort the given array in-place with the given comparator function.
  20701. *
  20702. * @param {Array} ary
  20703. * An array to sort.
  20704. * @param {function} comparator
  20705. * Function to use to compare two items.
  20706. */
  20707. let sortCache = new WeakMap();
  20708. quickSort$1.quickSort = function (ary, comparator, start = 0) {
  20709. let doQuickSort = sortCache.get(comparator);
  20710. if (doQuickSort === void 0) {
  20711. doQuickSort = cloneSort(comparator);
  20712. sortCache.set(comparator, doQuickSort);
  20713. }
  20714. doQuickSort(ary, comparator, start, ary.length - 1);
  20715. };
  20716. return quickSort$1;
  20717. }
  20718. /* -*- Mode: js; js-indent-level: 2; -*- */
  20719. var hasRequiredSourceMapConsumer$1;
  20720. function requireSourceMapConsumer$1 () {
  20721. if (hasRequiredSourceMapConsumer$1) return sourceMapConsumer$1;
  20722. hasRequiredSourceMapConsumer$1 = 1;
  20723. /*
  20724. * Copyright 2011 Mozilla Foundation and contributors
  20725. * Licensed under the New BSD license. See LICENSE or:
  20726. * http://opensource.org/licenses/BSD-3-Clause
  20727. */
  20728. var util = /*@__PURE__*/ requireUtil$2();
  20729. var binarySearch = /*@__PURE__*/ requireBinarySearch$1();
  20730. var ArraySet = /*@__PURE__*/ requireArraySet$1().ArraySet;
  20731. var base64VLQ = /*@__PURE__*/ requireBase64Vlq$1();
  20732. var quickSort = /*@__PURE__*/ requireQuickSort$1().quickSort;
  20733. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  20734. var sourceMap = aSourceMap;
  20735. if (typeof aSourceMap === 'string') {
  20736. sourceMap = util.parseSourceMapInput(aSourceMap);
  20737. }
  20738. return sourceMap.sections != null
  20739. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  20740. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  20741. }
  20742. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  20743. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  20744. };
  20745. /**
  20746. * The version of the source mapping spec that we are consuming.
  20747. */
  20748. SourceMapConsumer.prototype._version = 3;
  20749. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  20750. // parsed mapping coordinates from the source map's "mappings" attribute. They
  20751. // are lazily instantiated, accessed via the `_generatedMappings` and
  20752. // `_originalMappings` getters respectively, and we only parse the mappings
  20753. // and create these arrays once queried for a source location. We jump through
  20754. // these hoops because there can be many thousands of mappings, and parsing
  20755. // them is expensive, so we only want to do it if we must.
  20756. //
  20757. // Each object in the arrays is of the form:
  20758. //
  20759. // {
  20760. // generatedLine: The line number in the generated code,
  20761. // generatedColumn: The column number in the generated code,
  20762. // source: The path to the original source file that generated this
  20763. // chunk of code,
  20764. // originalLine: The line number in the original source that
  20765. // corresponds to this chunk of generated code,
  20766. // originalColumn: The column number in the original source that
  20767. // corresponds to this chunk of generated code,
  20768. // name: The name of the original symbol which generated this chunk of
  20769. // code.
  20770. // }
  20771. //
  20772. // All properties except for `generatedLine` and `generatedColumn` can be
  20773. // `null`.
  20774. //
  20775. // `_generatedMappings` is ordered by the generated positions.
  20776. //
  20777. // `_originalMappings` is ordered by the original positions.
  20778. SourceMapConsumer.prototype.__generatedMappings = null;
  20779. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  20780. configurable: true,
  20781. enumerable: true,
  20782. get: function () {
  20783. if (!this.__generatedMappings) {
  20784. this._parseMappings(this._mappings, this.sourceRoot);
  20785. }
  20786. return this.__generatedMappings;
  20787. }
  20788. });
  20789. SourceMapConsumer.prototype.__originalMappings = null;
  20790. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  20791. configurable: true,
  20792. enumerable: true,
  20793. get: function () {
  20794. if (!this.__originalMappings) {
  20795. this._parseMappings(this._mappings, this.sourceRoot);
  20796. }
  20797. return this.__originalMappings;
  20798. }
  20799. });
  20800. SourceMapConsumer.prototype._charIsMappingSeparator =
  20801. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  20802. var c = aStr.charAt(index);
  20803. return c === ";" || c === ",";
  20804. };
  20805. /**
  20806. * Parse the mappings in a string in to a data structure which we can easily
  20807. * query (the ordered arrays in the `this.__generatedMappings` and
  20808. * `this.__originalMappings` properties).
  20809. */
  20810. SourceMapConsumer.prototype._parseMappings =
  20811. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  20812. throw new Error("Subclasses must implement _parseMappings");
  20813. };
  20814. SourceMapConsumer.GENERATED_ORDER = 1;
  20815. SourceMapConsumer.ORIGINAL_ORDER = 2;
  20816. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  20817. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  20818. /**
  20819. * Iterate over each mapping between an original source/line/column and a
  20820. * generated line/column in this source map.
  20821. *
  20822. * @param Function aCallback
  20823. * The function that is called with each mapping.
  20824. * @param Object aContext
  20825. * Optional. If specified, this object will be the value of `this` every
  20826. * time that `aCallback` is called.
  20827. * @param aOrder
  20828. * Either `SourceMapConsumer.GENERATED_ORDER` or
  20829. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  20830. * iterate over the mappings sorted by the generated file's line/column
  20831. * order or the original's source/line/column order, respectively. Defaults to
  20832. * `SourceMapConsumer.GENERATED_ORDER`.
  20833. */
  20834. SourceMapConsumer.prototype.eachMapping =
  20835. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  20836. var context = aContext || null;
  20837. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  20838. var mappings;
  20839. switch (order) {
  20840. case SourceMapConsumer.GENERATED_ORDER:
  20841. mappings = this._generatedMappings;
  20842. break;
  20843. case SourceMapConsumer.ORIGINAL_ORDER:
  20844. mappings = this._originalMappings;
  20845. break;
  20846. default:
  20847. throw new Error("Unknown order of iteration.");
  20848. }
  20849. var sourceRoot = this.sourceRoot;
  20850. var boundCallback = aCallback.bind(context);
  20851. var names = this._names;
  20852. var sources = this._sources;
  20853. var sourceMapURL = this._sourceMapURL;
  20854. for (var i = 0, n = mappings.length; i < n; i++) {
  20855. var mapping = mappings[i];
  20856. var source = mapping.source === null ? null : sources.at(mapping.source);
  20857. if(source !== null) {
  20858. source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
  20859. }
  20860. boundCallback({
  20861. source: source,
  20862. generatedLine: mapping.generatedLine,
  20863. generatedColumn: mapping.generatedColumn,
  20864. originalLine: mapping.originalLine,
  20865. originalColumn: mapping.originalColumn,
  20866. name: mapping.name === null ? null : names.at(mapping.name)
  20867. });
  20868. }
  20869. };
  20870. /**
  20871. * Returns all generated line and column information for the original source,
  20872. * line, and column provided. If no column is provided, returns all mappings
  20873. * corresponding to a either the line we are searching for or the next
  20874. * closest line that has any mappings. Otherwise, returns all mappings
  20875. * corresponding to the given line and either the column we are searching for
  20876. * or the next closest column that has any offsets.
  20877. *
  20878. * The only argument is an object with the following properties:
  20879. *
  20880. * - source: The filename of the original source.
  20881. * - line: The line number in the original source. The line number is 1-based.
  20882. * - column: Optional. the column number in the original source.
  20883. * The column number is 0-based.
  20884. *
  20885. * and an array of objects is returned, each with the following properties:
  20886. *
  20887. * - line: The line number in the generated source, or null. The
  20888. * line number is 1-based.
  20889. * - column: The column number in the generated source, or null.
  20890. * The column number is 0-based.
  20891. */
  20892. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  20893. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  20894. var line = util.getArg(aArgs, 'line');
  20895. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  20896. // returns the index of the closest mapping less than the needle. By
  20897. // setting needle.originalColumn to 0, we thus find the last mapping for
  20898. // the given line, provided such a mapping exists.
  20899. var needle = {
  20900. source: util.getArg(aArgs, 'source'),
  20901. originalLine: line,
  20902. originalColumn: util.getArg(aArgs, 'column', 0)
  20903. };
  20904. needle.source = this._findSourceIndex(needle.source);
  20905. if (needle.source < 0) {
  20906. return [];
  20907. }
  20908. var mappings = [];
  20909. var index = this._findMapping(needle,
  20910. this._originalMappings,
  20911. "originalLine",
  20912. "originalColumn",
  20913. util.compareByOriginalPositions,
  20914. binarySearch.LEAST_UPPER_BOUND);
  20915. if (index >= 0) {
  20916. var mapping = this._originalMappings[index];
  20917. if (aArgs.column === undefined) {
  20918. var originalLine = mapping.originalLine;
  20919. // Iterate until either we run out of mappings, or we run into
  20920. // a mapping for a different line than the one we found. Since
  20921. // mappings are sorted, this is guaranteed to find all mappings for
  20922. // the line we found.
  20923. while (mapping && mapping.originalLine === originalLine) {
  20924. mappings.push({
  20925. line: util.getArg(mapping, 'generatedLine', null),
  20926. column: util.getArg(mapping, 'generatedColumn', null),
  20927. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  20928. });
  20929. mapping = this._originalMappings[++index];
  20930. }
  20931. } else {
  20932. var originalColumn = mapping.originalColumn;
  20933. // Iterate until either we run out of mappings, or we run into
  20934. // a mapping for a different line than the one we were searching for.
  20935. // Since mappings are sorted, this is guaranteed to find all mappings for
  20936. // the line we are searching for.
  20937. while (mapping &&
  20938. mapping.originalLine === line &&
  20939. mapping.originalColumn == originalColumn) {
  20940. mappings.push({
  20941. line: util.getArg(mapping, 'generatedLine', null),
  20942. column: util.getArg(mapping, 'generatedColumn', null),
  20943. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  20944. });
  20945. mapping = this._originalMappings[++index];
  20946. }
  20947. }
  20948. }
  20949. return mappings;
  20950. };
  20951. sourceMapConsumer$1.SourceMapConsumer = SourceMapConsumer;
  20952. /**
  20953. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  20954. * query for information about the original file positions by giving it a file
  20955. * position in the generated source.
  20956. *
  20957. * The first parameter is the raw source map (either as a JSON string, or
  20958. * already parsed to an object). According to the spec, source maps have the
  20959. * following attributes:
  20960. *
  20961. * - version: Which version of the source map spec this map is following.
  20962. * - sources: An array of URLs to the original source files.
  20963. * - names: An array of identifiers which can be referrenced by individual mappings.
  20964. * - sourceRoot: Optional. The URL root from which all sources are relative.
  20965. * - sourcesContent: Optional. An array of contents of the original source files.
  20966. * - mappings: A string of base64 VLQs which contain the actual mappings.
  20967. * - file: Optional. The generated file this source map is associated with.
  20968. *
  20969. * Here is an example source map, taken from the source map spec[0]:
  20970. *
  20971. * {
  20972. * version : 3,
  20973. * file: "out.js",
  20974. * sourceRoot : "",
  20975. * sources: ["foo.js", "bar.js"],
  20976. * names: ["src", "maps", "are", "fun"],
  20977. * mappings: "AA,AB;;ABCDE;"
  20978. * }
  20979. *
  20980. * The second parameter, if given, is a string whose value is the URL
  20981. * at which the source map was found. This URL is used to compute the
  20982. * sources array.
  20983. *
  20984. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  20985. */
  20986. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  20987. var sourceMap = aSourceMap;
  20988. if (typeof aSourceMap === 'string') {
  20989. sourceMap = util.parseSourceMapInput(aSourceMap);
  20990. }
  20991. var version = util.getArg(sourceMap, 'version');
  20992. var sources = util.getArg(sourceMap, 'sources');
  20993. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  20994. // requires the array) to play nice here.
  20995. var names = util.getArg(sourceMap, 'names', []);
  20996. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  20997. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  20998. var mappings = util.getArg(sourceMap, 'mappings');
  20999. var file = util.getArg(sourceMap, 'file', null);
  21000. // Once again, Sass deviates from the spec and supplies the version as a
  21001. // string rather than a number, so we use loose equality checking here.
  21002. if (version != this._version) {
  21003. throw new Error('Unsupported version: ' + version);
  21004. }
  21005. if (sourceRoot) {
  21006. sourceRoot = util.normalize(sourceRoot);
  21007. }
  21008. sources = sources
  21009. .map(String)
  21010. // Some source maps produce relative source paths like "./foo.js" instead of
  21011. // "foo.js". Normalize these first so that future comparisons will succeed.
  21012. // See bugzil.la/1090768.
  21013. .map(util.normalize)
  21014. // Always ensure that absolute sources are internally stored relative to
  21015. // the source root, if the source root is absolute. Not doing this would
  21016. // be particularly problematic when the source root is a prefix of the
  21017. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  21018. .map(function (source) {
  21019. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  21020. ? util.relative(sourceRoot, source)
  21021. : source;
  21022. });
  21023. // Pass `true` below to allow duplicate names and sources. While source maps
  21024. // are intended to be compressed and deduplicated, the TypeScript compiler
  21025. // sometimes generates source maps with duplicates in them. See Github issue
  21026. // #72 and bugzil.la/889492.
  21027. this._names = ArraySet.fromArray(names.map(String), true);
  21028. this._sources = ArraySet.fromArray(sources, true);
  21029. this._absoluteSources = this._sources.toArray().map(function (s) {
  21030. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  21031. });
  21032. this.sourceRoot = sourceRoot;
  21033. this.sourcesContent = sourcesContent;
  21034. this._mappings = mappings;
  21035. this._sourceMapURL = aSourceMapURL;
  21036. this.file = file;
  21037. }
  21038. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  21039. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  21040. /**
  21041. * Utility function to find the index of a source. Returns -1 if not
  21042. * found.
  21043. */
  21044. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  21045. var relativeSource = aSource;
  21046. if (this.sourceRoot != null) {
  21047. relativeSource = util.relative(this.sourceRoot, relativeSource);
  21048. }
  21049. if (this._sources.has(relativeSource)) {
  21050. return this._sources.indexOf(relativeSource);
  21051. }
  21052. // Maybe aSource is an absolute URL as returned by |sources|. In
  21053. // this case we can't simply undo the transform.
  21054. var i;
  21055. for (i = 0; i < this._absoluteSources.length; ++i) {
  21056. if (this._absoluteSources[i] == aSource) {
  21057. return i;
  21058. }
  21059. }
  21060. return -1;
  21061. };
  21062. /**
  21063. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  21064. *
  21065. * @param SourceMapGenerator aSourceMap
  21066. * The source map that will be consumed.
  21067. * @param String aSourceMapURL
  21068. * The URL at which the source map can be found (optional)
  21069. * @returns BasicSourceMapConsumer
  21070. */
  21071. BasicSourceMapConsumer.fromSourceMap =
  21072. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  21073. var smc = Object.create(BasicSourceMapConsumer.prototype);
  21074. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  21075. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  21076. smc.sourceRoot = aSourceMap._sourceRoot;
  21077. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  21078. smc.sourceRoot);
  21079. smc.file = aSourceMap._file;
  21080. smc._sourceMapURL = aSourceMapURL;
  21081. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  21082. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  21083. });
  21084. // Because we are modifying the entries (by converting string sources and
  21085. // names to indices into the sources and names ArraySets), we have to make
  21086. // a copy of the entry or else bad things happen. Shared mutable state
  21087. // strikes again! See github issue #191.
  21088. var generatedMappings = aSourceMap._mappings.toArray().slice();
  21089. var destGeneratedMappings = smc.__generatedMappings = [];
  21090. var destOriginalMappings = smc.__originalMappings = [];
  21091. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  21092. var srcMapping = generatedMappings[i];
  21093. var destMapping = new Mapping;
  21094. destMapping.generatedLine = srcMapping.generatedLine;
  21095. destMapping.generatedColumn = srcMapping.generatedColumn;
  21096. if (srcMapping.source) {
  21097. destMapping.source = sources.indexOf(srcMapping.source);
  21098. destMapping.originalLine = srcMapping.originalLine;
  21099. destMapping.originalColumn = srcMapping.originalColumn;
  21100. if (srcMapping.name) {
  21101. destMapping.name = names.indexOf(srcMapping.name);
  21102. }
  21103. destOriginalMappings.push(destMapping);
  21104. }
  21105. destGeneratedMappings.push(destMapping);
  21106. }
  21107. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  21108. return smc;
  21109. };
  21110. /**
  21111. * The version of the source mapping spec that we are consuming.
  21112. */
  21113. BasicSourceMapConsumer.prototype._version = 3;
  21114. /**
  21115. * The list of original sources.
  21116. */
  21117. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  21118. get: function () {
  21119. return this._absoluteSources.slice();
  21120. }
  21121. });
  21122. /**
  21123. * Provide the JIT with a nice shape / hidden class.
  21124. */
  21125. function Mapping() {
  21126. this.generatedLine = 0;
  21127. this.generatedColumn = 0;
  21128. this.source = null;
  21129. this.originalLine = null;
  21130. this.originalColumn = null;
  21131. this.name = null;
  21132. }
  21133. /**
  21134. * Parse the mappings in a string in to a data structure which we can easily
  21135. * query (the ordered arrays in the `this.__generatedMappings` and
  21136. * `this.__originalMappings` properties).
  21137. */
  21138. const compareGenerated = util.compareByGeneratedPositionsDeflatedNoLine;
  21139. function sortGenerated(array, start) {
  21140. let l = array.length;
  21141. let n = array.length - start;
  21142. if (n <= 1) {
  21143. return;
  21144. } else if (n == 2) {
  21145. let a = array[start];
  21146. let b = array[start + 1];
  21147. if (compareGenerated(a, b) > 0) {
  21148. array[start] = b;
  21149. array[start + 1] = a;
  21150. }
  21151. } else if (n < 20) {
  21152. for (let i = start; i < l; i++) {
  21153. for (let j = i; j > start; j--) {
  21154. let a = array[j - 1];
  21155. let b = array[j];
  21156. if (compareGenerated(a, b) <= 0) {
  21157. break;
  21158. }
  21159. array[j - 1] = b;
  21160. array[j] = a;
  21161. }
  21162. }
  21163. } else {
  21164. quickSort(array, compareGenerated, start);
  21165. }
  21166. }
  21167. BasicSourceMapConsumer.prototype._parseMappings =
  21168. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  21169. var generatedLine = 1;
  21170. var previousGeneratedColumn = 0;
  21171. var previousOriginalLine = 0;
  21172. var previousOriginalColumn = 0;
  21173. var previousSource = 0;
  21174. var previousName = 0;
  21175. var length = aStr.length;
  21176. var index = 0;
  21177. var temp = {};
  21178. var originalMappings = [];
  21179. var generatedMappings = [];
  21180. var mapping, segment, end, value;
  21181. let subarrayStart = 0;
  21182. while (index < length) {
  21183. if (aStr.charAt(index) === ';') {
  21184. generatedLine++;
  21185. index++;
  21186. previousGeneratedColumn = 0;
  21187. sortGenerated(generatedMappings, subarrayStart);
  21188. subarrayStart = generatedMappings.length;
  21189. }
  21190. else if (aStr.charAt(index) === ',') {
  21191. index++;
  21192. }
  21193. else {
  21194. mapping = new Mapping();
  21195. mapping.generatedLine = generatedLine;
  21196. for (end = index; end < length; end++) {
  21197. if (this._charIsMappingSeparator(aStr, end)) {
  21198. break;
  21199. }
  21200. }
  21201. aStr.slice(index, end);
  21202. segment = [];
  21203. while (index < end) {
  21204. base64VLQ.decode(aStr, index, temp);
  21205. value = temp.value;
  21206. index = temp.rest;
  21207. segment.push(value);
  21208. }
  21209. if (segment.length === 2) {
  21210. throw new Error('Found a source, but no line and column');
  21211. }
  21212. if (segment.length === 3) {
  21213. throw new Error('Found a source and line, but no column');
  21214. }
  21215. // Generated column.
  21216. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  21217. previousGeneratedColumn = mapping.generatedColumn;
  21218. if (segment.length > 1) {
  21219. // Original source.
  21220. mapping.source = previousSource + segment[1];
  21221. previousSource += segment[1];
  21222. // Original line.
  21223. mapping.originalLine = previousOriginalLine + segment[2];
  21224. previousOriginalLine = mapping.originalLine;
  21225. // Lines are stored 0-based
  21226. mapping.originalLine += 1;
  21227. // Original column.
  21228. mapping.originalColumn = previousOriginalColumn + segment[3];
  21229. previousOriginalColumn = mapping.originalColumn;
  21230. if (segment.length > 4) {
  21231. // Original name.
  21232. mapping.name = previousName + segment[4];
  21233. previousName += segment[4];
  21234. }
  21235. }
  21236. generatedMappings.push(mapping);
  21237. if (typeof mapping.originalLine === 'number') {
  21238. let currentSource = mapping.source;
  21239. while (originalMappings.length <= currentSource) {
  21240. originalMappings.push(null);
  21241. }
  21242. if (originalMappings[currentSource] === null) {
  21243. originalMappings[currentSource] = [];
  21244. }
  21245. originalMappings[currentSource].push(mapping);
  21246. }
  21247. }
  21248. }
  21249. sortGenerated(generatedMappings, subarrayStart);
  21250. this.__generatedMappings = generatedMappings;
  21251. for (var i = 0; i < originalMappings.length; i++) {
  21252. if (originalMappings[i] != null) {
  21253. quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource);
  21254. }
  21255. }
  21256. this.__originalMappings = [].concat(...originalMappings);
  21257. };
  21258. /**
  21259. * Find the mapping that best matches the hypothetical "needle" mapping that
  21260. * we are searching for in the given "haystack" of mappings.
  21261. */
  21262. BasicSourceMapConsumer.prototype._findMapping =
  21263. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  21264. aColumnName, aComparator, aBias) {
  21265. // To return the position we are searching for, we must first find the
  21266. // mapping for the given position and then return the opposite position it
  21267. // points to. Because the mappings are sorted, we can use binary search to
  21268. // find the best mapping.
  21269. if (aNeedle[aLineName] <= 0) {
  21270. throw new TypeError('Line must be greater than or equal to 1, got '
  21271. + aNeedle[aLineName]);
  21272. }
  21273. if (aNeedle[aColumnName] < 0) {
  21274. throw new TypeError('Column must be greater than or equal to 0, got '
  21275. + aNeedle[aColumnName]);
  21276. }
  21277. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  21278. };
  21279. /**
  21280. * Compute the last column for each generated mapping. The last column is
  21281. * inclusive.
  21282. */
  21283. BasicSourceMapConsumer.prototype.computeColumnSpans =
  21284. function SourceMapConsumer_computeColumnSpans() {
  21285. for (var index = 0; index < this._generatedMappings.length; ++index) {
  21286. var mapping = this._generatedMappings[index];
  21287. // Mappings do not contain a field for the last generated columnt. We
  21288. // can come up with an optimistic estimate, however, by assuming that
  21289. // mappings are contiguous (i.e. given two consecutive mappings, the
  21290. // first mapping ends where the second one starts).
  21291. if (index + 1 < this._generatedMappings.length) {
  21292. var nextMapping = this._generatedMappings[index + 1];
  21293. if (mapping.generatedLine === nextMapping.generatedLine) {
  21294. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  21295. continue;
  21296. }
  21297. }
  21298. // The last mapping for each line spans the entire line.
  21299. mapping.lastGeneratedColumn = Infinity;
  21300. }
  21301. };
  21302. /**
  21303. * Returns the original source, line, and column information for the generated
  21304. * source's line and column positions provided. The only argument is an object
  21305. * with the following properties:
  21306. *
  21307. * - line: The line number in the generated source. The line number
  21308. * is 1-based.
  21309. * - column: The column number in the generated source. The column
  21310. * number is 0-based.
  21311. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  21312. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  21313. * closest element that is smaller than or greater than the one we are
  21314. * searching for, respectively, if the exact element cannot be found.
  21315. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  21316. *
  21317. * and an object is returned with the following properties:
  21318. *
  21319. * - source: The original source file, or null.
  21320. * - line: The line number in the original source, or null. The
  21321. * line number is 1-based.
  21322. * - column: The column number in the original source, or null. The
  21323. * column number is 0-based.
  21324. * - name: The original identifier, or null.
  21325. */
  21326. BasicSourceMapConsumer.prototype.originalPositionFor =
  21327. function SourceMapConsumer_originalPositionFor(aArgs) {
  21328. var needle = {
  21329. generatedLine: util.getArg(aArgs, 'line'),
  21330. generatedColumn: util.getArg(aArgs, 'column')
  21331. };
  21332. var index = this._findMapping(
  21333. needle,
  21334. this._generatedMappings,
  21335. "generatedLine",
  21336. "generatedColumn",
  21337. util.compareByGeneratedPositionsDeflated,
  21338. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  21339. );
  21340. if (index >= 0) {
  21341. var mapping = this._generatedMappings[index];
  21342. if (mapping.generatedLine === needle.generatedLine) {
  21343. var source = util.getArg(mapping, 'source', null);
  21344. if (source !== null) {
  21345. source = this._sources.at(source);
  21346. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  21347. }
  21348. var name = util.getArg(mapping, 'name', null);
  21349. if (name !== null) {
  21350. name = this._names.at(name);
  21351. }
  21352. return {
  21353. source: source,
  21354. line: util.getArg(mapping, 'originalLine', null),
  21355. column: util.getArg(mapping, 'originalColumn', null),
  21356. name: name
  21357. };
  21358. }
  21359. }
  21360. return {
  21361. source: null,
  21362. line: null,
  21363. column: null,
  21364. name: null
  21365. };
  21366. };
  21367. /**
  21368. * Return true if we have the source content for every source in the source
  21369. * map, false otherwise.
  21370. */
  21371. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  21372. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  21373. if (!this.sourcesContent) {
  21374. return false;
  21375. }
  21376. return this.sourcesContent.length >= this._sources.size() &&
  21377. !this.sourcesContent.some(function (sc) { return sc == null; });
  21378. };
  21379. /**
  21380. * Returns the original source content. The only argument is the url of the
  21381. * original source file. Returns null if no original source content is
  21382. * available.
  21383. */
  21384. BasicSourceMapConsumer.prototype.sourceContentFor =
  21385. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  21386. if (!this.sourcesContent) {
  21387. return null;
  21388. }
  21389. var index = this._findSourceIndex(aSource);
  21390. if (index >= 0) {
  21391. return this.sourcesContent[index];
  21392. }
  21393. var relativeSource = aSource;
  21394. if (this.sourceRoot != null) {
  21395. relativeSource = util.relative(this.sourceRoot, relativeSource);
  21396. }
  21397. var url;
  21398. if (this.sourceRoot != null
  21399. && (url = util.urlParse(this.sourceRoot))) {
  21400. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  21401. // many users. We can help them out when they expect file:// URIs to
  21402. // behave like it would if they were running a local HTTP server. See
  21403. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  21404. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  21405. if (url.scheme == "file"
  21406. && this._sources.has(fileUriAbsPath)) {
  21407. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  21408. }
  21409. if ((!url.path || url.path == "/")
  21410. && this._sources.has("/" + relativeSource)) {
  21411. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  21412. }
  21413. }
  21414. // This function is used recursively from
  21415. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  21416. // don't want to throw if we can't find the source - we just want to
  21417. // return null, so we provide a flag to exit gracefully.
  21418. if (nullOnMissing) {
  21419. return null;
  21420. }
  21421. else {
  21422. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  21423. }
  21424. };
  21425. /**
  21426. * Returns the generated line and column information for the original source,
  21427. * line, and column positions provided. The only argument is an object with
  21428. * the following properties:
  21429. *
  21430. * - source: The filename of the original source.
  21431. * - line: The line number in the original source. The line number
  21432. * is 1-based.
  21433. * - column: The column number in the original source. The column
  21434. * number is 0-based.
  21435. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  21436. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  21437. * closest element that is smaller than or greater than the one we are
  21438. * searching for, respectively, if the exact element cannot be found.
  21439. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  21440. *
  21441. * and an object is returned with the following properties:
  21442. *
  21443. * - line: The line number in the generated source, or null. The
  21444. * line number is 1-based.
  21445. * - column: The column number in the generated source, or null.
  21446. * The column number is 0-based.
  21447. */
  21448. BasicSourceMapConsumer.prototype.generatedPositionFor =
  21449. function SourceMapConsumer_generatedPositionFor(aArgs) {
  21450. var source = util.getArg(aArgs, 'source');
  21451. source = this._findSourceIndex(source);
  21452. if (source < 0) {
  21453. return {
  21454. line: null,
  21455. column: null,
  21456. lastColumn: null
  21457. };
  21458. }
  21459. var needle = {
  21460. source: source,
  21461. originalLine: util.getArg(aArgs, 'line'),
  21462. originalColumn: util.getArg(aArgs, 'column')
  21463. };
  21464. var index = this._findMapping(
  21465. needle,
  21466. this._originalMappings,
  21467. "originalLine",
  21468. "originalColumn",
  21469. util.compareByOriginalPositions,
  21470. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  21471. );
  21472. if (index >= 0) {
  21473. var mapping = this._originalMappings[index];
  21474. if (mapping.source === needle.source) {
  21475. return {
  21476. line: util.getArg(mapping, 'generatedLine', null),
  21477. column: util.getArg(mapping, 'generatedColumn', null),
  21478. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  21479. };
  21480. }
  21481. }
  21482. return {
  21483. line: null,
  21484. column: null,
  21485. lastColumn: null
  21486. };
  21487. };
  21488. sourceMapConsumer$1.BasicSourceMapConsumer = BasicSourceMapConsumer;
  21489. /**
  21490. * An IndexedSourceMapConsumer instance represents a parsed source map which
  21491. * we can query for information. It differs from BasicSourceMapConsumer in
  21492. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  21493. * input.
  21494. *
  21495. * The first parameter is a raw source map (either as a JSON string, or already
  21496. * parsed to an object). According to the spec for indexed source maps, they
  21497. * have the following attributes:
  21498. *
  21499. * - version: Which version of the source map spec this map is following.
  21500. * - file: Optional. The generated file this source map is associated with.
  21501. * - sections: A list of section definitions.
  21502. *
  21503. * Each value under the "sections" field has two fields:
  21504. * - offset: The offset into the original specified at which this section
  21505. * begins to apply, defined as an object with a "line" and "column"
  21506. * field.
  21507. * - map: A source map definition. This source map could also be indexed,
  21508. * but doesn't have to be.
  21509. *
  21510. * Instead of the "map" field, it's also possible to have a "url" field
  21511. * specifying a URL to retrieve a source map from, but that's currently
  21512. * unsupported.
  21513. *
  21514. * Here's an example source map, taken from the source map spec[0], but
  21515. * modified to omit a section which uses the "url" field.
  21516. *
  21517. * {
  21518. * version : 3,
  21519. * file: "app.js",
  21520. * sections: [{
  21521. * offset: {line:100, column:10},
  21522. * map: {
  21523. * version : 3,
  21524. * file: "section.js",
  21525. * sources: ["foo.js", "bar.js"],
  21526. * names: ["src", "maps", "are", "fun"],
  21527. * mappings: "AAAA,E;;ABCDE;"
  21528. * }
  21529. * }],
  21530. * }
  21531. *
  21532. * The second parameter, if given, is a string whose value is the URL
  21533. * at which the source map was found. This URL is used to compute the
  21534. * sources array.
  21535. *
  21536. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  21537. */
  21538. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  21539. var sourceMap = aSourceMap;
  21540. if (typeof aSourceMap === 'string') {
  21541. sourceMap = util.parseSourceMapInput(aSourceMap);
  21542. }
  21543. var version = util.getArg(sourceMap, 'version');
  21544. var sections = util.getArg(sourceMap, 'sections');
  21545. if (version != this._version) {
  21546. throw new Error('Unsupported version: ' + version);
  21547. }
  21548. this._sources = new ArraySet();
  21549. this._names = new ArraySet();
  21550. var lastOffset = {
  21551. line: -1,
  21552. column: 0
  21553. };
  21554. this._sections = sections.map(function (s) {
  21555. if (s.url) {
  21556. // The url field will require support for asynchronicity.
  21557. // See https://github.com/mozilla/source-map/issues/16
  21558. throw new Error('Support for url field in sections not implemented.');
  21559. }
  21560. var offset = util.getArg(s, 'offset');
  21561. var offsetLine = util.getArg(offset, 'line');
  21562. var offsetColumn = util.getArg(offset, 'column');
  21563. if (offsetLine < lastOffset.line ||
  21564. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  21565. throw new Error('Section offsets must be ordered and non-overlapping.');
  21566. }
  21567. lastOffset = offset;
  21568. return {
  21569. generatedOffset: {
  21570. // The offset fields are 0-based, but we use 1-based indices when
  21571. // encoding/decoding from VLQ.
  21572. generatedLine: offsetLine + 1,
  21573. generatedColumn: offsetColumn + 1
  21574. },
  21575. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  21576. }
  21577. });
  21578. }
  21579. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  21580. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  21581. /**
  21582. * The version of the source mapping spec that we are consuming.
  21583. */
  21584. IndexedSourceMapConsumer.prototype._version = 3;
  21585. /**
  21586. * The list of original sources.
  21587. */
  21588. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  21589. get: function () {
  21590. var sources = [];
  21591. for (var i = 0; i < this._sections.length; i++) {
  21592. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  21593. sources.push(this._sections[i].consumer.sources[j]);
  21594. }
  21595. }
  21596. return sources;
  21597. }
  21598. });
  21599. /**
  21600. * Returns the original source, line, and column information for the generated
  21601. * source's line and column positions provided. The only argument is an object
  21602. * with the following properties:
  21603. *
  21604. * - line: The line number in the generated source. The line number
  21605. * is 1-based.
  21606. * - column: The column number in the generated source. The column
  21607. * number is 0-based.
  21608. *
  21609. * and an object is returned with the following properties:
  21610. *
  21611. * - source: The original source file, or null.
  21612. * - line: The line number in the original source, or null. The
  21613. * line number is 1-based.
  21614. * - column: The column number in the original source, or null. The
  21615. * column number is 0-based.
  21616. * - name: The original identifier, or null.
  21617. */
  21618. IndexedSourceMapConsumer.prototype.originalPositionFor =
  21619. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  21620. var needle = {
  21621. generatedLine: util.getArg(aArgs, 'line'),
  21622. generatedColumn: util.getArg(aArgs, 'column')
  21623. };
  21624. // Find the section containing the generated position we're trying to map
  21625. // to an original position.
  21626. var sectionIndex = binarySearch.search(needle, this._sections,
  21627. function(needle, section) {
  21628. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  21629. if (cmp) {
  21630. return cmp;
  21631. }
  21632. return (needle.generatedColumn -
  21633. section.generatedOffset.generatedColumn);
  21634. });
  21635. var section = this._sections[sectionIndex];
  21636. if (!section) {
  21637. return {
  21638. source: null,
  21639. line: null,
  21640. column: null,
  21641. name: null
  21642. };
  21643. }
  21644. return section.consumer.originalPositionFor({
  21645. line: needle.generatedLine -
  21646. (section.generatedOffset.generatedLine - 1),
  21647. column: needle.generatedColumn -
  21648. (section.generatedOffset.generatedLine === needle.generatedLine
  21649. ? section.generatedOffset.generatedColumn - 1
  21650. : 0),
  21651. bias: aArgs.bias
  21652. });
  21653. };
  21654. /**
  21655. * Return true if we have the source content for every source in the source
  21656. * map, false otherwise.
  21657. */
  21658. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  21659. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  21660. return this._sections.every(function (s) {
  21661. return s.consumer.hasContentsOfAllSources();
  21662. });
  21663. };
  21664. /**
  21665. * Returns the original source content. The only argument is the url of the
  21666. * original source file. Returns null if no original source content is
  21667. * available.
  21668. */
  21669. IndexedSourceMapConsumer.prototype.sourceContentFor =
  21670. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  21671. for (var i = 0; i < this._sections.length; i++) {
  21672. var section = this._sections[i];
  21673. var content = section.consumer.sourceContentFor(aSource, true);
  21674. if (content || content === '') {
  21675. return content;
  21676. }
  21677. }
  21678. if (nullOnMissing) {
  21679. return null;
  21680. }
  21681. else {
  21682. throw new Error('"' + aSource + '" is not in the SourceMap.');
  21683. }
  21684. };
  21685. /**
  21686. * Returns the generated line and column information for the original source,
  21687. * line, and column positions provided. The only argument is an object with
  21688. * the following properties:
  21689. *
  21690. * - source: The filename of the original source.
  21691. * - line: The line number in the original source. The line number
  21692. * is 1-based.
  21693. * - column: The column number in the original source. The column
  21694. * number is 0-based.
  21695. *
  21696. * and an object is returned with the following properties:
  21697. *
  21698. * - line: The line number in the generated source, or null. The
  21699. * line number is 1-based.
  21700. * - column: The column number in the generated source, or null.
  21701. * The column number is 0-based.
  21702. */
  21703. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  21704. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  21705. for (var i = 0; i < this._sections.length; i++) {
  21706. var section = this._sections[i];
  21707. // Only consider this section if the requested source is in the list of
  21708. // sources of the consumer.
  21709. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  21710. continue;
  21711. }
  21712. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  21713. if (generatedPosition) {
  21714. var ret = {
  21715. line: generatedPosition.line +
  21716. (section.generatedOffset.generatedLine - 1),
  21717. column: generatedPosition.column +
  21718. (section.generatedOffset.generatedLine === generatedPosition.line
  21719. ? section.generatedOffset.generatedColumn - 1
  21720. : 0)
  21721. };
  21722. return ret;
  21723. }
  21724. }
  21725. return {
  21726. line: null,
  21727. column: null
  21728. };
  21729. };
  21730. /**
  21731. * Parse the mappings in a string in to a data structure which we can easily
  21732. * query (the ordered arrays in the `this.__generatedMappings` and
  21733. * `this.__originalMappings` properties).
  21734. */
  21735. IndexedSourceMapConsumer.prototype._parseMappings =
  21736. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  21737. this.__generatedMappings = [];
  21738. this.__originalMappings = [];
  21739. for (var i = 0; i < this._sections.length; i++) {
  21740. var section = this._sections[i];
  21741. var sectionMappings = section.consumer._generatedMappings;
  21742. for (var j = 0; j < sectionMappings.length; j++) {
  21743. var mapping = sectionMappings[j];
  21744. var source = section.consumer._sources.at(mapping.source);
  21745. if(source !== null) {
  21746. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  21747. }
  21748. this._sources.add(source);
  21749. source = this._sources.indexOf(source);
  21750. var name = null;
  21751. if (mapping.name) {
  21752. name = section.consumer._names.at(mapping.name);
  21753. this._names.add(name);
  21754. name = this._names.indexOf(name);
  21755. }
  21756. // The mappings coming from the consumer for the section have
  21757. // generated positions relative to the start of the section, so we
  21758. // need to offset them to be relative to the start of the concatenated
  21759. // generated file.
  21760. var adjustedMapping = {
  21761. source: source,
  21762. generatedLine: mapping.generatedLine +
  21763. (section.generatedOffset.generatedLine - 1),
  21764. generatedColumn: mapping.generatedColumn +
  21765. (section.generatedOffset.generatedLine === mapping.generatedLine
  21766. ? section.generatedOffset.generatedColumn - 1
  21767. : 0),
  21768. originalLine: mapping.originalLine,
  21769. originalColumn: mapping.originalColumn,
  21770. name: name
  21771. };
  21772. this.__generatedMappings.push(adjustedMapping);
  21773. if (typeof adjustedMapping.originalLine === 'number') {
  21774. this.__originalMappings.push(adjustedMapping);
  21775. }
  21776. }
  21777. }
  21778. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  21779. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  21780. };
  21781. sourceMapConsumer$1.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  21782. return sourceMapConsumer$1;
  21783. }
  21784. var sourceNode$1 = {};
  21785. /* -*- Mode: js; js-indent-level: 2; -*- */
  21786. var hasRequiredSourceNode$1;
  21787. function requireSourceNode$1 () {
  21788. if (hasRequiredSourceNode$1) return sourceNode$1;
  21789. hasRequiredSourceNode$1 = 1;
  21790. /*
  21791. * Copyright 2011 Mozilla Foundation and contributors
  21792. * Licensed under the New BSD license. See LICENSE or:
  21793. * http://opensource.org/licenses/BSD-3-Clause
  21794. */
  21795. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  21796. var util = /*@__PURE__*/ requireUtil$2();
  21797. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  21798. // operating systems these days (capturing the result).
  21799. var REGEX_NEWLINE = /(\r?\n)/;
  21800. // Newline character code for charCodeAt() comparisons
  21801. var NEWLINE_CODE = 10;
  21802. // Private symbol for identifying `SourceNode`s when multiple versions of
  21803. // the source-map library are loaded. This MUST NOT CHANGE across
  21804. // versions!
  21805. var isSourceNode = "$$$isSourceNode$$$";
  21806. /**
  21807. * SourceNodes provide a way to abstract over interpolating/concatenating
  21808. * snippets of generated JavaScript source code while maintaining the line and
  21809. * column information associated with the original source code.
  21810. *
  21811. * @param aLine The original line number.
  21812. * @param aColumn The original column number.
  21813. * @param aSource The original source's filename.
  21814. * @param aChunks Optional. An array of strings which are snippets of
  21815. * generated JS, or other SourceNodes.
  21816. * @param aName The original identifier.
  21817. */
  21818. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  21819. this.children = [];
  21820. this.sourceContents = {};
  21821. this.line = aLine == null ? null : aLine;
  21822. this.column = aColumn == null ? null : aColumn;
  21823. this.source = aSource == null ? null : aSource;
  21824. this.name = aName == null ? null : aName;
  21825. this[isSourceNode] = true;
  21826. if (aChunks != null) this.add(aChunks);
  21827. }
  21828. /**
  21829. * Creates a SourceNode from generated code and a SourceMapConsumer.
  21830. *
  21831. * @param aGeneratedCode The generated code
  21832. * @param aSourceMapConsumer The SourceMap for the generated code
  21833. * @param aRelativePath Optional. The path that relative sources in the
  21834. * SourceMapConsumer should be relative to.
  21835. */
  21836. SourceNode.fromStringWithSourceMap =
  21837. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  21838. // The SourceNode we want to fill with the generated code
  21839. // and the SourceMap
  21840. var node = new SourceNode();
  21841. // All even indices of this array are one line of the generated code,
  21842. // while all odd indices are the newlines between two adjacent lines
  21843. // (since `REGEX_NEWLINE` captures its match).
  21844. // Processed fragments are accessed by calling `shiftNextLine`.
  21845. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  21846. var remainingLinesIndex = 0;
  21847. var shiftNextLine = function() {
  21848. var lineContents = getNextLine();
  21849. // The last line of a file might not have a newline.
  21850. var newLine = getNextLine() || "";
  21851. return lineContents + newLine;
  21852. function getNextLine() {
  21853. return remainingLinesIndex < remainingLines.length ?
  21854. remainingLines[remainingLinesIndex++] : undefined;
  21855. }
  21856. };
  21857. // We need to remember the position of "remainingLines"
  21858. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  21859. // The generate SourceNodes we need a code range.
  21860. // To extract it current and last mapping is used.
  21861. // Here we store the last mapping.
  21862. var lastMapping = null;
  21863. aSourceMapConsumer.eachMapping(function (mapping) {
  21864. if (lastMapping !== null) {
  21865. // We add the code from "lastMapping" to "mapping":
  21866. // First check if there is a new line in between.
  21867. if (lastGeneratedLine < mapping.generatedLine) {
  21868. // Associate first line with "lastMapping"
  21869. addMappingWithCode(lastMapping, shiftNextLine());
  21870. lastGeneratedLine++;
  21871. lastGeneratedColumn = 0;
  21872. // The remaining code is added without mapping
  21873. } else {
  21874. // There is no new line in between.
  21875. // Associate the code between "lastGeneratedColumn" and
  21876. // "mapping.generatedColumn" with "lastMapping"
  21877. var nextLine = remainingLines[remainingLinesIndex] || '';
  21878. var code = nextLine.substr(0, mapping.generatedColumn -
  21879. lastGeneratedColumn);
  21880. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  21881. lastGeneratedColumn);
  21882. lastGeneratedColumn = mapping.generatedColumn;
  21883. addMappingWithCode(lastMapping, code);
  21884. // No more remaining code, continue
  21885. lastMapping = mapping;
  21886. return;
  21887. }
  21888. }
  21889. // We add the generated code until the first mapping
  21890. // to the SourceNode without any mapping.
  21891. // Each line is added as separate string.
  21892. while (lastGeneratedLine < mapping.generatedLine) {
  21893. node.add(shiftNextLine());
  21894. lastGeneratedLine++;
  21895. }
  21896. if (lastGeneratedColumn < mapping.generatedColumn) {
  21897. var nextLine = remainingLines[remainingLinesIndex] || '';
  21898. node.add(nextLine.substr(0, mapping.generatedColumn));
  21899. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  21900. lastGeneratedColumn = mapping.generatedColumn;
  21901. }
  21902. lastMapping = mapping;
  21903. }, this);
  21904. // We have processed all mappings.
  21905. if (remainingLinesIndex < remainingLines.length) {
  21906. if (lastMapping) {
  21907. // Associate the remaining code in the current line with "lastMapping"
  21908. addMappingWithCode(lastMapping, shiftNextLine());
  21909. }
  21910. // and add the remaining lines without any mapping
  21911. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  21912. }
  21913. // Copy sourcesContent into SourceNode
  21914. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  21915. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  21916. if (content != null) {
  21917. if (aRelativePath != null) {
  21918. sourceFile = util.join(aRelativePath, sourceFile);
  21919. }
  21920. node.setSourceContent(sourceFile, content);
  21921. }
  21922. });
  21923. return node;
  21924. function addMappingWithCode(mapping, code) {
  21925. if (mapping === null || mapping.source === undefined) {
  21926. node.add(code);
  21927. } else {
  21928. var source = aRelativePath
  21929. ? util.join(aRelativePath, mapping.source)
  21930. : mapping.source;
  21931. node.add(new SourceNode(mapping.originalLine,
  21932. mapping.originalColumn,
  21933. source,
  21934. code,
  21935. mapping.name));
  21936. }
  21937. }
  21938. };
  21939. /**
  21940. * Add a chunk of generated JS to this source node.
  21941. *
  21942. * @param aChunk A string snippet of generated JS code, another instance of
  21943. * SourceNode, or an array where each member is one of those things.
  21944. */
  21945. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  21946. if (Array.isArray(aChunk)) {
  21947. aChunk.forEach(function (chunk) {
  21948. this.add(chunk);
  21949. }, this);
  21950. }
  21951. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  21952. if (aChunk) {
  21953. this.children.push(aChunk);
  21954. }
  21955. }
  21956. else {
  21957. throw new TypeError(
  21958. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  21959. );
  21960. }
  21961. return this;
  21962. };
  21963. /**
  21964. * Add a chunk of generated JS to the beginning of this source node.
  21965. *
  21966. * @param aChunk A string snippet of generated JS code, another instance of
  21967. * SourceNode, or an array where each member is one of those things.
  21968. */
  21969. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  21970. if (Array.isArray(aChunk)) {
  21971. for (var i = aChunk.length-1; i >= 0; i--) {
  21972. this.prepend(aChunk[i]);
  21973. }
  21974. }
  21975. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  21976. this.children.unshift(aChunk);
  21977. }
  21978. else {
  21979. throw new TypeError(
  21980. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  21981. );
  21982. }
  21983. return this;
  21984. };
  21985. /**
  21986. * Walk over the tree of JS snippets in this node and its children. The
  21987. * walking function is called once for each snippet of JS and is passed that
  21988. * snippet and the its original associated source's line/column location.
  21989. *
  21990. * @param aFn The traversal function.
  21991. */
  21992. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  21993. var chunk;
  21994. for (var i = 0, len = this.children.length; i < len; i++) {
  21995. chunk = this.children[i];
  21996. if (chunk[isSourceNode]) {
  21997. chunk.walk(aFn);
  21998. }
  21999. else {
  22000. if (chunk !== '') {
  22001. aFn(chunk, { source: this.source,
  22002. line: this.line,
  22003. column: this.column,
  22004. name: this.name });
  22005. }
  22006. }
  22007. }
  22008. };
  22009. /**
  22010. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  22011. * each of `this.children`.
  22012. *
  22013. * @param aSep The separator.
  22014. */
  22015. SourceNode.prototype.join = function SourceNode_join(aSep) {
  22016. var newChildren;
  22017. var i;
  22018. var len = this.children.length;
  22019. if (len > 0) {
  22020. newChildren = [];
  22021. for (i = 0; i < len-1; i++) {
  22022. newChildren.push(this.children[i]);
  22023. newChildren.push(aSep);
  22024. }
  22025. newChildren.push(this.children[i]);
  22026. this.children = newChildren;
  22027. }
  22028. return this;
  22029. };
  22030. /**
  22031. * Call String.prototype.replace on the very right-most source snippet. Useful
  22032. * for trimming whitespace from the end of a source node, etc.
  22033. *
  22034. * @param aPattern The pattern to replace.
  22035. * @param aReplacement The thing to replace the pattern with.
  22036. */
  22037. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  22038. var lastChild = this.children[this.children.length - 1];
  22039. if (lastChild[isSourceNode]) {
  22040. lastChild.replaceRight(aPattern, aReplacement);
  22041. }
  22042. else if (typeof lastChild === 'string') {
  22043. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  22044. }
  22045. else {
  22046. this.children.push(''.replace(aPattern, aReplacement));
  22047. }
  22048. return this;
  22049. };
  22050. /**
  22051. * Set the source content for a source file. This will be added to the SourceMapGenerator
  22052. * in the sourcesContent field.
  22053. *
  22054. * @param aSourceFile The filename of the source file
  22055. * @param aSourceContent The content of the source file
  22056. */
  22057. SourceNode.prototype.setSourceContent =
  22058. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  22059. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  22060. };
  22061. /**
  22062. * Walk over the tree of SourceNodes. The walking function is called for each
  22063. * source file content and is passed the filename and source content.
  22064. *
  22065. * @param aFn The traversal function.
  22066. */
  22067. SourceNode.prototype.walkSourceContents =
  22068. function SourceNode_walkSourceContents(aFn) {
  22069. for (var i = 0, len = this.children.length; i < len; i++) {
  22070. if (this.children[i][isSourceNode]) {
  22071. this.children[i].walkSourceContents(aFn);
  22072. }
  22073. }
  22074. var sources = Object.keys(this.sourceContents);
  22075. for (var i = 0, len = sources.length; i < len; i++) {
  22076. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  22077. }
  22078. };
  22079. /**
  22080. * Return the string representation of this source node. Walks over the tree
  22081. * and concatenates all the various snippets together to one string.
  22082. */
  22083. SourceNode.prototype.toString = function SourceNode_toString() {
  22084. var str = "";
  22085. this.walk(function (chunk) {
  22086. str += chunk;
  22087. });
  22088. return str;
  22089. };
  22090. /**
  22091. * Returns the string representation of this source node along with a source
  22092. * map.
  22093. */
  22094. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  22095. var generated = {
  22096. code: "",
  22097. line: 1,
  22098. column: 0
  22099. };
  22100. var map = new SourceMapGenerator(aArgs);
  22101. var sourceMappingActive = false;
  22102. var lastOriginalSource = null;
  22103. var lastOriginalLine = null;
  22104. var lastOriginalColumn = null;
  22105. var lastOriginalName = null;
  22106. this.walk(function (chunk, original) {
  22107. generated.code += chunk;
  22108. if (original.source !== null
  22109. && original.line !== null
  22110. && original.column !== null) {
  22111. if(lastOriginalSource !== original.source
  22112. || lastOriginalLine !== original.line
  22113. || lastOriginalColumn !== original.column
  22114. || lastOriginalName !== original.name) {
  22115. map.addMapping({
  22116. source: original.source,
  22117. original: {
  22118. line: original.line,
  22119. column: original.column
  22120. },
  22121. generated: {
  22122. line: generated.line,
  22123. column: generated.column
  22124. },
  22125. name: original.name
  22126. });
  22127. }
  22128. lastOriginalSource = original.source;
  22129. lastOriginalLine = original.line;
  22130. lastOriginalColumn = original.column;
  22131. lastOriginalName = original.name;
  22132. sourceMappingActive = true;
  22133. } else if (sourceMappingActive) {
  22134. map.addMapping({
  22135. generated: {
  22136. line: generated.line,
  22137. column: generated.column
  22138. }
  22139. });
  22140. lastOriginalSource = null;
  22141. sourceMappingActive = false;
  22142. }
  22143. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  22144. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  22145. generated.line++;
  22146. generated.column = 0;
  22147. // Mappings end at eol
  22148. if (idx + 1 === length) {
  22149. lastOriginalSource = null;
  22150. sourceMappingActive = false;
  22151. } else if (sourceMappingActive) {
  22152. map.addMapping({
  22153. source: original.source,
  22154. original: {
  22155. line: original.line,
  22156. column: original.column
  22157. },
  22158. generated: {
  22159. line: generated.line,
  22160. column: generated.column
  22161. },
  22162. name: original.name
  22163. });
  22164. }
  22165. } else {
  22166. generated.column++;
  22167. }
  22168. }
  22169. });
  22170. this.walkSourceContents(function (sourceFile, sourceContent) {
  22171. map.setSourceContent(sourceFile, sourceContent);
  22172. });
  22173. return { code: generated.code, map: map };
  22174. };
  22175. sourceNode$1.SourceNode = SourceNode;
  22176. return sourceNode$1;
  22177. }
  22178. /*
  22179. * Copyright 2009-2011 Mozilla Foundation and contributors
  22180. * Licensed under the New BSD license. See LICENSE.txt or:
  22181. * http://opensource.org/licenses/BSD-3-Clause
  22182. */
  22183. var hasRequiredSourceMap$1;
  22184. function requireSourceMap$1 () {
  22185. if (hasRequiredSourceMap$1) return sourceMap$1;
  22186. hasRequiredSourceMap$1 = 1;
  22187. sourceMap$1.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator$1().SourceMapGenerator;
  22188. sourceMap$1.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer$1().SourceMapConsumer;
  22189. sourceMap$1.SourceNode = /*@__PURE__*/ requireSourceNode$1().SourceNode;
  22190. return sourceMap$1;
  22191. }
  22192. var sourceMapExports = /*@__PURE__*/ requireSourceMap$1();
  22193. const PURE_ANNOTATION = `/*@__PURE__*/`;
  22194. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  22195. function createCodegenContext(ast, {
  22196. mode = "function",
  22197. prefixIdentifiers = mode === "module",
  22198. sourceMap = false,
  22199. filename = `template.vue.html`,
  22200. scopeId = null,
  22201. optimizeImports = false,
  22202. runtimeGlobalName = `Vue`,
  22203. runtimeModuleName = `vue`,
  22204. ssrRuntimeModuleName = "vue/server-renderer",
  22205. ssr = false,
  22206. isTS = false,
  22207. inSSR = false
  22208. }) {
  22209. const context = {
  22210. mode,
  22211. prefixIdentifiers,
  22212. sourceMap,
  22213. filename,
  22214. scopeId,
  22215. optimizeImports,
  22216. runtimeGlobalName,
  22217. runtimeModuleName,
  22218. ssrRuntimeModuleName,
  22219. ssr,
  22220. isTS,
  22221. inSSR,
  22222. source: ast.source,
  22223. code: ``,
  22224. column: 1,
  22225. line: 1,
  22226. offset: 0,
  22227. indentLevel: 0,
  22228. pure: false,
  22229. map: void 0,
  22230. helper(key) {
  22231. return `_${helperNameMap[key]}`;
  22232. },
  22233. push(code, newlineIndex = -2 /* None */, node) {
  22234. context.code += code;
  22235. if (context.map) {
  22236. if (node) {
  22237. let name;
  22238. if (node.type === 4 && !node.isStatic) {
  22239. const content = node.content.replace(/^_ctx\./, "");
  22240. if (content !== node.content && isSimpleIdentifier(content)) {
  22241. name = content;
  22242. }
  22243. }
  22244. if (node.loc.source) {
  22245. addMapping(node.loc.start, name);
  22246. }
  22247. }
  22248. if (newlineIndex === -3 /* Unknown */) {
  22249. advancePositionWithMutation(context, code);
  22250. } else {
  22251. context.offset += code.length;
  22252. if (newlineIndex === -2 /* None */) {
  22253. context.column += code.length;
  22254. } else {
  22255. if (newlineIndex === -1 /* End */) {
  22256. newlineIndex = code.length - 1;
  22257. }
  22258. context.line++;
  22259. context.column = code.length - newlineIndex;
  22260. }
  22261. }
  22262. if (node && node.loc !== locStub && node.loc.source) {
  22263. addMapping(node.loc.end);
  22264. }
  22265. }
  22266. },
  22267. indent() {
  22268. newline(++context.indentLevel);
  22269. },
  22270. deindent(withoutNewLine = false) {
  22271. if (withoutNewLine) {
  22272. --context.indentLevel;
  22273. } else {
  22274. newline(--context.indentLevel);
  22275. }
  22276. },
  22277. newline() {
  22278. newline(context.indentLevel);
  22279. }
  22280. };
  22281. function newline(n) {
  22282. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  22283. }
  22284. function addMapping(loc, name = null) {
  22285. const { _names, _mappings } = context.map;
  22286. if (name !== null && !_names.has(name)) _names.add(name);
  22287. _mappings.add({
  22288. originalLine: loc.line,
  22289. originalColumn: loc.column - 1,
  22290. // source-map column is 0 based
  22291. generatedLine: context.line,
  22292. generatedColumn: context.column - 1,
  22293. source: filename,
  22294. name
  22295. });
  22296. }
  22297. if (sourceMap) {
  22298. context.map = new sourceMapExports.SourceMapGenerator();
  22299. context.map.setSourceContent(filename, context.source);
  22300. context.map._sources.add(filename);
  22301. }
  22302. return context;
  22303. }
  22304. function generate(ast, options = {}) {
  22305. const context = createCodegenContext(ast, options);
  22306. if (options.onContextCreated) options.onContextCreated(context);
  22307. const {
  22308. mode,
  22309. push,
  22310. prefixIdentifiers,
  22311. indent,
  22312. deindent,
  22313. newline,
  22314. scopeId,
  22315. ssr
  22316. } = context;
  22317. const helpers = Array.from(ast.helpers);
  22318. const hasHelpers = helpers.length > 0;
  22319. const useWithBlock = !prefixIdentifiers && mode !== "module";
  22320. const genScopeId = scopeId != null && mode === "module";
  22321. const isSetupInlined = !!options.inline;
  22322. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  22323. if (mode === "module") {
  22324. genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
  22325. } else {
  22326. genFunctionPreamble(ast, preambleContext);
  22327. }
  22328. const functionName = ssr ? `ssrRender` : `render`;
  22329. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  22330. if (options.bindingMetadata && !options.inline) {
  22331. args.push("$props", "$setup", "$data", "$options");
  22332. }
  22333. const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
  22334. if (isSetupInlined) {
  22335. push(`(${signature}) => {`);
  22336. } else {
  22337. push(`function ${functionName}(${signature}) {`);
  22338. }
  22339. indent();
  22340. if (useWithBlock) {
  22341. push(`with (_ctx) {`);
  22342. indent();
  22343. if (hasHelpers) {
  22344. push(
  22345. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  22346. `,
  22347. -1 /* End */
  22348. );
  22349. newline();
  22350. }
  22351. }
  22352. if (ast.components.length) {
  22353. genAssets(ast.components, "component", context);
  22354. if (ast.directives.length || ast.temps > 0) {
  22355. newline();
  22356. }
  22357. }
  22358. if (ast.directives.length) {
  22359. genAssets(ast.directives, "directive", context);
  22360. if (ast.temps > 0) {
  22361. newline();
  22362. }
  22363. }
  22364. if (ast.temps > 0) {
  22365. push(`let `);
  22366. for (let i = 0; i < ast.temps; i++) {
  22367. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  22368. }
  22369. }
  22370. if (ast.components.length || ast.directives.length || ast.temps) {
  22371. push(`
  22372. `, 0 /* Start */);
  22373. newline();
  22374. }
  22375. if (!ssr) {
  22376. push(`return `);
  22377. }
  22378. if (ast.codegenNode) {
  22379. genNode(ast.codegenNode, context);
  22380. } else {
  22381. push(`null`);
  22382. }
  22383. if (useWithBlock) {
  22384. deindent();
  22385. push(`}`);
  22386. }
  22387. deindent();
  22388. push(`}`);
  22389. return {
  22390. ast,
  22391. code: context.code,
  22392. preamble: isSetupInlined ? preambleContext.code : ``,
  22393. map: context.map ? context.map.toJSON() : void 0
  22394. };
  22395. }
  22396. function genFunctionPreamble(ast, context) {
  22397. const {
  22398. ssr,
  22399. prefixIdentifiers,
  22400. push,
  22401. newline,
  22402. runtimeModuleName,
  22403. runtimeGlobalName,
  22404. ssrRuntimeModuleName
  22405. } = context;
  22406. const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
  22407. const helpers = Array.from(ast.helpers);
  22408. if (helpers.length > 0) {
  22409. if (prefixIdentifiers) {
  22410. push(
  22411. `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
  22412. `,
  22413. -1 /* End */
  22414. );
  22415. } else {
  22416. push(`const _Vue = ${VueBinding}
  22417. `, -1 /* End */);
  22418. if (ast.hoists.length) {
  22419. const staticHelpers = [
  22420. CREATE_VNODE,
  22421. CREATE_ELEMENT_VNODE,
  22422. CREATE_COMMENT,
  22423. CREATE_TEXT,
  22424. CREATE_STATIC
  22425. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  22426. push(`const { ${staticHelpers} } = _Vue
  22427. `, -1 /* End */);
  22428. }
  22429. }
  22430. }
  22431. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  22432. push(
  22433. `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
  22434. `,
  22435. -1 /* End */
  22436. );
  22437. }
  22438. genHoists(ast.hoists, context);
  22439. newline();
  22440. push(`return `);
  22441. }
  22442. function genModulePreamble(ast, context, genScopeId, inline) {
  22443. const {
  22444. push,
  22445. newline,
  22446. optimizeImports,
  22447. runtimeModuleName,
  22448. ssrRuntimeModuleName
  22449. } = context;
  22450. if (ast.helpers.size) {
  22451. const helpers = Array.from(ast.helpers);
  22452. if (optimizeImports) {
  22453. push(
  22454. `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  22455. `,
  22456. -1 /* End */
  22457. );
  22458. push(
  22459. `
  22460. // Binding optimization for webpack code-split
  22461. const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
  22462. `,
  22463. -1 /* End */
  22464. );
  22465. } else {
  22466. push(
  22467. `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
  22468. `,
  22469. -1 /* End */
  22470. );
  22471. }
  22472. }
  22473. if (ast.ssrHelpers && ast.ssrHelpers.length) {
  22474. push(
  22475. `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
  22476. `,
  22477. -1 /* End */
  22478. );
  22479. }
  22480. if (ast.imports.length) {
  22481. genImports(ast.imports, context);
  22482. newline();
  22483. }
  22484. genHoists(ast.hoists, context);
  22485. newline();
  22486. if (!inline) {
  22487. push(`export `);
  22488. }
  22489. }
  22490. function genAssets(assets, type, { helper, push, newline, isTS }) {
  22491. const resolver = helper(
  22492. type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  22493. );
  22494. for (let i = 0; i < assets.length; i++) {
  22495. let id = assets[i];
  22496. const maybeSelfReference = id.endsWith("__self");
  22497. if (maybeSelfReference) {
  22498. id = id.slice(0, -6);
  22499. }
  22500. push(
  22501. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  22502. );
  22503. if (i < assets.length - 1) {
  22504. newline();
  22505. }
  22506. }
  22507. }
  22508. function genHoists(hoists, context) {
  22509. if (!hoists.length) {
  22510. return;
  22511. }
  22512. context.pure = true;
  22513. const { push, newline } = context;
  22514. newline();
  22515. for (let i = 0; i < hoists.length; i++) {
  22516. const exp = hoists[i];
  22517. if (exp) {
  22518. push(`const _hoisted_${i + 1} = `);
  22519. genNode(exp, context);
  22520. newline();
  22521. }
  22522. }
  22523. context.pure = false;
  22524. }
  22525. function genImports(importsOptions, context) {
  22526. if (!importsOptions.length) {
  22527. return;
  22528. }
  22529. importsOptions.forEach((imports) => {
  22530. context.push(`import `);
  22531. genNode(imports.exp, context);
  22532. context.push(` from '${imports.path}'`);
  22533. context.newline();
  22534. });
  22535. }
  22536. function isText(n) {
  22537. return isString$1(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  22538. }
  22539. function genNodeListAsArray(nodes, context) {
  22540. const multilines = nodes.length > 3 || nodes.some((n) => isArray$3(n) || !isText(n));
  22541. context.push(`[`);
  22542. multilines && context.indent();
  22543. genNodeList(nodes, context, multilines);
  22544. multilines && context.deindent();
  22545. context.push(`]`);
  22546. }
  22547. function genNodeList(nodes, context, multilines = false, comma = true) {
  22548. const { push, newline } = context;
  22549. for (let i = 0; i < nodes.length; i++) {
  22550. const node = nodes[i];
  22551. if (isString$1(node)) {
  22552. push(node, -3 /* Unknown */);
  22553. } else if (isArray$3(node)) {
  22554. genNodeListAsArray(node, context);
  22555. } else {
  22556. genNode(node, context);
  22557. }
  22558. if (i < nodes.length - 1) {
  22559. if (multilines) {
  22560. comma && push(",");
  22561. newline();
  22562. } else {
  22563. comma && push(", ");
  22564. }
  22565. }
  22566. }
  22567. }
  22568. function genNode(node, context) {
  22569. if (isString$1(node)) {
  22570. context.push(node, -3 /* Unknown */);
  22571. return;
  22572. }
  22573. if (isSymbol$1(node)) {
  22574. context.push(context.helper(node));
  22575. return;
  22576. }
  22577. switch (node.type) {
  22578. case 1:
  22579. case 9:
  22580. case 11:
  22581. assert(
  22582. node.codegenNode != null,
  22583. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  22584. );
  22585. genNode(node.codegenNode, context);
  22586. break;
  22587. case 2:
  22588. genText(node, context);
  22589. break;
  22590. case 4:
  22591. genExpression(node, context);
  22592. break;
  22593. case 5:
  22594. genInterpolation(node, context);
  22595. break;
  22596. case 12:
  22597. genNode(node.codegenNode, context);
  22598. break;
  22599. case 8:
  22600. genCompoundExpression(node, context);
  22601. break;
  22602. case 3:
  22603. genComment(node, context);
  22604. break;
  22605. case 13:
  22606. genVNodeCall(node, context);
  22607. break;
  22608. case 14:
  22609. genCallExpression(node, context);
  22610. break;
  22611. case 15:
  22612. genObjectExpression(node, context);
  22613. break;
  22614. case 17:
  22615. genArrayExpression(node, context);
  22616. break;
  22617. case 18:
  22618. genFunctionExpression(node, context);
  22619. break;
  22620. case 19:
  22621. genConditionalExpression(node, context);
  22622. break;
  22623. case 20:
  22624. genCacheExpression(node, context);
  22625. break;
  22626. case 21:
  22627. genNodeList(node.body, context, true, false);
  22628. break;
  22629. // SSR only types
  22630. case 22:
  22631. genTemplateLiteral(node, context);
  22632. break;
  22633. case 23:
  22634. genIfStatement(node, context);
  22635. break;
  22636. case 24:
  22637. genAssignmentExpression(node, context);
  22638. break;
  22639. case 25:
  22640. genSequenceExpression(node, context);
  22641. break;
  22642. case 26:
  22643. genReturnStatement(node, context);
  22644. break;
  22645. /* v8 ignore start */
  22646. case 10:
  22647. break;
  22648. default:
  22649. {
  22650. assert(false, `unhandled codegen node type: ${node.type}`);
  22651. const exhaustiveCheck = node;
  22652. return exhaustiveCheck;
  22653. }
  22654. }
  22655. }
  22656. function genText(node, context) {
  22657. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  22658. }
  22659. function genExpression(node, context) {
  22660. const { content, isStatic } = node;
  22661. context.push(
  22662. isStatic ? JSON.stringify(content) : content,
  22663. -3 /* Unknown */,
  22664. node
  22665. );
  22666. }
  22667. function genInterpolation(node, context) {
  22668. const { push, helper, pure } = context;
  22669. if (pure) push(PURE_ANNOTATION);
  22670. push(`${helper(TO_DISPLAY_STRING)}(`);
  22671. genNode(node.content, context);
  22672. push(`)`);
  22673. }
  22674. function genCompoundExpression(node, context) {
  22675. for (let i = 0; i < node.children.length; i++) {
  22676. const child = node.children[i];
  22677. if (isString$1(child)) {
  22678. context.push(child, -3 /* Unknown */);
  22679. } else {
  22680. genNode(child, context);
  22681. }
  22682. }
  22683. }
  22684. function genExpressionAsPropertyKey(node, context) {
  22685. const { push } = context;
  22686. if (node.type === 8) {
  22687. push(`[`);
  22688. genCompoundExpression(node, context);
  22689. push(`]`);
  22690. } else if (node.isStatic) {
  22691. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  22692. push(text, -2 /* None */, node);
  22693. } else {
  22694. push(`[${node.content}]`, -3 /* Unknown */, node);
  22695. }
  22696. }
  22697. function genComment(node, context) {
  22698. const { push, helper, pure } = context;
  22699. if (pure) {
  22700. push(PURE_ANNOTATION);
  22701. }
  22702. push(
  22703. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  22704. -3 /* Unknown */,
  22705. node
  22706. );
  22707. }
  22708. function genVNodeCall(node, context) {
  22709. const { push, helper, pure } = context;
  22710. const {
  22711. tag,
  22712. props,
  22713. children,
  22714. patchFlag,
  22715. dynamicProps,
  22716. directives,
  22717. isBlock,
  22718. disableTracking,
  22719. isComponent
  22720. } = node;
  22721. let patchFlagString;
  22722. if (patchFlag) {
  22723. {
  22724. if (patchFlag < 0) {
  22725. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  22726. } else {
  22727. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  22728. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  22729. }
  22730. }
  22731. }
  22732. if (directives) {
  22733. push(helper(WITH_DIRECTIVES) + `(`);
  22734. }
  22735. if (isBlock) {
  22736. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  22737. }
  22738. if (pure) {
  22739. push(PURE_ANNOTATION);
  22740. }
  22741. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  22742. push(helper(callHelper) + `(`, -2 /* None */, node);
  22743. genNodeList(
  22744. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  22745. context
  22746. );
  22747. push(`)`);
  22748. if (isBlock) {
  22749. push(`)`);
  22750. }
  22751. if (directives) {
  22752. push(`, `);
  22753. genNode(directives, context);
  22754. push(`)`);
  22755. }
  22756. }
  22757. function genNullableArgs(args) {
  22758. let i = args.length;
  22759. while (i--) {
  22760. if (args[i] != null) break;
  22761. }
  22762. return args.slice(0, i + 1).map((arg) => arg || `null`);
  22763. }
  22764. function genCallExpression(node, context) {
  22765. const { push, helper, pure } = context;
  22766. const callee = isString$1(node.callee) ? node.callee : helper(node.callee);
  22767. if (pure) {
  22768. push(PURE_ANNOTATION);
  22769. }
  22770. push(callee + `(`, -2 /* None */, node);
  22771. genNodeList(node.arguments, context);
  22772. push(`)`);
  22773. }
  22774. function genObjectExpression(node, context) {
  22775. const { push, indent, deindent, newline } = context;
  22776. const { properties } = node;
  22777. if (!properties.length) {
  22778. push(`{}`, -2 /* None */, node);
  22779. return;
  22780. }
  22781. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  22782. push(multilines ? `{` : `{ `);
  22783. multilines && indent();
  22784. for (let i = 0; i < properties.length; i++) {
  22785. const { key, value } = properties[i];
  22786. genExpressionAsPropertyKey(key, context);
  22787. push(`: `);
  22788. genNode(value, context);
  22789. if (i < properties.length - 1) {
  22790. push(`,`);
  22791. newline();
  22792. }
  22793. }
  22794. multilines && deindent();
  22795. push(multilines ? `}` : ` }`);
  22796. }
  22797. function genArrayExpression(node, context) {
  22798. genNodeListAsArray(node.elements, context);
  22799. }
  22800. function genFunctionExpression(node, context) {
  22801. const { push, indent, deindent } = context;
  22802. const { params, returns, body, newline, isSlot } = node;
  22803. if (isSlot) {
  22804. push(`_${helperNameMap[WITH_CTX]}(`);
  22805. }
  22806. push(`(`, -2 /* None */, node);
  22807. if (isArray$3(params)) {
  22808. genNodeList(params, context);
  22809. } else if (params) {
  22810. genNode(params, context);
  22811. }
  22812. push(`) => `);
  22813. if (newline || body) {
  22814. push(`{`);
  22815. indent();
  22816. }
  22817. if (returns) {
  22818. if (newline) {
  22819. push(`return `);
  22820. }
  22821. if (isArray$3(returns)) {
  22822. genNodeListAsArray(returns, context);
  22823. } else {
  22824. genNode(returns, context);
  22825. }
  22826. } else if (body) {
  22827. genNode(body, context);
  22828. }
  22829. if (newline || body) {
  22830. deindent();
  22831. push(`}`);
  22832. }
  22833. if (isSlot) {
  22834. push(`)`);
  22835. }
  22836. }
  22837. function genConditionalExpression(node, context) {
  22838. const { test, consequent, alternate, newline: needNewline } = node;
  22839. const { push, indent, deindent, newline } = context;
  22840. if (test.type === 4) {
  22841. const needsParens = !isSimpleIdentifier(test.content);
  22842. needsParens && push(`(`);
  22843. genExpression(test, context);
  22844. needsParens && push(`)`);
  22845. } else {
  22846. push(`(`);
  22847. genNode(test, context);
  22848. push(`)`);
  22849. }
  22850. needNewline && indent();
  22851. context.indentLevel++;
  22852. needNewline || push(` `);
  22853. push(`? `);
  22854. genNode(consequent, context);
  22855. context.indentLevel--;
  22856. needNewline && newline();
  22857. needNewline || push(` `);
  22858. push(`: `);
  22859. const isNested = alternate.type === 19;
  22860. if (!isNested) {
  22861. context.indentLevel++;
  22862. }
  22863. genNode(alternate, context);
  22864. if (!isNested) {
  22865. context.indentLevel--;
  22866. }
  22867. needNewline && deindent(
  22868. true
  22869. /* without newline */
  22870. );
  22871. }
  22872. function genCacheExpression(node, context) {
  22873. const { push, helper, indent, deindent, newline } = context;
  22874. const { needPauseTracking, needArraySpread } = node;
  22875. if (needArraySpread) {
  22876. push(`[...(`);
  22877. }
  22878. push(`_cache[${node.index}] || (`);
  22879. if (needPauseTracking) {
  22880. indent();
  22881. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  22882. if (node.inVOnce) push(`, true`);
  22883. push(`),`);
  22884. newline();
  22885. push(`(`);
  22886. }
  22887. push(`_cache[${node.index}] = `);
  22888. genNode(node.value, context);
  22889. if (needPauseTracking) {
  22890. push(`).cacheIndex = ${node.index},`);
  22891. newline();
  22892. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  22893. newline();
  22894. push(`_cache[${node.index}]`);
  22895. deindent();
  22896. }
  22897. push(`)`);
  22898. if (needArraySpread) {
  22899. push(`)]`);
  22900. }
  22901. }
  22902. function genTemplateLiteral(node, context) {
  22903. const { push, indent, deindent } = context;
  22904. push("`");
  22905. const l = node.elements.length;
  22906. const multilines = l > 3;
  22907. for (let i = 0; i < l; i++) {
  22908. const e = node.elements[i];
  22909. if (isString$1(e)) {
  22910. push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
  22911. } else {
  22912. push("${");
  22913. if (multilines) indent();
  22914. genNode(e, context);
  22915. if (multilines) deindent();
  22916. push("}");
  22917. }
  22918. }
  22919. push("`");
  22920. }
  22921. function genIfStatement(node, context) {
  22922. const { push, indent, deindent } = context;
  22923. const { test, consequent, alternate } = node;
  22924. push(`if (`);
  22925. genNode(test, context);
  22926. push(`) {`);
  22927. indent();
  22928. genNode(consequent, context);
  22929. deindent();
  22930. push(`}`);
  22931. if (alternate) {
  22932. push(` else `);
  22933. if (alternate.type === 23) {
  22934. genIfStatement(alternate, context);
  22935. } else {
  22936. push(`{`);
  22937. indent();
  22938. genNode(alternate, context);
  22939. deindent();
  22940. push(`}`);
  22941. }
  22942. }
  22943. }
  22944. function genAssignmentExpression(node, context) {
  22945. genNode(node.left, context);
  22946. context.push(` = `);
  22947. genNode(node.right, context);
  22948. }
  22949. function genSequenceExpression(node, context) {
  22950. context.push(`(`);
  22951. genNodeList(node.expressions, context);
  22952. context.push(`)`);
  22953. }
  22954. function genReturnStatement({ returns }, context) {
  22955. context.push(`return `);
  22956. if (isArray$3(returns)) {
  22957. genNodeListAsArray(returns, context);
  22958. } else {
  22959. genNode(returns, context);
  22960. }
  22961. }
  22962. const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
  22963. const transformExpression = (node, context) => {
  22964. if (node.type === 5) {
  22965. node.content = processExpression(
  22966. node.content,
  22967. context
  22968. );
  22969. } else if (node.type === 1) {
  22970. const memo = findDir(node, "memo");
  22971. for (let i = 0; i < node.props.length; i++) {
  22972. const dir = node.props[i];
  22973. if (dir.type === 7 && dir.name !== "for") {
  22974. const exp = dir.exp;
  22975. const arg = dir.arg;
  22976. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  22977. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  22978. dir.exp = processExpression(
  22979. exp,
  22980. context,
  22981. // slot args must be processed as function params
  22982. dir.name === "slot"
  22983. );
  22984. }
  22985. if (arg && arg.type === 4 && !arg.isStatic) {
  22986. dir.arg = processExpression(arg, context);
  22987. }
  22988. }
  22989. }
  22990. }
  22991. };
  22992. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  22993. if (!context.prefixIdentifiers || !node.content.trim()) {
  22994. return node;
  22995. }
  22996. const { inline, bindingMetadata } = context;
  22997. const rewriteIdentifier = (raw, parent, id) => {
  22998. const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
  22999. if (inline) {
  23000. const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
  23001. const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
  23002. const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
  23003. const isNewExpression = parent && isInNewExpression(parentStack);
  23004. const wrapWithUnref = (raw2) => {
  23005. const wrapped = `${context.helperString(UNREF)}(${raw2})`;
  23006. return isNewExpression ? `(${wrapped})` : wrapped;
  23007. };
  23008. if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
  23009. return raw;
  23010. } else if (type === "setup-ref") {
  23011. return `${raw}.value`;
  23012. } else if (type === "setup-maybe-ref") {
  23013. return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
  23014. } else if (type === "setup-let") {
  23015. if (isAssignmentLVal) {
  23016. const { right: rVal, operator } = parent;
  23017. const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
  23018. const rExpString = stringifyExpression(
  23019. processExpression(
  23020. createSimpleExpression(rExp, false),
  23021. context,
  23022. false,
  23023. false,
  23024. knownIds
  23025. )
  23026. );
  23027. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  23028. ` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
  23029. } else if (isUpdateArg) {
  23030. id.start = parent.start;
  23031. id.end = parent.end;
  23032. const { prefix: isPrefix, operator } = parent;
  23033. const prefix = isPrefix ? operator : ``;
  23034. const postfix = isPrefix ? `` : operator;
  23035. return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
  23036. ` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
  23037. } else if (isDestructureAssignment) {
  23038. return raw;
  23039. } else {
  23040. return wrapWithUnref(raw);
  23041. }
  23042. } else if (type === "props") {
  23043. return genPropsAccessExp(raw);
  23044. } else if (type === "props-aliased") {
  23045. return genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
  23046. }
  23047. } else {
  23048. if (type && type.startsWith("setup") || type === "literal-const") {
  23049. return `$setup.${raw}`;
  23050. } else if (type === "props-aliased") {
  23051. return `$props['${bindingMetadata.__propsAliases[raw]}']`;
  23052. } else if (type) {
  23053. return `$${type}.${raw}`;
  23054. }
  23055. }
  23056. return `_ctx.${raw}`;
  23057. };
  23058. const rawExp = node.content;
  23059. let ast = node.ast;
  23060. if (ast === false) {
  23061. return node;
  23062. }
  23063. if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
  23064. const isScopeVarReference = context.identifiers[rawExp];
  23065. const isAllowedGlobal = isGloballyAllowed(rawExp);
  23066. const isLiteral = isLiteralWhitelisted(rawExp);
  23067. if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
  23068. if (isConst(bindingMetadata[rawExp])) {
  23069. node.constType = 1;
  23070. }
  23071. node.content = rewriteIdentifier(rawExp);
  23072. } else if (!isScopeVarReference) {
  23073. if (isLiteral) {
  23074. node.constType = 3;
  23075. } else {
  23076. node.constType = 2;
  23077. }
  23078. }
  23079. return node;
  23080. }
  23081. if (!ast) {
  23082. const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
  23083. try {
  23084. ast = libExports.parseExpression(source, {
  23085. sourceType: "module",
  23086. plugins: context.expressionPlugins
  23087. });
  23088. } catch (e) {
  23089. context.onError(
  23090. createCompilerError(
  23091. 45,
  23092. node.loc,
  23093. void 0,
  23094. e.message
  23095. )
  23096. );
  23097. return node;
  23098. }
  23099. }
  23100. const ids = [];
  23101. const parentStack = [];
  23102. const knownIds = Object.create(context.identifiers);
  23103. walkIdentifiers(
  23104. ast,
  23105. (node2, parent, _, isReferenced, isLocal) => {
  23106. if (isStaticPropertyKey(node2, parent)) {
  23107. return;
  23108. }
  23109. const needPrefix = isReferenced && canPrefix(node2);
  23110. if (needPrefix && !isLocal) {
  23111. if (isStaticProperty(parent) && parent.shorthand) {
  23112. node2.prefix = `${node2.name}: `;
  23113. }
  23114. node2.name = rewriteIdentifier(node2.name, parent, node2);
  23115. ids.push(node2);
  23116. } else {
  23117. if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
  23118. node2.isConstant = true;
  23119. }
  23120. ids.push(node2);
  23121. }
  23122. },
  23123. true,
  23124. // invoke on ALL identifiers
  23125. parentStack,
  23126. knownIds
  23127. );
  23128. const children = [];
  23129. ids.sort((a, b) => a.start - b.start);
  23130. ids.forEach((id, i) => {
  23131. const start = id.start - 1;
  23132. const end = id.end - 1;
  23133. const last = ids[i - 1];
  23134. const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
  23135. if (leadingText.length || id.prefix) {
  23136. children.push(leadingText + (id.prefix || ``));
  23137. }
  23138. const source = rawExp.slice(start, end);
  23139. children.push(
  23140. createSimpleExpression(
  23141. id.name,
  23142. false,
  23143. {
  23144. start: advancePositionWithClone(node.loc.start, source, start),
  23145. end: advancePositionWithClone(node.loc.start, source, end),
  23146. source
  23147. },
  23148. id.isConstant ? 3 : 0
  23149. )
  23150. );
  23151. if (i === ids.length - 1 && end < rawExp.length) {
  23152. children.push(rawExp.slice(end));
  23153. }
  23154. });
  23155. let ret;
  23156. if (children.length) {
  23157. ret = createCompoundExpression(children, node.loc);
  23158. ret.ast = ast;
  23159. } else {
  23160. ret = node;
  23161. ret.constType = 3;
  23162. }
  23163. ret.identifiers = Object.keys(knownIds);
  23164. return ret;
  23165. }
  23166. function canPrefix(id) {
  23167. if (isGloballyAllowed(id.name)) {
  23168. return false;
  23169. }
  23170. if (id.name === "require") {
  23171. return false;
  23172. }
  23173. return true;
  23174. }
  23175. function stringifyExpression(exp) {
  23176. if (isString$1(exp)) {
  23177. return exp;
  23178. } else if (exp.type === 4) {
  23179. return exp.content;
  23180. } else {
  23181. return exp.children.map(stringifyExpression).join("");
  23182. }
  23183. }
  23184. function isConst(type) {
  23185. return type === "setup-const" || type === "literal-const";
  23186. }
  23187. const transformIf = createStructuralDirectiveTransform(
  23188. /^(if|else|else-if)$/,
  23189. (node, dir, context) => {
  23190. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  23191. const siblings = context.parent.children;
  23192. let i = siblings.indexOf(ifNode);
  23193. let key = 0;
  23194. while (i-- >= 0) {
  23195. const sibling = siblings[i];
  23196. if (sibling && sibling.type === 9) {
  23197. key += sibling.branches.length;
  23198. }
  23199. }
  23200. return () => {
  23201. if (isRoot) {
  23202. ifNode.codegenNode = createCodegenNodeForBranch(
  23203. branch,
  23204. key,
  23205. context
  23206. );
  23207. } else {
  23208. const parentCondition = getParentCondition(ifNode.codegenNode);
  23209. parentCondition.alternate = createCodegenNodeForBranch(
  23210. branch,
  23211. key + ifNode.branches.length - 1,
  23212. context
  23213. );
  23214. }
  23215. };
  23216. });
  23217. }
  23218. );
  23219. function processIf(node, dir, context, processCodegen) {
  23220. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  23221. const loc = dir.exp ? dir.exp.loc : node.loc;
  23222. context.onError(
  23223. createCompilerError(28, dir.loc)
  23224. );
  23225. dir.exp = createSimpleExpression(`true`, false, loc);
  23226. }
  23227. if (context.prefixIdentifiers && dir.exp) {
  23228. dir.exp = processExpression(dir.exp, context);
  23229. }
  23230. if (dir.name === "if") {
  23231. const branch = createIfBranch(node, dir);
  23232. const ifNode = {
  23233. type: 9,
  23234. loc: cloneLoc(node.loc),
  23235. branches: [branch]
  23236. };
  23237. context.replaceNode(ifNode);
  23238. if (processCodegen) {
  23239. return processCodegen(ifNode, branch, true);
  23240. }
  23241. } else {
  23242. const siblings = context.parent.children;
  23243. const comments = [];
  23244. let i = siblings.indexOf(node);
  23245. while (i-- >= -1) {
  23246. const sibling = siblings[i];
  23247. if (sibling && sibling.type === 3) {
  23248. context.removeNode(sibling);
  23249. comments.unshift(sibling);
  23250. continue;
  23251. }
  23252. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  23253. context.removeNode(sibling);
  23254. continue;
  23255. }
  23256. if (sibling && sibling.type === 9) {
  23257. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  23258. context.onError(
  23259. createCompilerError(30, node.loc)
  23260. );
  23261. }
  23262. context.removeNode();
  23263. const branch = createIfBranch(node, dir);
  23264. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  23265. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  23266. branch.children = [...comments, ...branch.children];
  23267. }
  23268. {
  23269. const key = branch.userKey;
  23270. if (key) {
  23271. sibling.branches.forEach(({ userKey }) => {
  23272. if (isSameKey(userKey, key)) {
  23273. context.onError(
  23274. createCompilerError(
  23275. 29,
  23276. branch.userKey.loc
  23277. )
  23278. );
  23279. }
  23280. });
  23281. }
  23282. }
  23283. sibling.branches.push(branch);
  23284. const onExit = processCodegen && processCodegen(sibling, branch, false);
  23285. traverseNode(branch, context);
  23286. if (onExit) onExit();
  23287. context.currentNode = null;
  23288. } else {
  23289. context.onError(
  23290. createCompilerError(30, node.loc)
  23291. );
  23292. }
  23293. break;
  23294. }
  23295. }
  23296. }
  23297. function createIfBranch(node, dir) {
  23298. const isTemplateIf = node.tagType === 3;
  23299. return {
  23300. type: 10,
  23301. loc: node.loc,
  23302. condition: dir.name === "else" ? void 0 : dir.exp,
  23303. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  23304. userKey: findProp(node, `key`),
  23305. isTemplateIf
  23306. };
  23307. }
  23308. function createCodegenNodeForBranch(branch, keyIndex, context) {
  23309. if (branch.condition) {
  23310. return createConditionalExpression(
  23311. branch.condition,
  23312. createChildrenCodegenNode(branch, keyIndex, context),
  23313. // make sure to pass in asBlock: true so that the comment node call
  23314. // closes the current block.
  23315. createCallExpression(context.helper(CREATE_COMMENT), [
  23316. '"v-if"' ,
  23317. "true"
  23318. ])
  23319. );
  23320. } else {
  23321. return createChildrenCodegenNode(branch, keyIndex, context);
  23322. }
  23323. }
  23324. function createChildrenCodegenNode(branch, keyIndex, context) {
  23325. const { helper } = context;
  23326. const keyProperty = createObjectProperty(
  23327. `key`,
  23328. createSimpleExpression(
  23329. `${keyIndex}`,
  23330. false,
  23331. locStub,
  23332. 2
  23333. )
  23334. );
  23335. const { children } = branch;
  23336. const firstChild = children[0];
  23337. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  23338. if (needFragmentWrapper) {
  23339. if (children.length === 1 && firstChild.type === 11) {
  23340. const vnodeCall = firstChild.codegenNode;
  23341. injectProp(vnodeCall, keyProperty, context);
  23342. return vnodeCall;
  23343. } else {
  23344. let patchFlag = 64;
  23345. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  23346. patchFlag |= 2048;
  23347. }
  23348. return createVNodeCall(
  23349. context,
  23350. helper(FRAGMENT),
  23351. createObjectExpression([keyProperty]),
  23352. children,
  23353. patchFlag,
  23354. void 0,
  23355. void 0,
  23356. true,
  23357. false,
  23358. false,
  23359. branch.loc
  23360. );
  23361. }
  23362. } else {
  23363. const ret = firstChild.codegenNode;
  23364. const vnodeCall = getMemoedVNodeCall(ret);
  23365. if (vnodeCall.type === 13) {
  23366. convertToBlock(vnodeCall, context);
  23367. }
  23368. injectProp(vnodeCall, keyProperty, context);
  23369. return ret;
  23370. }
  23371. }
  23372. function isSameKey(a, b) {
  23373. if (!a || a.type !== b.type) {
  23374. return false;
  23375. }
  23376. if (a.type === 6) {
  23377. if (a.value.content !== b.value.content) {
  23378. return false;
  23379. }
  23380. } else {
  23381. const exp = a.exp;
  23382. const branchExp = b.exp;
  23383. if (exp.type !== branchExp.type) {
  23384. return false;
  23385. }
  23386. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  23387. return false;
  23388. }
  23389. }
  23390. return true;
  23391. }
  23392. function getParentCondition(node) {
  23393. while (true) {
  23394. if (node.type === 19) {
  23395. if (node.alternate.type === 19) {
  23396. node = node.alternate;
  23397. } else {
  23398. return node;
  23399. }
  23400. } else if (node.type === 20) {
  23401. node = node.value;
  23402. }
  23403. }
  23404. }
  23405. const transformBind = (dir, _node, context) => {
  23406. const { modifiers, loc } = dir;
  23407. const arg = dir.arg;
  23408. let { exp } = dir;
  23409. if (exp && exp.type === 4 && !exp.content.trim()) {
  23410. {
  23411. context.onError(
  23412. createCompilerError(34, loc)
  23413. );
  23414. return {
  23415. props: [
  23416. createObjectProperty(arg, createSimpleExpression("", true, loc))
  23417. ]
  23418. };
  23419. }
  23420. }
  23421. if (!exp) {
  23422. if (arg.type !== 4 || !arg.isStatic) {
  23423. context.onError(
  23424. createCompilerError(
  23425. 52,
  23426. arg.loc
  23427. )
  23428. );
  23429. return {
  23430. props: [
  23431. createObjectProperty(arg, createSimpleExpression("", true, loc))
  23432. ]
  23433. };
  23434. }
  23435. transformBindShorthand(dir, context);
  23436. exp = dir.exp;
  23437. }
  23438. if (arg.type !== 4) {
  23439. arg.children.unshift(`(`);
  23440. arg.children.push(`) || ""`);
  23441. } else if (!arg.isStatic) {
  23442. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  23443. }
  23444. if (modifiers.some((mod) => mod.content === "camel")) {
  23445. if (arg.type === 4) {
  23446. if (arg.isStatic) {
  23447. arg.content = camelize(arg.content);
  23448. } else {
  23449. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  23450. }
  23451. } else {
  23452. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  23453. arg.children.push(`)`);
  23454. }
  23455. }
  23456. if (!context.inSSR) {
  23457. if (modifiers.some((mod) => mod.content === "prop")) {
  23458. injectPrefix(arg, ".");
  23459. }
  23460. if (modifiers.some((mod) => mod.content === "attr")) {
  23461. injectPrefix(arg, "^");
  23462. }
  23463. }
  23464. return {
  23465. props: [createObjectProperty(arg, exp)]
  23466. };
  23467. };
  23468. const transformBindShorthand = (dir, context) => {
  23469. const arg = dir.arg;
  23470. const propName = camelize(arg.content);
  23471. dir.exp = createSimpleExpression(propName, false, arg.loc);
  23472. {
  23473. dir.exp = processExpression(dir.exp, context);
  23474. }
  23475. };
  23476. const injectPrefix = (arg, prefix) => {
  23477. if (arg.type === 4) {
  23478. if (arg.isStatic) {
  23479. arg.content = prefix + arg.content;
  23480. } else {
  23481. arg.content = `\`${prefix}\${${arg.content}}\``;
  23482. }
  23483. } else {
  23484. arg.children.unshift(`'${prefix}' + (`);
  23485. arg.children.push(`)`);
  23486. }
  23487. };
  23488. const transformFor = createStructuralDirectiveTransform(
  23489. "for",
  23490. (node, dir, context) => {
  23491. const { helper, removeHelper } = context;
  23492. return processFor(node, dir, context, (forNode) => {
  23493. const renderExp = createCallExpression(helper(RENDER_LIST), [
  23494. forNode.source
  23495. ]);
  23496. const isTemplate = isTemplateNode(node);
  23497. const memo = findDir(node, "memo");
  23498. const keyProp = findProp(node, `key`, false, true);
  23499. const isDirKey = keyProp && keyProp.type === 7;
  23500. if (isDirKey && !keyProp.exp) {
  23501. transformBindShorthand(keyProp, context);
  23502. }
  23503. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  23504. if (memo && keyExp && isDirKey) {
  23505. {
  23506. keyProp.exp = keyExp = processExpression(
  23507. keyExp,
  23508. context
  23509. );
  23510. }
  23511. }
  23512. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  23513. if (isTemplate) {
  23514. if (memo) {
  23515. memo.exp = processExpression(
  23516. memo.exp,
  23517. context
  23518. );
  23519. }
  23520. if (keyProperty && keyProp.type !== 6) {
  23521. keyProperty.value = processExpression(
  23522. keyProperty.value,
  23523. context
  23524. );
  23525. }
  23526. }
  23527. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  23528. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  23529. forNode.codegenNode = createVNodeCall(
  23530. context,
  23531. helper(FRAGMENT),
  23532. void 0,
  23533. renderExp,
  23534. fragmentFlag,
  23535. void 0,
  23536. void 0,
  23537. true,
  23538. !isStableFragment,
  23539. false,
  23540. node.loc
  23541. );
  23542. return () => {
  23543. let childBlock;
  23544. const { children } = forNode;
  23545. if (isTemplate) {
  23546. node.children.some((c) => {
  23547. if (c.type === 1) {
  23548. const key = findProp(c, "key");
  23549. if (key) {
  23550. context.onError(
  23551. createCompilerError(
  23552. 33,
  23553. key.loc
  23554. )
  23555. );
  23556. return true;
  23557. }
  23558. }
  23559. });
  23560. }
  23561. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  23562. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  23563. if (slotOutlet) {
  23564. childBlock = slotOutlet.codegenNode;
  23565. if (isTemplate && keyProperty) {
  23566. injectProp(childBlock, keyProperty, context);
  23567. }
  23568. } else if (needFragmentWrapper) {
  23569. childBlock = createVNodeCall(
  23570. context,
  23571. helper(FRAGMENT),
  23572. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  23573. node.children,
  23574. 64,
  23575. void 0,
  23576. void 0,
  23577. true,
  23578. void 0,
  23579. false
  23580. );
  23581. } else {
  23582. childBlock = children[0].codegenNode;
  23583. if (isTemplate && keyProperty) {
  23584. injectProp(childBlock, keyProperty, context);
  23585. }
  23586. if (childBlock.isBlock !== !isStableFragment) {
  23587. if (childBlock.isBlock) {
  23588. removeHelper(OPEN_BLOCK);
  23589. removeHelper(
  23590. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  23591. );
  23592. } else {
  23593. removeHelper(
  23594. getVNodeHelper(context.inSSR, childBlock.isComponent)
  23595. );
  23596. }
  23597. }
  23598. childBlock.isBlock = !isStableFragment;
  23599. if (childBlock.isBlock) {
  23600. helper(OPEN_BLOCK);
  23601. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  23602. } else {
  23603. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  23604. }
  23605. }
  23606. if (memo) {
  23607. const loop = createFunctionExpression(
  23608. createForLoopParams(forNode.parseResult, [
  23609. createSimpleExpression(`_cached`)
  23610. ])
  23611. );
  23612. loop.body = createBlockStatement([
  23613. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  23614. createCompoundExpression([
  23615. `if (_cached`,
  23616. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  23617. ` && ${context.helperString(
  23618. IS_MEMO_SAME
  23619. )}(_cached, _memo)) return _cached`
  23620. ]),
  23621. createCompoundExpression([`const _item = `, childBlock]),
  23622. createSimpleExpression(`_item.memo = _memo`),
  23623. createSimpleExpression(`return _item`)
  23624. ]);
  23625. renderExp.arguments.push(
  23626. loop,
  23627. createSimpleExpression(`_cache`),
  23628. createSimpleExpression(String(context.cached.length))
  23629. );
  23630. context.cached.push(null);
  23631. } else {
  23632. renderExp.arguments.push(
  23633. createFunctionExpression(
  23634. createForLoopParams(forNode.parseResult),
  23635. childBlock,
  23636. true
  23637. )
  23638. );
  23639. }
  23640. };
  23641. });
  23642. }
  23643. );
  23644. function processFor(node, dir, context, processCodegen) {
  23645. if (!dir.exp) {
  23646. context.onError(
  23647. createCompilerError(31, dir.loc)
  23648. );
  23649. return;
  23650. }
  23651. const parseResult = dir.forParseResult;
  23652. if (!parseResult) {
  23653. context.onError(
  23654. createCompilerError(32, dir.loc)
  23655. );
  23656. return;
  23657. }
  23658. finalizeForParseResult(parseResult, context);
  23659. const { addIdentifiers, removeIdentifiers, scopes } = context;
  23660. const { source, value, key, index } = parseResult;
  23661. const forNode = {
  23662. type: 11,
  23663. loc: dir.loc,
  23664. source,
  23665. valueAlias: value,
  23666. keyAlias: key,
  23667. objectIndexAlias: index,
  23668. parseResult,
  23669. children: isTemplateNode(node) ? node.children : [node]
  23670. };
  23671. context.replaceNode(forNode);
  23672. scopes.vFor++;
  23673. if (context.prefixIdentifiers) {
  23674. value && addIdentifiers(value);
  23675. key && addIdentifiers(key);
  23676. index && addIdentifiers(index);
  23677. }
  23678. const onExit = processCodegen && processCodegen(forNode);
  23679. return () => {
  23680. scopes.vFor--;
  23681. if (context.prefixIdentifiers) {
  23682. value && removeIdentifiers(value);
  23683. key && removeIdentifiers(key);
  23684. index && removeIdentifiers(index);
  23685. }
  23686. if (onExit) onExit();
  23687. };
  23688. }
  23689. function finalizeForParseResult(result, context) {
  23690. if (result.finalized) return;
  23691. if (context.prefixIdentifiers) {
  23692. result.source = processExpression(
  23693. result.source,
  23694. context
  23695. );
  23696. if (result.key) {
  23697. result.key = processExpression(
  23698. result.key,
  23699. context,
  23700. true
  23701. );
  23702. }
  23703. if (result.index) {
  23704. result.index = processExpression(
  23705. result.index,
  23706. context,
  23707. true
  23708. );
  23709. }
  23710. if (result.value) {
  23711. result.value = processExpression(
  23712. result.value,
  23713. context,
  23714. true
  23715. );
  23716. }
  23717. }
  23718. result.finalized = true;
  23719. }
  23720. function createForLoopParams({ value, key, index }, memoArgs = []) {
  23721. return createParamsList([value, key, index, ...memoArgs]);
  23722. }
  23723. function createParamsList(args) {
  23724. let i = args.length;
  23725. while (i--) {
  23726. if (args[i]) break;
  23727. }
  23728. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  23729. }
  23730. const defaultFallback = createSimpleExpression(`undefined`, false);
  23731. const trackSlotScopes = (node, context) => {
  23732. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  23733. const vSlot = findDir(node, "slot");
  23734. if (vSlot) {
  23735. const slotProps = vSlot.exp;
  23736. if (context.prefixIdentifiers) {
  23737. slotProps && context.addIdentifiers(slotProps);
  23738. }
  23739. context.scopes.vSlot++;
  23740. return () => {
  23741. if (context.prefixIdentifiers) {
  23742. slotProps && context.removeIdentifiers(slotProps);
  23743. }
  23744. context.scopes.vSlot--;
  23745. };
  23746. }
  23747. }
  23748. };
  23749. const trackVForSlotScopes = (node, context) => {
  23750. let vFor;
  23751. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  23752. const result = vFor.forParseResult;
  23753. if (result) {
  23754. finalizeForParseResult(result, context);
  23755. const { value, key, index } = result;
  23756. const { addIdentifiers, removeIdentifiers } = context;
  23757. value && addIdentifiers(value);
  23758. key && addIdentifiers(key);
  23759. index && addIdentifiers(index);
  23760. return () => {
  23761. value && removeIdentifiers(value);
  23762. key && removeIdentifiers(key);
  23763. index && removeIdentifiers(index);
  23764. };
  23765. }
  23766. }
  23767. };
  23768. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  23769. props,
  23770. children,
  23771. false,
  23772. true,
  23773. children.length ? children[0].loc : loc
  23774. );
  23775. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  23776. context.helper(WITH_CTX);
  23777. const { children, loc } = node;
  23778. const slotsProperties = [];
  23779. const dynamicSlots = [];
  23780. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  23781. if (!context.ssr && context.prefixIdentifiers) {
  23782. hasDynamicSlots = hasScopeRef(node, context.identifiers);
  23783. }
  23784. const onComponentSlot = findDir(node, "slot", true);
  23785. if (onComponentSlot) {
  23786. const { arg, exp } = onComponentSlot;
  23787. if (arg && !isStaticExp(arg)) {
  23788. hasDynamicSlots = true;
  23789. }
  23790. slotsProperties.push(
  23791. createObjectProperty(
  23792. arg || createSimpleExpression("default", true),
  23793. buildSlotFn(exp, void 0, children, loc)
  23794. )
  23795. );
  23796. }
  23797. let hasTemplateSlots = false;
  23798. let hasNamedDefaultSlot = false;
  23799. const implicitDefaultChildren = [];
  23800. const seenSlotNames = /* @__PURE__ */ new Set();
  23801. let conditionalBranchIndex = 0;
  23802. for (let i = 0; i < children.length; i++) {
  23803. const slotElement = children[i];
  23804. let slotDir;
  23805. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  23806. if (slotElement.type !== 3) {
  23807. implicitDefaultChildren.push(slotElement);
  23808. }
  23809. continue;
  23810. }
  23811. if (onComponentSlot) {
  23812. context.onError(
  23813. createCompilerError(37, slotDir.loc)
  23814. );
  23815. break;
  23816. }
  23817. hasTemplateSlots = true;
  23818. const { children: slotChildren, loc: slotLoc } = slotElement;
  23819. const {
  23820. arg: slotName = createSimpleExpression(`default`, true),
  23821. exp: slotProps,
  23822. loc: dirLoc
  23823. } = slotDir;
  23824. let staticSlotName;
  23825. if (isStaticExp(slotName)) {
  23826. staticSlotName = slotName ? slotName.content : `default`;
  23827. } else {
  23828. hasDynamicSlots = true;
  23829. }
  23830. const vFor = findDir(slotElement, "for");
  23831. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  23832. let vIf;
  23833. let vElse;
  23834. if (vIf = findDir(slotElement, "if")) {
  23835. hasDynamicSlots = true;
  23836. dynamicSlots.push(
  23837. createConditionalExpression(
  23838. vIf.exp,
  23839. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  23840. defaultFallback
  23841. )
  23842. );
  23843. } else if (vElse = findDir(
  23844. slotElement,
  23845. /^else(-if)?$/,
  23846. true
  23847. /* allowEmpty */
  23848. )) {
  23849. let j = i;
  23850. let prev;
  23851. while (j--) {
  23852. prev = children[j];
  23853. if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
  23854. break;
  23855. }
  23856. }
  23857. if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
  23858. let conditional = dynamicSlots[dynamicSlots.length - 1];
  23859. while (conditional.alternate.type === 19) {
  23860. conditional = conditional.alternate;
  23861. }
  23862. conditional.alternate = vElse.exp ? createConditionalExpression(
  23863. vElse.exp,
  23864. buildDynamicSlot(
  23865. slotName,
  23866. slotFunction,
  23867. conditionalBranchIndex++
  23868. ),
  23869. defaultFallback
  23870. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  23871. } else {
  23872. context.onError(
  23873. createCompilerError(30, vElse.loc)
  23874. );
  23875. }
  23876. } else if (vFor) {
  23877. hasDynamicSlots = true;
  23878. const parseResult = vFor.forParseResult;
  23879. if (parseResult) {
  23880. finalizeForParseResult(parseResult, context);
  23881. dynamicSlots.push(
  23882. createCallExpression(context.helper(RENDER_LIST), [
  23883. parseResult.source,
  23884. createFunctionExpression(
  23885. createForLoopParams(parseResult),
  23886. buildDynamicSlot(slotName, slotFunction),
  23887. true
  23888. )
  23889. ])
  23890. );
  23891. } else {
  23892. context.onError(
  23893. createCompilerError(
  23894. 32,
  23895. vFor.loc
  23896. )
  23897. );
  23898. }
  23899. } else {
  23900. if (staticSlotName) {
  23901. if (seenSlotNames.has(staticSlotName)) {
  23902. context.onError(
  23903. createCompilerError(
  23904. 38,
  23905. dirLoc
  23906. )
  23907. );
  23908. continue;
  23909. }
  23910. seenSlotNames.add(staticSlotName);
  23911. if (staticSlotName === "default") {
  23912. hasNamedDefaultSlot = true;
  23913. }
  23914. }
  23915. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  23916. }
  23917. }
  23918. if (!onComponentSlot) {
  23919. const buildDefaultSlotProperty = (props, children2) => {
  23920. const fn = buildSlotFn(props, void 0, children2, loc);
  23921. return createObjectProperty(`default`, fn);
  23922. };
  23923. if (!hasTemplateSlots) {
  23924. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  23925. } else if (implicitDefaultChildren.length && // #3766
  23926. // with whitespace: 'preserve', whitespaces between slots will end up in
  23927. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  23928. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  23929. if (hasNamedDefaultSlot) {
  23930. context.onError(
  23931. createCompilerError(
  23932. 39,
  23933. implicitDefaultChildren[0].loc
  23934. )
  23935. );
  23936. } else {
  23937. slotsProperties.push(
  23938. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  23939. );
  23940. }
  23941. }
  23942. }
  23943. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  23944. let slots = createObjectExpression(
  23945. slotsProperties.concat(
  23946. createObjectProperty(
  23947. `_`,
  23948. // 2 = compiled but dynamic = can skip normalization, but must run diff
  23949. // 1 = compiled and static = can skip normalization AND diff as optimized
  23950. createSimpleExpression(
  23951. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  23952. false
  23953. )
  23954. )
  23955. ),
  23956. loc
  23957. );
  23958. if (dynamicSlots.length) {
  23959. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  23960. slots,
  23961. createArrayExpression(dynamicSlots)
  23962. ]);
  23963. }
  23964. return {
  23965. slots,
  23966. hasDynamicSlots
  23967. };
  23968. }
  23969. function buildDynamicSlot(name, fn, index) {
  23970. const props = [
  23971. createObjectProperty(`name`, name),
  23972. createObjectProperty(`fn`, fn)
  23973. ];
  23974. if (index != null) {
  23975. props.push(
  23976. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  23977. );
  23978. }
  23979. return createObjectExpression(props);
  23980. }
  23981. function hasForwardedSlots(children) {
  23982. for (let i = 0; i < children.length; i++) {
  23983. const child = children[i];
  23984. switch (child.type) {
  23985. case 1:
  23986. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  23987. return true;
  23988. }
  23989. break;
  23990. case 9:
  23991. if (hasForwardedSlots(child.branches)) return true;
  23992. break;
  23993. case 10:
  23994. case 11:
  23995. if (hasForwardedSlots(child.children)) return true;
  23996. break;
  23997. }
  23998. }
  23999. return false;
  24000. }
  24001. function isNonWhitespaceContent(node) {
  24002. if (node.type !== 2 && node.type !== 12)
  24003. return true;
  24004. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  24005. }
  24006. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  24007. const transformElement = (node, context) => {
  24008. return function postTransformElement() {
  24009. node = context.currentNode;
  24010. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  24011. return;
  24012. }
  24013. const { tag, props } = node;
  24014. const isComponent = node.tagType === 1;
  24015. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  24016. const isDynamicComponent = isObject$2(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  24017. let vnodeProps;
  24018. let vnodeChildren;
  24019. let patchFlag = 0;
  24020. let vnodeDynamicProps;
  24021. let dynamicPropNames;
  24022. let vnodeDirectives;
  24023. let shouldUseBlock = (
  24024. // dynamic component may resolve to plain elements
  24025. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  24026. // updates inside get proper isSVG flag at runtime. (#639, #643)
  24027. // This is technically web-specific, but splitting the logic out of core
  24028. // leads to too much unnecessary complexity.
  24029. (tag === "svg" || tag === "foreignObject" || tag === "math")
  24030. );
  24031. if (props.length > 0) {
  24032. const propsBuildResult = buildProps(
  24033. node,
  24034. context,
  24035. void 0,
  24036. isComponent,
  24037. isDynamicComponent
  24038. );
  24039. vnodeProps = propsBuildResult.props;
  24040. patchFlag = propsBuildResult.patchFlag;
  24041. dynamicPropNames = propsBuildResult.dynamicPropNames;
  24042. const directives = propsBuildResult.directives;
  24043. vnodeDirectives = directives && directives.length ? createArrayExpression(
  24044. directives.map((dir) => buildDirectiveArgs(dir, context))
  24045. ) : void 0;
  24046. if (propsBuildResult.shouldUseBlock) {
  24047. shouldUseBlock = true;
  24048. }
  24049. }
  24050. if (node.children.length > 0) {
  24051. if (vnodeTag === KEEP_ALIVE) {
  24052. shouldUseBlock = true;
  24053. patchFlag |= 1024;
  24054. if (node.children.length > 1) {
  24055. context.onError(
  24056. createCompilerError(46, {
  24057. start: node.children[0].loc.start,
  24058. end: node.children[node.children.length - 1].loc.end,
  24059. source: ""
  24060. })
  24061. );
  24062. }
  24063. }
  24064. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  24065. vnodeTag !== TELEPORT && // explained above.
  24066. vnodeTag !== KEEP_ALIVE;
  24067. if (shouldBuildAsSlots) {
  24068. const { slots, hasDynamicSlots } = buildSlots(node, context);
  24069. vnodeChildren = slots;
  24070. if (hasDynamicSlots) {
  24071. patchFlag |= 1024;
  24072. }
  24073. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  24074. const child = node.children[0];
  24075. const type = child.type;
  24076. const hasDynamicTextChild = type === 5 || type === 8;
  24077. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  24078. patchFlag |= 1;
  24079. }
  24080. if (hasDynamicTextChild || type === 2) {
  24081. vnodeChildren = child;
  24082. } else {
  24083. vnodeChildren = node.children;
  24084. }
  24085. } else {
  24086. vnodeChildren = node.children;
  24087. }
  24088. }
  24089. if (dynamicPropNames && dynamicPropNames.length) {
  24090. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  24091. }
  24092. node.codegenNode = createVNodeCall(
  24093. context,
  24094. vnodeTag,
  24095. vnodeProps,
  24096. vnodeChildren,
  24097. patchFlag === 0 ? void 0 : patchFlag,
  24098. vnodeDynamicProps,
  24099. vnodeDirectives,
  24100. !!shouldUseBlock,
  24101. false,
  24102. isComponent,
  24103. node.loc
  24104. );
  24105. };
  24106. };
  24107. function resolveComponentType(node, context, ssr = false) {
  24108. let { tag } = node;
  24109. const isExplicitDynamic = isComponentTag(tag);
  24110. const isProp = findProp(
  24111. node,
  24112. "is",
  24113. false,
  24114. true
  24115. /* allow empty */
  24116. );
  24117. if (isProp) {
  24118. if (isExplicitDynamic || false) {
  24119. let exp;
  24120. if (isProp.type === 6) {
  24121. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  24122. } else {
  24123. exp = isProp.exp;
  24124. if (!exp) {
  24125. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  24126. {
  24127. exp = isProp.exp = processExpression(exp, context);
  24128. }
  24129. }
  24130. }
  24131. if (exp) {
  24132. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  24133. exp
  24134. ]);
  24135. }
  24136. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  24137. tag = isProp.value.content.slice(4);
  24138. }
  24139. }
  24140. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  24141. if (builtIn) {
  24142. if (!ssr) context.helper(builtIn);
  24143. return builtIn;
  24144. }
  24145. {
  24146. const fromSetup = resolveSetupReference(tag, context);
  24147. if (fromSetup) {
  24148. return fromSetup;
  24149. }
  24150. const dotIndex = tag.indexOf(".");
  24151. if (dotIndex > 0) {
  24152. const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
  24153. if (ns) {
  24154. return ns + tag.slice(dotIndex);
  24155. }
  24156. }
  24157. }
  24158. if (context.selfName && capitalize(camelize(tag)) === context.selfName) {
  24159. context.helper(RESOLVE_COMPONENT);
  24160. context.components.add(tag + `__self`);
  24161. return toValidAssetId(tag, `component`);
  24162. }
  24163. context.helper(RESOLVE_COMPONENT);
  24164. context.components.add(tag);
  24165. return toValidAssetId(tag, `component`);
  24166. }
  24167. function resolveSetupReference(name, context) {
  24168. const bindings = context.bindingMetadata;
  24169. if (!bindings || bindings.__isScriptSetup === false) {
  24170. return;
  24171. }
  24172. const camelName = camelize(name);
  24173. const PascalName = capitalize(camelName);
  24174. const checkType = (type) => {
  24175. if (bindings[name] === type) {
  24176. return name;
  24177. }
  24178. if (bindings[camelName] === type) {
  24179. return camelName;
  24180. }
  24181. if (bindings[PascalName] === type) {
  24182. return PascalName;
  24183. }
  24184. };
  24185. const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
  24186. if (fromConst) {
  24187. return context.inline ? (
  24188. // in inline mode, const setup bindings (e.g. imports) can be used as-is
  24189. fromConst
  24190. ) : `$setup[${JSON.stringify(fromConst)}]`;
  24191. }
  24192. const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
  24193. if (fromMaybeRef) {
  24194. return context.inline ? (
  24195. // setup scope bindings that may be refs need to be unrefed
  24196. `${context.helperString(UNREF)}(${fromMaybeRef})`
  24197. ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
  24198. }
  24199. const fromProps = checkType("props");
  24200. if (fromProps) {
  24201. return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
  24202. }
  24203. }
  24204. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  24205. const { tag, loc: elementLoc, children } = node;
  24206. let properties = [];
  24207. const mergeArgs = [];
  24208. const runtimeDirectives = [];
  24209. const hasChildren = children.length > 0;
  24210. let shouldUseBlock = false;
  24211. let patchFlag = 0;
  24212. let hasRef = false;
  24213. let hasClassBinding = false;
  24214. let hasStyleBinding = false;
  24215. let hasHydrationEventBinding = false;
  24216. let hasDynamicKeys = false;
  24217. let hasVnodeHook = false;
  24218. const dynamicPropNames = [];
  24219. const pushMergeArg = (arg) => {
  24220. if (properties.length) {
  24221. mergeArgs.push(
  24222. createObjectExpression(dedupeProperties(properties), elementLoc)
  24223. );
  24224. properties = [];
  24225. }
  24226. if (arg) mergeArgs.push(arg);
  24227. };
  24228. const pushRefVForMarker = () => {
  24229. if (context.scopes.vFor > 0) {
  24230. properties.push(
  24231. createObjectProperty(
  24232. createSimpleExpression("ref_for", true),
  24233. createSimpleExpression("true")
  24234. )
  24235. );
  24236. }
  24237. };
  24238. const analyzePatchFlag = ({ key, value }) => {
  24239. if (isStaticExp(key)) {
  24240. const name = key.content;
  24241. const isEventHandler = isOn(name);
  24242. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  24243. // dedicated fast path.
  24244. name.toLowerCase() !== "onclick" && // omit v-model handlers
  24245. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  24246. !isReservedProp(name)) {
  24247. hasHydrationEventBinding = true;
  24248. }
  24249. if (isEventHandler && isReservedProp(name)) {
  24250. hasVnodeHook = true;
  24251. }
  24252. if (isEventHandler && value.type === 14) {
  24253. value = value.arguments[0];
  24254. }
  24255. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  24256. return;
  24257. }
  24258. if (name === "ref") {
  24259. hasRef = true;
  24260. } else if (name === "class") {
  24261. hasClassBinding = true;
  24262. } else if (name === "style") {
  24263. hasStyleBinding = true;
  24264. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  24265. dynamicPropNames.push(name);
  24266. }
  24267. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  24268. dynamicPropNames.push(name);
  24269. }
  24270. } else {
  24271. hasDynamicKeys = true;
  24272. }
  24273. };
  24274. for (let i = 0; i < props.length; i++) {
  24275. const prop = props[i];
  24276. if (prop.type === 6) {
  24277. const { loc, name, nameLoc, value } = prop;
  24278. let isStatic = true;
  24279. if (name === "ref") {
  24280. hasRef = true;
  24281. pushRefVForMarker();
  24282. if (value && context.inline) {
  24283. const binding = context.bindingMetadata[value.content];
  24284. if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
  24285. isStatic = false;
  24286. properties.push(
  24287. createObjectProperty(
  24288. createSimpleExpression("ref_key", true),
  24289. createSimpleExpression(value.content, true, value.loc)
  24290. )
  24291. );
  24292. }
  24293. }
  24294. }
  24295. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || false)) {
  24296. continue;
  24297. }
  24298. properties.push(
  24299. createObjectProperty(
  24300. createSimpleExpression(name, true, nameLoc),
  24301. createSimpleExpression(
  24302. value ? value.content : "",
  24303. isStatic,
  24304. value ? value.loc : loc
  24305. )
  24306. )
  24307. );
  24308. } else {
  24309. const { name, arg, exp, loc, modifiers } = prop;
  24310. const isVBind = name === "bind";
  24311. const isVOn = name === "on";
  24312. if (name === "slot") {
  24313. if (!isComponent) {
  24314. context.onError(
  24315. createCompilerError(40, loc)
  24316. );
  24317. }
  24318. continue;
  24319. }
  24320. if (name === "once" || name === "memo") {
  24321. continue;
  24322. }
  24323. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || false)) {
  24324. continue;
  24325. }
  24326. if (isVOn && ssr) {
  24327. continue;
  24328. }
  24329. if (
  24330. // #938: elements with dynamic keys should be forced into blocks
  24331. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  24332. // before children
  24333. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  24334. ) {
  24335. shouldUseBlock = true;
  24336. }
  24337. if (isVBind && isStaticArgOf(arg, "ref")) {
  24338. pushRefVForMarker();
  24339. }
  24340. if (!arg && (isVBind || isVOn)) {
  24341. hasDynamicKeys = true;
  24342. if (exp) {
  24343. if (isVBind) {
  24344. pushRefVForMarker();
  24345. pushMergeArg();
  24346. mergeArgs.push(exp);
  24347. } else {
  24348. pushMergeArg({
  24349. type: 14,
  24350. loc,
  24351. callee: context.helper(TO_HANDLERS),
  24352. arguments: isComponent ? [exp] : [exp, `true`]
  24353. });
  24354. }
  24355. } else {
  24356. context.onError(
  24357. createCompilerError(
  24358. isVBind ? 34 : 35,
  24359. loc
  24360. )
  24361. );
  24362. }
  24363. continue;
  24364. }
  24365. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  24366. patchFlag |= 32;
  24367. }
  24368. const directiveTransform = context.directiveTransforms[name];
  24369. if (directiveTransform) {
  24370. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  24371. !ssr && props2.forEach(analyzePatchFlag);
  24372. if (isVOn && arg && !isStaticExp(arg)) {
  24373. pushMergeArg(createObjectExpression(props2, elementLoc));
  24374. } else {
  24375. properties.push(...props2);
  24376. }
  24377. if (needRuntime) {
  24378. runtimeDirectives.push(prop);
  24379. if (isSymbol$1(needRuntime)) {
  24380. directiveImportMap.set(prop, needRuntime);
  24381. }
  24382. }
  24383. } else if (!isBuiltInDirective(name)) {
  24384. runtimeDirectives.push(prop);
  24385. if (hasChildren) {
  24386. shouldUseBlock = true;
  24387. }
  24388. }
  24389. }
  24390. }
  24391. let propsExpression = void 0;
  24392. if (mergeArgs.length) {
  24393. pushMergeArg();
  24394. if (mergeArgs.length > 1) {
  24395. propsExpression = createCallExpression(
  24396. context.helper(MERGE_PROPS),
  24397. mergeArgs,
  24398. elementLoc
  24399. );
  24400. } else {
  24401. propsExpression = mergeArgs[0];
  24402. }
  24403. } else if (properties.length) {
  24404. propsExpression = createObjectExpression(
  24405. dedupeProperties(properties),
  24406. elementLoc
  24407. );
  24408. }
  24409. if (hasDynamicKeys) {
  24410. patchFlag |= 16;
  24411. } else {
  24412. if (hasClassBinding && !isComponent) {
  24413. patchFlag |= 2;
  24414. }
  24415. if (hasStyleBinding && !isComponent) {
  24416. patchFlag |= 4;
  24417. }
  24418. if (dynamicPropNames.length) {
  24419. patchFlag |= 8;
  24420. }
  24421. if (hasHydrationEventBinding) {
  24422. patchFlag |= 32;
  24423. }
  24424. }
  24425. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  24426. patchFlag |= 512;
  24427. }
  24428. if (!context.inSSR && propsExpression) {
  24429. switch (propsExpression.type) {
  24430. case 15:
  24431. let classKeyIndex = -1;
  24432. let styleKeyIndex = -1;
  24433. let hasDynamicKey = false;
  24434. for (let i = 0; i < propsExpression.properties.length; i++) {
  24435. const key = propsExpression.properties[i].key;
  24436. if (isStaticExp(key)) {
  24437. if (key.content === "class") {
  24438. classKeyIndex = i;
  24439. } else if (key.content === "style") {
  24440. styleKeyIndex = i;
  24441. }
  24442. } else if (!key.isHandlerKey) {
  24443. hasDynamicKey = true;
  24444. }
  24445. }
  24446. const classProp = propsExpression.properties[classKeyIndex];
  24447. const styleProp = propsExpression.properties[styleKeyIndex];
  24448. if (!hasDynamicKey) {
  24449. if (classProp && !isStaticExp(classProp.value)) {
  24450. classProp.value = createCallExpression(
  24451. context.helper(NORMALIZE_CLASS),
  24452. [classProp.value]
  24453. );
  24454. }
  24455. if (styleProp && // the static style is compiled into an object,
  24456. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  24457. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  24458. // v-bind:style with static literal object
  24459. styleProp.value.type === 17)) {
  24460. styleProp.value = createCallExpression(
  24461. context.helper(NORMALIZE_STYLE),
  24462. [styleProp.value]
  24463. );
  24464. }
  24465. } else {
  24466. propsExpression = createCallExpression(
  24467. context.helper(NORMALIZE_PROPS),
  24468. [propsExpression]
  24469. );
  24470. }
  24471. break;
  24472. case 14:
  24473. break;
  24474. default:
  24475. propsExpression = createCallExpression(
  24476. context.helper(NORMALIZE_PROPS),
  24477. [
  24478. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  24479. propsExpression
  24480. ])
  24481. ]
  24482. );
  24483. break;
  24484. }
  24485. }
  24486. return {
  24487. props: propsExpression,
  24488. directives: runtimeDirectives,
  24489. patchFlag,
  24490. dynamicPropNames,
  24491. shouldUseBlock
  24492. };
  24493. }
  24494. function dedupeProperties(properties) {
  24495. const knownProps = /* @__PURE__ */ new Map();
  24496. const deduped = [];
  24497. for (let i = 0; i < properties.length; i++) {
  24498. const prop = properties[i];
  24499. if (prop.key.type === 8 || !prop.key.isStatic) {
  24500. deduped.push(prop);
  24501. continue;
  24502. }
  24503. const name = prop.key.content;
  24504. const existing = knownProps.get(name);
  24505. if (existing) {
  24506. if (name === "style" || name === "class" || isOn(name)) {
  24507. mergeAsArray(existing, prop);
  24508. }
  24509. } else {
  24510. knownProps.set(name, prop);
  24511. deduped.push(prop);
  24512. }
  24513. }
  24514. return deduped;
  24515. }
  24516. function mergeAsArray(existing, incoming) {
  24517. if (existing.value.type === 17) {
  24518. existing.value.elements.push(incoming.value);
  24519. } else {
  24520. existing.value = createArrayExpression(
  24521. [existing.value, incoming.value],
  24522. existing.loc
  24523. );
  24524. }
  24525. }
  24526. function buildDirectiveArgs(dir, context) {
  24527. const dirArgs = [];
  24528. const runtime = directiveImportMap.get(dir);
  24529. if (runtime) {
  24530. dirArgs.push(context.helperString(runtime));
  24531. } else {
  24532. const fromSetup = resolveSetupReference("v-" + dir.name, context);
  24533. if (fromSetup) {
  24534. dirArgs.push(fromSetup);
  24535. } else {
  24536. context.helper(RESOLVE_DIRECTIVE);
  24537. context.directives.add(dir.name);
  24538. dirArgs.push(toValidAssetId(dir.name, `directive`));
  24539. }
  24540. }
  24541. const { loc } = dir;
  24542. if (dir.exp) dirArgs.push(dir.exp);
  24543. if (dir.arg) {
  24544. if (!dir.exp) {
  24545. dirArgs.push(`void 0`);
  24546. }
  24547. dirArgs.push(dir.arg);
  24548. }
  24549. if (Object.keys(dir.modifiers).length) {
  24550. if (!dir.arg) {
  24551. if (!dir.exp) {
  24552. dirArgs.push(`void 0`);
  24553. }
  24554. dirArgs.push(`void 0`);
  24555. }
  24556. const trueExpression = createSimpleExpression(`true`, false, loc);
  24557. dirArgs.push(
  24558. createObjectExpression(
  24559. dir.modifiers.map(
  24560. (modifier) => createObjectProperty(modifier, trueExpression)
  24561. ),
  24562. loc
  24563. )
  24564. );
  24565. }
  24566. return createArrayExpression(dirArgs, dir.loc);
  24567. }
  24568. function stringifyDynamicPropNames(props) {
  24569. let propsNamesString = `[`;
  24570. for (let i = 0, l = props.length; i < l; i++) {
  24571. propsNamesString += JSON.stringify(props[i]);
  24572. if (i < l - 1) propsNamesString += ", ";
  24573. }
  24574. return propsNamesString + `]`;
  24575. }
  24576. function isComponentTag(tag) {
  24577. return tag === "component" || tag === "Component";
  24578. }
  24579. const transformSlotOutlet = (node, context) => {
  24580. if (isSlotOutlet(node)) {
  24581. const { children, loc } = node;
  24582. const { slotName, slotProps } = processSlotOutlet(node, context);
  24583. const slotArgs = [
  24584. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  24585. slotName,
  24586. "{}",
  24587. "undefined",
  24588. "true"
  24589. ];
  24590. let expectedLen = 2;
  24591. if (slotProps) {
  24592. slotArgs[2] = slotProps;
  24593. expectedLen = 3;
  24594. }
  24595. if (children.length) {
  24596. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  24597. expectedLen = 4;
  24598. }
  24599. if (context.scopeId && !context.slotted) {
  24600. expectedLen = 5;
  24601. }
  24602. slotArgs.splice(expectedLen);
  24603. node.codegenNode = createCallExpression(
  24604. context.helper(RENDER_SLOT),
  24605. slotArgs,
  24606. loc
  24607. );
  24608. }
  24609. };
  24610. function processSlotOutlet(node, context) {
  24611. let slotName = `"default"`;
  24612. let slotProps = void 0;
  24613. const nonNameProps = [];
  24614. for (let i = 0; i < node.props.length; i++) {
  24615. const p = node.props[i];
  24616. if (p.type === 6) {
  24617. if (p.value) {
  24618. if (p.name === "name") {
  24619. slotName = JSON.stringify(p.value.content);
  24620. } else {
  24621. p.name = camelize(p.name);
  24622. nonNameProps.push(p);
  24623. }
  24624. }
  24625. } else {
  24626. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  24627. if (p.exp) {
  24628. slotName = p.exp;
  24629. } else if (p.arg && p.arg.type === 4) {
  24630. const name = camelize(p.arg.content);
  24631. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  24632. {
  24633. slotName = p.exp = processExpression(p.exp, context);
  24634. }
  24635. }
  24636. } else {
  24637. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  24638. p.arg.content = camelize(p.arg.content);
  24639. }
  24640. nonNameProps.push(p);
  24641. }
  24642. }
  24643. }
  24644. if (nonNameProps.length > 0) {
  24645. const { props, directives } = buildProps(
  24646. node,
  24647. context,
  24648. nonNameProps,
  24649. false,
  24650. false
  24651. );
  24652. slotProps = props;
  24653. if (directives.length) {
  24654. context.onError(
  24655. createCompilerError(
  24656. 36,
  24657. directives[0].loc
  24658. )
  24659. );
  24660. }
  24661. }
  24662. return {
  24663. slotName,
  24664. slotProps
  24665. };
  24666. }
  24667. const transformOn$1 = (dir, node, context, augmentor) => {
  24668. const { loc, modifiers, arg } = dir;
  24669. if (!dir.exp && !modifiers.length) {
  24670. context.onError(createCompilerError(35, loc));
  24671. }
  24672. let eventName;
  24673. if (arg.type === 4) {
  24674. if (arg.isStatic) {
  24675. let rawName = arg.content;
  24676. if (rawName.startsWith("vnode")) {
  24677. context.onError(createCompilerError(51, arg.loc));
  24678. }
  24679. if (rawName.startsWith("vue:")) {
  24680. rawName = `vnode-${rawName.slice(4)}`;
  24681. }
  24682. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  24683. // for non-element and vnode lifecycle event listeners, auto convert
  24684. // it to camelCase. See issue #2249
  24685. toHandlerKey(camelize(rawName))
  24686. ) : (
  24687. // preserve case for plain element listeners that have uppercase
  24688. // letters, as these may be custom elements' custom events
  24689. `on:${rawName}`
  24690. );
  24691. eventName = createSimpleExpression(eventString, true, arg.loc);
  24692. } else {
  24693. eventName = createCompoundExpression([
  24694. `${context.helperString(TO_HANDLER_KEY)}(`,
  24695. arg,
  24696. `)`
  24697. ]);
  24698. }
  24699. } else {
  24700. eventName = arg;
  24701. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  24702. eventName.children.push(`)`);
  24703. }
  24704. let exp = dir.exp;
  24705. if (exp && !exp.content.trim()) {
  24706. exp = void 0;
  24707. }
  24708. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  24709. if (exp) {
  24710. const isMemberExp = isMemberExpression(exp, context);
  24711. const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
  24712. const hasMultipleStatements = exp.content.includes(`;`);
  24713. if (context.prefixIdentifiers) {
  24714. isInlineStatement && context.addIdentifiers(`$event`);
  24715. exp = dir.exp = processExpression(
  24716. exp,
  24717. context,
  24718. false,
  24719. hasMultipleStatements
  24720. );
  24721. isInlineStatement && context.removeIdentifiers(`$event`);
  24722. shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
  24723. !context.inVOnce && // runtime constants don't need to be cached
  24724. // (this is analyzed by compileScript in SFC <script setup>)
  24725. !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
  24726. // we need to use the original function to preserve arity,
  24727. // e.g. <transition> relies on checking cb.length to determine
  24728. // transition end handling. Inline function is ok since its arity
  24729. // is preserved even when cached.
  24730. !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
  24731. // it must be passed fresh to avoid stale values.
  24732. !hasScopeRef(exp, context.identifiers);
  24733. if (shouldCache && isMemberExp) {
  24734. if (exp.type === 4) {
  24735. exp.content = `${exp.content} && ${exp.content}(...args)`;
  24736. } else {
  24737. exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
  24738. }
  24739. }
  24740. }
  24741. if (isInlineStatement || shouldCache && isMemberExp) {
  24742. exp = createCompoundExpression([
  24743. `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
  24744. //@ts-ignore
  24745. ` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  24746. exp,
  24747. hasMultipleStatements ? `}` : `)`
  24748. ]);
  24749. }
  24750. }
  24751. let ret = {
  24752. props: [
  24753. createObjectProperty(
  24754. eventName,
  24755. exp || createSimpleExpression(`() => {}`, false, loc)
  24756. )
  24757. ]
  24758. };
  24759. if (augmentor) {
  24760. ret = augmentor(ret);
  24761. }
  24762. if (shouldCache) {
  24763. ret.props[0].value = context.cache(ret.props[0].value);
  24764. }
  24765. ret.props.forEach((p) => p.key.isHandlerKey = true);
  24766. return ret;
  24767. };
  24768. const transformText = (node, context) => {
  24769. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  24770. return () => {
  24771. const children = node.children;
  24772. let currentContainer = void 0;
  24773. let hasText = false;
  24774. for (let i = 0; i < children.length; i++) {
  24775. const child = children[i];
  24776. if (isText$1(child)) {
  24777. hasText = true;
  24778. for (let j = i + 1; j < children.length; j++) {
  24779. const next = children[j];
  24780. if (isText$1(next)) {
  24781. if (!currentContainer) {
  24782. currentContainer = children[i] = createCompoundExpression(
  24783. [child],
  24784. child.loc
  24785. );
  24786. }
  24787. currentContainer.children.push(` + `, next);
  24788. children.splice(j, 1);
  24789. j--;
  24790. } else {
  24791. currentContainer = void 0;
  24792. break;
  24793. }
  24794. }
  24795. }
  24796. }
  24797. if (!hasText || // if this is a plain element with a single text child, leave it
  24798. // as-is since the runtime has dedicated fast path for this by directly
  24799. // setting textContent of the element.
  24800. // for component root it's always normalized anyway.
  24801. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  24802. // custom directives can potentially add DOM elements arbitrarily,
  24803. // we need to avoid setting textContent of the element at runtime
  24804. // to avoid accidentally overwriting the DOM elements added
  24805. // by the user through custom directives.
  24806. !node.props.find(
  24807. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  24808. ) && // in compat mode, <template> tags with no special directives
  24809. // will be rendered as a fragment so its children must be
  24810. // converted into vnodes.
  24811. true)) {
  24812. return;
  24813. }
  24814. for (let i = 0; i < children.length; i++) {
  24815. const child = children[i];
  24816. if (isText$1(child) || child.type === 8) {
  24817. const callArgs = [];
  24818. if (child.type !== 2 || child.content !== " ") {
  24819. callArgs.push(child);
  24820. }
  24821. if (!context.ssr && getConstantType(child, context) === 0) {
  24822. callArgs.push(
  24823. 1 + (` /* ${PatchFlagNames[1]} */` )
  24824. );
  24825. }
  24826. children[i] = {
  24827. type: 12,
  24828. content: child,
  24829. loc: child.loc,
  24830. codegenNode: createCallExpression(
  24831. context.helper(CREATE_TEXT),
  24832. callArgs
  24833. )
  24834. };
  24835. }
  24836. }
  24837. };
  24838. }
  24839. };
  24840. const seen$1 = /* @__PURE__ */ new WeakSet();
  24841. const transformOnce = (node, context) => {
  24842. if (node.type === 1 && findDir(node, "once", true)) {
  24843. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  24844. return;
  24845. }
  24846. seen$1.add(node);
  24847. context.inVOnce = true;
  24848. context.helper(SET_BLOCK_TRACKING);
  24849. return () => {
  24850. context.inVOnce = false;
  24851. const cur = context.currentNode;
  24852. if (cur.codegenNode) {
  24853. cur.codegenNode = context.cache(
  24854. cur.codegenNode,
  24855. true,
  24856. true
  24857. );
  24858. }
  24859. };
  24860. }
  24861. };
  24862. const transformModel$1 = (dir, node, context) => {
  24863. const { exp, arg } = dir;
  24864. if (!exp) {
  24865. context.onError(
  24866. createCompilerError(41, dir.loc)
  24867. );
  24868. return createTransformProps();
  24869. }
  24870. const rawExp = exp.loc.source.trim();
  24871. const expString = exp.type === 4 ? exp.content : rawExp;
  24872. const bindingType = context.bindingMetadata[rawExp];
  24873. if (bindingType === "props" || bindingType === "props-aliased") {
  24874. context.onError(createCompilerError(44, exp.loc));
  24875. return createTransformProps();
  24876. }
  24877. const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
  24878. if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
  24879. context.onError(
  24880. createCompilerError(42, exp.loc)
  24881. );
  24882. return createTransformProps();
  24883. }
  24884. if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
  24885. context.onError(
  24886. createCompilerError(43, exp.loc)
  24887. );
  24888. return createTransformProps();
  24889. }
  24890. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  24891. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  24892. let assignmentExp;
  24893. const eventArg = context.isTS ? `($event: any)` : `$event`;
  24894. if (maybeRef) {
  24895. if (bindingType === "setup-ref") {
  24896. assignmentExp = createCompoundExpression([
  24897. `${eventArg} => ((`,
  24898. createSimpleExpression(rawExp, false, exp.loc),
  24899. `).value = $event)`
  24900. ]);
  24901. } else {
  24902. const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
  24903. assignmentExp = createCompoundExpression([
  24904. `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
  24905. createSimpleExpression(rawExp, false, exp.loc),
  24906. `).value = $event : ${altAssignment})`
  24907. ]);
  24908. }
  24909. } else {
  24910. assignmentExp = createCompoundExpression([
  24911. `${eventArg} => ((`,
  24912. exp,
  24913. `) = $event)`
  24914. ]);
  24915. }
  24916. const props = [
  24917. // modelValue: foo
  24918. createObjectProperty(propName, dir.exp),
  24919. // "onUpdate:modelValue": $event => (foo = $event)
  24920. createObjectProperty(eventName, assignmentExp)
  24921. ];
  24922. if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
  24923. props[1].value = context.cache(props[1].value);
  24924. }
  24925. if (dir.modifiers.length && node.tagType === 1) {
  24926. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  24927. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  24928. props.push(
  24929. createObjectProperty(
  24930. modifiersKey,
  24931. createSimpleExpression(
  24932. `{ ${modifiers} }`,
  24933. false,
  24934. dir.loc,
  24935. 2
  24936. )
  24937. )
  24938. );
  24939. }
  24940. return createTransformProps(props);
  24941. };
  24942. function createTransformProps(props = []) {
  24943. return { props };
  24944. }
  24945. const seen = /* @__PURE__ */ new WeakSet();
  24946. const transformMemo = (node, context) => {
  24947. if (node.type === 1) {
  24948. const dir = findDir(node, "memo");
  24949. if (!dir || seen.has(node)) {
  24950. return;
  24951. }
  24952. seen.add(node);
  24953. return () => {
  24954. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  24955. if (codegenNode && codegenNode.type === 13) {
  24956. if (node.tagType !== 1) {
  24957. convertToBlock(codegenNode, context);
  24958. }
  24959. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  24960. dir.exp,
  24961. createFunctionExpression(void 0, codegenNode),
  24962. `_cache`,
  24963. String(context.cached.length)
  24964. ]);
  24965. context.cached.push(null);
  24966. }
  24967. };
  24968. }
  24969. };
  24970. function getBaseTransformPreset(prefixIdentifiers) {
  24971. return [
  24972. [
  24973. transformOnce,
  24974. transformIf,
  24975. transformMemo,
  24976. transformFor,
  24977. ...[],
  24978. ...prefixIdentifiers ? [
  24979. // order is important
  24980. trackVForSlotScopes,
  24981. transformExpression
  24982. ] : [],
  24983. transformSlotOutlet,
  24984. transformElement,
  24985. trackSlotScopes,
  24986. transformText
  24987. ],
  24988. {
  24989. on: transformOn$1,
  24990. bind: transformBind,
  24991. model: transformModel$1
  24992. }
  24993. ];
  24994. }
  24995. function baseCompile(source, options = {}) {
  24996. const onError = options.onError || defaultOnError;
  24997. const isModuleMode = options.mode === "module";
  24998. const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
  24999. if (!prefixIdentifiers && options.cacheHandlers) {
  25000. onError(createCompilerError(49));
  25001. }
  25002. if (options.scopeId && !isModuleMode) {
  25003. onError(createCompilerError(50));
  25004. }
  25005. const resolvedOptions = extend({}, options, {
  25006. prefixIdentifiers
  25007. });
  25008. const ast = isString$1(source) ? baseParse(source, resolvedOptions) : source;
  25009. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
  25010. if (options.isTS) {
  25011. const { expressionPlugins } = options;
  25012. if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
  25013. options.expressionPlugins = [...expressionPlugins || [], "typescript"];
  25014. }
  25015. }
  25016. transform(
  25017. ast,
  25018. extend({}, resolvedOptions, {
  25019. nodeTransforms: [
  25020. ...nodeTransforms,
  25021. ...options.nodeTransforms || []
  25022. // user transforms
  25023. ],
  25024. directiveTransforms: extend(
  25025. {},
  25026. directiveTransforms,
  25027. options.directiveTransforms || {}
  25028. // user transforms
  25029. )
  25030. })
  25031. );
  25032. return generate(ast, resolvedOptions);
  25033. }
  25034. const BindingTypes = {
  25035. "DATA": "data",
  25036. "PROPS": "props",
  25037. "PROPS_ALIASED": "props-aliased",
  25038. "SETUP_LET": "setup-let",
  25039. "SETUP_CONST": "setup-const",
  25040. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  25041. "SETUP_MAYBE_REF": "setup-maybe-ref",
  25042. "SETUP_REF": "setup-ref",
  25043. "OPTIONS": "options",
  25044. "LITERAL_CONST": "literal-const"
  25045. };
  25046. const noopDirectiveTransform = () => ({ props: [] });
  25047. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  25048. const V_MODEL_CHECKBOX = Symbol(
  25049. `vModelCheckbox`
  25050. );
  25051. const V_MODEL_TEXT = Symbol(`vModelText` );
  25052. const V_MODEL_SELECT = Symbol(
  25053. `vModelSelect`
  25054. );
  25055. const V_MODEL_DYNAMIC = Symbol(
  25056. `vModelDynamic`
  25057. );
  25058. const V_ON_WITH_MODIFIERS = Symbol(
  25059. `vOnModifiersGuard`
  25060. );
  25061. const V_ON_WITH_KEYS = Symbol(
  25062. `vOnKeysGuard`
  25063. );
  25064. const V_SHOW = Symbol(`vShow` );
  25065. const TRANSITION = Symbol(`Transition` );
  25066. const TRANSITION_GROUP = Symbol(
  25067. `TransitionGroup`
  25068. );
  25069. registerRuntimeHelpers({
  25070. [V_MODEL_RADIO]: `vModelRadio`,
  25071. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  25072. [V_MODEL_TEXT]: `vModelText`,
  25073. [V_MODEL_SELECT]: `vModelSelect`,
  25074. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  25075. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  25076. [V_ON_WITH_KEYS]: `withKeys`,
  25077. [V_SHOW]: `vShow`,
  25078. [TRANSITION]: `Transition`,
  25079. [TRANSITION_GROUP]: `TransitionGroup`
  25080. });
  25081. const parserOptions = {
  25082. parseMode: "html",
  25083. isVoidTag,
  25084. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  25085. isPreTag: (tag) => tag === "pre",
  25086. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  25087. decodeEntities: void 0,
  25088. isBuiltInComponent: (tag) => {
  25089. if (tag === "Transition" || tag === "transition") {
  25090. return TRANSITION;
  25091. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  25092. return TRANSITION_GROUP;
  25093. }
  25094. },
  25095. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  25096. getNamespace(tag, parent, rootNamespace) {
  25097. let ns = parent ? parent.ns : rootNamespace;
  25098. if (parent && ns === 2) {
  25099. if (parent.tag === "annotation-xml") {
  25100. if (tag === "svg") {
  25101. return 1;
  25102. }
  25103. if (parent.props.some(
  25104. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  25105. )) {
  25106. ns = 0;
  25107. }
  25108. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  25109. ns = 0;
  25110. }
  25111. } else if (parent && ns === 1) {
  25112. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  25113. ns = 0;
  25114. }
  25115. }
  25116. if (ns === 0) {
  25117. if (tag === "svg") {
  25118. return 1;
  25119. }
  25120. if (tag === "math") {
  25121. return 2;
  25122. }
  25123. }
  25124. return ns;
  25125. }
  25126. };
  25127. const transformStyle = (node) => {
  25128. if (node.type === 1) {
  25129. node.props.forEach((p, i) => {
  25130. if (p.type === 6 && p.name === "style" && p.value) {
  25131. node.props[i] = {
  25132. type: 7,
  25133. name: `bind`,
  25134. arg: createSimpleExpression(`style`, true, p.loc),
  25135. exp: parseInlineCSS(p.value.content, p.loc),
  25136. modifiers: [],
  25137. loc: p.loc
  25138. };
  25139. }
  25140. });
  25141. }
  25142. };
  25143. const parseInlineCSS = (cssText, loc) => {
  25144. const normalized = parseStringStyle(cssText);
  25145. return createSimpleExpression(
  25146. JSON.stringify(normalized),
  25147. false,
  25148. loc,
  25149. 3
  25150. );
  25151. };
  25152. function createDOMCompilerError(code, loc) {
  25153. return createCompilerError(
  25154. code,
  25155. loc,
  25156. DOMErrorMessages
  25157. );
  25158. }
  25159. const DOMErrorCodes = {
  25160. "X_V_HTML_NO_EXPRESSION": 53,
  25161. "53": "X_V_HTML_NO_EXPRESSION",
  25162. "X_V_HTML_WITH_CHILDREN": 54,
  25163. "54": "X_V_HTML_WITH_CHILDREN",
  25164. "X_V_TEXT_NO_EXPRESSION": 55,
  25165. "55": "X_V_TEXT_NO_EXPRESSION",
  25166. "X_V_TEXT_WITH_CHILDREN": 56,
  25167. "56": "X_V_TEXT_WITH_CHILDREN",
  25168. "X_V_MODEL_ON_INVALID_ELEMENT": 57,
  25169. "57": "X_V_MODEL_ON_INVALID_ELEMENT",
  25170. "X_V_MODEL_ARG_ON_ELEMENT": 58,
  25171. "58": "X_V_MODEL_ARG_ON_ELEMENT",
  25172. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
  25173. "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  25174. "X_V_MODEL_UNNECESSARY_VALUE": 60,
  25175. "60": "X_V_MODEL_UNNECESSARY_VALUE",
  25176. "X_V_SHOW_NO_EXPRESSION": 61,
  25177. "61": "X_V_SHOW_NO_EXPRESSION",
  25178. "X_TRANSITION_INVALID_CHILDREN": 62,
  25179. "62": "X_TRANSITION_INVALID_CHILDREN",
  25180. "X_IGNORED_SIDE_EFFECT_TAG": 63,
  25181. "63": "X_IGNORED_SIDE_EFFECT_TAG",
  25182. "__EXTEND_POINT__": 64,
  25183. "64": "__EXTEND_POINT__"
  25184. };
  25185. const DOMErrorMessages = {
  25186. [53]: `v-html is missing expression.`,
  25187. [54]: `v-html will override element children.`,
  25188. [55]: `v-text is missing expression.`,
  25189. [56]: `v-text will override element children.`,
  25190. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  25191. [58]: `v-model argument is not supported on plain elements.`,
  25192. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  25193. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  25194. [61]: `v-show is missing expression.`,
  25195. [62]: `<Transition> expects exactly one child element or component.`,
  25196. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  25197. };
  25198. const transformVHtml = (dir, node, context) => {
  25199. const { exp, loc } = dir;
  25200. if (!exp) {
  25201. context.onError(
  25202. createDOMCompilerError(53, loc)
  25203. );
  25204. }
  25205. if (node.children.length) {
  25206. context.onError(
  25207. createDOMCompilerError(54, loc)
  25208. );
  25209. node.children.length = 0;
  25210. }
  25211. return {
  25212. props: [
  25213. createObjectProperty(
  25214. createSimpleExpression(`innerHTML`, true, loc),
  25215. exp || createSimpleExpression("", true)
  25216. )
  25217. ]
  25218. };
  25219. };
  25220. const transformVText = (dir, node, context) => {
  25221. const { exp, loc } = dir;
  25222. if (!exp) {
  25223. context.onError(
  25224. createDOMCompilerError(55, loc)
  25225. );
  25226. }
  25227. if (node.children.length) {
  25228. context.onError(
  25229. createDOMCompilerError(56, loc)
  25230. );
  25231. node.children.length = 0;
  25232. }
  25233. return {
  25234. props: [
  25235. createObjectProperty(
  25236. createSimpleExpression(`textContent`, true),
  25237. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  25238. context.helperString(TO_DISPLAY_STRING),
  25239. [exp],
  25240. loc
  25241. ) : createSimpleExpression("", true)
  25242. )
  25243. ]
  25244. };
  25245. };
  25246. const transformModel = (dir, node, context) => {
  25247. const baseResult = transformModel$1(dir, node, context);
  25248. if (!baseResult.props.length || node.tagType === 1) {
  25249. return baseResult;
  25250. }
  25251. if (dir.arg) {
  25252. context.onError(
  25253. createDOMCompilerError(
  25254. 58,
  25255. dir.arg.loc
  25256. )
  25257. );
  25258. }
  25259. function checkDuplicatedValue() {
  25260. const value = findDir(node, "bind");
  25261. if (value && isStaticArgOf(value.arg, "value")) {
  25262. context.onError(
  25263. createDOMCompilerError(
  25264. 60,
  25265. value.loc
  25266. )
  25267. );
  25268. }
  25269. }
  25270. const { tag } = node;
  25271. const isCustomElement = context.isCustomElement(tag);
  25272. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  25273. let directiveToUse = V_MODEL_TEXT;
  25274. let isInvalidType = false;
  25275. if (tag === "input" || isCustomElement) {
  25276. const type = findProp(node, `type`);
  25277. if (type) {
  25278. if (type.type === 7) {
  25279. directiveToUse = V_MODEL_DYNAMIC;
  25280. } else if (type.value) {
  25281. switch (type.value.content) {
  25282. case "radio":
  25283. directiveToUse = V_MODEL_RADIO;
  25284. break;
  25285. case "checkbox":
  25286. directiveToUse = V_MODEL_CHECKBOX;
  25287. break;
  25288. case "file":
  25289. isInvalidType = true;
  25290. context.onError(
  25291. createDOMCompilerError(
  25292. 59,
  25293. dir.loc
  25294. )
  25295. );
  25296. break;
  25297. default:
  25298. checkDuplicatedValue();
  25299. break;
  25300. }
  25301. }
  25302. } else if (hasDynamicKeyVBind(node)) {
  25303. directiveToUse = V_MODEL_DYNAMIC;
  25304. } else {
  25305. checkDuplicatedValue();
  25306. }
  25307. } else if (tag === "select") {
  25308. directiveToUse = V_MODEL_SELECT;
  25309. } else {
  25310. checkDuplicatedValue();
  25311. }
  25312. if (!isInvalidType) {
  25313. baseResult.needRuntime = context.helper(directiveToUse);
  25314. }
  25315. } else {
  25316. context.onError(
  25317. createDOMCompilerError(
  25318. 57,
  25319. dir.loc
  25320. )
  25321. );
  25322. }
  25323. baseResult.props = baseResult.props.filter(
  25324. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  25325. );
  25326. return baseResult;
  25327. };
  25328. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  25329. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  25330. // event propagation management
  25331. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  25332. );
  25333. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  25334. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  25335. const resolveModifiers = (key, modifiers, context, loc) => {
  25336. const keyModifiers = [];
  25337. const nonKeyModifiers = [];
  25338. const eventOptionModifiers = [];
  25339. for (let i = 0; i < modifiers.length; i++) {
  25340. const modifier = modifiers[i].content;
  25341. if (isEventOptionModifier(modifier)) {
  25342. eventOptionModifiers.push(modifier);
  25343. } else {
  25344. if (maybeKeyModifier(modifier)) {
  25345. if (isStaticExp(key)) {
  25346. if (isKeyboardEvent(key.content.toLowerCase())) {
  25347. keyModifiers.push(modifier);
  25348. } else {
  25349. nonKeyModifiers.push(modifier);
  25350. }
  25351. } else {
  25352. keyModifiers.push(modifier);
  25353. nonKeyModifiers.push(modifier);
  25354. }
  25355. } else {
  25356. if (isNonKeyModifier(modifier)) {
  25357. nonKeyModifiers.push(modifier);
  25358. } else {
  25359. keyModifiers.push(modifier);
  25360. }
  25361. }
  25362. }
  25363. }
  25364. return {
  25365. keyModifiers,
  25366. nonKeyModifiers,
  25367. eventOptionModifiers
  25368. };
  25369. };
  25370. const transformClick = (key, event) => {
  25371. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  25372. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  25373. `(`,
  25374. key,
  25375. `) === "onClick" ? "${event}" : (`,
  25376. key,
  25377. `)`
  25378. ]) : key;
  25379. };
  25380. const transformOn = (dir, node, context) => {
  25381. return transformOn$1(dir, node, context, (baseResult) => {
  25382. const { modifiers } = dir;
  25383. if (!modifiers.length) return baseResult;
  25384. let { key, value: handlerExp } = baseResult.props[0];
  25385. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  25386. if (nonKeyModifiers.includes("right")) {
  25387. key = transformClick(key, `onContextmenu`);
  25388. }
  25389. if (nonKeyModifiers.includes("middle")) {
  25390. key = transformClick(key, `onMouseup`);
  25391. }
  25392. if (nonKeyModifiers.length) {
  25393. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  25394. handlerExp,
  25395. JSON.stringify(nonKeyModifiers)
  25396. ]);
  25397. }
  25398. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  25399. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  25400. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  25401. handlerExp,
  25402. JSON.stringify(keyModifiers)
  25403. ]);
  25404. }
  25405. if (eventOptionModifiers.length) {
  25406. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  25407. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  25408. }
  25409. return {
  25410. props: [createObjectProperty(key, handlerExp)]
  25411. };
  25412. });
  25413. };
  25414. const transformShow = (dir, node, context) => {
  25415. const { exp, loc } = dir;
  25416. if (!exp) {
  25417. context.onError(
  25418. createDOMCompilerError(61, loc)
  25419. );
  25420. }
  25421. return {
  25422. props: [],
  25423. needRuntime: context.helper(V_SHOW)
  25424. };
  25425. };
  25426. const transformTransition = (node, context) => {
  25427. if (node.type === 1 && node.tagType === 1) {
  25428. const component = context.isBuiltInComponent(node.tag);
  25429. if (component === TRANSITION) {
  25430. return () => {
  25431. if (!node.children.length) {
  25432. return;
  25433. }
  25434. if (hasMultipleChildren(node)) {
  25435. context.onError(
  25436. createDOMCompilerError(
  25437. 62,
  25438. {
  25439. start: node.children[0].loc.start,
  25440. end: node.children[node.children.length - 1].loc.end,
  25441. source: ""
  25442. }
  25443. )
  25444. );
  25445. }
  25446. const child = node.children[0];
  25447. if (child.type === 1) {
  25448. for (const p of child.props) {
  25449. if (p.type === 7 && p.name === "show") {
  25450. node.props.push({
  25451. type: 6,
  25452. name: "persisted",
  25453. nameLoc: node.loc,
  25454. value: void 0,
  25455. loc: node.loc
  25456. });
  25457. }
  25458. }
  25459. }
  25460. };
  25461. }
  25462. }
  25463. };
  25464. function hasMultipleChildren(node) {
  25465. const children = node.children = node.children.filter(
  25466. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  25467. );
  25468. const child = children[0];
  25469. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  25470. }
  25471. const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
  25472. const stringifyStatic = (children, context, parent) => {
  25473. if (context.scopes.vSlot > 0) {
  25474. return;
  25475. }
  25476. const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray$3(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
  25477. let nc = 0;
  25478. let ec = 0;
  25479. const currentChunk = [];
  25480. const stringifyCurrentChunk = (currentIndex) => {
  25481. if (nc >= 20 || ec >= 5) {
  25482. const staticCall = createCallExpression(context.helper(CREATE_STATIC), [
  25483. JSON.stringify(
  25484. currentChunk.map((node) => stringifyNode(node, context)).join("")
  25485. ).replace(expReplaceRE, `" + $1 + "`),
  25486. // the 2nd argument indicates the number of DOM nodes this static vnode
  25487. // will insert / hydrate
  25488. String(currentChunk.length)
  25489. ]);
  25490. const deleteCount = currentChunk.length - 1;
  25491. if (isParentCached) {
  25492. children.splice(
  25493. currentIndex - currentChunk.length,
  25494. currentChunk.length,
  25495. // @ts-expect-error
  25496. staticCall
  25497. );
  25498. } else {
  25499. currentChunk[0].codegenNode.value = staticCall;
  25500. if (currentChunk.length > 1) {
  25501. children.splice(currentIndex - currentChunk.length + 1, deleteCount);
  25502. const cacheIndex = context.cached.indexOf(
  25503. currentChunk[currentChunk.length - 1].codegenNode
  25504. );
  25505. if (cacheIndex > -1) {
  25506. for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
  25507. const c = context.cached[i2];
  25508. if (c) c.index -= deleteCount;
  25509. }
  25510. context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
  25511. }
  25512. }
  25513. }
  25514. return deleteCount;
  25515. }
  25516. return 0;
  25517. };
  25518. let i = 0;
  25519. for (; i < children.length; i++) {
  25520. const child = children[i];
  25521. const isCached = isParentCached || getCachedNode(child);
  25522. if (isCached) {
  25523. const result = analyzeNode(child);
  25524. if (result) {
  25525. nc += result[0];
  25526. ec += result[1];
  25527. currentChunk.push(child);
  25528. continue;
  25529. }
  25530. }
  25531. i -= stringifyCurrentChunk(i);
  25532. nc = 0;
  25533. ec = 0;
  25534. currentChunk.length = 0;
  25535. }
  25536. stringifyCurrentChunk(i);
  25537. };
  25538. const getCachedNode = (node) => {
  25539. if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
  25540. return node.codegenNode;
  25541. }
  25542. };
  25543. const dataAriaRE = /^(data|aria)-/;
  25544. const isStringifiableAttr = (name, ns) => {
  25545. return (ns === 0 ? isKnownHtmlAttr(name) : ns === 1 ? isKnownSvgAttr(name) : ns === 2 ? isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
  25546. };
  25547. const isNonStringifiable = /* @__PURE__ */ makeMap(
  25548. `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
  25549. );
  25550. function analyzeNode(node) {
  25551. if (node.type === 1 && isNonStringifiable(node.tag)) {
  25552. return false;
  25553. }
  25554. if (node.type === 12) {
  25555. return [1, 0];
  25556. }
  25557. let nc = 1;
  25558. let ec = node.props.length > 0 ? 1 : 0;
  25559. let bailed = false;
  25560. const bail = () => {
  25561. bailed = true;
  25562. return false;
  25563. };
  25564. function walk(node2) {
  25565. const isOptionTag = node2.tag === "option" && node2.ns === 0;
  25566. for (let i = 0; i < node2.props.length; i++) {
  25567. const p = node2.props[i];
  25568. if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
  25569. return bail();
  25570. }
  25571. if (p.type === 7 && p.name === "bind") {
  25572. if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
  25573. return bail();
  25574. }
  25575. if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
  25576. return bail();
  25577. }
  25578. if (isOptionTag && isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
  25579. return bail();
  25580. }
  25581. }
  25582. }
  25583. for (let i = 0; i < node2.children.length; i++) {
  25584. nc++;
  25585. const child = node2.children[i];
  25586. if (child.type === 1) {
  25587. if (child.props.length > 0) {
  25588. ec++;
  25589. }
  25590. walk(child);
  25591. if (bailed) {
  25592. return false;
  25593. }
  25594. }
  25595. }
  25596. return true;
  25597. }
  25598. return walk(node) ? [nc, ec] : false;
  25599. }
  25600. function stringifyNode(node, context) {
  25601. if (isString$1(node)) {
  25602. return node;
  25603. }
  25604. if (isSymbol$1(node)) {
  25605. return ``;
  25606. }
  25607. switch (node.type) {
  25608. case 1:
  25609. return stringifyElement(node, context);
  25610. case 2:
  25611. return escapeHtml(node.content);
  25612. case 3:
  25613. return `<!--${escapeHtml(node.content)}-->`;
  25614. case 5:
  25615. return escapeHtml(toDisplayString(evaluateConstant(node.content)));
  25616. case 8:
  25617. return escapeHtml(evaluateConstant(node));
  25618. case 12:
  25619. return stringifyNode(node.content, context);
  25620. default:
  25621. return "";
  25622. }
  25623. }
  25624. function stringifyElement(node, context) {
  25625. let res = `<${node.tag}`;
  25626. let innerHTML = "";
  25627. for (let i = 0; i < node.props.length; i++) {
  25628. const p = node.props[i];
  25629. if (p.type === 6) {
  25630. res += ` ${p.name}`;
  25631. if (p.value) {
  25632. res += `="${escapeHtml(p.value.content)}"`;
  25633. }
  25634. } else if (p.type === 7) {
  25635. if (p.name === "bind") {
  25636. const exp = p.exp;
  25637. if (exp.content[0] === "_") {
  25638. res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
  25639. continue;
  25640. }
  25641. if (isBooleanAttr(p.arg.content) && exp.content === "false") {
  25642. continue;
  25643. }
  25644. let evaluated = evaluateConstant(exp);
  25645. if (evaluated != null) {
  25646. const arg = p.arg && p.arg.content;
  25647. if (arg === "class") {
  25648. evaluated = normalizeClass(evaluated);
  25649. } else if (arg === "style") {
  25650. evaluated = stringifyStyle(normalizeStyle(evaluated));
  25651. }
  25652. res += ` ${p.arg.content}="${escapeHtml(
  25653. evaluated
  25654. )}"`;
  25655. }
  25656. } else if (p.name === "html") {
  25657. innerHTML = evaluateConstant(p.exp);
  25658. } else if (p.name === "text") {
  25659. innerHTML = escapeHtml(
  25660. toDisplayString(evaluateConstant(p.exp))
  25661. );
  25662. }
  25663. }
  25664. }
  25665. if (context.scopeId) {
  25666. res += ` ${context.scopeId}`;
  25667. }
  25668. res += `>`;
  25669. if (innerHTML) {
  25670. res += innerHTML;
  25671. } else {
  25672. for (let i = 0; i < node.children.length; i++) {
  25673. res += stringifyNode(node.children[i], context);
  25674. }
  25675. }
  25676. if (!isVoidTag(node.tag)) {
  25677. res += `</${node.tag}>`;
  25678. }
  25679. return res;
  25680. }
  25681. function evaluateConstant(exp) {
  25682. if (exp.type === 4) {
  25683. return new Function(`return (${exp.content})`)();
  25684. } else {
  25685. let res = ``;
  25686. exp.children.forEach((c) => {
  25687. if (isString$1(c) || isSymbol$1(c)) {
  25688. return;
  25689. }
  25690. if (c.type === 2) {
  25691. res += c.content;
  25692. } else if (c.type === 5) {
  25693. res += toDisplayString(evaluateConstant(c.content));
  25694. } else {
  25695. res += evaluateConstant(c);
  25696. }
  25697. });
  25698. return res;
  25699. }
  25700. }
  25701. const ignoreSideEffectTags = (node, context) => {
  25702. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  25703. context.onError(
  25704. createDOMCompilerError(
  25705. 63,
  25706. node.loc
  25707. )
  25708. );
  25709. context.removeNode();
  25710. }
  25711. };
  25712. function isValidHTMLNesting(parent, child) {
  25713. if (parent === "template") {
  25714. return true;
  25715. }
  25716. if (parent in onlyValidChildren) {
  25717. return onlyValidChildren[parent].has(child);
  25718. }
  25719. if (child in onlyValidParents) {
  25720. return onlyValidParents[child].has(parent);
  25721. }
  25722. if (parent in knownInvalidChildren) {
  25723. if (knownInvalidChildren[parent].has(child)) return false;
  25724. }
  25725. if (child in knownInvalidParents) {
  25726. if (knownInvalidParents[child].has(parent)) return false;
  25727. }
  25728. return true;
  25729. }
  25730. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  25731. const emptySet = /* @__PURE__ */ new Set([]);
  25732. const onlyValidChildren = {
  25733. head: /* @__PURE__ */ new Set([
  25734. "base",
  25735. "basefront",
  25736. "bgsound",
  25737. "link",
  25738. "meta",
  25739. "title",
  25740. "noscript",
  25741. "noframes",
  25742. "style",
  25743. "script",
  25744. "template"
  25745. ]),
  25746. optgroup: /* @__PURE__ */ new Set(["option"]),
  25747. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  25748. // table
  25749. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  25750. tr: /* @__PURE__ */ new Set(["td", "th"]),
  25751. colgroup: /* @__PURE__ */ new Set(["col"]),
  25752. tbody: /* @__PURE__ */ new Set(["tr"]),
  25753. thead: /* @__PURE__ */ new Set(["tr"]),
  25754. tfoot: /* @__PURE__ */ new Set(["tr"]),
  25755. // these elements can not have any children elements
  25756. script: emptySet,
  25757. iframe: emptySet,
  25758. option: emptySet,
  25759. textarea: emptySet,
  25760. style: emptySet,
  25761. title: emptySet
  25762. };
  25763. const onlyValidParents = {
  25764. // sections
  25765. html: emptySet,
  25766. body: /* @__PURE__ */ new Set(["html"]),
  25767. head: /* @__PURE__ */ new Set(["html"]),
  25768. // table
  25769. td: /* @__PURE__ */ new Set(["tr"]),
  25770. colgroup: /* @__PURE__ */ new Set(["table"]),
  25771. caption: /* @__PURE__ */ new Set(["table"]),
  25772. tbody: /* @__PURE__ */ new Set(["table"]),
  25773. tfoot: /* @__PURE__ */ new Set(["table"]),
  25774. col: /* @__PURE__ */ new Set(["colgroup"]),
  25775. th: /* @__PURE__ */ new Set(["tr"]),
  25776. thead: /* @__PURE__ */ new Set(["table"]),
  25777. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  25778. // data list
  25779. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  25780. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  25781. // other
  25782. figcaption: /* @__PURE__ */ new Set(["figure"]),
  25783. // li: new Set(["ul", "ol"]),
  25784. summary: /* @__PURE__ */ new Set(["details"]),
  25785. area: /* @__PURE__ */ new Set(["map"])
  25786. };
  25787. const knownInvalidChildren = {
  25788. p: /* @__PURE__ */ new Set([
  25789. "address",
  25790. "article",
  25791. "aside",
  25792. "blockquote",
  25793. "center",
  25794. "details",
  25795. "dialog",
  25796. "dir",
  25797. "div",
  25798. "dl",
  25799. "fieldset",
  25800. "figure",
  25801. "footer",
  25802. "form",
  25803. "h1",
  25804. "h2",
  25805. "h3",
  25806. "h4",
  25807. "h5",
  25808. "h6",
  25809. "header",
  25810. "hgroup",
  25811. "hr",
  25812. "li",
  25813. "main",
  25814. "nav",
  25815. "menu",
  25816. "ol",
  25817. "p",
  25818. "pre",
  25819. "section",
  25820. "table",
  25821. "ul"
  25822. ]),
  25823. svg: /* @__PURE__ */ new Set([
  25824. "b",
  25825. "blockquote",
  25826. "br",
  25827. "code",
  25828. "dd",
  25829. "div",
  25830. "dl",
  25831. "dt",
  25832. "em",
  25833. "embed",
  25834. "h1",
  25835. "h2",
  25836. "h3",
  25837. "h4",
  25838. "h5",
  25839. "h6",
  25840. "hr",
  25841. "i",
  25842. "img",
  25843. "li",
  25844. "menu",
  25845. "meta",
  25846. "ol",
  25847. "p",
  25848. "pre",
  25849. "ruby",
  25850. "s",
  25851. "small",
  25852. "span",
  25853. "strong",
  25854. "sub",
  25855. "sup",
  25856. "table",
  25857. "u",
  25858. "ul",
  25859. "var"
  25860. ])
  25861. };
  25862. const knownInvalidParents = {
  25863. a: /* @__PURE__ */ new Set(["a"]),
  25864. button: /* @__PURE__ */ new Set(["button"]),
  25865. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  25866. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  25867. form: /* @__PURE__ */ new Set(["form"]),
  25868. li: /* @__PURE__ */ new Set(["li"]),
  25869. h1: headings,
  25870. h2: headings,
  25871. h3: headings,
  25872. h4: headings,
  25873. h5: headings,
  25874. h6: headings
  25875. };
  25876. const validateHtmlNesting = (node, context) => {
  25877. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  25878. const error = new SyntaxError(
  25879. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  25880. );
  25881. error.loc = node.loc;
  25882. context.onWarn(error);
  25883. }
  25884. };
  25885. const DOMNodeTransforms = [
  25886. transformStyle,
  25887. ...[transformTransition, validateHtmlNesting]
  25888. ];
  25889. const DOMDirectiveTransforms = {
  25890. cloak: noopDirectiveTransform,
  25891. html: transformVHtml,
  25892. text: transformVText,
  25893. model: transformModel,
  25894. // override compiler-core
  25895. on: transformOn,
  25896. // override compiler-core
  25897. show: transformShow
  25898. };
  25899. function compile$1(src, options = {}) {
  25900. return baseCompile(
  25901. src,
  25902. extend({}, parserOptions, options, {
  25903. nodeTransforms: [
  25904. // ignore <script> and <tag>
  25905. // this is not put inside DOMNodeTransforms because that list is used
  25906. // by compiler-ssr to generate vnode fallback branches
  25907. ignoreSideEffectTags,
  25908. ...DOMNodeTransforms,
  25909. ...options.nodeTransforms || []
  25910. ],
  25911. directiveTransforms: extend(
  25912. {},
  25913. DOMDirectiveTransforms,
  25914. options.directiveTransforms || {}
  25915. ),
  25916. transformHoist: stringifyStatic
  25917. })
  25918. );
  25919. }
  25920. function parse$3(template, options = {}) {
  25921. return baseParse(template, extend({}, parserOptions, options));
  25922. }
  25923. var CompilerDOM = /*#__PURE__*/Object.freeze({
  25924. __proto__: null,
  25925. BASE_TRANSITION: BASE_TRANSITION,
  25926. BindingTypes: BindingTypes,
  25927. CAMELIZE: CAMELIZE,
  25928. CAPITALIZE: CAPITALIZE,
  25929. CREATE_BLOCK: CREATE_BLOCK,
  25930. CREATE_COMMENT: CREATE_COMMENT,
  25931. CREATE_ELEMENT_BLOCK: CREATE_ELEMENT_BLOCK,
  25932. CREATE_ELEMENT_VNODE: CREATE_ELEMENT_VNODE,
  25933. CREATE_SLOTS: CREATE_SLOTS,
  25934. CREATE_STATIC: CREATE_STATIC,
  25935. CREATE_TEXT: CREATE_TEXT,
  25936. CREATE_VNODE: CREATE_VNODE,
  25937. CompilerDeprecationTypes: CompilerDeprecationTypes,
  25938. ConstantTypes: ConstantTypes,
  25939. DOMDirectiveTransforms: DOMDirectiveTransforms,
  25940. DOMErrorCodes: DOMErrorCodes,
  25941. DOMErrorMessages: DOMErrorMessages,
  25942. DOMNodeTransforms: DOMNodeTransforms,
  25943. ElementTypes: ElementTypes,
  25944. ErrorCodes: ErrorCodes,
  25945. FRAGMENT: FRAGMENT,
  25946. GUARD_REACTIVE_PROPS: GUARD_REACTIVE_PROPS,
  25947. IS_MEMO_SAME: IS_MEMO_SAME,
  25948. IS_REF: IS_REF,
  25949. KEEP_ALIVE: KEEP_ALIVE,
  25950. MERGE_PROPS: MERGE_PROPS,
  25951. NORMALIZE_CLASS: NORMALIZE_CLASS,
  25952. NORMALIZE_PROPS: NORMALIZE_PROPS,
  25953. NORMALIZE_STYLE: NORMALIZE_STYLE,
  25954. Namespaces: Namespaces,
  25955. NodeTypes: NodeTypes,
  25956. OPEN_BLOCK: OPEN_BLOCK,
  25957. POP_SCOPE_ID: POP_SCOPE_ID,
  25958. PUSH_SCOPE_ID: PUSH_SCOPE_ID,
  25959. RENDER_LIST: RENDER_LIST,
  25960. RENDER_SLOT: RENDER_SLOT,
  25961. RESOLVE_COMPONENT: RESOLVE_COMPONENT,
  25962. RESOLVE_DIRECTIVE: RESOLVE_DIRECTIVE,
  25963. RESOLVE_DYNAMIC_COMPONENT: RESOLVE_DYNAMIC_COMPONENT,
  25964. RESOLVE_FILTER: RESOLVE_FILTER,
  25965. SET_BLOCK_TRACKING: SET_BLOCK_TRACKING,
  25966. SUSPENSE: SUSPENSE,
  25967. TELEPORT: TELEPORT,
  25968. TO_DISPLAY_STRING: TO_DISPLAY_STRING,
  25969. TO_HANDLERS: TO_HANDLERS,
  25970. TO_HANDLER_KEY: TO_HANDLER_KEY,
  25971. TRANSITION: TRANSITION,
  25972. TRANSITION_GROUP: TRANSITION_GROUP,
  25973. TS_NODE_TYPES: TS_NODE_TYPES,
  25974. UNREF: UNREF,
  25975. V_MODEL_CHECKBOX: V_MODEL_CHECKBOX,
  25976. V_MODEL_DYNAMIC: V_MODEL_DYNAMIC,
  25977. V_MODEL_RADIO: V_MODEL_RADIO,
  25978. V_MODEL_SELECT: V_MODEL_SELECT,
  25979. V_MODEL_TEXT: V_MODEL_TEXT,
  25980. V_ON_WITH_KEYS: V_ON_WITH_KEYS,
  25981. V_ON_WITH_MODIFIERS: V_ON_WITH_MODIFIERS,
  25982. V_SHOW: V_SHOW,
  25983. WITH_CTX: WITH_CTX,
  25984. WITH_DIRECTIVES: WITH_DIRECTIVES,
  25985. WITH_MEMO: WITH_MEMO,
  25986. advancePositionWithClone: advancePositionWithClone,
  25987. advancePositionWithMutation: advancePositionWithMutation,
  25988. assert: assert,
  25989. baseCompile: baseCompile,
  25990. baseParse: baseParse,
  25991. buildDirectiveArgs: buildDirectiveArgs,
  25992. buildProps: buildProps,
  25993. buildSlots: buildSlots,
  25994. checkCompatEnabled: checkCompatEnabled,
  25995. compile: compile$1,
  25996. convertToBlock: convertToBlock,
  25997. createArrayExpression: createArrayExpression,
  25998. createAssignmentExpression: createAssignmentExpression,
  25999. createBlockStatement: createBlockStatement,
  26000. createCacheExpression: createCacheExpression,
  26001. createCallExpression: createCallExpression,
  26002. createCompilerError: createCompilerError,
  26003. createCompoundExpression: createCompoundExpression,
  26004. createConditionalExpression: createConditionalExpression,
  26005. createDOMCompilerError: createDOMCompilerError,
  26006. createForLoopParams: createForLoopParams,
  26007. createFunctionExpression: createFunctionExpression,
  26008. createIfStatement: createIfStatement,
  26009. createInterpolation: createInterpolation,
  26010. createObjectExpression: createObjectExpression,
  26011. createObjectProperty: createObjectProperty,
  26012. createReturnStatement: createReturnStatement,
  26013. createRoot: createRoot,
  26014. createSequenceExpression: createSequenceExpression,
  26015. createSimpleExpression: createSimpleExpression,
  26016. createStructuralDirectiveTransform: createStructuralDirectiveTransform,
  26017. createTemplateLiteral: createTemplateLiteral,
  26018. createTransformContext: createTransformContext,
  26019. createVNodeCall: createVNodeCall,
  26020. errorMessages: errorMessages$1,
  26021. extractIdentifiers: extractIdentifiers$1,
  26022. findDir: findDir,
  26023. findProp: findProp,
  26024. forAliasRE: forAliasRE,
  26025. generate: generate,
  26026. generateCodeFrame: generateCodeFrame,
  26027. getBaseTransformPreset: getBaseTransformPreset,
  26028. getConstantType: getConstantType,
  26029. getMemoedVNodeCall: getMemoedVNodeCall,
  26030. getVNodeBlockHelper: getVNodeBlockHelper,
  26031. getVNodeHelper: getVNodeHelper,
  26032. hasDynamicKeyVBind: hasDynamicKeyVBind,
  26033. hasScopeRef: hasScopeRef,
  26034. helperNameMap: helperNameMap,
  26035. injectProp: injectProp,
  26036. isCoreComponent: isCoreComponent,
  26037. isFnExpression: isFnExpression,
  26038. isFnExpressionBrowser: isFnExpressionBrowser,
  26039. isFnExpressionNode: isFnExpressionNode,
  26040. isFunctionType: isFunctionType,
  26041. isInDestructureAssignment: isInDestructureAssignment,
  26042. isInNewExpression: isInNewExpression,
  26043. isMemberExpression: isMemberExpression,
  26044. isMemberExpressionBrowser: isMemberExpressionBrowser,
  26045. isMemberExpressionNode: isMemberExpressionNode,
  26046. isReferencedIdentifier: isReferencedIdentifier,
  26047. isSimpleIdentifier: isSimpleIdentifier,
  26048. isSlotOutlet: isSlotOutlet,
  26049. isStaticArgOf: isStaticArgOf,
  26050. isStaticExp: isStaticExp,
  26051. isStaticProperty: isStaticProperty,
  26052. isStaticPropertyKey: isStaticPropertyKey,
  26053. isTemplateNode: isTemplateNode,
  26054. isText: isText$1,
  26055. isVPre: isVPre,
  26056. isVSlot: isVSlot,
  26057. locStub: locStub,
  26058. noopDirectiveTransform: noopDirectiveTransform,
  26059. parse: parse$3,
  26060. parserOptions: parserOptions,
  26061. processExpression: processExpression,
  26062. processFor: processFor,
  26063. processIf: processIf,
  26064. processSlotOutlet: processSlotOutlet,
  26065. registerRuntimeHelpers: registerRuntimeHelpers,
  26066. resolveComponentType: resolveComponentType,
  26067. stringifyExpression: stringifyExpression,
  26068. toValidAssetId: toValidAssetId,
  26069. trackSlotScopes: trackSlotScopes,
  26070. trackVForSlotScopes: trackVForSlotScopes,
  26071. transform: transform,
  26072. transformBind: transformBind,
  26073. transformElement: transformElement,
  26074. transformExpression: transformExpression,
  26075. transformModel: transformModel$1,
  26076. transformOn: transformOn$1,
  26077. transformStyle: transformStyle,
  26078. traverseNode: traverseNode,
  26079. unwrapTSNode: unwrapTSNode,
  26080. walkBlockDeclarations: walkBlockDeclarations,
  26081. walkFunctionParams: walkFunctionParams,
  26082. walkIdentifiers: walkIdentifiers,
  26083. warnDeprecation: warnDeprecation
  26084. });
  26085. var hashSum;
  26086. var hasRequiredHashSum;
  26087. function requireHashSum () {
  26088. if (hasRequiredHashSum) return hashSum;
  26089. hasRequiredHashSum = 1;
  26090. function pad (hash, len) {
  26091. while (hash.length < len) {
  26092. hash = '0' + hash;
  26093. }
  26094. return hash;
  26095. }
  26096. function fold (hash, text) {
  26097. var i;
  26098. var chr;
  26099. var len;
  26100. if (text.length === 0) {
  26101. return hash;
  26102. }
  26103. for (i = 0, len = text.length; i < len; i++) {
  26104. chr = text.charCodeAt(i);
  26105. hash = ((hash << 5) - hash) + chr;
  26106. hash |= 0;
  26107. }
  26108. return hash < 0 ? hash * -2 : hash;
  26109. }
  26110. function foldObject (hash, o, seen) {
  26111. return Object.keys(o).sort().reduce(foldKey, hash);
  26112. function foldKey (hash, key) {
  26113. return foldValue(hash, o[key], key, seen);
  26114. }
  26115. }
  26116. function foldValue (input, value, key, seen) {
  26117. var hash = fold(fold(fold(input, key), toString(value)), typeof value);
  26118. if (value === null) {
  26119. return fold(hash, 'null');
  26120. }
  26121. if (value === undefined) {
  26122. return fold(hash, 'undefined');
  26123. }
  26124. if (typeof value === 'object' || typeof value === 'function') {
  26125. if (seen.indexOf(value) !== -1) {
  26126. return fold(hash, '[Circular]' + key);
  26127. }
  26128. seen.push(value);
  26129. var objHash = foldObject(hash, value, seen);
  26130. if (!('valueOf' in value) || typeof value.valueOf !== 'function') {
  26131. return objHash;
  26132. }
  26133. try {
  26134. return fold(objHash, String(value.valueOf()))
  26135. } catch (err) {
  26136. return fold(objHash, '[valueOf exception]' + (err.stack || err.message))
  26137. }
  26138. }
  26139. return fold(hash, value.toString());
  26140. }
  26141. function toString (o) {
  26142. return Object.prototype.toString.call(o);
  26143. }
  26144. function sum (o) {
  26145. return pad(foldValue(0, o, '', []).toString(16), 8);
  26146. }
  26147. hashSum = sum;
  26148. return hashSum;
  26149. }
  26150. var hashSumExports = /*@__PURE__*/ requireHashSum();
  26151. var hash = /*@__PURE__*/getDefaultExportFromCjs(hashSumExports);
  26152. const CSS_VARS_HELPER = `useCssVars`;
  26153. function genCssVarsFromList(vars, id, isProd, isSSR = false) {
  26154. return `{
  26155. ${vars.map(
  26156. (key) => (
  26157. // The `:` prefix here is used in `ssrRenderStyle` to distinguish whether
  26158. // a custom property comes from `ssrCssVars`. If it does, we need to reset
  26159. // its value to `initial` on the component instance to avoid unintentionally
  26160. // inheriting the same property value from a different instance of the same
  26161. // component in the outer scope.
  26162. `"${isSSR ? `:--` : ``}${genVarName(id, key, isProd, isSSR)}": (${key})`
  26163. )
  26164. ).join(",\n ")}
  26165. }`;
  26166. }
  26167. function genVarName(id, raw, isProd, isSSR = false) {
  26168. if (isProd) {
  26169. return hash(id + raw);
  26170. } else {
  26171. return `${id}-${getEscapedCssVarName(raw, isSSR)}`;
  26172. }
  26173. }
  26174. function normalizeExpression(exp) {
  26175. exp = exp.trim();
  26176. if (exp[0] === `'` && exp[exp.length - 1] === `'` || exp[0] === `"` && exp[exp.length - 1] === `"`) {
  26177. return exp.slice(1, -1);
  26178. }
  26179. return exp;
  26180. }
  26181. const vBindRE = /v-bind\s*\(/g;
  26182. function parseCssVars(sfc) {
  26183. const vars = [];
  26184. sfc.styles.forEach((style) => {
  26185. let match;
  26186. const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
  26187. while (match = vBindRE.exec(content)) {
  26188. const start = match.index + match[0].length;
  26189. const end = lexBinding(content, start);
  26190. if (end !== null) {
  26191. const variable = normalizeExpression(content.slice(start, end));
  26192. if (!vars.includes(variable)) {
  26193. vars.push(variable);
  26194. }
  26195. }
  26196. }
  26197. });
  26198. return vars;
  26199. }
  26200. function lexBinding(content, start) {
  26201. let state = 0 /* inParens */;
  26202. let parenDepth = 0;
  26203. for (let i = start; i < content.length; i++) {
  26204. const char = content.charAt(i);
  26205. switch (state) {
  26206. case 0 /* inParens */:
  26207. if (char === `'`) {
  26208. state = 1 /* inSingleQuoteString */;
  26209. } else if (char === `"`) {
  26210. state = 2 /* inDoubleQuoteString */;
  26211. } else if (char === `(`) {
  26212. parenDepth++;
  26213. } else if (char === `)`) {
  26214. if (parenDepth > 0) {
  26215. parenDepth--;
  26216. } else {
  26217. return i;
  26218. }
  26219. }
  26220. break;
  26221. case 1 /* inSingleQuoteString */:
  26222. if (char === `'`) {
  26223. state = 0 /* inParens */;
  26224. }
  26225. break;
  26226. case 2 /* inDoubleQuoteString */:
  26227. if (char === `"`) {
  26228. state = 0 /* inParens */;
  26229. }
  26230. break;
  26231. }
  26232. }
  26233. return null;
  26234. }
  26235. const cssVarsPlugin = (opts) => {
  26236. const { id, isProd } = opts;
  26237. return {
  26238. postcssPlugin: "vue-sfc-vars",
  26239. Declaration(decl) {
  26240. const value = decl.value;
  26241. if (vBindRE.test(value)) {
  26242. vBindRE.lastIndex = 0;
  26243. let transformed = "";
  26244. let lastIndex = 0;
  26245. let match;
  26246. while (match = vBindRE.exec(value)) {
  26247. const start = match.index + match[0].length;
  26248. const end = lexBinding(value, start);
  26249. if (end !== null) {
  26250. const variable = normalizeExpression(value.slice(start, end));
  26251. transformed += value.slice(lastIndex, match.index) + `var(--${genVarName(id, variable, isProd)})`;
  26252. lastIndex = end + 1;
  26253. }
  26254. }
  26255. decl.value = transformed + value.slice(lastIndex);
  26256. }
  26257. }
  26258. };
  26259. };
  26260. cssVarsPlugin.postcss = true;
  26261. function genCssVarsCode(vars, bindings, id, isProd) {
  26262. const varsExp = genCssVarsFromList(vars, id, isProd);
  26263. const exp = createSimpleExpression(varsExp, false);
  26264. const context = createTransformContext(createRoot([]), {
  26265. prefixIdentifiers: true,
  26266. inline: true,
  26267. bindingMetadata: bindings.__isScriptSetup === false ? void 0 : bindings
  26268. });
  26269. const transformed = processExpression(exp, context);
  26270. const transformedString = transformed.type === 4 ? transformed.content : transformed.children.map((c) => {
  26271. return typeof c === "string" ? c : c.content;
  26272. }).join("");
  26273. return `_${CSS_VARS_HELPER}(_ctx => (${transformedString}))`;
  26274. }
  26275. function genNormalScriptCssVarsCode(cssVars, bindings, id, isProd, defaultVar) {
  26276. return `
  26277. import { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'
  26278. const __injectCSSVars__ = () => {
  26279. ${genCssVarsCode(
  26280. cssVars,
  26281. bindings,
  26282. id,
  26283. isProd
  26284. )}}
  26285. const __setup__ = ${defaultVar}.setup
  26286. ${defaultVar}.setup = __setup__
  26287. ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }
  26288. : __injectCSSVars__
  26289. `;
  26290. }
  26291. var global$1 = (typeof global !== "undefined" ? global :
  26292. typeof self !== "undefined" ? self :
  26293. typeof window !== "undefined" ? window : {});
  26294. // shim for using process in browser
  26295. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  26296. function defaultSetTimout() {
  26297. throw new Error('setTimeout has not been defined');
  26298. }
  26299. function defaultClearTimeout () {
  26300. throw new Error('clearTimeout has not been defined');
  26301. }
  26302. var cachedSetTimeout = defaultSetTimout;
  26303. var cachedClearTimeout = defaultClearTimeout;
  26304. if (typeof global$1.setTimeout === 'function') {
  26305. cachedSetTimeout = setTimeout;
  26306. }
  26307. if (typeof global$1.clearTimeout === 'function') {
  26308. cachedClearTimeout = clearTimeout;
  26309. }
  26310. function runTimeout(fun) {
  26311. if (cachedSetTimeout === setTimeout) {
  26312. //normal enviroments in sane situations
  26313. return setTimeout(fun, 0);
  26314. }
  26315. // if setTimeout wasn't available but was latter defined
  26316. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  26317. cachedSetTimeout = setTimeout;
  26318. return setTimeout(fun, 0);
  26319. }
  26320. try {
  26321. // when when somebody has screwed with setTimeout but no I.E. maddness
  26322. return cachedSetTimeout(fun, 0);
  26323. } catch(e){
  26324. try {
  26325. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26326. return cachedSetTimeout.call(null, fun, 0);
  26327. } catch(e){
  26328. // 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
  26329. return cachedSetTimeout.call(this, fun, 0);
  26330. }
  26331. }
  26332. }
  26333. function runClearTimeout(marker) {
  26334. if (cachedClearTimeout === clearTimeout) {
  26335. //normal enviroments in sane situations
  26336. return clearTimeout(marker);
  26337. }
  26338. // if clearTimeout wasn't available but was latter defined
  26339. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  26340. cachedClearTimeout = clearTimeout;
  26341. return clearTimeout(marker);
  26342. }
  26343. try {
  26344. // when when somebody has screwed with setTimeout but no I.E. maddness
  26345. return cachedClearTimeout(marker);
  26346. } catch (e){
  26347. try {
  26348. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  26349. return cachedClearTimeout.call(null, marker);
  26350. } catch (e){
  26351. // 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.
  26352. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  26353. return cachedClearTimeout.call(this, marker);
  26354. }
  26355. }
  26356. }
  26357. var queue = [];
  26358. var draining = false;
  26359. var currentQueue;
  26360. var queueIndex = -1;
  26361. function cleanUpNextTick() {
  26362. if (!draining || !currentQueue) {
  26363. return;
  26364. }
  26365. draining = false;
  26366. if (currentQueue.length) {
  26367. queue = currentQueue.concat(queue);
  26368. } else {
  26369. queueIndex = -1;
  26370. }
  26371. if (queue.length) {
  26372. drainQueue();
  26373. }
  26374. }
  26375. function drainQueue() {
  26376. if (draining) {
  26377. return;
  26378. }
  26379. var timeout = runTimeout(cleanUpNextTick);
  26380. draining = true;
  26381. var len = queue.length;
  26382. while(len) {
  26383. currentQueue = queue;
  26384. queue = [];
  26385. while (++queueIndex < len) {
  26386. if (currentQueue) {
  26387. currentQueue[queueIndex].run();
  26388. }
  26389. }
  26390. queueIndex = -1;
  26391. len = queue.length;
  26392. }
  26393. currentQueue = null;
  26394. draining = false;
  26395. runClearTimeout(timeout);
  26396. }
  26397. function nextTick(fun) {
  26398. var args = new Array(arguments.length - 1);
  26399. if (arguments.length > 1) {
  26400. for (var i = 1; i < arguments.length; i++) {
  26401. args[i - 1] = arguments[i];
  26402. }
  26403. }
  26404. queue.push(new Item(fun, args));
  26405. if (queue.length === 1 && !draining) {
  26406. runTimeout(drainQueue);
  26407. }
  26408. }
  26409. // v8 likes predictible objects
  26410. function Item(fun, array) {
  26411. this.fun = fun;
  26412. this.array = array;
  26413. }
  26414. Item.prototype.run = function () {
  26415. this.fun.apply(null, this.array);
  26416. };
  26417. var title = 'browser';
  26418. var platform = 'browser';
  26419. var browser = true;
  26420. var env = {};
  26421. var argv = [];
  26422. var version$1 = ''; // empty string to avoid regexp issues
  26423. var versions = {};
  26424. var release = {};
  26425. var config = {};
  26426. function noop() {}
  26427. var on = noop;
  26428. var addListener = noop;
  26429. var once = noop;
  26430. var off = noop;
  26431. var removeListener = noop;
  26432. var removeAllListeners = noop;
  26433. var emit = noop;
  26434. function binding(name) {
  26435. throw new Error('process.binding is not supported');
  26436. }
  26437. function cwd () { return '/' }
  26438. function chdir (dir) {
  26439. throw new Error('process.chdir is not supported');
  26440. }function umask() { return 0; }
  26441. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  26442. var performance = global$1.performance || {};
  26443. var performanceNow =
  26444. performance.now ||
  26445. performance.mozNow ||
  26446. performance.msNow ||
  26447. performance.oNow ||
  26448. performance.webkitNow ||
  26449. function(){ return (new Date()).getTime() };
  26450. // generate timestamp or delta
  26451. // see http://nodejs.org/api/process.html#process_process_hrtime
  26452. function hrtime(previousTimestamp){
  26453. var clocktime = performanceNow.call(performance)*1e-3;
  26454. var seconds = Math.floor(clocktime);
  26455. var nanoseconds = Math.floor((clocktime%1)*1e9);
  26456. if (previousTimestamp) {
  26457. seconds = seconds - previousTimestamp[0];
  26458. nanoseconds = nanoseconds - previousTimestamp[1];
  26459. if (nanoseconds<0) {
  26460. seconds--;
  26461. nanoseconds += 1e9;
  26462. }
  26463. }
  26464. return [seconds,nanoseconds]
  26465. }
  26466. var startTime = new Date();
  26467. function uptime() {
  26468. var currentTime = new Date();
  26469. var dif = currentTime - startTime;
  26470. return dif / 1000;
  26471. }
  26472. var browser$1 = {
  26473. nextTick: nextTick,
  26474. title: title,
  26475. browser: browser,
  26476. env: env,
  26477. argv: argv,
  26478. version: version$1,
  26479. versions: versions,
  26480. on: on,
  26481. addListener: addListener,
  26482. once: once,
  26483. off: off,
  26484. removeListener: removeListener,
  26485. removeAllListeners: removeAllListeners,
  26486. emit: emit,
  26487. binding: binding,
  26488. cwd: cwd,
  26489. chdir: chdir,
  26490. umask: umask,
  26491. hrtime: hrtime,
  26492. platform: platform,
  26493. release: release,
  26494. config: config,
  26495. uptime: uptime
  26496. };
  26497. function createCache(max = 500) {
  26498. {
  26499. return /* @__PURE__ */ new Map();
  26500. }
  26501. }
  26502. function isImportUsed(local, sfc) {
  26503. return resolveTemplateUsedIdentifiers(sfc).has(local);
  26504. }
  26505. const templateUsageCheckCache = createCache();
  26506. function resolveTemplateUsedIdentifiers(sfc) {
  26507. const { content, ast } = sfc.template;
  26508. const cached = templateUsageCheckCache.get(content);
  26509. if (cached) {
  26510. return cached;
  26511. }
  26512. const ids = /* @__PURE__ */ new Set();
  26513. ast.children.forEach(walk);
  26514. function walk(node) {
  26515. var _a;
  26516. switch (node.type) {
  26517. case 1:
  26518. let tag = node.tag;
  26519. if (tag.includes(".")) tag = tag.split(".")[0].trim();
  26520. if (!parserOptions.isNativeTag(tag) && !parserOptions.isBuiltInComponent(tag)) {
  26521. ids.add(camelize(tag));
  26522. ids.add(capitalize(camelize(tag)));
  26523. }
  26524. for (let i = 0; i < node.props.length; i++) {
  26525. const prop = node.props[i];
  26526. if (prop.type === 7) {
  26527. if (!isBuiltInDirective(prop.name)) {
  26528. ids.add(`v${capitalize(camelize(prop.name))}`);
  26529. }
  26530. if (prop.arg && !prop.arg.isStatic) {
  26531. extractIdentifiers(ids, prop.arg);
  26532. }
  26533. if (prop.name === "for") {
  26534. extractIdentifiers(ids, prop.forParseResult.source);
  26535. } else if (prop.exp) {
  26536. extractIdentifiers(ids, prop.exp);
  26537. } else if (prop.name === "bind" && !prop.exp) {
  26538. ids.add(camelize(prop.arg.content));
  26539. }
  26540. }
  26541. if (prop.type === 6 && prop.name === "ref" && ((_a = prop.value) == null ? void 0 : _a.content)) {
  26542. ids.add(prop.value.content);
  26543. }
  26544. }
  26545. node.children.forEach(walk);
  26546. break;
  26547. case 5:
  26548. extractIdentifiers(ids, node.content);
  26549. break;
  26550. }
  26551. }
  26552. templateUsageCheckCache.set(content, ids);
  26553. return ids;
  26554. }
  26555. function extractIdentifiers(ids, node) {
  26556. if (node.ast) {
  26557. walkIdentifiers(node.ast, (n) => ids.add(n.name));
  26558. } else if (node.ast === null) {
  26559. ids.add(node.content);
  26560. }
  26561. }
  26562. var __defProp$a = Object.defineProperty;
  26563. var __defProps$9 = Object.defineProperties;
  26564. var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
  26565. var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
  26566. var __hasOwnProp$a = Object.prototype.hasOwnProperty;
  26567. var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
  26568. var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  26569. var __spreadValues$a = (a, b) => {
  26570. for (var prop in b || (b = {}))
  26571. if (__hasOwnProp$a.call(b, prop))
  26572. __defNormalProp$a(a, prop, b[prop]);
  26573. if (__getOwnPropSymbols$a)
  26574. for (var prop of __getOwnPropSymbols$a(b)) {
  26575. if (__propIsEnum$a.call(b, prop))
  26576. __defNormalProp$a(a, prop, b[prop]);
  26577. }
  26578. return a;
  26579. };
  26580. var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
  26581. const DEFAULT_FILENAME = "anonymous.vue";
  26582. const parseCache$1 = createCache();
  26583. function parse$2(source, options = {}) {
  26584. var _a;
  26585. const sourceKey = genCacheKey(source, __spreadProps$9(__spreadValues$a({}, options), {
  26586. compiler: { parse: (_a = options.compiler) == null ? void 0 : _a.parse }
  26587. }));
  26588. const cache = parseCache$1.get(sourceKey);
  26589. if (cache) {
  26590. return cache;
  26591. }
  26592. const {
  26593. sourceMap = true,
  26594. filename = DEFAULT_FILENAME,
  26595. sourceRoot = "",
  26596. pad = false,
  26597. ignoreEmpty = true,
  26598. compiler = CompilerDOM,
  26599. templateParseOptions = {}
  26600. } = options;
  26601. const descriptor = {
  26602. filename,
  26603. source,
  26604. template: null,
  26605. script: null,
  26606. scriptSetup: null,
  26607. styles: [],
  26608. customBlocks: [],
  26609. cssVars: [],
  26610. slotted: false,
  26611. shouldForceReload: (prevImports) => hmrShouldReload(prevImports, descriptor)
  26612. };
  26613. const errors = [];
  26614. const ast = compiler.parse(source, __spreadProps$9(__spreadValues$a({
  26615. parseMode: "sfc",
  26616. prefixIdentifiers: true
  26617. }, templateParseOptions), {
  26618. onError: (e) => {
  26619. errors.push(e);
  26620. }
  26621. }));
  26622. ast.children.forEach((node) => {
  26623. if (node.type !== 1) {
  26624. return;
  26625. }
  26626. if (ignoreEmpty && node.tag !== "template" && isEmpty(node) && !hasSrc(node)) {
  26627. return;
  26628. }
  26629. switch (node.tag) {
  26630. case "template":
  26631. if (!descriptor.template) {
  26632. const templateBlock = descriptor.template = createBlock(
  26633. node,
  26634. source,
  26635. false
  26636. );
  26637. if (!templateBlock.attrs.src) {
  26638. templateBlock.ast = createRoot(node.children, source);
  26639. }
  26640. if (templateBlock.attrs.functional) {
  26641. const err = new SyntaxError(
  26642. `<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.`
  26643. );
  26644. err.loc = node.props.find(
  26645. (p) => p.type === 6 && p.name === "functional"
  26646. ).loc;
  26647. errors.push(err);
  26648. }
  26649. } else {
  26650. errors.push(createDuplicateBlockError(node));
  26651. }
  26652. break;
  26653. case "script":
  26654. const scriptBlock = createBlock(node, source, pad);
  26655. const isSetup = !!scriptBlock.attrs.setup;
  26656. if (isSetup && !descriptor.scriptSetup) {
  26657. descriptor.scriptSetup = scriptBlock;
  26658. break;
  26659. }
  26660. if (!isSetup && !descriptor.script) {
  26661. descriptor.script = scriptBlock;
  26662. break;
  26663. }
  26664. errors.push(createDuplicateBlockError(node, isSetup));
  26665. break;
  26666. case "style":
  26667. const styleBlock = createBlock(node, source, pad);
  26668. if (styleBlock.attrs.vars) {
  26669. errors.push(
  26670. new SyntaxError(
  26671. `<style vars> has been replaced by a new proposal: https://github.com/vuejs/rfcs/pull/231`
  26672. )
  26673. );
  26674. }
  26675. descriptor.styles.push(styleBlock);
  26676. break;
  26677. default:
  26678. descriptor.customBlocks.push(createBlock(node, source, pad));
  26679. break;
  26680. }
  26681. });
  26682. if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
  26683. errors.push(
  26684. new SyntaxError(
  26685. `At least one <template> or <script> is required in a single file component. ${descriptor.filename}`
  26686. )
  26687. );
  26688. }
  26689. if (descriptor.scriptSetup) {
  26690. if (descriptor.scriptSetup.src) {
  26691. errors.push(
  26692. new SyntaxError(
  26693. `<script setup> cannot use the "src" attribute because its syntax will be ambiguous outside of the component.`
  26694. )
  26695. );
  26696. descriptor.scriptSetup = null;
  26697. }
  26698. if (descriptor.script && descriptor.script.src) {
  26699. errors.push(
  26700. new SyntaxError(
  26701. `<script> cannot use the "src" attribute when <script setup> is also present because they must be processed together.`
  26702. )
  26703. );
  26704. descriptor.script = null;
  26705. }
  26706. }
  26707. let templateColumnOffset = 0;
  26708. if (descriptor.template && (descriptor.template.lang === "pug" || descriptor.template.lang === "jade")) {
  26709. [descriptor.template.content, templateColumnOffset] = dedent(
  26710. descriptor.template.content
  26711. );
  26712. }
  26713. if (sourceMap) {
  26714. const genMap = (block, columnOffset = 0) => {
  26715. if (block && !block.src) {
  26716. block.map = generateSourceMap(
  26717. filename,
  26718. source,
  26719. block.content,
  26720. sourceRoot,
  26721. !pad || block.type === "template" ? block.loc.start.line - 1 : 0,
  26722. columnOffset
  26723. );
  26724. }
  26725. };
  26726. genMap(descriptor.template, templateColumnOffset);
  26727. genMap(descriptor.script);
  26728. descriptor.styles.forEach((s) => genMap(s));
  26729. descriptor.customBlocks.forEach((s) => genMap(s));
  26730. }
  26731. descriptor.cssVars = parseCssVars(descriptor);
  26732. const slottedRE = /(?:::v-|:)slotted\(/;
  26733. descriptor.slotted = descriptor.styles.some(
  26734. (s) => s.scoped && slottedRE.test(s.content)
  26735. );
  26736. const result = {
  26737. descriptor,
  26738. errors
  26739. };
  26740. parseCache$1.set(sourceKey, result);
  26741. return result;
  26742. }
  26743. function createDuplicateBlockError(node, isScriptSetup = false) {
  26744. const err = new SyntaxError(
  26745. `Single file component can contain only one <${node.tag}${isScriptSetup ? ` setup` : ``}> element`
  26746. );
  26747. err.loc = node.loc;
  26748. return err;
  26749. }
  26750. function createBlock(node, source, pad) {
  26751. const type = node.tag;
  26752. const loc = node.innerLoc;
  26753. const attrs = {};
  26754. const block = {
  26755. type,
  26756. content: source.slice(loc.start.offset, loc.end.offset),
  26757. loc,
  26758. attrs
  26759. };
  26760. if (pad) {
  26761. block.content = padContent(source, block, pad) + block.content;
  26762. }
  26763. node.props.forEach((p) => {
  26764. if (p.type === 6) {
  26765. const name = p.name;
  26766. attrs[name] = p.value ? p.value.content || true : true;
  26767. if (name === "lang") {
  26768. block.lang = p.value && p.value.content;
  26769. } else if (name === "src") {
  26770. block.src = p.value && p.value.content;
  26771. } else if (type === "style") {
  26772. if (name === "scoped") {
  26773. block.scoped = true;
  26774. } else if (name === "module") {
  26775. block.module = attrs[name];
  26776. }
  26777. } else if (type === "script" && name === "setup") {
  26778. block.setup = attrs.setup;
  26779. }
  26780. }
  26781. });
  26782. return block;
  26783. }
  26784. const splitRE = /\r?\n/g;
  26785. const emptyRE = /^(?:\/\/)?\s*$/;
  26786. const replaceRE = /./g;
  26787. function generateSourceMap(filename, source, generated, sourceRoot, lineOffset, columnOffset) {
  26788. const map = new sourceMapExports.SourceMapGenerator({
  26789. file: filename.replace(/\\/g, "/"),
  26790. sourceRoot: sourceRoot.replace(/\\/g, "/")
  26791. });
  26792. map.setSourceContent(filename, source);
  26793. map._sources.add(filename);
  26794. generated.split(splitRE).forEach((line, index) => {
  26795. if (!emptyRE.test(line)) {
  26796. const originalLine = index + 1 + lineOffset;
  26797. const generatedLine = index + 1;
  26798. for (let i = 0; i < line.length; i++) {
  26799. if (!/\s/.test(line[i])) {
  26800. map._mappings.add({
  26801. originalLine,
  26802. originalColumn: i + columnOffset,
  26803. generatedLine,
  26804. generatedColumn: i,
  26805. source: filename,
  26806. name: null
  26807. });
  26808. }
  26809. }
  26810. }
  26811. });
  26812. return map.toJSON();
  26813. }
  26814. function padContent(content, block, pad) {
  26815. content = content.slice(0, block.loc.start.offset);
  26816. if (pad === "space") {
  26817. return content.replace(replaceRE, " ");
  26818. } else {
  26819. const offset = content.split(splitRE).length;
  26820. const padChar = block.type === "script" && !block.lang ? "//\n" : "\n";
  26821. return Array(offset).join(padChar);
  26822. }
  26823. }
  26824. function hasSrc(node) {
  26825. return node.props.some((p) => {
  26826. if (p.type !== 6) {
  26827. return false;
  26828. }
  26829. return p.name === "src";
  26830. });
  26831. }
  26832. function isEmpty(node) {
  26833. for (let i = 0; i < node.children.length; i++) {
  26834. const child = node.children[i];
  26835. if (child.type !== 2 || child.content.trim() !== "") {
  26836. return false;
  26837. }
  26838. }
  26839. return true;
  26840. }
  26841. function hmrShouldReload(prevImports, next) {
  26842. if (!next.scriptSetup || next.scriptSetup.lang !== "ts" && next.scriptSetup.lang !== "tsx") {
  26843. return false;
  26844. }
  26845. for (const key in prevImports) {
  26846. if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
  26847. return true;
  26848. }
  26849. }
  26850. return false;
  26851. }
  26852. function dedent(s) {
  26853. const lines = s.split("\n");
  26854. const minIndent = lines.reduce(function(minIndent2, line) {
  26855. var _a, _b;
  26856. if (line.trim() === "") {
  26857. return minIndent2;
  26858. }
  26859. const indent = ((_b = (_a = line.match(/^\s*/)) == null ? void 0 : _a[0]) == null ? void 0 : _b.length) || 0;
  26860. return Math.min(indent, minIndent2);
  26861. }, Infinity);
  26862. if (minIndent === 0) {
  26863. return [s, minIndent];
  26864. }
  26865. return [
  26866. lines.map(function(line) {
  26867. return line.slice(minIndent);
  26868. }).join("\n"),
  26869. minIndent
  26870. ];
  26871. }
  26872. // Copyright Joyent, Inc. and other Node contributors.
  26873. //
  26874. // Permission is hereby granted, free of charge, to any person obtaining a
  26875. // copy of this software and associated documentation files (the
  26876. // "Software"), to deal in the Software without restriction, including
  26877. // without limitation the rights to use, copy, modify, merge, publish,
  26878. // distribute, sublicense, and/or sell copies of the Software, and to permit
  26879. // persons to whom the Software is furnished to do so, subject to the
  26880. // following conditions:
  26881. //
  26882. // The above copyright notice and this permission notice shall be included
  26883. // in all copies or substantial portions of the Software.
  26884. //
  26885. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  26886. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26887. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  26888. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  26889. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  26890. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  26891. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  26892. // resolves . and .. elements in a path array with directory names there
  26893. // must be no slashes, empty elements, or device names (c:\) in the array
  26894. // (so also no leading and trailing slashes - it does not distinguish
  26895. // relative and absolute paths)
  26896. function normalizeArray(parts, allowAboveRoot) {
  26897. // if the path tries to go above the root, `up` ends up > 0
  26898. var up = 0;
  26899. for (var i = parts.length - 1; i >= 0; i--) {
  26900. var last = parts[i];
  26901. if (last === '.') {
  26902. parts.splice(i, 1);
  26903. } else if (last === '..') {
  26904. parts.splice(i, 1);
  26905. up++;
  26906. } else if (up) {
  26907. parts.splice(i, 1);
  26908. up--;
  26909. }
  26910. }
  26911. // if the path is allowed to go above the root, restore leading ..s
  26912. if (allowAboveRoot) {
  26913. for (; up--; up) {
  26914. parts.unshift('..');
  26915. }
  26916. }
  26917. return parts;
  26918. }
  26919. // Split a filename into [root, dir, basename, ext], unix version
  26920. // 'root' is just a slash, or nothing.
  26921. var splitPathRe =
  26922. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  26923. var splitPath = function(filename) {
  26924. return splitPathRe.exec(filename).slice(1);
  26925. };
  26926. // path.resolve([from ...], to)
  26927. // posix version
  26928. function resolve() {
  26929. var resolvedPath = '',
  26930. resolvedAbsolute = false;
  26931. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  26932. var path = (i >= 0) ? arguments[i] : '/';
  26933. // Skip empty and invalid entries
  26934. if (typeof path !== 'string') {
  26935. throw new TypeError('Arguments to path.resolve must be strings');
  26936. } else if (!path) {
  26937. continue;
  26938. }
  26939. resolvedPath = path + '/' + resolvedPath;
  26940. resolvedAbsolute = path.charAt(0) === '/';
  26941. }
  26942. // At this point the path should be resolved to a full absolute path, but
  26943. // handle relative paths to be safe (might happen when process.cwd() fails)
  26944. // Normalize the path
  26945. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  26946. return !!p;
  26947. }), !resolvedAbsolute).join('/');
  26948. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  26949. }
  26950. // path.normalize(path)
  26951. // posix version
  26952. function normalize$1(path) {
  26953. var isPathAbsolute = isAbsolute(path),
  26954. trailingSlash = substr(path, -1) === '/';
  26955. // Normalize the path
  26956. path = normalizeArray(filter(path.split('/'), function(p) {
  26957. return !!p;
  26958. }), !isPathAbsolute).join('/');
  26959. if (!path && !isPathAbsolute) {
  26960. path = '.';
  26961. }
  26962. if (path && trailingSlash) {
  26963. path += '/';
  26964. }
  26965. return (isPathAbsolute ? '/' : '') + path;
  26966. }
  26967. // posix version
  26968. function isAbsolute(path) {
  26969. return path.charAt(0) === '/';
  26970. }
  26971. // posix version
  26972. function join() {
  26973. var paths = Array.prototype.slice.call(arguments, 0);
  26974. return normalize$1(filter(paths, function(p, index) {
  26975. if (typeof p !== 'string') {
  26976. throw new TypeError('Arguments to path.join must be strings');
  26977. }
  26978. return p;
  26979. }).join('/'));
  26980. }
  26981. // path.relative(from, to)
  26982. // posix version
  26983. function relative(from, to) {
  26984. from = resolve(from).substr(1);
  26985. to = resolve(to).substr(1);
  26986. function trim(arr) {
  26987. var start = 0;
  26988. for (; start < arr.length; start++) {
  26989. if (arr[start] !== '') break;
  26990. }
  26991. var end = arr.length - 1;
  26992. for (; end >= 0; end--) {
  26993. if (arr[end] !== '') break;
  26994. }
  26995. if (start > end) return [];
  26996. return arr.slice(start, end - start + 1);
  26997. }
  26998. var fromParts = trim(from.split('/'));
  26999. var toParts = trim(to.split('/'));
  27000. var length = Math.min(fromParts.length, toParts.length);
  27001. var samePartsLength = length;
  27002. for (var i = 0; i < length; i++) {
  27003. if (fromParts[i] !== toParts[i]) {
  27004. samePartsLength = i;
  27005. break;
  27006. }
  27007. }
  27008. var outputParts = [];
  27009. for (var i = samePartsLength; i < fromParts.length; i++) {
  27010. outputParts.push('..');
  27011. }
  27012. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  27013. return outputParts.join('/');
  27014. }
  27015. var sep = '/';
  27016. var delimiter$1 = ':';
  27017. function dirname(path) {
  27018. var result = splitPath(path),
  27019. root = result[0],
  27020. dir = result[1];
  27021. if (!root && !dir) {
  27022. // No dirname whatsoever
  27023. return '.';
  27024. }
  27025. if (dir) {
  27026. // It has a dirname, strip trailing slash
  27027. dir = dir.substr(0, dir.length - 1);
  27028. }
  27029. return root + dir;
  27030. }
  27031. function basename(path, ext) {
  27032. var f = splitPath(path)[2];
  27033. // TODO: make this comparison case-insensitive on windows?
  27034. if (ext && f.substr(-1 * ext.length) === ext) {
  27035. f = f.substr(0, f.length - ext.length);
  27036. }
  27037. return f;
  27038. }
  27039. function extname(path) {
  27040. return splitPath(path)[3];
  27041. }
  27042. var path = {
  27043. extname: extname,
  27044. basename: basename,
  27045. dirname: dirname,
  27046. sep: sep,
  27047. delimiter: delimiter$1,
  27048. relative: relative,
  27049. join: join,
  27050. isAbsolute: isAbsolute,
  27051. normalize: normalize$1,
  27052. resolve: resolve
  27053. };
  27054. function filter (xs, f) {
  27055. if (xs.filter) return xs.filter(f);
  27056. var res = [];
  27057. for (var i = 0; i < xs.length; i++) {
  27058. if (f(xs[i], i, xs)) res.push(xs[i]);
  27059. }
  27060. return res;
  27061. }
  27062. // String.prototype.substr - negative index don't work in IE8
  27063. var substr = 'ab'.substr(-1) === 'b' ?
  27064. function (str, start, len) { return str.substr(start, len) } :
  27065. function (str, start, len) {
  27066. if (start < 0) start = str.length + start;
  27067. return str.substr(start, len);
  27068. }
  27069. ;
  27070. var _polyfillNode_path = /*#__PURE__*/Object.freeze({
  27071. __proto__: null,
  27072. basename: basename,
  27073. default: path,
  27074. delimiter: delimiter$1,
  27075. dirname: dirname,
  27076. extname: extname,
  27077. isAbsolute: isAbsolute,
  27078. join: join,
  27079. normalize: normalize$1,
  27080. relative: relative,
  27081. resolve: resolve,
  27082. sep: sep
  27083. });
  27084. /*! https://mths.be/punycode v1.4.1 by @mathias */
  27085. /** Highest positive signed 32-bit float value */
  27086. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  27087. /** Bootstring parameters */
  27088. var base = 36;
  27089. var tMin = 1;
  27090. var tMax = 26;
  27091. var skew = 38;
  27092. var damp = 700;
  27093. var initialBias = 72;
  27094. var initialN = 128; // 0x80
  27095. var delimiter = '-'; // '\x2D'
  27096. var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
  27097. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  27098. /** Error messages */
  27099. var errors = {
  27100. 'overflow': 'Overflow: input needs wider integers to process',
  27101. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  27102. 'invalid-input': 'Invalid input'
  27103. };
  27104. /** Convenience shortcuts */
  27105. var baseMinusTMin = base - tMin;
  27106. var floor = Math.floor;
  27107. var stringFromCharCode = String.fromCharCode;
  27108. /*--------------------------------------------------------------------------*/
  27109. /**
  27110. * A generic error utility function.
  27111. * @private
  27112. * @param {String} type The error type.
  27113. * @returns {Error} Throws a `RangeError` with the applicable error message.
  27114. */
  27115. function error(type) {
  27116. throw new RangeError(errors[type]);
  27117. }
  27118. /**
  27119. * A generic `Array#map` utility function.
  27120. * @private
  27121. * @param {Array} array The array to iterate over.
  27122. * @param {Function} callback The function that gets called for every array
  27123. * item.
  27124. * @returns {Array} A new array of values returned by the callback function.
  27125. */
  27126. function map$1(array, fn) {
  27127. var length = array.length;
  27128. var result = [];
  27129. while (length--) {
  27130. result[length] = fn(array[length]);
  27131. }
  27132. return result;
  27133. }
  27134. /**
  27135. * A simple `Array#map`-like wrapper to work with domain name strings or email
  27136. * addresses.
  27137. * @private
  27138. * @param {String} domain The domain name or email address.
  27139. * @param {Function} callback The function that gets called for every
  27140. * character.
  27141. * @returns {Array} A new string of characters returned by the callback
  27142. * function.
  27143. */
  27144. function mapDomain(string, fn) {
  27145. var parts = string.split('@');
  27146. var result = '';
  27147. if (parts.length > 1) {
  27148. // In email addresses, only the domain name should be punycoded. Leave
  27149. // the local part (i.e. everything up to `@`) intact.
  27150. result = parts[0] + '@';
  27151. string = parts[1];
  27152. }
  27153. // Avoid `split(regex)` for IE8 compatibility. See #17.
  27154. string = string.replace(regexSeparators, '\x2E');
  27155. var labels = string.split('.');
  27156. var encoded = map$1(labels, fn).join('.');
  27157. return result + encoded;
  27158. }
  27159. /**
  27160. * Creates an array containing the numeric code points of each Unicode
  27161. * character in the string. While JavaScript uses UCS-2 internally,
  27162. * this function will convert a pair of surrogate halves (each of which
  27163. * UCS-2 exposes as separate characters) into a single code point,
  27164. * matching UTF-16.
  27165. * @see `punycode.ucs2.encode`
  27166. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  27167. * @memberOf punycode.ucs2
  27168. * @name decode
  27169. * @param {String} string The Unicode input string (UCS-2).
  27170. * @returns {Array} The new array of code points.
  27171. */
  27172. function ucs2decode(string) {
  27173. var output = [],
  27174. counter = 0,
  27175. length = string.length,
  27176. value,
  27177. extra;
  27178. while (counter < length) {
  27179. value = string.charCodeAt(counter++);
  27180. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  27181. // high surrogate, and there is a next character
  27182. extra = string.charCodeAt(counter++);
  27183. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  27184. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  27185. } else {
  27186. // unmatched surrogate; only append this code unit, in case the next
  27187. // code unit is the high surrogate of a surrogate pair
  27188. output.push(value);
  27189. counter--;
  27190. }
  27191. } else {
  27192. output.push(value);
  27193. }
  27194. }
  27195. return output;
  27196. }
  27197. /**
  27198. * Converts a digit/integer into a basic code point.
  27199. * @see `basicToDigit()`
  27200. * @private
  27201. * @param {Number} digit The numeric value of a basic code point.
  27202. * @returns {Number} The basic code point whose value (when used for
  27203. * representing integers) is `digit`, which needs to be in the range
  27204. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  27205. * used; else, the lowercase form is used. The behavior is undefined
  27206. * if `flag` is non-zero and `digit` has no uppercase form.
  27207. */
  27208. function digitToBasic(digit, flag) {
  27209. // 0..25 map to ASCII a..z or A..Z
  27210. // 26..35 map to ASCII 0..9
  27211. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  27212. }
  27213. /**
  27214. * Bias adaptation function as per section 3.4 of RFC 3492.
  27215. * https://tools.ietf.org/html/rfc3492#section-3.4
  27216. * @private
  27217. */
  27218. function adapt(delta, numPoints, firstTime) {
  27219. var k = 0;
  27220. delta = firstTime ? floor(delta / damp) : delta >> 1;
  27221. delta += floor(delta / numPoints);
  27222. for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
  27223. delta = floor(delta / baseMinusTMin);
  27224. }
  27225. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  27226. }
  27227. /**
  27228. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  27229. * Punycode string of ASCII-only symbols.
  27230. * @memberOf punycode
  27231. * @param {String} input The string of Unicode symbols.
  27232. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  27233. */
  27234. function encode$1(input) {
  27235. var n,
  27236. delta,
  27237. handledCPCount,
  27238. basicLength,
  27239. bias,
  27240. j,
  27241. m,
  27242. q,
  27243. k,
  27244. t,
  27245. currentValue,
  27246. output = [],
  27247. /** `inputLength` will hold the number of code points in `input`. */
  27248. inputLength,
  27249. /** Cached calculation results */
  27250. handledCPCountPlusOne,
  27251. baseMinusT,
  27252. qMinusT;
  27253. // Convert the input in UCS-2 to Unicode
  27254. input = ucs2decode(input);
  27255. // Cache the length
  27256. inputLength = input.length;
  27257. // Initialize the state
  27258. n = initialN;
  27259. delta = 0;
  27260. bias = initialBias;
  27261. // Handle the basic code points
  27262. for (j = 0; j < inputLength; ++j) {
  27263. currentValue = input[j];
  27264. if (currentValue < 0x80) {
  27265. output.push(stringFromCharCode(currentValue));
  27266. }
  27267. }
  27268. handledCPCount = basicLength = output.length;
  27269. // `handledCPCount` is the number of code points that have been handled;
  27270. // `basicLength` is the number of basic code points.
  27271. // Finish the basic string - if it is not empty - with a delimiter
  27272. if (basicLength) {
  27273. output.push(delimiter);
  27274. }
  27275. // Main encoding loop:
  27276. while (handledCPCount < inputLength) {
  27277. // All non-basic code points < n have been handled already. Find the next
  27278. // larger one:
  27279. for (m = maxInt, j = 0; j < inputLength; ++j) {
  27280. currentValue = input[j];
  27281. if (currentValue >= n && currentValue < m) {
  27282. m = currentValue;
  27283. }
  27284. }
  27285. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  27286. // but guard against overflow
  27287. handledCPCountPlusOne = handledCPCount + 1;
  27288. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  27289. error('overflow');
  27290. }
  27291. delta += (m - n) * handledCPCountPlusOne;
  27292. n = m;
  27293. for (j = 0; j < inputLength; ++j) {
  27294. currentValue = input[j];
  27295. if (currentValue < n && ++delta > maxInt) {
  27296. error('overflow');
  27297. }
  27298. if (currentValue == n) {
  27299. // Represent delta as a generalized variable-length integer
  27300. for (q = delta, k = base; /* no condition */ ; k += base) {
  27301. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  27302. if (q < t) {
  27303. break;
  27304. }
  27305. qMinusT = q - t;
  27306. baseMinusT = base - t;
  27307. output.push(
  27308. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  27309. );
  27310. q = floor(qMinusT / baseMinusT);
  27311. }
  27312. output.push(stringFromCharCode(digitToBasic(q, 0)));
  27313. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  27314. delta = 0;
  27315. ++handledCPCount;
  27316. }
  27317. }
  27318. ++delta;
  27319. ++n;
  27320. }
  27321. return output.join('');
  27322. }
  27323. /**
  27324. * Converts a Unicode string representing a domain name or an email address to
  27325. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  27326. * i.e. it doesn't matter if you call it with a domain that's already in
  27327. * ASCII.
  27328. * @memberOf punycode
  27329. * @param {String} input The domain name or email address to convert, as a
  27330. * Unicode string.
  27331. * @returns {String} The Punycode representation of the given domain name or
  27332. * email address.
  27333. */
  27334. function toASCII(input) {
  27335. return mapDomain(input, function(string) {
  27336. return regexNonASCII.test(string) ?
  27337. 'xn--' + encode$1(string) :
  27338. string;
  27339. });
  27340. }
  27341. var lookup = [];
  27342. var revLookup = [];
  27343. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  27344. var inited = false;
  27345. function init () {
  27346. inited = true;
  27347. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  27348. for (var i = 0, len = code.length; i < len; ++i) {
  27349. lookup[i] = code[i];
  27350. revLookup[code.charCodeAt(i)] = i;
  27351. }
  27352. revLookup['-'.charCodeAt(0)] = 62;
  27353. revLookup['_'.charCodeAt(0)] = 63;
  27354. }
  27355. function toByteArray (b64) {
  27356. if (!inited) {
  27357. init();
  27358. }
  27359. var i, j, l, tmp, placeHolders, arr;
  27360. var len = b64.length;
  27361. if (len % 4 > 0) {
  27362. throw new Error('Invalid string. Length must be a multiple of 4')
  27363. }
  27364. // the number of equal signs (place holders)
  27365. // if there are two placeholders, than the two characters before it
  27366. // represent one byte
  27367. // if there is only one, then the three characters before it represent 2 bytes
  27368. // this is just a cheap hack to not do indexOf twice
  27369. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  27370. // base64 is 4/3 + up to two characters of the original data
  27371. arr = new Arr(len * 3 / 4 - placeHolders);
  27372. // if there are placeholders, only get up to the last complete 4 chars
  27373. l = placeHolders > 0 ? len - 4 : len;
  27374. var L = 0;
  27375. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  27376. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  27377. arr[L++] = (tmp >> 16) & 0xFF;
  27378. arr[L++] = (tmp >> 8) & 0xFF;
  27379. arr[L++] = tmp & 0xFF;
  27380. }
  27381. if (placeHolders === 2) {
  27382. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  27383. arr[L++] = tmp & 0xFF;
  27384. } else if (placeHolders === 1) {
  27385. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  27386. arr[L++] = (tmp >> 8) & 0xFF;
  27387. arr[L++] = tmp & 0xFF;
  27388. }
  27389. return arr
  27390. }
  27391. function tripletToBase64 (num) {
  27392. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  27393. }
  27394. function encodeChunk (uint8, start, end) {
  27395. var tmp;
  27396. var output = [];
  27397. for (var i = start; i < end; i += 3) {
  27398. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  27399. output.push(tripletToBase64(tmp));
  27400. }
  27401. return output.join('')
  27402. }
  27403. function fromByteArray (uint8) {
  27404. if (!inited) {
  27405. init();
  27406. }
  27407. var tmp;
  27408. var len = uint8.length;
  27409. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  27410. var output = '';
  27411. var parts = [];
  27412. var maxChunkLength = 16383; // must be multiple of 3
  27413. // go through the array every three bytes, we'll deal with trailing stuff later
  27414. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  27415. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  27416. }
  27417. // pad the end with zeros, but make sure to not forget the extra bytes
  27418. if (extraBytes === 1) {
  27419. tmp = uint8[len - 1];
  27420. output += lookup[tmp >> 2];
  27421. output += lookup[(tmp << 4) & 0x3F];
  27422. output += '==';
  27423. } else if (extraBytes === 2) {
  27424. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  27425. output += lookup[tmp >> 10];
  27426. output += lookup[(tmp >> 4) & 0x3F];
  27427. output += lookup[(tmp << 2) & 0x3F];
  27428. output += '=';
  27429. }
  27430. parts.push(output);
  27431. return parts.join('')
  27432. }
  27433. function read (buffer, offset, isLE, mLen, nBytes) {
  27434. var e, m;
  27435. var eLen = nBytes * 8 - mLen - 1;
  27436. var eMax = (1 << eLen) - 1;
  27437. var eBias = eMax >> 1;
  27438. var nBits = -7;
  27439. var i = isLE ? (nBytes - 1) : 0;
  27440. var d = isLE ? -1 : 1;
  27441. var s = buffer[offset + i];
  27442. i += d;
  27443. e = s & ((1 << (-nBits)) - 1);
  27444. s >>= (-nBits);
  27445. nBits += eLen;
  27446. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27447. m = e & ((1 << (-nBits)) - 1);
  27448. e >>= (-nBits);
  27449. nBits += mLen;
  27450. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  27451. if (e === 0) {
  27452. e = 1 - eBias;
  27453. } else if (e === eMax) {
  27454. return m ? NaN : ((s ? -1 : 1) * Infinity)
  27455. } else {
  27456. m = m + Math.pow(2, mLen);
  27457. e = e - eBias;
  27458. }
  27459. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  27460. }
  27461. function write (buffer, value, offset, isLE, mLen, nBytes) {
  27462. var e, m, c;
  27463. var eLen = nBytes * 8 - mLen - 1;
  27464. var eMax = (1 << eLen) - 1;
  27465. var eBias = eMax >> 1;
  27466. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  27467. var i = isLE ? 0 : (nBytes - 1);
  27468. var d = isLE ? 1 : -1;
  27469. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  27470. value = Math.abs(value);
  27471. if (isNaN(value) || value === Infinity) {
  27472. m = isNaN(value) ? 1 : 0;
  27473. e = eMax;
  27474. } else {
  27475. e = Math.floor(Math.log(value) / Math.LN2);
  27476. if (value * (c = Math.pow(2, -e)) < 1) {
  27477. e--;
  27478. c *= 2;
  27479. }
  27480. if (e + eBias >= 1) {
  27481. value += rt / c;
  27482. } else {
  27483. value += rt * Math.pow(2, 1 - eBias);
  27484. }
  27485. if (value * c >= 2) {
  27486. e++;
  27487. c /= 2;
  27488. }
  27489. if (e + eBias >= eMax) {
  27490. m = 0;
  27491. e = eMax;
  27492. } else if (e + eBias >= 1) {
  27493. m = (value * c - 1) * Math.pow(2, mLen);
  27494. e = e + eBias;
  27495. } else {
  27496. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  27497. e = 0;
  27498. }
  27499. }
  27500. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  27501. e = (e << mLen) | m;
  27502. eLen += mLen;
  27503. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  27504. buffer[offset + i - d] |= s * 128;
  27505. }
  27506. var toString$1 = {}.toString;
  27507. var isArray$2 = Array.isArray || function (arr) {
  27508. return toString$1.call(arr) == '[object Array]';
  27509. };
  27510. /*!
  27511. * The buffer module from node.js, for the browser.
  27512. *
  27513. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  27514. * @license MIT
  27515. */
  27516. /* eslint-disable no-proto */
  27517. var INSPECT_MAX_BYTES = 50;
  27518. /**
  27519. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  27520. * === true Use Uint8Array implementation (fastest)
  27521. * === false Use Object implementation (most compatible, even IE6)
  27522. *
  27523. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  27524. * Opera 11.6+, iOS 4.2+.
  27525. *
  27526. * Due to various browser bugs, sometimes the Object implementation will be used even
  27527. * when the browser supports typed arrays.
  27528. *
  27529. * Note:
  27530. *
  27531. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  27532. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  27533. *
  27534. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  27535. *
  27536. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  27537. * incorrect length in some situations.
  27538. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  27539. * get the Object implementation, which is slower but behaves correctly.
  27540. */
  27541. Buffer$1.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  27542. ? global$1.TYPED_ARRAY_SUPPORT
  27543. : true;
  27544. /*
  27545. * Export kMaxLength after typed array support is determined.
  27546. */
  27547. kMaxLength();
  27548. function kMaxLength () {
  27549. return Buffer$1.TYPED_ARRAY_SUPPORT
  27550. ? 0x7fffffff
  27551. : 0x3fffffff
  27552. }
  27553. function createBuffer (that, length) {
  27554. if (kMaxLength() < length) {
  27555. throw new RangeError('Invalid typed array length')
  27556. }
  27557. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27558. // Return an augmented `Uint8Array` instance, for best performance
  27559. that = new Uint8Array(length);
  27560. that.__proto__ = Buffer$1.prototype;
  27561. } else {
  27562. // Fallback: Return an object instance of the Buffer class
  27563. if (that === null) {
  27564. that = new Buffer$1(length);
  27565. }
  27566. that.length = length;
  27567. }
  27568. return that
  27569. }
  27570. /**
  27571. * The Buffer constructor returns instances of `Uint8Array` that have their
  27572. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  27573. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  27574. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  27575. * returns a single octet.
  27576. *
  27577. * The `Uint8Array` prototype remains unmodified.
  27578. */
  27579. function Buffer$1 (arg, encodingOrOffset, length) {
  27580. if (!Buffer$1.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer$1)) {
  27581. return new Buffer$1(arg, encodingOrOffset, length)
  27582. }
  27583. // Common case.
  27584. if (typeof arg === 'number') {
  27585. if (typeof encodingOrOffset === 'string') {
  27586. throw new Error(
  27587. 'If encoding is specified then the first argument must be a string'
  27588. )
  27589. }
  27590. return allocUnsafe(this, arg)
  27591. }
  27592. return from(this, arg, encodingOrOffset, length)
  27593. }
  27594. Buffer$1.poolSize = 8192; // not used by this implementation
  27595. // TODO: Legacy, not needed anymore. Remove in next major version.
  27596. Buffer$1._augment = function (arr) {
  27597. arr.__proto__ = Buffer$1.prototype;
  27598. return arr
  27599. };
  27600. function from (that, value, encodingOrOffset, length) {
  27601. if (typeof value === 'number') {
  27602. throw new TypeError('"value" argument must not be a number')
  27603. }
  27604. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  27605. return fromArrayBuffer(that, value, encodingOrOffset, length)
  27606. }
  27607. if (typeof value === 'string') {
  27608. return fromString(that, value, encodingOrOffset)
  27609. }
  27610. return fromObject(that, value)
  27611. }
  27612. /**
  27613. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  27614. * if value is a number.
  27615. * Buffer.from(str[, encoding])
  27616. * Buffer.from(array)
  27617. * Buffer.from(buffer)
  27618. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  27619. **/
  27620. Buffer$1.from = function (value, encodingOrOffset, length) {
  27621. return from(null, value, encodingOrOffset, length)
  27622. };
  27623. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27624. Buffer$1.prototype.__proto__ = Uint8Array.prototype;
  27625. Buffer$1.__proto__ = Uint8Array;
  27626. if (typeof Symbol !== 'undefined' && Symbol.species &&
  27627. Buffer$1[Symbol.species] === Buffer$1) ;
  27628. }
  27629. function assertSize (size) {
  27630. if (typeof size !== 'number') {
  27631. throw new TypeError('"size" argument must be a number')
  27632. } else if (size < 0) {
  27633. throw new RangeError('"size" argument must not be negative')
  27634. }
  27635. }
  27636. function alloc (that, size, fill, encoding) {
  27637. assertSize(size);
  27638. if (size <= 0) {
  27639. return createBuffer(that, size)
  27640. }
  27641. if (fill !== undefined) {
  27642. // Only pay attention to encoding if it's a string. This
  27643. // prevents accidentally sending in a number that would
  27644. // be interpretted as a start offset.
  27645. return typeof encoding === 'string'
  27646. ? createBuffer(that, size).fill(fill, encoding)
  27647. : createBuffer(that, size).fill(fill)
  27648. }
  27649. return createBuffer(that, size)
  27650. }
  27651. /**
  27652. * Creates a new filled Buffer instance.
  27653. * alloc(size[, fill[, encoding]])
  27654. **/
  27655. Buffer$1.alloc = function (size, fill, encoding) {
  27656. return alloc(null, size, fill, encoding)
  27657. };
  27658. function allocUnsafe (that, size) {
  27659. assertSize(size);
  27660. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  27661. if (!Buffer$1.TYPED_ARRAY_SUPPORT) {
  27662. for (var i = 0; i < size; ++i) {
  27663. that[i] = 0;
  27664. }
  27665. }
  27666. return that
  27667. }
  27668. /**
  27669. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  27670. * */
  27671. Buffer$1.allocUnsafe = function (size) {
  27672. return allocUnsafe(null, size)
  27673. };
  27674. /**
  27675. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  27676. */
  27677. Buffer$1.allocUnsafeSlow = function (size) {
  27678. return allocUnsafe(null, size)
  27679. };
  27680. function fromString (that, string, encoding) {
  27681. if (typeof encoding !== 'string' || encoding === '') {
  27682. encoding = 'utf8';
  27683. }
  27684. if (!Buffer$1.isEncoding(encoding)) {
  27685. throw new TypeError('"encoding" must be a valid string encoding')
  27686. }
  27687. var length = byteLength(string, encoding) | 0;
  27688. that = createBuffer(that, length);
  27689. var actual = that.write(string, encoding);
  27690. if (actual !== length) {
  27691. // Writing a hex string, for example, that contains invalid characters will
  27692. // cause everything after the first invalid character to be ignored. (e.g.
  27693. // 'abxxcd' will be treated as 'ab')
  27694. that = that.slice(0, actual);
  27695. }
  27696. return that
  27697. }
  27698. function fromArrayLike (that, array) {
  27699. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  27700. that = createBuffer(that, length);
  27701. for (var i = 0; i < length; i += 1) {
  27702. that[i] = array[i] & 255;
  27703. }
  27704. return that
  27705. }
  27706. function fromArrayBuffer (that, array, byteOffset, length) {
  27707. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  27708. if (byteOffset < 0 || array.byteLength < byteOffset) {
  27709. throw new RangeError('\'offset\' is out of bounds')
  27710. }
  27711. if (array.byteLength < byteOffset + (length || 0)) {
  27712. throw new RangeError('\'length\' is out of bounds')
  27713. }
  27714. if (byteOffset === undefined && length === undefined) {
  27715. array = new Uint8Array(array);
  27716. } else if (length === undefined) {
  27717. array = new Uint8Array(array, byteOffset);
  27718. } else {
  27719. array = new Uint8Array(array, byteOffset, length);
  27720. }
  27721. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  27722. // Return an augmented `Uint8Array` instance, for best performance
  27723. that = array;
  27724. that.__proto__ = Buffer$1.prototype;
  27725. } else {
  27726. // Fallback: Return an object instance of the Buffer class
  27727. that = fromArrayLike(that, array);
  27728. }
  27729. return that
  27730. }
  27731. function fromObject (that, obj) {
  27732. if (internalIsBuffer(obj)) {
  27733. var len = checked(obj.length) | 0;
  27734. that = createBuffer(that, len);
  27735. if (that.length === 0) {
  27736. return that
  27737. }
  27738. obj.copy(that, 0, 0, len);
  27739. return that
  27740. }
  27741. if (obj) {
  27742. if ((typeof ArrayBuffer !== 'undefined' &&
  27743. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  27744. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  27745. return createBuffer(that, 0)
  27746. }
  27747. return fromArrayLike(that, obj)
  27748. }
  27749. if (obj.type === 'Buffer' && isArray$2(obj.data)) {
  27750. return fromArrayLike(that, obj.data)
  27751. }
  27752. }
  27753. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  27754. }
  27755. function checked (length) {
  27756. // Note: cannot use `length < kMaxLength()` here because that fails when
  27757. // length is NaN (which is otherwise coerced to zero.)
  27758. if (length >= kMaxLength()) {
  27759. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  27760. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  27761. }
  27762. return length | 0
  27763. }
  27764. Buffer$1.isBuffer = isBuffer$1;
  27765. function internalIsBuffer (b) {
  27766. return !!(b != null && b._isBuffer)
  27767. }
  27768. Buffer$1.compare = function compare (a, b) {
  27769. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  27770. throw new TypeError('Arguments must be Buffers')
  27771. }
  27772. if (a === b) return 0
  27773. var x = a.length;
  27774. var y = b.length;
  27775. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  27776. if (a[i] !== b[i]) {
  27777. x = a[i];
  27778. y = b[i];
  27779. break
  27780. }
  27781. }
  27782. if (x < y) return -1
  27783. if (y < x) return 1
  27784. return 0
  27785. };
  27786. Buffer$1.isEncoding = function isEncoding (encoding) {
  27787. switch (String(encoding).toLowerCase()) {
  27788. case 'hex':
  27789. case 'utf8':
  27790. case 'utf-8':
  27791. case 'ascii':
  27792. case 'latin1':
  27793. case 'binary':
  27794. case 'base64':
  27795. case 'ucs2':
  27796. case 'ucs-2':
  27797. case 'utf16le':
  27798. case 'utf-16le':
  27799. return true
  27800. default:
  27801. return false
  27802. }
  27803. };
  27804. Buffer$1.concat = function concat (list, length) {
  27805. if (!isArray$2(list)) {
  27806. throw new TypeError('"list" argument must be an Array of Buffers')
  27807. }
  27808. if (list.length === 0) {
  27809. return Buffer$1.alloc(0)
  27810. }
  27811. var i;
  27812. if (length === undefined) {
  27813. length = 0;
  27814. for (i = 0; i < list.length; ++i) {
  27815. length += list[i].length;
  27816. }
  27817. }
  27818. var buffer = Buffer$1.allocUnsafe(length);
  27819. var pos = 0;
  27820. for (i = 0; i < list.length; ++i) {
  27821. var buf = list[i];
  27822. if (!internalIsBuffer(buf)) {
  27823. throw new TypeError('"list" argument must be an Array of Buffers')
  27824. }
  27825. buf.copy(buffer, pos);
  27826. pos += buf.length;
  27827. }
  27828. return buffer
  27829. };
  27830. function byteLength (string, encoding) {
  27831. if (internalIsBuffer(string)) {
  27832. return string.length
  27833. }
  27834. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  27835. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  27836. return string.byteLength
  27837. }
  27838. if (typeof string !== 'string') {
  27839. string = '' + string;
  27840. }
  27841. var len = string.length;
  27842. if (len === 0) return 0
  27843. // Use a for loop to avoid recursion
  27844. var loweredCase = false;
  27845. for (;;) {
  27846. switch (encoding) {
  27847. case 'ascii':
  27848. case 'latin1':
  27849. case 'binary':
  27850. return len
  27851. case 'utf8':
  27852. case 'utf-8':
  27853. case undefined:
  27854. return utf8ToBytes(string).length
  27855. case 'ucs2':
  27856. case 'ucs-2':
  27857. case 'utf16le':
  27858. case 'utf-16le':
  27859. return len * 2
  27860. case 'hex':
  27861. return len >>> 1
  27862. case 'base64':
  27863. return base64ToBytes(string).length
  27864. default:
  27865. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  27866. encoding = ('' + encoding).toLowerCase();
  27867. loweredCase = true;
  27868. }
  27869. }
  27870. }
  27871. Buffer$1.byteLength = byteLength;
  27872. function slowToString (encoding, start, end) {
  27873. var loweredCase = false;
  27874. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  27875. // property of a typed array.
  27876. // This behaves neither like String nor Uint8Array in that we set start/end
  27877. // to their upper/lower bounds if the value passed is out of range.
  27878. // undefined is handled specially as per ECMA-262 6th Edition,
  27879. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  27880. if (start === undefined || start < 0) {
  27881. start = 0;
  27882. }
  27883. // Return early if start > this.length. Done here to prevent potential uint32
  27884. // coercion fail below.
  27885. if (start > this.length) {
  27886. return ''
  27887. }
  27888. if (end === undefined || end > this.length) {
  27889. end = this.length;
  27890. }
  27891. if (end <= 0) {
  27892. return ''
  27893. }
  27894. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  27895. end >>>= 0;
  27896. start >>>= 0;
  27897. if (end <= start) {
  27898. return ''
  27899. }
  27900. if (!encoding) encoding = 'utf8';
  27901. while (true) {
  27902. switch (encoding) {
  27903. case 'hex':
  27904. return hexSlice(this, start, end)
  27905. case 'utf8':
  27906. case 'utf-8':
  27907. return utf8Slice(this, start, end)
  27908. case 'ascii':
  27909. return asciiSlice(this, start, end)
  27910. case 'latin1':
  27911. case 'binary':
  27912. return latin1Slice(this, start, end)
  27913. case 'base64':
  27914. return base64Slice(this, start, end)
  27915. case 'ucs2':
  27916. case 'ucs-2':
  27917. case 'utf16le':
  27918. case 'utf-16le':
  27919. return utf16leSlice(this, start, end)
  27920. default:
  27921. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  27922. encoding = (encoding + '').toLowerCase();
  27923. loweredCase = true;
  27924. }
  27925. }
  27926. }
  27927. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  27928. // Buffer instances.
  27929. Buffer$1.prototype._isBuffer = true;
  27930. function swap (b, n, m) {
  27931. var i = b[n];
  27932. b[n] = b[m];
  27933. b[m] = i;
  27934. }
  27935. Buffer$1.prototype.swap16 = function swap16 () {
  27936. var len = this.length;
  27937. if (len % 2 !== 0) {
  27938. throw new RangeError('Buffer size must be a multiple of 16-bits')
  27939. }
  27940. for (var i = 0; i < len; i += 2) {
  27941. swap(this, i, i + 1);
  27942. }
  27943. return this
  27944. };
  27945. Buffer$1.prototype.swap32 = function swap32 () {
  27946. var len = this.length;
  27947. if (len % 4 !== 0) {
  27948. throw new RangeError('Buffer size must be a multiple of 32-bits')
  27949. }
  27950. for (var i = 0; i < len; i += 4) {
  27951. swap(this, i, i + 3);
  27952. swap(this, i + 1, i + 2);
  27953. }
  27954. return this
  27955. };
  27956. Buffer$1.prototype.swap64 = function swap64 () {
  27957. var len = this.length;
  27958. if (len % 8 !== 0) {
  27959. throw new RangeError('Buffer size must be a multiple of 64-bits')
  27960. }
  27961. for (var i = 0; i < len; i += 8) {
  27962. swap(this, i, i + 7);
  27963. swap(this, i + 1, i + 6);
  27964. swap(this, i + 2, i + 5);
  27965. swap(this, i + 3, i + 4);
  27966. }
  27967. return this
  27968. };
  27969. Buffer$1.prototype.toString = function toString () {
  27970. var length = this.length | 0;
  27971. if (length === 0) return ''
  27972. if (arguments.length === 0) return utf8Slice(this, 0, length)
  27973. return slowToString.apply(this, arguments)
  27974. };
  27975. Buffer$1.prototype.equals = function equals (b) {
  27976. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  27977. if (this === b) return true
  27978. return Buffer$1.compare(this, b) === 0
  27979. };
  27980. Buffer$1.prototype.inspect = function inspect () {
  27981. var str = '';
  27982. var max = INSPECT_MAX_BYTES;
  27983. if (this.length > 0) {
  27984. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  27985. if (this.length > max) str += ' ... ';
  27986. }
  27987. return '<Buffer ' + str + '>'
  27988. };
  27989. Buffer$1.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  27990. if (!internalIsBuffer(target)) {
  27991. throw new TypeError('Argument must be a Buffer')
  27992. }
  27993. if (start === undefined) {
  27994. start = 0;
  27995. }
  27996. if (end === undefined) {
  27997. end = target ? target.length : 0;
  27998. }
  27999. if (thisStart === undefined) {
  28000. thisStart = 0;
  28001. }
  28002. if (thisEnd === undefined) {
  28003. thisEnd = this.length;
  28004. }
  28005. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  28006. throw new RangeError('out of range index')
  28007. }
  28008. if (thisStart >= thisEnd && start >= end) {
  28009. return 0
  28010. }
  28011. if (thisStart >= thisEnd) {
  28012. return -1
  28013. }
  28014. if (start >= end) {
  28015. return 1
  28016. }
  28017. start >>>= 0;
  28018. end >>>= 0;
  28019. thisStart >>>= 0;
  28020. thisEnd >>>= 0;
  28021. if (this === target) return 0
  28022. var x = thisEnd - thisStart;
  28023. var y = end - start;
  28024. var len = Math.min(x, y);
  28025. var thisCopy = this.slice(thisStart, thisEnd);
  28026. var targetCopy = target.slice(start, end);
  28027. for (var i = 0; i < len; ++i) {
  28028. if (thisCopy[i] !== targetCopy[i]) {
  28029. x = thisCopy[i];
  28030. y = targetCopy[i];
  28031. break
  28032. }
  28033. }
  28034. if (x < y) return -1
  28035. if (y < x) return 1
  28036. return 0
  28037. };
  28038. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  28039. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  28040. //
  28041. // Arguments:
  28042. // - buffer - a Buffer to search
  28043. // - val - a string, Buffer, or number
  28044. // - byteOffset - an index into `buffer`; will be clamped to an int32
  28045. // - encoding - an optional encoding, relevant is val is a string
  28046. // - dir - true for indexOf, false for lastIndexOf
  28047. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  28048. // Empty buffer means no match
  28049. if (buffer.length === 0) return -1
  28050. // Normalize byteOffset
  28051. if (typeof byteOffset === 'string') {
  28052. encoding = byteOffset;
  28053. byteOffset = 0;
  28054. } else if (byteOffset > 0x7fffffff) {
  28055. byteOffset = 0x7fffffff;
  28056. } else if (byteOffset < -2147483648) {
  28057. byteOffset = -2147483648;
  28058. }
  28059. byteOffset = +byteOffset; // Coerce to Number.
  28060. if (isNaN(byteOffset)) {
  28061. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  28062. byteOffset = dir ? 0 : (buffer.length - 1);
  28063. }
  28064. // Normalize byteOffset: negative offsets start from the end of the buffer
  28065. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  28066. if (byteOffset >= buffer.length) {
  28067. if (dir) return -1
  28068. else byteOffset = buffer.length - 1;
  28069. } else if (byteOffset < 0) {
  28070. if (dir) byteOffset = 0;
  28071. else return -1
  28072. }
  28073. // Normalize val
  28074. if (typeof val === 'string') {
  28075. val = Buffer$1.from(val, encoding);
  28076. }
  28077. // Finally, search either indexOf (if dir is true) or lastIndexOf
  28078. if (internalIsBuffer(val)) {
  28079. // Special case: looking for empty string/buffer always fails
  28080. if (val.length === 0) {
  28081. return -1
  28082. }
  28083. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  28084. } else if (typeof val === 'number') {
  28085. val = val & 0xFF; // Search for a byte value [0-255]
  28086. if (Buffer$1.TYPED_ARRAY_SUPPORT &&
  28087. typeof Uint8Array.prototype.indexOf === 'function') {
  28088. if (dir) {
  28089. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  28090. } else {
  28091. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  28092. }
  28093. }
  28094. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  28095. }
  28096. throw new TypeError('val must be string, number or Buffer')
  28097. }
  28098. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  28099. var indexSize = 1;
  28100. var arrLength = arr.length;
  28101. var valLength = val.length;
  28102. if (encoding !== undefined) {
  28103. encoding = String(encoding).toLowerCase();
  28104. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  28105. encoding === 'utf16le' || encoding === 'utf-16le') {
  28106. if (arr.length < 2 || val.length < 2) {
  28107. return -1
  28108. }
  28109. indexSize = 2;
  28110. arrLength /= 2;
  28111. valLength /= 2;
  28112. byteOffset /= 2;
  28113. }
  28114. }
  28115. function read (buf, i) {
  28116. if (indexSize === 1) {
  28117. return buf[i]
  28118. } else {
  28119. return buf.readUInt16BE(i * indexSize)
  28120. }
  28121. }
  28122. var i;
  28123. if (dir) {
  28124. var foundIndex = -1;
  28125. for (i = byteOffset; i < arrLength; i++) {
  28126. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  28127. if (foundIndex === -1) foundIndex = i;
  28128. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  28129. } else {
  28130. if (foundIndex !== -1) i -= i - foundIndex;
  28131. foundIndex = -1;
  28132. }
  28133. }
  28134. } else {
  28135. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  28136. for (i = byteOffset; i >= 0; i--) {
  28137. var found = true;
  28138. for (var j = 0; j < valLength; j++) {
  28139. if (read(arr, i + j) !== read(val, j)) {
  28140. found = false;
  28141. break
  28142. }
  28143. }
  28144. if (found) return i
  28145. }
  28146. }
  28147. return -1
  28148. }
  28149. Buffer$1.prototype.includes = function includes (val, byteOffset, encoding) {
  28150. return this.indexOf(val, byteOffset, encoding) !== -1
  28151. };
  28152. Buffer$1.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  28153. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  28154. };
  28155. Buffer$1.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  28156. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  28157. };
  28158. function hexWrite (buf, string, offset, length) {
  28159. offset = Number(offset) || 0;
  28160. var remaining = buf.length - offset;
  28161. if (!length) {
  28162. length = remaining;
  28163. } else {
  28164. length = Number(length);
  28165. if (length > remaining) {
  28166. length = remaining;
  28167. }
  28168. }
  28169. // must be an even number of digits
  28170. var strLen = string.length;
  28171. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  28172. if (length > strLen / 2) {
  28173. length = strLen / 2;
  28174. }
  28175. for (var i = 0; i < length; ++i) {
  28176. var parsed = parseInt(string.substr(i * 2, 2), 16);
  28177. if (isNaN(parsed)) return i
  28178. buf[offset + i] = parsed;
  28179. }
  28180. return i
  28181. }
  28182. function utf8Write (buf, string, offset, length) {
  28183. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  28184. }
  28185. function asciiWrite (buf, string, offset, length) {
  28186. return blitBuffer(asciiToBytes(string), buf, offset, length)
  28187. }
  28188. function latin1Write (buf, string, offset, length) {
  28189. return asciiWrite(buf, string, offset, length)
  28190. }
  28191. function base64Write (buf, string, offset, length) {
  28192. return blitBuffer(base64ToBytes(string), buf, offset, length)
  28193. }
  28194. function ucs2Write (buf, string, offset, length) {
  28195. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  28196. }
  28197. Buffer$1.prototype.write = function write (string, offset, length, encoding) {
  28198. // Buffer#write(string)
  28199. if (offset === undefined) {
  28200. encoding = 'utf8';
  28201. length = this.length;
  28202. offset = 0;
  28203. // Buffer#write(string, encoding)
  28204. } else if (length === undefined && typeof offset === 'string') {
  28205. encoding = offset;
  28206. length = this.length;
  28207. offset = 0;
  28208. // Buffer#write(string, offset[, length][, encoding])
  28209. } else if (isFinite(offset)) {
  28210. offset = offset | 0;
  28211. if (isFinite(length)) {
  28212. length = length | 0;
  28213. if (encoding === undefined) encoding = 'utf8';
  28214. } else {
  28215. encoding = length;
  28216. length = undefined;
  28217. }
  28218. // legacy write(string, encoding, offset, length) - remove in v0.13
  28219. } else {
  28220. throw new Error(
  28221. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  28222. )
  28223. }
  28224. var remaining = this.length - offset;
  28225. if (length === undefined || length > remaining) length = remaining;
  28226. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  28227. throw new RangeError('Attempt to write outside buffer bounds')
  28228. }
  28229. if (!encoding) encoding = 'utf8';
  28230. var loweredCase = false;
  28231. for (;;) {
  28232. switch (encoding) {
  28233. case 'hex':
  28234. return hexWrite(this, string, offset, length)
  28235. case 'utf8':
  28236. case 'utf-8':
  28237. return utf8Write(this, string, offset, length)
  28238. case 'ascii':
  28239. return asciiWrite(this, string, offset, length)
  28240. case 'latin1':
  28241. case 'binary':
  28242. return latin1Write(this, string, offset, length)
  28243. case 'base64':
  28244. // Warning: maxLength not taken into account in base64Write
  28245. return base64Write(this, string, offset, length)
  28246. case 'ucs2':
  28247. case 'ucs-2':
  28248. case 'utf16le':
  28249. case 'utf-16le':
  28250. return ucs2Write(this, string, offset, length)
  28251. default:
  28252. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  28253. encoding = ('' + encoding).toLowerCase();
  28254. loweredCase = true;
  28255. }
  28256. }
  28257. };
  28258. Buffer$1.prototype.toJSON = function toJSON () {
  28259. return {
  28260. type: 'Buffer',
  28261. data: Array.prototype.slice.call(this._arr || this, 0)
  28262. }
  28263. };
  28264. function base64Slice (buf, start, end) {
  28265. if (start === 0 && end === buf.length) {
  28266. return fromByteArray(buf)
  28267. } else {
  28268. return fromByteArray(buf.slice(start, end))
  28269. }
  28270. }
  28271. function utf8Slice (buf, start, end) {
  28272. end = Math.min(buf.length, end);
  28273. var res = [];
  28274. var i = start;
  28275. while (i < end) {
  28276. var firstByte = buf[i];
  28277. var codePoint = null;
  28278. var bytesPerSequence = (firstByte > 0xEF) ? 4
  28279. : (firstByte > 0xDF) ? 3
  28280. : (firstByte > 0xBF) ? 2
  28281. : 1;
  28282. if (i + bytesPerSequence <= end) {
  28283. var secondByte, thirdByte, fourthByte, tempCodePoint;
  28284. switch (bytesPerSequence) {
  28285. case 1:
  28286. if (firstByte < 0x80) {
  28287. codePoint = firstByte;
  28288. }
  28289. break
  28290. case 2:
  28291. secondByte = buf[i + 1];
  28292. if ((secondByte & 0xC0) === 0x80) {
  28293. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  28294. if (tempCodePoint > 0x7F) {
  28295. codePoint = tempCodePoint;
  28296. }
  28297. }
  28298. break
  28299. case 3:
  28300. secondByte = buf[i + 1];
  28301. thirdByte = buf[i + 2];
  28302. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  28303. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  28304. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  28305. codePoint = tempCodePoint;
  28306. }
  28307. }
  28308. break
  28309. case 4:
  28310. secondByte = buf[i + 1];
  28311. thirdByte = buf[i + 2];
  28312. fourthByte = buf[i + 3];
  28313. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  28314. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  28315. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  28316. codePoint = tempCodePoint;
  28317. }
  28318. }
  28319. }
  28320. }
  28321. if (codePoint === null) {
  28322. // we did not generate a valid codePoint so insert a
  28323. // replacement char (U+FFFD) and advance only 1 byte
  28324. codePoint = 0xFFFD;
  28325. bytesPerSequence = 1;
  28326. } else if (codePoint > 0xFFFF) {
  28327. // encode to utf16 (surrogate pair dance)
  28328. codePoint -= 0x10000;
  28329. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  28330. codePoint = 0xDC00 | codePoint & 0x3FF;
  28331. }
  28332. res.push(codePoint);
  28333. i += bytesPerSequence;
  28334. }
  28335. return decodeCodePointsArray(res)
  28336. }
  28337. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  28338. // the lowest limit is Chrome, with 0x10000 args.
  28339. // We go 1 magnitude less, for safety
  28340. var MAX_ARGUMENTS_LENGTH = 0x1000;
  28341. function decodeCodePointsArray (codePoints) {
  28342. var len = codePoints.length;
  28343. if (len <= MAX_ARGUMENTS_LENGTH) {
  28344. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  28345. }
  28346. // Decode in chunks to avoid "call stack size exceeded".
  28347. var res = '';
  28348. var i = 0;
  28349. while (i < len) {
  28350. res += String.fromCharCode.apply(
  28351. String,
  28352. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  28353. );
  28354. }
  28355. return res
  28356. }
  28357. function asciiSlice (buf, start, end) {
  28358. var ret = '';
  28359. end = Math.min(buf.length, end);
  28360. for (var i = start; i < end; ++i) {
  28361. ret += String.fromCharCode(buf[i] & 0x7F);
  28362. }
  28363. return ret
  28364. }
  28365. function latin1Slice (buf, start, end) {
  28366. var ret = '';
  28367. end = Math.min(buf.length, end);
  28368. for (var i = start; i < end; ++i) {
  28369. ret += String.fromCharCode(buf[i]);
  28370. }
  28371. return ret
  28372. }
  28373. function hexSlice (buf, start, end) {
  28374. var len = buf.length;
  28375. if (!start || start < 0) start = 0;
  28376. if (!end || end < 0 || end > len) end = len;
  28377. var out = '';
  28378. for (var i = start; i < end; ++i) {
  28379. out += toHex(buf[i]);
  28380. }
  28381. return out
  28382. }
  28383. function utf16leSlice (buf, start, end) {
  28384. var bytes = buf.slice(start, end);
  28385. var res = '';
  28386. for (var i = 0; i < bytes.length; i += 2) {
  28387. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  28388. }
  28389. return res
  28390. }
  28391. Buffer$1.prototype.slice = function slice (start, end) {
  28392. var len = this.length;
  28393. start = ~~start;
  28394. end = end === undefined ? len : ~~end;
  28395. if (start < 0) {
  28396. start += len;
  28397. if (start < 0) start = 0;
  28398. } else if (start > len) {
  28399. start = len;
  28400. }
  28401. if (end < 0) {
  28402. end += len;
  28403. if (end < 0) end = 0;
  28404. } else if (end > len) {
  28405. end = len;
  28406. }
  28407. if (end < start) end = start;
  28408. var newBuf;
  28409. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28410. newBuf = this.subarray(start, end);
  28411. newBuf.__proto__ = Buffer$1.prototype;
  28412. } else {
  28413. var sliceLen = end - start;
  28414. newBuf = new Buffer$1(sliceLen, undefined);
  28415. for (var i = 0; i < sliceLen; ++i) {
  28416. newBuf[i] = this[i + start];
  28417. }
  28418. }
  28419. return newBuf
  28420. };
  28421. /*
  28422. * Need to make sure that buffer isn't trying to write out of bounds.
  28423. */
  28424. function checkOffset (offset, ext, length) {
  28425. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  28426. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  28427. }
  28428. Buffer$1.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  28429. offset = offset | 0;
  28430. byteLength = byteLength | 0;
  28431. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28432. var val = this[offset];
  28433. var mul = 1;
  28434. var i = 0;
  28435. while (++i < byteLength && (mul *= 0x100)) {
  28436. val += this[offset + i] * mul;
  28437. }
  28438. return val
  28439. };
  28440. Buffer$1.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  28441. offset = offset | 0;
  28442. byteLength = byteLength | 0;
  28443. if (!noAssert) {
  28444. checkOffset(offset, byteLength, this.length);
  28445. }
  28446. var val = this[offset + --byteLength];
  28447. var mul = 1;
  28448. while (byteLength > 0 && (mul *= 0x100)) {
  28449. val += this[offset + --byteLength] * mul;
  28450. }
  28451. return val
  28452. };
  28453. Buffer$1.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  28454. if (!noAssert) checkOffset(offset, 1, this.length);
  28455. return this[offset]
  28456. };
  28457. Buffer$1.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  28458. if (!noAssert) checkOffset(offset, 2, this.length);
  28459. return this[offset] | (this[offset + 1] << 8)
  28460. };
  28461. Buffer$1.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  28462. if (!noAssert) checkOffset(offset, 2, this.length);
  28463. return (this[offset] << 8) | this[offset + 1]
  28464. };
  28465. Buffer$1.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  28466. if (!noAssert) checkOffset(offset, 4, this.length);
  28467. return ((this[offset]) |
  28468. (this[offset + 1] << 8) |
  28469. (this[offset + 2] << 16)) +
  28470. (this[offset + 3] * 0x1000000)
  28471. };
  28472. Buffer$1.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  28473. if (!noAssert) checkOffset(offset, 4, this.length);
  28474. return (this[offset] * 0x1000000) +
  28475. ((this[offset + 1] << 16) |
  28476. (this[offset + 2] << 8) |
  28477. this[offset + 3])
  28478. };
  28479. Buffer$1.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  28480. offset = offset | 0;
  28481. byteLength = byteLength | 0;
  28482. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28483. var val = this[offset];
  28484. var mul = 1;
  28485. var i = 0;
  28486. while (++i < byteLength && (mul *= 0x100)) {
  28487. val += this[offset + i] * mul;
  28488. }
  28489. mul *= 0x80;
  28490. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28491. return val
  28492. };
  28493. Buffer$1.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  28494. offset = offset | 0;
  28495. byteLength = byteLength | 0;
  28496. if (!noAssert) checkOffset(offset, byteLength, this.length);
  28497. var i = byteLength;
  28498. var mul = 1;
  28499. var val = this[offset + --i];
  28500. while (i > 0 && (mul *= 0x100)) {
  28501. val += this[offset + --i] * mul;
  28502. }
  28503. mul *= 0x80;
  28504. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  28505. return val
  28506. };
  28507. Buffer$1.prototype.readInt8 = function readInt8 (offset, noAssert) {
  28508. if (!noAssert) checkOffset(offset, 1, this.length);
  28509. if (!(this[offset] & 0x80)) return (this[offset])
  28510. return ((0xff - this[offset] + 1) * -1)
  28511. };
  28512. Buffer$1.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  28513. if (!noAssert) checkOffset(offset, 2, this.length);
  28514. var val = this[offset] | (this[offset + 1] << 8);
  28515. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28516. };
  28517. Buffer$1.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  28518. if (!noAssert) checkOffset(offset, 2, this.length);
  28519. var val = this[offset + 1] | (this[offset] << 8);
  28520. return (val & 0x8000) ? val | 0xFFFF0000 : val
  28521. };
  28522. Buffer$1.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  28523. if (!noAssert) checkOffset(offset, 4, this.length);
  28524. return (this[offset]) |
  28525. (this[offset + 1] << 8) |
  28526. (this[offset + 2] << 16) |
  28527. (this[offset + 3] << 24)
  28528. };
  28529. Buffer$1.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  28530. if (!noAssert) checkOffset(offset, 4, this.length);
  28531. return (this[offset] << 24) |
  28532. (this[offset + 1] << 16) |
  28533. (this[offset + 2] << 8) |
  28534. (this[offset + 3])
  28535. };
  28536. Buffer$1.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  28537. if (!noAssert) checkOffset(offset, 4, this.length);
  28538. return read(this, offset, true, 23, 4)
  28539. };
  28540. Buffer$1.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  28541. if (!noAssert) checkOffset(offset, 4, this.length);
  28542. return read(this, offset, false, 23, 4)
  28543. };
  28544. Buffer$1.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  28545. if (!noAssert) checkOffset(offset, 8, this.length);
  28546. return read(this, offset, true, 52, 8)
  28547. };
  28548. Buffer$1.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  28549. if (!noAssert) checkOffset(offset, 8, this.length);
  28550. return read(this, offset, false, 52, 8)
  28551. };
  28552. function checkInt (buf, value, offset, ext, max, min) {
  28553. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  28554. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  28555. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28556. }
  28557. Buffer$1.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  28558. value = +value;
  28559. offset = offset | 0;
  28560. byteLength = byteLength | 0;
  28561. if (!noAssert) {
  28562. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28563. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28564. }
  28565. var mul = 1;
  28566. var i = 0;
  28567. this[offset] = value & 0xFF;
  28568. while (++i < byteLength && (mul *= 0x100)) {
  28569. this[offset + i] = (value / mul) & 0xFF;
  28570. }
  28571. return offset + byteLength
  28572. };
  28573. Buffer$1.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  28574. value = +value;
  28575. offset = offset | 0;
  28576. byteLength = byteLength | 0;
  28577. if (!noAssert) {
  28578. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  28579. checkInt(this, value, offset, byteLength, maxBytes, 0);
  28580. }
  28581. var i = byteLength - 1;
  28582. var mul = 1;
  28583. this[offset + i] = value & 0xFF;
  28584. while (--i >= 0 && (mul *= 0x100)) {
  28585. this[offset + i] = (value / mul) & 0xFF;
  28586. }
  28587. return offset + byteLength
  28588. };
  28589. Buffer$1.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  28590. value = +value;
  28591. offset = offset | 0;
  28592. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  28593. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28594. this[offset] = (value & 0xff);
  28595. return offset + 1
  28596. };
  28597. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  28598. if (value < 0) value = 0xffff + value + 1;
  28599. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  28600. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  28601. (littleEndian ? i : 1 - i) * 8;
  28602. }
  28603. }
  28604. Buffer$1.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  28605. value = +value;
  28606. offset = offset | 0;
  28607. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28608. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28609. this[offset] = (value & 0xff);
  28610. this[offset + 1] = (value >>> 8);
  28611. } else {
  28612. objectWriteUInt16(this, value, offset, true);
  28613. }
  28614. return offset + 2
  28615. };
  28616. Buffer$1.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  28617. value = +value;
  28618. offset = offset | 0;
  28619. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  28620. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28621. this[offset] = (value >>> 8);
  28622. this[offset + 1] = (value & 0xff);
  28623. } else {
  28624. objectWriteUInt16(this, value, offset, false);
  28625. }
  28626. return offset + 2
  28627. };
  28628. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  28629. if (value < 0) value = 0xffffffff + value + 1;
  28630. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  28631. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  28632. }
  28633. }
  28634. Buffer$1.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  28635. value = +value;
  28636. offset = offset | 0;
  28637. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28638. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28639. this[offset + 3] = (value >>> 24);
  28640. this[offset + 2] = (value >>> 16);
  28641. this[offset + 1] = (value >>> 8);
  28642. this[offset] = (value & 0xff);
  28643. } else {
  28644. objectWriteUInt32(this, value, offset, true);
  28645. }
  28646. return offset + 4
  28647. };
  28648. Buffer$1.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  28649. value = +value;
  28650. offset = offset | 0;
  28651. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  28652. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28653. this[offset] = (value >>> 24);
  28654. this[offset + 1] = (value >>> 16);
  28655. this[offset + 2] = (value >>> 8);
  28656. this[offset + 3] = (value & 0xff);
  28657. } else {
  28658. objectWriteUInt32(this, value, offset, false);
  28659. }
  28660. return offset + 4
  28661. };
  28662. Buffer$1.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  28663. value = +value;
  28664. offset = offset | 0;
  28665. if (!noAssert) {
  28666. var limit = Math.pow(2, 8 * byteLength - 1);
  28667. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28668. }
  28669. var i = 0;
  28670. var mul = 1;
  28671. var sub = 0;
  28672. this[offset] = value & 0xFF;
  28673. while (++i < byteLength && (mul *= 0x100)) {
  28674. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  28675. sub = 1;
  28676. }
  28677. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28678. }
  28679. return offset + byteLength
  28680. };
  28681. Buffer$1.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  28682. value = +value;
  28683. offset = offset | 0;
  28684. if (!noAssert) {
  28685. var limit = Math.pow(2, 8 * byteLength - 1);
  28686. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  28687. }
  28688. var i = byteLength - 1;
  28689. var mul = 1;
  28690. var sub = 0;
  28691. this[offset + i] = value & 0xFF;
  28692. while (--i >= 0 && (mul *= 0x100)) {
  28693. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  28694. sub = 1;
  28695. }
  28696. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  28697. }
  28698. return offset + byteLength
  28699. };
  28700. Buffer$1.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  28701. value = +value;
  28702. offset = offset | 0;
  28703. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
  28704. if (!Buffer$1.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  28705. if (value < 0) value = 0xff + value + 1;
  28706. this[offset] = (value & 0xff);
  28707. return offset + 1
  28708. };
  28709. Buffer$1.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  28710. value = +value;
  28711. offset = offset | 0;
  28712. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  28713. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28714. this[offset] = (value & 0xff);
  28715. this[offset + 1] = (value >>> 8);
  28716. } else {
  28717. objectWriteUInt16(this, value, offset, true);
  28718. }
  28719. return offset + 2
  28720. };
  28721. Buffer$1.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  28722. value = +value;
  28723. offset = offset | 0;
  28724. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
  28725. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28726. this[offset] = (value >>> 8);
  28727. this[offset + 1] = (value & 0xff);
  28728. } else {
  28729. objectWriteUInt16(this, value, offset, false);
  28730. }
  28731. return offset + 2
  28732. };
  28733. Buffer$1.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  28734. value = +value;
  28735. offset = offset | 0;
  28736. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  28737. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28738. this[offset] = (value & 0xff);
  28739. this[offset + 1] = (value >>> 8);
  28740. this[offset + 2] = (value >>> 16);
  28741. this[offset + 3] = (value >>> 24);
  28742. } else {
  28743. objectWriteUInt32(this, value, offset, true);
  28744. }
  28745. return offset + 4
  28746. };
  28747. Buffer$1.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  28748. value = +value;
  28749. offset = offset | 0;
  28750. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
  28751. if (value < 0) value = 0xffffffff + value + 1;
  28752. if (Buffer$1.TYPED_ARRAY_SUPPORT) {
  28753. this[offset] = (value >>> 24);
  28754. this[offset + 1] = (value >>> 16);
  28755. this[offset + 2] = (value >>> 8);
  28756. this[offset + 3] = (value & 0xff);
  28757. } else {
  28758. objectWriteUInt32(this, value, offset, false);
  28759. }
  28760. return offset + 4
  28761. };
  28762. function checkIEEE754 (buf, value, offset, ext, max, min) {
  28763. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  28764. if (offset < 0) throw new RangeError('Index out of range')
  28765. }
  28766. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  28767. if (!noAssert) {
  28768. checkIEEE754(buf, value, offset, 4);
  28769. }
  28770. write(buf, value, offset, littleEndian, 23, 4);
  28771. return offset + 4
  28772. }
  28773. Buffer$1.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  28774. return writeFloat(this, value, offset, true, noAssert)
  28775. };
  28776. Buffer$1.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  28777. return writeFloat(this, value, offset, false, noAssert)
  28778. };
  28779. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  28780. if (!noAssert) {
  28781. checkIEEE754(buf, value, offset, 8);
  28782. }
  28783. write(buf, value, offset, littleEndian, 52, 8);
  28784. return offset + 8
  28785. }
  28786. Buffer$1.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  28787. return writeDouble(this, value, offset, true, noAssert)
  28788. };
  28789. Buffer$1.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  28790. return writeDouble(this, value, offset, false, noAssert)
  28791. };
  28792. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  28793. Buffer$1.prototype.copy = function copy (target, targetStart, start, end) {
  28794. if (!start) start = 0;
  28795. if (!end && end !== 0) end = this.length;
  28796. if (targetStart >= target.length) targetStart = target.length;
  28797. if (!targetStart) targetStart = 0;
  28798. if (end > 0 && end < start) end = start;
  28799. // Copy 0 bytes; we're done
  28800. if (end === start) return 0
  28801. if (target.length === 0 || this.length === 0) return 0
  28802. // Fatal error conditions
  28803. if (targetStart < 0) {
  28804. throw new RangeError('targetStart out of bounds')
  28805. }
  28806. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  28807. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  28808. // Are we oob?
  28809. if (end > this.length) end = this.length;
  28810. if (target.length - targetStart < end - start) {
  28811. end = target.length - targetStart + start;
  28812. }
  28813. var len = end - start;
  28814. var i;
  28815. if (this === target && start < targetStart && targetStart < end) {
  28816. // descending copy from end
  28817. for (i = len - 1; i >= 0; --i) {
  28818. target[i + targetStart] = this[i + start];
  28819. }
  28820. } else if (len < 1000 || !Buffer$1.TYPED_ARRAY_SUPPORT) {
  28821. // ascending copy from start
  28822. for (i = 0; i < len; ++i) {
  28823. target[i + targetStart] = this[i + start];
  28824. }
  28825. } else {
  28826. Uint8Array.prototype.set.call(
  28827. target,
  28828. this.subarray(start, start + len),
  28829. targetStart
  28830. );
  28831. }
  28832. return len
  28833. };
  28834. // Usage:
  28835. // buffer.fill(number[, offset[, end]])
  28836. // buffer.fill(buffer[, offset[, end]])
  28837. // buffer.fill(string[, offset[, end]][, encoding])
  28838. Buffer$1.prototype.fill = function fill (val, start, end, encoding) {
  28839. // Handle string cases:
  28840. if (typeof val === 'string') {
  28841. if (typeof start === 'string') {
  28842. encoding = start;
  28843. start = 0;
  28844. end = this.length;
  28845. } else if (typeof end === 'string') {
  28846. encoding = end;
  28847. end = this.length;
  28848. }
  28849. if (val.length === 1) {
  28850. var code = val.charCodeAt(0);
  28851. if (code < 256) {
  28852. val = code;
  28853. }
  28854. }
  28855. if (encoding !== undefined && typeof encoding !== 'string') {
  28856. throw new TypeError('encoding must be a string')
  28857. }
  28858. if (typeof encoding === 'string' && !Buffer$1.isEncoding(encoding)) {
  28859. throw new TypeError('Unknown encoding: ' + encoding)
  28860. }
  28861. } else if (typeof val === 'number') {
  28862. val = val & 255;
  28863. }
  28864. // Invalid ranges are not set to a default, so can range check early.
  28865. if (start < 0 || this.length < start || this.length < end) {
  28866. throw new RangeError('Out of range index')
  28867. }
  28868. if (end <= start) {
  28869. return this
  28870. }
  28871. start = start >>> 0;
  28872. end = end === undefined ? this.length : end >>> 0;
  28873. if (!val) val = 0;
  28874. var i;
  28875. if (typeof val === 'number') {
  28876. for (i = start; i < end; ++i) {
  28877. this[i] = val;
  28878. }
  28879. } else {
  28880. var bytes = internalIsBuffer(val)
  28881. ? val
  28882. : utf8ToBytes(new Buffer$1(val, encoding).toString());
  28883. var len = bytes.length;
  28884. for (i = 0; i < end - start; ++i) {
  28885. this[i + start] = bytes[i % len];
  28886. }
  28887. }
  28888. return this
  28889. };
  28890. // HELPER FUNCTIONS
  28891. // ================
  28892. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  28893. function base64clean (str) {
  28894. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  28895. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  28896. // Node converts strings with length < 2 to ''
  28897. if (str.length < 2) return ''
  28898. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  28899. while (str.length % 4 !== 0) {
  28900. str = str + '=';
  28901. }
  28902. return str
  28903. }
  28904. function stringtrim (str) {
  28905. if (str.trim) return str.trim()
  28906. return str.replace(/^\s+|\s+$/g, '')
  28907. }
  28908. function toHex (n) {
  28909. if (n < 16) return '0' + n.toString(16)
  28910. return n.toString(16)
  28911. }
  28912. function utf8ToBytes (string, units) {
  28913. units = units || Infinity;
  28914. var codePoint;
  28915. var length = string.length;
  28916. var leadSurrogate = null;
  28917. var bytes = [];
  28918. for (var i = 0; i < length; ++i) {
  28919. codePoint = string.charCodeAt(i);
  28920. // is surrogate component
  28921. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  28922. // last char was a lead
  28923. if (!leadSurrogate) {
  28924. // no lead yet
  28925. if (codePoint > 0xDBFF) {
  28926. // unexpected trail
  28927. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28928. continue
  28929. } else if (i + 1 === length) {
  28930. // unpaired lead
  28931. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28932. continue
  28933. }
  28934. // valid lead
  28935. leadSurrogate = codePoint;
  28936. continue
  28937. }
  28938. // 2 leads in a row
  28939. if (codePoint < 0xDC00) {
  28940. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28941. leadSurrogate = codePoint;
  28942. continue
  28943. }
  28944. // valid surrogate pair
  28945. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  28946. } else if (leadSurrogate) {
  28947. // valid bmp char, but last char was a lead
  28948. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  28949. }
  28950. leadSurrogate = null;
  28951. // encode utf8
  28952. if (codePoint < 0x80) {
  28953. if ((units -= 1) < 0) break
  28954. bytes.push(codePoint);
  28955. } else if (codePoint < 0x800) {
  28956. if ((units -= 2) < 0) break
  28957. bytes.push(
  28958. codePoint >> 0x6 | 0xC0,
  28959. codePoint & 0x3F | 0x80
  28960. );
  28961. } else if (codePoint < 0x10000) {
  28962. if ((units -= 3) < 0) break
  28963. bytes.push(
  28964. codePoint >> 0xC | 0xE0,
  28965. codePoint >> 0x6 & 0x3F | 0x80,
  28966. codePoint & 0x3F | 0x80
  28967. );
  28968. } else if (codePoint < 0x110000) {
  28969. if ((units -= 4) < 0) break
  28970. bytes.push(
  28971. codePoint >> 0x12 | 0xF0,
  28972. codePoint >> 0xC & 0x3F | 0x80,
  28973. codePoint >> 0x6 & 0x3F | 0x80,
  28974. codePoint & 0x3F | 0x80
  28975. );
  28976. } else {
  28977. throw new Error('Invalid code point')
  28978. }
  28979. }
  28980. return bytes
  28981. }
  28982. function asciiToBytes (str) {
  28983. var byteArray = [];
  28984. for (var i = 0; i < str.length; ++i) {
  28985. // Node's code seems to be doing this and not & 0x7F..
  28986. byteArray.push(str.charCodeAt(i) & 0xFF);
  28987. }
  28988. return byteArray
  28989. }
  28990. function utf16leToBytes (str, units) {
  28991. var c, hi, lo;
  28992. var byteArray = [];
  28993. for (var i = 0; i < str.length; ++i) {
  28994. if ((units -= 2) < 0) break
  28995. c = str.charCodeAt(i);
  28996. hi = c >> 8;
  28997. lo = c % 256;
  28998. byteArray.push(lo);
  28999. byteArray.push(hi);
  29000. }
  29001. return byteArray
  29002. }
  29003. function base64ToBytes (str) {
  29004. return toByteArray(base64clean(str))
  29005. }
  29006. function blitBuffer (src, dst, offset, length) {
  29007. for (var i = 0; i < length; ++i) {
  29008. if ((i + offset >= dst.length) || (i >= src.length)) break
  29009. dst[i + offset] = src[i];
  29010. }
  29011. return i
  29012. }
  29013. function isnan (val) {
  29014. return val !== val // eslint-disable-line no-self-compare
  29015. }
  29016. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  29017. // The _isBuffer check is for Safari 5-7 support, because it's missing
  29018. // Object.prototype.constructor. Remove this eventually
  29019. function isBuffer$1(obj) {
  29020. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  29021. }
  29022. function isFastBuffer (obj) {
  29023. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  29024. }
  29025. // For Node v0.10 support. Remove this eventually.
  29026. function isSlowBuffer (obj) {
  29027. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  29028. }
  29029. var inherits;
  29030. if (typeof Object.create === 'function'){
  29031. inherits = function inherits(ctor, superCtor) {
  29032. // implementation from standard node.js 'util' module
  29033. ctor.super_ = superCtor;
  29034. ctor.prototype = Object.create(superCtor.prototype, {
  29035. constructor: {
  29036. value: ctor,
  29037. enumerable: false,
  29038. writable: true,
  29039. configurable: true
  29040. }
  29041. });
  29042. };
  29043. } else {
  29044. inherits = function inherits(ctor, superCtor) {
  29045. ctor.super_ = superCtor;
  29046. var TempCtor = function () {};
  29047. TempCtor.prototype = superCtor.prototype;
  29048. ctor.prototype = new TempCtor();
  29049. ctor.prototype.constructor = ctor;
  29050. };
  29051. }
  29052. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  29053. function getOwnPropertyDescriptors(obj) {
  29054. var keys = Object.keys(obj);
  29055. var descriptors = {};
  29056. for (var i = 0; i < keys.length; i++) {
  29057. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  29058. }
  29059. return descriptors;
  29060. };
  29061. var formatRegExp = /%[sdj%]/g;
  29062. function format$1(f) {
  29063. if (!isString(f)) {
  29064. var objects = [];
  29065. for (var i = 0; i < arguments.length; i++) {
  29066. objects.push(inspect(arguments[i]));
  29067. }
  29068. return objects.join(' ');
  29069. }
  29070. var i = 1;
  29071. var args = arguments;
  29072. var len = args.length;
  29073. var str = String(f).replace(formatRegExp, function(x) {
  29074. if (x === '%%') return '%';
  29075. if (i >= len) return x;
  29076. switch (x) {
  29077. case '%s': return String(args[i++]);
  29078. case '%d': return Number(args[i++]);
  29079. case '%j':
  29080. try {
  29081. return JSON.stringify(args[i++]);
  29082. } catch (_) {
  29083. return '[Circular]';
  29084. }
  29085. default:
  29086. return x;
  29087. }
  29088. });
  29089. for (var x = args[i]; i < len; x = args[++i]) {
  29090. if (isNull(x) || !isObject$1(x)) {
  29091. str += ' ' + x;
  29092. } else {
  29093. str += ' ' + inspect(x);
  29094. }
  29095. }
  29096. return str;
  29097. }
  29098. // Mark that a method should not be used.
  29099. // Returns a modified function which warns once by default.
  29100. // If --no-deprecation is set, then it is a no-op.
  29101. function deprecate(fn, msg) {
  29102. // Allow for deprecating things in the process of starting up.
  29103. if (isUndefined(global$1.process)) {
  29104. return function() {
  29105. return deprecate(fn, msg).apply(this, arguments);
  29106. };
  29107. }
  29108. if (browser$1.noDeprecation === true) {
  29109. return fn;
  29110. }
  29111. var warned = false;
  29112. function deprecated() {
  29113. if (!warned) {
  29114. if (browser$1.throwDeprecation) {
  29115. throw new Error(msg);
  29116. } else if (browser$1.traceDeprecation) {
  29117. console.trace(msg);
  29118. } else {
  29119. console.error(msg);
  29120. }
  29121. warned = true;
  29122. }
  29123. return fn.apply(this, arguments);
  29124. }
  29125. return deprecated;
  29126. }
  29127. var debugs = {};
  29128. var debugEnviron;
  29129. function debuglog(set) {
  29130. if (isUndefined(debugEnviron))
  29131. debugEnviron = browser$1.env.NODE_DEBUG || '';
  29132. set = set.toUpperCase();
  29133. if (!debugs[set]) {
  29134. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  29135. var pid = 0;
  29136. debugs[set] = function() {
  29137. var msg = format$1.apply(null, arguments);
  29138. console.error('%s %d: %s', set, pid, msg);
  29139. };
  29140. } else {
  29141. debugs[set] = function() {};
  29142. }
  29143. }
  29144. return debugs[set];
  29145. }
  29146. /**
  29147. * Echos the value of a value. Trys to print the value out
  29148. * in the best way possible given the different types.
  29149. *
  29150. * @param {Object} obj The object to print out.
  29151. * @param {Object} opts Optional options object that alters the output.
  29152. */
  29153. /* legacy: obj, showHidden, depth, colors*/
  29154. function inspect(obj, opts) {
  29155. // default options
  29156. var ctx = {
  29157. seen: [],
  29158. stylize: stylizeNoColor
  29159. };
  29160. // legacy...
  29161. if (arguments.length >= 3) ctx.depth = arguments[2];
  29162. if (arguments.length >= 4) ctx.colors = arguments[3];
  29163. if (isBoolean(opts)) {
  29164. // legacy...
  29165. ctx.showHidden = opts;
  29166. } else if (opts) {
  29167. // got an "options" object
  29168. _extend(ctx, opts);
  29169. }
  29170. // set default options
  29171. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  29172. if (isUndefined(ctx.depth)) ctx.depth = 2;
  29173. if (isUndefined(ctx.colors)) ctx.colors = false;
  29174. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  29175. if (ctx.colors) ctx.stylize = stylizeWithColor;
  29176. return formatValue(ctx, obj, ctx.depth);
  29177. }
  29178. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  29179. inspect.colors = {
  29180. 'bold' : [1, 22],
  29181. 'italic' : [3, 23],
  29182. 'underline' : [4, 24],
  29183. 'inverse' : [7, 27],
  29184. 'white' : [37, 39],
  29185. 'grey' : [90, 39],
  29186. 'black' : [30, 39],
  29187. 'blue' : [34, 39],
  29188. 'cyan' : [36, 39],
  29189. 'green' : [32, 39],
  29190. 'magenta' : [35, 39],
  29191. 'red' : [31, 39],
  29192. 'yellow' : [33, 39]
  29193. };
  29194. // Don't use 'blue' not visible on cmd.exe
  29195. inspect.styles = {
  29196. 'special': 'cyan',
  29197. 'number': 'yellow',
  29198. 'boolean': 'yellow',
  29199. 'undefined': 'grey',
  29200. 'null': 'bold',
  29201. 'string': 'green',
  29202. 'date': 'magenta',
  29203. // "name": intentionally not styling
  29204. 'regexp': 'red'
  29205. };
  29206. function stylizeWithColor(str, styleType) {
  29207. var style = inspect.styles[styleType];
  29208. if (style) {
  29209. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  29210. '\u001b[' + inspect.colors[style][1] + 'm';
  29211. } else {
  29212. return str;
  29213. }
  29214. }
  29215. function stylizeNoColor(str, styleType) {
  29216. return str;
  29217. }
  29218. function arrayToHash(array) {
  29219. var hash = {};
  29220. array.forEach(function(val, idx) {
  29221. hash[val] = true;
  29222. });
  29223. return hash;
  29224. }
  29225. function formatValue(ctx, value, recurseTimes) {
  29226. // Provide a hook for user-specified inspect functions.
  29227. // Check that value is an object with an inspect function on it
  29228. if (ctx.customInspect &&
  29229. value &&
  29230. isFunction(value.inspect) &&
  29231. // Filter out the util module, it's inspect function is special
  29232. value.inspect !== inspect &&
  29233. // Also filter out any prototype objects using the circular check.
  29234. !(value.constructor && value.constructor.prototype === value)) {
  29235. var ret = value.inspect(recurseTimes, ctx);
  29236. if (!isString(ret)) {
  29237. ret = formatValue(ctx, ret, recurseTimes);
  29238. }
  29239. return ret;
  29240. }
  29241. // Primitive types cannot have properties
  29242. var primitive = formatPrimitive(ctx, value);
  29243. if (primitive) {
  29244. return primitive;
  29245. }
  29246. // Look up the keys of the object.
  29247. var keys = Object.keys(value);
  29248. var visibleKeys = arrayToHash(keys);
  29249. if (ctx.showHidden) {
  29250. keys = Object.getOwnPropertyNames(value);
  29251. }
  29252. // IE doesn't make error fields non-enumerable
  29253. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  29254. if (isError(value)
  29255. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  29256. return formatError(value);
  29257. }
  29258. // Some type of object without properties can be shortcutted.
  29259. if (keys.length === 0) {
  29260. if (isFunction(value)) {
  29261. var name = value.name ? ': ' + value.name : '';
  29262. return ctx.stylize('[Function' + name + ']', 'special');
  29263. }
  29264. if (isRegExp(value)) {
  29265. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29266. }
  29267. if (isDate(value)) {
  29268. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  29269. }
  29270. if (isError(value)) {
  29271. return formatError(value);
  29272. }
  29273. }
  29274. var base = '', array = false, braces = ['{', '}'];
  29275. // Make Array say that they are Array
  29276. if (isArray$1(value)) {
  29277. array = true;
  29278. braces = ['[', ']'];
  29279. }
  29280. // Make functions say that they are functions
  29281. if (isFunction(value)) {
  29282. var n = value.name ? ': ' + value.name : '';
  29283. base = ' [Function' + n + ']';
  29284. }
  29285. // Make RegExps say that they are RegExps
  29286. if (isRegExp(value)) {
  29287. base = ' ' + RegExp.prototype.toString.call(value);
  29288. }
  29289. // Make dates with properties first say the date
  29290. if (isDate(value)) {
  29291. base = ' ' + Date.prototype.toUTCString.call(value);
  29292. }
  29293. // Make error with message first say the error
  29294. if (isError(value)) {
  29295. base = ' ' + formatError(value);
  29296. }
  29297. if (keys.length === 0 && (!array || value.length == 0)) {
  29298. return braces[0] + base + braces[1];
  29299. }
  29300. if (recurseTimes < 0) {
  29301. if (isRegExp(value)) {
  29302. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  29303. } else {
  29304. return ctx.stylize('[Object]', 'special');
  29305. }
  29306. }
  29307. ctx.seen.push(value);
  29308. var output;
  29309. if (array) {
  29310. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  29311. } else {
  29312. output = keys.map(function(key) {
  29313. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  29314. });
  29315. }
  29316. ctx.seen.pop();
  29317. return reduceToSingleString(output, base, braces);
  29318. }
  29319. function formatPrimitive(ctx, value) {
  29320. if (isUndefined(value))
  29321. return ctx.stylize('undefined', 'undefined');
  29322. if (isString(value)) {
  29323. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  29324. .replace(/'/g, "\\'")
  29325. .replace(/\\"/g, '"') + '\'';
  29326. return ctx.stylize(simple, 'string');
  29327. }
  29328. if (isNumber(value))
  29329. return ctx.stylize('' + value, 'number');
  29330. if (isBoolean(value))
  29331. return ctx.stylize('' + value, 'boolean');
  29332. // For some reason typeof null is "object", so special case here.
  29333. if (isNull(value))
  29334. return ctx.stylize('null', 'null');
  29335. }
  29336. function formatError(value) {
  29337. return '[' + Error.prototype.toString.call(value) + ']';
  29338. }
  29339. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  29340. var output = [];
  29341. for (var i = 0, l = value.length; i < l; ++i) {
  29342. if (hasOwnProperty$2(value, String(i))) {
  29343. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29344. String(i), true));
  29345. } else {
  29346. output.push('');
  29347. }
  29348. }
  29349. keys.forEach(function(key) {
  29350. if (!key.match(/^\d+$/)) {
  29351. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  29352. key, true));
  29353. }
  29354. });
  29355. return output;
  29356. }
  29357. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  29358. var name, str, desc;
  29359. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  29360. if (desc.get) {
  29361. if (desc.set) {
  29362. str = ctx.stylize('[Getter/Setter]', 'special');
  29363. } else {
  29364. str = ctx.stylize('[Getter]', 'special');
  29365. }
  29366. } else {
  29367. if (desc.set) {
  29368. str = ctx.stylize('[Setter]', 'special');
  29369. }
  29370. }
  29371. if (!hasOwnProperty$2(visibleKeys, key)) {
  29372. name = '[' + key + ']';
  29373. }
  29374. if (!str) {
  29375. if (ctx.seen.indexOf(desc.value) < 0) {
  29376. if (isNull(recurseTimes)) {
  29377. str = formatValue(ctx, desc.value, null);
  29378. } else {
  29379. str = formatValue(ctx, desc.value, recurseTimes - 1);
  29380. }
  29381. if (str.indexOf('\n') > -1) {
  29382. if (array) {
  29383. str = str.split('\n').map(function(line) {
  29384. return ' ' + line;
  29385. }).join('\n').substr(2);
  29386. } else {
  29387. str = '\n' + str.split('\n').map(function(line) {
  29388. return ' ' + line;
  29389. }).join('\n');
  29390. }
  29391. }
  29392. } else {
  29393. str = ctx.stylize('[Circular]', 'special');
  29394. }
  29395. }
  29396. if (isUndefined(name)) {
  29397. if (array && key.match(/^\d+$/)) {
  29398. return str;
  29399. }
  29400. name = JSON.stringify('' + key);
  29401. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  29402. name = name.substr(1, name.length - 2);
  29403. name = ctx.stylize(name, 'name');
  29404. } else {
  29405. name = name.replace(/'/g, "\\'")
  29406. .replace(/\\"/g, '"')
  29407. .replace(/(^"|"$)/g, "'");
  29408. name = ctx.stylize(name, 'string');
  29409. }
  29410. }
  29411. return name + ': ' + str;
  29412. }
  29413. function reduceToSingleString(output, base, braces) {
  29414. var length = output.reduce(function(prev, cur) {
  29415. if (cur.indexOf('\n') >= 0) ;
  29416. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  29417. }, 0);
  29418. if (length > 60) {
  29419. return braces[0] +
  29420. (base === '' ? '' : base + '\n ') +
  29421. ' ' +
  29422. output.join(',\n ') +
  29423. ' ' +
  29424. braces[1];
  29425. }
  29426. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  29427. }
  29428. // NOTE: These type checking functions intentionally don't use `instanceof`
  29429. // because it is fragile and can be easily faked with `Object.create()`.
  29430. function isArray$1(ar) {
  29431. return Array.isArray(ar);
  29432. }
  29433. function isBoolean(arg) {
  29434. return typeof arg === 'boolean';
  29435. }
  29436. function isNull(arg) {
  29437. return arg === null;
  29438. }
  29439. function isNullOrUndefined(arg) {
  29440. return arg == null;
  29441. }
  29442. function isNumber(arg) {
  29443. return typeof arg === 'number';
  29444. }
  29445. function isString(arg) {
  29446. return typeof arg === 'string';
  29447. }
  29448. function isSymbol(arg) {
  29449. return typeof arg === 'symbol';
  29450. }
  29451. function isUndefined(arg) {
  29452. return arg === void 0;
  29453. }
  29454. function isRegExp(re) {
  29455. return isObject$1(re) && objectToString(re) === '[object RegExp]';
  29456. }
  29457. function isObject$1(arg) {
  29458. return typeof arg === 'object' && arg !== null;
  29459. }
  29460. function isDate(d) {
  29461. return isObject$1(d) && objectToString(d) === '[object Date]';
  29462. }
  29463. function isError(e) {
  29464. return isObject$1(e) &&
  29465. (objectToString(e) === '[object Error]' || e instanceof Error);
  29466. }
  29467. function isFunction(arg) {
  29468. return typeof arg === 'function';
  29469. }
  29470. function isPrimitive(arg) {
  29471. return arg === null ||
  29472. typeof arg === 'boolean' ||
  29473. typeof arg === 'number' ||
  29474. typeof arg === 'string' ||
  29475. typeof arg === 'symbol' || // ES6 symbol
  29476. typeof arg === 'undefined';
  29477. }
  29478. function isBuffer(maybeBuf) {
  29479. return Buffer$1.isBuffer(maybeBuf);
  29480. }
  29481. function objectToString(o) {
  29482. return Object.prototype.toString.call(o);
  29483. }
  29484. function pad(n) {
  29485. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  29486. }
  29487. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  29488. 'Oct', 'Nov', 'Dec'];
  29489. // 26 Feb 16:19:34
  29490. function timestamp() {
  29491. var d = new Date();
  29492. var time = [pad(d.getHours()),
  29493. pad(d.getMinutes()),
  29494. pad(d.getSeconds())].join(':');
  29495. return [d.getDate(), months[d.getMonth()], time].join(' ');
  29496. }
  29497. // log is just a thin wrapper to console.log that prepends a timestamp
  29498. function log() {
  29499. console.log('%s - %s', timestamp(), format$1.apply(null, arguments));
  29500. }
  29501. function _extend(origin, add) {
  29502. // Don't do anything if add isn't an object
  29503. if (!add || !isObject$1(add)) return origin;
  29504. var keys = Object.keys(add);
  29505. var i = keys.length;
  29506. while (i--) {
  29507. origin[keys[i]] = add[keys[i]];
  29508. }
  29509. return origin;
  29510. }
  29511. function hasOwnProperty$2(obj, prop) {
  29512. return Object.prototype.hasOwnProperty.call(obj, prop);
  29513. }
  29514. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  29515. function promisify(original) {
  29516. if (typeof original !== 'function')
  29517. throw new TypeError('The "original" argument must be of type Function');
  29518. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  29519. var fn = original[kCustomPromisifiedSymbol];
  29520. if (typeof fn !== 'function') {
  29521. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  29522. }
  29523. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29524. value: fn, enumerable: false, writable: false, configurable: true
  29525. });
  29526. return fn;
  29527. }
  29528. function fn() {
  29529. var promiseResolve, promiseReject;
  29530. var promise = new Promise(function (resolve, reject) {
  29531. promiseResolve = resolve;
  29532. promiseReject = reject;
  29533. });
  29534. var args = [];
  29535. for (var i = 0; i < arguments.length; i++) {
  29536. args.push(arguments[i]);
  29537. }
  29538. args.push(function (err, value) {
  29539. if (err) {
  29540. promiseReject(err);
  29541. } else {
  29542. promiseResolve(value);
  29543. }
  29544. });
  29545. try {
  29546. original.apply(this, args);
  29547. } catch (err) {
  29548. promiseReject(err);
  29549. }
  29550. return promise;
  29551. }
  29552. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  29553. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  29554. value: fn, enumerable: false, writable: false, configurable: true
  29555. });
  29556. return Object.defineProperties(
  29557. fn,
  29558. getOwnPropertyDescriptors(original)
  29559. );
  29560. }
  29561. promisify.custom = kCustomPromisifiedSymbol;
  29562. function callbackifyOnRejected(reason, cb) {
  29563. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  29564. // Because `null` is a special error value in callbacks which means "no error
  29565. // occurred", we error-wrap so the callback consumer can distinguish between
  29566. // "the promise rejected with null" or "the promise fulfilled with undefined".
  29567. if (!reason) {
  29568. var newReason = new Error('Promise was rejected with a falsy value');
  29569. newReason.reason = reason;
  29570. reason = newReason;
  29571. }
  29572. return cb(reason);
  29573. }
  29574. function callbackify(original) {
  29575. if (typeof original !== 'function') {
  29576. throw new TypeError('The "original" argument must be of type Function');
  29577. }
  29578. // We DO NOT return the promise as it gives the user a false sense that
  29579. // the promise is actually somehow related to the callback's execution
  29580. // and that the callback throwing will reject the promise.
  29581. function callbackified() {
  29582. var args = [];
  29583. for (var i = 0; i < arguments.length; i++) {
  29584. args.push(arguments[i]);
  29585. }
  29586. var maybeCb = args.pop();
  29587. if (typeof maybeCb !== 'function') {
  29588. throw new TypeError('The last argument must be of type Function');
  29589. }
  29590. var self = this;
  29591. var cb = function() {
  29592. return maybeCb.apply(self, arguments);
  29593. };
  29594. // In true node style we process the callback on `nextTick` with all the
  29595. // implications (stack, `uncaughtException`, `async_hooks`)
  29596. original.apply(this, args)
  29597. .then(function(ret) { browser$1.nextTick(cb.bind(null, null, ret)); },
  29598. function(rej) { browser$1.nextTick(callbackifyOnRejected.bind(null, rej, cb)); });
  29599. }
  29600. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  29601. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  29602. return callbackified;
  29603. }
  29604. var _polyfillNode_util = {
  29605. inherits: inherits,
  29606. _extend: _extend,
  29607. log: log,
  29608. isBuffer: isBuffer,
  29609. isPrimitive: isPrimitive,
  29610. isFunction: isFunction,
  29611. isError: isError,
  29612. isDate: isDate,
  29613. isObject: isObject$1,
  29614. isRegExp: isRegExp,
  29615. isUndefined: isUndefined,
  29616. isSymbol: isSymbol,
  29617. isString: isString,
  29618. isNumber: isNumber,
  29619. isNullOrUndefined: isNullOrUndefined,
  29620. isNull: isNull,
  29621. isBoolean: isBoolean,
  29622. isArray: isArray$1,
  29623. inspect: inspect,
  29624. deprecate: deprecate,
  29625. format: format$1,
  29626. debuglog: debuglog,
  29627. promisify: promisify,
  29628. callbackify: callbackify,
  29629. };
  29630. var _polyfillNode_util$1 = /*#__PURE__*/Object.freeze({
  29631. __proto__: null,
  29632. _extend: _extend,
  29633. callbackify: callbackify,
  29634. debuglog: debuglog,
  29635. default: _polyfillNode_util,
  29636. deprecate: deprecate,
  29637. format: format$1,
  29638. inherits: inherits,
  29639. inspect: inspect,
  29640. isArray: isArray$1,
  29641. isBoolean: isBoolean,
  29642. isBuffer: isBuffer,
  29643. isDate: isDate,
  29644. isError: isError,
  29645. isFunction: isFunction,
  29646. isNull: isNull,
  29647. isNullOrUndefined: isNullOrUndefined,
  29648. isNumber: isNumber,
  29649. isObject: isObject$1,
  29650. isPrimitive: isPrimitive,
  29651. isRegExp: isRegExp,
  29652. isString: isString,
  29653. isSymbol: isSymbol,
  29654. isUndefined: isUndefined,
  29655. log: log,
  29656. promisify: promisify
  29657. });
  29658. // Copyright Joyent, Inc. and other Node contributors.
  29659. //
  29660. // Permission is hereby granted, free of charge, to any person obtaining a
  29661. // copy of this software and associated documentation files (the
  29662. // "Software"), to deal in the Software without restriction, including
  29663. // without limitation the rights to use, copy, modify, merge, publish,
  29664. // distribute, sublicense, and/or sell copies of the Software, and to permit
  29665. // persons to whom the Software is furnished to do so, subject to the
  29666. // following conditions:
  29667. //
  29668. // The above copyright notice and this permission notice shall be included
  29669. // in all copies or substantial portions of the Software.
  29670. //
  29671. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  29672. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29673. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  29674. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  29675. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29676. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  29677. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  29678. // If obj.hasOwnProperty has been overridden, then calling
  29679. // obj.hasOwnProperty(prop) will break.
  29680. // See: https://github.com/joyent/node/issues/1707
  29681. function hasOwnProperty$1(obj, prop) {
  29682. return Object.prototype.hasOwnProperty.call(obj, prop);
  29683. }
  29684. var isArray = Array.isArray || function (xs) {
  29685. return Object.prototype.toString.call(xs) === '[object Array]';
  29686. };
  29687. function stringifyPrimitive(v) {
  29688. switch (typeof v) {
  29689. case 'string':
  29690. return v;
  29691. case 'boolean':
  29692. return v ? 'true' : 'false';
  29693. case 'number':
  29694. return isFinite(v) ? v : '';
  29695. default:
  29696. return '';
  29697. }
  29698. }
  29699. function stringify (obj, sep, eq, name) {
  29700. sep = sep || '&';
  29701. eq = eq || '=';
  29702. if (obj === null) {
  29703. obj = undefined;
  29704. }
  29705. if (typeof obj === 'object') {
  29706. return map(objectKeys(obj), function(k) {
  29707. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  29708. if (isArray(obj[k])) {
  29709. return map(obj[k], function(v) {
  29710. return ks + encodeURIComponent(stringifyPrimitive(v));
  29711. }).join(sep);
  29712. } else {
  29713. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  29714. }
  29715. }).join(sep);
  29716. }
  29717. if (!name) return '';
  29718. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  29719. encodeURIComponent(stringifyPrimitive(obj));
  29720. }
  29721. function map (xs, f) {
  29722. if (xs.map) return xs.map(f);
  29723. var res = [];
  29724. for (var i = 0; i < xs.length; i++) {
  29725. res.push(f(xs[i], i));
  29726. }
  29727. return res;
  29728. }
  29729. var objectKeys = Object.keys || function (obj) {
  29730. var res = [];
  29731. for (var key in obj) {
  29732. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  29733. }
  29734. return res;
  29735. };
  29736. function parse$1(qs, sep, eq, options) {
  29737. sep = sep || '&';
  29738. eq = eq || '=';
  29739. var obj = {};
  29740. if (typeof qs !== 'string' || qs.length === 0) {
  29741. return obj;
  29742. }
  29743. var regexp = /\+/g;
  29744. qs = qs.split(sep);
  29745. var maxKeys = 1000;
  29746. if (options && typeof options.maxKeys === 'number') {
  29747. maxKeys = options.maxKeys;
  29748. }
  29749. var len = qs.length;
  29750. // maxKeys <= 0 means that we should not limit keys count
  29751. if (maxKeys > 0 && len > maxKeys) {
  29752. len = maxKeys;
  29753. }
  29754. for (var i = 0; i < len; ++i) {
  29755. var x = qs[i].replace(regexp, '%20'),
  29756. idx = x.indexOf(eq),
  29757. kstr, vstr, k, v;
  29758. if (idx >= 0) {
  29759. kstr = x.substr(0, idx);
  29760. vstr = x.substr(idx + 1);
  29761. } else {
  29762. kstr = x;
  29763. vstr = '';
  29764. }
  29765. k = decodeURIComponent(kstr);
  29766. v = decodeURIComponent(vstr);
  29767. if (!hasOwnProperty$1(obj, k)) {
  29768. obj[k] = v;
  29769. } else if (isArray(obj[k])) {
  29770. obj[k].push(v);
  29771. } else {
  29772. obj[k] = [obj[k], v];
  29773. }
  29774. }
  29775. return obj;
  29776. }
  29777. // WHATWG API
  29778. const URL$1 = global$1.URL;
  29779. const URLSearchParams = global$1.URLSearchParams;
  29780. var _polyfillNode_url = {
  29781. parse: urlParse,
  29782. resolve: urlResolve,
  29783. resolveObject: urlResolveObject,
  29784. fileURLToPath: urlFileURLToPath,
  29785. format: urlFormat,
  29786. Url: Url,
  29787. // WHATWG API
  29788. URL: URL$1,
  29789. URLSearchParams,
  29790. };
  29791. function Url() {
  29792. this.protocol = null;
  29793. this.slashes = null;
  29794. this.auth = null;
  29795. this.host = null;
  29796. this.port = null;
  29797. this.hostname = null;
  29798. this.hash = null;
  29799. this.search = null;
  29800. this.query = null;
  29801. this.pathname = null;
  29802. this.path = null;
  29803. this.href = null;
  29804. }
  29805. // Reference: RFC 3986, RFC 1808, RFC 2396
  29806. // define these here so at least they only have to be
  29807. // compiled once on the first module load.
  29808. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  29809. portPattern = /:[0-9]*$/,
  29810. // Special case for a simple path URL
  29811. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  29812. // RFC 2396: characters reserved for delimiting URLs.
  29813. // We actually just auto-escape these.
  29814. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  29815. // RFC 2396: characters not allowed for various reasons.
  29816. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  29817. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  29818. autoEscape = ['\''].concat(unwise),
  29819. // Characters that are never ever allowed in a hostname.
  29820. // Note that any invalid chars are also handled, but these
  29821. // are the ones that are *expected* to be seen, so we fast-path
  29822. // them.
  29823. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  29824. hostEndingChars = ['/', '?', '#'],
  29825. hostnameMaxLen = 255,
  29826. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  29827. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  29828. // protocols that can allow "unsafe" and "unwise" chars.
  29829. unsafeProtocol = {
  29830. 'javascript': true,
  29831. 'javascript:': true
  29832. },
  29833. // protocols that never have a hostname.
  29834. hostlessProtocol = {
  29835. 'javascript': true,
  29836. 'javascript:': true
  29837. },
  29838. // protocols that always contain a // bit.
  29839. slashedProtocol = {
  29840. 'http': true,
  29841. 'https': true,
  29842. 'ftp': true,
  29843. 'gopher': true,
  29844. 'file': true,
  29845. 'http:': true,
  29846. 'https:': true,
  29847. 'ftp:': true,
  29848. 'gopher:': true,
  29849. 'file:': true
  29850. };
  29851. function urlParse(url, parseQueryString, slashesDenoteHost) {
  29852. if (url && isObject$1(url) && url instanceof Url) return url;
  29853. var u = new Url;
  29854. u.parse(url, parseQueryString, slashesDenoteHost);
  29855. return u;
  29856. }
  29857. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  29858. return parse(this, url, parseQueryString, slashesDenoteHost);
  29859. };
  29860. function parse(self, url, parseQueryString, slashesDenoteHost) {
  29861. if (!isString(url)) {
  29862. throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
  29863. }
  29864. // Copy chrome, IE, opera backslash-handling behavior.
  29865. // Back slashes before the query string get converted to forward slashes
  29866. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  29867. var queryIndex = url.indexOf('?'),
  29868. splitter =
  29869. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  29870. uSplit = url.split(splitter),
  29871. slashRegex = /\\/g;
  29872. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  29873. url = uSplit.join(splitter);
  29874. var rest = url;
  29875. // trim before proceeding.
  29876. // This is to support parse stuff like " http://foo.com \n"
  29877. rest = rest.trim();
  29878. if (!slashesDenoteHost && url.split('#').length === 1) {
  29879. // Try fast path regexp
  29880. var simplePath = simplePathPattern.exec(rest);
  29881. if (simplePath) {
  29882. self.path = rest;
  29883. self.href = rest;
  29884. self.pathname = simplePath[1];
  29885. if (simplePath[2]) {
  29886. self.search = simplePath[2];
  29887. if (parseQueryString) {
  29888. self.query = parse$1(self.search.substr(1));
  29889. } else {
  29890. self.query = self.search.substr(1);
  29891. }
  29892. } else if (parseQueryString) {
  29893. self.search = '';
  29894. self.query = {};
  29895. }
  29896. return self;
  29897. }
  29898. }
  29899. var proto = protocolPattern.exec(rest);
  29900. if (proto) {
  29901. proto = proto[0];
  29902. var lowerProto = proto.toLowerCase();
  29903. self.protocol = lowerProto;
  29904. rest = rest.substr(proto.length);
  29905. }
  29906. // figure out if it's got a host
  29907. // user@server is *always* interpreted as a hostname, and url
  29908. // resolution will treat //foo/bar as host=foo,path=bar because that's
  29909. // how the browser resolves relative URLs.
  29910. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  29911. var slashes = rest.substr(0, 2) === '//';
  29912. if (slashes && !(proto && hostlessProtocol[proto])) {
  29913. rest = rest.substr(2);
  29914. self.slashes = true;
  29915. }
  29916. }
  29917. var i, hec, l, p;
  29918. if (!hostlessProtocol[proto] &&
  29919. (slashes || (proto && !slashedProtocol[proto]))) {
  29920. // there's a hostname.
  29921. // the first instance of /, ?, ;, or # ends the host.
  29922. //
  29923. // If there is an @ in the hostname, then non-host chars *are* allowed
  29924. // to the left of the last @ sign, unless some host-ending character
  29925. // comes *before* the @-sign.
  29926. // URLs are obnoxious.
  29927. //
  29928. // ex:
  29929. // http://a@b@c/ => user:a@b host:c
  29930. // http://a@b?@c => user:a host:c path:/?@c
  29931. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  29932. // Review our test case against browsers more comprehensively.
  29933. // find the first instance of any hostEndingChars
  29934. var hostEnd = -1;
  29935. for (i = 0; i < hostEndingChars.length; i++) {
  29936. hec = rest.indexOf(hostEndingChars[i]);
  29937. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29938. hostEnd = hec;
  29939. }
  29940. // at this point, either we have an explicit point where the
  29941. // auth portion cannot go past, or the last @ char is the decider.
  29942. var auth, atSign;
  29943. if (hostEnd === -1) {
  29944. // atSign can be anywhere.
  29945. atSign = rest.lastIndexOf('@');
  29946. } else {
  29947. // atSign must be in auth portion.
  29948. // http://a@b/c@d => host:b auth:a path:/c@d
  29949. atSign = rest.lastIndexOf('@', hostEnd);
  29950. }
  29951. // Now we have a portion which is definitely the auth.
  29952. // Pull that off.
  29953. if (atSign !== -1) {
  29954. auth = rest.slice(0, atSign);
  29955. rest = rest.slice(atSign + 1);
  29956. self.auth = decodeURIComponent(auth);
  29957. }
  29958. // the host is the remaining to the left of the first non-host char
  29959. hostEnd = -1;
  29960. for (i = 0; i < nonHostChars.length; i++) {
  29961. hec = rest.indexOf(nonHostChars[i]);
  29962. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  29963. hostEnd = hec;
  29964. }
  29965. // if we still have not hit it, then the entire thing is a host.
  29966. if (hostEnd === -1)
  29967. hostEnd = rest.length;
  29968. self.host = rest.slice(0, hostEnd);
  29969. rest = rest.slice(hostEnd);
  29970. // pull out port.
  29971. parseHost(self);
  29972. // we've indicated that there is a hostname,
  29973. // so even if it's empty, it has to be present.
  29974. self.hostname = self.hostname || '';
  29975. // if hostname begins with [ and ends with ]
  29976. // assume that it's an IPv6 address.
  29977. var ipv6Hostname = self.hostname[0] === '[' &&
  29978. self.hostname[self.hostname.length - 1] === ']';
  29979. // validate a little.
  29980. if (!ipv6Hostname) {
  29981. var hostparts = self.hostname.split(/\./);
  29982. for (i = 0, l = hostparts.length; i < l; i++) {
  29983. var part = hostparts[i];
  29984. if (!part) continue;
  29985. if (!part.match(hostnamePartPattern)) {
  29986. var newpart = '';
  29987. for (var j = 0, k = part.length; j < k; j++) {
  29988. if (part.charCodeAt(j) > 127) {
  29989. // we replace non-ASCII char with a temporary placeholder
  29990. // we need this to make sure size of hostname is not
  29991. // broken by replacing non-ASCII by nothing
  29992. newpart += 'x';
  29993. } else {
  29994. newpart += part[j];
  29995. }
  29996. }
  29997. // we test again with ASCII char only
  29998. if (!newpart.match(hostnamePartPattern)) {
  29999. var validParts = hostparts.slice(0, i);
  30000. var notHost = hostparts.slice(i + 1);
  30001. var bit = part.match(hostnamePartStart);
  30002. if (bit) {
  30003. validParts.push(bit[1]);
  30004. notHost.unshift(bit[2]);
  30005. }
  30006. if (notHost.length) {
  30007. rest = '/' + notHost.join('.') + rest;
  30008. }
  30009. self.hostname = validParts.join('.');
  30010. break;
  30011. }
  30012. }
  30013. }
  30014. }
  30015. if (self.hostname.length > hostnameMaxLen) {
  30016. self.hostname = '';
  30017. } else {
  30018. // hostnames are always lower case.
  30019. self.hostname = self.hostname.toLowerCase();
  30020. }
  30021. if (!ipv6Hostname) {
  30022. // IDNA Support: Returns a punycoded representation of "domain".
  30023. // It only converts parts of the domain name that
  30024. // have non-ASCII characters, i.e. it doesn't matter if
  30025. // you call it with a domain that already is ASCII-only.
  30026. self.hostname = toASCII(self.hostname);
  30027. }
  30028. p = self.port ? ':' + self.port : '';
  30029. var h = self.hostname || '';
  30030. self.host = h + p;
  30031. self.href += self.host;
  30032. // strip [ and ] from the hostname
  30033. // the host field still retains them, though
  30034. if (ipv6Hostname) {
  30035. self.hostname = self.hostname.substr(1, self.hostname.length - 2);
  30036. if (rest[0] !== '/') {
  30037. rest = '/' + rest;
  30038. }
  30039. }
  30040. }
  30041. // now rest is set to the post-host stuff.
  30042. // chop off any delim chars.
  30043. if (!unsafeProtocol[lowerProto]) {
  30044. // First, make 100% sure that any "autoEscape" chars get
  30045. // escaped, even if encodeURIComponent doesn't think they
  30046. // need to be.
  30047. for (i = 0, l = autoEscape.length; i < l; i++) {
  30048. var ae = autoEscape[i];
  30049. if (rest.indexOf(ae) === -1)
  30050. continue;
  30051. var esc = encodeURIComponent(ae);
  30052. if (esc === ae) {
  30053. esc = escape(ae);
  30054. }
  30055. rest = rest.split(ae).join(esc);
  30056. }
  30057. }
  30058. // chop off from the tail first.
  30059. var hash = rest.indexOf('#');
  30060. if (hash !== -1) {
  30061. // got a fragment string.
  30062. self.hash = rest.substr(hash);
  30063. rest = rest.slice(0, hash);
  30064. }
  30065. var qm = rest.indexOf('?');
  30066. if (qm !== -1) {
  30067. self.search = rest.substr(qm);
  30068. self.query = rest.substr(qm + 1);
  30069. if (parseQueryString) {
  30070. self.query = parse$1(self.query);
  30071. }
  30072. rest = rest.slice(0, qm);
  30073. } else if (parseQueryString) {
  30074. // no query string, but parseQueryString still requested
  30075. self.search = '';
  30076. self.query = {};
  30077. }
  30078. if (rest) self.pathname = rest;
  30079. if (slashedProtocol[lowerProto] &&
  30080. self.hostname && !self.pathname) {
  30081. self.pathname = '/';
  30082. }
  30083. //to support http.request
  30084. if (self.pathname || self.search) {
  30085. p = self.pathname || '';
  30086. var s = self.search || '';
  30087. self.path = p + s;
  30088. }
  30089. // finally, reconstruct the href based on what has been validated.
  30090. self.href = format(self);
  30091. return self;
  30092. }
  30093. function urlFileURLToPath(path) {
  30094. if (typeof path === 'string')
  30095. path = new Url().parse(path);
  30096. else if (!(path instanceof Url))
  30097. throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
  30098. if (path.protocol !== 'file:')
  30099. throw new TypeError('The URL must be of scheme file');
  30100. return getPathFromURLPosix(path);
  30101. }
  30102. function getPathFromURLPosix(url) {
  30103. const pathname = url.pathname;
  30104. for (let n = 0; n < pathname.length; n++) {
  30105. if (pathname[n] === '%') {
  30106. const third = pathname.codePointAt(n + 2) | 0x20;
  30107. if (pathname[n + 1] === '2' && third === 102) {
  30108. throw new TypeError(
  30109. 'must not include encoded / characters'
  30110. );
  30111. }
  30112. }
  30113. }
  30114. return decodeURIComponent(pathname);
  30115. }
  30116. // format a parsed object into a url string
  30117. function urlFormat(obj) {
  30118. // ensure it's an object, and not a string url.
  30119. // If it's an obj, this is a no-op.
  30120. // this way, you can call url_format() on strings
  30121. // to clean up potentially wonky urls.
  30122. if (isString(obj)) obj = parse({}, obj);
  30123. return format(obj);
  30124. }
  30125. function format(self) {
  30126. var auth = self.auth || '';
  30127. if (auth) {
  30128. auth = encodeURIComponent(auth);
  30129. auth = auth.replace(/%3A/i, ':');
  30130. auth += '@';
  30131. }
  30132. var protocol = self.protocol || '',
  30133. pathname = self.pathname || '',
  30134. hash = self.hash || '',
  30135. host = false,
  30136. query = '';
  30137. if (self.host) {
  30138. host = auth + self.host;
  30139. } else if (self.hostname) {
  30140. host = auth + (self.hostname.indexOf(':') === -1 ?
  30141. self.hostname :
  30142. '[' + this.hostname + ']');
  30143. if (self.port) {
  30144. host += ':' + self.port;
  30145. }
  30146. }
  30147. if (self.query &&
  30148. isObject$1(self.query) &&
  30149. Object.keys(self.query).length) {
  30150. query = stringify(self.query);
  30151. }
  30152. var search = self.search || (query && ('?' + query)) || '';
  30153. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  30154. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  30155. // unless they had them to begin with.
  30156. if (self.slashes ||
  30157. (!protocol || slashedProtocol[protocol]) && host !== false) {
  30158. host = '//' + (host || '');
  30159. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  30160. } else if (!host) {
  30161. host = '';
  30162. }
  30163. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  30164. if (search && search.charAt(0) !== '?') search = '?' + search;
  30165. pathname = pathname.replace(/[?#]/g, function(match) {
  30166. return encodeURIComponent(match);
  30167. });
  30168. search = search.replace('#', '%23');
  30169. return protocol + host + pathname + search + hash;
  30170. }
  30171. Url.prototype.format = function() {
  30172. return format(this);
  30173. };
  30174. function urlResolve(source, relative) {
  30175. return urlParse(source, false, true).resolve(relative);
  30176. }
  30177. Url.prototype.resolve = function(relative) {
  30178. return this.resolveObject(urlParse(relative, false, true)).format();
  30179. };
  30180. function urlResolveObject(source, relative) {
  30181. if (!source) return relative;
  30182. return urlParse(source, false, true).resolveObject(relative);
  30183. }
  30184. Url.prototype.resolveObject = function(relative) {
  30185. if (isString(relative)) {
  30186. var rel = new Url();
  30187. rel.parse(relative, false, true);
  30188. relative = rel;
  30189. }
  30190. var result = new Url();
  30191. var tkeys = Object.keys(this);
  30192. for (var tk = 0; tk < tkeys.length; tk++) {
  30193. var tkey = tkeys[tk];
  30194. result[tkey] = this[tkey];
  30195. }
  30196. // hash is always overridden, no matter what.
  30197. // even href="" will remove it.
  30198. result.hash = relative.hash;
  30199. // if the relative url is empty, then there's nothing left to do here.
  30200. if (relative.href === '') {
  30201. result.href = result.format();
  30202. return result;
  30203. }
  30204. // hrefs like //foo/bar always cut to the protocol.
  30205. if (relative.slashes && !relative.protocol) {
  30206. // take everything except the protocol from relative
  30207. var rkeys = Object.keys(relative);
  30208. for (var rk = 0; rk < rkeys.length; rk++) {
  30209. var rkey = rkeys[rk];
  30210. if (rkey !== 'protocol')
  30211. result[rkey] = relative[rkey];
  30212. }
  30213. //urlParse appends trailing / to urls like http://www.example.com
  30214. if (slashedProtocol[result.protocol] &&
  30215. result.hostname && !result.pathname) {
  30216. result.path = result.pathname = '/';
  30217. }
  30218. result.href = result.format();
  30219. return result;
  30220. }
  30221. var relPath;
  30222. if (relative.protocol && relative.protocol !== result.protocol) {
  30223. // if it's a known url protocol, then changing
  30224. // the protocol does weird things
  30225. // first, if it's not file:, then we MUST have a host,
  30226. // and if there was a path
  30227. // to begin with, then we MUST have a path.
  30228. // if it is file:, then the host is dropped,
  30229. // because that's known to be hostless.
  30230. // anything else is assumed to be absolute.
  30231. if (!slashedProtocol[relative.protocol]) {
  30232. var keys = Object.keys(relative);
  30233. for (var v = 0; v < keys.length; v++) {
  30234. var k = keys[v];
  30235. result[k] = relative[k];
  30236. }
  30237. result.href = result.format();
  30238. return result;
  30239. }
  30240. result.protocol = relative.protocol;
  30241. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  30242. relPath = (relative.pathname || '').split('/');
  30243. while (relPath.length && !(relative.host = relPath.shift()));
  30244. if (!relative.host) relative.host = '';
  30245. if (!relative.hostname) relative.hostname = '';
  30246. if (relPath[0] !== '') relPath.unshift('');
  30247. if (relPath.length < 2) relPath.unshift('');
  30248. result.pathname = relPath.join('/');
  30249. } else {
  30250. result.pathname = relative.pathname;
  30251. }
  30252. result.search = relative.search;
  30253. result.query = relative.query;
  30254. result.host = relative.host || '';
  30255. result.auth = relative.auth;
  30256. result.hostname = relative.hostname || relative.host;
  30257. result.port = relative.port;
  30258. // to support http.request
  30259. if (result.pathname || result.search) {
  30260. var p = result.pathname || '';
  30261. var s = result.search || '';
  30262. result.path = p + s;
  30263. }
  30264. result.slashes = result.slashes || relative.slashes;
  30265. result.href = result.format();
  30266. return result;
  30267. }
  30268. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  30269. isRelAbs = (
  30270. relative.host ||
  30271. relative.pathname && relative.pathname.charAt(0) === '/'
  30272. ),
  30273. mustEndAbs = (isRelAbs || isSourceAbs ||
  30274. (result.host && relative.pathname)),
  30275. removeAllDots = mustEndAbs,
  30276. srcPath = result.pathname && result.pathname.split('/') || [],
  30277. psychotic = result.protocol && !slashedProtocol[result.protocol];
  30278. relPath = relative.pathname && relative.pathname.split('/') || [];
  30279. // if the url is a non-slashed url, then relative
  30280. // links like ../.. should be able
  30281. // to crawl up to the hostname, as well. This is strange.
  30282. // result.protocol has already been set by now.
  30283. // Later on, put the first path part into the host field.
  30284. if (psychotic) {
  30285. result.hostname = '';
  30286. result.port = null;
  30287. if (result.host) {
  30288. if (srcPath[0] === '') srcPath[0] = result.host;
  30289. else srcPath.unshift(result.host);
  30290. }
  30291. result.host = '';
  30292. if (relative.protocol) {
  30293. relative.hostname = null;
  30294. relative.port = null;
  30295. if (relative.host) {
  30296. if (relPath[0] === '') relPath[0] = relative.host;
  30297. else relPath.unshift(relative.host);
  30298. }
  30299. relative.host = null;
  30300. }
  30301. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  30302. }
  30303. var authInHost;
  30304. if (isRelAbs) {
  30305. // it's absolute.
  30306. result.host = (relative.host || relative.host === '') ?
  30307. relative.host : result.host;
  30308. result.hostname = (relative.hostname || relative.hostname === '') ?
  30309. relative.hostname : result.hostname;
  30310. result.search = relative.search;
  30311. result.query = relative.query;
  30312. srcPath = relPath;
  30313. // fall through to the dot-handling below.
  30314. } else if (relPath.length) {
  30315. // it's relative
  30316. // throw away the existing file, and take the new path instead.
  30317. if (!srcPath) srcPath = [];
  30318. srcPath.pop();
  30319. srcPath = srcPath.concat(relPath);
  30320. result.search = relative.search;
  30321. result.query = relative.query;
  30322. } else if (!isNullOrUndefined(relative.search)) {
  30323. // just pull out the search.
  30324. // like href='?foo'.
  30325. // Put this after the other two cases because it simplifies the booleans
  30326. if (psychotic) {
  30327. result.hostname = result.host = srcPath.shift();
  30328. //occationaly the auth can get stuck only in host
  30329. //this especially happens in cases like
  30330. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30331. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30332. result.host.split('@') : false;
  30333. if (authInHost) {
  30334. result.auth = authInHost.shift();
  30335. result.host = result.hostname = authInHost.shift();
  30336. }
  30337. }
  30338. result.search = relative.search;
  30339. result.query = relative.query;
  30340. //to support http.request
  30341. if (!isNull(result.pathname) || !isNull(result.search)) {
  30342. result.path = (result.pathname ? result.pathname : '') +
  30343. (result.search ? result.search : '');
  30344. }
  30345. result.href = result.format();
  30346. return result;
  30347. }
  30348. if (!srcPath.length) {
  30349. // no path at all. easy.
  30350. // we've already handled the other stuff above.
  30351. result.pathname = null;
  30352. //to support http.request
  30353. if (result.search) {
  30354. result.path = '/' + result.search;
  30355. } else {
  30356. result.path = null;
  30357. }
  30358. result.href = result.format();
  30359. return result;
  30360. }
  30361. // if a url ENDs in . or .., then it must get a trailing slash.
  30362. // however, if it ends in anything else non-slashy,
  30363. // then it must NOT get a trailing slash.
  30364. var last = srcPath.slice(-1)[0];
  30365. var hasTrailingSlash = (
  30366. (result.host || relative.host || srcPath.length > 1) &&
  30367. (last === '.' || last === '..') || last === '');
  30368. // strip single dots, resolve double dots to parent dir
  30369. // if the path tries to go above the root, `up` ends up > 0
  30370. var up = 0;
  30371. for (var i = srcPath.length; i >= 0; i--) {
  30372. last = srcPath[i];
  30373. if (last === '.') {
  30374. srcPath.splice(i, 1);
  30375. } else if (last === '..') {
  30376. srcPath.splice(i, 1);
  30377. up++;
  30378. } else if (up) {
  30379. srcPath.splice(i, 1);
  30380. up--;
  30381. }
  30382. }
  30383. // if the path is allowed to go above the root, restore leading ..s
  30384. if (!mustEndAbs && !removeAllDots) {
  30385. for (; up--; up) {
  30386. srcPath.unshift('..');
  30387. }
  30388. }
  30389. if (mustEndAbs && srcPath[0] !== '' &&
  30390. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  30391. srcPath.unshift('');
  30392. }
  30393. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  30394. srcPath.push('');
  30395. }
  30396. var isAbsolute = srcPath[0] === '' ||
  30397. (srcPath[0] && srcPath[0].charAt(0) === '/');
  30398. // put the host back
  30399. if (psychotic) {
  30400. result.hostname = result.host = isAbsolute ? '' :
  30401. srcPath.length ? srcPath.shift() : '';
  30402. //occationaly the auth can get stuck only in host
  30403. //this especially happens in cases like
  30404. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  30405. authInHost = result.host && result.host.indexOf('@') > 0 ?
  30406. result.host.split('@') : false;
  30407. if (authInHost) {
  30408. result.auth = authInHost.shift();
  30409. result.host = result.hostname = authInHost.shift();
  30410. }
  30411. }
  30412. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  30413. if (mustEndAbs && !isAbsolute) {
  30414. srcPath.unshift('');
  30415. }
  30416. if (!srcPath.length) {
  30417. result.pathname = null;
  30418. result.path = null;
  30419. } else {
  30420. result.pathname = srcPath.join('/');
  30421. }
  30422. //to support request.http
  30423. if (!isNull(result.pathname) || !isNull(result.search)) {
  30424. result.path = (result.pathname ? result.pathname : '') +
  30425. (result.search ? result.search : '');
  30426. }
  30427. result.auth = relative.auth || result.auth;
  30428. result.slashes = result.slashes || relative.slashes;
  30429. result.href = result.format();
  30430. return result;
  30431. };
  30432. Url.prototype.parseHost = function() {
  30433. return parseHost(this);
  30434. };
  30435. function parseHost(self) {
  30436. var host = self.host;
  30437. var port = portPattern.exec(host);
  30438. if (port) {
  30439. port = port[0];
  30440. if (port !== ':') {
  30441. self.port = port.substr(1);
  30442. }
  30443. host = host.substr(0, host.length - port.length);
  30444. }
  30445. if (host) self.hostname = host;
  30446. }
  30447. var _polyfillNode_url$1 = /*#__PURE__*/Object.freeze({
  30448. __proto__: null,
  30449. URL: URL$1,
  30450. URLSearchParams: URLSearchParams,
  30451. Url: Url,
  30452. default: _polyfillNode_url,
  30453. fileURLToPath: urlFileURLToPath,
  30454. format: urlFormat,
  30455. parse: urlParse,
  30456. resolve: urlResolve,
  30457. resolveObject: urlResolveObject
  30458. });
  30459. function isRelativeUrl(url) {
  30460. const firstChar = url.charAt(0);
  30461. return firstChar === "." || firstChar === "~" || firstChar === "@";
  30462. }
  30463. const externalRE = /^(https?:)?\/\//;
  30464. function isExternalUrl(url) {
  30465. return externalRE.test(url);
  30466. }
  30467. const dataUrlRE = /^\s*data:/i;
  30468. function isDataUrl(url) {
  30469. return dataUrlRE.test(url);
  30470. }
  30471. function parseUrl(url) {
  30472. const firstChar = url.charAt(0);
  30473. if (firstChar === "~") {
  30474. const secondChar = url.charAt(1);
  30475. url = url.slice(secondChar === "/" ? 2 : 1);
  30476. }
  30477. return parseUriParts(url);
  30478. }
  30479. function parseUriParts(urlString) {
  30480. return urlParse(isString$1(urlString) ? urlString : "", false, true);
  30481. }
  30482. var __defProp$9 = Object.defineProperty;
  30483. var __defProps$8 = Object.defineProperties;
  30484. var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
  30485. var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
  30486. var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
  30487. var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
  30488. var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  30489. var __spreadValues$9 = (a, b) => {
  30490. for (var prop in b || (b = {}))
  30491. if (__hasOwnProp$9.call(b, prop))
  30492. __defNormalProp$9(a, prop, b[prop]);
  30493. if (__getOwnPropSymbols$9)
  30494. for (var prop of __getOwnPropSymbols$9(b)) {
  30495. if (__propIsEnum$9.call(b, prop))
  30496. __defNormalProp$9(a, prop, b[prop]);
  30497. }
  30498. return a;
  30499. };
  30500. var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
  30501. const defaultAssetUrlOptions = {
  30502. base: null,
  30503. includeAbsolute: false,
  30504. tags: {
  30505. video: ["src", "poster"],
  30506. source: ["src"],
  30507. img: ["src"],
  30508. image: ["xlink:href", "href"],
  30509. use: ["xlink:href", "href"]
  30510. }
  30511. };
  30512. const normalizeOptions = (options) => {
  30513. if (Object.keys(options).some((key) => isArray$3(options[key]))) {
  30514. return __spreadProps$8(__spreadValues$9({}, defaultAssetUrlOptions), {
  30515. tags: options
  30516. });
  30517. }
  30518. return __spreadValues$9(__spreadValues$9({}, defaultAssetUrlOptions), options);
  30519. };
  30520. const createAssetUrlTransformWithOptions = (options) => {
  30521. return (node, context) => transformAssetUrl(node, context, options);
  30522. };
  30523. const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
  30524. if (node.type === 1) {
  30525. if (!node.props.length) {
  30526. return;
  30527. }
  30528. const tags = options.tags || defaultAssetUrlOptions.tags;
  30529. const attrs = tags[node.tag];
  30530. const wildCardAttrs = tags["*"];
  30531. if (!attrs && !wildCardAttrs) {
  30532. return;
  30533. }
  30534. const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
  30535. node.props.forEach((attr, index) => {
  30536. 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)) {
  30537. return;
  30538. }
  30539. const url = parseUrl(attr.value.content);
  30540. if (options.base && attr.value.content[0] === ".") {
  30541. const base = parseUrl(options.base);
  30542. const protocol = base.protocol || "";
  30543. const host = base.host ? protocol + "//" + base.host : "";
  30544. const basePath = base.path || "/";
  30545. attr.value.content = host + (path.posix || path).join(basePath, url.path + (url.hash || ""));
  30546. return;
  30547. }
  30548. const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
  30549. node.props[index] = {
  30550. type: 7,
  30551. name: "bind",
  30552. arg: createSimpleExpression(attr.name, true, attr.loc),
  30553. exp,
  30554. modifiers: [],
  30555. loc: attr.loc
  30556. };
  30557. });
  30558. }
  30559. };
  30560. function getImportsExpressionExp(path2, hash, loc, context) {
  30561. if (path2) {
  30562. let name;
  30563. let exp;
  30564. const existingIndex = context.imports.findIndex((i) => i.path === path2);
  30565. if (existingIndex > -1) {
  30566. name = `_imports_${existingIndex}`;
  30567. exp = context.imports[existingIndex].exp;
  30568. } else {
  30569. name = `_imports_${context.imports.length}`;
  30570. exp = createSimpleExpression(
  30571. name,
  30572. false,
  30573. loc,
  30574. 3
  30575. );
  30576. context.imports.push({
  30577. exp,
  30578. path: decodeURIComponent(path2)
  30579. });
  30580. }
  30581. if (!hash) {
  30582. return exp;
  30583. }
  30584. const hashExp = `${name} + '${hash}'`;
  30585. const finalExp = createSimpleExpression(
  30586. hashExp,
  30587. false,
  30588. loc,
  30589. 3
  30590. );
  30591. if (!context.hoistStatic) {
  30592. return finalExp;
  30593. }
  30594. const existingHoistIndex = context.hoists.findIndex((h) => {
  30595. return h && h.type === 4 && !h.isStatic && h.content === hashExp;
  30596. });
  30597. if (existingHoistIndex > -1) {
  30598. return createSimpleExpression(
  30599. `_hoisted_${existingHoistIndex + 1}`,
  30600. false,
  30601. loc,
  30602. 3
  30603. );
  30604. }
  30605. return context.hoist(finalExp);
  30606. } else {
  30607. return createSimpleExpression(`''`, false, loc, 3);
  30608. }
  30609. }
  30610. const srcsetTags = ["img", "source"];
  30611. const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
  30612. const createSrcsetTransformWithOptions = (options) => {
  30613. return (node, context) => transformSrcset(node, context, options);
  30614. };
  30615. const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
  30616. if (node.type === 1) {
  30617. if (srcsetTags.includes(node.tag) && node.props.length) {
  30618. node.props.forEach((attr, index) => {
  30619. if (attr.name === "srcset" && attr.type === 6) {
  30620. if (!attr.value) return;
  30621. const value = attr.value.content;
  30622. if (!value) return;
  30623. const imageCandidates = value.split(",").map((s) => {
  30624. const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
  30625. return { url, descriptor };
  30626. });
  30627. for (let i = 0; i < imageCandidates.length; i++) {
  30628. const { url } = imageCandidates[i];
  30629. if (isDataUrl(url)) {
  30630. imageCandidates[i + 1].url = url + "," + imageCandidates[i + 1].url;
  30631. imageCandidates.splice(i, 1);
  30632. }
  30633. }
  30634. const shouldProcessUrl = (url) => {
  30635. return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
  30636. };
  30637. if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
  30638. return;
  30639. }
  30640. if (options.base) {
  30641. const base = options.base;
  30642. const set = [];
  30643. let needImportTransform = false;
  30644. imageCandidates.forEach((candidate) => {
  30645. let { url, descriptor } = candidate;
  30646. descriptor = descriptor ? ` ${descriptor}` : ``;
  30647. if (url[0] === ".") {
  30648. candidate.url = (path.posix || path).join(base, url);
  30649. set.push(candidate.url + descriptor);
  30650. } else if (shouldProcessUrl(url)) {
  30651. needImportTransform = true;
  30652. } else {
  30653. set.push(url + descriptor);
  30654. }
  30655. });
  30656. if (!needImportTransform) {
  30657. attr.value.content = set.join(", ");
  30658. return;
  30659. }
  30660. }
  30661. const compoundExpression = createCompoundExpression([], attr.loc);
  30662. imageCandidates.forEach(({ url, descriptor }, index2) => {
  30663. if (shouldProcessUrl(url)) {
  30664. const { path: path2 } = parseUrl(url);
  30665. let exp2;
  30666. if (path2) {
  30667. const existingImportsIndex = context.imports.findIndex(
  30668. (i) => i.path === path2
  30669. );
  30670. if (existingImportsIndex > -1) {
  30671. exp2 = createSimpleExpression(
  30672. `_imports_${existingImportsIndex}`,
  30673. false,
  30674. attr.loc,
  30675. 3
  30676. );
  30677. } else {
  30678. exp2 = createSimpleExpression(
  30679. `_imports_${context.imports.length}`,
  30680. false,
  30681. attr.loc,
  30682. 3
  30683. );
  30684. context.imports.push({ exp: exp2, path: path2 });
  30685. }
  30686. compoundExpression.children.push(exp2);
  30687. }
  30688. } else {
  30689. const exp2 = createSimpleExpression(
  30690. `"${url}"`,
  30691. false,
  30692. attr.loc,
  30693. 3
  30694. );
  30695. compoundExpression.children.push(exp2);
  30696. }
  30697. const isNotLast = imageCandidates.length - 1 > index2;
  30698. if (descriptor && isNotLast) {
  30699. compoundExpression.children.push(` + ' ${descriptor}, ' + `);
  30700. } else if (descriptor) {
  30701. compoundExpression.children.push(` + ' ${descriptor}'`);
  30702. } else if (isNotLast) {
  30703. compoundExpression.children.push(` + ', ' + `);
  30704. }
  30705. });
  30706. let exp = compoundExpression;
  30707. if (context.hoistStatic) {
  30708. exp = context.hoist(compoundExpression);
  30709. exp.constType = 3;
  30710. }
  30711. node.props[index] = {
  30712. type: 7,
  30713. name: "bind",
  30714. arg: createSimpleExpression("srcset", true, attr.loc),
  30715. exp,
  30716. modifiers: [],
  30717. loc: attr.loc
  30718. };
  30719. }
  30720. });
  30721. }
  30722. }
  30723. };
  30724. const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
  30725. const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
  30726. const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
  30727. const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
  30728. const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
  30729. const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
  30730. const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
  30731. const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
  30732. const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`);
  30733. const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`);
  30734. const SSR_RENDER_LIST = Symbol(`ssrRenderList`);
  30735. const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(
  30736. `ssrIncludeBooleanAttr`
  30737. );
  30738. const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`);
  30739. const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`);
  30740. const SSR_RENDER_DYNAMIC_MODEL = Symbol(
  30741. `ssrRenderDynamicModel`
  30742. );
  30743. const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(
  30744. `ssrGetDynamicModelProps`
  30745. );
  30746. const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
  30747. const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
  30748. const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`);
  30749. const ssrHelpers = {
  30750. [SSR_INTERPOLATE]: `ssrInterpolate`,
  30751. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  30752. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  30753. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  30754. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  30755. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  30756. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  30757. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  30758. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  30759. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  30760. [SSR_RENDER_LIST]: `ssrRenderList`,
  30761. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  30762. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  30763. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  30764. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  30765. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  30766. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  30767. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  30768. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  30769. };
  30770. registerRuntimeHelpers(ssrHelpers);
  30771. const ssrTransformIf = createStructuralDirectiveTransform(
  30772. /^(if|else|else-if)$/,
  30773. processIf
  30774. );
  30775. function ssrProcessIf(node, context, disableNestedFragments = false, disableComment = false) {
  30776. const [rootBranch] = node.branches;
  30777. const ifStatement = createIfStatement(
  30778. rootBranch.condition,
  30779. processIfBranch(rootBranch, context, disableNestedFragments)
  30780. );
  30781. context.pushStatement(ifStatement);
  30782. let currentIf = ifStatement;
  30783. for (let i = 1; i < node.branches.length; i++) {
  30784. const branch = node.branches[i];
  30785. const branchBlockStatement = processIfBranch(
  30786. branch,
  30787. context,
  30788. disableNestedFragments
  30789. );
  30790. if (branch.condition) {
  30791. currentIf = currentIf.alternate = createIfStatement(
  30792. branch.condition,
  30793. branchBlockStatement
  30794. );
  30795. } else {
  30796. currentIf.alternate = branchBlockStatement;
  30797. }
  30798. }
  30799. if (!currentIf.alternate && !disableComment) {
  30800. currentIf.alternate = createBlockStatement([
  30801. createCallExpression(`_push`, ["`<!---->`"])
  30802. ]);
  30803. }
  30804. }
  30805. function processIfBranch(branch, context, disableNestedFragments = false) {
  30806. const { children } = branch;
  30807. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  30808. !(children.length === 1 && children[0].type === 11);
  30809. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  30810. }
  30811. const ssrTransformFor = createStructuralDirectiveTransform("for", processFor);
  30812. function ssrProcessFor(node, context, disableNestedFragments = false) {
  30813. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  30814. const renderLoop = createFunctionExpression(
  30815. createForLoopParams(node.parseResult)
  30816. );
  30817. renderLoop.body = processChildrenAsStatement(
  30818. node,
  30819. context,
  30820. needFragmentWrapper
  30821. );
  30822. if (!disableNestedFragments) {
  30823. context.pushStringPart(`<!--[-->`);
  30824. }
  30825. context.pushStatement(
  30826. createCallExpression(context.helper(SSR_RENDER_LIST), [
  30827. node.source,
  30828. renderLoop
  30829. ])
  30830. );
  30831. if (!disableNestedFragments) {
  30832. context.pushStringPart(`<!--]-->`);
  30833. }
  30834. }
  30835. const ssrTransformSlotOutlet = (node, context) => {
  30836. if (isSlotOutlet(node)) {
  30837. const { slotName, slotProps } = processSlotOutlet(node, context);
  30838. const args = [
  30839. `_ctx.$slots`,
  30840. slotName,
  30841. slotProps || `{}`,
  30842. // fallback content placeholder. will be replaced in the process phase
  30843. `null`,
  30844. `_push`,
  30845. `_parent`
  30846. ];
  30847. if (context.scopeId && context.slotted !== false) {
  30848. args.push(`"${context.scopeId}-s"`);
  30849. }
  30850. let method = SSR_RENDER_SLOT;
  30851. let parent = context.parent;
  30852. if (parent) {
  30853. const children = parent.children;
  30854. if (parent.type === 10) {
  30855. parent = context.grandParent;
  30856. }
  30857. let componentType;
  30858. if (parent.type === 1 && parent.tagType === 1 && ((componentType = resolveComponentType(parent, context, true)) === TRANSITION || componentType === TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) {
  30859. method = SSR_RENDER_SLOT_INNER;
  30860. if (!(context.scopeId && context.slotted !== false)) {
  30861. args.push("null");
  30862. }
  30863. args.push("true");
  30864. }
  30865. }
  30866. node.ssrCodegenNode = createCallExpression(context.helper(method), args);
  30867. }
  30868. };
  30869. function ssrProcessSlotOutlet(node, context) {
  30870. const renderCall = node.ssrCodegenNode;
  30871. if (node.children.length) {
  30872. const fallbackRenderFn = createFunctionExpression([]);
  30873. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  30874. renderCall.arguments[3] = fallbackRenderFn;
  30875. }
  30876. if (context.withSlotScopeId) {
  30877. const slotScopeId = renderCall.arguments[6];
  30878. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  30879. }
  30880. context.pushStatement(node.ssrCodegenNode);
  30881. }
  30882. function createSSRCompilerError(code, loc) {
  30883. return createCompilerError(code, loc, SSRErrorMessages);
  30884. }
  30885. const SSRErrorMessages = {
  30886. [65]: `Unsafe attribute name for SSR.`,
  30887. [66]: `Missing the 'to' prop on teleport element.`,
  30888. [67]: `Invalid AST node during SSR transform.`
  30889. };
  30890. function ssrProcessTeleport(node, context) {
  30891. const targetProp = findProp(node, "to");
  30892. if (!targetProp) {
  30893. context.onError(
  30894. createSSRCompilerError(66, node.loc)
  30895. );
  30896. return;
  30897. }
  30898. let target;
  30899. if (targetProp.type === 6) {
  30900. target = targetProp.value && createSimpleExpression(targetProp.value.content, true);
  30901. } else {
  30902. target = targetProp.exp;
  30903. }
  30904. if (!target) {
  30905. context.onError(
  30906. createSSRCompilerError(
  30907. 66,
  30908. targetProp.loc
  30909. )
  30910. );
  30911. return;
  30912. }
  30913. const disabledProp = findProp(
  30914. node,
  30915. "disabled",
  30916. false,
  30917. true
  30918. /* allow empty */
  30919. );
  30920. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  30921. const contentRenderFn = createFunctionExpression(
  30922. [`_push`],
  30923. void 0,
  30924. // Body is added later
  30925. true,
  30926. // newline
  30927. false,
  30928. // isSlot
  30929. node.loc
  30930. );
  30931. contentRenderFn.body = processChildrenAsStatement(node, context);
  30932. context.pushStatement(
  30933. createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  30934. `_push`,
  30935. contentRenderFn,
  30936. target,
  30937. disabled,
  30938. `_parent`
  30939. ])
  30940. );
  30941. }
  30942. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  30943. function ssrTransformSuspense(node, context) {
  30944. return () => {
  30945. if (node.children.length) {
  30946. const wipEntry = {
  30947. slotsExp: null,
  30948. // to be immediately set
  30949. wipSlots: []
  30950. };
  30951. wipMap$3.set(node, wipEntry);
  30952. wipEntry.slotsExp = buildSlots(
  30953. node,
  30954. context,
  30955. (_props, _vForExp, children, loc) => {
  30956. const fn = createFunctionExpression(
  30957. [],
  30958. void 0,
  30959. // no return, assign body later
  30960. true,
  30961. // newline
  30962. false,
  30963. // suspense slots are not treated as normal slots
  30964. loc
  30965. );
  30966. wipEntry.wipSlots.push({
  30967. fn,
  30968. children
  30969. });
  30970. return fn;
  30971. }
  30972. ).slots;
  30973. }
  30974. };
  30975. }
  30976. function ssrProcessSuspense(node, context) {
  30977. const wipEntry = wipMap$3.get(node);
  30978. if (!wipEntry) {
  30979. return;
  30980. }
  30981. const { slotsExp, wipSlots } = wipEntry;
  30982. for (let i = 0; i < wipSlots.length; i++) {
  30983. const slot = wipSlots[i];
  30984. slot.fn.body = processChildrenAsStatement(slot, context);
  30985. }
  30986. context.pushStatement(
  30987. createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  30988. `_push`,
  30989. slotsExp
  30990. ])
  30991. );
  30992. }
  30993. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  30994. const ssrTransformElement = (node, context) => {
  30995. if (node.type !== 1 || node.tagType !== 0) {
  30996. return;
  30997. }
  30998. return function ssrPostTransformElement() {
  30999. const openTag = [`<${node.tag}`];
  31000. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  31001. const hasDynamicVBind = hasDynamicKeyVBind(node);
  31002. const hasCustomDir = node.props.some(
  31003. (p) => p.type === 7 && !isBuiltInDirective(p.name)
  31004. );
  31005. const needMergeProps = hasDynamicVBind || hasCustomDir;
  31006. if (needMergeProps) {
  31007. const { props, directives } = buildProps(
  31008. node,
  31009. context,
  31010. node.props,
  31011. false,
  31012. false,
  31013. true
  31014. );
  31015. if (props || directives.length) {
  31016. const mergedProps = buildSSRProps(props, directives, context);
  31017. const propsExp = createCallExpression(
  31018. context.helper(SSR_RENDER_ATTRS),
  31019. [mergedProps]
  31020. );
  31021. if (node.tag === "textarea") {
  31022. const existingText = node.children[0];
  31023. if (!existingText || existingText.type !== 5) {
  31024. const tempId = `_temp${context.temps++}`;
  31025. propsExp.arguments = [
  31026. createAssignmentExpression(
  31027. createSimpleExpression(tempId, false),
  31028. mergedProps
  31029. )
  31030. ];
  31031. rawChildrenMap.set(
  31032. node,
  31033. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31034. createConditionalExpression(
  31035. createSimpleExpression(`"value" in ${tempId}`, false),
  31036. createSimpleExpression(`${tempId}.value`, false),
  31037. createSimpleExpression(
  31038. existingText ? existingText.content : ``,
  31039. true
  31040. ),
  31041. false
  31042. )
  31043. ])
  31044. );
  31045. }
  31046. } else if (node.tag === "input") {
  31047. const vModel = findVModel(node);
  31048. if (vModel) {
  31049. const tempId = `_temp${context.temps++}`;
  31050. const tempExp = createSimpleExpression(tempId, false);
  31051. propsExp.arguments = [
  31052. createSequenceExpression([
  31053. createAssignmentExpression(tempExp, mergedProps),
  31054. createCallExpression(context.helper(MERGE_PROPS), [
  31055. tempExp,
  31056. createCallExpression(
  31057. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  31058. [
  31059. tempExp,
  31060. // existing props
  31061. vModel.exp
  31062. // model
  31063. ]
  31064. )
  31065. ])
  31066. ])
  31067. ];
  31068. }
  31069. } else if (directives.length && !node.children.length) {
  31070. const vText = findDir(node, "text");
  31071. if (!vText) {
  31072. const tempId = `_temp${context.temps++}`;
  31073. propsExp.arguments = [
  31074. createAssignmentExpression(
  31075. createSimpleExpression(tempId, false),
  31076. mergedProps
  31077. )
  31078. ];
  31079. rawChildrenMap.set(
  31080. node,
  31081. createConditionalExpression(
  31082. createSimpleExpression(`"textContent" in ${tempId}`, false),
  31083. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31084. createSimpleExpression(`${tempId}.textContent`, false)
  31085. ]),
  31086. createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
  31087. false
  31088. )
  31089. );
  31090. }
  31091. }
  31092. if (needTagForRuntime) {
  31093. propsExp.arguments.push(`"${node.tag}"`);
  31094. }
  31095. openTag.push(propsExp);
  31096. }
  31097. }
  31098. let dynamicClassBinding = void 0;
  31099. let staticClassBinding = void 0;
  31100. let dynamicStyleBinding = void 0;
  31101. for (let i = 0; i < node.props.length; i++) {
  31102. const prop = node.props[i];
  31103. if (node.tag === "input" && isTrueFalseValue(prop)) {
  31104. continue;
  31105. }
  31106. if (prop.type === 7) {
  31107. if (prop.name === "html" && prop.exp) {
  31108. rawChildrenMap.set(
  31109. node,
  31110. createCompoundExpression([`(`, prop.exp, `) ?? ''`])
  31111. );
  31112. } else if (prop.name === "text" && prop.exp) {
  31113. node.children = [createInterpolation(prop.exp, prop.loc)];
  31114. } else if (prop.name === "slot") {
  31115. context.onError(
  31116. createCompilerError(40, prop.loc)
  31117. );
  31118. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  31119. if (!needMergeProps) {
  31120. node.children = [createInterpolation(prop.exp, prop.loc)];
  31121. }
  31122. } else if (!needMergeProps && prop.name !== "on") {
  31123. const directiveTransform = context.directiveTransforms[prop.name];
  31124. if (directiveTransform) {
  31125. const { props, ssrTagParts } = directiveTransform(
  31126. prop,
  31127. node,
  31128. context
  31129. );
  31130. if (ssrTagParts) {
  31131. openTag.push(...ssrTagParts);
  31132. }
  31133. for (let j = 0; j < props.length; j++) {
  31134. const { key, value } = props[j];
  31135. if (isStaticExp(key)) {
  31136. let attrName = key.content;
  31137. if (attrName === "key" || attrName === "ref") {
  31138. continue;
  31139. }
  31140. if (attrName === "class") {
  31141. openTag.push(
  31142. ` class="`,
  31143. dynamicClassBinding = createCallExpression(
  31144. context.helper(SSR_RENDER_CLASS),
  31145. [value]
  31146. ),
  31147. `"`
  31148. );
  31149. } else if (attrName === "style") {
  31150. if (dynamicStyleBinding) {
  31151. mergeCall(dynamicStyleBinding, value);
  31152. } else {
  31153. openTag.push(
  31154. ` style="`,
  31155. dynamicStyleBinding = createCallExpression(
  31156. context.helper(SSR_RENDER_STYLE),
  31157. [value]
  31158. ),
  31159. `"`
  31160. );
  31161. }
  31162. } else {
  31163. attrName = node.tag.indexOf("-") > 0 ? attrName : propsToAttrMap[attrName] || attrName.toLowerCase();
  31164. if (isBooleanAttr(attrName)) {
  31165. openTag.push(
  31166. createConditionalExpression(
  31167. createCallExpression(
  31168. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  31169. [value]
  31170. ),
  31171. createSimpleExpression(" " + attrName, true),
  31172. createSimpleExpression("", true),
  31173. false
  31174. )
  31175. );
  31176. } else if (isSSRSafeAttrName(attrName)) {
  31177. openTag.push(
  31178. createCallExpression(context.helper(SSR_RENDER_ATTR), [
  31179. key,
  31180. value
  31181. ])
  31182. );
  31183. } else {
  31184. context.onError(
  31185. createSSRCompilerError(
  31186. 65,
  31187. key.loc
  31188. )
  31189. );
  31190. }
  31191. }
  31192. } else {
  31193. const args = [key, value];
  31194. if (needTagForRuntime) {
  31195. args.push(`"${node.tag}"`);
  31196. }
  31197. openTag.push(
  31198. createCallExpression(
  31199. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  31200. args
  31201. )
  31202. );
  31203. }
  31204. }
  31205. }
  31206. }
  31207. } else {
  31208. const name = prop.name;
  31209. if (node.tag === "textarea" && name === "value" && prop.value) {
  31210. rawChildrenMap.set(node, escapeHtml(prop.value.content));
  31211. } else if (!needMergeProps) {
  31212. if (name === "key" || name === "ref") {
  31213. continue;
  31214. }
  31215. if (name === "class" && prop.value) {
  31216. staticClassBinding = JSON.stringify(prop.value.content);
  31217. }
  31218. openTag.push(
  31219. ` ${prop.name}` + (prop.value ? `="${escapeHtml(prop.value.content)}"` : ``)
  31220. );
  31221. }
  31222. }
  31223. }
  31224. if (dynamicClassBinding && staticClassBinding) {
  31225. mergeCall(dynamicClassBinding, staticClassBinding);
  31226. removeStaticBinding(openTag, "class");
  31227. }
  31228. if (context.scopeId) {
  31229. openTag.push(` ${context.scopeId}`);
  31230. }
  31231. node.ssrCodegenNode = createTemplateLiteral(openTag);
  31232. };
  31233. };
  31234. function buildSSRProps(props, directives, context) {
  31235. let mergePropsArgs = [];
  31236. if (props) {
  31237. if (props.type === 14) {
  31238. mergePropsArgs = props.arguments;
  31239. } else {
  31240. mergePropsArgs.push(props);
  31241. }
  31242. }
  31243. if (directives.length) {
  31244. for (const dir of directives) {
  31245. mergePropsArgs.push(
  31246. createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  31247. `_ctx`,
  31248. ...buildDirectiveArgs(dir, context).elements
  31249. ])
  31250. );
  31251. }
  31252. }
  31253. return mergePropsArgs.length > 1 ? createCallExpression(context.helper(MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  31254. }
  31255. function isTrueFalseValue(prop) {
  31256. if (prop.type === 7) {
  31257. return prop.name === "bind" && prop.arg && isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  31258. } else {
  31259. return prop.name === "true-value" || prop.name === "false-value";
  31260. }
  31261. }
  31262. function isTextareaWithValue(node, prop) {
  31263. return !!(node.tag === "textarea" && prop.name === "bind" && isStaticArgOf(prop.arg, "value"));
  31264. }
  31265. function mergeCall(call, arg) {
  31266. const existing = call.arguments[0];
  31267. if (existing.type === 17) {
  31268. existing.elements.push(arg);
  31269. } else {
  31270. call.arguments[0] = createArrayExpression([existing, arg]);
  31271. }
  31272. }
  31273. function removeStaticBinding(tag, binding) {
  31274. const regExp = new RegExp(`^ ${binding}=".+"$`);
  31275. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  31276. if (i > -1) {
  31277. tag.splice(i, 1);
  31278. }
  31279. }
  31280. function findVModel(node) {
  31281. return node.props.find(
  31282. (p) => p.type === 7 && p.name === "model" && p.exp
  31283. );
  31284. }
  31285. function ssrProcessElement(node, context) {
  31286. const isVoidTag = context.options.isVoidTag || NO;
  31287. const elementsToAdd = node.ssrCodegenNode.elements;
  31288. for (let j = 0; j < elementsToAdd.length; j++) {
  31289. context.pushStringPart(elementsToAdd[j]);
  31290. }
  31291. if (context.withSlotScopeId) {
  31292. context.pushStringPart(createSimpleExpression(`_scopeId`, false));
  31293. }
  31294. context.pushStringPart(`>`);
  31295. const rawChildren = rawChildrenMap.get(node);
  31296. if (rawChildren) {
  31297. context.pushStringPart(rawChildren);
  31298. } else if (node.children.length) {
  31299. processChildren(node, context);
  31300. }
  31301. if (!isVoidTag(node.tag)) {
  31302. context.pushStringPart(`</${node.tag}>`);
  31303. }
  31304. }
  31305. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  31306. function ssrTransformTransitionGroup(node, context) {
  31307. return () => {
  31308. const tag = findProp(node, "tag");
  31309. if (tag) {
  31310. const otherProps = node.props.filter((p) => p !== tag);
  31311. const { props, directives } = buildProps(
  31312. node,
  31313. context,
  31314. otherProps,
  31315. true,
  31316. false,
  31317. true
  31318. );
  31319. let propsExp = null;
  31320. if (props || directives.length) {
  31321. propsExp = createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  31322. buildSSRProps(props, directives, context)
  31323. ]);
  31324. }
  31325. wipMap$2.set(node, {
  31326. tag,
  31327. propsExp,
  31328. scopeId: context.scopeId || null
  31329. });
  31330. }
  31331. };
  31332. }
  31333. function ssrProcessTransitionGroup(node, context) {
  31334. const entry = wipMap$2.get(node);
  31335. if (entry) {
  31336. const { tag, propsExp, scopeId } = entry;
  31337. if (tag.type === 7) {
  31338. context.pushStringPart(`<`);
  31339. context.pushStringPart(tag.exp);
  31340. if (propsExp) {
  31341. context.pushStringPart(propsExp);
  31342. }
  31343. if (scopeId) {
  31344. context.pushStringPart(` ${scopeId}`);
  31345. }
  31346. context.pushStringPart(`>`);
  31347. processChildren(
  31348. node,
  31349. context,
  31350. false,
  31351. /**
  31352. * TransitionGroup has the special runtime behavior of flattening and
  31353. * concatenating all children into a single fragment (in order for them to
  31354. * be patched using the same key map) so we need to account for that here
  31355. * by disabling nested fragment wrappers from being generated.
  31356. */
  31357. true,
  31358. /**
  31359. * TransitionGroup filters out comment children at runtime and thus
  31360. * doesn't expect comments to be present during hydration. We need to
  31361. * account for that by disabling the empty comment that is otherwise
  31362. * rendered for a falsy v-if that has no v-else specified. (#6715)
  31363. */
  31364. true
  31365. );
  31366. context.pushStringPart(`</`);
  31367. context.pushStringPart(tag.exp);
  31368. context.pushStringPart(`>`);
  31369. } else {
  31370. context.pushStringPart(`<${tag.value.content}`);
  31371. if (propsExp) {
  31372. context.pushStringPart(propsExp);
  31373. }
  31374. if (scopeId) {
  31375. context.pushStringPart(` ${scopeId}`);
  31376. }
  31377. context.pushStringPart(`>`);
  31378. processChildren(node, context, false, true, true);
  31379. context.pushStringPart(`</${tag.value.content}>`);
  31380. }
  31381. } else {
  31382. processChildren(node, context, true, true, true);
  31383. }
  31384. }
  31385. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  31386. function ssrTransformTransition(node, context) {
  31387. return () => {
  31388. const appear = findProp(node, "appear", false, true);
  31389. wipMap$1.set(node, !!appear);
  31390. };
  31391. }
  31392. function ssrProcessTransition(node, context) {
  31393. node.children = node.children.filter((c) => c.type !== 3);
  31394. const appear = wipMap$1.get(node);
  31395. if (appear) {
  31396. context.pushStringPart(`<template>`);
  31397. processChildren(node, context, false, true);
  31398. context.pushStringPart(`</template>`);
  31399. } else {
  31400. processChildren(node, context, false, true);
  31401. }
  31402. }
  31403. var __defProp$8 = Object.defineProperty;
  31404. var __defProps$7 = Object.defineProperties;
  31405. var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
  31406. var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
  31407. var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
  31408. var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
  31409. var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  31410. var __spreadValues$8 = (a, b) => {
  31411. for (var prop in b || (b = {}))
  31412. if (__hasOwnProp$8.call(b, prop))
  31413. __defNormalProp$8(a, prop, b[prop]);
  31414. if (__getOwnPropSymbols$8)
  31415. for (var prop of __getOwnPropSymbols$8(b)) {
  31416. if (__propIsEnum$8.call(b, prop))
  31417. __defNormalProp$8(a, prop, b[prop]);
  31418. }
  31419. return a;
  31420. };
  31421. var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
  31422. const wipMap = /* @__PURE__ */ new WeakMap();
  31423. const WIP_SLOT = Symbol();
  31424. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  31425. const ssrTransformComponent = (node, context) => {
  31426. if (node.type !== 1 || node.tagType !== 1) {
  31427. return;
  31428. }
  31429. const component = resolveComponentType(
  31430. node,
  31431. context,
  31432. true
  31433. /* ssr */
  31434. );
  31435. const isDynamicComponent = isObject$2(component) && component.callee === RESOLVE_DYNAMIC_COMPONENT;
  31436. componentTypeMap.set(node, component);
  31437. if (isSymbol$1(component)) {
  31438. if (component === SUSPENSE) {
  31439. return ssrTransformSuspense(node, context);
  31440. } else if (component === TRANSITION_GROUP) {
  31441. return ssrTransformTransitionGroup(node, context);
  31442. } else if (component === TRANSITION) {
  31443. return ssrTransformTransition(node);
  31444. }
  31445. return;
  31446. }
  31447. const vnodeBranches = [];
  31448. const clonedNode = clone(node);
  31449. return function ssrPostTransformComponent() {
  31450. if (clonedNode.children.length) {
  31451. buildSlots(clonedNode, context, (props, vFor, children) => {
  31452. vnodeBranches.push(
  31453. createVNodeSlotBranch(props, vFor, children, context)
  31454. );
  31455. return createFunctionExpression(void 0);
  31456. });
  31457. }
  31458. let propsExp = `null`;
  31459. if (node.props.length) {
  31460. const { props, directives } = buildProps(
  31461. node,
  31462. context,
  31463. void 0,
  31464. true,
  31465. isDynamicComponent
  31466. );
  31467. if (props || directives.length) {
  31468. propsExp = buildSSRProps(props, directives, context);
  31469. }
  31470. }
  31471. const wipEntries = [];
  31472. wipMap.set(node, wipEntries);
  31473. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  31474. const param0 = props && stringifyExpression(props) || `_`;
  31475. const fn = createFunctionExpression(
  31476. [param0, `_push`, `_parent`, `_scopeId`],
  31477. void 0,
  31478. // no return, assign body later
  31479. true,
  31480. // newline
  31481. true,
  31482. // isSlot
  31483. loc
  31484. );
  31485. wipEntries.push({
  31486. type: WIP_SLOT,
  31487. fn,
  31488. children,
  31489. // also collect the corresponding vnode branch built earlier
  31490. vnodeBranch: vnodeBranches[wipEntries.length]
  31491. });
  31492. return fn;
  31493. };
  31494. const slots = node.children.length ? buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  31495. if (typeof component !== "string") {
  31496. node.ssrCodegenNode = createCallExpression(
  31497. context.helper(SSR_RENDER_VNODE),
  31498. [
  31499. `_push`,
  31500. createCallExpression(context.helper(CREATE_VNODE), [
  31501. component,
  31502. propsExp,
  31503. slots
  31504. ]),
  31505. `_parent`
  31506. ]
  31507. );
  31508. } else {
  31509. node.ssrCodegenNode = createCallExpression(
  31510. context.helper(SSR_RENDER_COMPONENT),
  31511. [component, propsExp, slots, `_parent`]
  31512. );
  31513. }
  31514. };
  31515. };
  31516. function ssrProcessComponent(node, context, parent) {
  31517. const component = componentTypeMap.get(node);
  31518. if (!node.ssrCodegenNode) {
  31519. if (component === TELEPORT) {
  31520. return ssrProcessTeleport(node, context);
  31521. } else if (component === SUSPENSE) {
  31522. return ssrProcessSuspense(node, context);
  31523. } else if (component === TRANSITION_GROUP) {
  31524. return ssrProcessTransitionGroup(node, context);
  31525. } else {
  31526. if (parent.type === WIP_SLOT) {
  31527. context.pushStringPart(``);
  31528. }
  31529. if (component === TRANSITION) {
  31530. return ssrProcessTransition(node, context);
  31531. }
  31532. processChildren(node, context);
  31533. }
  31534. } else {
  31535. const wipEntries = wipMap.get(node) || [];
  31536. for (let i = 0; i < wipEntries.length; i++) {
  31537. const { fn, vnodeBranch } = wipEntries[i];
  31538. fn.body = createIfStatement(
  31539. createSimpleExpression(`_push`, false),
  31540. processChildrenAsStatement(
  31541. wipEntries[i],
  31542. context,
  31543. false,
  31544. true
  31545. ),
  31546. vnodeBranch
  31547. );
  31548. }
  31549. if (context.withSlotScopeId) {
  31550. node.ssrCodegenNode.arguments.push(`_scopeId`);
  31551. }
  31552. if (typeof component === "string") {
  31553. context.pushStatement(
  31554. createCallExpression(`_push`, [node.ssrCodegenNode])
  31555. );
  31556. } else {
  31557. context.pushStatement(node.ssrCodegenNode);
  31558. }
  31559. }
  31560. }
  31561. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  31562. const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(true);
  31563. const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms];
  31564. const vnodeDirectiveTransforms = __spreadValues$8(__spreadValues$8({}, baseDirectiveTransforms), DOMDirectiveTransforms);
  31565. function createVNodeSlotBranch(slotProps, vFor, children, parentContext) {
  31566. const rawOptions = rawOptionsMap.get(parentContext.root);
  31567. const subOptions = __spreadProps$7(__spreadValues$8({}, rawOptions), {
  31568. // overwrite with vnode-based transforms
  31569. nodeTransforms: [
  31570. ...vnodeNodeTransforms,
  31571. ...rawOptions.nodeTransforms || []
  31572. ],
  31573. directiveTransforms: __spreadValues$8(__spreadValues$8({}, vnodeDirectiveTransforms), rawOptions.directiveTransforms || {})
  31574. });
  31575. const wrapperProps = [];
  31576. if (slotProps) {
  31577. wrapperProps.push({
  31578. type: 7,
  31579. name: "slot",
  31580. exp: slotProps,
  31581. arg: void 0,
  31582. modifiers: [],
  31583. loc: locStub
  31584. });
  31585. }
  31586. if (vFor) {
  31587. wrapperProps.push(extend({}, vFor));
  31588. }
  31589. const wrapperNode = {
  31590. type: 1,
  31591. ns: 0,
  31592. tag: "template",
  31593. tagType: 3,
  31594. props: wrapperProps,
  31595. children,
  31596. loc: locStub,
  31597. codegenNode: void 0
  31598. };
  31599. subTransform(wrapperNode, subOptions, parentContext);
  31600. return createReturnStatement(children);
  31601. }
  31602. function subTransform(node, options, parentContext) {
  31603. const childRoot = createRoot([node]);
  31604. const childContext = createTransformContext(childRoot, options);
  31605. childContext.ssr = false;
  31606. childContext.scopes = __spreadValues$8({}, parentContext.scopes);
  31607. childContext.identifiers = __spreadValues$8({}, parentContext.identifiers);
  31608. childContext.imports = parentContext.imports;
  31609. traverseNode(childRoot, childContext);
  31610. ["helpers", "components", "directives"].forEach((key) => {
  31611. childContext[key].forEach((value, helperKey) => {
  31612. if (key === "helpers") {
  31613. const parentCount = parentContext.helpers.get(helperKey);
  31614. if (parentCount === void 0) {
  31615. parentContext.helpers.set(helperKey, value);
  31616. } else {
  31617. parentContext.helpers.set(helperKey, value + parentCount);
  31618. }
  31619. } else {
  31620. parentContext[key].add(value);
  31621. }
  31622. });
  31623. });
  31624. }
  31625. function clone(v) {
  31626. if (isArray$3(v)) {
  31627. return v.map(clone);
  31628. } else if (isPlainObject(v)) {
  31629. const res = {};
  31630. for (const key in v) {
  31631. res[key] = clone(v[key]);
  31632. }
  31633. return res;
  31634. } else {
  31635. return v;
  31636. }
  31637. }
  31638. function ssrCodegenTransform(ast, options) {
  31639. const context = createSSRTransformContext(ast, options);
  31640. if (options.ssrCssVars) {
  31641. const cssContext = createTransformContext(createRoot([]), options);
  31642. const varsExp = processExpression(
  31643. createSimpleExpression(options.ssrCssVars, false),
  31644. cssContext
  31645. );
  31646. context.body.push(
  31647. createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  31648. );
  31649. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  31650. ast.helpers.add(helper);
  31651. });
  31652. }
  31653. const isFragment = ast.children.length > 1 && ast.children.some((c) => !isText$1(c));
  31654. processChildren(ast, context, isFragment);
  31655. ast.codegenNode = createBlockStatement(context.body);
  31656. ast.ssrHelpers = Array.from(
  31657. /* @__PURE__ */ new Set([
  31658. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  31659. ...context.helpers
  31660. ])
  31661. );
  31662. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  31663. }
  31664. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  31665. const body = [];
  31666. let currentString = null;
  31667. return {
  31668. root,
  31669. options,
  31670. body,
  31671. helpers,
  31672. withSlotScopeId,
  31673. onError: options.onError || ((e) => {
  31674. throw e;
  31675. }),
  31676. helper(name) {
  31677. helpers.add(name);
  31678. return name;
  31679. },
  31680. pushStringPart(part) {
  31681. if (!currentString) {
  31682. const currentCall = createCallExpression(`_push`);
  31683. body.push(currentCall);
  31684. currentString = createTemplateLiteral([]);
  31685. currentCall.arguments.push(currentString);
  31686. }
  31687. const bufferedElements = currentString.elements;
  31688. const lastItem = bufferedElements[bufferedElements.length - 1];
  31689. if (isString$1(part) && isString$1(lastItem)) {
  31690. bufferedElements[bufferedElements.length - 1] += part;
  31691. } else {
  31692. bufferedElements.push(part);
  31693. }
  31694. },
  31695. pushStatement(statement) {
  31696. currentString = null;
  31697. body.push(statement);
  31698. }
  31699. };
  31700. }
  31701. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  31702. return createSSRTransformContext(
  31703. parent.root,
  31704. parent.options,
  31705. parent.helpers,
  31706. withSlotScopeId
  31707. );
  31708. }
  31709. function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableComment = false) {
  31710. if (asFragment) {
  31711. context.pushStringPart(`<!--[-->`);
  31712. }
  31713. const { children } = parent;
  31714. for (let i = 0; i < children.length; i++) {
  31715. const child = children[i];
  31716. switch (child.type) {
  31717. case 1:
  31718. switch (child.tagType) {
  31719. case 0:
  31720. ssrProcessElement(child, context);
  31721. break;
  31722. case 1:
  31723. ssrProcessComponent(child, context, parent);
  31724. break;
  31725. case 2:
  31726. ssrProcessSlotOutlet(child, context);
  31727. break;
  31728. case 3:
  31729. break;
  31730. default:
  31731. context.onError(
  31732. createSSRCompilerError(
  31733. 67,
  31734. child.loc
  31735. )
  31736. );
  31737. const exhaustiveCheck2 = child;
  31738. return exhaustiveCheck2;
  31739. }
  31740. break;
  31741. case 2:
  31742. context.pushStringPart(escapeHtml(child.content));
  31743. break;
  31744. case 3:
  31745. if (!disableComment) {
  31746. context.pushStringPart(`<!--${child.content}-->`);
  31747. }
  31748. break;
  31749. case 5:
  31750. context.pushStringPart(
  31751. createCallExpression(context.helper(SSR_INTERPOLATE), [
  31752. child.content
  31753. ])
  31754. );
  31755. break;
  31756. case 9:
  31757. ssrProcessIf(child, context, disableNestedFragments, disableComment);
  31758. break;
  31759. case 11:
  31760. ssrProcessFor(child, context, disableNestedFragments);
  31761. break;
  31762. case 10:
  31763. break;
  31764. case 12:
  31765. case 8:
  31766. break;
  31767. default:
  31768. context.onError(
  31769. createSSRCompilerError(
  31770. 67,
  31771. child.loc
  31772. )
  31773. );
  31774. const exhaustiveCheck = child;
  31775. return exhaustiveCheck;
  31776. }
  31777. }
  31778. if (asFragment) {
  31779. context.pushStringPart(`<!--]-->`);
  31780. }
  31781. }
  31782. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  31783. const childContext = createChildContext(parentContext, withSlotScopeId);
  31784. processChildren(parent, childContext, asFragment);
  31785. return createBlockStatement(childContext.body);
  31786. }
  31787. const ssrTransformModel = (dir, node, context) => {
  31788. const model = dir.exp;
  31789. function checkDuplicatedValue() {
  31790. const value = findProp(node, "value");
  31791. if (value) {
  31792. context.onError(
  31793. createDOMCompilerError(
  31794. 60,
  31795. value.loc
  31796. )
  31797. );
  31798. }
  31799. }
  31800. const processSelectChildren = (children) => {
  31801. children.forEach((child) => {
  31802. if (child.type === 1) {
  31803. processOption(child);
  31804. } else if (child.type === 11) {
  31805. processSelectChildren(child.children);
  31806. } else if (child.type === 9) {
  31807. child.branches.forEach((b) => processSelectChildren(b.children));
  31808. }
  31809. });
  31810. };
  31811. function processOption(plainNode) {
  31812. if (plainNode.tag === "option") {
  31813. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  31814. const value = findValueBinding(plainNode);
  31815. plainNode.ssrCodegenNode.elements.push(
  31816. createConditionalExpression(
  31817. createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  31818. createConditionalExpression(
  31819. createCallExpression(`Array.isArray`, [model]),
  31820. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31821. model,
  31822. value
  31823. ]),
  31824. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31825. model,
  31826. value
  31827. ])
  31828. )
  31829. ]),
  31830. createSimpleExpression(" selected", true),
  31831. createSimpleExpression("", true),
  31832. false
  31833. )
  31834. );
  31835. }
  31836. } else if (plainNode.tag === "optgroup") {
  31837. processSelectChildren(plainNode.children);
  31838. }
  31839. }
  31840. if (node.tagType === 0) {
  31841. const res = { props: [] };
  31842. const defaultProps = [
  31843. // default value binding for text type inputs
  31844. createObjectProperty(`value`, model)
  31845. ];
  31846. if (node.tag === "input") {
  31847. const type = findProp(node, "type");
  31848. if (type) {
  31849. const value = findValueBinding(node);
  31850. if (type.type === 7) {
  31851. res.ssrTagParts = [
  31852. createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  31853. type.exp,
  31854. model,
  31855. value
  31856. ])
  31857. ];
  31858. } else if (type.value) {
  31859. switch (type.value.content) {
  31860. case "radio":
  31861. res.props = [
  31862. createObjectProperty(
  31863. `checked`,
  31864. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31865. model,
  31866. value
  31867. ])
  31868. )
  31869. ];
  31870. break;
  31871. case "checkbox":
  31872. const trueValueBinding = findProp(node, "true-value");
  31873. if (trueValueBinding) {
  31874. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  31875. res.props = [
  31876. createObjectProperty(
  31877. `checked`,
  31878. createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  31879. model,
  31880. trueValue
  31881. ])
  31882. )
  31883. ];
  31884. } else {
  31885. res.props = [
  31886. createObjectProperty(
  31887. `checked`,
  31888. createConditionalExpression(
  31889. createCallExpression(`Array.isArray`, [model]),
  31890. createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  31891. model,
  31892. value
  31893. ]),
  31894. model
  31895. )
  31896. )
  31897. ];
  31898. }
  31899. break;
  31900. case "file":
  31901. context.onError(
  31902. createDOMCompilerError(
  31903. 59,
  31904. dir.loc
  31905. )
  31906. );
  31907. break;
  31908. default:
  31909. checkDuplicatedValue();
  31910. res.props = defaultProps;
  31911. break;
  31912. }
  31913. }
  31914. } else if (hasDynamicKeyVBind(node)) ; else {
  31915. checkDuplicatedValue();
  31916. res.props = defaultProps;
  31917. }
  31918. } else if (node.tag === "textarea") {
  31919. checkDuplicatedValue();
  31920. node.children = [createInterpolation(model, model.loc)];
  31921. } else if (node.tag === "select") {
  31922. processSelectChildren(node.children);
  31923. } else {
  31924. context.onError(
  31925. createDOMCompilerError(
  31926. 57,
  31927. dir.loc
  31928. )
  31929. );
  31930. }
  31931. return res;
  31932. } else {
  31933. return transformModel$1(dir, node, context);
  31934. }
  31935. };
  31936. function findValueBinding(node) {
  31937. const valueBinding = findProp(node, "value");
  31938. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : createSimpleExpression(valueBinding.value.content, true) : createSimpleExpression(`null`, false);
  31939. }
  31940. const ssrTransformShow = (dir, node, context) => {
  31941. if (!dir.exp) {
  31942. context.onError(
  31943. createDOMCompilerError(61)
  31944. );
  31945. }
  31946. return {
  31947. props: [
  31948. createObjectProperty(
  31949. `style`,
  31950. createConditionalExpression(
  31951. dir.exp,
  31952. createSimpleExpression(`null`, false),
  31953. createObjectExpression([
  31954. createObjectProperty(
  31955. `display`,
  31956. createSimpleExpression(`none`, true)
  31957. )
  31958. ]),
  31959. false
  31960. )
  31961. )
  31962. ]
  31963. };
  31964. };
  31965. const filterChild = (node) => node.children.filter((n) => n.type !== 3);
  31966. const hasSingleChild = (node) => filterChild(node).length === 1;
  31967. const ssrInjectFallthroughAttrs = (node, context) => {
  31968. if (node.type === 0) {
  31969. context.identifiers._attrs = 1;
  31970. }
  31971. if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) {
  31972. const rootChildren = filterChild(context.root);
  31973. if (rootChildren.length === 1 && rootChildren[0] === node) {
  31974. if (hasSingleChild(node)) {
  31975. injectFallthroughAttrs(node.children[0]);
  31976. }
  31977. return;
  31978. }
  31979. }
  31980. const parent = context.parent;
  31981. if (!parent || parent.type !== 0) {
  31982. return;
  31983. }
  31984. if (node.type === 10 && hasSingleChild(node)) {
  31985. let hasEncounteredIf = false;
  31986. for (const c of filterChild(parent)) {
  31987. if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
  31988. if (hasEncounteredIf) return;
  31989. hasEncounteredIf = true;
  31990. } else if (
  31991. // node before v-if
  31992. !hasEncounteredIf || // non else nodes
  31993. !(c.type === 1 && findDir(c, /else/, true))
  31994. ) {
  31995. return;
  31996. }
  31997. }
  31998. injectFallthroughAttrs(node.children[0]);
  31999. } else if (hasSingleChild(parent)) {
  32000. injectFallthroughAttrs(node);
  32001. }
  32002. };
  32003. function injectFallthroughAttrs(node) {
  32004. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32005. node.props.push({
  32006. type: 7,
  32007. name: "bind",
  32008. arg: void 0,
  32009. exp: createSimpleExpression(`_attrs`, false),
  32010. modifiers: [],
  32011. loc: locStub
  32012. });
  32013. }
  32014. }
  32015. const ssrInjectCssVars = (node, context) => {
  32016. if (!context.ssrCssVars) {
  32017. return;
  32018. }
  32019. if (node.type === 0) {
  32020. context.identifiers._cssVars = 1;
  32021. }
  32022. const parent = context.parent;
  32023. if (!parent || parent.type !== 0) {
  32024. return;
  32025. }
  32026. if (node.type === 10) {
  32027. for (const child of node.children) {
  32028. injectCssVars(child);
  32029. }
  32030. } else {
  32031. injectCssVars(node);
  32032. }
  32033. };
  32034. function injectCssVars(node) {
  32035. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !findDir(node, "for")) {
  32036. if (node.tag === "suspense" || node.tag === "Suspense") {
  32037. for (const child of node.children) {
  32038. if (child.type === 1 && child.tagType === 3) {
  32039. child.children.forEach(injectCssVars);
  32040. } else {
  32041. injectCssVars(child);
  32042. }
  32043. }
  32044. } else {
  32045. node.props.push({
  32046. type: 7,
  32047. name: "bind",
  32048. arg: void 0,
  32049. exp: createSimpleExpression(`_cssVars`, false),
  32050. modifiers: [],
  32051. loc: locStub
  32052. });
  32053. }
  32054. }
  32055. }
  32056. var __defProp$7 = Object.defineProperty;
  32057. var __defProps$6 = Object.defineProperties;
  32058. var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
  32059. var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
  32060. var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
  32061. var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
  32062. var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32063. var __spreadValues$7 = (a, b) => {
  32064. for (var prop in b || (b = {}))
  32065. if (__hasOwnProp$7.call(b, prop))
  32066. __defNormalProp$7(a, prop, b[prop]);
  32067. if (__getOwnPropSymbols$7)
  32068. for (var prop of __getOwnPropSymbols$7(b)) {
  32069. if (__propIsEnum$7.call(b, prop))
  32070. __defNormalProp$7(a, prop, b[prop]);
  32071. }
  32072. return a;
  32073. };
  32074. var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
  32075. function compile(source, options = {}) {
  32076. options = __spreadProps$6(__spreadValues$7(__spreadValues$7({}, options), parserOptions), {
  32077. ssr: true,
  32078. inSSR: true,
  32079. scopeId: options.mode === "function" ? null : options.scopeId,
  32080. // always prefix since compiler-ssr doesn't have size concern
  32081. prefixIdentifiers: true,
  32082. // disable optimizations that are unnecessary for ssr
  32083. cacheHandlers: false,
  32084. hoistStatic: false
  32085. });
  32086. const ast = typeof source === "string" ? baseParse(source, options) : source;
  32087. rawOptionsMap.set(ast, options);
  32088. transform(ast, __spreadProps$6(__spreadValues$7({}, options), {
  32089. hoistStatic: false,
  32090. nodeTransforms: [
  32091. ssrTransformIf,
  32092. ssrTransformFor,
  32093. trackVForSlotScopes,
  32094. transformExpression,
  32095. ssrTransformSlotOutlet,
  32096. ssrInjectFallthroughAttrs,
  32097. ssrInjectCssVars,
  32098. ssrTransformElement,
  32099. ssrTransformComponent,
  32100. trackSlotScopes,
  32101. transformStyle,
  32102. ...options.nodeTransforms || []
  32103. // user transforms
  32104. ],
  32105. directiveTransforms: __spreadValues$7({
  32106. // reusing core v-bind
  32107. bind: transformBind,
  32108. on: transformOn$1,
  32109. // model and show have dedicated SSR handling
  32110. model: ssrTransformModel,
  32111. show: ssrTransformShow,
  32112. // the following are ignored during SSR
  32113. // on: noopDirectiveTransform,
  32114. cloak: noopDirectiveTransform,
  32115. once: noopDirectiveTransform,
  32116. memo: noopDirectiveTransform
  32117. }, options.directiveTransforms || {})
  32118. }));
  32119. ssrCodegenTransform(ast, options);
  32120. return generate(ast, options);
  32121. }
  32122. var CompilerSSR = /*#__PURE__*/Object.freeze({
  32123. __proto__: null,
  32124. compile: compile
  32125. });
  32126. var _polyfillNode_fs = {};
  32127. var _polyfillNode_fs$1 = /*#__PURE__*/Object.freeze({
  32128. __proto__: null,
  32129. default: _polyfillNode_fs
  32130. });
  32131. var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
  32132. var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_path);
  32133. var require$$0 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_util$1);
  32134. const hasWarned = {};
  32135. function warnOnce$1(msg) {
  32136. const isNodeProd = typeof process !== "undefined" && process.env.NODE_ENV === "production";
  32137. if (!isNodeProd && true && !hasWarned[msg]) {
  32138. hasWarned[msg] = true;
  32139. warn(msg);
  32140. }
  32141. }
  32142. function warn(msg) {
  32143. console.warn(
  32144. `\x1B[1m\x1B[33m[@vue/compiler-sfc]\x1B[0m\x1B[33m ${msg}\x1B[0m
  32145. `
  32146. );
  32147. }
  32148. var __defProp$6 = Object.defineProperty;
  32149. var __defProps$5 = Object.defineProperties;
  32150. var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
  32151. var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
  32152. var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
  32153. var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
  32154. var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  32155. var __spreadValues$6 = (a, b) => {
  32156. for (var prop in b || (b = {}))
  32157. if (__hasOwnProp$6.call(b, prop))
  32158. __defNormalProp$6(a, prop, b[prop]);
  32159. if (__getOwnPropSymbols$6)
  32160. for (var prop of __getOwnPropSymbols$6(b)) {
  32161. if (__propIsEnum$6.call(b, prop))
  32162. __defNormalProp$6(a, prop, b[prop]);
  32163. }
  32164. return a;
  32165. };
  32166. var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
  32167. function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
  32168. let res = "";
  32169. let err = null;
  32170. preprocessor.render(
  32171. source,
  32172. __spreadValues$6({ filename }, preprocessOptions),
  32173. (_err, _res) => {
  32174. if (_err) err = _err;
  32175. res = _res;
  32176. }
  32177. );
  32178. if (err) throw err;
  32179. return res;
  32180. }
  32181. function compileTemplate(options) {
  32182. const { preprocessLang, preprocessCustomRequire } = options;
  32183. if (preprocessLang && !preprocessCustomRequire) {
  32184. throw new Error(
  32185. `[@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 }.`
  32186. );
  32187. }
  32188. const preprocessor = preprocessLang ? preprocessCustomRequire ? preprocessCustomRequire(preprocessLang) : void 0 : false;
  32189. if (preprocessor) {
  32190. try {
  32191. return doCompileTemplate(__spreadProps$5(__spreadValues$6({}, options), {
  32192. source: preprocess$1(options, preprocessor),
  32193. ast: void 0
  32194. // invalidate AST if template goes through preprocessor
  32195. }));
  32196. } catch (e) {
  32197. return {
  32198. code: `export default function render() {}`,
  32199. source: options.source,
  32200. tips: [],
  32201. errors: [e]
  32202. };
  32203. }
  32204. } else if (preprocessLang) {
  32205. return {
  32206. code: `export default function render() {}`,
  32207. source: options.source,
  32208. tips: [
  32209. `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
  32210. ],
  32211. errors: [
  32212. `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
  32213. ]
  32214. };
  32215. } else {
  32216. return doCompileTemplate(options);
  32217. }
  32218. }
  32219. function doCompileTemplate({
  32220. filename,
  32221. id,
  32222. scoped,
  32223. slotted,
  32224. inMap,
  32225. source,
  32226. ast: inAST,
  32227. ssr = false,
  32228. ssrCssVars,
  32229. isProd = false,
  32230. compiler,
  32231. compilerOptions = {},
  32232. transformAssetUrls
  32233. }) {
  32234. const errors = [];
  32235. const warnings = [];
  32236. let nodeTransforms = [];
  32237. if (isObject$2(transformAssetUrls)) {
  32238. const assetOptions = normalizeOptions(transformAssetUrls);
  32239. nodeTransforms = [
  32240. createAssetUrlTransformWithOptions(assetOptions),
  32241. createSrcsetTransformWithOptions(assetOptions)
  32242. ];
  32243. } else if (transformAssetUrls !== false) {
  32244. nodeTransforms = [transformAssetUrl, transformSrcset];
  32245. }
  32246. if (ssr && !ssrCssVars) {
  32247. warnOnce$1(
  32248. `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.`
  32249. );
  32250. }
  32251. if (!id) {
  32252. warnOnce$1(`compileTemplate now requires the \`id\` option.`);
  32253. id = "";
  32254. }
  32255. const shortId = id.replace(/^data-v-/, "");
  32256. const longId = `data-v-${shortId}`;
  32257. const defaultCompiler = ssr ? CompilerSSR : CompilerDOM;
  32258. compiler = compiler || defaultCompiler;
  32259. if (compiler !== defaultCompiler) {
  32260. inAST = void 0;
  32261. }
  32262. if (inAST == null ? void 0 : inAST.transformed) {
  32263. const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, __spreadProps$5(__spreadValues$6({
  32264. prefixIdentifiers: true
  32265. }, compilerOptions), {
  32266. parseMode: "sfc",
  32267. onError: (e) => errors.push(e)
  32268. }));
  32269. const template = newAST.children.find(
  32270. (node) => node.type === 1 && node.tag === "template"
  32271. );
  32272. inAST = createRoot(template.children, inAST.source);
  32273. }
  32274. let { code, ast, preamble, map } = compiler.compile(inAST || source, __spreadProps$5(__spreadValues$6({
  32275. mode: "module",
  32276. prefixIdentifiers: true,
  32277. hoistStatic: true,
  32278. cacheHandlers: true,
  32279. ssrCssVars: ssr && ssrCssVars && ssrCssVars.length ? genCssVarsFromList(ssrCssVars, shortId, isProd, true) : "",
  32280. scopeId: scoped ? longId : void 0,
  32281. slotted,
  32282. sourceMap: true
  32283. }, compilerOptions), {
  32284. hmr: !isProd,
  32285. nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
  32286. filename,
  32287. onError: (e) => errors.push(e),
  32288. onWarn: (w) => warnings.push(w)
  32289. }));
  32290. if (inMap && !inAST) {
  32291. if (map) {
  32292. map = mapLines(inMap, map);
  32293. }
  32294. if (errors.length) {
  32295. patchErrors(errors, source, inMap);
  32296. }
  32297. }
  32298. const tips = warnings.map((w) => {
  32299. let msg = w.message;
  32300. if (w.loc) {
  32301. msg += `
  32302. ${generateCodeFrame(
  32303. (inAST == null ? void 0 : inAST.source) || source,
  32304. w.loc.start.offset,
  32305. w.loc.end.offset
  32306. )}`;
  32307. }
  32308. return msg;
  32309. });
  32310. return { code, ast, preamble, source, errors, tips, map };
  32311. }
  32312. function mapLines(oldMap, newMap) {
  32313. if (!oldMap) return newMap;
  32314. if (!newMap) return oldMap;
  32315. const oldMapConsumer = new sourceMapExports.SourceMapConsumer(oldMap);
  32316. const newMapConsumer = new sourceMapExports.SourceMapConsumer(newMap);
  32317. const mergedMapGenerator = new sourceMapExports.SourceMapGenerator();
  32318. newMapConsumer.eachMapping((m) => {
  32319. if (m.originalLine == null) {
  32320. return;
  32321. }
  32322. const origPosInOldMap = oldMapConsumer.originalPositionFor({
  32323. line: m.originalLine,
  32324. column: m.originalColumn
  32325. });
  32326. if (origPosInOldMap.source == null) {
  32327. return;
  32328. }
  32329. mergedMapGenerator.addMapping({
  32330. generated: {
  32331. line: m.generatedLine,
  32332. column: m.generatedColumn
  32333. },
  32334. original: {
  32335. line: origPosInOldMap.line,
  32336. // map line
  32337. // use current column, since the oldMap produced by @vue/compiler-sfc
  32338. // does not
  32339. column: m.originalColumn
  32340. },
  32341. source: origPosInOldMap.source,
  32342. name: origPosInOldMap.name
  32343. });
  32344. });
  32345. const generator = mergedMapGenerator;
  32346. oldMapConsumer.sources.forEach((sourceFile) => {
  32347. generator._sources.add(sourceFile);
  32348. const sourceContent = oldMapConsumer.sourceContentFor(sourceFile);
  32349. if (sourceContent != null) {
  32350. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  32351. }
  32352. });
  32353. generator._sourceRoot = oldMap.sourceRoot;
  32354. generator._file = oldMap.file;
  32355. return generator.toJSON();
  32356. }
  32357. function patchErrors(errors, source, inMap) {
  32358. const originalSource = inMap.sourcesContent[0];
  32359. const offset = originalSource.indexOf(source);
  32360. const lineOffset = originalSource.slice(0, offset).split(/\r?\n/).length - 1;
  32361. errors.forEach((err) => {
  32362. if (err.loc) {
  32363. err.loc.start.line += lineOffset;
  32364. err.loc.start.offset += offset;
  32365. if (err.loc.end !== err.loc.start) {
  32366. err.loc.end.line += lineOffset;
  32367. err.loc.end.offset += offset;
  32368. }
  32369. }
  32370. });
  32371. }
  32372. var picocolors = {exports: {}};
  32373. var hasRequiredPicocolors;
  32374. function requirePicocolors () {
  32375. if (hasRequiredPicocolors) return picocolors.exports;
  32376. hasRequiredPicocolors = 1;
  32377. let p = browser$1 || {}, argv = p.argv || [], env = p.env || {};
  32378. let isColorSupported =
  32379. !(!!env.NO_COLOR || argv.includes("--no-color")) &&
  32380. (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI);
  32381. let formatter = (open, close, replace = open) =>
  32382. input => {
  32383. let string = "" + input, index = string.indexOf(close, open.length);
  32384. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
  32385. };
  32386. let replaceClose = (string, close, replace, index) => {
  32387. let result = "", cursor = 0;
  32388. do {
  32389. result += string.substring(cursor, index) + replace;
  32390. cursor = index + close.length;
  32391. index = string.indexOf(close, cursor);
  32392. } while (~index)
  32393. return result + string.substring(cursor)
  32394. };
  32395. let createColors = (enabled = isColorSupported) => {
  32396. let f = enabled ? formatter : () => String;
  32397. return {
  32398. isColorSupported: enabled,
  32399. reset: f("\x1b[0m", "\x1b[0m"),
  32400. bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
  32401. dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
  32402. italic: f("\x1b[3m", "\x1b[23m"),
  32403. underline: f("\x1b[4m", "\x1b[24m"),
  32404. inverse: f("\x1b[7m", "\x1b[27m"),
  32405. hidden: f("\x1b[8m", "\x1b[28m"),
  32406. strikethrough: f("\x1b[9m", "\x1b[29m"),
  32407. black: f("\x1b[30m", "\x1b[39m"),
  32408. red: f("\x1b[31m", "\x1b[39m"),
  32409. green: f("\x1b[32m", "\x1b[39m"),
  32410. yellow: f("\x1b[33m", "\x1b[39m"),
  32411. blue: f("\x1b[34m", "\x1b[39m"),
  32412. magenta: f("\x1b[35m", "\x1b[39m"),
  32413. cyan: f("\x1b[36m", "\x1b[39m"),
  32414. white: f("\x1b[37m", "\x1b[39m"),
  32415. gray: f("\x1b[90m", "\x1b[39m"),
  32416. bgBlack: f("\x1b[40m", "\x1b[49m"),
  32417. bgRed: f("\x1b[41m", "\x1b[49m"),
  32418. bgGreen: f("\x1b[42m", "\x1b[49m"),
  32419. bgYellow: f("\x1b[43m", "\x1b[49m"),
  32420. bgBlue: f("\x1b[44m", "\x1b[49m"),
  32421. bgMagenta: f("\x1b[45m", "\x1b[49m"),
  32422. bgCyan: f("\x1b[46m", "\x1b[49m"),
  32423. bgWhite: f("\x1b[47m", "\x1b[49m"),
  32424. blackBright: f("\x1b[90m", "\x1b[39m"),
  32425. redBright: f("\x1b[91m", "\x1b[39m"),
  32426. greenBright: f("\x1b[92m", "\x1b[39m"),
  32427. yellowBright: f("\x1b[93m", "\x1b[39m"),
  32428. blueBright: f("\x1b[94m", "\x1b[39m"),
  32429. magentaBright: f("\x1b[95m", "\x1b[39m"),
  32430. cyanBright: f("\x1b[96m", "\x1b[39m"),
  32431. whiteBright: f("\x1b[97m", "\x1b[39m"),
  32432. bgBlackBright: f("\x1b[100m", "\x1b[49m"),
  32433. bgRedBright: f("\x1b[101m", "\x1b[49m"),
  32434. bgGreenBright: f("\x1b[102m", "\x1b[49m"),
  32435. bgYellowBright: f("\x1b[103m", "\x1b[49m"),
  32436. bgBlueBright: f("\x1b[104m", "\x1b[49m"),
  32437. bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
  32438. bgCyanBright: f("\x1b[106m", "\x1b[49m"),
  32439. bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
  32440. }
  32441. };
  32442. picocolors.exports = createColors();
  32443. picocolors.exports.createColors = createColors;
  32444. return picocolors.exports;
  32445. }
  32446. var tokenize$1;
  32447. var hasRequiredTokenize$1;
  32448. function requireTokenize$1 () {
  32449. if (hasRequiredTokenize$1) return tokenize$1;
  32450. hasRequiredTokenize$1 = 1;
  32451. const SINGLE_QUOTE = "'".charCodeAt(0);
  32452. const DOUBLE_QUOTE = '"'.charCodeAt(0);
  32453. const BACKSLASH = '\\'.charCodeAt(0);
  32454. const SLASH = '/'.charCodeAt(0);
  32455. const NEWLINE = '\n'.charCodeAt(0);
  32456. const SPACE = ' '.charCodeAt(0);
  32457. const FEED = '\f'.charCodeAt(0);
  32458. const TAB = '\t'.charCodeAt(0);
  32459. const CR = '\r'.charCodeAt(0);
  32460. const OPEN_SQUARE = '['.charCodeAt(0);
  32461. const CLOSE_SQUARE = ']'.charCodeAt(0);
  32462. const OPEN_PARENTHESES = '('.charCodeAt(0);
  32463. const CLOSE_PARENTHESES = ')'.charCodeAt(0);
  32464. const OPEN_CURLY = '{'.charCodeAt(0);
  32465. const CLOSE_CURLY = '}'.charCodeAt(0);
  32466. const SEMICOLON = ';'.charCodeAt(0);
  32467. const ASTERISK = '*'.charCodeAt(0);
  32468. const COLON = ':'.charCodeAt(0);
  32469. const AT = '@'.charCodeAt(0);
  32470. const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g;
  32471. const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g;
  32472. const RE_BAD_BRACKET = /.[\r\n"'(/\\]/;
  32473. const RE_HEX_ESCAPE = /[\da-f]/i;
  32474. tokenize$1 = function tokenizer(input, options = {}) {
  32475. let css = input.css.valueOf();
  32476. let ignore = options.ignoreErrors;
  32477. let code, content, escape, next, quote;
  32478. let currentToken, escaped, escapePos, n, prev;
  32479. let length = css.length;
  32480. let pos = 0;
  32481. let buffer = [];
  32482. let returned = [];
  32483. function position() {
  32484. return pos
  32485. }
  32486. function unclosed(what) {
  32487. throw input.error('Unclosed ' + what, pos)
  32488. }
  32489. function endOfFile() {
  32490. return returned.length === 0 && pos >= length
  32491. }
  32492. function nextToken(opts) {
  32493. if (returned.length) return returned.pop()
  32494. if (pos >= length) return
  32495. let ignoreUnclosed = opts ? opts.ignoreUnclosed : false;
  32496. code = css.charCodeAt(pos);
  32497. switch (code) {
  32498. case NEWLINE:
  32499. case SPACE:
  32500. case TAB:
  32501. case CR:
  32502. case FEED: {
  32503. next = pos;
  32504. do {
  32505. next += 1;
  32506. code = css.charCodeAt(next);
  32507. } while (
  32508. code === SPACE ||
  32509. code === NEWLINE ||
  32510. code === TAB ||
  32511. code === CR ||
  32512. code === FEED
  32513. )
  32514. currentToken = ['space', css.slice(pos, next)];
  32515. pos = next - 1;
  32516. break
  32517. }
  32518. case OPEN_SQUARE:
  32519. case CLOSE_SQUARE:
  32520. case OPEN_CURLY:
  32521. case CLOSE_CURLY:
  32522. case COLON:
  32523. case SEMICOLON:
  32524. case CLOSE_PARENTHESES: {
  32525. let controlChar = String.fromCharCode(code);
  32526. currentToken = [controlChar, controlChar, pos];
  32527. break
  32528. }
  32529. case OPEN_PARENTHESES: {
  32530. prev = buffer.length ? buffer.pop()[1] : '';
  32531. n = css.charCodeAt(pos + 1);
  32532. if (
  32533. prev === 'url' &&
  32534. n !== SINGLE_QUOTE &&
  32535. n !== DOUBLE_QUOTE &&
  32536. n !== SPACE &&
  32537. n !== NEWLINE &&
  32538. n !== TAB &&
  32539. n !== FEED &&
  32540. n !== CR
  32541. ) {
  32542. next = pos;
  32543. do {
  32544. escaped = false;
  32545. next = css.indexOf(')', next + 1);
  32546. if (next === -1) {
  32547. if (ignore || ignoreUnclosed) {
  32548. next = pos;
  32549. break
  32550. } else {
  32551. unclosed('bracket');
  32552. }
  32553. }
  32554. escapePos = next;
  32555. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32556. escapePos -= 1;
  32557. escaped = !escaped;
  32558. }
  32559. } while (escaped)
  32560. currentToken = ['brackets', css.slice(pos, next + 1), pos, next];
  32561. pos = next;
  32562. } else {
  32563. next = css.indexOf(')', pos + 1);
  32564. content = css.slice(pos, next + 1);
  32565. if (next === -1 || RE_BAD_BRACKET.test(content)) {
  32566. currentToken = ['(', '(', pos];
  32567. } else {
  32568. currentToken = ['brackets', content, pos, next];
  32569. pos = next;
  32570. }
  32571. }
  32572. break
  32573. }
  32574. case SINGLE_QUOTE:
  32575. case DOUBLE_QUOTE: {
  32576. quote = code === SINGLE_QUOTE ? "'" : '"';
  32577. next = pos;
  32578. do {
  32579. escaped = false;
  32580. next = css.indexOf(quote, next + 1);
  32581. if (next === -1) {
  32582. if (ignore || ignoreUnclosed) {
  32583. next = pos + 1;
  32584. break
  32585. } else {
  32586. unclosed('string');
  32587. }
  32588. }
  32589. escapePos = next;
  32590. while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
  32591. escapePos -= 1;
  32592. escaped = !escaped;
  32593. }
  32594. } while (escaped)
  32595. currentToken = ['string', css.slice(pos, next + 1), pos, next];
  32596. pos = next;
  32597. break
  32598. }
  32599. case AT: {
  32600. RE_AT_END.lastIndex = pos + 1;
  32601. RE_AT_END.test(css);
  32602. if (RE_AT_END.lastIndex === 0) {
  32603. next = css.length - 1;
  32604. } else {
  32605. next = RE_AT_END.lastIndex - 2;
  32606. }
  32607. currentToken = ['at-word', css.slice(pos, next + 1), pos, next];
  32608. pos = next;
  32609. break
  32610. }
  32611. case BACKSLASH: {
  32612. next = pos;
  32613. escape = true;
  32614. while (css.charCodeAt(next + 1) === BACKSLASH) {
  32615. next += 1;
  32616. escape = !escape;
  32617. }
  32618. code = css.charCodeAt(next + 1);
  32619. if (
  32620. escape &&
  32621. code !== SLASH &&
  32622. code !== SPACE &&
  32623. code !== NEWLINE &&
  32624. code !== TAB &&
  32625. code !== CR &&
  32626. code !== FEED
  32627. ) {
  32628. next += 1;
  32629. if (RE_HEX_ESCAPE.test(css.charAt(next))) {
  32630. while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
  32631. next += 1;
  32632. }
  32633. if (css.charCodeAt(next + 1) === SPACE) {
  32634. next += 1;
  32635. }
  32636. }
  32637. }
  32638. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32639. pos = next;
  32640. break
  32641. }
  32642. default: {
  32643. if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
  32644. next = css.indexOf('*/', pos + 2) + 1;
  32645. if (next === 0) {
  32646. if (ignore || ignoreUnclosed) {
  32647. next = css.length;
  32648. } else {
  32649. unclosed('comment');
  32650. }
  32651. }
  32652. currentToken = ['comment', css.slice(pos, next + 1), pos, next];
  32653. pos = next;
  32654. } else {
  32655. RE_WORD_END.lastIndex = pos + 1;
  32656. RE_WORD_END.test(css);
  32657. if (RE_WORD_END.lastIndex === 0) {
  32658. next = css.length - 1;
  32659. } else {
  32660. next = RE_WORD_END.lastIndex - 2;
  32661. }
  32662. currentToken = ['word', css.slice(pos, next + 1), pos, next];
  32663. buffer.push(currentToken);
  32664. pos = next;
  32665. }
  32666. break
  32667. }
  32668. }
  32669. pos++;
  32670. return currentToken
  32671. }
  32672. function back(token) {
  32673. returned.push(token);
  32674. }
  32675. return {
  32676. back,
  32677. endOfFile,
  32678. nextToken,
  32679. position
  32680. }
  32681. };
  32682. return tokenize$1;
  32683. }
  32684. var terminalHighlight_1;
  32685. var hasRequiredTerminalHighlight;
  32686. function requireTerminalHighlight () {
  32687. if (hasRequiredTerminalHighlight) return terminalHighlight_1;
  32688. hasRequiredTerminalHighlight = 1;
  32689. let pico = /*@__PURE__*/ requirePicocolors();
  32690. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  32691. let Input;
  32692. function registerInput(dependant) {
  32693. Input = dependant;
  32694. }
  32695. const HIGHLIGHT_THEME = {
  32696. ';': pico.yellow,
  32697. ':': pico.yellow,
  32698. '(': pico.cyan,
  32699. ')': pico.cyan,
  32700. '[': pico.yellow,
  32701. ']': pico.yellow,
  32702. '{': pico.yellow,
  32703. '}': pico.yellow,
  32704. 'at-word': pico.cyan,
  32705. 'brackets': pico.cyan,
  32706. 'call': pico.cyan,
  32707. 'class': pico.yellow,
  32708. 'comment': pico.gray,
  32709. 'hash': pico.magenta,
  32710. 'string': pico.green
  32711. };
  32712. function getTokenType([type, value], processor) {
  32713. if (type === 'word') {
  32714. if (value[0] === '.') {
  32715. return 'class'
  32716. }
  32717. if (value[0] === '#') {
  32718. return 'hash'
  32719. }
  32720. }
  32721. if (!processor.endOfFile()) {
  32722. let next = processor.nextToken();
  32723. processor.back(next);
  32724. if (next[0] === 'brackets' || next[0] === '(') return 'call'
  32725. }
  32726. return type
  32727. }
  32728. function terminalHighlight(css) {
  32729. let processor = tokenizer(new Input(css), { ignoreErrors: true });
  32730. let result = '';
  32731. while (!processor.endOfFile()) {
  32732. let token = processor.nextToken();
  32733. let color = HIGHLIGHT_THEME[getTokenType(token, processor)];
  32734. if (color) {
  32735. result += token[1]
  32736. .split(/\r?\n/)
  32737. .map(i => color(i))
  32738. .join('\n');
  32739. } else {
  32740. result += token[1];
  32741. }
  32742. }
  32743. return result
  32744. }
  32745. terminalHighlight.registerInput = registerInput;
  32746. terminalHighlight_1 = terminalHighlight;
  32747. return terminalHighlight_1;
  32748. }
  32749. var cssSyntaxError;
  32750. var hasRequiredCssSyntaxError;
  32751. function requireCssSyntaxError () {
  32752. if (hasRequiredCssSyntaxError) return cssSyntaxError;
  32753. hasRequiredCssSyntaxError = 1;
  32754. let pico = /*@__PURE__*/ requirePicocolors();
  32755. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  32756. class CssSyntaxError extends Error {
  32757. constructor(message, line, column, source, file, plugin) {
  32758. super(message);
  32759. this.name = 'CssSyntaxError';
  32760. this.reason = message;
  32761. if (file) {
  32762. this.file = file;
  32763. }
  32764. if (source) {
  32765. this.source = source;
  32766. }
  32767. if (plugin) {
  32768. this.plugin = plugin;
  32769. }
  32770. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  32771. if (typeof line === 'number') {
  32772. this.line = line;
  32773. this.column = column;
  32774. } else {
  32775. this.line = line.line;
  32776. this.column = line.column;
  32777. this.endLine = column.line;
  32778. this.endColumn = column.column;
  32779. }
  32780. }
  32781. this.setMessage();
  32782. if (Error.captureStackTrace) {
  32783. Error.captureStackTrace(this, CssSyntaxError);
  32784. }
  32785. }
  32786. setMessage() {
  32787. this.message = this.plugin ? this.plugin + ': ' : '';
  32788. this.message += this.file ? this.file : '<css input>';
  32789. if (typeof this.line !== 'undefined') {
  32790. this.message += ':' + this.line + ':' + this.column;
  32791. }
  32792. this.message += ': ' + this.reason;
  32793. }
  32794. showSourceCode(color) {
  32795. if (!this.source) return ''
  32796. let css = this.source;
  32797. if (color == null) color = pico.isColorSupported;
  32798. let aside = text => text;
  32799. let mark = text => text;
  32800. let highlight = text => text;
  32801. if (color) {
  32802. let { bold, gray, red } = pico.createColors(true);
  32803. mark = text => bold(red(text));
  32804. aside = text => gray(text);
  32805. if (terminalHighlight) {
  32806. highlight = text => terminalHighlight(text);
  32807. }
  32808. }
  32809. let lines = css.split(/\r?\n/);
  32810. let start = Math.max(this.line - 3, 0);
  32811. let end = Math.min(this.line + 2, lines.length);
  32812. let maxWidth = String(end).length;
  32813. return lines
  32814. .slice(start, end)
  32815. .map((line, index) => {
  32816. let number = start + 1 + index;
  32817. let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  32818. if (number === this.line) {
  32819. if (line.length > 160) {
  32820. let padding = 20;
  32821. let subLineStart = Math.max(0, this.column - padding);
  32822. let subLineEnd = Math.max(
  32823. this.column + padding,
  32824. this.endColumn + padding
  32825. );
  32826. let subLine = line.slice(subLineStart, subLineEnd);
  32827. let spacing =
  32828. aside(gutter.replace(/\d/g, ' ')) +
  32829. line
  32830. .slice(0, Math.min(this.column - 1, padding - 1))
  32831. .replace(/[^\t]/g, ' ');
  32832. return (
  32833. mark('>') +
  32834. aside(gutter) +
  32835. highlight(subLine) +
  32836. '\n ' +
  32837. spacing +
  32838. mark('^')
  32839. )
  32840. }
  32841. let spacing =
  32842. aside(gutter.replace(/\d/g, ' ')) +
  32843. line.slice(0, this.column - 1).replace(/[^\t]/g, ' ');
  32844. return (
  32845. mark('>') +
  32846. aside(gutter) +
  32847. highlight(line) +
  32848. '\n ' +
  32849. spacing +
  32850. mark('^')
  32851. )
  32852. }
  32853. return ' ' + aside(gutter) + highlight(line)
  32854. })
  32855. .join('\n')
  32856. }
  32857. toString() {
  32858. let code = this.showSourceCode();
  32859. if (code) {
  32860. code = '\n\n' + code + '\n';
  32861. }
  32862. return this.name + ': ' + this.message + code
  32863. }
  32864. }
  32865. cssSyntaxError = CssSyntaxError;
  32866. CssSyntaxError.default = CssSyntaxError;
  32867. return cssSyntaxError;
  32868. }
  32869. var stringifier;
  32870. var hasRequiredStringifier;
  32871. function requireStringifier () {
  32872. if (hasRequiredStringifier) return stringifier;
  32873. hasRequiredStringifier = 1;
  32874. const DEFAULT_RAW = {
  32875. after: '\n',
  32876. beforeClose: '\n',
  32877. beforeComment: '\n',
  32878. beforeDecl: '\n',
  32879. beforeOpen: ' ',
  32880. beforeRule: '\n',
  32881. colon: ': ',
  32882. commentLeft: ' ',
  32883. commentRight: ' ',
  32884. emptyBody: '',
  32885. indent: ' ',
  32886. semicolon: false
  32887. };
  32888. function capitalize(str) {
  32889. return str[0].toUpperCase() + str.slice(1)
  32890. }
  32891. class Stringifier {
  32892. constructor(builder) {
  32893. this.builder = builder;
  32894. }
  32895. atrule(node, semicolon) {
  32896. let name = '@' + node.name;
  32897. let params = node.params ? this.rawValue(node, 'params') : '';
  32898. if (typeof node.raws.afterName !== 'undefined') {
  32899. name += node.raws.afterName;
  32900. } else if (params) {
  32901. name += ' ';
  32902. }
  32903. if (node.nodes) {
  32904. this.block(node, name + params);
  32905. } else {
  32906. let end = (node.raws.between || '') + (semicolon ? ';' : '');
  32907. this.builder(name + params + end, node);
  32908. }
  32909. }
  32910. beforeAfter(node, detect) {
  32911. let value;
  32912. if (node.type === 'decl') {
  32913. value = this.raw(node, null, 'beforeDecl');
  32914. } else if (node.type === 'comment') {
  32915. value = this.raw(node, null, 'beforeComment');
  32916. } else if (detect === 'before') {
  32917. value = this.raw(node, null, 'beforeRule');
  32918. } else {
  32919. value = this.raw(node, null, 'beforeClose');
  32920. }
  32921. let buf = node.parent;
  32922. let depth = 0;
  32923. while (buf && buf.type !== 'root') {
  32924. depth += 1;
  32925. buf = buf.parent;
  32926. }
  32927. if (value.includes('\n')) {
  32928. let indent = this.raw(node, null, 'indent');
  32929. if (indent.length) {
  32930. for (let step = 0; step < depth; step++) value += indent;
  32931. }
  32932. }
  32933. return value
  32934. }
  32935. block(node, start) {
  32936. let between = this.raw(node, 'between', 'beforeOpen');
  32937. this.builder(start + between + '{', node, 'start');
  32938. let after;
  32939. if (node.nodes && node.nodes.length) {
  32940. this.body(node);
  32941. after = this.raw(node, 'after');
  32942. } else {
  32943. after = this.raw(node, 'after', 'emptyBody');
  32944. }
  32945. if (after) this.builder(after);
  32946. this.builder('}', node, 'end');
  32947. }
  32948. body(node) {
  32949. let last = node.nodes.length - 1;
  32950. while (last > 0) {
  32951. if (node.nodes[last].type !== 'comment') break
  32952. last -= 1;
  32953. }
  32954. let semicolon = this.raw(node, 'semicolon');
  32955. for (let i = 0; i < node.nodes.length; i++) {
  32956. let child = node.nodes[i];
  32957. let before = this.raw(child, 'before');
  32958. if (before) this.builder(before);
  32959. this.stringify(child, last !== i || semicolon);
  32960. }
  32961. }
  32962. comment(node) {
  32963. let left = this.raw(node, 'left', 'commentLeft');
  32964. let right = this.raw(node, 'right', 'commentRight');
  32965. this.builder('/*' + left + node.text + right + '*/', node);
  32966. }
  32967. decl(node, semicolon) {
  32968. let between = this.raw(node, 'between', 'colon');
  32969. let string = node.prop + between + this.rawValue(node, 'value');
  32970. if (node.important) {
  32971. string += node.raws.important || ' !important';
  32972. }
  32973. if (semicolon) string += ';';
  32974. this.builder(string, node);
  32975. }
  32976. document(node) {
  32977. this.body(node);
  32978. }
  32979. raw(node, own, detect) {
  32980. let value;
  32981. if (!detect) detect = own;
  32982. // Already had
  32983. if (own) {
  32984. value = node.raws[own];
  32985. if (typeof value !== 'undefined') return value
  32986. }
  32987. let parent = node.parent;
  32988. if (detect === 'before') {
  32989. // Hack for first rule in CSS
  32990. if (!parent || (parent.type === 'root' && parent.first === node)) {
  32991. return ''
  32992. }
  32993. // `root` nodes in `document` should use only their own raws
  32994. if (parent && parent.type === 'document') {
  32995. return ''
  32996. }
  32997. }
  32998. // Floating child without parent
  32999. if (!parent) return DEFAULT_RAW[detect]
  33000. // Detect style by other nodes
  33001. let root = node.root();
  33002. if (!root.rawCache) root.rawCache = {};
  33003. if (typeof root.rawCache[detect] !== 'undefined') {
  33004. return root.rawCache[detect]
  33005. }
  33006. if (detect === 'before' || detect === 'after') {
  33007. return this.beforeAfter(node, detect)
  33008. } else {
  33009. let method = 'raw' + capitalize(detect);
  33010. if (this[method]) {
  33011. value = this[method](root, node);
  33012. } else {
  33013. root.walk(i => {
  33014. value = i.raws[own];
  33015. if (typeof value !== 'undefined') return false
  33016. });
  33017. }
  33018. }
  33019. if (typeof value === 'undefined') value = DEFAULT_RAW[detect];
  33020. root.rawCache[detect] = value;
  33021. return value
  33022. }
  33023. rawBeforeClose(root) {
  33024. let value;
  33025. root.walk(i => {
  33026. if (i.nodes && i.nodes.length > 0) {
  33027. if (typeof i.raws.after !== 'undefined') {
  33028. value = i.raws.after;
  33029. if (value.includes('\n')) {
  33030. value = value.replace(/[^\n]+$/, '');
  33031. }
  33032. return false
  33033. }
  33034. }
  33035. });
  33036. if (value) value = value.replace(/\S/g, '');
  33037. return value
  33038. }
  33039. rawBeforeComment(root, node) {
  33040. let value;
  33041. root.walkComments(i => {
  33042. if (typeof i.raws.before !== 'undefined') {
  33043. value = i.raws.before;
  33044. if (value.includes('\n')) {
  33045. value = value.replace(/[^\n]+$/, '');
  33046. }
  33047. return false
  33048. }
  33049. });
  33050. if (typeof value === 'undefined') {
  33051. value = this.raw(node, null, 'beforeDecl');
  33052. } else if (value) {
  33053. value = value.replace(/\S/g, '');
  33054. }
  33055. return value
  33056. }
  33057. rawBeforeDecl(root, node) {
  33058. let value;
  33059. root.walkDecls(i => {
  33060. if (typeof i.raws.before !== 'undefined') {
  33061. value = i.raws.before;
  33062. if (value.includes('\n')) {
  33063. value = value.replace(/[^\n]+$/, '');
  33064. }
  33065. return false
  33066. }
  33067. });
  33068. if (typeof value === 'undefined') {
  33069. value = this.raw(node, null, 'beforeRule');
  33070. } else if (value) {
  33071. value = value.replace(/\S/g, '');
  33072. }
  33073. return value
  33074. }
  33075. rawBeforeOpen(root) {
  33076. let value;
  33077. root.walk(i => {
  33078. if (i.type !== 'decl') {
  33079. value = i.raws.between;
  33080. if (typeof value !== 'undefined') return false
  33081. }
  33082. });
  33083. return value
  33084. }
  33085. rawBeforeRule(root) {
  33086. let value;
  33087. root.walk(i => {
  33088. if (i.nodes && (i.parent !== root || root.first !== i)) {
  33089. if (typeof i.raws.before !== 'undefined') {
  33090. value = i.raws.before;
  33091. if (value.includes('\n')) {
  33092. value = value.replace(/[^\n]+$/, '');
  33093. }
  33094. return false
  33095. }
  33096. }
  33097. });
  33098. if (value) value = value.replace(/\S/g, '');
  33099. return value
  33100. }
  33101. rawColon(root) {
  33102. let value;
  33103. root.walkDecls(i => {
  33104. if (typeof i.raws.between !== 'undefined') {
  33105. value = i.raws.between.replace(/[^\s:]/g, '');
  33106. return false
  33107. }
  33108. });
  33109. return value
  33110. }
  33111. rawEmptyBody(root) {
  33112. let value;
  33113. root.walk(i => {
  33114. if (i.nodes && i.nodes.length === 0) {
  33115. value = i.raws.after;
  33116. if (typeof value !== 'undefined') return false
  33117. }
  33118. });
  33119. return value
  33120. }
  33121. rawIndent(root) {
  33122. if (root.raws.indent) return root.raws.indent
  33123. let value;
  33124. root.walk(i => {
  33125. let p = i.parent;
  33126. if (p && p !== root && p.parent && p.parent === root) {
  33127. if (typeof i.raws.before !== 'undefined') {
  33128. let parts = i.raws.before.split('\n');
  33129. value = parts[parts.length - 1];
  33130. value = value.replace(/\S/g, '');
  33131. return false
  33132. }
  33133. }
  33134. });
  33135. return value
  33136. }
  33137. rawSemicolon(root) {
  33138. let value;
  33139. root.walk(i => {
  33140. if (i.nodes && i.nodes.length && i.last.type === 'decl') {
  33141. value = i.raws.semicolon;
  33142. if (typeof value !== 'undefined') return false
  33143. }
  33144. });
  33145. return value
  33146. }
  33147. rawValue(node, prop) {
  33148. let value = node[prop];
  33149. let raw = node.raws[prop];
  33150. if (raw && raw.value === value) {
  33151. return raw.raw
  33152. }
  33153. return value
  33154. }
  33155. root(node) {
  33156. this.body(node);
  33157. if (node.raws.after) this.builder(node.raws.after);
  33158. }
  33159. rule(node) {
  33160. this.block(node, this.rawValue(node, 'selector'));
  33161. if (node.raws.ownSemicolon) {
  33162. this.builder(node.raws.ownSemicolon, node, 'end');
  33163. }
  33164. }
  33165. stringify(node, semicolon) {
  33166. /* c8 ignore start */
  33167. if (!this[node.type]) {
  33168. throw new Error(
  33169. 'Unknown AST node type ' +
  33170. node.type +
  33171. '. ' +
  33172. 'Maybe you need to change PostCSS stringifier.'
  33173. )
  33174. }
  33175. /* c8 ignore stop */
  33176. this[node.type](node, semicolon);
  33177. }
  33178. }
  33179. stringifier = Stringifier;
  33180. Stringifier.default = Stringifier;
  33181. return stringifier;
  33182. }
  33183. var stringify_1;
  33184. var hasRequiredStringify;
  33185. function requireStringify () {
  33186. if (hasRequiredStringify) return stringify_1;
  33187. hasRequiredStringify = 1;
  33188. let Stringifier = /*@__PURE__*/ requireStringifier();
  33189. function stringify(node, builder) {
  33190. let str = new Stringifier(builder);
  33191. str.stringify(node);
  33192. }
  33193. stringify_1 = stringify;
  33194. stringify.default = stringify;
  33195. return stringify_1;
  33196. }
  33197. var symbols = {};
  33198. var hasRequiredSymbols;
  33199. function requireSymbols () {
  33200. if (hasRequiredSymbols) return symbols;
  33201. hasRequiredSymbols = 1;
  33202. symbols.isClean = Symbol('isClean');
  33203. symbols.my = Symbol('my');
  33204. return symbols;
  33205. }
  33206. var node$2;
  33207. var hasRequiredNode$2;
  33208. function requireNode$2 () {
  33209. if (hasRequiredNode$2) return node$2;
  33210. hasRequiredNode$2 = 1;
  33211. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  33212. let Stringifier = /*@__PURE__*/ requireStringifier();
  33213. let stringify = /*@__PURE__*/ requireStringify();
  33214. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33215. function cloneNode(obj, parent) {
  33216. let cloned = new obj.constructor();
  33217. for (let i in obj) {
  33218. if (!Object.prototype.hasOwnProperty.call(obj, i)) {
  33219. /* c8 ignore next 2 */
  33220. continue
  33221. }
  33222. if (i === 'proxyCache') continue
  33223. let value = obj[i];
  33224. let type = typeof value;
  33225. if (i === 'parent' && type === 'object') {
  33226. if (parent) cloned[i] = parent;
  33227. } else if (i === 'source') {
  33228. cloned[i] = value;
  33229. } else if (Array.isArray(value)) {
  33230. cloned[i] = value.map(j => cloneNode(j, cloned));
  33231. } else {
  33232. if (type === 'object' && value !== null) value = cloneNode(value);
  33233. cloned[i] = value;
  33234. }
  33235. }
  33236. return cloned
  33237. }
  33238. function sourceOffset(inputCSS, position) {
  33239. // Not all custom syntaxes support `offset` in `source.start` and `source.end`
  33240. if (position && typeof position.offset !== 'undefined') {
  33241. return position.offset
  33242. }
  33243. let column = 1;
  33244. let line = 1;
  33245. let offset = 0;
  33246. for (let i = 0; i < inputCSS.length; i++) {
  33247. if (line === position.line && column === position.column) {
  33248. offset = i;
  33249. break
  33250. }
  33251. if (inputCSS[i] === '\n') {
  33252. column = 1;
  33253. line += 1;
  33254. } else {
  33255. column += 1;
  33256. }
  33257. }
  33258. return offset
  33259. }
  33260. class Node {
  33261. get proxyOf() {
  33262. return this
  33263. }
  33264. constructor(defaults = {}) {
  33265. this.raws = {};
  33266. this[isClean] = false;
  33267. this[my] = true;
  33268. for (let name in defaults) {
  33269. if (name === 'nodes') {
  33270. this.nodes = [];
  33271. for (let node of defaults[name]) {
  33272. if (typeof node.clone === 'function') {
  33273. this.append(node.clone());
  33274. } else {
  33275. this.append(node);
  33276. }
  33277. }
  33278. } else {
  33279. this[name] = defaults[name];
  33280. }
  33281. }
  33282. }
  33283. addToError(error) {
  33284. error.postcssNode = this;
  33285. if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
  33286. let s = this.source;
  33287. error.stack = error.stack.replace(
  33288. /\n\s{4}at /,
  33289. `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
  33290. );
  33291. }
  33292. return error
  33293. }
  33294. after(add) {
  33295. this.parent.insertAfter(this, add);
  33296. return this
  33297. }
  33298. assign(overrides = {}) {
  33299. for (let name in overrides) {
  33300. this[name] = overrides[name];
  33301. }
  33302. return this
  33303. }
  33304. before(add) {
  33305. this.parent.insertBefore(this, add);
  33306. return this
  33307. }
  33308. cleanRaws(keepBetween) {
  33309. delete this.raws.before;
  33310. delete this.raws.after;
  33311. if (!keepBetween) delete this.raws.between;
  33312. }
  33313. clone(overrides = {}) {
  33314. let cloned = cloneNode(this);
  33315. for (let name in overrides) {
  33316. cloned[name] = overrides[name];
  33317. }
  33318. return cloned
  33319. }
  33320. cloneAfter(overrides = {}) {
  33321. let cloned = this.clone(overrides);
  33322. this.parent.insertAfter(this, cloned);
  33323. return cloned
  33324. }
  33325. cloneBefore(overrides = {}) {
  33326. let cloned = this.clone(overrides);
  33327. this.parent.insertBefore(this, cloned);
  33328. return cloned
  33329. }
  33330. error(message, opts = {}) {
  33331. if (this.source) {
  33332. let { end, start } = this.rangeBy(opts);
  33333. return this.source.input.error(
  33334. message,
  33335. { column: start.column, line: start.line },
  33336. { column: end.column, line: end.line },
  33337. opts
  33338. )
  33339. }
  33340. return new CssSyntaxError(message)
  33341. }
  33342. getProxyProcessor() {
  33343. return {
  33344. get(node, prop) {
  33345. if (prop === 'proxyOf') {
  33346. return node
  33347. } else if (prop === 'root') {
  33348. return () => node.root().toProxy()
  33349. } else {
  33350. return node[prop]
  33351. }
  33352. },
  33353. set(node, prop, value) {
  33354. if (node[prop] === value) return true
  33355. node[prop] = value;
  33356. if (
  33357. prop === 'prop' ||
  33358. prop === 'value' ||
  33359. prop === 'name' ||
  33360. prop === 'params' ||
  33361. prop === 'important' ||
  33362. /* c8 ignore next */
  33363. prop === 'text'
  33364. ) {
  33365. node.markDirty();
  33366. }
  33367. return true
  33368. }
  33369. }
  33370. }
  33371. /* c8 ignore next 3 */
  33372. markClean() {
  33373. this[isClean] = true;
  33374. }
  33375. markDirty() {
  33376. if (this[isClean]) {
  33377. this[isClean] = false;
  33378. let next = this;
  33379. while ((next = next.parent)) {
  33380. next[isClean] = false;
  33381. }
  33382. }
  33383. }
  33384. next() {
  33385. if (!this.parent) return undefined
  33386. let index = this.parent.index(this);
  33387. return this.parent.nodes[index + 1]
  33388. }
  33389. positionBy(opts = {}) {
  33390. let pos = this.source.start;
  33391. if (opts.index) {
  33392. pos = this.positionInside(opts.index);
  33393. } else if (opts.word) {
  33394. let inputString =
  33395. 'document' in this.source.input
  33396. ? this.source.input.document
  33397. : this.source.input.css;
  33398. let stringRepresentation = inputString.slice(
  33399. sourceOffset(inputString, this.source.start),
  33400. sourceOffset(inputString, this.source.end)
  33401. );
  33402. let index = stringRepresentation.indexOf(opts.word);
  33403. if (index !== -1) pos = this.positionInside(index);
  33404. }
  33405. return pos
  33406. }
  33407. positionInside(index) {
  33408. let column = this.source.start.column;
  33409. let line = this.source.start.line;
  33410. let inputString =
  33411. 'document' in this.source.input
  33412. ? this.source.input.document
  33413. : this.source.input.css;
  33414. let offset = sourceOffset(inputString, this.source.start);
  33415. let end = offset + index;
  33416. for (let i = offset; i < end; i++) {
  33417. if (inputString[i] === '\n') {
  33418. column = 1;
  33419. line += 1;
  33420. } else {
  33421. column += 1;
  33422. }
  33423. }
  33424. return { column, line, offset: end }
  33425. }
  33426. prev() {
  33427. if (!this.parent) return undefined
  33428. let index = this.parent.index(this);
  33429. return this.parent.nodes[index - 1]
  33430. }
  33431. rangeBy(opts = {}) {
  33432. let inputString =
  33433. 'document' in this.source.input
  33434. ? this.source.input.document
  33435. : this.source.input.css;
  33436. let start = {
  33437. column: this.source.start.column,
  33438. line: this.source.start.line,
  33439. offset: sourceOffset(inputString, this.source.start)
  33440. };
  33441. let end = this.source.end
  33442. ? {
  33443. column: this.source.end.column + 1,
  33444. line: this.source.end.line,
  33445. offset:
  33446. typeof this.source.end.offset === 'number'
  33447. ? // `source.end.offset` is exclusive, so we don't need to add 1
  33448. this.source.end.offset
  33449. : // Since line/column in this.source.end is inclusive,
  33450. // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
  33451. // So, we add 1 to convert it to exclusive.
  33452. sourceOffset(inputString, this.source.end) + 1
  33453. }
  33454. : {
  33455. column: start.column + 1,
  33456. line: start.line,
  33457. offset: start.offset + 1
  33458. };
  33459. if (opts.word) {
  33460. let stringRepresentation = inputString.slice(
  33461. sourceOffset(inputString, this.source.start),
  33462. sourceOffset(inputString, this.source.end)
  33463. );
  33464. let index = stringRepresentation.indexOf(opts.word);
  33465. if (index !== -1) {
  33466. start = this.positionInside(index);
  33467. end = this.positionInside(index + opts.word.length);
  33468. }
  33469. } else {
  33470. if (opts.start) {
  33471. start = {
  33472. column: opts.start.column,
  33473. line: opts.start.line,
  33474. offset: sourceOffset(inputString, opts.start)
  33475. };
  33476. } else if (opts.index) {
  33477. start = this.positionInside(opts.index);
  33478. }
  33479. if (opts.end) {
  33480. end = {
  33481. column: opts.end.column,
  33482. line: opts.end.line,
  33483. offset: sourceOffset(inputString, opts.end)
  33484. };
  33485. } else if (typeof opts.endIndex === 'number') {
  33486. end = this.positionInside(opts.endIndex);
  33487. } else if (opts.index) {
  33488. end = this.positionInside(opts.index + 1);
  33489. }
  33490. }
  33491. if (
  33492. end.line < start.line ||
  33493. (end.line === start.line && end.column <= start.column)
  33494. ) {
  33495. end = {
  33496. column: start.column + 1,
  33497. line: start.line,
  33498. offset: start.offset + 1
  33499. };
  33500. }
  33501. return { end, start }
  33502. }
  33503. raw(prop, defaultType) {
  33504. let str = new Stringifier();
  33505. return str.raw(this, prop, defaultType)
  33506. }
  33507. remove() {
  33508. if (this.parent) {
  33509. this.parent.removeChild(this);
  33510. }
  33511. this.parent = undefined;
  33512. return this
  33513. }
  33514. replaceWith(...nodes) {
  33515. if (this.parent) {
  33516. let bookmark = this;
  33517. let foundSelf = false;
  33518. for (let node of nodes) {
  33519. if (node === this) {
  33520. foundSelf = true;
  33521. } else if (foundSelf) {
  33522. this.parent.insertAfter(bookmark, node);
  33523. bookmark = node;
  33524. } else {
  33525. this.parent.insertBefore(bookmark, node);
  33526. }
  33527. }
  33528. if (!foundSelf) {
  33529. this.remove();
  33530. }
  33531. }
  33532. return this
  33533. }
  33534. root() {
  33535. let result = this;
  33536. while (result.parent && result.parent.type !== 'document') {
  33537. result = result.parent;
  33538. }
  33539. return result
  33540. }
  33541. toJSON(_, inputs) {
  33542. let fixed = {};
  33543. let emitInputs = inputs == null;
  33544. inputs = inputs || new Map();
  33545. let inputsNextIndex = 0;
  33546. for (let name in this) {
  33547. if (!Object.prototype.hasOwnProperty.call(this, name)) {
  33548. /* c8 ignore next 2 */
  33549. continue
  33550. }
  33551. if (name === 'parent' || name === 'proxyCache') continue
  33552. let value = this[name];
  33553. if (Array.isArray(value)) {
  33554. fixed[name] = value.map(i => {
  33555. if (typeof i === 'object' && i.toJSON) {
  33556. return i.toJSON(null, inputs)
  33557. } else {
  33558. return i
  33559. }
  33560. });
  33561. } else if (typeof value === 'object' && value.toJSON) {
  33562. fixed[name] = value.toJSON(null, inputs);
  33563. } else if (name === 'source') {
  33564. if (value == null) continue
  33565. let inputId = inputs.get(value.input);
  33566. if (inputId == null) {
  33567. inputId = inputsNextIndex;
  33568. inputs.set(value.input, inputsNextIndex);
  33569. inputsNextIndex++;
  33570. }
  33571. fixed[name] = {
  33572. end: value.end,
  33573. inputId,
  33574. start: value.start
  33575. };
  33576. } else {
  33577. fixed[name] = value;
  33578. }
  33579. }
  33580. if (emitInputs) {
  33581. fixed.inputs = [...inputs.keys()].map(input => input.toJSON());
  33582. }
  33583. return fixed
  33584. }
  33585. toProxy() {
  33586. if (!this.proxyCache) {
  33587. this.proxyCache = new Proxy(this, this.getProxyProcessor());
  33588. }
  33589. return this.proxyCache
  33590. }
  33591. toString(stringifier = stringify) {
  33592. if (stringifier.stringify) stringifier = stringifier.stringify;
  33593. let result = '';
  33594. stringifier(this, i => {
  33595. result += i;
  33596. });
  33597. return result
  33598. }
  33599. warn(result, text, opts = {}) {
  33600. let data = { node: this };
  33601. for (let i in opts) data[i] = opts[i];
  33602. return result.warn(text, data)
  33603. }
  33604. }
  33605. node$2 = Node;
  33606. Node.default = Node;
  33607. return node$2;
  33608. }
  33609. var comment$1;
  33610. var hasRequiredComment$1;
  33611. function requireComment$1 () {
  33612. if (hasRequiredComment$1) return comment$1;
  33613. hasRequiredComment$1 = 1;
  33614. let Node = /*@__PURE__*/ requireNode$2();
  33615. class Comment extends Node {
  33616. constructor(defaults) {
  33617. super(defaults);
  33618. this.type = 'comment';
  33619. }
  33620. }
  33621. comment$1 = Comment;
  33622. Comment.default = Comment;
  33623. return comment$1;
  33624. }
  33625. var declaration;
  33626. var hasRequiredDeclaration;
  33627. function requireDeclaration () {
  33628. if (hasRequiredDeclaration) return declaration;
  33629. hasRequiredDeclaration = 1;
  33630. let Node = /*@__PURE__*/ requireNode$2();
  33631. class Declaration extends Node {
  33632. get variable() {
  33633. return this.prop.startsWith('--') || this.prop[0] === '$'
  33634. }
  33635. constructor(defaults) {
  33636. if (
  33637. defaults &&
  33638. typeof defaults.value !== 'undefined' &&
  33639. typeof defaults.value !== 'string'
  33640. ) {
  33641. defaults = { ...defaults, value: String(defaults.value) };
  33642. }
  33643. super(defaults);
  33644. this.type = 'decl';
  33645. }
  33646. }
  33647. declaration = Declaration;
  33648. Declaration.default = Declaration;
  33649. return declaration;
  33650. }
  33651. var container$1;
  33652. var hasRequiredContainer$1;
  33653. function requireContainer$1 () {
  33654. if (hasRequiredContainer$1) return container$1;
  33655. hasRequiredContainer$1 = 1;
  33656. let Comment = /*@__PURE__*/ requireComment$1();
  33657. let Declaration = /*@__PURE__*/ requireDeclaration();
  33658. let Node = /*@__PURE__*/ requireNode$2();
  33659. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  33660. let AtRule, parse, Root, Rule;
  33661. function cleanSource(nodes) {
  33662. return nodes.map(i => {
  33663. if (i.nodes) i.nodes = cleanSource(i.nodes);
  33664. delete i.source;
  33665. return i
  33666. })
  33667. }
  33668. function markTreeDirty(node) {
  33669. node[isClean] = false;
  33670. if (node.proxyOf.nodes) {
  33671. for (let i of node.proxyOf.nodes) {
  33672. markTreeDirty(i);
  33673. }
  33674. }
  33675. }
  33676. class Container extends Node {
  33677. get first() {
  33678. if (!this.proxyOf.nodes) return undefined
  33679. return this.proxyOf.nodes[0]
  33680. }
  33681. get last() {
  33682. if (!this.proxyOf.nodes) return undefined
  33683. return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
  33684. }
  33685. append(...children) {
  33686. for (let child of children) {
  33687. let nodes = this.normalize(child, this.last);
  33688. for (let node of nodes) this.proxyOf.nodes.push(node);
  33689. }
  33690. this.markDirty();
  33691. return this
  33692. }
  33693. cleanRaws(keepBetween) {
  33694. super.cleanRaws(keepBetween);
  33695. if (this.nodes) {
  33696. for (let node of this.nodes) node.cleanRaws(keepBetween);
  33697. }
  33698. }
  33699. each(callback) {
  33700. if (!this.proxyOf.nodes) return undefined
  33701. let iterator = this.getIterator();
  33702. let index, result;
  33703. while (this.indexes[iterator] < this.proxyOf.nodes.length) {
  33704. index = this.indexes[iterator];
  33705. result = callback(this.proxyOf.nodes[index], index);
  33706. if (result === false) break
  33707. this.indexes[iterator] += 1;
  33708. }
  33709. delete this.indexes[iterator];
  33710. return result
  33711. }
  33712. every(condition) {
  33713. return this.nodes.every(condition)
  33714. }
  33715. getIterator() {
  33716. if (!this.lastEach) this.lastEach = 0;
  33717. if (!this.indexes) this.indexes = {};
  33718. this.lastEach += 1;
  33719. let iterator = this.lastEach;
  33720. this.indexes[iterator] = 0;
  33721. return iterator
  33722. }
  33723. getProxyProcessor() {
  33724. return {
  33725. get(node, prop) {
  33726. if (prop === 'proxyOf') {
  33727. return node
  33728. } else if (!node[prop]) {
  33729. return node[prop]
  33730. } else if (
  33731. prop === 'each' ||
  33732. (typeof prop === 'string' && prop.startsWith('walk'))
  33733. ) {
  33734. return (...args) => {
  33735. return node[prop](
  33736. ...args.map(i => {
  33737. if (typeof i === 'function') {
  33738. return (child, index) => i(child.toProxy(), index)
  33739. } else {
  33740. return i
  33741. }
  33742. })
  33743. )
  33744. }
  33745. } else if (prop === 'every' || prop === 'some') {
  33746. return cb => {
  33747. return node[prop]((child, ...other) =>
  33748. cb(child.toProxy(), ...other)
  33749. )
  33750. }
  33751. } else if (prop === 'root') {
  33752. return () => node.root().toProxy()
  33753. } else if (prop === 'nodes') {
  33754. return node.nodes.map(i => i.toProxy())
  33755. } else if (prop === 'first' || prop === 'last') {
  33756. return node[prop].toProxy()
  33757. } else {
  33758. return node[prop]
  33759. }
  33760. },
  33761. set(node, prop, value) {
  33762. if (node[prop] === value) return true
  33763. node[prop] = value;
  33764. if (prop === 'name' || prop === 'params' || prop === 'selector') {
  33765. node.markDirty();
  33766. }
  33767. return true
  33768. }
  33769. }
  33770. }
  33771. index(child) {
  33772. if (typeof child === 'number') return child
  33773. if (child.proxyOf) child = child.proxyOf;
  33774. return this.proxyOf.nodes.indexOf(child)
  33775. }
  33776. insertAfter(exist, add) {
  33777. let existIndex = this.index(exist);
  33778. let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse();
  33779. existIndex = this.index(exist);
  33780. for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node);
  33781. let index;
  33782. for (let id in this.indexes) {
  33783. index = this.indexes[id];
  33784. if (existIndex < index) {
  33785. this.indexes[id] = index + nodes.length;
  33786. }
  33787. }
  33788. this.markDirty();
  33789. return this
  33790. }
  33791. insertBefore(exist, add) {
  33792. let existIndex = this.index(exist);
  33793. let type = existIndex === 0 ? 'prepend' : false;
  33794. let nodes = this.normalize(
  33795. add,
  33796. this.proxyOf.nodes[existIndex],
  33797. type
  33798. ).reverse();
  33799. existIndex = this.index(exist);
  33800. for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node);
  33801. let index;
  33802. for (let id in this.indexes) {
  33803. index = this.indexes[id];
  33804. if (existIndex <= index) {
  33805. this.indexes[id] = index + nodes.length;
  33806. }
  33807. }
  33808. this.markDirty();
  33809. return this
  33810. }
  33811. normalize(nodes, sample) {
  33812. if (typeof nodes === 'string') {
  33813. nodes = cleanSource(parse(nodes).nodes);
  33814. } else if (typeof nodes === 'undefined') {
  33815. nodes = [];
  33816. } else if (Array.isArray(nodes)) {
  33817. nodes = nodes.slice(0);
  33818. for (let i of nodes) {
  33819. if (i.parent) i.parent.removeChild(i, 'ignore');
  33820. }
  33821. } else if (nodes.type === 'root' && this.type !== 'document') {
  33822. nodes = nodes.nodes.slice(0);
  33823. for (let i of nodes) {
  33824. if (i.parent) i.parent.removeChild(i, 'ignore');
  33825. }
  33826. } else if (nodes.type) {
  33827. nodes = [nodes];
  33828. } else if (nodes.prop) {
  33829. if (typeof nodes.value === 'undefined') {
  33830. throw new Error('Value field is missed in node creation')
  33831. } else if (typeof nodes.value !== 'string') {
  33832. nodes.value = String(nodes.value);
  33833. }
  33834. nodes = [new Declaration(nodes)];
  33835. } else if (nodes.selector || nodes.selectors) {
  33836. nodes = [new Rule(nodes)];
  33837. } else if (nodes.name) {
  33838. nodes = [new AtRule(nodes)];
  33839. } else if (nodes.text) {
  33840. nodes = [new Comment(nodes)];
  33841. } else {
  33842. throw new Error('Unknown node type in node creation')
  33843. }
  33844. let processed = nodes.map(i => {
  33845. /* c8 ignore next */
  33846. if (!i[my]) Container.rebuild(i);
  33847. i = i.proxyOf;
  33848. if (i.parent) i.parent.removeChild(i);
  33849. if (i[isClean]) markTreeDirty(i);
  33850. if (!i.raws) i.raws = {};
  33851. if (typeof i.raws.before === 'undefined') {
  33852. if (sample && typeof sample.raws.before !== 'undefined') {
  33853. i.raws.before = sample.raws.before.replace(/\S/g, '');
  33854. }
  33855. }
  33856. i.parent = this.proxyOf;
  33857. return i
  33858. });
  33859. return processed
  33860. }
  33861. prepend(...children) {
  33862. children = children.reverse();
  33863. for (let child of children) {
  33864. let nodes = this.normalize(child, this.first, 'prepend').reverse();
  33865. for (let node of nodes) this.proxyOf.nodes.unshift(node);
  33866. for (let id in this.indexes) {
  33867. this.indexes[id] = this.indexes[id] + nodes.length;
  33868. }
  33869. }
  33870. this.markDirty();
  33871. return this
  33872. }
  33873. push(child) {
  33874. child.parent = this;
  33875. this.proxyOf.nodes.push(child);
  33876. return this
  33877. }
  33878. removeAll() {
  33879. for (let node of this.proxyOf.nodes) node.parent = undefined;
  33880. this.proxyOf.nodes = [];
  33881. this.markDirty();
  33882. return this
  33883. }
  33884. removeChild(child) {
  33885. child = this.index(child);
  33886. this.proxyOf.nodes[child].parent = undefined;
  33887. this.proxyOf.nodes.splice(child, 1);
  33888. let index;
  33889. for (let id in this.indexes) {
  33890. index = this.indexes[id];
  33891. if (index >= child) {
  33892. this.indexes[id] = index - 1;
  33893. }
  33894. }
  33895. this.markDirty();
  33896. return this
  33897. }
  33898. replaceValues(pattern, opts, callback) {
  33899. if (!callback) {
  33900. callback = opts;
  33901. opts = {};
  33902. }
  33903. this.walkDecls(decl => {
  33904. if (opts.props && !opts.props.includes(decl.prop)) return
  33905. if (opts.fast && !decl.value.includes(opts.fast)) return
  33906. decl.value = decl.value.replace(pattern, callback);
  33907. });
  33908. this.markDirty();
  33909. return this
  33910. }
  33911. some(condition) {
  33912. return this.nodes.some(condition)
  33913. }
  33914. walk(callback) {
  33915. return this.each((child, i) => {
  33916. let result;
  33917. try {
  33918. result = callback(child, i);
  33919. } catch (e) {
  33920. throw child.addToError(e)
  33921. }
  33922. if (result !== false && child.walk) {
  33923. result = child.walk(callback);
  33924. }
  33925. return result
  33926. })
  33927. }
  33928. walkAtRules(name, callback) {
  33929. if (!callback) {
  33930. callback = name;
  33931. return this.walk((child, i) => {
  33932. if (child.type === 'atrule') {
  33933. return callback(child, i)
  33934. }
  33935. })
  33936. }
  33937. if (name instanceof RegExp) {
  33938. return this.walk((child, i) => {
  33939. if (child.type === 'atrule' && name.test(child.name)) {
  33940. return callback(child, i)
  33941. }
  33942. })
  33943. }
  33944. return this.walk((child, i) => {
  33945. if (child.type === 'atrule' && child.name === name) {
  33946. return callback(child, i)
  33947. }
  33948. })
  33949. }
  33950. walkComments(callback) {
  33951. return this.walk((child, i) => {
  33952. if (child.type === 'comment') {
  33953. return callback(child, i)
  33954. }
  33955. })
  33956. }
  33957. walkDecls(prop, callback) {
  33958. if (!callback) {
  33959. callback = prop;
  33960. return this.walk((child, i) => {
  33961. if (child.type === 'decl') {
  33962. return callback(child, i)
  33963. }
  33964. })
  33965. }
  33966. if (prop instanceof RegExp) {
  33967. return this.walk((child, i) => {
  33968. if (child.type === 'decl' && prop.test(child.prop)) {
  33969. return callback(child, i)
  33970. }
  33971. })
  33972. }
  33973. return this.walk((child, i) => {
  33974. if (child.type === 'decl' && child.prop === prop) {
  33975. return callback(child, i)
  33976. }
  33977. })
  33978. }
  33979. walkRules(selector, callback) {
  33980. if (!callback) {
  33981. callback = selector;
  33982. return this.walk((child, i) => {
  33983. if (child.type === 'rule') {
  33984. return callback(child, i)
  33985. }
  33986. })
  33987. }
  33988. if (selector instanceof RegExp) {
  33989. return this.walk((child, i) => {
  33990. if (child.type === 'rule' && selector.test(child.selector)) {
  33991. return callback(child, i)
  33992. }
  33993. })
  33994. }
  33995. return this.walk((child, i) => {
  33996. if (child.type === 'rule' && child.selector === selector) {
  33997. return callback(child, i)
  33998. }
  33999. })
  34000. }
  34001. }
  34002. Container.registerParse = dependant => {
  34003. parse = dependant;
  34004. };
  34005. Container.registerRule = dependant => {
  34006. Rule = dependant;
  34007. };
  34008. Container.registerAtRule = dependant => {
  34009. AtRule = dependant;
  34010. };
  34011. Container.registerRoot = dependant => {
  34012. Root = dependant;
  34013. };
  34014. container$1 = Container;
  34015. Container.default = Container;
  34016. /* c8 ignore start */
  34017. Container.rebuild = node => {
  34018. if (node.type === 'atrule') {
  34019. Object.setPrototypeOf(node, AtRule.prototype);
  34020. } else if (node.type === 'rule') {
  34021. Object.setPrototypeOf(node, Rule.prototype);
  34022. } else if (node.type === 'decl') {
  34023. Object.setPrototypeOf(node, Declaration.prototype);
  34024. } else if (node.type === 'comment') {
  34025. Object.setPrototypeOf(node, Comment.prototype);
  34026. } else if (node.type === 'root') {
  34027. Object.setPrototypeOf(node, Root.prototype);
  34028. }
  34029. node[my] = true;
  34030. if (node.nodes) {
  34031. node.nodes.forEach(child => {
  34032. Container.rebuild(child);
  34033. });
  34034. }
  34035. };
  34036. /* c8 ignore stop */
  34037. return container$1;
  34038. }
  34039. var atRule;
  34040. var hasRequiredAtRule;
  34041. function requireAtRule () {
  34042. if (hasRequiredAtRule) return atRule;
  34043. hasRequiredAtRule = 1;
  34044. let Container = /*@__PURE__*/ requireContainer$1();
  34045. class AtRule extends Container {
  34046. constructor(defaults) {
  34047. super(defaults);
  34048. this.type = 'atrule';
  34049. }
  34050. append(...children) {
  34051. if (!this.proxyOf.nodes) this.nodes = [];
  34052. return super.append(...children)
  34053. }
  34054. prepend(...children) {
  34055. if (!this.proxyOf.nodes) this.nodes = [];
  34056. return super.prepend(...children)
  34057. }
  34058. }
  34059. atRule = AtRule;
  34060. AtRule.default = AtRule;
  34061. Container.registerAtRule(AtRule);
  34062. return atRule;
  34063. }
  34064. var document;
  34065. var hasRequiredDocument;
  34066. function requireDocument () {
  34067. if (hasRequiredDocument) return document;
  34068. hasRequiredDocument = 1;
  34069. let Container = /*@__PURE__*/ requireContainer$1();
  34070. let LazyResult, Processor;
  34071. class Document extends Container {
  34072. constructor(defaults) {
  34073. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  34074. super({ type: 'document', ...defaults });
  34075. if (!this.nodes) {
  34076. this.nodes = [];
  34077. }
  34078. }
  34079. toResult(opts = {}) {
  34080. let lazy = new LazyResult(new Processor(), this, opts);
  34081. return lazy.stringify()
  34082. }
  34083. }
  34084. Document.registerLazyResult = dependant => {
  34085. LazyResult = dependant;
  34086. };
  34087. Document.registerProcessor = dependant => {
  34088. Processor = dependant;
  34089. };
  34090. document = Document;
  34091. Document.default = Document;
  34092. return document;
  34093. }
  34094. var nonSecure;
  34095. var hasRequiredNonSecure;
  34096. function requireNonSecure () {
  34097. if (hasRequiredNonSecure) return nonSecure;
  34098. hasRequiredNonSecure = 1;
  34099. // This alphabet uses `A-Za-z0-9_-` symbols.
  34100. // The order of characters is optimized for better gzip and brotli compression.
  34101. // References to the same file (works both for gzip and brotli):
  34102. // `'use`, `andom`, and `rict'`
  34103. // References to the brotli default dictionary:
  34104. // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
  34105. let urlAlphabet =
  34106. 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
  34107. let customAlphabet = (alphabet, defaultSize = 21) => {
  34108. return (size = defaultSize) => {
  34109. let id = '';
  34110. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34111. let i = size | 0;
  34112. while (i--) {
  34113. // `| 0` is more compact and faster than `Math.floor()`.
  34114. id += alphabet[(Math.random() * alphabet.length) | 0];
  34115. }
  34116. return id
  34117. }
  34118. };
  34119. let nanoid = (size = 21) => {
  34120. let id = '';
  34121. // A compact alternative for `for (var i = 0; i < step; i++)`.
  34122. let i = size | 0;
  34123. while (i--) {
  34124. // `| 0` is more compact and faster than `Math.floor()`.
  34125. id += urlAlphabet[(Math.random() * 64) | 0];
  34126. }
  34127. return id
  34128. };
  34129. nonSecure = { nanoid, customAlphabet };
  34130. return nonSecure;
  34131. }
  34132. var require$$2 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_url$1);
  34133. var previousMap;
  34134. var hasRequiredPreviousMap;
  34135. function requirePreviousMap () {
  34136. if (hasRequiredPreviousMap) return previousMap;
  34137. hasRequiredPreviousMap = 1;
  34138. let { existsSync, readFileSync } = require$$0$1;
  34139. let { dirname, join } = require$$1;
  34140. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34141. function fromBase64(str) {
  34142. if (Buffer$1) {
  34143. return Buffer$1.from(str, 'base64').toString()
  34144. } else {
  34145. /* c8 ignore next 2 */
  34146. return window.atob(str)
  34147. }
  34148. }
  34149. class PreviousMap {
  34150. constructor(css, opts) {
  34151. if (opts.map === false) return
  34152. this.loadAnnotation(css);
  34153. this.inline = this.startWith(this.annotation, 'data:');
  34154. let prev = opts.map ? opts.map.prev : undefined;
  34155. let text = this.loadMap(opts.from, prev);
  34156. if (!this.mapFile && opts.from) {
  34157. this.mapFile = opts.from;
  34158. }
  34159. if (this.mapFile) this.root = dirname(this.mapFile);
  34160. if (text) this.text = text;
  34161. }
  34162. consumer() {
  34163. if (!this.consumerCache) {
  34164. this.consumerCache = new SourceMapConsumer(this.text);
  34165. }
  34166. return this.consumerCache
  34167. }
  34168. decodeInline(text) {
  34169. let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/;
  34170. let baseUri = /^data:application\/json;base64,/;
  34171. let charsetUri = /^data:application\/json;charset=utf-?8,/;
  34172. let uri = /^data:application\/json,/;
  34173. let uriMatch = text.match(charsetUri) || text.match(uri);
  34174. if (uriMatch) {
  34175. return decodeURIComponent(text.substr(uriMatch[0].length))
  34176. }
  34177. let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri);
  34178. if (baseUriMatch) {
  34179. return fromBase64(text.substr(baseUriMatch[0].length))
  34180. }
  34181. let encoding = text.match(/data:application\/json;([^,]+),/)[1];
  34182. throw new Error('Unsupported source map encoding ' + encoding)
  34183. }
  34184. getAnnotationURL(sourceMapString) {
  34185. return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
  34186. }
  34187. isMap(map) {
  34188. if (typeof map !== 'object') return false
  34189. return (
  34190. typeof map.mappings === 'string' ||
  34191. typeof map._mappings === 'string' ||
  34192. Array.isArray(map.sections)
  34193. )
  34194. }
  34195. loadAnnotation(css) {
  34196. let comments = css.match(/\/\*\s*# sourceMappingURL=/g);
  34197. if (!comments) return
  34198. // sourceMappingURLs from comments, strings, etc.
  34199. let start = css.lastIndexOf(comments.pop());
  34200. let end = css.indexOf('*/', start);
  34201. if (start > -1 && end > -1) {
  34202. // Locate the last sourceMappingURL to avoid pickin
  34203. this.annotation = this.getAnnotationURL(css.substring(start, end));
  34204. }
  34205. }
  34206. loadFile(path) {
  34207. this.root = dirname(path);
  34208. if (existsSync(path)) {
  34209. this.mapFile = path;
  34210. return readFileSync(path, 'utf-8').toString().trim()
  34211. }
  34212. }
  34213. loadMap(file, prev) {
  34214. if (prev === false) return false
  34215. if (prev) {
  34216. if (typeof prev === 'string') {
  34217. return prev
  34218. } else if (typeof prev === 'function') {
  34219. let prevPath = prev(file);
  34220. if (prevPath) {
  34221. let map = this.loadFile(prevPath);
  34222. if (!map) {
  34223. throw new Error(
  34224. 'Unable to load previous source map: ' + prevPath.toString()
  34225. )
  34226. }
  34227. return map
  34228. }
  34229. } else if (prev instanceof SourceMapConsumer) {
  34230. return SourceMapGenerator.fromSourceMap(prev).toString()
  34231. } else if (prev instanceof SourceMapGenerator) {
  34232. return prev.toString()
  34233. } else if (this.isMap(prev)) {
  34234. return JSON.stringify(prev)
  34235. } else {
  34236. throw new Error(
  34237. 'Unsupported previous source map format: ' + prev.toString()
  34238. )
  34239. }
  34240. } else if (this.inline) {
  34241. return this.decodeInline(this.annotation)
  34242. } else if (this.annotation) {
  34243. let map = this.annotation;
  34244. if (file) map = join(dirname(file), map);
  34245. return this.loadFile(map)
  34246. }
  34247. }
  34248. startWith(string, start) {
  34249. if (!string) return false
  34250. return string.substr(0, start.length) === start
  34251. }
  34252. withContent() {
  34253. return !!(
  34254. this.consumer().sourcesContent &&
  34255. this.consumer().sourcesContent.length > 0
  34256. )
  34257. }
  34258. }
  34259. previousMap = PreviousMap;
  34260. PreviousMap.default = PreviousMap;
  34261. return previousMap;
  34262. }
  34263. var input;
  34264. var hasRequiredInput;
  34265. function requireInput () {
  34266. if (hasRequiredInput) return input;
  34267. hasRequiredInput = 1;
  34268. let { nanoid } = /*@__PURE__*/ requireNonSecure();
  34269. let { isAbsolute, resolve } = require$$1;
  34270. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34271. let { fileURLToPath, pathToFileURL } = require$$2;
  34272. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  34273. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34274. let terminalHighlight = /*@__PURE__*/ requireTerminalHighlight();
  34275. let lineToIndexCache = Symbol('lineToIndexCache');
  34276. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34277. let pathAvailable = Boolean(resolve && isAbsolute);
  34278. function getLineToIndex(input) {
  34279. if (input[lineToIndexCache]) return input[lineToIndexCache]
  34280. let lines = input.css.split('\n');
  34281. let lineToIndex = new Array(lines.length);
  34282. let prevIndex = 0;
  34283. for (let i = 0, l = lines.length; i < l; i++) {
  34284. lineToIndex[i] = prevIndex;
  34285. prevIndex += lines[i].length + 1;
  34286. }
  34287. input[lineToIndexCache] = lineToIndex;
  34288. return lineToIndex
  34289. }
  34290. class Input {
  34291. get from() {
  34292. return this.file || this.id
  34293. }
  34294. constructor(css, opts = {}) {
  34295. if (
  34296. css === null ||
  34297. typeof css === 'undefined' ||
  34298. (typeof css === 'object' && !css.toString)
  34299. ) {
  34300. throw new Error(`PostCSS received ${css} instead of CSS string`)
  34301. }
  34302. this.css = css.toString();
  34303. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  34304. this.hasBOM = true;
  34305. this.css = this.css.slice(1);
  34306. } else {
  34307. this.hasBOM = false;
  34308. }
  34309. this.document = this.css;
  34310. if (opts.document) this.document = opts.document.toString();
  34311. if (opts.from) {
  34312. if (
  34313. !pathAvailable ||
  34314. /^\w+:\/\//.test(opts.from) ||
  34315. isAbsolute(opts.from)
  34316. ) {
  34317. this.file = opts.from;
  34318. } else {
  34319. this.file = resolve(opts.from);
  34320. }
  34321. }
  34322. if (pathAvailable && sourceMapAvailable) {
  34323. let map = new PreviousMap(this.css, opts);
  34324. if (map.text) {
  34325. this.map = map;
  34326. let file = map.consumer().file;
  34327. if (!this.file && file) this.file = this.mapResolve(file);
  34328. }
  34329. }
  34330. if (!this.file) {
  34331. this.id = '<input css ' + nanoid(6) + '>';
  34332. }
  34333. if (this.map) this.map.file = this.from;
  34334. }
  34335. error(message, line, column, opts = {}) {
  34336. let endColumn, endLine, endOffset, offset, result;
  34337. if (line && typeof line === 'object') {
  34338. let start = line;
  34339. let end = column;
  34340. if (typeof start.offset === 'number') {
  34341. offset = start.offset;
  34342. let pos = this.fromOffset(offset);
  34343. line = pos.line;
  34344. column = pos.col;
  34345. } else {
  34346. line = start.line;
  34347. column = start.column;
  34348. offset = this.fromLineAndColumn(line, column);
  34349. }
  34350. if (typeof end.offset === 'number') {
  34351. endOffset = end.offset;
  34352. let pos = this.fromOffset(endOffset);
  34353. endLine = pos.line;
  34354. endColumn = pos.col;
  34355. } else {
  34356. endLine = end.line;
  34357. endColumn = end.column;
  34358. endOffset = this.fromLineAndColumn(end.line, end.column);
  34359. }
  34360. } else if (!column) {
  34361. offset = line;
  34362. let pos = this.fromOffset(offset);
  34363. line = pos.line;
  34364. column = pos.col;
  34365. } else {
  34366. offset = this.fromLineAndColumn(line, column);
  34367. }
  34368. let origin = this.origin(line, column, endLine, endColumn);
  34369. if (origin) {
  34370. result = new CssSyntaxError(
  34371. message,
  34372. origin.endLine === undefined
  34373. ? origin.line
  34374. : { column: origin.column, line: origin.line },
  34375. origin.endLine === undefined
  34376. ? origin.column
  34377. : { column: origin.endColumn, line: origin.endLine },
  34378. origin.source,
  34379. origin.file,
  34380. opts.plugin
  34381. );
  34382. } else {
  34383. result = new CssSyntaxError(
  34384. message,
  34385. endLine === undefined ? line : { column, line },
  34386. endLine === undefined ? column : { column: endColumn, line: endLine },
  34387. this.css,
  34388. this.file,
  34389. opts.plugin
  34390. );
  34391. }
  34392. result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css };
  34393. if (this.file) {
  34394. if (pathToFileURL) {
  34395. result.input.url = pathToFileURL(this.file).toString();
  34396. }
  34397. result.input.file = this.file;
  34398. }
  34399. return result
  34400. }
  34401. fromLineAndColumn(line, column) {
  34402. let lineToIndex = getLineToIndex(this);
  34403. let index = lineToIndex[line - 1];
  34404. return index + column - 1
  34405. }
  34406. fromOffset(offset) {
  34407. let lineToIndex = getLineToIndex(this);
  34408. let lastLine = lineToIndex[lineToIndex.length - 1];
  34409. let min = 0;
  34410. if (offset >= lastLine) {
  34411. min = lineToIndex.length - 1;
  34412. } else {
  34413. let max = lineToIndex.length - 2;
  34414. let mid;
  34415. while (min < max) {
  34416. mid = min + ((max - min) >> 1);
  34417. if (offset < lineToIndex[mid]) {
  34418. max = mid - 1;
  34419. } else if (offset >= lineToIndex[mid + 1]) {
  34420. min = mid + 1;
  34421. } else {
  34422. min = mid;
  34423. break
  34424. }
  34425. }
  34426. }
  34427. return {
  34428. col: offset - lineToIndex[min] + 1,
  34429. line: min + 1
  34430. }
  34431. }
  34432. mapResolve(file) {
  34433. if (/^\w+:\/\//.test(file)) {
  34434. return file
  34435. }
  34436. return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
  34437. }
  34438. origin(line, column, endLine, endColumn) {
  34439. if (!this.map) return false
  34440. let consumer = this.map.consumer();
  34441. let from = consumer.originalPositionFor({ column, line });
  34442. if (!from.source) return false
  34443. let to;
  34444. if (typeof endLine === 'number') {
  34445. to = consumer.originalPositionFor({ column: endColumn, line: endLine });
  34446. }
  34447. let fromUrl;
  34448. if (isAbsolute(from.source)) {
  34449. fromUrl = pathToFileURL(from.source);
  34450. } else {
  34451. fromUrl = new URL(
  34452. from.source,
  34453. this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
  34454. );
  34455. }
  34456. let result = {
  34457. column: from.column,
  34458. endColumn: to && to.column,
  34459. endLine: to && to.line,
  34460. line: from.line,
  34461. url: fromUrl.toString()
  34462. };
  34463. if (fromUrl.protocol === 'file:') {
  34464. if (fileURLToPath) {
  34465. result.file = fileURLToPath(fromUrl);
  34466. } else {
  34467. /* c8 ignore next 2 */
  34468. throw new Error(`file: protocol is not available in this PostCSS build`)
  34469. }
  34470. }
  34471. let source = consumer.sourceContentFor(from.source);
  34472. if (source) result.source = source;
  34473. return result
  34474. }
  34475. toJSON() {
  34476. let json = {};
  34477. for (let name of ['hasBOM', 'css', 'file', 'id']) {
  34478. if (this[name] != null) {
  34479. json[name] = this[name];
  34480. }
  34481. }
  34482. if (this.map) {
  34483. json.map = { ...this.map };
  34484. if (json.map.consumerCache) {
  34485. json.map.consumerCache = undefined;
  34486. }
  34487. }
  34488. return json
  34489. }
  34490. }
  34491. input = Input;
  34492. Input.default = Input;
  34493. if (terminalHighlight && terminalHighlight.registerInput) {
  34494. terminalHighlight.registerInput(Input);
  34495. }
  34496. return input;
  34497. }
  34498. var root$1;
  34499. var hasRequiredRoot$1;
  34500. function requireRoot$1 () {
  34501. if (hasRequiredRoot$1) return root$1;
  34502. hasRequiredRoot$1 = 1;
  34503. let Container = /*@__PURE__*/ requireContainer$1();
  34504. let LazyResult, Processor;
  34505. class Root extends Container {
  34506. constructor(defaults) {
  34507. super(defaults);
  34508. this.type = 'root';
  34509. if (!this.nodes) this.nodes = [];
  34510. }
  34511. normalize(child, sample, type) {
  34512. let nodes = super.normalize(child);
  34513. if (sample) {
  34514. if (type === 'prepend') {
  34515. if (this.nodes.length > 1) {
  34516. sample.raws.before = this.nodes[1].raws.before;
  34517. } else {
  34518. delete sample.raws.before;
  34519. }
  34520. } else if (this.first !== sample) {
  34521. for (let node of nodes) {
  34522. node.raws.before = sample.raws.before;
  34523. }
  34524. }
  34525. }
  34526. return nodes
  34527. }
  34528. removeChild(child, ignore) {
  34529. let index = this.index(child);
  34530. if (!ignore && index === 0 && this.nodes.length > 1) {
  34531. this.nodes[1].raws.before = this.nodes[index].raws.before;
  34532. }
  34533. return super.removeChild(child)
  34534. }
  34535. toResult(opts = {}) {
  34536. let lazy = new LazyResult(new Processor(), this, opts);
  34537. return lazy.stringify()
  34538. }
  34539. }
  34540. Root.registerLazyResult = dependant => {
  34541. LazyResult = dependant;
  34542. };
  34543. Root.registerProcessor = dependant => {
  34544. Processor = dependant;
  34545. };
  34546. root$1 = Root;
  34547. Root.default = Root;
  34548. Container.registerRoot(Root);
  34549. return root$1;
  34550. }
  34551. var list_1;
  34552. var hasRequiredList;
  34553. function requireList () {
  34554. if (hasRequiredList) return list_1;
  34555. hasRequiredList = 1;
  34556. let list = {
  34557. comma(string) {
  34558. return list.split(string, [','], true)
  34559. },
  34560. space(string) {
  34561. let spaces = [' ', '\n', '\t'];
  34562. return list.split(string, spaces)
  34563. },
  34564. split(string, separators, last) {
  34565. let array = [];
  34566. let current = '';
  34567. let split = false;
  34568. let func = 0;
  34569. let inQuote = false;
  34570. let prevQuote = '';
  34571. let escape = false;
  34572. for (let letter of string) {
  34573. if (escape) {
  34574. escape = false;
  34575. } else if (letter === '\\') {
  34576. escape = true;
  34577. } else if (inQuote) {
  34578. if (letter === prevQuote) {
  34579. inQuote = false;
  34580. }
  34581. } else if (letter === '"' || letter === "'") {
  34582. inQuote = true;
  34583. prevQuote = letter;
  34584. } else if (letter === '(') {
  34585. func += 1;
  34586. } else if (letter === ')') {
  34587. if (func > 0) func -= 1;
  34588. } else if (func === 0) {
  34589. if (separators.includes(letter)) split = true;
  34590. }
  34591. if (split) {
  34592. if (current !== '') array.push(current.trim());
  34593. current = '';
  34594. split = false;
  34595. } else {
  34596. current += letter;
  34597. }
  34598. }
  34599. if (last || current !== '') array.push(current.trim());
  34600. return array
  34601. }
  34602. };
  34603. list_1 = list;
  34604. list.default = list;
  34605. return list_1;
  34606. }
  34607. var rule;
  34608. var hasRequiredRule;
  34609. function requireRule () {
  34610. if (hasRequiredRule) return rule;
  34611. hasRequiredRule = 1;
  34612. let Container = /*@__PURE__*/ requireContainer$1();
  34613. let list = /*@__PURE__*/ requireList();
  34614. class Rule extends Container {
  34615. get selectors() {
  34616. return list.comma(this.selector)
  34617. }
  34618. set selectors(values) {
  34619. let match = this.selector ? this.selector.match(/,\s*/) : null;
  34620. let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen');
  34621. this.selector = values.join(sep);
  34622. }
  34623. constructor(defaults) {
  34624. super(defaults);
  34625. this.type = 'rule';
  34626. if (!this.nodes) this.nodes = [];
  34627. }
  34628. }
  34629. rule = Rule;
  34630. Rule.default = Rule;
  34631. Container.registerRule(Rule);
  34632. return rule;
  34633. }
  34634. var fromJSON_1;
  34635. var hasRequiredFromJSON;
  34636. function requireFromJSON () {
  34637. if (hasRequiredFromJSON) return fromJSON_1;
  34638. hasRequiredFromJSON = 1;
  34639. let AtRule = /*@__PURE__*/ requireAtRule();
  34640. let Comment = /*@__PURE__*/ requireComment$1();
  34641. let Declaration = /*@__PURE__*/ requireDeclaration();
  34642. let Input = /*@__PURE__*/ requireInput();
  34643. let PreviousMap = /*@__PURE__*/ requirePreviousMap();
  34644. let Root = /*@__PURE__*/ requireRoot$1();
  34645. let Rule = /*@__PURE__*/ requireRule();
  34646. function fromJSON(json, inputs) {
  34647. if (Array.isArray(json)) return json.map(n => fromJSON(n))
  34648. let { inputs: ownInputs, ...defaults } = json;
  34649. if (ownInputs) {
  34650. inputs = [];
  34651. for (let input of ownInputs) {
  34652. let inputHydrated = { ...input, __proto__: Input.prototype };
  34653. if (inputHydrated.map) {
  34654. inputHydrated.map = {
  34655. ...inputHydrated.map,
  34656. __proto__: PreviousMap.prototype
  34657. };
  34658. }
  34659. inputs.push(inputHydrated);
  34660. }
  34661. }
  34662. if (defaults.nodes) {
  34663. defaults.nodes = json.nodes.map(n => fromJSON(n, inputs));
  34664. }
  34665. if (defaults.source) {
  34666. let { inputId, ...source } = defaults.source;
  34667. defaults.source = source;
  34668. if (inputId != null) {
  34669. defaults.source.input = inputs[inputId];
  34670. }
  34671. }
  34672. if (defaults.type === 'root') {
  34673. return new Root(defaults)
  34674. } else if (defaults.type === 'decl') {
  34675. return new Declaration(defaults)
  34676. } else if (defaults.type === 'rule') {
  34677. return new Rule(defaults)
  34678. } else if (defaults.type === 'comment') {
  34679. return new Comment(defaults)
  34680. } else if (defaults.type === 'atrule') {
  34681. return new AtRule(defaults)
  34682. } else {
  34683. throw new Error('Unknown node type: ' + json.type)
  34684. }
  34685. }
  34686. fromJSON_1 = fromJSON;
  34687. fromJSON.default = fromJSON;
  34688. return fromJSON_1;
  34689. }
  34690. var mapGenerator;
  34691. var hasRequiredMapGenerator;
  34692. function requireMapGenerator () {
  34693. if (hasRequiredMapGenerator) return mapGenerator;
  34694. hasRequiredMapGenerator = 1;
  34695. let { dirname, relative, resolve, sep } = require$$1;
  34696. let { SourceMapConsumer, SourceMapGenerator } = /*@__PURE__*/ requireSourceMap$1();
  34697. let { pathToFileURL } = require$$2;
  34698. let Input = /*@__PURE__*/ requireInput();
  34699. let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator);
  34700. let pathAvailable = Boolean(dirname && resolve && relative && sep);
  34701. class MapGenerator {
  34702. constructor(stringify, root, opts, cssString) {
  34703. this.stringify = stringify;
  34704. this.mapOpts = opts.map || {};
  34705. this.root = root;
  34706. this.opts = opts;
  34707. this.css = cssString;
  34708. this.originalCSS = cssString;
  34709. this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute;
  34710. this.memoizedFileURLs = new Map();
  34711. this.memoizedPaths = new Map();
  34712. this.memoizedURLs = new Map();
  34713. }
  34714. addAnnotation() {
  34715. let content;
  34716. if (this.isInline()) {
  34717. content =
  34718. 'data:application/json;base64,' + this.toBase64(this.map.toString());
  34719. } else if (typeof this.mapOpts.annotation === 'string') {
  34720. content = this.mapOpts.annotation;
  34721. } else if (typeof this.mapOpts.annotation === 'function') {
  34722. content = this.mapOpts.annotation(this.opts.to, this.root);
  34723. } else {
  34724. content = this.outputFile() + '.map';
  34725. }
  34726. let eol = '\n';
  34727. if (this.css.includes('\r\n')) eol = '\r\n';
  34728. this.css += eol + '/*# sourceMappingURL=' + content + ' */';
  34729. }
  34730. applyPrevMaps() {
  34731. for (let prev of this.previous()) {
  34732. let from = this.toUrl(this.path(prev.file));
  34733. let root = prev.root || dirname(prev.file);
  34734. let map;
  34735. if (this.mapOpts.sourcesContent === false) {
  34736. map = new SourceMapConsumer(prev.text);
  34737. if (map.sourcesContent) {
  34738. map.sourcesContent = null;
  34739. }
  34740. } else {
  34741. map = prev.consumer();
  34742. }
  34743. this.map.applySourceMap(map, from, this.toUrl(this.path(root)));
  34744. }
  34745. }
  34746. clearAnnotation() {
  34747. if (this.mapOpts.annotation === false) return
  34748. if (this.root) {
  34749. let node;
  34750. for (let i = this.root.nodes.length - 1; i >= 0; i--) {
  34751. node = this.root.nodes[i];
  34752. if (node.type !== 'comment') continue
  34753. if (node.text.startsWith('# sourceMappingURL=')) {
  34754. this.root.removeChild(i);
  34755. }
  34756. }
  34757. } else if (this.css) {
  34758. this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '');
  34759. }
  34760. }
  34761. generate() {
  34762. this.clearAnnotation();
  34763. if (pathAvailable && sourceMapAvailable && this.isMap()) {
  34764. return this.generateMap()
  34765. } else {
  34766. let result = '';
  34767. this.stringify(this.root, i => {
  34768. result += i;
  34769. });
  34770. return [result]
  34771. }
  34772. }
  34773. generateMap() {
  34774. if (this.root) {
  34775. this.generateString();
  34776. } else if (this.previous().length === 1) {
  34777. let prev = this.previous()[0].consumer();
  34778. prev.file = this.outputFile();
  34779. this.map = SourceMapGenerator.fromSourceMap(prev, {
  34780. ignoreInvalidMapping: true
  34781. });
  34782. } else {
  34783. this.map = new SourceMapGenerator({
  34784. file: this.outputFile(),
  34785. ignoreInvalidMapping: true
  34786. });
  34787. this.map.addMapping({
  34788. generated: { column: 0, line: 1 },
  34789. original: { column: 0, line: 1 },
  34790. source: this.opts.from
  34791. ? this.toUrl(this.path(this.opts.from))
  34792. : '<no source>'
  34793. });
  34794. }
  34795. if (this.isSourcesContent()) this.setSourcesContent();
  34796. if (this.root && this.previous().length > 0) this.applyPrevMaps();
  34797. if (this.isAnnotation()) this.addAnnotation();
  34798. if (this.isInline()) {
  34799. return [this.css]
  34800. } else {
  34801. return [this.css, this.map]
  34802. }
  34803. }
  34804. generateString() {
  34805. this.css = '';
  34806. this.map = new SourceMapGenerator({
  34807. file: this.outputFile(),
  34808. ignoreInvalidMapping: true
  34809. });
  34810. let line = 1;
  34811. let column = 1;
  34812. let noSource = '<no source>';
  34813. let mapping = {
  34814. generated: { column: 0, line: 0 },
  34815. original: { column: 0, line: 0 },
  34816. source: ''
  34817. };
  34818. let last, lines;
  34819. this.stringify(this.root, (str, node, type) => {
  34820. this.css += str;
  34821. if (node && type !== 'end') {
  34822. mapping.generated.line = line;
  34823. mapping.generated.column = column - 1;
  34824. if (node.source && node.source.start) {
  34825. mapping.source = this.sourcePath(node);
  34826. mapping.original.line = node.source.start.line;
  34827. mapping.original.column = node.source.start.column - 1;
  34828. this.map.addMapping(mapping);
  34829. } else {
  34830. mapping.source = noSource;
  34831. mapping.original.line = 1;
  34832. mapping.original.column = 0;
  34833. this.map.addMapping(mapping);
  34834. }
  34835. }
  34836. lines = str.match(/\n/g);
  34837. if (lines) {
  34838. line += lines.length;
  34839. last = str.lastIndexOf('\n');
  34840. column = str.length - last;
  34841. } else {
  34842. column += str.length;
  34843. }
  34844. if (node && type !== 'start') {
  34845. let p = node.parent || { raws: {} };
  34846. let childless =
  34847. node.type === 'decl' || (node.type === 'atrule' && !node.nodes);
  34848. if (!childless || node !== p.last || p.raws.semicolon) {
  34849. if (node.source && node.source.end) {
  34850. mapping.source = this.sourcePath(node);
  34851. mapping.original.line = node.source.end.line;
  34852. mapping.original.column = node.source.end.column - 1;
  34853. mapping.generated.line = line;
  34854. mapping.generated.column = column - 2;
  34855. this.map.addMapping(mapping);
  34856. } else {
  34857. mapping.source = noSource;
  34858. mapping.original.line = 1;
  34859. mapping.original.column = 0;
  34860. mapping.generated.line = line;
  34861. mapping.generated.column = column - 1;
  34862. this.map.addMapping(mapping);
  34863. }
  34864. }
  34865. }
  34866. });
  34867. }
  34868. isAnnotation() {
  34869. if (this.isInline()) {
  34870. return true
  34871. }
  34872. if (typeof this.mapOpts.annotation !== 'undefined') {
  34873. return this.mapOpts.annotation
  34874. }
  34875. if (this.previous().length) {
  34876. return this.previous().some(i => i.annotation)
  34877. }
  34878. return true
  34879. }
  34880. isInline() {
  34881. if (typeof this.mapOpts.inline !== 'undefined') {
  34882. return this.mapOpts.inline
  34883. }
  34884. let annotation = this.mapOpts.annotation;
  34885. if (typeof annotation !== 'undefined' && annotation !== true) {
  34886. return false
  34887. }
  34888. if (this.previous().length) {
  34889. return this.previous().some(i => i.inline)
  34890. }
  34891. return true
  34892. }
  34893. isMap() {
  34894. if (typeof this.opts.map !== 'undefined') {
  34895. return !!this.opts.map
  34896. }
  34897. return this.previous().length > 0
  34898. }
  34899. isSourcesContent() {
  34900. if (typeof this.mapOpts.sourcesContent !== 'undefined') {
  34901. return this.mapOpts.sourcesContent
  34902. }
  34903. if (this.previous().length) {
  34904. return this.previous().some(i => i.withContent())
  34905. }
  34906. return true
  34907. }
  34908. outputFile() {
  34909. if (this.opts.to) {
  34910. return this.path(this.opts.to)
  34911. } else if (this.opts.from) {
  34912. return this.path(this.opts.from)
  34913. } else {
  34914. return 'to.css'
  34915. }
  34916. }
  34917. path(file) {
  34918. if (this.mapOpts.absolute) return file
  34919. if (file.charCodeAt(0) === 60 /* `<` */) return file
  34920. if (/^\w+:\/\//.test(file)) return file
  34921. let cached = this.memoizedPaths.get(file);
  34922. if (cached) return cached
  34923. let from = this.opts.to ? dirname(this.opts.to) : '.';
  34924. if (typeof this.mapOpts.annotation === 'string') {
  34925. from = dirname(resolve(from, this.mapOpts.annotation));
  34926. }
  34927. let path = relative(from, file);
  34928. this.memoizedPaths.set(file, path);
  34929. return path
  34930. }
  34931. previous() {
  34932. if (!this.previousMaps) {
  34933. this.previousMaps = [];
  34934. if (this.root) {
  34935. this.root.walk(node => {
  34936. if (node.source && node.source.input.map) {
  34937. let map = node.source.input.map;
  34938. if (!this.previousMaps.includes(map)) {
  34939. this.previousMaps.push(map);
  34940. }
  34941. }
  34942. });
  34943. } else {
  34944. let input = new Input(this.originalCSS, this.opts);
  34945. if (input.map) this.previousMaps.push(input.map);
  34946. }
  34947. }
  34948. return this.previousMaps
  34949. }
  34950. setSourcesContent() {
  34951. let already = {};
  34952. if (this.root) {
  34953. this.root.walk(node => {
  34954. if (node.source) {
  34955. let from = node.source.input.from;
  34956. if (from && !already[from]) {
  34957. already[from] = true;
  34958. let fromUrl = this.usesFileUrls
  34959. ? this.toFileUrl(from)
  34960. : this.toUrl(this.path(from));
  34961. this.map.setSourceContent(fromUrl, node.source.input.css);
  34962. }
  34963. }
  34964. });
  34965. } else if (this.css) {
  34966. let from = this.opts.from
  34967. ? this.toUrl(this.path(this.opts.from))
  34968. : '<no source>';
  34969. this.map.setSourceContent(from, this.css);
  34970. }
  34971. }
  34972. sourcePath(node) {
  34973. if (this.mapOpts.from) {
  34974. return this.toUrl(this.mapOpts.from)
  34975. } else if (this.usesFileUrls) {
  34976. return this.toFileUrl(node.source.input.from)
  34977. } else {
  34978. return this.toUrl(this.path(node.source.input.from))
  34979. }
  34980. }
  34981. toBase64(str) {
  34982. if (Buffer$1) {
  34983. return Buffer$1.from(str).toString('base64')
  34984. } else {
  34985. return window.btoa(unescape(encodeURIComponent(str)))
  34986. }
  34987. }
  34988. toFileUrl(path) {
  34989. let cached = this.memoizedFileURLs.get(path);
  34990. if (cached) return cached
  34991. if (pathToFileURL) {
  34992. let fileURL = pathToFileURL(path).toString();
  34993. this.memoizedFileURLs.set(path, fileURL);
  34994. return fileURL
  34995. } else {
  34996. throw new Error(
  34997. '`map.absolute` option is not available in this PostCSS build'
  34998. )
  34999. }
  35000. }
  35001. toUrl(path) {
  35002. let cached = this.memoizedURLs.get(path);
  35003. if (cached) return cached
  35004. if (sep === '\\') {
  35005. path = path.replace(/\\/g, '/');
  35006. }
  35007. let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent);
  35008. this.memoizedURLs.set(path, url);
  35009. return url
  35010. }
  35011. }
  35012. mapGenerator = MapGenerator;
  35013. return mapGenerator;
  35014. }
  35015. var parser$1;
  35016. var hasRequiredParser$1;
  35017. function requireParser$1 () {
  35018. if (hasRequiredParser$1) return parser$1;
  35019. hasRequiredParser$1 = 1;
  35020. let AtRule = /*@__PURE__*/ requireAtRule();
  35021. let Comment = /*@__PURE__*/ requireComment$1();
  35022. let Declaration = /*@__PURE__*/ requireDeclaration();
  35023. let Root = /*@__PURE__*/ requireRoot$1();
  35024. let Rule = /*@__PURE__*/ requireRule();
  35025. let tokenizer = /*@__PURE__*/ requireTokenize$1();
  35026. const SAFE_COMMENT_NEIGHBOR = {
  35027. empty: true,
  35028. space: true
  35029. };
  35030. function findLastWithPosition(tokens) {
  35031. for (let i = tokens.length - 1; i >= 0; i--) {
  35032. let token = tokens[i];
  35033. let pos = token[3] || token[2];
  35034. if (pos) return pos
  35035. }
  35036. }
  35037. class Parser {
  35038. constructor(input) {
  35039. this.input = input;
  35040. this.root = new Root();
  35041. this.current = this.root;
  35042. this.spaces = '';
  35043. this.semicolon = false;
  35044. this.createTokenizer();
  35045. this.root.source = { input, start: { column: 1, line: 1, offset: 0 } };
  35046. }
  35047. atrule(token) {
  35048. let node = new AtRule();
  35049. node.name = token[1].slice(1);
  35050. if (node.name === '') {
  35051. this.unnamedAtrule(node, token);
  35052. }
  35053. this.init(node, token[2]);
  35054. let type;
  35055. let prev;
  35056. let shift;
  35057. let last = false;
  35058. let open = false;
  35059. let params = [];
  35060. let brackets = [];
  35061. while (!this.tokenizer.endOfFile()) {
  35062. token = this.tokenizer.nextToken();
  35063. type = token[0];
  35064. if (type === '(' || type === '[') {
  35065. brackets.push(type === '(' ? ')' : ']');
  35066. } else if (type === '{' && brackets.length > 0) {
  35067. brackets.push('}');
  35068. } else if (type === brackets[brackets.length - 1]) {
  35069. brackets.pop();
  35070. }
  35071. if (brackets.length === 0) {
  35072. if (type === ';') {
  35073. node.source.end = this.getPosition(token[2]);
  35074. node.source.end.offset++;
  35075. this.semicolon = true;
  35076. break
  35077. } else if (type === '{') {
  35078. open = true;
  35079. break
  35080. } else if (type === '}') {
  35081. if (params.length > 0) {
  35082. shift = params.length - 1;
  35083. prev = params[shift];
  35084. while (prev && prev[0] === 'space') {
  35085. prev = params[--shift];
  35086. }
  35087. if (prev) {
  35088. node.source.end = this.getPosition(prev[3] || prev[2]);
  35089. node.source.end.offset++;
  35090. }
  35091. }
  35092. this.end(token);
  35093. break
  35094. } else {
  35095. params.push(token);
  35096. }
  35097. } else {
  35098. params.push(token);
  35099. }
  35100. if (this.tokenizer.endOfFile()) {
  35101. last = true;
  35102. break
  35103. }
  35104. }
  35105. node.raws.between = this.spacesAndCommentsFromEnd(params);
  35106. if (params.length) {
  35107. node.raws.afterName = this.spacesAndCommentsFromStart(params);
  35108. this.raw(node, 'params', params);
  35109. if (last) {
  35110. token = params[params.length - 1];
  35111. node.source.end = this.getPosition(token[3] || token[2]);
  35112. node.source.end.offset++;
  35113. this.spaces = node.raws.between;
  35114. node.raws.between = '';
  35115. }
  35116. } else {
  35117. node.raws.afterName = '';
  35118. node.params = '';
  35119. }
  35120. if (open) {
  35121. node.nodes = [];
  35122. this.current = node;
  35123. }
  35124. }
  35125. checkMissedSemicolon(tokens) {
  35126. let colon = this.colon(tokens);
  35127. if (colon === false) return
  35128. let founded = 0;
  35129. let token;
  35130. for (let j = colon - 1; j >= 0; j--) {
  35131. token = tokens[j];
  35132. if (token[0] !== 'space') {
  35133. founded += 1;
  35134. if (founded === 2) break
  35135. }
  35136. }
  35137. // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
  35138. // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
  35139. // And because we need it after that one we do +1 to get the next one.
  35140. throw this.input.error(
  35141. 'Missed semicolon',
  35142. token[0] === 'word' ? token[3] + 1 : token[2]
  35143. )
  35144. }
  35145. colon(tokens) {
  35146. let brackets = 0;
  35147. let prev, token, type;
  35148. for (let [i, element] of tokens.entries()) {
  35149. token = element;
  35150. type = token[0];
  35151. if (type === '(') {
  35152. brackets += 1;
  35153. }
  35154. if (type === ')') {
  35155. brackets -= 1;
  35156. }
  35157. if (brackets === 0 && type === ':') {
  35158. if (!prev) {
  35159. this.doubleColon(token);
  35160. } else if (prev[0] === 'word' && prev[1] === 'progid') {
  35161. continue
  35162. } else {
  35163. return i
  35164. }
  35165. }
  35166. prev = token;
  35167. }
  35168. return false
  35169. }
  35170. comment(token) {
  35171. let node = new Comment();
  35172. this.init(node, token[2]);
  35173. node.source.end = this.getPosition(token[3] || token[2]);
  35174. node.source.end.offset++;
  35175. let text = token[1].slice(2, -2);
  35176. if (/^\s*$/.test(text)) {
  35177. node.text = '';
  35178. node.raws.left = text;
  35179. node.raws.right = '';
  35180. } else {
  35181. let match = text.match(/^(\s*)([^]*\S)(\s*)$/);
  35182. node.text = match[2];
  35183. node.raws.left = match[1];
  35184. node.raws.right = match[3];
  35185. }
  35186. }
  35187. createTokenizer() {
  35188. this.tokenizer = tokenizer(this.input);
  35189. }
  35190. decl(tokens, customProperty) {
  35191. let node = new Declaration();
  35192. this.init(node, tokens[0][2]);
  35193. let last = tokens[tokens.length - 1];
  35194. if (last[0] === ';') {
  35195. this.semicolon = true;
  35196. tokens.pop();
  35197. }
  35198. node.source.end = this.getPosition(
  35199. last[3] || last[2] || findLastWithPosition(tokens)
  35200. );
  35201. node.source.end.offset++;
  35202. while (tokens[0][0] !== 'word') {
  35203. if (tokens.length === 1) this.unknownWord(tokens);
  35204. node.raws.before += tokens.shift()[1];
  35205. }
  35206. node.source.start = this.getPosition(tokens[0][2]);
  35207. node.prop = '';
  35208. while (tokens.length) {
  35209. let type = tokens[0][0];
  35210. if (type === ':' || type === 'space' || type === 'comment') {
  35211. break
  35212. }
  35213. node.prop += tokens.shift()[1];
  35214. }
  35215. node.raws.between = '';
  35216. let token;
  35217. while (tokens.length) {
  35218. token = tokens.shift();
  35219. if (token[0] === ':') {
  35220. node.raws.between += token[1];
  35221. break
  35222. } else {
  35223. if (token[0] === 'word' && /\w/.test(token[1])) {
  35224. this.unknownWord([token]);
  35225. }
  35226. node.raws.between += token[1];
  35227. }
  35228. }
  35229. if (node.prop[0] === '_' || node.prop[0] === '*') {
  35230. node.raws.before += node.prop[0];
  35231. node.prop = node.prop.slice(1);
  35232. }
  35233. let firstSpaces = [];
  35234. let next;
  35235. while (tokens.length) {
  35236. next = tokens[0][0];
  35237. if (next !== 'space' && next !== 'comment') break
  35238. firstSpaces.push(tokens.shift());
  35239. }
  35240. this.precheckMissedSemicolon(tokens);
  35241. for (let i = tokens.length - 1; i >= 0; i--) {
  35242. token = tokens[i];
  35243. if (token[1].toLowerCase() === '!important') {
  35244. node.important = true;
  35245. let string = this.stringFrom(tokens, i);
  35246. string = this.spacesFromEnd(tokens) + string;
  35247. if (string !== ' !important') node.raws.important = string;
  35248. break
  35249. } else if (token[1].toLowerCase() === 'important') {
  35250. let cache = tokens.slice(0);
  35251. let str = '';
  35252. for (let j = i; j > 0; j--) {
  35253. let type = cache[j][0];
  35254. if (str.trim().startsWith('!') && type !== 'space') {
  35255. break
  35256. }
  35257. str = cache.pop()[1] + str;
  35258. }
  35259. if (str.trim().startsWith('!')) {
  35260. node.important = true;
  35261. node.raws.important = str;
  35262. tokens = cache;
  35263. }
  35264. }
  35265. if (token[0] !== 'space' && token[0] !== 'comment') {
  35266. break
  35267. }
  35268. }
  35269. let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment');
  35270. if (hasWord) {
  35271. node.raws.between += firstSpaces.map(i => i[1]).join('');
  35272. firstSpaces = [];
  35273. }
  35274. this.raw(node, 'value', firstSpaces.concat(tokens), customProperty);
  35275. if (node.value.includes(':') && !customProperty) {
  35276. this.checkMissedSemicolon(tokens);
  35277. }
  35278. }
  35279. doubleColon(token) {
  35280. throw this.input.error(
  35281. 'Double colon',
  35282. { offset: token[2] },
  35283. { offset: token[2] + token[1].length }
  35284. )
  35285. }
  35286. emptyRule(token) {
  35287. let node = new Rule();
  35288. this.init(node, token[2]);
  35289. node.selector = '';
  35290. node.raws.between = '';
  35291. this.current = node;
  35292. }
  35293. end(token) {
  35294. if (this.current.nodes && this.current.nodes.length) {
  35295. this.current.raws.semicolon = this.semicolon;
  35296. }
  35297. this.semicolon = false;
  35298. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35299. this.spaces = '';
  35300. if (this.current.parent) {
  35301. this.current.source.end = this.getPosition(token[2]);
  35302. this.current.source.end.offset++;
  35303. this.current = this.current.parent;
  35304. } else {
  35305. this.unexpectedClose(token);
  35306. }
  35307. }
  35308. endFile() {
  35309. if (this.current.parent) this.unclosedBlock();
  35310. if (this.current.nodes && this.current.nodes.length) {
  35311. this.current.raws.semicolon = this.semicolon;
  35312. }
  35313. this.current.raws.after = (this.current.raws.after || '') + this.spaces;
  35314. this.root.source.end = this.getPosition(this.tokenizer.position());
  35315. }
  35316. freeSemicolon(token) {
  35317. this.spaces += token[1];
  35318. if (this.current.nodes) {
  35319. let prev = this.current.nodes[this.current.nodes.length - 1];
  35320. if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
  35321. prev.raws.ownSemicolon = this.spaces;
  35322. this.spaces = '';
  35323. prev.source.end = this.getPosition(token[2]);
  35324. prev.source.end.offset += prev.raws.ownSemicolon.length;
  35325. }
  35326. }
  35327. }
  35328. // Helpers
  35329. getPosition(offset) {
  35330. let pos = this.input.fromOffset(offset);
  35331. return {
  35332. column: pos.col,
  35333. line: pos.line,
  35334. offset
  35335. }
  35336. }
  35337. init(node, offset) {
  35338. this.current.push(node);
  35339. node.source = {
  35340. input: this.input,
  35341. start: this.getPosition(offset)
  35342. };
  35343. node.raws.before = this.spaces;
  35344. this.spaces = '';
  35345. if (node.type !== 'comment') this.semicolon = false;
  35346. }
  35347. other(start) {
  35348. let end = false;
  35349. let type = null;
  35350. let colon = false;
  35351. let bracket = null;
  35352. let brackets = [];
  35353. let customProperty = start[1].startsWith('--');
  35354. let tokens = [];
  35355. let token = start;
  35356. while (token) {
  35357. type = token[0];
  35358. tokens.push(token);
  35359. if (type === '(' || type === '[') {
  35360. if (!bracket) bracket = token;
  35361. brackets.push(type === '(' ? ')' : ']');
  35362. } else if (customProperty && colon && type === '{') {
  35363. if (!bracket) bracket = token;
  35364. brackets.push('}');
  35365. } else if (brackets.length === 0) {
  35366. if (type === ';') {
  35367. if (colon) {
  35368. this.decl(tokens, customProperty);
  35369. return
  35370. } else {
  35371. break
  35372. }
  35373. } else if (type === '{') {
  35374. this.rule(tokens);
  35375. return
  35376. } else if (type === '}') {
  35377. this.tokenizer.back(tokens.pop());
  35378. end = true;
  35379. break
  35380. } else if (type === ':') {
  35381. colon = true;
  35382. }
  35383. } else if (type === brackets[brackets.length - 1]) {
  35384. brackets.pop();
  35385. if (brackets.length === 0) bracket = null;
  35386. }
  35387. token = this.tokenizer.nextToken();
  35388. }
  35389. if (this.tokenizer.endOfFile()) end = true;
  35390. if (brackets.length > 0) this.unclosedBracket(bracket);
  35391. if (end && colon) {
  35392. if (!customProperty) {
  35393. while (tokens.length) {
  35394. token = tokens[tokens.length - 1][0];
  35395. if (token !== 'space' && token !== 'comment') break
  35396. this.tokenizer.back(tokens.pop());
  35397. }
  35398. }
  35399. this.decl(tokens, customProperty);
  35400. } else {
  35401. this.unknownWord(tokens);
  35402. }
  35403. }
  35404. parse() {
  35405. let token;
  35406. while (!this.tokenizer.endOfFile()) {
  35407. token = this.tokenizer.nextToken();
  35408. switch (token[0]) {
  35409. case 'space':
  35410. this.spaces += token[1];
  35411. break
  35412. case ';':
  35413. this.freeSemicolon(token);
  35414. break
  35415. case '}':
  35416. this.end(token);
  35417. break
  35418. case 'comment':
  35419. this.comment(token);
  35420. break
  35421. case 'at-word':
  35422. this.atrule(token);
  35423. break
  35424. case '{':
  35425. this.emptyRule(token);
  35426. break
  35427. default:
  35428. this.other(token);
  35429. break
  35430. }
  35431. }
  35432. this.endFile();
  35433. }
  35434. precheckMissedSemicolon(/* tokens */) {
  35435. // Hook for Safe Parser
  35436. }
  35437. raw(node, prop, tokens, customProperty) {
  35438. let token, type;
  35439. let length = tokens.length;
  35440. let value = '';
  35441. let clean = true;
  35442. let next, prev;
  35443. for (let i = 0; i < length; i += 1) {
  35444. token = tokens[i];
  35445. type = token[0];
  35446. if (type === 'space' && i === length - 1 && !customProperty) {
  35447. clean = false;
  35448. } else if (type === 'comment') {
  35449. prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty';
  35450. next = tokens[i + 1] ? tokens[i + 1][0] : 'empty';
  35451. if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
  35452. if (value.slice(-1) === ',') {
  35453. clean = false;
  35454. } else {
  35455. value += token[1];
  35456. }
  35457. } else {
  35458. clean = false;
  35459. }
  35460. } else {
  35461. value += token[1];
  35462. }
  35463. }
  35464. if (!clean) {
  35465. let raw = tokens.reduce((all, i) => all + i[1], '');
  35466. node.raws[prop] = { raw, value };
  35467. }
  35468. node[prop] = value;
  35469. }
  35470. rule(tokens) {
  35471. tokens.pop();
  35472. let node = new Rule();
  35473. this.init(node, tokens[0][2]);
  35474. node.raws.between = this.spacesAndCommentsFromEnd(tokens);
  35475. this.raw(node, 'selector', tokens);
  35476. this.current = node;
  35477. }
  35478. spacesAndCommentsFromEnd(tokens) {
  35479. let lastTokenType;
  35480. let spaces = '';
  35481. while (tokens.length) {
  35482. lastTokenType = tokens[tokens.length - 1][0];
  35483. if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
  35484. spaces = tokens.pop()[1] + spaces;
  35485. }
  35486. return spaces
  35487. }
  35488. // Errors
  35489. spacesAndCommentsFromStart(tokens) {
  35490. let next;
  35491. let spaces = '';
  35492. while (tokens.length) {
  35493. next = tokens[0][0];
  35494. if (next !== 'space' && next !== 'comment') break
  35495. spaces += tokens.shift()[1];
  35496. }
  35497. return spaces
  35498. }
  35499. spacesFromEnd(tokens) {
  35500. let lastTokenType;
  35501. let spaces = '';
  35502. while (tokens.length) {
  35503. lastTokenType = tokens[tokens.length - 1][0];
  35504. if (lastTokenType !== 'space') break
  35505. spaces = tokens.pop()[1] + spaces;
  35506. }
  35507. return spaces
  35508. }
  35509. stringFrom(tokens, from) {
  35510. let result = '';
  35511. for (let i = from; i < tokens.length; i++) {
  35512. result += tokens[i][1];
  35513. }
  35514. tokens.splice(from, tokens.length - from);
  35515. return result
  35516. }
  35517. unclosedBlock() {
  35518. let pos = this.current.source.start;
  35519. throw this.input.error('Unclosed block', pos.line, pos.column)
  35520. }
  35521. unclosedBracket(bracket) {
  35522. throw this.input.error(
  35523. 'Unclosed bracket',
  35524. { offset: bracket[2] },
  35525. { offset: bracket[2] + 1 }
  35526. )
  35527. }
  35528. unexpectedClose(token) {
  35529. throw this.input.error(
  35530. 'Unexpected }',
  35531. { offset: token[2] },
  35532. { offset: token[2] + 1 }
  35533. )
  35534. }
  35535. unknownWord(tokens) {
  35536. throw this.input.error(
  35537. 'Unknown word ' + tokens[0][1],
  35538. { offset: tokens[0][2] },
  35539. { offset: tokens[0][2] + tokens[0][1].length }
  35540. )
  35541. }
  35542. unnamedAtrule(node, token) {
  35543. throw this.input.error(
  35544. 'At-rule without name',
  35545. { offset: token[2] },
  35546. { offset: token[2] + token[1].length }
  35547. )
  35548. }
  35549. }
  35550. parser$1 = Parser;
  35551. return parser$1;
  35552. }
  35553. var parse_1;
  35554. var hasRequiredParse;
  35555. function requireParse () {
  35556. if (hasRequiredParse) return parse_1;
  35557. hasRequiredParse = 1;
  35558. let Container = /*@__PURE__*/ requireContainer$1();
  35559. let Input = /*@__PURE__*/ requireInput();
  35560. let Parser = /*@__PURE__*/ requireParser$1();
  35561. function parse(css, opts) {
  35562. let input = new Input(css, opts);
  35563. let parser = new Parser(input);
  35564. try {
  35565. parser.parse();
  35566. } catch (e) {
  35567. if (browser$1.env.NODE_ENV !== 'production') {
  35568. if (e.name === 'CssSyntaxError' && opts && opts.from) {
  35569. if (/\.scss$/i.test(opts.from)) {
  35570. e.message +=
  35571. '\nYou tried to parse SCSS with ' +
  35572. 'the standard CSS parser; ' +
  35573. 'try again with the postcss-scss parser';
  35574. } else if (/\.sass/i.test(opts.from)) {
  35575. e.message +=
  35576. '\nYou tried to parse Sass with ' +
  35577. 'the standard CSS parser; ' +
  35578. 'try again with the postcss-sass parser';
  35579. } else if (/\.less$/i.test(opts.from)) {
  35580. e.message +=
  35581. '\nYou tried to parse Less with ' +
  35582. 'the standard CSS parser; ' +
  35583. 'try again with the postcss-less parser';
  35584. }
  35585. }
  35586. }
  35587. throw e
  35588. }
  35589. return parser.root
  35590. }
  35591. parse_1 = parse;
  35592. parse.default = parse;
  35593. Container.registerParse(parse);
  35594. return parse_1;
  35595. }
  35596. var warning;
  35597. var hasRequiredWarning;
  35598. function requireWarning () {
  35599. if (hasRequiredWarning) return warning;
  35600. hasRequiredWarning = 1;
  35601. class Warning {
  35602. constructor(text, opts = {}) {
  35603. this.type = 'warning';
  35604. this.text = text;
  35605. if (opts.node && opts.node.source) {
  35606. let range = opts.node.rangeBy(opts);
  35607. this.line = range.start.line;
  35608. this.column = range.start.column;
  35609. this.endLine = range.end.line;
  35610. this.endColumn = range.end.column;
  35611. }
  35612. for (let opt in opts) this[opt] = opts[opt];
  35613. }
  35614. toString() {
  35615. if (this.node) {
  35616. return this.node.error(this.text, {
  35617. index: this.index,
  35618. plugin: this.plugin,
  35619. word: this.word
  35620. }).message
  35621. }
  35622. if (this.plugin) {
  35623. return this.plugin + ': ' + this.text
  35624. }
  35625. return this.text
  35626. }
  35627. }
  35628. warning = Warning;
  35629. Warning.default = Warning;
  35630. return warning;
  35631. }
  35632. var result;
  35633. var hasRequiredResult;
  35634. function requireResult () {
  35635. if (hasRequiredResult) return result;
  35636. hasRequiredResult = 1;
  35637. let Warning = /*@__PURE__*/ requireWarning();
  35638. class Result {
  35639. get content() {
  35640. return this.css
  35641. }
  35642. constructor(processor, root, opts) {
  35643. this.processor = processor;
  35644. this.messages = [];
  35645. this.root = root;
  35646. this.opts = opts;
  35647. this.css = '';
  35648. this.map = undefined;
  35649. }
  35650. toString() {
  35651. return this.css
  35652. }
  35653. warn(text, opts = {}) {
  35654. if (!opts.plugin) {
  35655. if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
  35656. opts.plugin = this.lastPlugin.postcssPlugin;
  35657. }
  35658. }
  35659. let warning = new Warning(text, opts);
  35660. this.messages.push(warning);
  35661. return warning
  35662. }
  35663. warnings() {
  35664. return this.messages.filter(i => i.type === 'warning')
  35665. }
  35666. }
  35667. result = Result;
  35668. Result.default = Result;
  35669. return result;
  35670. }
  35671. /* eslint-disable no-console */
  35672. var warnOnce;
  35673. var hasRequiredWarnOnce;
  35674. function requireWarnOnce () {
  35675. if (hasRequiredWarnOnce) return warnOnce;
  35676. hasRequiredWarnOnce = 1;
  35677. let printed = {};
  35678. warnOnce = function warnOnce(message) {
  35679. if (printed[message]) return
  35680. printed[message] = true;
  35681. if (typeof console !== 'undefined' && console.warn) {
  35682. console.warn(message);
  35683. }
  35684. };
  35685. return warnOnce;
  35686. }
  35687. var lazyResult;
  35688. var hasRequiredLazyResult;
  35689. function requireLazyResult () {
  35690. if (hasRequiredLazyResult) return lazyResult;
  35691. hasRequiredLazyResult = 1;
  35692. let Container = /*@__PURE__*/ requireContainer$1();
  35693. let Document = /*@__PURE__*/ requireDocument();
  35694. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  35695. let parse = /*@__PURE__*/ requireParse();
  35696. let Result = /*@__PURE__*/ requireResult();
  35697. let Root = /*@__PURE__*/ requireRoot$1();
  35698. let stringify = /*@__PURE__*/ requireStringify();
  35699. let { isClean, my } = /*@__PURE__*/ requireSymbols();
  35700. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  35701. const TYPE_TO_CLASS_NAME = {
  35702. atrule: 'AtRule',
  35703. comment: 'Comment',
  35704. decl: 'Declaration',
  35705. document: 'Document',
  35706. root: 'Root',
  35707. rule: 'Rule'
  35708. };
  35709. const PLUGIN_PROPS = {
  35710. AtRule: true,
  35711. AtRuleExit: true,
  35712. Comment: true,
  35713. CommentExit: true,
  35714. Declaration: true,
  35715. DeclarationExit: true,
  35716. Document: true,
  35717. DocumentExit: true,
  35718. Once: true,
  35719. OnceExit: true,
  35720. postcssPlugin: true,
  35721. prepare: true,
  35722. Root: true,
  35723. RootExit: true,
  35724. Rule: true,
  35725. RuleExit: true
  35726. };
  35727. const NOT_VISITORS = {
  35728. Once: true,
  35729. postcssPlugin: true,
  35730. prepare: true
  35731. };
  35732. const CHILDREN = 0;
  35733. function isPromise(obj) {
  35734. return typeof obj === 'object' && typeof obj.then === 'function'
  35735. }
  35736. function getEvents(node) {
  35737. let key = false;
  35738. let type = TYPE_TO_CLASS_NAME[node.type];
  35739. if (node.type === 'decl') {
  35740. key = node.prop.toLowerCase();
  35741. } else if (node.type === 'atrule') {
  35742. key = node.name.toLowerCase();
  35743. }
  35744. if (key && node.append) {
  35745. return [
  35746. type,
  35747. type + '-' + key,
  35748. CHILDREN,
  35749. type + 'Exit',
  35750. type + 'Exit-' + key
  35751. ]
  35752. } else if (key) {
  35753. return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
  35754. } else if (node.append) {
  35755. return [type, CHILDREN, type + 'Exit']
  35756. } else {
  35757. return [type, type + 'Exit']
  35758. }
  35759. }
  35760. function toStack(node) {
  35761. let events;
  35762. if (node.type === 'document') {
  35763. events = ['Document', CHILDREN, 'DocumentExit'];
  35764. } else if (node.type === 'root') {
  35765. events = ['Root', CHILDREN, 'RootExit'];
  35766. } else {
  35767. events = getEvents(node);
  35768. }
  35769. return {
  35770. eventIndex: 0,
  35771. events,
  35772. iterator: 0,
  35773. node,
  35774. visitorIndex: 0,
  35775. visitors: []
  35776. }
  35777. }
  35778. function cleanMarks(node) {
  35779. node[isClean] = false;
  35780. if (node.nodes) node.nodes.forEach(i => cleanMarks(i));
  35781. return node
  35782. }
  35783. let postcss = {};
  35784. class LazyResult {
  35785. get content() {
  35786. return this.stringify().content
  35787. }
  35788. get css() {
  35789. return this.stringify().css
  35790. }
  35791. get map() {
  35792. return this.stringify().map
  35793. }
  35794. get messages() {
  35795. return this.sync().messages
  35796. }
  35797. get opts() {
  35798. return this.result.opts
  35799. }
  35800. get processor() {
  35801. return this.result.processor
  35802. }
  35803. get root() {
  35804. return this.sync().root
  35805. }
  35806. get [Symbol.toStringTag]() {
  35807. return 'LazyResult'
  35808. }
  35809. constructor(processor, css, opts) {
  35810. this.stringified = false;
  35811. this.processed = false;
  35812. let root;
  35813. if (
  35814. typeof css === 'object' &&
  35815. css !== null &&
  35816. (css.type === 'root' || css.type === 'document')
  35817. ) {
  35818. root = cleanMarks(css);
  35819. } else if (css instanceof LazyResult || css instanceof Result) {
  35820. root = cleanMarks(css.root);
  35821. if (css.map) {
  35822. if (typeof opts.map === 'undefined') opts.map = {};
  35823. if (!opts.map.inline) opts.map.inline = false;
  35824. opts.map.prev = css.map;
  35825. }
  35826. } else {
  35827. let parser = parse;
  35828. if (opts.syntax) parser = opts.syntax.parse;
  35829. if (opts.parser) parser = opts.parser;
  35830. if (parser.parse) parser = parser.parse;
  35831. try {
  35832. root = parser(css, opts);
  35833. } catch (error) {
  35834. this.processed = true;
  35835. this.error = error;
  35836. }
  35837. if (root && !root[my]) {
  35838. /* c8 ignore next 2 */
  35839. Container.rebuild(root);
  35840. }
  35841. }
  35842. this.result = new Result(processor, root, opts);
  35843. this.helpers = { ...postcss, postcss, result: this.result };
  35844. this.plugins = this.processor.plugins.map(plugin => {
  35845. if (typeof plugin === 'object' && plugin.prepare) {
  35846. return { ...plugin, ...plugin.prepare(this.result) }
  35847. } else {
  35848. return plugin
  35849. }
  35850. });
  35851. }
  35852. async() {
  35853. if (this.error) return Promise.reject(this.error)
  35854. if (this.processed) return Promise.resolve(this.result)
  35855. if (!this.processing) {
  35856. this.processing = this.runAsync();
  35857. }
  35858. return this.processing
  35859. }
  35860. catch(onRejected) {
  35861. return this.async().catch(onRejected)
  35862. }
  35863. finally(onFinally) {
  35864. return this.async().then(onFinally, onFinally)
  35865. }
  35866. getAsyncError() {
  35867. throw new Error('Use process(css).then(cb) to work with async plugins')
  35868. }
  35869. handleError(error, node) {
  35870. let plugin = this.result.lastPlugin;
  35871. try {
  35872. if (node) node.addToError(error);
  35873. this.error = error;
  35874. if (error.name === 'CssSyntaxError' && !error.plugin) {
  35875. error.plugin = plugin.postcssPlugin;
  35876. error.setMessage();
  35877. } else if (plugin.postcssVersion) {
  35878. if (browser$1.env.NODE_ENV !== 'production') {
  35879. let pluginName = plugin.postcssPlugin;
  35880. let pluginVer = plugin.postcssVersion;
  35881. let runtimeVer = this.result.processor.version;
  35882. let a = pluginVer.split('.');
  35883. let b = runtimeVer.split('.');
  35884. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  35885. // eslint-disable-next-line no-console
  35886. console.error(
  35887. 'Unknown error from PostCSS plugin. Your current PostCSS ' +
  35888. 'version is ' +
  35889. runtimeVer +
  35890. ', but ' +
  35891. pluginName +
  35892. ' uses ' +
  35893. pluginVer +
  35894. '. Perhaps this is the source of the error below.'
  35895. );
  35896. }
  35897. }
  35898. }
  35899. } catch (err) {
  35900. /* c8 ignore next 3 */
  35901. // eslint-disable-next-line no-console
  35902. if (console && console.error) console.error(err);
  35903. }
  35904. return error
  35905. }
  35906. prepareVisitors() {
  35907. this.listeners = {};
  35908. let add = (plugin, type, cb) => {
  35909. if (!this.listeners[type]) this.listeners[type] = [];
  35910. this.listeners[type].push([plugin, cb]);
  35911. };
  35912. for (let plugin of this.plugins) {
  35913. if (typeof plugin === 'object') {
  35914. for (let event in plugin) {
  35915. if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
  35916. throw new Error(
  35917. `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
  35918. `Try to update PostCSS (${this.processor.version} now).`
  35919. )
  35920. }
  35921. if (!NOT_VISITORS[event]) {
  35922. if (typeof plugin[event] === 'object') {
  35923. for (let filter in plugin[event]) {
  35924. if (filter === '*') {
  35925. add(plugin, event, plugin[event][filter]);
  35926. } else {
  35927. add(
  35928. plugin,
  35929. event + '-' + filter.toLowerCase(),
  35930. plugin[event][filter]
  35931. );
  35932. }
  35933. }
  35934. } else if (typeof plugin[event] === 'function') {
  35935. add(plugin, event, plugin[event]);
  35936. }
  35937. }
  35938. }
  35939. }
  35940. }
  35941. this.hasListener = Object.keys(this.listeners).length > 0;
  35942. }
  35943. async runAsync() {
  35944. this.plugin = 0;
  35945. for (let i = 0; i < this.plugins.length; i++) {
  35946. let plugin = this.plugins[i];
  35947. let promise = this.runOnRoot(plugin);
  35948. if (isPromise(promise)) {
  35949. try {
  35950. await promise;
  35951. } catch (error) {
  35952. throw this.handleError(error)
  35953. }
  35954. }
  35955. }
  35956. this.prepareVisitors();
  35957. if (this.hasListener) {
  35958. let root = this.result.root;
  35959. while (!root[isClean]) {
  35960. root[isClean] = true;
  35961. let stack = [toStack(root)];
  35962. while (stack.length > 0) {
  35963. let promise = this.visitTick(stack);
  35964. if (isPromise(promise)) {
  35965. try {
  35966. await promise;
  35967. } catch (e) {
  35968. let node = stack[stack.length - 1].node;
  35969. throw this.handleError(e, node)
  35970. }
  35971. }
  35972. }
  35973. }
  35974. if (this.listeners.OnceExit) {
  35975. for (let [plugin, visitor] of this.listeners.OnceExit) {
  35976. this.result.lastPlugin = plugin;
  35977. try {
  35978. if (root.type === 'document') {
  35979. let roots = root.nodes.map(subRoot =>
  35980. visitor(subRoot, this.helpers)
  35981. );
  35982. await Promise.all(roots);
  35983. } else {
  35984. await visitor(root, this.helpers);
  35985. }
  35986. } catch (e) {
  35987. throw this.handleError(e)
  35988. }
  35989. }
  35990. }
  35991. }
  35992. this.processed = true;
  35993. return this.stringify()
  35994. }
  35995. runOnRoot(plugin) {
  35996. this.result.lastPlugin = plugin;
  35997. try {
  35998. if (typeof plugin === 'object' && plugin.Once) {
  35999. if (this.result.root.type === 'document') {
  36000. let roots = this.result.root.nodes.map(root =>
  36001. plugin.Once(root, this.helpers)
  36002. );
  36003. if (isPromise(roots[0])) {
  36004. return Promise.all(roots)
  36005. }
  36006. return roots
  36007. }
  36008. return plugin.Once(this.result.root, this.helpers)
  36009. } else if (typeof plugin === 'function') {
  36010. return plugin(this.result.root, this.result)
  36011. }
  36012. } catch (error) {
  36013. throw this.handleError(error)
  36014. }
  36015. }
  36016. stringify() {
  36017. if (this.error) throw this.error
  36018. if (this.stringified) return this.result
  36019. this.stringified = true;
  36020. this.sync();
  36021. let opts = this.result.opts;
  36022. let str = stringify;
  36023. if (opts.syntax) str = opts.syntax.stringify;
  36024. if (opts.stringifier) str = opts.stringifier;
  36025. if (str.stringify) str = str.stringify;
  36026. let map = new MapGenerator(str, this.result.root, this.result.opts);
  36027. let data = map.generate();
  36028. this.result.css = data[0];
  36029. this.result.map = data[1];
  36030. return this.result
  36031. }
  36032. sync() {
  36033. if (this.error) throw this.error
  36034. if (this.processed) return this.result
  36035. this.processed = true;
  36036. if (this.processing) {
  36037. throw this.getAsyncError()
  36038. }
  36039. for (let plugin of this.plugins) {
  36040. let promise = this.runOnRoot(plugin);
  36041. if (isPromise(promise)) {
  36042. throw this.getAsyncError()
  36043. }
  36044. }
  36045. this.prepareVisitors();
  36046. if (this.hasListener) {
  36047. let root = this.result.root;
  36048. while (!root[isClean]) {
  36049. root[isClean] = true;
  36050. this.walkSync(root);
  36051. }
  36052. if (this.listeners.OnceExit) {
  36053. if (root.type === 'document') {
  36054. for (let subRoot of root.nodes) {
  36055. this.visitSync(this.listeners.OnceExit, subRoot);
  36056. }
  36057. } else {
  36058. this.visitSync(this.listeners.OnceExit, root);
  36059. }
  36060. }
  36061. }
  36062. return this.result
  36063. }
  36064. then(onFulfilled, onRejected) {
  36065. if (browser$1.env.NODE_ENV !== 'production') {
  36066. if (!('from' in this.opts)) {
  36067. warnOnce(
  36068. 'Without `from` option PostCSS could generate wrong source map ' +
  36069. 'and will not find Browserslist config. Set it to CSS file path ' +
  36070. 'or to `undefined` to prevent this warning.'
  36071. );
  36072. }
  36073. }
  36074. return this.async().then(onFulfilled, onRejected)
  36075. }
  36076. toString() {
  36077. return this.css
  36078. }
  36079. visitSync(visitors, node) {
  36080. for (let [plugin, visitor] of visitors) {
  36081. this.result.lastPlugin = plugin;
  36082. let promise;
  36083. try {
  36084. promise = visitor(node, this.helpers);
  36085. } catch (e) {
  36086. throw this.handleError(e, node.proxyOf)
  36087. }
  36088. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36089. return true
  36090. }
  36091. if (isPromise(promise)) {
  36092. throw this.getAsyncError()
  36093. }
  36094. }
  36095. }
  36096. visitTick(stack) {
  36097. let visit = stack[stack.length - 1];
  36098. let { node, visitors } = visit;
  36099. if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
  36100. stack.pop();
  36101. return
  36102. }
  36103. if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
  36104. let [plugin, visitor] = visitors[visit.visitorIndex];
  36105. visit.visitorIndex += 1;
  36106. if (visit.visitorIndex === visitors.length) {
  36107. visit.visitors = [];
  36108. visit.visitorIndex = 0;
  36109. }
  36110. this.result.lastPlugin = plugin;
  36111. try {
  36112. return visitor(node.toProxy(), this.helpers)
  36113. } catch (e) {
  36114. throw this.handleError(e, node)
  36115. }
  36116. }
  36117. if (visit.iterator !== 0) {
  36118. let iterator = visit.iterator;
  36119. let child;
  36120. while ((child = node.nodes[node.indexes[iterator]])) {
  36121. node.indexes[iterator] += 1;
  36122. if (!child[isClean]) {
  36123. child[isClean] = true;
  36124. stack.push(toStack(child));
  36125. return
  36126. }
  36127. }
  36128. visit.iterator = 0;
  36129. delete node.indexes[iterator];
  36130. }
  36131. let events = visit.events;
  36132. while (visit.eventIndex < events.length) {
  36133. let event = events[visit.eventIndex];
  36134. visit.eventIndex += 1;
  36135. if (event === CHILDREN) {
  36136. if (node.nodes && node.nodes.length) {
  36137. node[isClean] = true;
  36138. visit.iterator = node.getIterator();
  36139. }
  36140. return
  36141. } else if (this.listeners[event]) {
  36142. visit.visitors = this.listeners[event];
  36143. return
  36144. }
  36145. }
  36146. stack.pop();
  36147. }
  36148. walkSync(node) {
  36149. node[isClean] = true;
  36150. let events = getEvents(node);
  36151. for (let event of events) {
  36152. if (event === CHILDREN) {
  36153. if (node.nodes) {
  36154. node.each(child => {
  36155. if (!child[isClean]) this.walkSync(child);
  36156. });
  36157. }
  36158. } else {
  36159. let visitors = this.listeners[event];
  36160. if (visitors) {
  36161. if (this.visitSync(visitors, node.toProxy())) return
  36162. }
  36163. }
  36164. }
  36165. }
  36166. warnings() {
  36167. return this.sync().warnings()
  36168. }
  36169. }
  36170. LazyResult.registerPostcss = dependant => {
  36171. postcss = dependant;
  36172. };
  36173. lazyResult = LazyResult;
  36174. LazyResult.default = LazyResult;
  36175. Root.registerLazyResult(LazyResult);
  36176. Document.registerLazyResult(LazyResult);
  36177. return lazyResult;
  36178. }
  36179. var noWorkResult;
  36180. var hasRequiredNoWorkResult;
  36181. function requireNoWorkResult () {
  36182. if (hasRequiredNoWorkResult) return noWorkResult;
  36183. hasRequiredNoWorkResult = 1;
  36184. let MapGenerator = /*@__PURE__*/ requireMapGenerator();
  36185. let parse = /*@__PURE__*/ requireParse();
  36186. const Result = /*@__PURE__*/ requireResult();
  36187. let stringify = /*@__PURE__*/ requireStringify();
  36188. let warnOnce = /*@__PURE__*/ requireWarnOnce();
  36189. class NoWorkResult {
  36190. get content() {
  36191. return this.result.css
  36192. }
  36193. get css() {
  36194. return this.result.css
  36195. }
  36196. get map() {
  36197. return this.result.map
  36198. }
  36199. get messages() {
  36200. return []
  36201. }
  36202. get opts() {
  36203. return this.result.opts
  36204. }
  36205. get processor() {
  36206. return this.result.processor
  36207. }
  36208. get root() {
  36209. if (this._root) {
  36210. return this._root
  36211. }
  36212. let root;
  36213. let parser = parse;
  36214. try {
  36215. root = parser(this._css, this._opts);
  36216. } catch (error) {
  36217. this.error = error;
  36218. }
  36219. if (this.error) {
  36220. throw this.error
  36221. } else {
  36222. this._root = root;
  36223. return root
  36224. }
  36225. }
  36226. get [Symbol.toStringTag]() {
  36227. return 'NoWorkResult'
  36228. }
  36229. constructor(processor, css, opts) {
  36230. css = css.toString();
  36231. this.stringified = false;
  36232. this._processor = processor;
  36233. this._css = css;
  36234. this._opts = opts;
  36235. this._map = undefined;
  36236. let root;
  36237. let str = stringify;
  36238. this.result = new Result(this._processor, root, this._opts);
  36239. this.result.css = css;
  36240. let self = this;
  36241. Object.defineProperty(this.result, 'root', {
  36242. get() {
  36243. return self.root
  36244. }
  36245. });
  36246. let map = new MapGenerator(str, root, this._opts, css);
  36247. if (map.isMap()) {
  36248. let [generatedCSS, generatedMap] = map.generate();
  36249. if (generatedCSS) {
  36250. this.result.css = generatedCSS;
  36251. }
  36252. if (generatedMap) {
  36253. this.result.map = generatedMap;
  36254. }
  36255. } else {
  36256. map.clearAnnotation();
  36257. this.result.css = map.css;
  36258. }
  36259. }
  36260. async() {
  36261. if (this.error) return Promise.reject(this.error)
  36262. return Promise.resolve(this.result)
  36263. }
  36264. catch(onRejected) {
  36265. return this.async().catch(onRejected)
  36266. }
  36267. finally(onFinally) {
  36268. return this.async().then(onFinally, onFinally)
  36269. }
  36270. sync() {
  36271. if (this.error) throw this.error
  36272. return this.result
  36273. }
  36274. then(onFulfilled, onRejected) {
  36275. if (browser$1.env.NODE_ENV !== 'production') {
  36276. if (!('from' in this._opts)) {
  36277. warnOnce(
  36278. 'Without `from` option PostCSS could generate wrong source map ' +
  36279. 'and will not find Browserslist config. Set it to CSS file path ' +
  36280. 'or to `undefined` to prevent this warning.'
  36281. );
  36282. }
  36283. }
  36284. return this.async().then(onFulfilled, onRejected)
  36285. }
  36286. toString() {
  36287. return this._css
  36288. }
  36289. warnings() {
  36290. return []
  36291. }
  36292. }
  36293. noWorkResult = NoWorkResult;
  36294. NoWorkResult.default = NoWorkResult;
  36295. return noWorkResult;
  36296. }
  36297. var processor$1;
  36298. var hasRequiredProcessor$1;
  36299. function requireProcessor$1 () {
  36300. if (hasRequiredProcessor$1) return processor$1;
  36301. hasRequiredProcessor$1 = 1;
  36302. let Document = /*@__PURE__*/ requireDocument();
  36303. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36304. let NoWorkResult = /*@__PURE__*/ requireNoWorkResult();
  36305. let Root = /*@__PURE__*/ requireRoot$1();
  36306. class Processor {
  36307. constructor(plugins = []) {
  36308. this.version = '8.5.6';
  36309. this.plugins = this.normalize(plugins);
  36310. }
  36311. normalize(plugins) {
  36312. let normalized = [];
  36313. for (let i of plugins) {
  36314. if (i.postcss === true) {
  36315. i = i();
  36316. } else if (i.postcss) {
  36317. i = i.postcss;
  36318. }
  36319. if (typeof i === 'object' && Array.isArray(i.plugins)) {
  36320. normalized = normalized.concat(i.plugins);
  36321. } else if (typeof i === 'object' && i.postcssPlugin) {
  36322. normalized.push(i);
  36323. } else if (typeof i === 'function') {
  36324. normalized.push(i);
  36325. } else if (typeof i === 'object' && (i.parse || i.stringify)) {
  36326. if (browser$1.env.NODE_ENV !== 'production') {
  36327. throw new Error(
  36328. 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
  36329. 'one of the syntax/parser/stringifier options as outlined ' +
  36330. 'in your PostCSS runner documentation.'
  36331. )
  36332. }
  36333. } else {
  36334. throw new Error(i + ' is not a PostCSS plugin')
  36335. }
  36336. }
  36337. return normalized
  36338. }
  36339. process(css, opts = {}) {
  36340. if (
  36341. !this.plugins.length &&
  36342. !opts.parser &&
  36343. !opts.stringifier &&
  36344. !opts.syntax
  36345. ) {
  36346. return new NoWorkResult(this, css, opts)
  36347. } else {
  36348. return new LazyResult(this, css, opts)
  36349. }
  36350. }
  36351. use(plugin) {
  36352. this.plugins = this.plugins.concat(this.normalize([plugin]));
  36353. return this
  36354. }
  36355. }
  36356. processor$1 = Processor;
  36357. Processor.default = Processor;
  36358. Root.registerProcessor(Processor);
  36359. Document.registerProcessor(Processor);
  36360. return processor$1;
  36361. }
  36362. var postcss_1;
  36363. var hasRequiredPostcss;
  36364. function requirePostcss () {
  36365. if (hasRequiredPostcss) return postcss_1;
  36366. hasRequiredPostcss = 1;
  36367. let AtRule = /*@__PURE__*/ requireAtRule();
  36368. let Comment = /*@__PURE__*/ requireComment$1();
  36369. let Container = /*@__PURE__*/ requireContainer$1();
  36370. let CssSyntaxError = /*@__PURE__*/ requireCssSyntaxError();
  36371. let Declaration = /*@__PURE__*/ requireDeclaration();
  36372. let Document = /*@__PURE__*/ requireDocument();
  36373. let fromJSON = /*@__PURE__*/ requireFromJSON();
  36374. let Input = /*@__PURE__*/ requireInput();
  36375. let LazyResult = /*@__PURE__*/ requireLazyResult();
  36376. let list = /*@__PURE__*/ requireList();
  36377. let Node = /*@__PURE__*/ requireNode$2();
  36378. let parse = /*@__PURE__*/ requireParse();
  36379. let Processor = /*@__PURE__*/ requireProcessor$1();
  36380. let Result = /*@__PURE__*/ requireResult();
  36381. let Root = /*@__PURE__*/ requireRoot$1();
  36382. let Rule = /*@__PURE__*/ requireRule();
  36383. let stringify = /*@__PURE__*/ requireStringify();
  36384. let Warning = /*@__PURE__*/ requireWarning();
  36385. function postcss(...plugins) {
  36386. if (plugins.length === 1 && Array.isArray(plugins[0])) {
  36387. plugins = plugins[0];
  36388. }
  36389. return new Processor(plugins)
  36390. }
  36391. postcss.plugin = function plugin(name, initializer) {
  36392. let warningPrinted = false;
  36393. function creator(...args) {
  36394. // eslint-disable-next-line no-console
  36395. if (console && console.warn && !warningPrinted) {
  36396. warningPrinted = true;
  36397. // eslint-disable-next-line no-console
  36398. console.warn(
  36399. name +
  36400. ': postcss.plugin was deprecated. Migration guide:\n' +
  36401. 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
  36402. );
  36403. if (browser$1.env.LANG && browser$1.env.LANG.startsWith('cn')) {
  36404. /* c8 ignore next 7 */
  36405. // eslint-disable-next-line no-console
  36406. console.warn(
  36407. name +
  36408. ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
  36409. 'https://www.w3ctech.com/topic/2226'
  36410. );
  36411. }
  36412. }
  36413. let transformer = initializer(...args);
  36414. transformer.postcssPlugin = name;
  36415. transformer.postcssVersion = new Processor().version;
  36416. return transformer
  36417. }
  36418. let cache;
  36419. Object.defineProperty(creator, 'postcss', {
  36420. get() {
  36421. if (!cache) cache = creator();
  36422. return cache
  36423. }
  36424. });
  36425. creator.process = function (css, processOpts, pluginOpts) {
  36426. return postcss([creator(pluginOpts)]).process(css, processOpts)
  36427. };
  36428. return creator
  36429. };
  36430. postcss.stringify = stringify;
  36431. postcss.parse = parse;
  36432. postcss.fromJSON = fromJSON;
  36433. postcss.list = list;
  36434. postcss.comment = defaults => new Comment(defaults);
  36435. postcss.atRule = defaults => new AtRule(defaults);
  36436. postcss.decl = defaults => new Declaration(defaults);
  36437. postcss.rule = defaults => new Rule(defaults);
  36438. postcss.root = defaults => new Root(defaults);
  36439. postcss.document = defaults => new Document(defaults);
  36440. postcss.CssSyntaxError = CssSyntaxError;
  36441. postcss.Declaration = Declaration;
  36442. postcss.Container = Container;
  36443. postcss.Processor = Processor;
  36444. postcss.Document = Document;
  36445. postcss.Comment = Comment;
  36446. postcss.Warning = Warning;
  36447. postcss.AtRule = AtRule;
  36448. postcss.Result = Result;
  36449. postcss.Input = Input;
  36450. postcss.Rule = Rule;
  36451. postcss.Root = Root;
  36452. postcss.Node = Node;
  36453. LazyResult.registerPostcss(postcss);
  36454. postcss_1 = postcss;
  36455. postcss.default = postcss;
  36456. return postcss_1;
  36457. }
  36458. var postcssExports = /*@__PURE__*/ requirePostcss();
  36459. var postcss = /*@__PURE__*/getDefaultExportFromCjs(postcssExports);
  36460. postcss.stringify;
  36461. postcss.fromJSON;
  36462. postcss.plugin;
  36463. postcss.parse;
  36464. postcss.list;
  36465. postcss.document;
  36466. postcss.comment;
  36467. postcss.atRule;
  36468. postcss.rule;
  36469. postcss.decl;
  36470. postcss.root;
  36471. postcss.CssSyntaxError;
  36472. postcss.Declaration;
  36473. postcss.Container;
  36474. postcss.Processor;
  36475. postcss.Document;
  36476. postcss.Comment;
  36477. postcss.Warning;
  36478. postcss.AtRule;
  36479. postcss.Result;
  36480. postcss.Input;
  36481. const Rule = postcss.Rule;
  36482. postcss.Root;
  36483. postcss.Node;
  36484. const trimPlugin = () => {
  36485. return {
  36486. postcssPlugin: "vue-sfc-trim",
  36487. Once(root) {
  36488. root.walk(({ type, raws }) => {
  36489. if (type === "rule" || type === "atrule") {
  36490. if (raws.before) raws.before = "\n";
  36491. if ("after" in raws && raws.after) raws.after = "\n";
  36492. }
  36493. });
  36494. }
  36495. };
  36496. };
  36497. trimPlugin.postcss = true;
  36498. var dist = {exports: {}};
  36499. var processor = {exports: {}};
  36500. var parser = {exports: {}};
  36501. var root = {exports: {}};
  36502. var container = {exports: {}};
  36503. var node$1 = {exports: {}};
  36504. var util$1 = {};
  36505. var unesc = {exports: {}};
  36506. var hasRequiredUnesc;
  36507. function requireUnesc () {
  36508. if (hasRequiredUnesc) return unesc.exports;
  36509. hasRequiredUnesc = 1;
  36510. (function (module, exports) {
  36511. exports.__esModule = true;
  36512. exports["default"] = unesc;
  36513. // Many thanks for this post which made this migration much easier.
  36514. // https://mathiasbynens.be/notes/css-escapes
  36515. /**
  36516. *
  36517. * @param {string} str
  36518. * @returns {[string, number]|undefined}
  36519. */
  36520. function gobbleHex(str) {
  36521. var lower = str.toLowerCase();
  36522. var hex = '';
  36523. var spaceTerminated = false;
  36524. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  36525. var code = lower.charCodeAt(i);
  36526. // check to see if we are dealing with a valid hex char [a-f|0-9]
  36527. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
  36528. // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  36529. spaceTerminated = code === 32;
  36530. if (!valid) {
  36531. break;
  36532. }
  36533. hex += lower[i];
  36534. }
  36535. if (hex.length === 0) {
  36536. return undefined;
  36537. }
  36538. var codePoint = parseInt(hex, 16);
  36539. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
  36540. // Add special case for
  36541. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  36542. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  36543. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  36544. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  36545. }
  36546. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  36547. }
  36548. var CONTAINS_ESCAPE = /\\/;
  36549. function unesc(str) {
  36550. var needToProcess = CONTAINS_ESCAPE.test(str);
  36551. if (!needToProcess) {
  36552. return str;
  36553. }
  36554. var ret = "";
  36555. for (var i = 0; i < str.length; i++) {
  36556. if (str[i] === "\\") {
  36557. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  36558. if (gobbled !== undefined) {
  36559. ret += gobbled[0];
  36560. i += gobbled[1];
  36561. continue;
  36562. }
  36563. // Retain a pair of \\ if double escaped `\\\\`
  36564. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  36565. if (str[i + 1] === "\\") {
  36566. ret += "\\";
  36567. i++;
  36568. continue;
  36569. }
  36570. // if \\ is at the end of the string retain it
  36571. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  36572. if (str.length === i + 1) {
  36573. ret += str[i];
  36574. }
  36575. continue;
  36576. }
  36577. ret += str[i];
  36578. }
  36579. return ret;
  36580. }
  36581. module.exports = exports.default;
  36582. } (unesc, unesc.exports));
  36583. return unesc.exports;
  36584. }
  36585. var getProp = {exports: {}};
  36586. var hasRequiredGetProp;
  36587. function requireGetProp () {
  36588. if (hasRequiredGetProp) return getProp.exports;
  36589. hasRequiredGetProp = 1;
  36590. (function (module, exports) {
  36591. exports.__esModule = true;
  36592. exports["default"] = getProp;
  36593. function getProp(obj) {
  36594. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36595. props[_key - 1] = arguments[_key];
  36596. }
  36597. while (props.length > 0) {
  36598. var prop = props.shift();
  36599. if (!obj[prop]) {
  36600. return undefined;
  36601. }
  36602. obj = obj[prop];
  36603. }
  36604. return obj;
  36605. }
  36606. module.exports = exports.default;
  36607. } (getProp, getProp.exports));
  36608. return getProp.exports;
  36609. }
  36610. var ensureObject = {exports: {}};
  36611. var hasRequiredEnsureObject;
  36612. function requireEnsureObject () {
  36613. if (hasRequiredEnsureObject) return ensureObject.exports;
  36614. hasRequiredEnsureObject = 1;
  36615. (function (module, exports) {
  36616. exports.__esModule = true;
  36617. exports["default"] = ensureObject;
  36618. function ensureObject(obj) {
  36619. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36620. props[_key - 1] = arguments[_key];
  36621. }
  36622. while (props.length > 0) {
  36623. var prop = props.shift();
  36624. if (!obj[prop]) {
  36625. obj[prop] = {};
  36626. }
  36627. obj = obj[prop];
  36628. }
  36629. }
  36630. module.exports = exports.default;
  36631. } (ensureObject, ensureObject.exports));
  36632. return ensureObject.exports;
  36633. }
  36634. var stripComments = {exports: {}};
  36635. var hasRequiredStripComments;
  36636. function requireStripComments () {
  36637. if (hasRequiredStripComments) return stripComments.exports;
  36638. hasRequiredStripComments = 1;
  36639. (function (module, exports) {
  36640. exports.__esModule = true;
  36641. exports["default"] = stripComments;
  36642. function stripComments(str) {
  36643. var s = "";
  36644. var commentStart = str.indexOf("/*");
  36645. var lastEnd = 0;
  36646. while (commentStart >= 0) {
  36647. s = s + str.slice(lastEnd, commentStart);
  36648. var commentEnd = str.indexOf("*/", commentStart + 2);
  36649. if (commentEnd < 0) {
  36650. return s;
  36651. }
  36652. lastEnd = commentEnd + 2;
  36653. commentStart = str.indexOf("/*", lastEnd);
  36654. }
  36655. s = s + str.slice(lastEnd);
  36656. return s;
  36657. }
  36658. module.exports = exports.default;
  36659. } (stripComments, stripComments.exports));
  36660. return stripComments.exports;
  36661. }
  36662. var hasRequiredUtil$1;
  36663. function requireUtil$1 () {
  36664. if (hasRequiredUtil$1) return util$1;
  36665. hasRequiredUtil$1 = 1;
  36666. util$1.__esModule = true;
  36667. util$1.unesc = util$1.stripComments = util$1.getProp = util$1.ensureObject = void 0;
  36668. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  36669. util$1.unesc = _unesc["default"];
  36670. var _getProp = _interopRequireDefault(/*@__PURE__*/ requireGetProp());
  36671. util$1.getProp = _getProp["default"];
  36672. var _ensureObject = _interopRequireDefault(/*@__PURE__*/ requireEnsureObject());
  36673. util$1.ensureObject = _ensureObject["default"];
  36674. var _stripComments = _interopRequireDefault(/*@__PURE__*/ requireStripComments());
  36675. util$1.stripComments = _stripComments["default"];
  36676. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36677. return util$1;
  36678. }
  36679. var hasRequiredNode$1;
  36680. function requireNode$1 () {
  36681. if (hasRequiredNode$1) return node$1.exports;
  36682. hasRequiredNode$1 = 1;
  36683. (function (module, exports) {
  36684. exports.__esModule = true;
  36685. exports["default"] = void 0;
  36686. var _util = /*@__PURE__*/ requireUtil$1();
  36687. 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); } }
  36688. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36689. var cloneNode = function cloneNode(obj, parent) {
  36690. if (typeof obj !== 'object' || obj === null) {
  36691. return obj;
  36692. }
  36693. var cloned = new obj.constructor();
  36694. for (var i in obj) {
  36695. if (!obj.hasOwnProperty(i)) {
  36696. continue;
  36697. }
  36698. var value = obj[i];
  36699. var type = typeof value;
  36700. if (i === 'parent' && type === 'object') {
  36701. if (parent) {
  36702. cloned[i] = parent;
  36703. }
  36704. } else if (value instanceof Array) {
  36705. cloned[i] = value.map(function (j) {
  36706. return cloneNode(j, cloned);
  36707. });
  36708. } else {
  36709. cloned[i] = cloneNode(value, cloned);
  36710. }
  36711. }
  36712. return cloned;
  36713. };
  36714. var Node = /*#__PURE__*/function () {
  36715. function Node(opts) {
  36716. if (opts === void 0) {
  36717. opts = {};
  36718. }
  36719. Object.assign(this, opts);
  36720. this.spaces = this.spaces || {};
  36721. this.spaces.before = this.spaces.before || '';
  36722. this.spaces.after = this.spaces.after || '';
  36723. }
  36724. var _proto = Node.prototype;
  36725. _proto.remove = function remove() {
  36726. if (this.parent) {
  36727. this.parent.removeChild(this);
  36728. }
  36729. this.parent = undefined;
  36730. return this;
  36731. };
  36732. _proto.replaceWith = function replaceWith() {
  36733. if (this.parent) {
  36734. for (var index in arguments) {
  36735. this.parent.insertBefore(this, arguments[index]);
  36736. }
  36737. this.remove();
  36738. }
  36739. return this;
  36740. };
  36741. _proto.next = function next() {
  36742. return this.parent.at(this.parent.index(this) + 1);
  36743. };
  36744. _proto.prev = function prev() {
  36745. return this.parent.at(this.parent.index(this) - 1);
  36746. };
  36747. _proto.clone = function clone(overrides) {
  36748. if (overrides === void 0) {
  36749. overrides = {};
  36750. }
  36751. var cloned = cloneNode(this);
  36752. for (var name in overrides) {
  36753. cloned[name] = overrides[name];
  36754. }
  36755. return cloned;
  36756. }
  36757. /**
  36758. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36759. * This allows non standard syntax to be appended to an existing property
  36760. * by specifying the escaped value. By specifying the escaped value,
  36761. * illegal characters are allowed to be directly inserted into css output.
  36762. * @param {string} name the property to set
  36763. * @param {any} value the unescaped value of the property
  36764. * @param {string} valueEscaped optional. the escaped value of the property.
  36765. */;
  36766. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  36767. if (!this.raws) {
  36768. this.raws = {};
  36769. }
  36770. var originalValue = this[name];
  36771. var originalEscaped = this.raws[name];
  36772. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  36773. if (originalEscaped || valueEscaped !== value) {
  36774. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  36775. } else {
  36776. delete this.raws[name]; // delete any escaped value that was created by the setter.
  36777. }
  36778. }
  36779. /**
  36780. * Some non-standard syntax doesn't follow normal escaping rules for css.
  36781. * This allows the escaped value to be specified directly, allowing illegal
  36782. * characters to be directly inserted into css output.
  36783. * @param {string} name the property to set
  36784. * @param {any} value the unescaped value of the property
  36785. * @param {string} valueEscaped the escaped value of the property.
  36786. */;
  36787. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  36788. if (!this.raws) {
  36789. this.raws = {};
  36790. }
  36791. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36792. this.raws[name] = valueEscaped;
  36793. }
  36794. /**
  36795. * When you want a value to passed through to CSS directly. This method
  36796. * deletes the corresponding raw value causing the stringifier to fallback
  36797. * to the unescaped value.
  36798. * @param {string} name the property to set.
  36799. * @param {any} value The value that is both escaped and unescaped.
  36800. */;
  36801. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  36802. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  36803. if (this.raws) {
  36804. delete this.raws[name];
  36805. }
  36806. }
  36807. /**
  36808. *
  36809. * @param {number} line The number (starting with 1)
  36810. * @param {number} column The column number (starting with 1)
  36811. */;
  36812. _proto.isAtPosition = function isAtPosition(line, column) {
  36813. if (this.source && this.source.start && this.source.end) {
  36814. if (this.source.start.line > line) {
  36815. return false;
  36816. }
  36817. if (this.source.end.line < line) {
  36818. return false;
  36819. }
  36820. if (this.source.start.line === line && this.source.start.column > column) {
  36821. return false;
  36822. }
  36823. if (this.source.end.line === line && this.source.end.column < column) {
  36824. return false;
  36825. }
  36826. return true;
  36827. }
  36828. return undefined;
  36829. };
  36830. _proto.stringifyProperty = function stringifyProperty(name) {
  36831. return this.raws && this.raws[name] || this[name];
  36832. };
  36833. _proto.valueToString = function valueToString() {
  36834. return String(this.stringifyProperty("value"));
  36835. };
  36836. _proto.toString = function toString() {
  36837. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  36838. };
  36839. _createClass(Node, [{
  36840. key: "rawSpaceBefore",
  36841. get: function get() {
  36842. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  36843. if (rawSpace === undefined) {
  36844. rawSpace = this.spaces && this.spaces.before;
  36845. }
  36846. return rawSpace || "";
  36847. },
  36848. set: function set(raw) {
  36849. (0, _util.ensureObject)(this, "raws", "spaces");
  36850. this.raws.spaces.before = raw;
  36851. }
  36852. }, {
  36853. key: "rawSpaceAfter",
  36854. get: function get() {
  36855. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  36856. if (rawSpace === undefined) {
  36857. rawSpace = this.spaces.after;
  36858. }
  36859. return rawSpace || "";
  36860. },
  36861. set: function set(raw) {
  36862. (0, _util.ensureObject)(this, "raws", "spaces");
  36863. this.raws.spaces.after = raw;
  36864. }
  36865. }]);
  36866. return Node;
  36867. }();
  36868. exports["default"] = Node;
  36869. module.exports = exports.default;
  36870. } (node$1, node$1.exports));
  36871. return node$1.exports;
  36872. }
  36873. var types = {};
  36874. var hasRequiredTypes;
  36875. function requireTypes () {
  36876. if (hasRequiredTypes) return types;
  36877. hasRequiredTypes = 1;
  36878. types.__esModule = true;
  36879. 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;
  36880. var TAG = 'tag';
  36881. types.TAG = TAG;
  36882. var STRING = 'string';
  36883. types.STRING = STRING;
  36884. var SELECTOR = 'selector';
  36885. types.SELECTOR = SELECTOR;
  36886. var ROOT = 'root';
  36887. types.ROOT = ROOT;
  36888. var PSEUDO = 'pseudo';
  36889. types.PSEUDO = PSEUDO;
  36890. var NESTING = 'nesting';
  36891. types.NESTING = NESTING;
  36892. var ID = 'id';
  36893. types.ID = ID;
  36894. var COMMENT = 'comment';
  36895. types.COMMENT = COMMENT;
  36896. var COMBINATOR = 'combinator';
  36897. types.COMBINATOR = COMBINATOR;
  36898. var CLASS = 'class';
  36899. types.CLASS = CLASS;
  36900. var ATTRIBUTE = 'attribute';
  36901. types.ATTRIBUTE = ATTRIBUTE;
  36902. var UNIVERSAL = 'universal';
  36903. types.UNIVERSAL = UNIVERSAL;
  36904. return types;
  36905. }
  36906. var hasRequiredContainer;
  36907. function requireContainer () {
  36908. if (hasRequiredContainer) return container.exports;
  36909. hasRequiredContainer = 1;
  36910. (function (module, exports) {
  36911. exports.__esModule = true;
  36912. exports["default"] = void 0;
  36913. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  36914. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  36915. 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); }
  36916. 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; }
  36917. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  36918. 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."); }
  36919. 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); }
  36920. 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; }
  36921. 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); } }
  36922. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  36923. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  36924. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  36925. var Container = /*#__PURE__*/function (_Node) {
  36926. _inheritsLoose(Container, _Node);
  36927. function Container(opts) {
  36928. var _this;
  36929. _this = _Node.call(this, opts) || this;
  36930. if (!_this.nodes) {
  36931. _this.nodes = [];
  36932. }
  36933. return _this;
  36934. }
  36935. var _proto = Container.prototype;
  36936. _proto.append = function append(selector) {
  36937. selector.parent = this;
  36938. this.nodes.push(selector);
  36939. return this;
  36940. };
  36941. _proto.prepend = function prepend(selector) {
  36942. selector.parent = this;
  36943. this.nodes.unshift(selector);
  36944. for (var id in this.indexes) {
  36945. this.indexes[id]++;
  36946. }
  36947. return this;
  36948. };
  36949. _proto.at = function at(index) {
  36950. return this.nodes[index];
  36951. };
  36952. _proto.index = function index(child) {
  36953. if (typeof child === 'number') {
  36954. return child;
  36955. }
  36956. return this.nodes.indexOf(child);
  36957. };
  36958. _proto.removeChild = function removeChild(child) {
  36959. child = this.index(child);
  36960. this.at(child).parent = undefined;
  36961. this.nodes.splice(child, 1);
  36962. var index;
  36963. for (var id in this.indexes) {
  36964. index = this.indexes[id];
  36965. if (index >= child) {
  36966. this.indexes[id] = index - 1;
  36967. }
  36968. }
  36969. return this;
  36970. };
  36971. _proto.removeAll = function removeAll() {
  36972. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  36973. var node = _step.value;
  36974. node.parent = undefined;
  36975. }
  36976. this.nodes = [];
  36977. return this;
  36978. };
  36979. _proto.empty = function empty() {
  36980. return this.removeAll();
  36981. };
  36982. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  36983. var _this$nodes;
  36984. newNode.parent = this;
  36985. var oldIndex = this.index(oldNode);
  36986. var resetNode = [];
  36987. for (var i = 2; i < arguments.length; i++) {
  36988. resetNode.push(arguments[i]);
  36989. }
  36990. (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
  36991. newNode.parent = this;
  36992. var index;
  36993. for (var id in this.indexes) {
  36994. index = this.indexes[id];
  36995. if (oldIndex < index) {
  36996. this.indexes[id] = index + arguments.length - 1;
  36997. }
  36998. }
  36999. return this;
  37000. };
  37001. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  37002. var _this$nodes2;
  37003. newNode.parent = this;
  37004. var oldIndex = this.index(oldNode);
  37005. var resetNode = [];
  37006. for (var i = 2; i < arguments.length; i++) {
  37007. resetNode.push(arguments[i]);
  37008. }
  37009. (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
  37010. newNode.parent = this;
  37011. var index;
  37012. for (var id in this.indexes) {
  37013. index = this.indexes[id];
  37014. if (index >= oldIndex) {
  37015. this.indexes[id] = index + arguments.length - 1;
  37016. }
  37017. }
  37018. return this;
  37019. };
  37020. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  37021. var found = undefined;
  37022. this.each(function (node) {
  37023. if (node.atPosition) {
  37024. var foundChild = node.atPosition(line, col);
  37025. if (foundChild) {
  37026. found = foundChild;
  37027. return false;
  37028. }
  37029. } else if (node.isAtPosition(line, col)) {
  37030. found = node;
  37031. return false;
  37032. }
  37033. });
  37034. return found;
  37035. }
  37036. /**
  37037. * Return the most specific node at the line and column number given.
  37038. * The source location is based on the original parsed location, locations aren't
  37039. * updated as selector nodes are mutated.
  37040. *
  37041. * Note that this location is relative to the location of the first character
  37042. * of the selector, and not the location of the selector in the overall document
  37043. * when used in conjunction with postcss.
  37044. *
  37045. * If not found, returns undefined.
  37046. * @param {number} line The line number of the node to find. (1-based index)
  37047. * @param {number} col The column number of the node to find. (1-based index)
  37048. */;
  37049. _proto.atPosition = function atPosition(line, col) {
  37050. if (this.isAtPosition(line, col)) {
  37051. return this._findChildAtPosition(line, col) || this;
  37052. } else {
  37053. return undefined;
  37054. }
  37055. };
  37056. _proto._inferEndPosition = function _inferEndPosition() {
  37057. if (this.last && this.last.source && this.last.source.end) {
  37058. this.source = this.source || {};
  37059. this.source.end = this.source.end || {};
  37060. Object.assign(this.source.end, this.last.source.end);
  37061. }
  37062. };
  37063. _proto.each = function each(callback) {
  37064. if (!this.lastEach) {
  37065. this.lastEach = 0;
  37066. }
  37067. if (!this.indexes) {
  37068. this.indexes = {};
  37069. }
  37070. this.lastEach++;
  37071. var id = this.lastEach;
  37072. this.indexes[id] = 0;
  37073. if (!this.length) {
  37074. return undefined;
  37075. }
  37076. var index, result;
  37077. while (this.indexes[id] < this.length) {
  37078. index = this.indexes[id];
  37079. result = callback(this.at(index), index);
  37080. if (result === false) {
  37081. break;
  37082. }
  37083. this.indexes[id] += 1;
  37084. }
  37085. delete this.indexes[id];
  37086. if (result === false) {
  37087. return false;
  37088. }
  37089. };
  37090. _proto.walk = function walk(callback) {
  37091. return this.each(function (node, i) {
  37092. var result = callback(node, i);
  37093. if (result !== false && node.length) {
  37094. result = node.walk(callback);
  37095. }
  37096. if (result === false) {
  37097. return false;
  37098. }
  37099. });
  37100. };
  37101. _proto.walkAttributes = function walkAttributes(callback) {
  37102. var _this2 = this;
  37103. return this.walk(function (selector) {
  37104. if (selector.type === types.ATTRIBUTE) {
  37105. return callback.call(_this2, selector);
  37106. }
  37107. });
  37108. };
  37109. _proto.walkClasses = function walkClasses(callback) {
  37110. var _this3 = this;
  37111. return this.walk(function (selector) {
  37112. if (selector.type === types.CLASS) {
  37113. return callback.call(_this3, selector);
  37114. }
  37115. });
  37116. };
  37117. _proto.walkCombinators = function walkCombinators(callback) {
  37118. var _this4 = this;
  37119. return this.walk(function (selector) {
  37120. if (selector.type === types.COMBINATOR) {
  37121. return callback.call(_this4, selector);
  37122. }
  37123. });
  37124. };
  37125. _proto.walkComments = function walkComments(callback) {
  37126. var _this5 = this;
  37127. return this.walk(function (selector) {
  37128. if (selector.type === types.COMMENT) {
  37129. return callback.call(_this5, selector);
  37130. }
  37131. });
  37132. };
  37133. _proto.walkIds = function walkIds(callback) {
  37134. var _this6 = this;
  37135. return this.walk(function (selector) {
  37136. if (selector.type === types.ID) {
  37137. return callback.call(_this6, selector);
  37138. }
  37139. });
  37140. };
  37141. _proto.walkNesting = function walkNesting(callback) {
  37142. var _this7 = this;
  37143. return this.walk(function (selector) {
  37144. if (selector.type === types.NESTING) {
  37145. return callback.call(_this7, selector);
  37146. }
  37147. });
  37148. };
  37149. _proto.walkPseudos = function walkPseudos(callback) {
  37150. var _this8 = this;
  37151. return this.walk(function (selector) {
  37152. if (selector.type === types.PSEUDO) {
  37153. return callback.call(_this8, selector);
  37154. }
  37155. });
  37156. };
  37157. _proto.walkTags = function walkTags(callback) {
  37158. var _this9 = this;
  37159. return this.walk(function (selector) {
  37160. if (selector.type === types.TAG) {
  37161. return callback.call(_this9, selector);
  37162. }
  37163. });
  37164. };
  37165. _proto.walkUniversals = function walkUniversals(callback) {
  37166. var _this10 = this;
  37167. return this.walk(function (selector) {
  37168. if (selector.type === types.UNIVERSAL) {
  37169. return callback.call(_this10, selector);
  37170. }
  37171. });
  37172. };
  37173. _proto.split = function split(callback) {
  37174. var _this11 = this;
  37175. var current = [];
  37176. return this.reduce(function (memo, node, index) {
  37177. var split = callback.call(_this11, node);
  37178. current.push(node);
  37179. if (split) {
  37180. memo.push(current);
  37181. current = [];
  37182. } else if (index === _this11.length - 1) {
  37183. memo.push(current);
  37184. }
  37185. return memo;
  37186. }, []);
  37187. };
  37188. _proto.map = function map(callback) {
  37189. return this.nodes.map(callback);
  37190. };
  37191. _proto.reduce = function reduce(callback, memo) {
  37192. return this.nodes.reduce(callback, memo);
  37193. };
  37194. _proto.every = function every(callback) {
  37195. return this.nodes.every(callback);
  37196. };
  37197. _proto.some = function some(callback) {
  37198. return this.nodes.some(callback);
  37199. };
  37200. _proto.filter = function filter(callback) {
  37201. return this.nodes.filter(callback);
  37202. };
  37203. _proto.sort = function sort(callback) {
  37204. return this.nodes.sort(callback);
  37205. };
  37206. _proto.toString = function toString() {
  37207. return this.map(String).join('');
  37208. };
  37209. _createClass(Container, [{
  37210. key: "first",
  37211. get: function get() {
  37212. return this.at(0);
  37213. }
  37214. }, {
  37215. key: "last",
  37216. get: function get() {
  37217. return this.at(this.length - 1);
  37218. }
  37219. }, {
  37220. key: "length",
  37221. get: function get() {
  37222. return this.nodes.length;
  37223. }
  37224. }]);
  37225. return Container;
  37226. }(_node["default"]);
  37227. exports["default"] = Container;
  37228. module.exports = exports.default;
  37229. } (container, container.exports));
  37230. return container.exports;
  37231. }
  37232. var hasRequiredRoot;
  37233. function requireRoot () {
  37234. if (hasRequiredRoot) return root.exports;
  37235. hasRequiredRoot = 1;
  37236. (function (module, exports) {
  37237. exports.__esModule = true;
  37238. exports["default"] = void 0;
  37239. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37240. var _types = /*@__PURE__*/ requireTypes();
  37241. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37242. 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); } }
  37243. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37244. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37245. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37246. var Root = /*#__PURE__*/function (_Container) {
  37247. _inheritsLoose(Root, _Container);
  37248. function Root(opts) {
  37249. var _this;
  37250. _this = _Container.call(this, opts) || this;
  37251. _this.type = _types.ROOT;
  37252. return _this;
  37253. }
  37254. var _proto = Root.prototype;
  37255. _proto.toString = function toString() {
  37256. var str = this.reduce(function (memo, selector) {
  37257. memo.push(String(selector));
  37258. return memo;
  37259. }, []).join(',');
  37260. return this.trailingComma ? str + ',' : str;
  37261. };
  37262. _proto.error = function error(message, options) {
  37263. if (this._error) {
  37264. return this._error(message, options);
  37265. } else {
  37266. return new Error(message);
  37267. }
  37268. };
  37269. _createClass(Root, [{
  37270. key: "errorGenerator",
  37271. set: function set(handler) {
  37272. this._error = handler;
  37273. }
  37274. }]);
  37275. return Root;
  37276. }(_container["default"]);
  37277. exports["default"] = Root;
  37278. module.exports = exports.default;
  37279. } (root, root.exports));
  37280. return root.exports;
  37281. }
  37282. var selector = {exports: {}};
  37283. var hasRequiredSelector;
  37284. function requireSelector () {
  37285. if (hasRequiredSelector) return selector.exports;
  37286. hasRequiredSelector = 1;
  37287. (function (module, exports) {
  37288. exports.__esModule = true;
  37289. exports["default"] = void 0;
  37290. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37291. var _types = /*@__PURE__*/ requireTypes();
  37292. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37293. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37294. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37295. var Selector = /*#__PURE__*/function (_Container) {
  37296. _inheritsLoose(Selector, _Container);
  37297. function Selector(opts) {
  37298. var _this;
  37299. _this = _Container.call(this, opts) || this;
  37300. _this.type = _types.SELECTOR;
  37301. return _this;
  37302. }
  37303. return Selector;
  37304. }(_container["default"]);
  37305. exports["default"] = Selector;
  37306. module.exports = exports.default;
  37307. } (selector, selector.exports));
  37308. return selector.exports;
  37309. }
  37310. var className = {exports: {}};
  37311. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  37312. var cssesc_1;
  37313. var hasRequiredCssesc;
  37314. function requireCssesc () {
  37315. if (hasRequiredCssesc) return cssesc_1;
  37316. hasRequiredCssesc = 1;
  37317. var object = {};
  37318. var hasOwnProperty = object.hasOwnProperty;
  37319. var merge = function merge(options, defaults) {
  37320. if (!options) {
  37321. return defaults;
  37322. }
  37323. var result = {};
  37324. for (var key in defaults) {
  37325. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  37326. // only recognized option names are used.
  37327. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  37328. }
  37329. return result;
  37330. };
  37331. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  37332. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  37333. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
  37334. // https://mathiasbynens.be/notes/css-escapes#css
  37335. var cssesc = function cssesc(string, options) {
  37336. options = merge(options, cssesc.options);
  37337. if (options.quotes != 'single' && options.quotes != 'double') {
  37338. options.quotes = 'single';
  37339. }
  37340. var quote = options.quotes == 'double' ? '"' : '\'';
  37341. var isIdentifier = options.isIdentifier;
  37342. var firstChar = string.charAt(0);
  37343. var output = '';
  37344. var counter = 0;
  37345. var length = string.length;
  37346. while (counter < length) {
  37347. var character = string.charAt(counter++);
  37348. var codePoint = character.charCodeAt();
  37349. var value = void 0;
  37350. // If it’s not a printable ASCII character…
  37351. if (codePoint < 0x20 || codePoint > 0x7E) {
  37352. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  37353. // It’s a high surrogate, and there is a next character.
  37354. var extra = string.charCodeAt(counter++);
  37355. if ((extra & 0xFC00) == 0xDC00) {
  37356. // next character is low surrogate
  37357. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  37358. } else {
  37359. // It’s an unmatched surrogate; only append this code unit, in case
  37360. // the next code unit is the high surrogate of a surrogate pair.
  37361. counter--;
  37362. }
  37363. }
  37364. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37365. } else {
  37366. if (options.escapeEverything) {
  37367. if (regexAnySingleEscape.test(character)) {
  37368. value = '\\' + character;
  37369. } else {
  37370. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37371. }
  37372. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  37373. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  37374. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  37375. value = '\\' + character;
  37376. } else {
  37377. value = character;
  37378. }
  37379. }
  37380. output += value;
  37381. }
  37382. if (isIdentifier) {
  37383. if (/^-[-\d]/.test(output)) {
  37384. output = '\\-' + output.slice(1);
  37385. } else if (/\d/.test(firstChar)) {
  37386. output = '\\3' + firstChar + ' ' + output.slice(1);
  37387. }
  37388. }
  37389. // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  37390. // since they’re redundant. Note that this is only possible if the escape
  37391. // sequence isn’t preceded by an odd number of backslashes.
  37392. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  37393. if ($1 && $1.length % 2) {
  37394. // It’s not safe to remove the space, so don’t.
  37395. return $0;
  37396. }
  37397. // Strip the space.
  37398. return ($1 || '') + $2;
  37399. });
  37400. if (!isIdentifier && options.wrap) {
  37401. return quote + output + quote;
  37402. }
  37403. return output;
  37404. };
  37405. // Expose default options (so they can be overridden globally).
  37406. cssesc.options = {
  37407. 'escapeEverything': false,
  37408. 'isIdentifier': false,
  37409. 'quotes': 'single',
  37410. 'wrap': false
  37411. };
  37412. cssesc.version = '3.0.0';
  37413. cssesc_1 = cssesc;
  37414. return cssesc_1;
  37415. }
  37416. var hasRequiredClassName;
  37417. function requireClassName () {
  37418. if (hasRequiredClassName) return className.exports;
  37419. hasRequiredClassName = 1;
  37420. (function (module, exports) {
  37421. exports.__esModule = true;
  37422. exports["default"] = void 0;
  37423. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37424. var _util = /*@__PURE__*/ requireUtil$1();
  37425. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37426. var _types = /*@__PURE__*/ requireTypes();
  37427. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37428. 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); } }
  37429. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37430. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37431. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37432. var ClassName = /*#__PURE__*/function (_Node) {
  37433. _inheritsLoose(ClassName, _Node);
  37434. function ClassName(opts) {
  37435. var _this;
  37436. _this = _Node.call(this, opts) || this;
  37437. _this.type = _types.CLASS;
  37438. _this._constructed = true;
  37439. return _this;
  37440. }
  37441. var _proto = ClassName.prototype;
  37442. _proto.valueToString = function valueToString() {
  37443. return '.' + _Node.prototype.valueToString.call(this);
  37444. };
  37445. _createClass(ClassName, [{
  37446. key: "value",
  37447. get: function get() {
  37448. return this._value;
  37449. },
  37450. set: function set(v) {
  37451. if (this._constructed) {
  37452. var escaped = (0, _cssesc["default"])(v, {
  37453. isIdentifier: true
  37454. });
  37455. if (escaped !== v) {
  37456. (0, _util.ensureObject)(this, "raws");
  37457. this.raws.value = escaped;
  37458. } else if (this.raws) {
  37459. delete this.raws.value;
  37460. }
  37461. }
  37462. this._value = v;
  37463. }
  37464. }]);
  37465. return ClassName;
  37466. }(_node["default"]);
  37467. exports["default"] = ClassName;
  37468. module.exports = exports.default;
  37469. } (className, className.exports));
  37470. return className.exports;
  37471. }
  37472. var comment = {exports: {}};
  37473. var hasRequiredComment;
  37474. function requireComment () {
  37475. if (hasRequiredComment) return comment.exports;
  37476. hasRequiredComment = 1;
  37477. (function (module, exports) {
  37478. exports.__esModule = true;
  37479. exports["default"] = void 0;
  37480. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37481. var _types = /*@__PURE__*/ requireTypes();
  37482. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37483. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37484. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37485. var Comment = /*#__PURE__*/function (_Node) {
  37486. _inheritsLoose(Comment, _Node);
  37487. function Comment(opts) {
  37488. var _this;
  37489. _this = _Node.call(this, opts) || this;
  37490. _this.type = _types.COMMENT;
  37491. return _this;
  37492. }
  37493. return Comment;
  37494. }(_node["default"]);
  37495. exports["default"] = Comment;
  37496. module.exports = exports.default;
  37497. } (comment, comment.exports));
  37498. return comment.exports;
  37499. }
  37500. var id = {exports: {}};
  37501. var hasRequiredId;
  37502. function requireId () {
  37503. if (hasRequiredId) return id.exports;
  37504. hasRequiredId = 1;
  37505. (function (module, exports) {
  37506. exports.__esModule = true;
  37507. exports["default"] = void 0;
  37508. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37509. var _types = /*@__PURE__*/ requireTypes();
  37510. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37511. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37512. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37513. var ID = /*#__PURE__*/function (_Node) {
  37514. _inheritsLoose(ID, _Node);
  37515. function ID(opts) {
  37516. var _this;
  37517. _this = _Node.call(this, opts) || this;
  37518. _this.type = _types.ID;
  37519. return _this;
  37520. }
  37521. var _proto = ID.prototype;
  37522. _proto.valueToString = function valueToString() {
  37523. return '#' + _Node.prototype.valueToString.call(this);
  37524. };
  37525. return ID;
  37526. }(_node["default"]);
  37527. exports["default"] = ID;
  37528. module.exports = exports.default;
  37529. } (id, id.exports));
  37530. return id.exports;
  37531. }
  37532. var tag = {exports: {}};
  37533. var namespace = {exports: {}};
  37534. var hasRequiredNamespace;
  37535. function requireNamespace () {
  37536. if (hasRequiredNamespace) return namespace.exports;
  37537. hasRequiredNamespace = 1;
  37538. (function (module, exports) {
  37539. exports.__esModule = true;
  37540. exports["default"] = void 0;
  37541. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37542. var _util = /*@__PURE__*/ requireUtil$1();
  37543. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37544. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37545. 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); } }
  37546. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37547. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37548. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37549. var Namespace = /*#__PURE__*/function (_Node) {
  37550. _inheritsLoose(Namespace, _Node);
  37551. function Namespace() {
  37552. return _Node.apply(this, arguments) || this;
  37553. }
  37554. var _proto = Namespace.prototype;
  37555. _proto.qualifiedName = function qualifiedName(value) {
  37556. if (this.namespace) {
  37557. return this.namespaceString + "|" + value;
  37558. } else {
  37559. return value;
  37560. }
  37561. };
  37562. _proto.valueToString = function valueToString() {
  37563. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  37564. };
  37565. _createClass(Namespace, [{
  37566. key: "namespace",
  37567. get: function get() {
  37568. return this._namespace;
  37569. },
  37570. set: function set(namespace) {
  37571. if (namespace === true || namespace === "*" || namespace === "&") {
  37572. this._namespace = namespace;
  37573. if (this.raws) {
  37574. delete this.raws.namespace;
  37575. }
  37576. return;
  37577. }
  37578. var escaped = (0, _cssesc["default"])(namespace, {
  37579. isIdentifier: true
  37580. });
  37581. this._namespace = namespace;
  37582. if (escaped !== namespace) {
  37583. (0, _util.ensureObject)(this, "raws");
  37584. this.raws.namespace = escaped;
  37585. } else if (this.raws) {
  37586. delete this.raws.namespace;
  37587. }
  37588. }
  37589. }, {
  37590. key: "ns",
  37591. get: function get() {
  37592. return this._namespace;
  37593. },
  37594. set: function set(namespace) {
  37595. this.namespace = namespace;
  37596. }
  37597. }, {
  37598. key: "namespaceString",
  37599. get: function get() {
  37600. if (this.namespace) {
  37601. var ns = this.stringifyProperty("namespace");
  37602. if (ns === true) {
  37603. return '';
  37604. } else {
  37605. return ns;
  37606. }
  37607. } else {
  37608. return '';
  37609. }
  37610. }
  37611. }]);
  37612. return Namespace;
  37613. }(_node["default"]);
  37614. exports["default"] = Namespace;
  37615. module.exports = exports.default;
  37616. } (namespace, namespace.exports));
  37617. return namespace.exports;
  37618. }
  37619. var hasRequiredTag;
  37620. function requireTag () {
  37621. if (hasRequiredTag) return tag.exports;
  37622. hasRequiredTag = 1;
  37623. (function (module, exports) {
  37624. exports.__esModule = true;
  37625. exports["default"] = void 0;
  37626. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37627. var _types = /*@__PURE__*/ requireTypes();
  37628. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37629. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37630. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37631. var Tag = /*#__PURE__*/function (_Namespace) {
  37632. _inheritsLoose(Tag, _Namespace);
  37633. function Tag(opts) {
  37634. var _this;
  37635. _this = _Namespace.call(this, opts) || this;
  37636. _this.type = _types.TAG;
  37637. return _this;
  37638. }
  37639. return Tag;
  37640. }(_namespace["default"]);
  37641. exports["default"] = Tag;
  37642. module.exports = exports.default;
  37643. } (tag, tag.exports));
  37644. return tag.exports;
  37645. }
  37646. var string = {exports: {}};
  37647. var hasRequiredString;
  37648. function requireString () {
  37649. if (hasRequiredString) return string.exports;
  37650. hasRequiredString = 1;
  37651. (function (module, exports) {
  37652. exports.__esModule = true;
  37653. exports["default"] = void 0;
  37654. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  37655. var _types = /*@__PURE__*/ requireTypes();
  37656. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37657. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37658. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37659. var String = /*#__PURE__*/function (_Node) {
  37660. _inheritsLoose(String, _Node);
  37661. function String(opts) {
  37662. var _this;
  37663. _this = _Node.call(this, opts) || this;
  37664. _this.type = _types.STRING;
  37665. return _this;
  37666. }
  37667. return String;
  37668. }(_node["default"]);
  37669. exports["default"] = String;
  37670. module.exports = exports.default;
  37671. } (string, string.exports));
  37672. return string.exports;
  37673. }
  37674. var pseudo = {exports: {}};
  37675. var hasRequiredPseudo;
  37676. function requirePseudo () {
  37677. if (hasRequiredPseudo) return pseudo.exports;
  37678. hasRequiredPseudo = 1;
  37679. (function (module, exports) {
  37680. exports.__esModule = true;
  37681. exports["default"] = void 0;
  37682. var _container = _interopRequireDefault(/*@__PURE__*/ requireContainer());
  37683. var _types = /*@__PURE__*/ requireTypes();
  37684. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37685. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37686. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37687. var Pseudo = /*#__PURE__*/function (_Container) {
  37688. _inheritsLoose(Pseudo, _Container);
  37689. function Pseudo(opts) {
  37690. var _this;
  37691. _this = _Container.call(this, opts) || this;
  37692. _this.type = _types.PSEUDO;
  37693. return _this;
  37694. }
  37695. var _proto = Pseudo.prototype;
  37696. _proto.toString = function toString() {
  37697. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  37698. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  37699. };
  37700. return Pseudo;
  37701. }(_container["default"]);
  37702. exports["default"] = Pseudo;
  37703. module.exports = exports.default;
  37704. } (pseudo, pseudo.exports));
  37705. return pseudo.exports;
  37706. }
  37707. var attribute = {};
  37708. var node;
  37709. var hasRequiredNode;
  37710. function requireNode () {
  37711. if (hasRequiredNode) return node;
  37712. hasRequiredNode = 1;
  37713. /**
  37714. * For Node.js, simply re-export the core `util.deprecate` function.
  37715. */
  37716. node = require$$0.deprecate;
  37717. return node;
  37718. }
  37719. var hasRequiredAttribute;
  37720. function requireAttribute () {
  37721. if (hasRequiredAttribute) return attribute;
  37722. hasRequiredAttribute = 1;
  37723. (function (exports) {
  37724. exports.__esModule = true;
  37725. exports["default"] = void 0;
  37726. exports.unescapeValue = unescapeValue;
  37727. var _cssesc = _interopRequireDefault(/*@__PURE__*/ requireCssesc());
  37728. var _unesc = _interopRequireDefault(/*@__PURE__*/ requireUnesc());
  37729. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  37730. var _types = /*@__PURE__*/ requireTypes();
  37731. var _CSSESC_QUOTE_OPTIONS;
  37732. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  37733. 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); } }
  37734. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  37735. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  37736. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  37737. var deprecate = /*@__PURE__*/ requireNode();
  37738. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  37739. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  37740. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  37741. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  37742. function unescapeValue(value) {
  37743. var deprecatedUsage = false;
  37744. var quoteMark = null;
  37745. var unescaped = value;
  37746. var m = unescaped.match(WRAPPED_IN_QUOTES);
  37747. if (m) {
  37748. quoteMark = m[1];
  37749. unescaped = m[2];
  37750. }
  37751. unescaped = (0, _unesc["default"])(unescaped);
  37752. if (unescaped !== value) {
  37753. deprecatedUsage = true;
  37754. }
  37755. return {
  37756. deprecatedUsage: deprecatedUsage,
  37757. unescaped: unescaped,
  37758. quoteMark: quoteMark
  37759. };
  37760. }
  37761. function handleDeprecatedContructorOpts(opts) {
  37762. if (opts.quoteMark !== undefined) {
  37763. return opts;
  37764. }
  37765. if (opts.value === undefined) {
  37766. return opts;
  37767. }
  37768. warnOfDeprecatedConstructor();
  37769. var _unescapeValue = unescapeValue(opts.value),
  37770. quoteMark = _unescapeValue.quoteMark,
  37771. unescaped = _unescapeValue.unescaped;
  37772. if (!opts.raws) {
  37773. opts.raws = {};
  37774. }
  37775. if (opts.raws.value === undefined) {
  37776. opts.raws.value = opts.value;
  37777. }
  37778. opts.value = unescaped;
  37779. opts.quoteMark = quoteMark;
  37780. return opts;
  37781. }
  37782. var Attribute = /*#__PURE__*/function (_Namespace) {
  37783. _inheritsLoose(Attribute, _Namespace);
  37784. function Attribute(opts) {
  37785. var _this;
  37786. if (opts === void 0) {
  37787. opts = {};
  37788. }
  37789. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  37790. _this.type = _types.ATTRIBUTE;
  37791. _this.raws = _this.raws || {};
  37792. Object.defineProperty(_this.raws, 'unquoted', {
  37793. get: deprecate(function () {
  37794. return _this.value;
  37795. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  37796. set: deprecate(function () {
  37797. return _this.value;
  37798. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  37799. });
  37800. _this._constructed = true;
  37801. return _this;
  37802. }
  37803. /**
  37804. * Returns the Attribute's value quoted such that it would be legal to use
  37805. * in the value of a css file. The original value's quotation setting
  37806. * used for stringification is left unchanged. See `setValue(value, options)`
  37807. * if you want to control the quote settings of a new value for the attribute.
  37808. *
  37809. * You can also change the quotation used for the current value by setting quoteMark.
  37810. *
  37811. * Options:
  37812. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  37813. * option is not set, the original value for quoteMark will be used. If
  37814. * indeterminate, a double quote is used. The legal values are:
  37815. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  37816. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  37817. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  37818. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  37819. * over the quoteMark option value.
  37820. * * smart {boolean} - if true, will select a quote mark based on the value
  37821. * and the other options specified here. See the `smartQuoteMark()`
  37822. * method.
  37823. **/
  37824. var _proto = Attribute.prototype;
  37825. _proto.getQuotedValue = function getQuotedValue(options) {
  37826. if (options === void 0) {
  37827. options = {};
  37828. }
  37829. var quoteMark = this._determineQuoteMark(options);
  37830. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  37831. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  37832. return escaped;
  37833. };
  37834. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  37835. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  37836. }
  37837. /**
  37838. * Set the unescaped value with the specified quotation options. The value
  37839. * provided must not include any wrapping quote marks -- those quotes will
  37840. * be interpreted as part of the value and escaped accordingly.
  37841. */;
  37842. _proto.setValue = function setValue(value, options) {
  37843. if (options === void 0) {
  37844. options = {};
  37845. }
  37846. this._value = value;
  37847. this._quoteMark = this._determineQuoteMark(options);
  37848. this._syncRawValue();
  37849. }
  37850. /**
  37851. * Intelligently select a quoteMark value based on the value's contents. If
  37852. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  37853. * mark will be picked that minimizes the number of escapes.
  37854. *
  37855. * If there's no clear winner, the quote mark from these options is used,
  37856. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  37857. * true). If the quoteMark is unspecified, a double quote is used.
  37858. *
  37859. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  37860. * from the quoteValue method.
  37861. */;
  37862. _proto.smartQuoteMark = function smartQuoteMark(options) {
  37863. var v = this.value;
  37864. var numSingleQuotes = v.replace(/[^']/g, '').length;
  37865. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  37866. if (numSingleQuotes + numDoubleQuotes === 0) {
  37867. var escaped = (0, _cssesc["default"])(v, {
  37868. isIdentifier: true
  37869. });
  37870. if (escaped === v) {
  37871. return Attribute.NO_QUOTE;
  37872. } else {
  37873. var pref = this.preferredQuoteMark(options);
  37874. if (pref === Attribute.NO_QUOTE) {
  37875. // pick a quote mark that isn't none and see if it's smaller
  37876. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  37877. var opts = CSSESC_QUOTE_OPTIONS[quote];
  37878. var quoteValue = (0, _cssesc["default"])(v, opts);
  37879. if (quoteValue.length < escaped.length) {
  37880. return quote;
  37881. }
  37882. }
  37883. return pref;
  37884. }
  37885. } else if (numDoubleQuotes === numSingleQuotes) {
  37886. return this.preferredQuoteMark(options);
  37887. } else if (numDoubleQuotes < numSingleQuotes) {
  37888. return Attribute.DOUBLE_QUOTE;
  37889. } else {
  37890. return Attribute.SINGLE_QUOTE;
  37891. }
  37892. }
  37893. /**
  37894. * Selects the preferred quote mark based on the options and the current quote mark value.
  37895. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  37896. * instead.
  37897. */;
  37898. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  37899. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  37900. if (quoteMark === undefined) {
  37901. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  37902. }
  37903. if (quoteMark === undefined) {
  37904. quoteMark = Attribute.DOUBLE_QUOTE;
  37905. }
  37906. return quoteMark;
  37907. };
  37908. _proto._syncRawValue = function _syncRawValue() {
  37909. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  37910. if (rawValue === this._value) {
  37911. if (this.raws) {
  37912. delete this.raws.value;
  37913. }
  37914. } else {
  37915. this.raws.value = rawValue;
  37916. }
  37917. };
  37918. _proto._handleEscapes = function _handleEscapes(prop, value) {
  37919. if (this._constructed) {
  37920. var escaped = (0, _cssesc["default"])(value, {
  37921. isIdentifier: true
  37922. });
  37923. if (escaped !== value) {
  37924. this.raws[prop] = escaped;
  37925. } else {
  37926. delete this.raws[prop];
  37927. }
  37928. }
  37929. };
  37930. _proto._spacesFor = function _spacesFor(name) {
  37931. var attrSpaces = {
  37932. before: '',
  37933. after: ''
  37934. };
  37935. var spaces = this.spaces[name] || {};
  37936. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  37937. return Object.assign(attrSpaces, spaces, rawSpaces);
  37938. };
  37939. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  37940. if (spaceName === void 0) {
  37941. spaceName = name;
  37942. }
  37943. if (concat === void 0) {
  37944. concat = defaultAttrConcat;
  37945. }
  37946. var attrSpaces = this._spacesFor(spaceName);
  37947. return concat(this.stringifyProperty(name), attrSpaces);
  37948. }
  37949. /**
  37950. * returns the offset of the attribute part specified relative to the
  37951. * start of the node of the output string.
  37952. *
  37953. * * "ns" - alias for "namespace"
  37954. * * "namespace" - the namespace if it exists.
  37955. * * "attribute" - the attribute name
  37956. * * "attributeNS" - the start of the attribute or its namespace
  37957. * * "operator" - the match operator of the attribute
  37958. * * "value" - The value (string or identifier)
  37959. * * "insensitive" - the case insensitivity flag;
  37960. * @param part One of the possible values inside an attribute.
  37961. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  37962. */;
  37963. _proto.offsetOf = function offsetOf(name) {
  37964. var count = 1;
  37965. var attributeSpaces = this._spacesFor("attribute");
  37966. count += attributeSpaces.before.length;
  37967. if (name === "namespace" || name === "ns") {
  37968. return this.namespace ? count : -1;
  37969. }
  37970. if (name === "attributeNS") {
  37971. return count;
  37972. }
  37973. count += this.namespaceString.length;
  37974. if (this.namespace) {
  37975. count += 1;
  37976. }
  37977. if (name === "attribute") {
  37978. return count;
  37979. }
  37980. count += this.stringifyProperty("attribute").length;
  37981. count += attributeSpaces.after.length;
  37982. var operatorSpaces = this._spacesFor("operator");
  37983. count += operatorSpaces.before.length;
  37984. var operator = this.stringifyProperty("operator");
  37985. if (name === "operator") {
  37986. return operator ? count : -1;
  37987. }
  37988. count += operator.length;
  37989. count += operatorSpaces.after.length;
  37990. var valueSpaces = this._spacesFor("value");
  37991. count += valueSpaces.before.length;
  37992. var value = this.stringifyProperty("value");
  37993. if (name === "value") {
  37994. return value ? count : -1;
  37995. }
  37996. count += value.length;
  37997. count += valueSpaces.after.length;
  37998. var insensitiveSpaces = this._spacesFor("insensitive");
  37999. count += insensitiveSpaces.before.length;
  38000. if (name === "insensitive") {
  38001. return this.insensitive ? count : -1;
  38002. }
  38003. return -1;
  38004. };
  38005. _proto.toString = function toString() {
  38006. var _this2 = this;
  38007. var selector = [this.rawSpaceBefore, '['];
  38008. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  38009. if (this.operator && (this.value || this.value === '')) {
  38010. selector.push(this._stringFor('operator'));
  38011. selector.push(this._stringFor('value'));
  38012. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  38013. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  38014. attrSpaces.before = " ";
  38015. }
  38016. return defaultAttrConcat(attrValue, attrSpaces);
  38017. }));
  38018. }
  38019. selector.push(']');
  38020. selector.push(this.rawSpaceAfter);
  38021. return selector.join('');
  38022. };
  38023. _createClass(Attribute, [{
  38024. key: "quoted",
  38025. get: function get() {
  38026. var qm = this.quoteMark;
  38027. return qm === "'" || qm === '"';
  38028. },
  38029. set: function set(value) {
  38030. warnOfDeprecatedQuotedAssignment();
  38031. }
  38032. /**
  38033. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  38034. * returns `null` if the value is not quoted.
  38035. * returns `undefined` if the quotation state is unknown (this can happen when
  38036. * the attribute is constructed without specifying a quote mark.)
  38037. */
  38038. }, {
  38039. key: "quoteMark",
  38040. get: function get() {
  38041. return this._quoteMark;
  38042. }
  38043. /**
  38044. * Set the quote mark to be used by this attribute's value.
  38045. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  38046. * value is updated accordingly.
  38047. *
  38048. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  38049. */,
  38050. set: function set(quoteMark) {
  38051. if (!this._constructed) {
  38052. this._quoteMark = quoteMark;
  38053. return;
  38054. }
  38055. if (this._quoteMark !== quoteMark) {
  38056. this._quoteMark = quoteMark;
  38057. this._syncRawValue();
  38058. }
  38059. }
  38060. }, {
  38061. key: "qualifiedAttribute",
  38062. get: function get() {
  38063. return this.qualifiedName(this.raws.attribute || this.attribute);
  38064. }
  38065. }, {
  38066. key: "insensitiveFlag",
  38067. get: function get() {
  38068. return this.insensitive ? 'i' : '';
  38069. }
  38070. }, {
  38071. key: "value",
  38072. get: function get() {
  38073. return this._value;
  38074. },
  38075. set:
  38076. /**
  38077. * Before 3.0, the value had to be set to an escaped value including any wrapped
  38078. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  38079. * is unescaped during parsing and any quote marks are removed.
  38080. *
  38081. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  38082. * a deprecation warning is raised when the new value contains any characters that would
  38083. * require escaping (including if it contains wrapped quotes).
  38084. *
  38085. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  38086. * how the new value is quoted.
  38087. */
  38088. function set(v) {
  38089. if (this._constructed) {
  38090. var _unescapeValue2 = unescapeValue(v),
  38091. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  38092. unescaped = _unescapeValue2.unescaped,
  38093. quoteMark = _unescapeValue2.quoteMark;
  38094. if (deprecatedUsage) {
  38095. warnOfDeprecatedValueAssignment();
  38096. }
  38097. if (unescaped === this._value && quoteMark === this._quoteMark) {
  38098. return;
  38099. }
  38100. this._value = unescaped;
  38101. this._quoteMark = quoteMark;
  38102. this._syncRawValue();
  38103. } else {
  38104. this._value = v;
  38105. }
  38106. }
  38107. }, {
  38108. key: "insensitive",
  38109. get: function get() {
  38110. return this._insensitive;
  38111. }
  38112. /**
  38113. * Set the case insensitive flag.
  38114. * If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
  38115. * of the attribute is updated accordingly.
  38116. *
  38117. * @param {true | false} insensitive true if the attribute should match case-insensitively.
  38118. */,
  38119. set: function set(insensitive) {
  38120. if (!insensitive) {
  38121. this._insensitive = false;
  38122. // "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
  38123. // When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
  38124. if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
  38125. this.raws.insensitiveFlag = undefined;
  38126. }
  38127. }
  38128. this._insensitive = insensitive;
  38129. }
  38130. }, {
  38131. key: "attribute",
  38132. get: function get() {
  38133. return this._attribute;
  38134. },
  38135. set: function set(name) {
  38136. this._handleEscapes("attribute", name);
  38137. this._attribute = name;
  38138. }
  38139. }]);
  38140. return Attribute;
  38141. }(_namespace["default"]);
  38142. exports["default"] = Attribute;
  38143. Attribute.NO_QUOTE = null;
  38144. Attribute.SINGLE_QUOTE = "'";
  38145. Attribute.DOUBLE_QUOTE = '"';
  38146. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  38147. "'": {
  38148. quotes: 'single',
  38149. wrap: true
  38150. },
  38151. '"': {
  38152. quotes: 'double',
  38153. wrap: true
  38154. }
  38155. }, _CSSESC_QUOTE_OPTIONS[null] = {
  38156. isIdentifier: true
  38157. }, _CSSESC_QUOTE_OPTIONS);
  38158. function defaultAttrConcat(attrValue, attrSpaces) {
  38159. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  38160. }
  38161. } (attribute));
  38162. return attribute;
  38163. }
  38164. var universal = {exports: {}};
  38165. var hasRequiredUniversal;
  38166. function requireUniversal () {
  38167. if (hasRequiredUniversal) return universal.exports;
  38168. hasRequiredUniversal = 1;
  38169. (function (module, exports) {
  38170. exports.__esModule = true;
  38171. exports["default"] = void 0;
  38172. var _namespace = _interopRequireDefault(/*@__PURE__*/ requireNamespace());
  38173. var _types = /*@__PURE__*/ requireTypes();
  38174. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38175. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38176. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38177. var Universal = /*#__PURE__*/function (_Namespace) {
  38178. _inheritsLoose(Universal, _Namespace);
  38179. function Universal(opts) {
  38180. var _this;
  38181. _this = _Namespace.call(this, opts) || this;
  38182. _this.type = _types.UNIVERSAL;
  38183. _this.value = '*';
  38184. return _this;
  38185. }
  38186. return Universal;
  38187. }(_namespace["default"]);
  38188. exports["default"] = Universal;
  38189. module.exports = exports.default;
  38190. } (universal, universal.exports));
  38191. return universal.exports;
  38192. }
  38193. var combinator = {exports: {}};
  38194. var hasRequiredCombinator;
  38195. function requireCombinator () {
  38196. if (hasRequiredCombinator) return combinator.exports;
  38197. hasRequiredCombinator = 1;
  38198. (function (module, exports) {
  38199. exports.__esModule = true;
  38200. exports["default"] = void 0;
  38201. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38202. var _types = /*@__PURE__*/ requireTypes();
  38203. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38204. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38205. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38206. var Combinator = /*#__PURE__*/function (_Node) {
  38207. _inheritsLoose(Combinator, _Node);
  38208. function Combinator(opts) {
  38209. var _this;
  38210. _this = _Node.call(this, opts) || this;
  38211. _this.type = _types.COMBINATOR;
  38212. return _this;
  38213. }
  38214. return Combinator;
  38215. }(_node["default"]);
  38216. exports["default"] = Combinator;
  38217. module.exports = exports.default;
  38218. } (combinator, combinator.exports));
  38219. return combinator.exports;
  38220. }
  38221. var nesting = {exports: {}};
  38222. var hasRequiredNesting;
  38223. function requireNesting () {
  38224. if (hasRequiredNesting) return nesting.exports;
  38225. hasRequiredNesting = 1;
  38226. (function (module, exports) {
  38227. exports.__esModule = true;
  38228. exports["default"] = void 0;
  38229. var _node = _interopRequireDefault(/*@__PURE__*/ requireNode$1());
  38230. var _types = /*@__PURE__*/ requireTypes();
  38231. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38232. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  38233. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  38234. var Nesting = /*#__PURE__*/function (_Node) {
  38235. _inheritsLoose(Nesting, _Node);
  38236. function Nesting(opts) {
  38237. var _this;
  38238. _this = _Node.call(this, opts) || this;
  38239. _this.type = _types.NESTING;
  38240. _this.value = '&';
  38241. return _this;
  38242. }
  38243. return Nesting;
  38244. }(_node["default"]);
  38245. exports["default"] = Nesting;
  38246. module.exports = exports.default;
  38247. } (nesting, nesting.exports));
  38248. return nesting.exports;
  38249. }
  38250. var sortAscending = {exports: {}};
  38251. var hasRequiredSortAscending;
  38252. function requireSortAscending () {
  38253. if (hasRequiredSortAscending) return sortAscending.exports;
  38254. hasRequiredSortAscending = 1;
  38255. (function (module, exports) {
  38256. exports.__esModule = true;
  38257. exports["default"] = sortAscending;
  38258. function sortAscending(list) {
  38259. return list.sort(function (a, b) {
  38260. return a - b;
  38261. });
  38262. }
  38263. module.exports = exports.default;
  38264. } (sortAscending, sortAscending.exports));
  38265. return sortAscending.exports;
  38266. }
  38267. var tokenize = {};
  38268. var tokenTypes = {};
  38269. var hasRequiredTokenTypes;
  38270. function requireTokenTypes () {
  38271. if (hasRequiredTokenTypes) return tokenTypes;
  38272. hasRequiredTokenTypes = 1;
  38273. tokenTypes.__esModule = true;
  38274. 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;
  38275. var ampersand = 38; // `&`.charCodeAt(0);
  38276. tokenTypes.ampersand = ampersand;
  38277. var asterisk = 42; // `*`.charCodeAt(0);
  38278. tokenTypes.asterisk = asterisk;
  38279. var at = 64; // `@`.charCodeAt(0);
  38280. tokenTypes.at = at;
  38281. var comma = 44; // `,`.charCodeAt(0);
  38282. tokenTypes.comma = comma;
  38283. var colon = 58; // `:`.charCodeAt(0);
  38284. tokenTypes.colon = colon;
  38285. var semicolon = 59; // `;`.charCodeAt(0);
  38286. tokenTypes.semicolon = semicolon;
  38287. var openParenthesis = 40; // `(`.charCodeAt(0);
  38288. tokenTypes.openParenthesis = openParenthesis;
  38289. var closeParenthesis = 41; // `)`.charCodeAt(0);
  38290. tokenTypes.closeParenthesis = closeParenthesis;
  38291. var openSquare = 91; // `[`.charCodeAt(0);
  38292. tokenTypes.openSquare = openSquare;
  38293. var closeSquare = 93; // `]`.charCodeAt(0);
  38294. tokenTypes.closeSquare = closeSquare;
  38295. var dollar = 36; // `$`.charCodeAt(0);
  38296. tokenTypes.dollar = dollar;
  38297. var tilde = 126; // `~`.charCodeAt(0);
  38298. tokenTypes.tilde = tilde;
  38299. var caret = 94; // `^`.charCodeAt(0);
  38300. tokenTypes.caret = caret;
  38301. var plus = 43; // `+`.charCodeAt(0);
  38302. tokenTypes.plus = plus;
  38303. var equals = 61; // `=`.charCodeAt(0);
  38304. tokenTypes.equals = equals;
  38305. var pipe = 124; // `|`.charCodeAt(0);
  38306. tokenTypes.pipe = pipe;
  38307. var greaterThan = 62; // `>`.charCodeAt(0);
  38308. tokenTypes.greaterThan = greaterThan;
  38309. var space = 32; // ` `.charCodeAt(0);
  38310. tokenTypes.space = space;
  38311. var singleQuote = 39; // `'`.charCodeAt(0);
  38312. tokenTypes.singleQuote = singleQuote;
  38313. var doubleQuote = 34; // `"`.charCodeAt(0);
  38314. tokenTypes.doubleQuote = doubleQuote;
  38315. var slash = 47; // `/`.charCodeAt(0);
  38316. tokenTypes.slash = slash;
  38317. var bang = 33; // `!`.charCodeAt(0);
  38318. tokenTypes.bang = bang;
  38319. var backslash = 92; // '\\'.charCodeAt(0);
  38320. tokenTypes.backslash = backslash;
  38321. var cr = 13; // '\r'.charCodeAt(0);
  38322. tokenTypes.cr = cr;
  38323. var feed = 12; // '\f'.charCodeAt(0);
  38324. tokenTypes.feed = feed;
  38325. var newline = 10; // '\n'.charCodeAt(0);
  38326. tokenTypes.newline = newline;
  38327. var tab = 9; // '\t'.charCodeAt(0);
  38328. // Expose aliases primarily for readability.
  38329. tokenTypes.tab = tab;
  38330. var str = singleQuote;
  38331. // No good single character representation!
  38332. tokenTypes.str = str;
  38333. var comment = -1;
  38334. tokenTypes.comment = comment;
  38335. var word = -2;
  38336. tokenTypes.word = word;
  38337. var combinator = -3;
  38338. tokenTypes.combinator = combinator;
  38339. return tokenTypes;
  38340. }
  38341. var hasRequiredTokenize;
  38342. function requireTokenize () {
  38343. if (hasRequiredTokenize) return tokenize;
  38344. hasRequiredTokenize = 1;
  38345. (function (exports) {
  38346. exports.__esModule = true;
  38347. exports.FIELDS = void 0;
  38348. exports["default"] = tokenize;
  38349. var t = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38350. var _unescapable, _wordDelimiters;
  38351. 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); }
  38352. 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; }
  38353. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  38354. 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);
  38355. var hex = {};
  38356. var hexChars = "0123456789abcdefABCDEF";
  38357. for (var i = 0; i < hexChars.length; i++) {
  38358. hex[hexChars.charCodeAt(i)] = true;
  38359. }
  38360. /**
  38361. * Returns the last index of the bar css word
  38362. * @param {string} css The string in which the word begins
  38363. * @param {number} start The index into the string where word's first letter occurs
  38364. */
  38365. function consumeWord(css, start) {
  38366. var next = start;
  38367. var code;
  38368. do {
  38369. code = css.charCodeAt(next);
  38370. if (wordDelimiters[code]) {
  38371. return next - 1;
  38372. } else if (code === t.backslash) {
  38373. next = consumeEscape(css, next) + 1;
  38374. } else {
  38375. // All other characters are part of the word
  38376. next++;
  38377. }
  38378. } while (next < css.length);
  38379. return next - 1;
  38380. }
  38381. /**
  38382. * Returns the last index of the escape sequence
  38383. * @param {string} css The string in which the sequence begins
  38384. * @param {number} start The index into the string where escape character (`\`) occurs.
  38385. */
  38386. function consumeEscape(css, start) {
  38387. var next = start;
  38388. var code = css.charCodeAt(next + 1);
  38389. if (unescapable[code]) ; else if (hex[code]) {
  38390. var hexDigits = 0;
  38391. // consume up to 6 hex chars
  38392. do {
  38393. next++;
  38394. hexDigits++;
  38395. code = css.charCodeAt(next + 1);
  38396. } while (hex[code] && hexDigits < 6);
  38397. // if fewer than 6 hex chars, a trailing space ends the escape
  38398. if (hexDigits < 6 && code === t.space) {
  38399. next++;
  38400. }
  38401. } else {
  38402. // the next char is part of the current word
  38403. next++;
  38404. }
  38405. return next;
  38406. }
  38407. var FIELDS = {
  38408. TYPE: 0,
  38409. START_LINE: 1,
  38410. START_COL: 2,
  38411. END_LINE: 3,
  38412. END_COL: 4,
  38413. START_POS: 5,
  38414. END_POS: 6
  38415. };
  38416. exports.FIELDS = FIELDS;
  38417. function tokenize(input) {
  38418. var tokens = [];
  38419. var css = input.css.valueOf();
  38420. var _css = css,
  38421. length = _css.length;
  38422. var offset = -1;
  38423. var line = 1;
  38424. var start = 0;
  38425. var end = 0;
  38426. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  38427. function unclosed(what, fix) {
  38428. if (input.safe) {
  38429. // fyi: this is never set to true.
  38430. css += fix;
  38431. next = css.length - 1;
  38432. } else {
  38433. throw input.error('Unclosed ' + what, line, start - offset, start);
  38434. }
  38435. }
  38436. while (start < length) {
  38437. code = css.charCodeAt(start);
  38438. if (code === t.newline) {
  38439. offset = start;
  38440. line += 1;
  38441. }
  38442. switch (code) {
  38443. case t.space:
  38444. case t.tab:
  38445. case t.newline:
  38446. case t.cr:
  38447. case t.feed:
  38448. next = start;
  38449. do {
  38450. next += 1;
  38451. code = css.charCodeAt(next);
  38452. if (code === t.newline) {
  38453. offset = next;
  38454. line += 1;
  38455. }
  38456. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  38457. tokenType = t.space;
  38458. endLine = line;
  38459. endColumn = next - offset - 1;
  38460. end = next;
  38461. break;
  38462. case t.plus:
  38463. case t.greaterThan:
  38464. case t.tilde:
  38465. case t.pipe:
  38466. next = start;
  38467. do {
  38468. next += 1;
  38469. code = css.charCodeAt(next);
  38470. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  38471. tokenType = t.combinator;
  38472. endLine = line;
  38473. endColumn = start - offset;
  38474. end = next;
  38475. break;
  38476. // Consume these characters as single tokens.
  38477. case t.asterisk:
  38478. case t.ampersand:
  38479. case t.bang:
  38480. case t.comma:
  38481. case t.equals:
  38482. case t.dollar:
  38483. case t.caret:
  38484. case t.openSquare:
  38485. case t.closeSquare:
  38486. case t.colon:
  38487. case t.semicolon:
  38488. case t.openParenthesis:
  38489. case t.closeParenthesis:
  38490. next = start;
  38491. tokenType = code;
  38492. endLine = line;
  38493. endColumn = start - offset;
  38494. end = next + 1;
  38495. break;
  38496. case t.singleQuote:
  38497. case t.doubleQuote:
  38498. quote = code === t.singleQuote ? "'" : '"';
  38499. next = start;
  38500. do {
  38501. escaped = false;
  38502. next = css.indexOf(quote, next + 1);
  38503. if (next === -1) {
  38504. unclosed('quote', quote);
  38505. }
  38506. escapePos = next;
  38507. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  38508. escapePos -= 1;
  38509. escaped = !escaped;
  38510. }
  38511. } while (escaped);
  38512. tokenType = t.str;
  38513. endLine = line;
  38514. endColumn = start - offset;
  38515. end = next + 1;
  38516. break;
  38517. default:
  38518. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  38519. next = css.indexOf('*/', start + 2) + 1;
  38520. if (next === 0) {
  38521. unclosed('comment', '*/');
  38522. }
  38523. content = css.slice(start, next + 1);
  38524. lines = content.split('\n');
  38525. last = lines.length - 1;
  38526. if (last > 0) {
  38527. nextLine = line + last;
  38528. nextOffset = next - lines[last].length;
  38529. } else {
  38530. nextLine = line;
  38531. nextOffset = offset;
  38532. }
  38533. tokenType = t.comment;
  38534. line = nextLine;
  38535. endLine = nextLine;
  38536. endColumn = next - nextOffset;
  38537. } else if (code === t.slash) {
  38538. next = start;
  38539. tokenType = code;
  38540. endLine = line;
  38541. endColumn = start - offset;
  38542. end = next + 1;
  38543. } else {
  38544. next = consumeWord(css, start);
  38545. tokenType = t.word;
  38546. endLine = line;
  38547. endColumn = next - offset;
  38548. }
  38549. end = next + 1;
  38550. break;
  38551. }
  38552. // Ensure that the token structure remains consistent
  38553. tokens.push([tokenType,
  38554. // [0] Token type
  38555. line,
  38556. // [1] Starting line
  38557. start - offset,
  38558. // [2] Starting column
  38559. endLine,
  38560. // [3] Ending line
  38561. endColumn,
  38562. // [4] Ending column
  38563. start,
  38564. // [5] Start position / Source index
  38565. end // [6] End position
  38566. ]);
  38567. // Reset offset for the next token
  38568. if (nextOffset) {
  38569. offset = nextOffset;
  38570. nextOffset = null;
  38571. }
  38572. start = end;
  38573. }
  38574. return tokens;
  38575. }
  38576. } (tokenize));
  38577. return tokenize;
  38578. }
  38579. var hasRequiredParser;
  38580. function requireParser () {
  38581. if (hasRequiredParser) return parser.exports;
  38582. hasRequiredParser = 1;
  38583. (function (module, exports) {
  38584. exports.__esModule = true;
  38585. exports["default"] = void 0;
  38586. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  38587. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  38588. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  38589. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  38590. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  38591. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  38592. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  38593. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  38594. var _attribute = _interopRequireWildcard(/*@__PURE__*/ requireAttribute());
  38595. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  38596. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  38597. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  38598. var _sortAscending = _interopRequireDefault(/*@__PURE__*/ requireSortAscending());
  38599. var _tokenize = _interopRequireWildcard(/*@__PURE__*/ requireTokenize());
  38600. var tokens = _interopRequireWildcard(/*@__PURE__*/ requireTokenTypes());
  38601. var types = _interopRequireWildcard(/*@__PURE__*/ requireTypes());
  38602. var _util = /*@__PURE__*/ requireUtil$1();
  38603. var _WHITESPACE_TOKENS, _Object$assign;
  38604. 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); }
  38605. 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; }
  38606. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  38607. 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); } }
  38608. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  38609. 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);
  38610. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  38611. function tokenStart(token) {
  38612. return {
  38613. line: token[_tokenize.FIELDS.START_LINE],
  38614. column: token[_tokenize.FIELDS.START_COL]
  38615. };
  38616. }
  38617. function tokenEnd(token) {
  38618. return {
  38619. line: token[_tokenize.FIELDS.END_LINE],
  38620. column: token[_tokenize.FIELDS.END_COL]
  38621. };
  38622. }
  38623. function getSource(startLine, startColumn, endLine, endColumn) {
  38624. return {
  38625. start: {
  38626. line: startLine,
  38627. column: startColumn
  38628. },
  38629. end: {
  38630. line: endLine,
  38631. column: endColumn
  38632. }
  38633. };
  38634. }
  38635. function getTokenSource(token) {
  38636. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  38637. }
  38638. function getTokenSourceSpan(startToken, endToken) {
  38639. if (!startToken) {
  38640. return undefined;
  38641. }
  38642. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  38643. }
  38644. function unescapeProp(node, prop) {
  38645. var value = node[prop];
  38646. if (typeof value !== "string") {
  38647. return;
  38648. }
  38649. if (value.indexOf("\\") !== -1) {
  38650. (0, _util.ensureObject)(node, 'raws');
  38651. node[prop] = (0, _util.unesc)(value);
  38652. if (node.raws[prop] === undefined) {
  38653. node.raws[prop] = value;
  38654. }
  38655. }
  38656. return node;
  38657. }
  38658. function indexesOf(array, item) {
  38659. var i = -1;
  38660. var indexes = [];
  38661. while ((i = array.indexOf(item, i + 1)) !== -1) {
  38662. indexes.push(i);
  38663. }
  38664. return indexes;
  38665. }
  38666. function uniqs() {
  38667. var list = Array.prototype.concat.apply([], arguments);
  38668. return list.filter(function (item, i) {
  38669. return i === list.indexOf(item);
  38670. });
  38671. }
  38672. var Parser = /*#__PURE__*/function () {
  38673. function Parser(rule, options) {
  38674. if (options === void 0) {
  38675. options = {};
  38676. }
  38677. this.rule = rule;
  38678. this.options = Object.assign({
  38679. lossy: false,
  38680. safe: false
  38681. }, options);
  38682. this.position = 0;
  38683. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  38684. this.tokens = (0, _tokenize["default"])({
  38685. css: this.css,
  38686. error: this._errorGenerator(),
  38687. safe: this.options.safe
  38688. });
  38689. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  38690. this.root = new _root["default"]({
  38691. source: rootSource
  38692. });
  38693. this.root.errorGenerator = this._errorGenerator();
  38694. var selector = new _selector["default"]({
  38695. source: {
  38696. start: {
  38697. line: 1,
  38698. column: 1
  38699. }
  38700. },
  38701. sourceIndex: 0
  38702. });
  38703. this.root.append(selector);
  38704. this.current = selector;
  38705. this.loop();
  38706. }
  38707. var _proto = Parser.prototype;
  38708. _proto._errorGenerator = function _errorGenerator() {
  38709. var _this = this;
  38710. return function (message, errorOptions) {
  38711. if (typeof _this.rule === 'string') {
  38712. return new Error(message);
  38713. }
  38714. return _this.rule.error(message, errorOptions);
  38715. };
  38716. };
  38717. _proto.attribute = function attribute() {
  38718. var attr = [];
  38719. var startingToken = this.currToken;
  38720. this.position++;
  38721. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38722. attr.push(this.currToken);
  38723. this.position++;
  38724. }
  38725. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  38726. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  38727. }
  38728. var len = attr.length;
  38729. var node = {
  38730. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  38731. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  38732. };
  38733. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  38734. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  38735. }
  38736. var pos = 0;
  38737. var spaceBefore = '';
  38738. var commentBefore = '';
  38739. var lastAdded = null;
  38740. var spaceAfterMeaningfulToken = false;
  38741. while (pos < len) {
  38742. var token = attr[pos];
  38743. var content = this.content(token);
  38744. var next = attr[pos + 1];
  38745. switch (token[_tokenize.FIELDS.TYPE]) {
  38746. case tokens.space:
  38747. // if (
  38748. // len === 1 ||
  38749. // pos === 0 && this.content(next) === '|'
  38750. // ) {
  38751. // return this.expected('attribute', token[TOKEN.START_POS], content);
  38752. // }
  38753. spaceAfterMeaningfulToken = true;
  38754. if (this.options.lossy) {
  38755. break;
  38756. }
  38757. if (lastAdded) {
  38758. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  38759. var prevContent = node.spaces[lastAdded].after || '';
  38760. node.spaces[lastAdded].after = prevContent + content;
  38761. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  38762. if (existingComment) {
  38763. node.raws.spaces[lastAdded].after = existingComment + content;
  38764. }
  38765. } else {
  38766. spaceBefore = spaceBefore + content;
  38767. commentBefore = commentBefore + content;
  38768. }
  38769. break;
  38770. case tokens.asterisk:
  38771. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38772. node.operator = content;
  38773. lastAdded = 'operator';
  38774. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  38775. if (spaceBefore) {
  38776. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38777. node.spaces.attribute.before = spaceBefore;
  38778. spaceBefore = '';
  38779. }
  38780. if (commentBefore) {
  38781. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38782. node.raws.spaces.attribute.before = spaceBefore;
  38783. commentBefore = '';
  38784. }
  38785. node.namespace = (node.namespace || "") + content;
  38786. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  38787. if (rawValue) {
  38788. node.raws.namespace += content;
  38789. }
  38790. lastAdded = 'namespace';
  38791. }
  38792. spaceAfterMeaningfulToken = false;
  38793. break;
  38794. case tokens.dollar:
  38795. if (lastAdded === "value") {
  38796. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  38797. node.value += "$";
  38798. if (oldRawValue) {
  38799. node.raws.value = oldRawValue + "$";
  38800. }
  38801. break;
  38802. }
  38803. // Falls through
  38804. case tokens.caret:
  38805. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38806. node.operator = content;
  38807. lastAdded = 'operator';
  38808. }
  38809. spaceAfterMeaningfulToken = false;
  38810. break;
  38811. case tokens.combinator:
  38812. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38813. node.operator = content;
  38814. lastAdded = 'operator';
  38815. }
  38816. if (content !== '|') {
  38817. spaceAfterMeaningfulToken = false;
  38818. break;
  38819. }
  38820. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  38821. node.operator = content;
  38822. lastAdded = 'operator';
  38823. } else if (!node.namespace && !node.attribute) {
  38824. node.namespace = true;
  38825. }
  38826. spaceAfterMeaningfulToken = false;
  38827. break;
  38828. case tokens.word:
  38829. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
  38830. // this look-ahead probably fails with comment nodes involved.
  38831. !node.operator && !node.namespace) {
  38832. node.namespace = content;
  38833. lastAdded = 'namespace';
  38834. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  38835. if (spaceBefore) {
  38836. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  38837. node.spaces.attribute.before = spaceBefore;
  38838. spaceBefore = '';
  38839. }
  38840. if (commentBefore) {
  38841. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  38842. node.raws.spaces.attribute.before = commentBefore;
  38843. commentBefore = '';
  38844. }
  38845. node.attribute = (node.attribute || "") + content;
  38846. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  38847. if (_rawValue) {
  38848. node.raws.attribute += content;
  38849. }
  38850. lastAdded = 'attribute';
  38851. } else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
  38852. var _unescaped = (0, _util.unesc)(content);
  38853. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  38854. var oldValue = node.value || '';
  38855. node.value = oldValue + _unescaped;
  38856. node.quoteMark = null;
  38857. if (_unescaped !== content || _oldRawValue) {
  38858. (0, _util.ensureObject)(node, 'raws');
  38859. node.raws.value = (_oldRawValue || oldValue) + content;
  38860. }
  38861. lastAdded = 'value';
  38862. } else {
  38863. var insensitive = content === 'i' || content === "I";
  38864. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  38865. node.insensitive = insensitive;
  38866. if (!insensitive || content === "I") {
  38867. (0, _util.ensureObject)(node, 'raws');
  38868. node.raws.insensitiveFlag = content;
  38869. }
  38870. lastAdded = 'insensitive';
  38871. if (spaceBefore) {
  38872. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  38873. node.spaces.insensitive.before = spaceBefore;
  38874. spaceBefore = '';
  38875. }
  38876. if (commentBefore) {
  38877. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  38878. node.raws.spaces.insensitive.before = commentBefore;
  38879. commentBefore = '';
  38880. }
  38881. } else if (node.value || node.value === '') {
  38882. lastAdded = 'value';
  38883. node.value += content;
  38884. if (node.raws.value) {
  38885. node.raws.value += content;
  38886. }
  38887. }
  38888. }
  38889. spaceAfterMeaningfulToken = false;
  38890. break;
  38891. case tokens.str:
  38892. if (!node.attribute || !node.operator) {
  38893. return this.error("Expected an attribute followed by an operator preceding the string.", {
  38894. index: token[_tokenize.FIELDS.START_POS]
  38895. });
  38896. }
  38897. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  38898. unescaped = _unescapeValue.unescaped,
  38899. quoteMark = _unescapeValue.quoteMark;
  38900. node.value = unescaped;
  38901. node.quoteMark = quoteMark;
  38902. lastAdded = 'value';
  38903. (0, _util.ensureObject)(node, 'raws');
  38904. node.raws.value = content;
  38905. spaceAfterMeaningfulToken = false;
  38906. break;
  38907. case tokens.equals:
  38908. if (!node.attribute) {
  38909. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  38910. }
  38911. if (node.value) {
  38912. return this.error('Unexpected "=" found; an operator was already defined.', {
  38913. index: token[_tokenize.FIELDS.START_POS]
  38914. });
  38915. }
  38916. node.operator = node.operator ? node.operator + content : content;
  38917. lastAdded = 'operator';
  38918. spaceAfterMeaningfulToken = false;
  38919. break;
  38920. case tokens.comment:
  38921. if (lastAdded) {
  38922. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  38923. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  38924. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  38925. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  38926. node.raws.spaces[lastAdded].after = rawLastComment + content;
  38927. } else {
  38928. var lastValue = node[lastAdded] || '';
  38929. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  38930. (0, _util.ensureObject)(node, 'raws');
  38931. node.raws[lastAdded] = rawLastValue + content;
  38932. }
  38933. } else {
  38934. commentBefore = commentBefore + content;
  38935. }
  38936. break;
  38937. default:
  38938. return this.error("Unexpected \"" + content + "\" found.", {
  38939. index: token[_tokenize.FIELDS.START_POS]
  38940. });
  38941. }
  38942. pos++;
  38943. }
  38944. unescapeProp(node, "attribute");
  38945. unescapeProp(node, "namespace");
  38946. this.newNode(new _attribute["default"](node));
  38947. this.position++;
  38948. }
  38949. /**
  38950. * return a node containing meaningless garbage up to (but not including) the specified token position.
  38951. * if the token position is negative, all remaining tokens are consumed.
  38952. *
  38953. * This returns an array containing a single string node if all whitespace,
  38954. * otherwise an array of comment nodes with space before and after.
  38955. *
  38956. * These tokens are not added to the current selector, the caller can add them or use them to amend
  38957. * a previous node's space metadata.
  38958. *
  38959. * In lossy mode, this returns only comments.
  38960. */;
  38961. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  38962. if (stopPosition < 0) {
  38963. stopPosition = this.tokens.length;
  38964. }
  38965. var startPosition = this.position;
  38966. var nodes = [];
  38967. var space = "";
  38968. var lastComment = undefined;
  38969. do {
  38970. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  38971. if (!this.options.lossy) {
  38972. space += this.content();
  38973. }
  38974. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  38975. var spaces = {};
  38976. if (space) {
  38977. spaces.before = space;
  38978. space = "";
  38979. }
  38980. lastComment = new _comment["default"]({
  38981. value: this.content(),
  38982. source: getTokenSource(this.currToken),
  38983. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  38984. spaces: spaces
  38985. });
  38986. nodes.push(lastComment);
  38987. }
  38988. } while (++this.position < stopPosition);
  38989. if (space) {
  38990. if (lastComment) {
  38991. lastComment.spaces.after = space;
  38992. } else if (!this.options.lossy) {
  38993. var firstToken = this.tokens[startPosition];
  38994. var lastToken = this.tokens[this.position - 1];
  38995. nodes.push(new _string["default"]({
  38996. value: '',
  38997. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  38998. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  38999. spaces: {
  39000. before: space,
  39001. after: ''
  39002. }
  39003. }));
  39004. }
  39005. }
  39006. return nodes;
  39007. }
  39008. /**
  39009. *
  39010. * @param {*} nodes
  39011. */;
  39012. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  39013. var _this2 = this;
  39014. if (requiredSpace === void 0) {
  39015. requiredSpace = false;
  39016. }
  39017. var space = "";
  39018. var rawSpace = "";
  39019. nodes.forEach(function (n) {
  39020. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  39021. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  39022. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  39023. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  39024. });
  39025. if (rawSpace === space) {
  39026. rawSpace = undefined;
  39027. }
  39028. var result = {
  39029. space: space,
  39030. rawSpace: rawSpace
  39031. };
  39032. return result;
  39033. };
  39034. _proto.isNamedCombinator = function isNamedCombinator(position) {
  39035. if (position === void 0) {
  39036. position = this.position;
  39037. }
  39038. 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;
  39039. };
  39040. _proto.namedCombinator = function namedCombinator() {
  39041. if (this.isNamedCombinator()) {
  39042. var nameRaw = this.content(this.tokens[this.position + 1]);
  39043. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  39044. var raws = {};
  39045. if (name !== nameRaw) {
  39046. raws.value = "/" + nameRaw + "/";
  39047. }
  39048. var node = new _combinator["default"]({
  39049. value: "/" + name + "/",
  39050. 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]),
  39051. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  39052. raws: raws
  39053. });
  39054. this.position = this.position + 3;
  39055. return node;
  39056. } else {
  39057. this.unexpected();
  39058. }
  39059. };
  39060. _proto.combinator = function combinator() {
  39061. var _this3 = this;
  39062. if (this.content() === '|') {
  39063. return this.namespace();
  39064. }
  39065. // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  39066. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  39067. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39068. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39069. if (nodes.length > 0) {
  39070. var last = this.current.last;
  39071. if (last) {
  39072. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  39073. space = _this$convertWhitespa.space,
  39074. rawSpace = _this$convertWhitespa.rawSpace;
  39075. if (rawSpace !== undefined) {
  39076. last.rawSpaceAfter += rawSpace;
  39077. }
  39078. last.spaces.after += space;
  39079. } else {
  39080. nodes.forEach(function (n) {
  39081. return _this3.newNode(n);
  39082. });
  39083. }
  39084. }
  39085. return;
  39086. }
  39087. var firstToken = this.currToken;
  39088. var spaceOrDescendantSelectorNodes = undefined;
  39089. if (nextSigTokenPos > this.position) {
  39090. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  39091. }
  39092. var node;
  39093. if (this.isNamedCombinator()) {
  39094. node = this.namedCombinator();
  39095. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  39096. node = new _combinator["default"]({
  39097. value: this.content(),
  39098. source: getTokenSource(this.currToken),
  39099. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  39100. });
  39101. this.position++;
  39102. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  39103. this.unexpected();
  39104. }
  39105. if (node) {
  39106. if (spaceOrDescendantSelectorNodes) {
  39107. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  39108. _space = _this$convertWhitespa2.space,
  39109. _rawSpace = _this$convertWhitespa2.rawSpace;
  39110. node.spaces.before = _space;
  39111. node.rawSpaceBefore = _rawSpace;
  39112. }
  39113. } else {
  39114. // descendant combinator
  39115. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  39116. _space2 = _this$convertWhitespa3.space,
  39117. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  39118. if (!_rawSpace2) {
  39119. _rawSpace2 = _space2;
  39120. }
  39121. var spaces = {};
  39122. var raws = {
  39123. spaces: {}
  39124. };
  39125. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  39126. spaces.before = _space2.slice(0, _space2.length - 1);
  39127. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  39128. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  39129. spaces.after = _space2.slice(1);
  39130. raws.spaces.after = _rawSpace2.slice(1);
  39131. } else {
  39132. raws.value = _rawSpace2;
  39133. }
  39134. node = new _combinator["default"]({
  39135. value: ' ',
  39136. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  39137. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  39138. spaces: spaces,
  39139. raws: raws
  39140. });
  39141. }
  39142. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  39143. node.spaces.after = this.optionalSpace(this.content());
  39144. this.position++;
  39145. }
  39146. return this.newNode(node);
  39147. };
  39148. _proto.comma = function comma() {
  39149. if (this.position === this.tokens.length - 1) {
  39150. this.root.trailingComma = true;
  39151. this.position++;
  39152. return;
  39153. }
  39154. this.current._inferEndPosition();
  39155. var selector = new _selector["default"]({
  39156. source: {
  39157. start: tokenStart(this.tokens[this.position + 1])
  39158. },
  39159. sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
  39160. });
  39161. this.current.parent.append(selector);
  39162. this.current = selector;
  39163. this.position++;
  39164. };
  39165. _proto.comment = function comment() {
  39166. var current = this.currToken;
  39167. this.newNode(new _comment["default"]({
  39168. value: this.content(),
  39169. source: getTokenSource(current),
  39170. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39171. }));
  39172. this.position++;
  39173. };
  39174. _proto.error = function error(message, opts) {
  39175. throw this.root.error(message, opts);
  39176. };
  39177. _proto.missingBackslash = function missingBackslash() {
  39178. return this.error('Expected a backslash preceding the semicolon.', {
  39179. index: this.currToken[_tokenize.FIELDS.START_POS]
  39180. });
  39181. };
  39182. _proto.missingParenthesis = function missingParenthesis() {
  39183. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39184. };
  39185. _proto.missingSquareBracket = function missingSquareBracket() {
  39186. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  39187. };
  39188. _proto.unexpected = function unexpected() {
  39189. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  39190. };
  39191. _proto.unexpectedPipe = function unexpectedPipe() {
  39192. return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
  39193. };
  39194. _proto.namespace = function namespace() {
  39195. var before = this.prevToken && this.content(this.prevToken) || true;
  39196. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39197. this.position++;
  39198. return this.word(before);
  39199. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  39200. this.position++;
  39201. return this.universal(before);
  39202. }
  39203. this.unexpectedPipe();
  39204. };
  39205. _proto.nesting = function nesting() {
  39206. if (this.nextToken) {
  39207. var nextContent = this.content(this.nextToken);
  39208. if (nextContent === "|") {
  39209. this.position++;
  39210. return;
  39211. }
  39212. }
  39213. var current = this.currToken;
  39214. this.newNode(new _nesting["default"]({
  39215. value: this.content(),
  39216. source: getTokenSource(current),
  39217. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39218. }));
  39219. this.position++;
  39220. };
  39221. _proto.parentheses = function parentheses() {
  39222. var last = this.current.last;
  39223. var unbalanced = 1;
  39224. this.position++;
  39225. if (last && last.type === types.PSEUDO) {
  39226. var selector = new _selector["default"]({
  39227. source: {
  39228. start: tokenStart(this.tokens[this.position])
  39229. },
  39230. sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
  39231. });
  39232. var cache = this.current;
  39233. last.append(selector);
  39234. this.current = selector;
  39235. while (this.position < this.tokens.length && unbalanced) {
  39236. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39237. unbalanced++;
  39238. }
  39239. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39240. unbalanced--;
  39241. }
  39242. if (unbalanced) {
  39243. this.parse();
  39244. } else {
  39245. this.current.source.end = tokenEnd(this.currToken);
  39246. this.current.parent.source.end = tokenEnd(this.currToken);
  39247. this.position++;
  39248. }
  39249. }
  39250. this.current = cache;
  39251. } else {
  39252. // I think this case should be an error. It's used to implement a basic parse of media queries
  39253. // but I don't think it's a good idea.
  39254. var parenStart = this.currToken;
  39255. var parenValue = "(";
  39256. var parenEnd;
  39257. while (this.position < this.tokens.length && unbalanced) {
  39258. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39259. unbalanced++;
  39260. }
  39261. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39262. unbalanced--;
  39263. }
  39264. parenEnd = this.currToken;
  39265. parenValue += this.parseParenthesisToken(this.currToken);
  39266. this.position++;
  39267. }
  39268. if (last) {
  39269. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  39270. } else {
  39271. this.newNode(new _string["default"]({
  39272. value: parenValue,
  39273. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  39274. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  39275. }));
  39276. }
  39277. }
  39278. if (unbalanced) {
  39279. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  39280. }
  39281. };
  39282. _proto.pseudo = function pseudo() {
  39283. var _this4 = this;
  39284. var pseudoStr = '';
  39285. var startingToken = this.currToken;
  39286. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  39287. pseudoStr += this.content();
  39288. this.position++;
  39289. }
  39290. if (!this.currToken) {
  39291. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  39292. }
  39293. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  39294. this.splitWord(false, function (first, length) {
  39295. pseudoStr += first;
  39296. _this4.newNode(new _pseudo["default"]({
  39297. value: pseudoStr,
  39298. source: getTokenSourceSpan(startingToken, _this4.currToken),
  39299. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  39300. }));
  39301. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  39302. _this4.error('Misplaced parenthesis.', {
  39303. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  39304. });
  39305. }
  39306. });
  39307. } else {
  39308. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  39309. }
  39310. };
  39311. _proto.space = function space() {
  39312. var content = this.content();
  39313. // Handle space before and after the selector
  39314. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  39315. return node.type === 'comment';
  39316. })) {
  39317. this.spaces = this.optionalSpace(content);
  39318. this.position++;
  39319. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  39320. this.current.last.spaces.after = this.optionalSpace(content);
  39321. this.position++;
  39322. } else {
  39323. this.combinator();
  39324. }
  39325. };
  39326. _proto.string = function string() {
  39327. var current = this.currToken;
  39328. this.newNode(new _string["default"]({
  39329. value: this.content(),
  39330. source: getTokenSource(current),
  39331. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39332. }));
  39333. this.position++;
  39334. };
  39335. _proto.universal = function universal(namespace) {
  39336. var nextToken = this.nextToken;
  39337. if (nextToken && this.content(nextToken) === '|') {
  39338. this.position++;
  39339. return this.namespace();
  39340. }
  39341. var current = this.currToken;
  39342. this.newNode(new _universal["default"]({
  39343. value: this.content(),
  39344. source: getTokenSource(current),
  39345. sourceIndex: current[_tokenize.FIELDS.START_POS]
  39346. }), namespace);
  39347. this.position++;
  39348. };
  39349. _proto.splitWord = function splitWord(namespace, firstCallback) {
  39350. var _this5 = this;
  39351. var nextToken = this.nextToken;
  39352. var word = this.content();
  39353. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  39354. this.position++;
  39355. var current = this.content();
  39356. word += current;
  39357. if (current.lastIndexOf('\\') === current.length - 1) {
  39358. var next = this.nextToken;
  39359. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  39360. word += this.requiredSpace(this.content(next));
  39361. this.position++;
  39362. }
  39363. }
  39364. nextToken = this.nextToken;
  39365. }
  39366. var hasClass = indexesOf(word, '.').filter(function (i) {
  39367. // Allow escaped dot within class name
  39368. var escapedDot = word[i - 1] === '\\';
  39369. // Allow decimal numbers percent in @keyframes
  39370. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  39371. return !escapedDot && !isKeyframesPercent;
  39372. });
  39373. var hasId = indexesOf(word, '#').filter(function (i) {
  39374. return word[i - 1] !== '\\';
  39375. });
  39376. // Eliminate Sass interpolations from the list of id indexes
  39377. var interpolations = indexesOf(word, '#{');
  39378. if (interpolations.length) {
  39379. hasId = hasId.filter(function (hashIndex) {
  39380. return !~interpolations.indexOf(hashIndex);
  39381. });
  39382. }
  39383. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  39384. indices.forEach(function (ind, i) {
  39385. var index = indices[i + 1] || word.length;
  39386. var value = word.slice(ind, index);
  39387. if (i === 0 && firstCallback) {
  39388. return firstCallback.call(_this5, value, indices.length);
  39389. }
  39390. var node;
  39391. var current = _this5.currToken;
  39392. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  39393. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  39394. if (~hasClass.indexOf(ind)) {
  39395. var classNameOpts = {
  39396. value: value.slice(1),
  39397. source: source,
  39398. sourceIndex: sourceIndex
  39399. };
  39400. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  39401. } else if (~hasId.indexOf(ind)) {
  39402. var idOpts = {
  39403. value: value.slice(1),
  39404. source: source,
  39405. sourceIndex: sourceIndex
  39406. };
  39407. node = new _id["default"](unescapeProp(idOpts, "value"));
  39408. } else {
  39409. var tagOpts = {
  39410. value: value,
  39411. source: source,
  39412. sourceIndex: sourceIndex
  39413. };
  39414. unescapeProp(tagOpts, "value");
  39415. node = new _tag["default"](tagOpts);
  39416. }
  39417. _this5.newNode(node, namespace);
  39418. // Ensure that the namespace is used only once
  39419. namespace = null;
  39420. });
  39421. this.position++;
  39422. };
  39423. _proto.word = function word(namespace) {
  39424. var nextToken = this.nextToken;
  39425. if (nextToken && this.content(nextToken) === '|') {
  39426. this.position++;
  39427. return this.namespace();
  39428. }
  39429. return this.splitWord(namespace);
  39430. };
  39431. _proto.loop = function loop() {
  39432. while (this.position < this.tokens.length) {
  39433. this.parse(true);
  39434. }
  39435. this.current._inferEndPosition();
  39436. return this.root;
  39437. };
  39438. _proto.parse = function parse(throwOnParenthesis) {
  39439. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  39440. case tokens.space:
  39441. this.space();
  39442. break;
  39443. case tokens.comment:
  39444. this.comment();
  39445. break;
  39446. case tokens.openParenthesis:
  39447. this.parentheses();
  39448. break;
  39449. case tokens.closeParenthesis:
  39450. if (throwOnParenthesis) {
  39451. this.missingParenthesis();
  39452. }
  39453. break;
  39454. case tokens.openSquare:
  39455. this.attribute();
  39456. break;
  39457. case tokens.dollar:
  39458. case tokens.caret:
  39459. case tokens.equals:
  39460. case tokens.word:
  39461. this.word();
  39462. break;
  39463. case tokens.colon:
  39464. this.pseudo();
  39465. break;
  39466. case tokens.comma:
  39467. this.comma();
  39468. break;
  39469. case tokens.asterisk:
  39470. this.universal();
  39471. break;
  39472. case tokens.ampersand:
  39473. this.nesting();
  39474. break;
  39475. case tokens.slash:
  39476. case tokens.combinator:
  39477. this.combinator();
  39478. break;
  39479. case tokens.str:
  39480. this.string();
  39481. break;
  39482. // These cases throw; no break needed.
  39483. case tokens.closeSquare:
  39484. this.missingSquareBracket();
  39485. case tokens.semicolon:
  39486. this.missingBackslash();
  39487. default:
  39488. this.unexpected();
  39489. }
  39490. }
  39491. /**
  39492. * Helpers
  39493. */;
  39494. _proto.expected = function expected(description, index, found) {
  39495. if (Array.isArray(description)) {
  39496. var last = description.pop();
  39497. description = description.join(', ') + " or " + last;
  39498. }
  39499. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  39500. if (!found) {
  39501. return this.error("Expected " + an + " " + description + ".", {
  39502. index: index
  39503. });
  39504. }
  39505. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  39506. index: index
  39507. });
  39508. };
  39509. _proto.requiredSpace = function requiredSpace(space) {
  39510. return this.options.lossy ? ' ' : space;
  39511. };
  39512. _proto.optionalSpace = function optionalSpace(space) {
  39513. return this.options.lossy ? '' : space;
  39514. };
  39515. _proto.lossySpace = function lossySpace(space, required) {
  39516. if (this.options.lossy) {
  39517. return required ? ' ' : '';
  39518. } else {
  39519. return space;
  39520. }
  39521. };
  39522. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  39523. var content = this.content(token);
  39524. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  39525. return this.requiredSpace(content);
  39526. } else {
  39527. return content;
  39528. }
  39529. };
  39530. _proto.newNode = function newNode(node, namespace) {
  39531. if (namespace) {
  39532. if (/^ +$/.test(namespace)) {
  39533. if (!this.options.lossy) {
  39534. this.spaces = (this.spaces || '') + namespace;
  39535. }
  39536. namespace = true;
  39537. }
  39538. node.namespace = namespace;
  39539. unescapeProp(node, "namespace");
  39540. }
  39541. if (this.spaces) {
  39542. node.spaces.before = this.spaces;
  39543. this.spaces = '';
  39544. }
  39545. return this.current.append(node);
  39546. };
  39547. _proto.content = function content(token) {
  39548. if (token === void 0) {
  39549. token = this.currToken;
  39550. }
  39551. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  39552. };
  39553. /**
  39554. * returns the index of the next non-whitespace, non-comment token.
  39555. * returns -1 if no meaningful token is found.
  39556. */
  39557. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  39558. if (startPosition === void 0) {
  39559. startPosition = this.position + 1;
  39560. }
  39561. var searchPosition = startPosition;
  39562. while (searchPosition < this.tokens.length) {
  39563. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  39564. searchPosition++;
  39565. continue;
  39566. } else {
  39567. return searchPosition;
  39568. }
  39569. }
  39570. return -1;
  39571. };
  39572. _createClass(Parser, [{
  39573. key: "currToken",
  39574. get: function get() {
  39575. return this.tokens[this.position];
  39576. }
  39577. }, {
  39578. key: "nextToken",
  39579. get: function get() {
  39580. return this.tokens[this.position + 1];
  39581. }
  39582. }, {
  39583. key: "prevToken",
  39584. get: function get() {
  39585. return this.tokens[this.position - 1];
  39586. }
  39587. }]);
  39588. return Parser;
  39589. }();
  39590. exports["default"] = Parser;
  39591. module.exports = exports.default;
  39592. } (parser, parser.exports));
  39593. return parser.exports;
  39594. }
  39595. var hasRequiredProcessor;
  39596. function requireProcessor () {
  39597. if (hasRequiredProcessor) return processor.exports;
  39598. hasRequiredProcessor = 1;
  39599. (function (module, exports) {
  39600. exports.__esModule = true;
  39601. exports["default"] = void 0;
  39602. var _parser = _interopRequireDefault(/*@__PURE__*/ requireParser());
  39603. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39604. var Processor = /*#__PURE__*/function () {
  39605. function Processor(func, options) {
  39606. this.func = func || function noop() {};
  39607. this.funcRes = null;
  39608. this.options = options;
  39609. }
  39610. var _proto = Processor.prototype;
  39611. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  39612. if (options === void 0) {
  39613. options = {};
  39614. }
  39615. var merged = Object.assign({}, this.options, options);
  39616. if (merged.updateSelector === false) {
  39617. return false;
  39618. } else {
  39619. return typeof rule !== "string";
  39620. }
  39621. };
  39622. _proto._isLossy = function _isLossy(options) {
  39623. if (options === void 0) {
  39624. options = {};
  39625. }
  39626. var merged = Object.assign({}, this.options, options);
  39627. if (merged.lossless === false) {
  39628. return true;
  39629. } else {
  39630. return false;
  39631. }
  39632. };
  39633. _proto._root = function _root(rule, options) {
  39634. if (options === void 0) {
  39635. options = {};
  39636. }
  39637. var parser = new _parser["default"](rule, this._parseOptions(options));
  39638. return parser.root;
  39639. };
  39640. _proto._parseOptions = function _parseOptions(options) {
  39641. return {
  39642. lossy: this._isLossy(options)
  39643. };
  39644. };
  39645. _proto._run = function _run(rule, options) {
  39646. var _this = this;
  39647. if (options === void 0) {
  39648. options = {};
  39649. }
  39650. return new Promise(function (resolve, reject) {
  39651. try {
  39652. var root = _this._root(rule, options);
  39653. Promise.resolve(_this.func(root)).then(function (transform) {
  39654. var string = undefined;
  39655. if (_this._shouldUpdateSelector(rule, options)) {
  39656. string = root.toString();
  39657. rule.selector = string;
  39658. }
  39659. return {
  39660. transform: transform,
  39661. root: root,
  39662. string: string
  39663. };
  39664. }).then(resolve, reject);
  39665. } catch (e) {
  39666. reject(e);
  39667. return;
  39668. }
  39669. });
  39670. };
  39671. _proto._runSync = function _runSync(rule, options) {
  39672. if (options === void 0) {
  39673. options = {};
  39674. }
  39675. var root = this._root(rule, options);
  39676. var transform = this.func(root);
  39677. if (transform && typeof transform.then === "function") {
  39678. throw new Error("Selector processor returned a promise to a synchronous call.");
  39679. }
  39680. var string = undefined;
  39681. if (options.updateSelector && typeof rule !== "string") {
  39682. string = root.toString();
  39683. rule.selector = string;
  39684. }
  39685. return {
  39686. transform: transform,
  39687. root: root,
  39688. string: string
  39689. };
  39690. }
  39691. /**
  39692. * Process rule into a selector AST.
  39693. *
  39694. * @param rule {postcss.Rule | string} The css selector to be processed
  39695. * @param options The options for processing
  39696. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  39697. */;
  39698. _proto.ast = function ast(rule, options) {
  39699. return this._run(rule, options).then(function (result) {
  39700. return result.root;
  39701. });
  39702. }
  39703. /**
  39704. * Process rule into a selector AST synchronously.
  39705. *
  39706. * @param rule {postcss.Rule | string} The css selector to be processed
  39707. * @param options The options for processing
  39708. * @returns {parser.Root} The AST of the selector after processing it.
  39709. */;
  39710. _proto.astSync = function astSync(rule, options) {
  39711. return this._runSync(rule, options).root;
  39712. }
  39713. /**
  39714. * Process a selector into a transformed value asynchronously
  39715. *
  39716. * @param rule {postcss.Rule | string} The css selector to be processed
  39717. * @param options The options for processing
  39718. * @returns {Promise<any>} The value returned by the processor.
  39719. */;
  39720. _proto.transform = function transform(rule, options) {
  39721. return this._run(rule, options).then(function (result) {
  39722. return result.transform;
  39723. });
  39724. }
  39725. /**
  39726. * Process a selector into a transformed value synchronously.
  39727. *
  39728. * @param rule {postcss.Rule | string} The css selector to be processed
  39729. * @param options The options for processing
  39730. * @returns {any} The value returned by the processor.
  39731. */;
  39732. _proto.transformSync = function transformSync(rule, options) {
  39733. return this._runSync(rule, options).transform;
  39734. }
  39735. /**
  39736. * Process a selector into a new selector string asynchronously.
  39737. *
  39738. * @param rule {postcss.Rule | string} The css selector to be processed
  39739. * @param options The options for processing
  39740. * @returns {string} the selector after processing.
  39741. */;
  39742. _proto.process = function process(rule, options) {
  39743. return this._run(rule, options).then(function (result) {
  39744. return result.string || result.root.toString();
  39745. });
  39746. }
  39747. /**
  39748. * Process a selector into a new selector string synchronously.
  39749. *
  39750. * @param rule {postcss.Rule | string} The css selector to be processed
  39751. * @param options The options for processing
  39752. * @returns {string} the selector after processing.
  39753. */;
  39754. _proto.processSync = function processSync(rule, options) {
  39755. var result = this._runSync(rule, options);
  39756. return result.string || result.root.toString();
  39757. };
  39758. return Processor;
  39759. }();
  39760. exports["default"] = Processor;
  39761. module.exports = exports.default;
  39762. } (processor, processor.exports));
  39763. return processor.exports;
  39764. }
  39765. var selectors = {};
  39766. var constructors = {};
  39767. var hasRequiredConstructors;
  39768. function requireConstructors () {
  39769. if (hasRequiredConstructors) return constructors;
  39770. hasRequiredConstructors = 1;
  39771. constructors.__esModule = true;
  39772. 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;
  39773. var _attribute = _interopRequireDefault(/*@__PURE__*/ requireAttribute());
  39774. var _className = _interopRequireDefault(/*@__PURE__*/ requireClassName());
  39775. var _combinator = _interopRequireDefault(/*@__PURE__*/ requireCombinator());
  39776. var _comment = _interopRequireDefault(/*@__PURE__*/ requireComment());
  39777. var _id = _interopRequireDefault(/*@__PURE__*/ requireId());
  39778. var _nesting = _interopRequireDefault(/*@__PURE__*/ requireNesting());
  39779. var _pseudo = _interopRequireDefault(/*@__PURE__*/ requirePseudo());
  39780. var _root = _interopRequireDefault(/*@__PURE__*/ requireRoot());
  39781. var _selector = _interopRequireDefault(/*@__PURE__*/ requireSelector());
  39782. var _string = _interopRequireDefault(/*@__PURE__*/ requireString());
  39783. var _tag = _interopRequireDefault(/*@__PURE__*/ requireTag());
  39784. var _universal = _interopRequireDefault(/*@__PURE__*/ requireUniversal());
  39785. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39786. var attribute = function attribute(opts) {
  39787. return new _attribute["default"](opts);
  39788. };
  39789. constructors.attribute = attribute;
  39790. var className = function className(opts) {
  39791. return new _className["default"](opts);
  39792. };
  39793. constructors.className = className;
  39794. var combinator = function combinator(opts) {
  39795. return new _combinator["default"](opts);
  39796. };
  39797. constructors.combinator = combinator;
  39798. var comment = function comment(opts) {
  39799. return new _comment["default"](opts);
  39800. };
  39801. constructors.comment = comment;
  39802. var id = function id(opts) {
  39803. return new _id["default"](opts);
  39804. };
  39805. constructors.id = id;
  39806. var nesting = function nesting(opts) {
  39807. return new _nesting["default"](opts);
  39808. };
  39809. constructors.nesting = nesting;
  39810. var pseudo = function pseudo(opts) {
  39811. return new _pseudo["default"](opts);
  39812. };
  39813. constructors.pseudo = pseudo;
  39814. var root = function root(opts) {
  39815. return new _root["default"](opts);
  39816. };
  39817. constructors.root = root;
  39818. var selector = function selector(opts) {
  39819. return new _selector["default"](opts);
  39820. };
  39821. constructors.selector = selector;
  39822. var string = function string(opts) {
  39823. return new _string["default"](opts);
  39824. };
  39825. constructors.string = string;
  39826. var tag = function tag(opts) {
  39827. return new _tag["default"](opts);
  39828. };
  39829. constructors.tag = tag;
  39830. var universal = function universal(opts) {
  39831. return new _universal["default"](opts);
  39832. };
  39833. constructors.universal = universal;
  39834. return constructors;
  39835. }
  39836. var guards = {};
  39837. var hasRequiredGuards;
  39838. function requireGuards () {
  39839. if (hasRequiredGuards) return guards;
  39840. hasRequiredGuards = 1;
  39841. guards.__esModule = true;
  39842. guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  39843. guards.isContainer = isContainer;
  39844. guards.isIdentifier = void 0;
  39845. guards.isNamespace = isNamespace;
  39846. guards.isNesting = void 0;
  39847. guards.isNode = isNode;
  39848. guards.isPseudo = void 0;
  39849. guards.isPseudoClass = isPseudoClass;
  39850. guards.isPseudoElement = isPseudoElement;
  39851. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = void 0;
  39852. var _types = /*@__PURE__*/ requireTypes();
  39853. var _IS_TYPE;
  39854. 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);
  39855. function isNode(node) {
  39856. return typeof node === "object" && IS_TYPE[node.type];
  39857. }
  39858. function isNodeType(type, node) {
  39859. return isNode(node) && node.type === type;
  39860. }
  39861. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  39862. guards.isAttribute = isAttribute;
  39863. var isClassName = isNodeType.bind(null, _types.CLASS);
  39864. guards.isClassName = isClassName;
  39865. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  39866. guards.isCombinator = isCombinator;
  39867. var isComment = isNodeType.bind(null, _types.COMMENT);
  39868. guards.isComment = isComment;
  39869. var isIdentifier = isNodeType.bind(null, _types.ID);
  39870. guards.isIdentifier = isIdentifier;
  39871. var isNesting = isNodeType.bind(null, _types.NESTING);
  39872. guards.isNesting = isNesting;
  39873. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  39874. guards.isPseudo = isPseudo;
  39875. var isRoot = isNodeType.bind(null, _types.ROOT);
  39876. guards.isRoot = isRoot;
  39877. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  39878. guards.isSelector = isSelector;
  39879. var isString = isNodeType.bind(null, _types.STRING);
  39880. guards.isString = isString;
  39881. var isTag = isNodeType.bind(null, _types.TAG);
  39882. guards.isTag = isTag;
  39883. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  39884. guards.isUniversal = isUniversal;
  39885. function isPseudoElement(node) {
  39886. 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");
  39887. }
  39888. function isPseudoClass(node) {
  39889. return isPseudo(node) && !isPseudoElement(node);
  39890. }
  39891. function isContainer(node) {
  39892. return !!(isNode(node) && node.walk);
  39893. }
  39894. function isNamespace(node) {
  39895. return isAttribute(node) || isTag(node);
  39896. }
  39897. return guards;
  39898. }
  39899. var hasRequiredSelectors;
  39900. function requireSelectors () {
  39901. if (hasRequiredSelectors) return selectors;
  39902. hasRequiredSelectors = 1;
  39903. (function (exports) {
  39904. exports.__esModule = true;
  39905. var _types = /*@__PURE__*/ requireTypes();
  39906. Object.keys(_types).forEach(function (key) {
  39907. if (key === "default" || key === "__esModule") return;
  39908. if (key in exports && exports[key] === _types[key]) return;
  39909. exports[key] = _types[key];
  39910. });
  39911. var _constructors = /*@__PURE__*/ requireConstructors();
  39912. Object.keys(_constructors).forEach(function (key) {
  39913. if (key === "default" || key === "__esModule") return;
  39914. if (key in exports && exports[key] === _constructors[key]) return;
  39915. exports[key] = _constructors[key];
  39916. });
  39917. var _guards = /*@__PURE__*/ requireGuards();
  39918. Object.keys(_guards).forEach(function (key) {
  39919. if (key === "default" || key === "__esModule") return;
  39920. if (key in exports && exports[key] === _guards[key]) return;
  39921. exports[key] = _guards[key];
  39922. });
  39923. } (selectors));
  39924. return selectors;
  39925. }
  39926. var hasRequiredDist;
  39927. function requireDist () {
  39928. if (hasRequiredDist) return dist.exports;
  39929. hasRequiredDist = 1;
  39930. (function (module, exports) {
  39931. exports.__esModule = true;
  39932. exports["default"] = void 0;
  39933. var _processor = _interopRequireDefault(/*@__PURE__*/ requireProcessor());
  39934. var selectors = _interopRequireWildcard(/*@__PURE__*/ requireSelectors());
  39935. 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); }
  39936. 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; }
  39937. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  39938. var parser = function parser(processor) {
  39939. return new _processor["default"](processor);
  39940. };
  39941. Object.assign(parser, selectors);
  39942. delete parser.__esModule;
  39943. var _default = parser;
  39944. exports["default"] = _default;
  39945. module.exports = exports.default;
  39946. } (dist, dist.exports));
  39947. return dist.exports;
  39948. }
  39949. var distExports = /*@__PURE__*/ requireDist();
  39950. var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
  39951. const animationNameRE = /^(-\w+-)?animation-name$/;
  39952. const animationRE = /^(-\w+-)?animation$/;
  39953. const keyframesRE = /^(?:-\w+-)?keyframes$/;
  39954. const scopedPlugin = (id = "") => {
  39955. const keyframes = /* @__PURE__ */ Object.create(null);
  39956. const shortId = id.replace(/^data-v-/, "");
  39957. return {
  39958. postcssPlugin: "vue-sfc-scoped",
  39959. Rule(rule) {
  39960. processRule(id, rule);
  39961. },
  39962. AtRule(node) {
  39963. if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
  39964. keyframes[node.params] = node.params = node.params + "-" + shortId;
  39965. }
  39966. },
  39967. OnceExit(root) {
  39968. if (Object.keys(keyframes).length) {
  39969. root.walkDecls((decl) => {
  39970. if (animationNameRE.test(decl.prop)) {
  39971. decl.value = decl.value.split(",").map((v) => keyframes[v.trim()] || v.trim()).join(",");
  39972. }
  39973. if (animationRE.test(decl.prop)) {
  39974. decl.value = decl.value.split(",").map((v) => {
  39975. const vals = v.trim().split(/\s+/);
  39976. const i = vals.findIndex((val) => keyframes[val]);
  39977. if (i !== -1) {
  39978. vals.splice(i, 1, keyframes[vals[i]]);
  39979. return vals.join(" ");
  39980. } else {
  39981. return v;
  39982. }
  39983. }).join(",");
  39984. }
  39985. });
  39986. }
  39987. }
  39988. };
  39989. };
  39990. const processedRules = /* @__PURE__ */ new WeakSet();
  39991. function processRule(id, rule) {
  39992. if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
  39993. return;
  39994. }
  39995. processedRules.add(rule);
  39996. let deep = false;
  39997. let parent = rule.parent;
  39998. while (parent && parent.type !== "root") {
  39999. if (parent.__deep) {
  40000. deep = true;
  40001. break;
  40002. }
  40003. parent = parent.parent;
  40004. }
  40005. rule.selector = selectorParser((selectorRoot) => {
  40006. selectorRoot.each((selector) => {
  40007. rewriteSelector(id, rule, selector, selectorRoot, deep);
  40008. });
  40009. }).processSync(rule.selector);
  40010. }
  40011. function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
  40012. let node = null;
  40013. let shouldInject = !deep;
  40014. selector.each((n) => {
  40015. if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
  40016. n.value = " ";
  40017. n.spaces.before = n.spaces.after = "";
  40018. warn(
  40019. `the >>> and /deep/ combinators have been deprecated. Use :deep() instead.`
  40020. );
  40021. return false;
  40022. }
  40023. if (n.type === "pseudo") {
  40024. const { value } = n;
  40025. if (value === ":deep" || value === "::v-deep") {
  40026. rule.__deep = true;
  40027. if (n.nodes.length) {
  40028. let last = n;
  40029. n.nodes[0].each((ss) => {
  40030. selector.insertAfter(last, ss);
  40031. last = ss;
  40032. });
  40033. const prev = selector.at(selector.index(n) - 1);
  40034. if (!prev || !isSpaceCombinator(prev)) {
  40035. selector.insertAfter(
  40036. n,
  40037. selectorParser.combinator({
  40038. value: " "
  40039. })
  40040. );
  40041. }
  40042. selector.removeChild(n);
  40043. } else {
  40044. warn(
  40045. `${value} usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead of ${value} <inner-selector>.`
  40046. );
  40047. const prev = selector.at(selector.index(n) - 1);
  40048. if (prev && isSpaceCombinator(prev)) {
  40049. selector.removeChild(prev);
  40050. }
  40051. selector.removeChild(n);
  40052. }
  40053. return false;
  40054. }
  40055. if (value === ":slotted" || value === "::v-slotted") {
  40056. rewriteSelector(
  40057. id,
  40058. rule,
  40059. n.nodes[0],
  40060. selectorRoot,
  40061. deep,
  40062. true
  40063. );
  40064. let last = n;
  40065. n.nodes[0].each((ss) => {
  40066. selector.insertAfter(last, ss);
  40067. last = ss;
  40068. });
  40069. selector.removeChild(n);
  40070. shouldInject = false;
  40071. return false;
  40072. }
  40073. if (value === ":global" || value === "::v-global") {
  40074. selector.replaceWith(n.nodes[0]);
  40075. return false;
  40076. }
  40077. }
  40078. if (n.type === "universal") {
  40079. const prev = selector.at(selector.index(n) - 1);
  40080. const next = selector.at(selector.index(n) + 1);
  40081. if (!prev) {
  40082. if (next) {
  40083. if (next.type === "combinator" && next.value === " ") {
  40084. selector.removeChild(next);
  40085. }
  40086. selector.removeChild(n);
  40087. return;
  40088. } else {
  40089. node = selectorParser.combinator({
  40090. value: ""
  40091. });
  40092. selector.insertBefore(n, node);
  40093. selector.removeChild(n);
  40094. return false;
  40095. }
  40096. }
  40097. if (node) return;
  40098. }
  40099. if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
  40100. node = n;
  40101. }
  40102. });
  40103. if (rule.nodes.some((node2) => node2.type === "rule")) {
  40104. const deep2 = rule.__deep;
  40105. if (!deep2) {
  40106. extractAndWrapNodes(rule);
  40107. const atruleNodes = rule.nodes.filter((node2) => node2.type === "atrule");
  40108. for (const atnode of atruleNodes) {
  40109. extractAndWrapNodes(atnode);
  40110. }
  40111. }
  40112. shouldInject = deep2;
  40113. }
  40114. if (node) {
  40115. const { type, value } = node;
  40116. if (type === "pseudo" && (value === ":is" || value === ":where")) {
  40117. node.nodes.forEach(
  40118. (value2) => rewriteSelector(id, rule, value2, selectorRoot, deep, slotted)
  40119. );
  40120. shouldInject = false;
  40121. }
  40122. }
  40123. if (node) {
  40124. node.spaces.after = "";
  40125. } else {
  40126. selector.first.spaces.before = "";
  40127. }
  40128. if (shouldInject) {
  40129. const idToAdd = slotted ? id + "-s" : id;
  40130. selector.insertAfter(
  40131. // If node is null it means we need to inject [id] at the start
  40132. // insertAfter can handle `null` here
  40133. node,
  40134. selectorParser.attribute({
  40135. attribute: idToAdd,
  40136. value: idToAdd,
  40137. raws: {},
  40138. quoteMark: `"`
  40139. })
  40140. );
  40141. }
  40142. }
  40143. function isSpaceCombinator(node) {
  40144. return node.type === "combinator" && /^\s+$/.test(node.value);
  40145. }
  40146. function extractAndWrapNodes(parentNode) {
  40147. if (!parentNode.nodes) return;
  40148. const nodes = parentNode.nodes.filter(
  40149. (node) => node.type === "decl" || node.type === "comment"
  40150. );
  40151. if (nodes.length) {
  40152. for (const node of nodes) {
  40153. parentNode.removeChild(node);
  40154. }
  40155. const wrappedRule = new Rule({
  40156. nodes,
  40157. selector: "&"
  40158. });
  40159. parentNode.prepend(wrappedRule);
  40160. }
  40161. }
  40162. scopedPlugin.postcss = true;
  40163. var sourceMap = {};
  40164. var sourceMapGenerator = {};
  40165. var base64Vlq = {};
  40166. var base64 = {};
  40167. /* -*- Mode: js; js-indent-level: 2; -*- */
  40168. var hasRequiredBase64;
  40169. function requireBase64 () {
  40170. if (hasRequiredBase64) return base64;
  40171. hasRequiredBase64 = 1;
  40172. /*
  40173. * Copyright 2011 Mozilla Foundation and contributors
  40174. * Licensed under the New BSD license. See LICENSE or:
  40175. * http://opensource.org/licenses/BSD-3-Clause
  40176. */
  40177. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  40178. /**
  40179. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  40180. */
  40181. base64.encode = function (number) {
  40182. if (0 <= number && number < intToCharMap.length) {
  40183. return intToCharMap[number];
  40184. }
  40185. throw new TypeError("Must be between 0 and 63: " + number);
  40186. };
  40187. /**
  40188. * Decode a single base 64 character code digit to an integer. Returns -1 on
  40189. * failure.
  40190. */
  40191. base64.decode = function (charCode) {
  40192. var bigA = 65; // 'A'
  40193. var bigZ = 90; // 'Z'
  40194. var littleA = 97; // 'a'
  40195. var littleZ = 122; // 'z'
  40196. var zero = 48; // '0'
  40197. var nine = 57; // '9'
  40198. var plus = 43; // '+'
  40199. var slash = 47; // '/'
  40200. var littleOffset = 26;
  40201. var numberOffset = 52;
  40202. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  40203. if (bigA <= charCode && charCode <= bigZ) {
  40204. return (charCode - bigA);
  40205. }
  40206. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  40207. if (littleA <= charCode && charCode <= littleZ) {
  40208. return (charCode - littleA + littleOffset);
  40209. }
  40210. // 52 - 61: 0123456789
  40211. if (zero <= charCode && charCode <= nine) {
  40212. return (charCode - zero + numberOffset);
  40213. }
  40214. // 62: +
  40215. if (charCode == plus) {
  40216. return 62;
  40217. }
  40218. // 63: /
  40219. if (charCode == slash) {
  40220. return 63;
  40221. }
  40222. // Invalid base64 digit.
  40223. return -1;
  40224. };
  40225. return base64;
  40226. }
  40227. /* -*- Mode: js; js-indent-level: 2; -*- */
  40228. var hasRequiredBase64Vlq;
  40229. function requireBase64Vlq () {
  40230. if (hasRequiredBase64Vlq) return base64Vlq;
  40231. hasRequiredBase64Vlq = 1;
  40232. /*
  40233. * Copyright 2011 Mozilla Foundation and contributors
  40234. * Licensed under the New BSD license. See LICENSE or:
  40235. * http://opensource.org/licenses/BSD-3-Clause
  40236. *
  40237. * Based on the Base 64 VLQ implementation in Closure Compiler:
  40238. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  40239. *
  40240. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  40241. * Redistribution and use in source and binary forms, with or without
  40242. * modification, are permitted provided that the following conditions are
  40243. * met:
  40244. *
  40245. * * Redistributions of source code must retain the above copyright
  40246. * notice, this list of conditions and the following disclaimer.
  40247. * * Redistributions in binary form must reproduce the above
  40248. * copyright notice, this list of conditions and the following
  40249. * disclaimer in the documentation and/or other materials provided
  40250. * with the distribution.
  40251. * * Neither the name of Google Inc. nor the names of its
  40252. * contributors may be used to endorse or promote products derived
  40253. * from this software without specific prior written permission.
  40254. *
  40255. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40256. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40257. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  40258. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40259. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40260. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40261. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40262. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  40263. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40264. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40265. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40266. */
  40267. var base64 = /*@__PURE__*/ requireBase64();
  40268. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  40269. // length quantities we use in the source map spec, the first bit is the sign,
  40270. // the next four bits are the actual value, and the 6th bit is the
  40271. // continuation bit. The continuation bit tells us whether there are more
  40272. // digits in this value following this digit.
  40273. //
  40274. // Continuation
  40275. // | Sign
  40276. // | |
  40277. // V V
  40278. // 101011
  40279. var VLQ_BASE_SHIFT = 5;
  40280. // binary: 100000
  40281. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  40282. // binary: 011111
  40283. var VLQ_BASE_MASK = VLQ_BASE - 1;
  40284. // binary: 100000
  40285. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  40286. /**
  40287. * Converts from a two-complement value to a value where the sign bit is
  40288. * placed in the least significant bit. For example, as decimals:
  40289. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  40290. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  40291. */
  40292. function toVLQSigned(aValue) {
  40293. return aValue < 0
  40294. ? ((-aValue) << 1) + 1
  40295. : (aValue << 1) + 0;
  40296. }
  40297. /**
  40298. * Converts to a two-complement value from a value where the sign bit is
  40299. * placed in the least significant bit. For example, as decimals:
  40300. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  40301. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  40302. */
  40303. function fromVLQSigned(aValue) {
  40304. var isNegative = (aValue & 1) === 1;
  40305. var shifted = aValue >> 1;
  40306. return isNegative
  40307. ? -shifted
  40308. : shifted;
  40309. }
  40310. /**
  40311. * Returns the base 64 VLQ encoded value.
  40312. */
  40313. base64Vlq.encode = function base64VLQ_encode(aValue) {
  40314. var encoded = "";
  40315. var digit;
  40316. var vlq = toVLQSigned(aValue);
  40317. do {
  40318. digit = vlq & VLQ_BASE_MASK;
  40319. vlq >>>= VLQ_BASE_SHIFT;
  40320. if (vlq > 0) {
  40321. // There are still more digits in this value, so we must make sure the
  40322. // continuation bit is marked.
  40323. digit |= VLQ_CONTINUATION_BIT;
  40324. }
  40325. encoded += base64.encode(digit);
  40326. } while (vlq > 0);
  40327. return encoded;
  40328. };
  40329. /**
  40330. * Decodes the next base 64 VLQ value from the given string and returns the
  40331. * value and the rest of the string via the out parameter.
  40332. */
  40333. base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  40334. var strLen = aStr.length;
  40335. var result = 0;
  40336. var shift = 0;
  40337. var continuation, digit;
  40338. do {
  40339. if (aIndex >= strLen) {
  40340. throw new Error("Expected more digits in base 64 VLQ value.");
  40341. }
  40342. digit = base64.decode(aStr.charCodeAt(aIndex++));
  40343. if (digit === -1) {
  40344. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  40345. }
  40346. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  40347. digit &= VLQ_BASE_MASK;
  40348. result = result + (digit << shift);
  40349. shift += VLQ_BASE_SHIFT;
  40350. } while (continuation);
  40351. aOutParam.value = fromVLQSigned(result);
  40352. aOutParam.rest = aIndex;
  40353. };
  40354. return base64Vlq;
  40355. }
  40356. var util = {};
  40357. /* -*- Mode: js; js-indent-level: 2; -*- */
  40358. var hasRequiredUtil;
  40359. function requireUtil () {
  40360. if (hasRequiredUtil) return util;
  40361. hasRequiredUtil = 1;
  40362. (function (exports) {
  40363. /*
  40364. * Copyright 2011 Mozilla Foundation and contributors
  40365. * Licensed under the New BSD license. See LICENSE or:
  40366. * http://opensource.org/licenses/BSD-3-Clause
  40367. */
  40368. /**
  40369. * This is a helper function for getting values from parameter/options
  40370. * objects.
  40371. *
  40372. * @param args The object we are extracting values from
  40373. * @param name The name of the property we are getting.
  40374. * @param defaultValue An optional value to return if the property is missing
  40375. * from the object. If this is not specified and the property is missing, an
  40376. * error will be thrown.
  40377. */
  40378. function getArg(aArgs, aName, aDefaultValue) {
  40379. if (aName in aArgs) {
  40380. return aArgs[aName];
  40381. } else if (arguments.length === 3) {
  40382. return aDefaultValue;
  40383. } else {
  40384. throw new Error('"' + aName + '" is a required argument.');
  40385. }
  40386. }
  40387. exports.getArg = getArg;
  40388. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  40389. var dataUrlRegexp = /^data:.+\,.+$/;
  40390. function urlParse(aUrl) {
  40391. var match = aUrl.match(urlRegexp);
  40392. if (!match) {
  40393. return null;
  40394. }
  40395. return {
  40396. scheme: match[1],
  40397. auth: match[2],
  40398. host: match[3],
  40399. port: match[4],
  40400. path: match[5]
  40401. };
  40402. }
  40403. exports.urlParse = urlParse;
  40404. function urlGenerate(aParsedUrl) {
  40405. var url = '';
  40406. if (aParsedUrl.scheme) {
  40407. url += aParsedUrl.scheme + ':';
  40408. }
  40409. url += '//';
  40410. if (aParsedUrl.auth) {
  40411. url += aParsedUrl.auth + '@';
  40412. }
  40413. if (aParsedUrl.host) {
  40414. url += aParsedUrl.host;
  40415. }
  40416. if (aParsedUrl.port) {
  40417. url += ":" + aParsedUrl.port;
  40418. }
  40419. if (aParsedUrl.path) {
  40420. url += aParsedUrl.path;
  40421. }
  40422. return url;
  40423. }
  40424. exports.urlGenerate = urlGenerate;
  40425. /**
  40426. * Normalizes a path, or the path portion of a URL:
  40427. *
  40428. * - Replaces consecutive slashes with one slash.
  40429. * - Removes unnecessary '.' parts.
  40430. * - Removes unnecessary '<dir>/..' parts.
  40431. *
  40432. * Based on code in the Node.js 'path' core module.
  40433. *
  40434. * @param aPath The path or url to normalize.
  40435. */
  40436. function normalize(aPath) {
  40437. var path = aPath;
  40438. var url = urlParse(aPath);
  40439. if (url) {
  40440. if (!url.path) {
  40441. return aPath;
  40442. }
  40443. path = url.path;
  40444. }
  40445. var isAbsolute = exports.isAbsolute(path);
  40446. var parts = path.split(/\/+/);
  40447. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  40448. part = parts[i];
  40449. if (part === '.') {
  40450. parts.splice(i, 1);
  40451. } else if (part === '..') {
  40452. up++;
  40453. } else if (up > 0) {
  40454. if (part === '') {
  40455. // The first part is blank if the path is absolute. Trying to go
  40456. // above the root is a no-op. Therefore we can remove all '..' parts
  40457. // directly after the root.
  40458. parts.splice(i + 1, up);
  40459. up = 0;
  40460. } else {
  40461. parts.splice(i, 2);
  40462. up--;
  40463. }
  40464. }
  40465. }
  40466. path = parts.join('/');
  40467. if (path === '') {
  40468. path = isAbsolute ? '/' : '.';
  40469. }
  40470. if (url) {
  40471. url.path = path;
  40472. return urlGenerate(url);
  40473. }
  40474. return path;
  40475. }
  40476. exports.normalize = normalize;
  40477. /**
  40478. * Joins two paths/URLs.
  40479. *
  40480. * @param aRoot The root path or URL.
  40481. * @param aPath The path or URL to be joined with the root.
  40482. *
  40483. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  40484. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  40485. * first.
  40486. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  40487. * is updated with the result and aRoot is returned. Otherwise the result
  40488. * is returned.
  40489. * - If aPath is absolute, the result is aPath.
  40490. * - Otherwise the two paths are joined with a slash.
  40491. * - Joining for example 'http://' and 'www.example.com' is also supported.
  40492. */
  40493. function join(aRoot, aPath) {
  40494. if (aRoot === "") {
  40495. aRoot = ".";
  40496. }
  40497. if (aPath === "") {
  40498. aPath = ".";
  40499. }
  40500. var aPathUrl = urlParse(aPath);
  40501. var aRootUrl = urlParse(aRoot);
  40502. if (aRootUrl) {
  40503. aRoot = aRootUrl.path || '/';
  40504. }
  40505. // `join(foo, '//www.example.org')`
  40506. if (aPathUrl && !aPathUrl.scheme) {
  40507. if (aRootUrl) {
  40508. aPathUrl.scheme = aRootUrl.scheme;
  40509. }
  40510. return urlGenerate(aPathUrl);
  40511. }
  40512. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  40513. return aPath;
  40514. }
  40515. // `join('http://', 'www.example.com')`
  40516. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  40517. aRootUrl.host = aPath;
  40518. return urlGenerate(aRootUrl);
  40519. }
  40520. var joined = aPath.charAt(0) === '/'
  40521. ? aPath
  40522. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  40523. if (aRootUrl) {
  40524. aRootUrl.path = joined;
  40525. return urlGenerate(aRootUrl);
  40526. }
  40527. return joined;
  40528. }
  40529. exports.join = join;
  40530. exports.isAbsolute = function (aPath) {
  40531. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  40532. };
  40533. /**
  40534. * Make a path relative to a URL or another path.
  40535. *
  40536. * @param aRoot The root path or URL.
  40537. * @param aPath The path or URL to be made relative to aRoot.
  40538. */
  40539. function relative(aRoot, aPath) {
  40540. if (aRoot === "") {
  40541. aRoot = ".";
  40542. }
  40543. aRoot = aRoot.replace(/\/$/, '');
  40544. // It is possible for the path to be above the root. In this case, simply
  40545. // checking whether the root is a prefix of the path won't work. Instead, we
  40546. // need to remove components from the root one by one, until either we find
  40547. // a prefix that fits, or we run out of components to remove.
  40548. var level = 0;
  40549. while (aPath.indexOf(aRoot + '/') !== 0) {
  40550. var index = aRoot.lastIndexOf("/");
  40551. if (index < 0) {
  40552. return aPath;
  40553. }
  40554. // If the only part of the root that is left is the scheme (i.e. http://,
  40555. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  40556. // have exhausted all components, so the path is not relative to the root.
  40557. aRoot = aRoot.slice(0, index);
  40558. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  40559. return aPath;
  40560. }
  40561. ++level;
  40562. }
  40563. // Make sure we add a "../" for each component we removed from the root.
  40564. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  40565. }
  40566. exports.relative = relative;
  40567. var supportsNullProto = (function () {
  40568. var obj = Object.create(null);
  40569. return !('__proto__' in obj);
  40570. }());
  40571. function identity (s) {
  40572. return s;
  40573. }
  40574. /**
  40575. * Because behavior goes wacky when you set `__proto__` on objects, we
  40576. * have to prefix all the strings in our set with an arbitrary character.
  40577. *
  40578. * See https://github.com/mozilla/source-map/pull/31 and
  40579. * https://github.com/mozilla/source-map/issues/30
  40580. *
  40581. * @param String aStr
  40582. */
  40583. function toSetString(aStr) {
  40584. if (isProtoString(aStr)) {
  40585. return '$' + aStr;
  40586. }
  40587. return aStr;
  40588. }
  40589. exports.toSetString = supportsNullProto ? identity : toSetString;
  40590. function fromSetString(aStr) {
  40591. if (isProtoString(aStr)) {
  40592. return aStr.slice(1);
  40593. }
  40594. return aStr;
  40595. }
  40596. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  40597. function isProtoString(s) {
  40598. if (!s) {
  40599. return false;
  40600. }
  40601. var length = s.length;
  40602. if (length < 9 /* "__proto__".length */) {
  40603. return false;
  40604. }
  40605. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  40606. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  40607. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  40608. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  40609. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  40610. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  40611. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  40612. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  40613. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  40614. return false;
  40615. }
  40616. for (var i = length - 10; i >= 0; i--) {
  40617. if (s.charCodeAt(i) !== 36 /* '$' */) {
  40618. return false;
  40619. }
  40620. }
  40621. return true;
  40622. }
  40623. /**
  40624. * Comparator between two mappings where the original positions are compared.
  40625. *
  40626. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40627. * mappings with the same original source/line/column, but different generated
  40628. * line and column the same. Useful when searching for a mapping with a
  40629. * stubbed out mapping.
  40630. */
  40631. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  40632. var cmp = strcmp(mappingA.source, mappingB.source);
  40633. if (cmp !== 0) {
  40634. return cmp;
  40635. }
  40636. cmp = mappingA.originalLine - mappingB.originalLine;
  40637. if (cmp !== 0) {
  40638. return cmp;
  40639. }
  40640. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40641. if (cmp !== 0 || onlyCompareOriginal) {
  40642. return cmp;
  40643. }
  40644. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40645. if (cmp !== 0) {
  40646. return cmp;
  40647. }
  40648. cmp = mappingA.generatedLine - mappingB.generatedLine;
  40649. if (cmp !== 0) {
  40650. return cmp;
  40651. }
  40652. return strcmp(mappingA.name, mappingB.name);
  40653. }
  40654. exports.compareByOriginalPositions = compareByOriginalPositions;
  40655. /**
  40656. * Comparator between two mappings with deflated source and name indices where
  40657. * the generated positions are compared.
  40658. *
  40659. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  40660. * mappings with the same generated line and column, but different
  40661. * source/name/original line and column the same. Useful when searching for a
  40662. * mapping with a stubbed out mapping.
  40663. */
  40664. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  40665. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40666. if (cmp !== 0) {
  40667. return cmp;
  40668. }
  40669. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40670. if (cmp !== 0 || onlyCompareGenerated) {
  40671. return cmp;
  40672. }
  40673. cmp = strcmp(mappingA.source, mappingB.source);
  40674. if (cmp !== 0) {
  40675. return cmp;
  40676. }
  40677. cmp = mappingA.originalLine - mappingB.originalLine;
  40678. if (cmp !== 0) {
  40679. return cmp;
  40680. }
  40681. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40682. if (cmp !== 0) {
  40683. return cmp;
  40684. }
  40685. return strcmp(mappingA.name, mappingB.name);
  40686. }
  40687. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  40688. function strcmp(aStr1, aStr2) {
  40689. if (aStr1 === aStr2) {
  40690. return 0;
  40691. }
  40692. if (aStr1 === null) {
  40693. return 1; // aStr2 !== null
  40694. }
  40695. if (aStr2 === null) {
  40696. return -1; // aStr1 !== null
  40697. }
  40698. if (aStr1 > aStr2) {
  40699. return 1;
  40700. }
  40701. return -1;
  40702. }
  40703. /**
  40704. * Comparator between two mappings with inflated source and name strings where
  40705. * the generated positions are compared.
  40706. */
  40707. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  40708. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  40709. if (cmp !== 0) {
  40710. return cmp;
  40711. }
  40712. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  40713. if (cmp !== 0) {
  40714. return cmp;
  40715. }
  40716. cmp = strcmp(mappingA.source, mappingB.source);
  40717. if (cmp !== 0) {
  40718. return cmp;
  40719. }
  40720. cmp = mappingA.originalLine - mappingB.originalLine;
  40721. if (cmp !== 0) {
  40722. return cmp;
  40723. }
  40724. cmp = mappingA.originalColumn - mappingB.originalColumn;
  40725. if (cmp !== 0) {
  40726. return cmp;
  40727. }
  40728. return strcmp(mappingA.name, mappingB.name);
  40729. }
  40730. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  40731. /**
  40732. * Strip any JSON XSSI avoidance prefix from the string (as documented
  40733. * in the source maps specification), and then parse the string as
  40734. * JSON.
  40735. */
  40736. function parseSourceMapInput(str) {
  40737. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  40738. }
  40739. exports.parseSourceMapInput = parseSourceMapInput;
  40740. /**
  40741. * Compute the URL of a source given the the source root, the source's
  40742. * URL, and the source map's URL.
  40743. */
  40744. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  40745. sourceURL = sourceURL || '';
  40746. if (sourceRoot) {
  40747. // This follows what Chrome does.
  40748. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  40749. sourceRoot += '/';
  40750. }
  40751. // The spec says:
  40752. // Line 4: An optional source root, useful for relocating source
  40753. // files on a server or removing repeated values in the
  40754. // “sources” entry. This value is prepended to the individual
  40755. // entries in the “source” field.
  40756. sourceURL = sourceRoot + sourceURL;
  40757. }
  40758. // Historically, SourceMapConsumer did not take the sourceMapURL as
  40759. // a parameter. This mode is still somewhat supported, which is why
  40760. // this code block is conditional. However, it's preferable to pass
  40761. // the source map URL to SourceMapConsumer, so that this function
  40762. // can implement the source URL resolution algorithm as outlined in
  40763. // the spec. This block is basically the equivalent of:
  40764. // new URL(sourceURL, sourceMapURL).toString()
  40765. // ... except it avoids using URL, which wasn't available in the
  40766. // older releases of node still supported by this library.
  40767. //
  40768. // The spec says:
  40769. // If the sources are not absolute URLs after prepending of the
  40770. // “sourceRoot”, the sources are resolved relative to the
  40771. // SourceMap (like resolving script src in a html document).
  40772. if (sourceMapURL) {
  40773. var parsed = urlParse(sourceMapURL);
  40774. if (!parsed) {
  40775. throw new Error("sourceMapURL could not be parsed");
  40776. }
  40777. if (parsed.path) {
  40778. // Strip the last path component, but keep the "/".
  40779. var index = parsed.path.lastIndexOf('/');
  40780. if (index >= 0) {
  40781. parsed.path = parsed.path.substring(0, index + 1);
  40782. }
  40783. }
  40784. sourceURL = join(urlGenerate(parsed), sourceURL);
  40785. }
  40786. return normalize(sourceURL);
  40787. }
  40788. exports.computeSourceURL = computeSourceURL;
  40789. } (util));
  40790. return util;
  40791. }
  40792. var arraySet = {};
  40793. /* -*- Mode: js; js-indent-level: 2; -*- */
  40794. var hasRequiredArraySet;
  40795. function requireArraySet () {
  40796. if (hasRequiredArraySet) return arraySet;
  40797. hasRequiredArraySet = 1;
  40798. /*
  40799. * Copyright 2011 Mozilla Foundation and contributors
  40800. * Licensed under the New BSD license. See LICENSE or:
  40801. * http://opensource.org/licenses/BSD-3-Clause
  40802. */
  40803. var util = /*@__PURE__*/ requireUtil();
  40804. var has = Object.prototype.hasOwnProperty;
  40805. var hasNativeMap = typeof Map !== "undefined";
  40806. /**
  40807. * A data structure which is a combination of an array and a set. Adding a new
  40808. * member is O(1), testing for membership is O(1), and finding the index of an
  40809. * element is O(1). Removing elements from the set is not supported. Only
  40810. * strings are supported for membership.
  40811. */
  40812. function ArraySet() {
  40813. this._array = [];
  40814. this._set = hasNativeMap ? new Map() : Object.create(null);
  40815. }
  40816. /**
  40817. * Static method for creating ArraySet instances from an existing array.
  40818. */
  40819. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  40820. var set = new ArraySet();
  40821. for (var i = 0, len = aArray.length; i < len; i++) {
  40822. set.add(aArray[i], aAllowDuplicates);
  40823. }
  40824. return set;
  40825. };
  40826. /**
  40827. * Return how many unique items are in this ArraySet. If duplicates have been
  40828. * added, than those do not count towards the size.
  40829. *
  40830. * @returns Number
  40831. */
  40832. ArraySet.prototype.size = function ArraySet_size() {
  40833. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  40834. };
  40835. /**
  40836. * Add the given string to this set.
  40837. *
  40838. * @param String aStr
  40839. */
  40840. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  40841. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  40842. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  40843. var idx = this._array.length;
  40844. if (!isDuplicate || aAllowDuplicates) {
  40845. this._array.push(aStr);
  40846. }
  40847. if (!isDuplicate) {
  40848. if (hasNativeMap) {
  40849. this._set.set(aStr, idx);
  40850. } else {
  40851. this._set[sStr] = idx;
  40852. }
  40853. }
  40854. };
  40855. /**
  40856. * Is the given string a member of this set?
  40857. *
  40858. * @param String aStr
  40859. */
  40860. ArraySet.prototype.has = function ArraySet_has(aStr) {
  40861. if (hasNativeMap) {
  40862. return this._set.has(aStr);
  40863. } else {
  40864. var sStr = util.toSetString(aStr);
  40865. return has.call(this._set, sStr);
  40866. }
  40867. };
  40868. /**
  40869. * What is the index of the given string in the array?
  40870. *
  40871. * @param String aStr
  40872. */
  40873. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  40874. if (hasNativeMap) {
  40875. var idx = this._set.get(aStr);
  40876. if (idx >= 0) {
  40877. return idx;
  40878. }
  40879. } else {
  40880. var sStr = util.toSetString(aStr);
  40881. if (has.call(this._set, sStr)) {
  40882. return this._set[sStr];
  40883. }
  40884. }
  40885. throw new Error('"' + aStr + '" is not in the set.');
  40886. };
  40887. /**
  40888. * What is the element at the given index?
  40889. *
  40890. * @param Number aIdx
  40891. */
  40892. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  40893. if (aIdx >= 0 && aIdx < this._array.length) {
  40894. return this._array[aIdx];
  40895. }
  40896. throw new Error('No element indexed by ' + aIdx);
  40897. };
  40898. /**
  40899. * Returns the array representation of this set (which has the proper indices
  40900. * indicated by indexOf). Note that this is a copy of the internal array used
  40901. * for storing the members so that no one can mess with internal state.
  40902. */
  40903. ArraySet.prototype.toArray = function ArraySet_toArray() {
  40904. return this._array.slice();
  40905. };
  40906. arraySet.ArraySet = ArraySet;
  40907. return arraySet;
  40908. }
  40909. var mappingList = {};
  40910. /* -*- Mode: js; js-indent-level: 2; -*- */
  40911. var hasRequiredMappingList;
  40912. function requireMappingList () {
  40913. if (hasRequiredMappingList) return mappingList;
  40914. hasRequiredMappingList = 1;
  40915. /*
  40916. * Copyright 2014 Mozilla Foundation and contributors
  40917. * Licensed under the New BSD license. See LICENSE or:
  40918. * http://opensource.org/licenses/BSD-3-Clause
  40919. */
  40920. var util = /*@__PURE__*/ requireUtil();
  40921. /**
  40922. * Determine whether mappingB is after mappingA with respect to generated
  40923. * position.
  40924. */
  40925. function generatedPositionAfter(mappingA, mappingB) {
  40926. // Optimized for most common case
  40927. var lineA = mappingA.generatedLine;
  40928. var lineB = mappingB.generatedLine;
  40929. var columnA = mappingA.generatedColumn;
  40930. var columnB = mappingB.generatedColumn;
  40931. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  40932. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  40933. }
  40934. /**
  40935. * A data structure to provide a sorted view of accumulated mappings in a
  40936. * performance conscious manner. It trades a neglibable overhead in general
  40937. * case for a large speedup in case of mappings being added in order.
  40938. */
  40939. function MappingList() {
  40940. this._array = [];
  40941. this._sorted = true;
  40942. // Serves as infimum
  40943. this._last = {generatedLine: -1, generatedColumn: 0};
  40944. }
  40945. /**
  40946. * Iterate through internal items. This method takes the same arguments that
  40947. * `Array.prototype.forEach` takes.
  40948. *
  40949. * NOTE: The order of the mappings is NOT guaranteed.
  40950. */
  40951. MappingList.prototype.unsortedForEach =
  40952. function MappingList_forEach(aCallback, aThisArg) {
  40953. this._array.forEach(aCallback, aThisArg);
  40954. };
  40955. /**
  40956. * Add the given source mapping.
  40957. *
  40958. * @param Object aMapping
  40959. */
  40960. MappingList.prototype.add = function MappingList_add(aMapping) {
  40961. if (generatedPositionAfter(this._last, aMapping)) {
  40962. this._last = aMapping;
  40963. this._array.push(aMapping);
  40964. } else {
  40965. this._sorted = false;
  40966. this._array.push(aMapping);
  40967. }
  40968. };
  40969. /**
  40970. * Returns the flat, sorted array of mappings. The mappings are sorted by
  40971. * generated position.
  40972. *
  40973. * WARNING: This method returns internal data without copying, for
  40974. * performance. The return value must NOT be mutated, and should be treated as
  40975. * an immutable borrow. If you want to take ownership, you must make your own
  40976. * copy.
  40977. */
  40978. MappingList.prototype.toArray = function MappingList_toArray() {
  40979. if (!this._sorted) {
  40980. this._array.sort(util.compareByGeneratedPositionsInflated);
  40981. this._sorted = true;
  40982. }
  40983. return this._array;
  40984. };
  40985. mappingList.MappingList = MappingList;
  40986. return mappingList;
  40987. }
  40988. /* -*- Mode: js; js-indent-level: 2; -*- */
  40989. var hasRequiredSourceMapGenerator;
  40990. function requireSourceMapGenerator () {
  40991. if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
  40992. hasRequiredSourceMapGenerator = 1;
  40993. /*
  40994. * Copyright 2011 Mozilla Foundation and contributors
  40995. * Licensed under the New BSD license. See LICENSE or:
  40996. * http://opensource.org/licenses/BSD-3-Clause
  40997. */
  40998. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  40999. var util = /*@__PURE__*/ requireUtil();
  41000. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41001. var MappingList = /*@__PURE__*/ requireMappingList().MappingList;
  41002. /**
  41003. * An instance of the SourceMapGenerator represents a source map which is
  41004. * being built incrementally. You may pass an object with the following
  41005. * properties:
  41006. *
  41007. * - file: The filename of the generated source.
  41008. * - sourceRoot: A root for all relative URLs in this source map.
  41009. */
  41010. function SourceMapGenerator(aArgs) {
  41011. if (!aArgs) {
  41012. aArgs = {};
  41013. }
  41014. this._file = util.getArg(aArgs, 'file', null);
  41015. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  41016. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  41017. this._sources = new ArraySet();
  41018. this._names = new ArraySet();
  41019. this._mappings = new MappingList();
  41020. this._sourcesContents = null;
  41021. }
  41022. SourceMapGenerator.prototype._version = 3;
  41023. /**
  41024. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  41025. *
  41026. * @param aSourceMapConsumer The SourceMap.
  41027. */
  41028. SourceMapGenerator.fromSourceMap =
  41029. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  41030. var sourceRoot = aSourceMapConsumer.sourceRoot;
  41031. var generator = new SourceMapGenerator({
  41032. file: aSourceMapConsumer.file,
  41033. sourceRoot: sourceRoot
  41034. });
  41035. aSourceMapConsumer.eachMapping(function (mapping) {
  41036. var newMapping = {
  41037. generated: {
  41038. line: mapping.generatedLine,
  41039. column: mapping.generatedColumn
  41040. }
  41041. };
  41042. if (mapping.source != null) {
  41043. newMapping.source = mapping.source;
  41044. if (sourceRoot != null) {
  41045. newMapping.source = util.relative(sourceRoot, newMapping.source);
  41046. }
  41047. newMapping.original = {
  41048. line: mapping.originalLine,
  41049. column: mapping.originalColumn
  41050. };
  41051. if (mapping.name != null) {
  41052. newMapping.name = mapping.name;
  41053. }
  41054. }
  41055. generator.addMapping(newMapping);
  41056. });
  41057. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41058. var sourceRelative = sourceFile;
  41059. if (sourceRoot !== null) {
  41060. sourceRelative = util.relative(sourceRoot, sourceFile);
  41061. }
  41062. if (!generator._sources.has(sourceRelative)) {
  41063. generator._sources.add(sourceRelative);
  41064. }
  41065. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41066. if (content != null) {
  41067. generator.setSourceContent(sourceFile, content);
  41068. }
  41069. });
  41070. return generator;
  41071. };
  41072. /**
  41073. * Add a single mapping from original source line and column to the generated
  41074. * source's line and column for this source map being created. The mapping
  41075. * object should have the following properties:
  41076. *
  41077. * - generated: An object with the generated line and column positions.
  41078. * - original: An object with the original line and column positions.
  41079. * - source: The original source file (relative to the sourceRoot).
  41080. * - name: An optional original token name for this mapping.
  41081. */
  41082. SourceMapGenerator.prototype.addMapping =
  41083. function SourceMapGenerator_addMapping(aArgs) {
  41084. var generated = util.getArg(aArgs, 'generated');
  41085. var original = util.getArg(aArgs, 'original', null);
  41086. var source = util.getArg(aArgs, 'source', null);
  41087. var name = util.getArg(aArgs, 'name', null);
  41088. if (!this._skipValidation) {
  41089. this._validateMapping(generated, original, source, name);
  41090. }
  41091. if (source != null) {
  41092. source = String(source);
  41093. if (!this._sources.has(source)) {
  41094. this._sources.add(source);
  41095. }
  41096. }
  41097. if (name != null) {
  41098. name = String(name);
  41099. if (!this._names.has(name)) {
  41100. this._names.add(name);
  41101. }
  41102. }
  41103. this._mappings.add({
  41104. generatedLine: generated.line,
  41105. generatedColumn: generated.column,
  41106. originalLine: original != null && original.line,
  41107. originalColumn: original != null && original.column,
  41108. source: source,
  41109. name: name
  41110. });
  41111. };
  41112. /**
  41113. * Set the source content for a source file.
  41114. */
  41115. SourceMapGenerator.prototype.setSourceContent =
  41116. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  41117. var source = aSourceFile;
  41118. if (this._sourceRoot != null) {
  41119. source = util.relative(this._sourceRoot, source);
  41120. }
  41121. if (aSourceContent != null) {
  41122. // Add the source content to the _sourcesContents map.
  41123. // Create a new _sourcesContents map if the property is null.
  41124. if (!this._sourcesContents) {
  41125. this._sourcesContents = Object.create(null);
  41126. }
  41127. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  41128. } else if (this._sourcesContents) {
  41129. // Remove the source file from the _sourcesContents map.
  41130. // If the _sourcesContents map is empty, set the property to null.
  41131. delete this._sourcesContents[util.toSetString(source)];
  41132. if (Object.keys(this._sourcesContents).length === 0) {
  41133. this._sourcesContents = null;
  41134. }
  41135. }
  41136. };
  41137. /**
  41138. * Applies the mappings of a sub-source-map for a specific source file to the
  41139. * source map being generated. Each mapping to the supplied source file is
  41140. * rewritten using the supplied source map. Note: The resolution for the
  41141. * resulting mappings is the minimium of this map and the supplied map.
  41142. *
  41143. * @param aSourceMapConsumer The source map to be applied.
  41144. * @param aSourceFile Optional. The filename of the source file.
  41145. * If omitted, SourceMapConsumer's file property will be used.
  41146. * @param aSourceMapPath Optional. The dirname of the path to the source map
  41147. * to be applied. If relative, it is relative to the SourceMapConsumer.
  41148. * This parameter is needed when the two source maps aren't in the same
  41149. * directory, and the source map to be applied contains relative source
  41150. * paths. If so, those relative source paths need to be rewritten
  41151. * relative to the SourceMapGenerator.
  41152. */
  41153. SourceMapGenerator.prototype.applySourceMap =
  41154. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  41155. var sourceFile = aSourceFile;
  41156. // If aSourceFile is omitted, we will use the file property of the SourceMap
  41157. if (aSourceFile == null) {
  41158. if (aSourceMapConsumer.file == null) {
  41159. throw new Error(
  41160. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  41161. 'or the source map\'s "file" property. Both were omitted.'
  41162. );
  41163. }
  41164. sourceFile = aSourceMapConsumer.file;
  41165. }
  41166. var sourceRoot = this._sourceRoot;
  41167. // Make "sourceFile" relative if an absolute Url is passed.
  41168. if (sourceRoot != null) {
  41169. sourceFile = util.relative(sourceRoot, sourceFile);
  41170. }
  41171. // Applying the SourceMap can add and remove items from the sources and
  41172. // the names array.
  41173. var newSources = new ArraySet();
  41174. var newNames = new ArraySet();
  41175. // Find mappings for the "sourceFile"
  41176. this._mappings.unsortedForEach(function (mapping) {
  41177. if (mapping.source === sourceFile && mapping.originalLine != null) {
  41178. // Check if it can be mapped by the source map, then update the mapping.
  41179. var original = aSourceMapConsumer.originalPositionFor({
  41180. line: mapping.originalLine,
  41181. column: mapping.originalColumn
  41182. });
  41183. if (original.source != null) {
  41184. // Copy mapping
  41185. mapping.source = original.source;
  41186. if (aSourceMapPath != null) {
  41187. mapping.source = util.join(aSourceMapPath, mapping.source);
  41188. }
  41189. if (sourceRoot != null) {
  41190. mapping.source = util.relative(sourceRoot, mapping.source);
  41191. }
  41192. mapping.originalLine = original.line;
  41193. mapping.originalColumn = original.column;
  41194. if (original.name != null) {
  41195. mapping.name = original.name;
  41196. }
  41197. }
  41198. }
  41199. var source = mapping.source;
  41200. if (source != null && !newSources.has(source)) {
  41201. newSources.add(source);
  41202. }
  41203. var name = mapping.name;
  41204. if (name != null && !newNames.has(name)) {
  41205. newNames.add(name);
  41206. }
  41207. }, this);
  41208. this._sources = newSources;
  41209. this._names = newNames;
  41210. // Copy sourcesContents of applied map.
  41211. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  41212. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  41213. if (content != null) {
  41214. if (aSourceMapPath != null) {
  41215. sourceFile = util.join(aSourceMapPath, sourceFile);
  41216. }
  41217. if (sourceRoot != null) {
  41218. sourceFile = util.relative(sourceRoot, sourceFile);
  41219. }
  41220. this.setSourceContent(sourceFile, content);
  41221. }
  41222. }, this);
  41223. };
  41224. /**
  41225. * A mapping can have one of the three levels of data:
  41226. *
  41227. * 1. Just the generated position.
  41228. * 2. The Generated position, original position, and original source.
  41229. * 3. Generated and original position, original source, as well as a name
  41230. * token.
  41231. *
  41232. * To maintain consistency, we validate that any new mapping being added falls
  41233. * in to one of these categories.
  41234. */
  41235. SourceMapGenerator.prototype._validateMapping =
  41236. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  41237. aName) {
  41238. // When aOriginal is truthy but has empty values for .line and .column,
  41239. // it is most likely a programmer error. In this case we throw a very
  41240. // specific error message to try to guide them the right way.
  41241. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  41242. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  41243. throw new Error(
  41244. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  41245. 'the original mapping entirely and only map the generated position. If so, pass ' +
  41246. 'null for the original mapping instead of an object with empty or null values.'
  41247. );
  41248. }
  41249. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41250. && aGenerated.line > 0 && aGenerated.column >= 0
  41251. && !aOriginal && !aSource && !aName) {
  41252. // Case 1.
  41253. return;
  41254. }
  41255. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  41256. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  41257. && aGenerated.line > 0 && aGenerated.column >= 0
  41258. && aOriginal.line > 0 && aOriginal.column >= 0
  41259. && aSource) {
  41260. // Cases 2 and 3.
  41261. return;
  41262. }
  41263. else {
  41264. throw new Error('Invalid mapping: ' + JSON.stringify({
  41265. generated: aGenerated,
  41266. source: aSource,
  41267. original: aOriginal,
  41268. name: aName
  41269. }));
  41270. }
  41271. };
  41272. /**
  41273. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  41274. * specified by the source map format.
  41275. */
  41276. SourceMapGenerator.prototype._serializeMappings =
  41277. function SourceMapGenerator_serializeMappings() {
  41278. var previousGeneratedColumn = 0;
  41279. var previousGeneratedLine = 1;
  41280. var previousOriginalColumn = 0;
  41281. var previousOriginalLine = 0;
  41282. var previousName = 0;
  41283. var previousSource = 0;
  41284. var result = '';
  41285. var next;
  41286. var mapping;
  41287. var nameIdx;
  41288. var sourceIdx;
  41289. var mappings = this._mappings.toArray();
  41290. for (var i = 0, len = mappings.length; i < len; i++) {
  41291. mapping = mappings[i];
  41292. next = '';
  41293. if (mapping.generatedLine !== previousGeneratedLine) {
  41294. previousGeneratedColumn = 0;
  41295. while (mapping.generatedLine !== previousGeneratedLine) {
  41296. next += ';';
  41297. previousGeneratedLine++;
  41298. }
  41299. }
  41300. else {
  41301. if (i > 0) {
  41302. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  41303. continue;
  41304. }
  41305. next += ',';
  41306. }
  41307. }
  41308. next += base64VLQ.encode(mapping.generatedColumn
  41309. - previousGeneratedColumn);
  41310. previousGeneratedColumn = mapping.generatedColumn;
  41311. if (mapping.source != null) {
  41312. sourceIdx = this._sources.indexOf(mapping.source);
  41313. next += base64VLQ.encode(sourceIdx - previousSource);
  41314. previousSource = sourceIdx;
  41315. // lines are stored 0-based in SourceMap spec version 3
  41316. next += base64VLQ.encode(mapping.originalLine - 1
  41317. - previousOriginalLine);
  41318. previousOriginalLine = mapping.originalLine - 1;
  41319. next += base64VLQ.encode(mapping.originalColumn
  41320. - previousOriginalColumn);
  41321. previousOriginalColumn = mapping.originalColumn;
  41322. if (mapping.name != null) {
  41323. nameIdx = this._names.indexOf(mapping.name);
  41324. next += base64VLQ.encode(nameIdx - previousName);
  41325. previousName = nameIdx;
  41326. }
  41327. }
  41328. result += next;
  41329. }
  41330. return result;
  41331. };
  41332. SourceMapGenerator.prototype._generateSourcesContent =
  41333. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  41334. return aSources.map(function (source) {
  41335. if (!this._sourcesContents) {
  41336. return null;
  41337. }
  41338. if (aSourceRoot != null) {
  41339. source = util.relative(aSourceRoot, source);
  41340. }
  41341. var key = util.toSetString(source);
  41342. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  41343. ? this._sourcesContents[key]
  41344. : null;
  41345. }, this);
  41346. };
  41347. /**
  41348. * Externalize the source map.
  41349. */
  41350. SourceMapGenerator.prototype.toJSON =
  41351. function SourceMapGenerator_toJSON() {
  41352. var map = {
  41353. version: this._version,
  41354. sources: this._sources.toArray(),
  41355. names: this._names.toArray(),
  41356. mappings: this._serializeMappings()
  41357. };
  41358. if (this._file != null) {
  41359. map.file = this._file;
  41360. }
  41361. if (this._sourceRoot != null) {
  41362. map.sourceRoot = this._sourceRoot;
  41363. }
  41364. if (this._sourcesContents) {
  41365. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  41366. }
  41367. return map;
  41368. };
  41369. /**
  41370. * Render the source map being generated to a string.
  41371. */
  41372. SourceMapGenerator.prototype.toString =
  41373. function SourceMapGenerator_toString() {
  41374. return JSON.stringify(this.toJSON());
  41375. };
  41376. sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
  41377. return sourceMapGenerator;
  41378. }
  41379. var sourceMapConsumer = {};
  41380. var binarySearch = {};
  41381. /* -*- Mode: js; js-indent-level: 2; -*- */
  41382. var hasRequiredBinarySearch;
  41383. function requireBinarySearch () {
  41384. if (hasRequiredBinarySearch) return binarySearch;
  41385. hasRequiredBinarySearch = 1;
  41386. (function (exports) {
  41387. /*
  41388. * Copyright 2011 Mozilla Foundation and contributors
  41389. * Licensed under the New BSD license. See LICENSE or:
  41390. * http://opensource.org/licenses/BSD-3-Clause
  41391. */
  41392. exports.GREATEST_LOWER_BOUND = 1;
  41393. exports.LEAST_UPPER_BOUND = 2;
  41394. /**
  41395. * Recursive implementation of binary search.
  41396. *
  41397. * @param aLow Indices here and lower do not contain the needle.
  41398. * @param aHigh Indices here and higher do not contain the needle.
  41399. * @param aNeedle The element being searched for.
  41400. * @param aHaystack The non-empty array being searched.
  41401. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  41402. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41403. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41404. * closest element that is smaller than or greater than the one we are
  41405. * searching for, respectively, if the exact element cannot be found.
  41406. */
  41407. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  41408. // This function terminates when one of the following is true:
  41409. //
  41410. // 1. We find the exact element we are looking for.
  41411. //
  41412. // 2. We did not find the exact element, but we can return the index of
  41413. // the next-closest element.
  41414. //
  41415. // 3. We did not find the exact element, and there is no next-closest
  41416. // element than the one we are searching for, so we return -1.
  41417. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  41418. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  41419. if (cmp === 0) {
  41420. // Found the element we are looking for.
  41421. return mid;
  41422. }
  41423. else if (cmp > 0) {
  41424. // Our needle is greater than aHaystack[mid].
  41425. if (aHigh - mid > 1) {
  41426. // The element is in the upper half.
  41427. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  41428. }
  41429. // The exact needle element was not found in this haystack. Determine if
  41430. // we are in termination case (3) or (2) and return the appropriate thing.
  41431. if (aBias == exports.LEAST_UPPER_BOUND) {
  41432. return aHigh < aHaystack.length ? aHigh : -1;
  41433. } else {
  41434. return mid;
  41435. }
  41436. }
  41437. else {
  41438. // Our needle is less than aHaystack[mid].
  41439. if (mid - aLow > 1) {
  41440. // The element is in the lower half.
  41441. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  41442. }
  41443. // we are in termination case (3) or (2) and return the appropriate thing.
  41444. if (aBias == exports.LEAST_UPPER_BOUND) {
  41445. return mid;
  41446. } else {
  41447. return aLow < 0 ? -1 : aLow;
  41448. }
  41449. }
  41450. }
  41451. /**
  41452. * This is an implementation of binary search which will always try and return
  41453. * the index of the closest element if there is no exact hit. This is because
  41454. * mappings between original and generated line/col pairs are single points,
  41455. * and there is an implicit region between each of them, so a miss just means
  41456. * that you aren't on the very start of a region.
  41457. *
  41458. * @param aNeedle The element you are looking for.
  41459. * @param aHaystack The array that is being searched.
  41460. * @param aCompare A function which takes the needle and an element in the
  41461. * array and returns -1, 0, or 1 depending on whether the needle is less
  41462. * than, equal to, or greater than the element, respectively.
  41463. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  41464. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  41465. * closest element that is smaller than or greater than the one we are
  41466. * searching for, respectively, if the exact element cannot be found.
  41467. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  41468. */
  41469. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  41470. if (aHaystack.length === 0) {
  41471. return -1;
  41472. }
  41473. var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  41474. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  41475. if (index < 0) {
  41476. return -1;
  41477. }
  41478. // We have found either the exact element, or the next-closest element than
  41479. // the one we are searching for. However, there may be more than one such
  41480. // element. Make sure we always return the smallest of these.
  41481. while (index - 1 >= 0) {
  41482. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  41483. break;
  41484. }
  41485. --index;
  41486. }
  41487. return index;
  41488. };
  41489. } (binarySearch));
  41490. return binarySearch;
  41491. }
  41492. var quickSort = {};
  41493. /* -*- Mode: js; js-indent-level: 2; -*- */
  41494. var hasRequiredQuickSort;
  41495. function requireQuickSort () {
  41496. if (hasRequiredQuickSort) return quickSort;
  41497. hasRequiredQuickSort = 1;
  41498. /*
  41499. * Copyright 2011 Mozilla Foundation and contributors
  41500. * Licensed under the New BSD license. See LICENSE or:
  41501. * http://opensource.org/licenses/BSD-3-Clause
  41502. */
  41503. // It turns out that some (most?) JavaScript engines don't self-host
  41504. // `Array.prototype.sort`. This makes sense because C++ will likely remain
  41505. // faster than JS when doing raw CPU-intensive sorting. However, when using a
  41506. // custom comparator function, calling back and forth between the VM's C++ and
  41507. // JIT'd JS is rather slow *and* loses JIT type information, resulting in
  41508. // worse generated code for the comparator function than would be optimal. In
  41509. // fact, when sorting with a comparator, these costs outweigh the benefits of
  41510. // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
  41511. // a ~3500ms mean speed-up in `bench/bench.html`.
  41512. /**
  41513. * Swap the elements indexed by `x` and `y` in the array `ary`.
  41514. *
  41515. * @param {Array} ary
  41516. * The array.
  41517. * @param {Number} x
  41518. * The index of the first item.
  41519. * @param {Number} y
  41520. * The index of the second item.
  41521. */
  41522. function swap(ary, x, y) {
  41523. var temp = ary[x];
  41524. ary[x] = ary[y];
  41525. ary[y] = temp;
  41526. }
  41527. /**
  41528. * Returns a random integer within the range `low .. high` inclusive.
  41529. *
  41530. * @param {Number} low
  41531. * The lower bound on the range.
  41532. * @param {Number} high
  41533. * The upper bound on the range.
  41534. */
  41535. function randomIntInRange(low, high) {
  41536. return Math.round(low + (Math.random() * (high - low)));
  41537. }
  41538. /**
  41539. * The Quick Sort algorithm.
  41540. *
  41541. * @param {Array} ary
  41542. * An array to sort.
  41543. * @param {function} comparator
  41544. * Function to use to compare two items.
  41545. * @param {Number} p
  41546. * Start index of the array
  41547. * @param {Number} r
  41548. * End index of the array
  41549. */
  41550. function doQuickSort(ary, comparator, p, r) {
  41551. // If our lower bound is less than our upper bound, we (1) partition the
  41552. // array into two pieces and (2) recurse on each half. If it is not, this is
  41553. // the empty array and our base case.
  41554. if (p < r) {
  41555. // (1) Partitioning.
  41556. //
  41557. // The partitioning chooses a pivot between `p` and `r` and moves all
  41558. // elements that are less than or equal to the pivot to the before it, and
  41559. // all the elements that are greater than it after it. The effect is that
  41560. // once partition is done, the pivot is in the exact place it will be when
  41561. // the array is put in sorted order, and it will not need to be moved
  41562. // again. This runs in O(n) time.
  41563. // Always choose a random pivot so that an input array which is reverse
  41564. // sorted does not cause O(n^2) running time.
  41565. var pivotIndex = randomIntInRange(p, r);
  41566. var i = p - 1;
  41567. swap(ary, pivotIndex, r);
  41568. var pivot = ary[r];
  41569. // Immediately after `j` is incremented in this loop, the following hold
  41570. // true:
  41571. //
  41572. // * Every element in `ary[p .. i]` is less than or equal to the pivot.
  41573. //
  41574. // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
  41575. for (var j = p; j < r; j++) {
  41576. if (comparator(ary[j], pivot) <= 0) {
  41577. i += 1;
  41578. swap(ary, i, j);
  41579. }
  41580. }
  41581. swap(ary, i + 1, j);
  41582. var q = i + 1;
  41583. // (2) Recurse on each half.
  41584. doQuickSort(ary, comparator, p, q - 1);
  41585. doQuickSort(ary, comparator, q + 1, r);
  41586. }
  41587. }
  41588. /**
  41589. * Sort the given array in-place with the given comparator function.
  41590. *
  41591. * @param {Array} ary
  41592. * An array to sort.
  41593. * @param {function} comparator
  41594. * Function to use to compare two items.
  41595. */
  41596. quickSort.quickSort = function (ary, comparator) {
  41597. doQuickSort(ary, comparator, 0, ary.length - 1);
  41598. };
  41599. return quickSort;
  41600. }
  41601. /* -*- Mode: js; js-indent-level: 2; -*- */
  41602. var hasRequiredSourceMapConsumer;
  41603. function requireSourceMapConsumer () {
  41604. if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
  41605. hasRequiredSourceMapConsumer = 1;
  41606. /*
  41607. * Copyright 2011 Mozilla Foundation and contributors
  41608. * Licensed under the New BSD license. See LICENSE or:
  41609. * http://opensource.org/licenses/BSD-3-Clause
  41610. */
  41611. var util = /*@__PURE__*/ requireUtil();
  41612. var binarySearch = /*@__PURE__*/ requireBinarySearch();
  41613. var ArraySet = /*@__PURE__*/ requireArraySet().ArraySet;
  41614. var base64VLQ = /*@__PURE__*/ requireBase64Vlq();
  41615. var quickSort = /*@__PURE__*/ requireQuickSort().quickSort;
  41616. function SourceMapConsumer(aSourceMap, aSourceMapURL) {
  41617. var sourceMap = aSourceMap;
  41618. if (typeof aSourceMap === 'string') {
  41619. sourceMap = util.parseSourceMapInput(aSourceMap);
  41620. }
  41621. return sourceMap.sections != null
  41622. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  41623. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  41624. }
  41625. SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
  41626. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  41627. };
  41628. /**
  41629. * The version of the source mapping spec that we are consuming.
  41630. */
  41631. SourceMapConsumer.prototype._version = 3;
  41632. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  41633. // parsed mapping coordinates from the source map's "mappings" attribute. They
  41634. // are lazily instantiated, accessed via the `_generatedMappings` and
  41635. // `_originalMappings` getters respectively, and we only parse the mappings
  41636. // and create these arrays once queried for a source location. We jump through
  41637. // these hoops because there can be many thousands of mappings, and parsing
  41638. // them is expensive, so we only want to do it if we must.
  41639. //
  41640. // Each object in the arrays is of the form:
  41641. //
  41642. // {
  41643. // generatedLine: The line number in the generated code,
  41644. // generatedColumn: The column number in the generated code,
  41645. // source: The path to the original source file that generated this
  41646. // chunk of code,
  41647. // originalLine: The line number in the original source that
  41648. // corresponds to this chunk of generated code,
  41649. // originalColumn: The column number in the original source that
  41650. // corresponds to this chunk of generated code,
  41651. // name: The name of the original symbol which generated this chunk of
  41652. // code.
  41653. // }
  41654. //
  41655. // All properties except for `generatedLine` and `generatedColumn` can be
  41656. // `null`.
  41657. //
  41658. // `_generatedMappings` is ordered by the generated positions.
  41659. //
  41660. // `_originalMappings` is ordered by the original positions.
  41661. SourceMapConsumer.prototype.__generatedMappings = null;
  41662. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  41663. configurable: true,
  41664. enumerable: true,
  41665. get: function () {
  41666. if (!this.__generatedMappings) {
  41667. this._parseMappings(this._mappings, this.sourceRoot);
  41668. }
  41669. return this.__generatedMappings;
  41670. }
  41671. });
  41672. SourceMapConsumer.prototype.__originalMappings = null;
  41673. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  41674. configurable: true,
  41675. enumerable: true,
  41676. get: function () {
  41677. if (!this.__originalMappings) {
  41678. this._parseMappings(this._mappings, this.sourceRoot);
  41679. }
  41680. return this.__originalMappings;
  41681. }
  41682. });
  41683. SourceMapConsumer.prototype._charIsMappingSeparator =
  41684. function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
  41685. var c = aStr.charAt(index);
  41686. return c === ";" || c === ",";
  41687. };
  41688. /**
  41689. * Parse the mappings in a string in to a data structure which we can easily
  41690. * query (the ordered arrays in the `this.__generatedMappings` and
  41691. * `this.__originalMappings` properties).
  41692. */
  41693. SourceMapConsumer.prototype._parseMappings =
  41694. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  41695. throw new Error("Subclasses must implement _parseMappings");
  41696. };
  41697. SourceMapConsumer.GENERATED_ORDER = 1;
  41698. SourceMapConsumer.ORIGINAL_ORDER = 2;
  41699. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  41700. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  41701. /**
  41702. * Iterate over each mapping between an original source/line/column and a
  41703. * generated line/column in this source map.
  41704. *
  41705. * @param Function aCallback
  41706. * The function that is called with each mapping.
  41707. * @param Object aContext
  41708. * Optional. If specified, this object will be the value of `this` every
  41709. * time that `aCallback` is called.
  41710. * @param aOrder
  41711. * Either `SourceMapConsumer.GENERATED_ORDER` or
  41712. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  41713. * iterate over the mappings sorted by the generated file's line/column
  41714. * order or the original's source/line/column order, respectively. Defaults to
  41715. * `SourceMapConsumer.GENERATED_ORDER`.
  41716. */
  41717. SourceMapConsumer.prototype.eachMapping =
  41718. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  41719. var context = aContext || null;
  41720. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  41721. var mappings;
  41722. switch (order) {
  41723. case SourceMapConsumer.GENERATED_ORDER:
  41724. mappings = this._generatedMappings;
  41725. break;
  41726. case SourceMapConsumer.ORIGINAL_ORDER:
  41727. mappings = this._originalMappings;
  41728. break;
  41729. default:
  41730. throw new Error("Unknown order of iteration.");
  41731. }
  41732. var sourceRoot = this.sourceRoot;
  41733. mappings.map(function (mapping) {
  41734. var source = mapping.source === null ? null : this._sources.at(mapping.source);
  41735. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  41736. return {
  41737. source: source,
  41738. generatedLine: mapping.generatedLine,
  41739. generatedColumn: mapping.generatedColumn,
  41740. originalLine: mapping.originalLine,
  41741. originalColumn: mapping.originalColumn,
  41742. name: mapping.name === null ? null : this._names.at(mapping.name)
  41743. };
  41744. }, this).forEach(aCallback, context);
  41745. };
  41746. /**
  41747. * Returns all generated line and column information for the original source,
  41748. * line, and column provided. If no column is provided, returns all mappings
  41749. * corresponding to a either the line we are searching for or the next
  41750. * closest line that has any mappings. Otherwise, returns all mappings
  41751. * corresponding to the given line and either the column we are searching for
  41752. * or the next closest column that has any offsets.
  41753. *
  41754. * The only argument is an object with the following properties:
  41755. *
  41756. * - source: The filename of the original source.
  41757. * - line: The line number in the original source. The line number is 1-based.
  41758. * - column: Optional. the column number in the original source.
  41759. * The column number is 0-based.
  41760. *
  41761. * and an array of objects is returned, each with the following properties:
  41762. *
  41763. * - line: The line number in the generated source, or null. The
  41764. * line number is 1-based.
  41765. * - column: The column number in the generated source, or null.
  41766. * The column number is 0-based.
  41767. */
  41768. SourceMapConsumer.prototype.allGeneratedPositionsFor =
  41769. function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
  41770. var line = util.getArg(aArgs, 'line');
  41771. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  41772. // returns the index of the closest mapping less than the needle. By
  41773. // setting needle.originalColumn to 0, we thus find the last mapping for
  41774. // the given line, provided such a mapping exists.
  41775. var needle = {
  41776. source: util.getArg(aArgs, 'source'),
  41777. originalLine: line,
  41778. originalColumn: util.getArg(aArgs, 'column', 0)
  41779. };
  41780. needle.source = this._findSourceIndex(needle.source);
  41781. if (needle.source < 0) {
  41782. return [];
  41783. }
  41784. var mappings = [];
  41785. var index = this._findMapping(needle,
  41786. this._originalMappings,
  41787. "originalLine",
  41788. "originalColumn",
  41789. util.compareByOriginalPositions,
  41790. binarySearch.LEAST_UPPER_BOUND);
  41791. if (index >= 0) {
  41792. var mapping = this._originalMappings[index];
  41793. if (aArgs.column === undefined) {
  41794. var originalLine = mapping.originalLine;
  41795. // Iterate until either we run out of mappings, or we run into
  41796. // a mapping for a different line than the one we found. Since
  41797. // mappings are sorted, this is guaranteed to find all mappings for
  41798. // the line we found.
  41799. while (mapping && mapping.originalLine === originalLine) {
  41800. mappings.push({
  41801. line: util.getArg(mapping, 'generatedLine', null),
  41802. column: util.getArg(mapping, 'generatedColumn', null),
  41803. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  41804. });
  41805. mapping = this._originalMappings[++index];
  41806. }
  41807. } else {
  41808. var originalColumn = mapping.originalColumn;
  41809. // Iterate until either we run out of mappings, or we run into
  41810. // a mapping for a different line than the one we were searching for.
  41811. // Since mappings are sorted, this is guaranteed to find all mappings for
  41812. // the line we are searching for.
  41813. while (mapping &&
  41814. mapping.originalLine === line &&
  41815. mapping.originalColumn == originalColumn) {
  41816. mappings.push({
  41817. line: util.getArg(mapping, 'generatedLine', null),
  41818. column: util.getArg(mapping, 'generatedColumn', null),
  41819. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  41820. });
  41821. mapping = this._originalMappings[++index];
  41822. }
  41823. }
  41824. }
  41825. return mappings;
  41826. };
  41827. sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
  41828. /**
  41829. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  41830. * query for information about the original file positions by giving it a file
  41831. * position in the generated source.
  41832. *
  41833. * The first parameter is the raw source map (either as a JSON string, or
  41834. * already parsed to an object). According to the spec, source maps have the
  41835. * following attributes:
  41836. *
  41837. * - version: Which version of the source map spec this map is following.
  41838. * - sources: An array of URLs to the original source files.
  41839. * - names: An array of identifiers which can be referrenced by individual mappings.
  41840. * - sourceRoot: Optional. The URL root from which all sources are relative.
  41841. * - sourcesContent: Optional. An array of contents of the original source files.
  41842. * - mappings: A string of base64 VLQs which contain the actual mappings.
  41843. * - file: Optional. The generated file this source map is associated with.
  41844. *
  41845. * Here is an example source map, taken from the source map spec[0]:
  41846. *
  41847. * {
  41848. * version : 3,
  41849. * file: "out.js",
  41850. * sourceRoot : "",
  41851. * sources: ["foo.js", "bar.js"],
  41852. * names: ["src", "maps", "are", "fun"],
  41853. * mappings: "AA,AB;;ABCDE;"
  41854. * }
  41855. *
  41856. * The second parameter, if given, is a string whose value is the URL
  41857. * at which the source map was found. This URL is used to compute the
  41858. * sources array.
  41859. *
  41860. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  41861. */
  41862. function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
  41863. var sourceMap = aSourceMap;
  41864. if (typeof aSourceMap === 'string') {
  41865. sourceMap = util.parseSourceMapInput(aSourceMap);
  41866. }
  41867. var version = util.getArg(sourceMap, 'version');
  41868. var sources = util.getArg(sourceMap, 'sources');
  41869. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  41870. // requires the array) to play nice here.
  41871. var names = util.getArg(sourceMap, 'names', []);
  41872. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  41873. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  41874. var mappings = util.getArg(sourceMap, 'mappings');
  41875. var file = util.getArg(sourceMap, 'file', null);
  41876. // Once again, Sass deviates from the spec and supplies the version as a
  41877. // string rather than a number, so we use loose equality checking here.
  41878. if (version != this._version) {
  41879. throw new Error('Unsupported version: ' + version);
  41880. }
  41881. if (sourceRoot) {
  41882. sourceRoot = util.normalize(sourceRoot);
  41883. }
  41884. sources = sources
  41885. .map(String)
  41886. // Some source maps produce relative source paths like "./foo.js" instead of
  41887. // "foo.js". Normalize these first so that future comparisons will succeed.
  41888. // See bugzil.la/1090768.
  41889. .map(util.normalize)
  41890. // Always ensure that absolute sources are internally stored relative to
  41891. // the source root, if the source root is absolute. Not doing this would
  41892. // be particularly problematic when the source root is a prefix of the
  41893. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  41894. .map(function (source) {
  41895. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  41896. ? util.relative(sourceRoot, source)
  41897. : source;
  41898. });
  41899. // Pass `true` below to allow duplicate names and sources. While source maps
  41900. // are intended to be compressed and deduplicated, the TypeScript compiler
  41901. // sometimes generates source maps with duplicates in them. See Github issue
  41902. // #72 and bugzil.la/889492.
  41903. this._names = ArraySet.fromArray(names.map(String), true);
  41904. this._sources = ArraySet.fromArray(sources, true);
  41905. this._absoluteSources = this._sources.toArray().map(function (s) {
  41906. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  41907. });
  41908. this.sourceRoot = sourceRoot;
  41909. this.sourcesContent = sourcesContent;
  41910. this._mappings = mappings;
  41911. this._sourceMapURL = aSourceMapURL;
  41912. this.file = file;
  41913. }
  41914. BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  41915. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  41916. /**
  41917. * Utility function to find the index of a source. Returns -1 if not
  41918. * found.
  41919. */
  41920. BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
  41921. var relativeSource = aSource;
  41922. if (this.sourceRoot != null) {
  41923. relativeSource = util.relative(this.sourceRoot, relativeSource);
  41924. }
  41925. if (this._sources.has(relativeSource)) {
  41926. return this._sources.indexOf(relativeSource);
  41927. }
  41928. // Maybe aSource is an absolute URL as returned by |sources|. In
  41929. // this case we can't simply undo the transform.
  41930. var i;
  41931. for (i = 0; i < this._absoluteSources.length; ++i) {
  41932. if (this._absoluteSources[i] == aSource) {
  41933. return i;
  41934. }
  41935. }
  41936. return -1;
  41937. };
  41938. /**
  41939. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  41940. *
  41941. * @param SourceMapGenerator aSourceMap
  41942. * The source map that will be consumed.
  41943. * @param String aSourceMapURL
  41944. * The URL at which the source map can be found (optional)
  41945. * @returns BasicSourceMapConsumer
  41946. */
  41947. BasicSourceMapConsumer.fromSourceMap =
  41948. function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
  41949. var smc = Object.create(BasicSourceMapConsumer.prototype);
  41950. var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  41951. var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  41952. smc.sourceRoot = aSourceMap._sourceRoot;
  41953. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  41954. smc.sourceRoot);
  41955. smc.file = aSourceMap._file;
  41956. smc._sourceMapURL = aSourceMapURL;
  41957. smc._absoluteSources = smc._sources.toArray().map(function (s) {
  41958. return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
  41959. });
  41960. // Because we are modifying the entries (by converting string sources and
  41961. // names to indices into the sources and names ArraySets), we have to make
  41962. // a copy of the entry or else bad things happen. Shared mutable state
  41963. // strikes again! See github issue #191.
  41964. var generatedMappings = aSourceMap._mappings.toArray().slice();
  41965. var destGeneratedMappings = smc.__generatedMappings = [];
  41966. var destOriginalMappings = smc.__originalMappings = [];
  41967. for (var i = 0, length = generatedMappings.length; i < length; i++) {
  41968. var srcMapping = generatedMappings[i];
  41969. var destMapping = new Mapping;
  41970. destMapping.generatedLine = srcMapping.generatedLine;
  41971. destMapping.generatedColumn = srcMapping.generatedColumn;
  41972. if (srcMapping.source) {
  41973. destMapping.source = sources.indexOf(srcMapping.source);
  41974. destMapping.originalLine = srcMapping.originalLine;
  41975. destMapping.originalColumn = srcMapping.originalColumn;
  41976. if (srcMapping.name) {
  41977. destMapping.name = names.indexOf(srcMapping.name);
  41978. }
  41979. destOriginalMappings.push(destMapping);
  41980. }
  41981. destGeneratedMappings.push(destMapping);
  41982. }
  41983. quickSort(smc.__originalMappings, util.compareByOriginalPositions);
  41984. return smc;
  41985. };
  41986. /**
  41987. * The version of the source mapping spec that we are consuming.
  41988. */
  41989. BasicSourceMapConsumer.prototype._version = 3;
  41990. /**
  41991. * The list of original sources.
  41992. */
  41993. Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
  41994. get: function () {
  41995. return this._absoluteSources.slice();
  41996. }
  41997. });
  41998. /**
  41999. * Provide the JIT with a nice shape / hidden class.
  42000. */
  42001. function Mapping() {
  42002. this.generatedLine = 0;
  42003. this.generatedColumn = 0;
  42004. this.source = null;
  42005. this.originalLine = null;
  42006. this.originalColumn = null;
  42007. this.name = null;
  42008. }
  42009. /**
  42010. * Parse the mappings in a string in to a data structure which we can easily
  42011. * query (the ordered arrays in the `this.__generatedMappings` and
  42012. * `this.__originalMappings` properties).
  42013. */
  42014. BasicSourceMapConsumer.prototype._parseMappings =
  42015. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42016. var generatedLine = 1;
  42017. var previousGeneratedColumn = 0;
  42018. var previousOriginalLine = 0;
  42019. var previousOriginalColumn = 0;
  42020. var previousSource = 0;
  42021. var previousName = 0;
  42022. var length = aStr.length;
  42023. var index = 0;
  42024. var cachedSegments = {};
  42025. var temp = {};
  42026. var originalMappings = [];
  42027. var generatedMappings = [];
  42028. var mapping, str, segment, end, value;
  42029. while (index < length) {
  42030. if (aStr.charAt(index) === ';') {
  42031. generatedLine++;
  42032. index++;
  42033. previousGeneratedColumn = 0;
  42034. }
  42035. else if (aStr.charAt(index) === ',') {
  42036. index++;
  42037. }
  42038. else {
  42039. mapping = new Mapping();
  42040. mapping.generatedLine = generatedLine;
  42041. // Because each offset is encoded relative to the previous one,
  42042. // many segments often have the same encoding. We can exploit this
  42043. // fact by caching the parsed variable length fields of each segment,
  42044. // allowing us to avoid a second parse if we encounter the same
  42045. // segment again.
  42046. for (end = index; end < length; end++) {
  42047. if (this._charIsMappingSeparator(aStr, end)) {
  42048. break;
  42049. }
  42050. }
  42051. str = aStr.slice(index, end);
  42052. segment = cachedSegments[str];
  42053. if (segment) {
  42054. index += str.length;
  42055. } else {
  42056. segment = [];
  42057. while (index < end) {
  42058. base64VLQ.decode(aStr, index, temp);
  42059. value = temp.value;
  42060. index = temp.rest;
  42061. segment.push(value);
  42062. }
  42063. if (segment.length === 2) {
  42064. throw new Error('Found a source, but no line and column');
  42065. }
  42066. if (segment.length === 3) {
  42067. throw new Error('Found a source and line, but no column');
  42068. }
  42069. cachedSegments[str] = segment;
  42070. }
  42071. // Generated column.
  42072. mapping.generatedColumn = previousGeneratedColumn + segment[0];
  42073. previousGeneratedColumn = mapping.generatedColumn;
  42074. if (segment.length > 1) {
  42075. // Original source.
  42076. mapping.source = previousSource + segment[1];
  42077. previousSource += segment[1];
  42078. // Original line.
  42079. mapping.originalLine = previousOriginalLine + segment[2];
  42080. previousOriginalLine = mapping.originalLine;
  42081. // Lines are stored 0-based
  42082. mapping.originalLine += 1;
  42083. // Original column.
  42084. mapping.originalColumn = previousOriginalColumn + segment[3];
  42085. previousOriginalColumn = mapping.originalColumn;
  42086. if (segment.length > 4) {
  42087. // Original name.
  42088. mapping.name = previousName + segment[4];
  42089. previousName += segment[4];
  42090. }
  42091. }
  42092. generatedMappings.push(mapping);
  42093. if (typeof mapping.originalLine === 'number') {
  42094. originalMappings.push(mapping);
  42095. }
  42096. }
  42097. }
  42098. quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
  42099. this.__generatedMappings = generatedMappings;
  42100. quickSort(originalMappings, util.compareByOriginalPositions);
  42101. this.__originalMappings = originalMappings;
  42102. };
  42103. /**
  42104. * Find the mapping that best matches the hypothetical "needle" mapping that
  42105. * we are searching for in the given "haystack" of mappings.
  42106. */
  42107. BasicSourceMapConsumer.prototype._findMapping =
  42108. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  42109. aColumnName, aComparator, aBias) {
  42110. // To return the position we are searching for, we must first find the
  42111. // mapping for the given position and then return the opposite position it
  42112. // points to. Because the mappings are sorted, we can use binary search to
  42113. // find the best mapping.
  42114. if (aNeedle[aLineName] <= 0) {
  42115. throw new TypeError('Line must be greater than or equal to 1, got '
  42116. + aNeedle[aLineName]);
  42117. }
  42118. if (aNeedle[aColumnName] < 0) {
  42119. throw new TypeError('Column must be greater than or equal to 0, got '
  42120. + aNeedle[aColumnName]);
  42121. }
  42122. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  42123. };
  42124. /**
  42125. * Compute the last column for each generated mapping. The last column is
  42126. * inclusive.
  42127. */
  42128. BasicSourceMapConsumer.prototype.computeColumnSpans =
  42129. function SourceMapConsumer_computeColumnSpans() {
  42130. for (var index = 0; index < this._generatedMappings.length; ++index) {
  42131. var mapping = this._generatedMappings[index];
  42132. // Mappings do not contain a field for the last generated columnt. We
  42133. // can come up with an optimistic estimate, however, by assuming that
  42134. // mappings are contiguous (i.e. given two consecutive mappings, the
  42135. // first mapping ends where the second one starts).
  42136. if (index + 1 < this._generatedMappings.length) {
  42137. var nextMapping = this._generatedMappings[index + 1];
  42138. if (mapping.generatedLine === nextMapping.generatedLine) {
  42139. mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
  42140. continue;
  42141. }
  42142. }
  42143. // The last mapping for each line spans the entire line.
  42144. mapping.lastGeneratedColumn = Infinity;
  42145. }
  42146. };
  42147. /**
  42148. * Returns the original source, line, and column information for the generated
  42149. * source's line and column positions provided. The only argument is an object
  42150. * with the following properties:
  42151. *
  42152. * - line: The line number in the generated source. The line number
  42153. * is 1-based.
  42154. * - column: The column number in the generated source. The column
  42155. * number is 0-based.
  42156. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42157. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42158. * closest element that is smaller than or greater than the one we are
  42159. * searching for, respectively, if the exact element cannot be found.
  42160. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42161. *
  42162. * and an object is returned with the following properties:
  42163. *
  42164. * - source: The original source file, or null.
  42165. * - line: The line number in the original source, or null. The
  42166. * line number is 1-based.
  42167. * - column: The column number in the original source, or null. The
  42168. * column number is 0-based.
  42169. * - name: The original identifier, or null.
  42170. */
  42171. BasicSourceMapConsumer.prototype.originalPositionFor =
  42172. function SourceMapConsumer_originalPositionFor(aArgs) {
  42173. var needle = {
  42174. generatedLine: util.getArg(aArgs, 'line'),
  42175. generatedColumn: util.getArg(aArgs, 'column')
  42176. };
  42177. var index = this._findMapping(
  42178. needle,
  42179. this._generatedMappings,
  42180. "generatedLine",
  42181. "generatedColumn",
  42182. util.compareByGeneratedPositionsDeflated,
  42183. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42184. );
  42185. if (index >= 0) {
  42186. var mapping = this._generatedMappings[index];
  42187. if (mapping.generatedLine === needle.generatedLine) {
  42188. var source = util.getArg(mapping, 'source', null);
  42189. if (source !== null) {
  42190. source = this._sources.at(source);
  42191. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  42192. }
  42193. var name = util.getArg(mapping, 'name', null);
  42194. if (name !== null) {
  42195. name = this._names.at(name);
  42196. }
  42197. return {
  42198. source: source,
  42199. line: util.getArg(mapping, 'originalLine', null),
  42200. column: util.getArg(mapping, 'originalColumn', null),
  42201. name: name
  42202. };
  42203. }
  42204. }
  42205. return {
  42206. source: null,
  42207. line: null,
  42208. column: null,
  42209. name: null
  42210. };
  42211. };
  42212. /**
  42213. * Return true if we have the source content for every source in the source
  42214. * map, false otherwise.
  42215. */
  42216. BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
  42217. function BasicSourceMapConsumer_hasContentsOfAllSources() {
  42218. if (!this.sourcesContent) {
  42219. return false;
  42220. }
  42221. return this.sourcesContent.length >= this._sources.size() &&
  42222. !this.sourcesContent.some(function (sc) { return sc == null; });
  42223. };
  42224. /**
  42225. * Returns the original source content. The only argument is the url of the
  42226. * original source file. Returns null if no original source content is
  42227. * available.
  42228. */
  42229. BasicSourceMapConsumer.prototype.sourceContentFor =
  42230. function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42231. if (!this.sourcesContent) {
  42232. return null;
  42233. }
  42234. var index = this._findSourceIndex(aSource);
  42235. if (index >= 0) {
  42236. return this.sourcesContent[index];
  42237. }
  42238. var relativeSource = aSource;
  42239. if (this.sourceRoot != null) {
  42240. relativeSource = util.relative(this.sourceRoot, relativeSource);
  42241. }
  42242. var url;
  42243. if (this.sourceRoot != null
  42244. && (url = util.urlParse(this.sourceRoot))) {
  42245. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  42246. // many users. We can help them out when they expect file:// URIs to
  42247. // behave like it would if they were running a local HTTP server. See
  42248. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  42249. var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  42250. if (url.scheme == "file"
  42251. && this._sources.has(fileUriAbsPath)) {
  42252. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  42253. }
  42254. if ((!url.path || url.path == "/")
  42255. && this._sources.has("/" + relativeSource)) {
  42256. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  42257. }
  42258. }
  42259. // This function is used recursively from
  42260. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  42261. // don't want to throw if we can't find the source - we just want to
  42262. // return null, so we provide a flag to exit gracefully.
  42263. if (nullOnMissing) {
  42264. return null;
  42265. }
  42266. else {
  42267. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  42268. }
  42269. };
  42270. /**
  42271. * Returns the generated line and column information for the original source,
  42272. * line, and column positions provided. The only argument is an object with
  42273. * the following properties:
  42274. *
  42275. * - source: The filename of the original source.
  42276. * - line: The line number in the original source. The line number
  42277. * is 1-based.
  42278. * - column: The column number in the original source. The column
  42279. * number is 0-based.
  42280. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  42281. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  42282. * closest element that is smaller than or greater than the one we are
  42283. * searching for, respectively, if the exact element cannot be found.
  42284. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  42285. *
  42286. * and an object is returned with the following properties:
  42287. *
  42288. * - line: The line number in the generated source, or null. The
  42289. * line number is 1-based.
  42290. * - column: The column number in the generated source, or null.
  42291. * The column number is 0-based.
  42292. */
  42293. BasicSourceMapConsumer.prototype.generatedPositionFor =
  42294. function SourceMapConsumer_generatedPositionFor(aArgs) {
  42295. var source = util.getArg(aArgs, 'source');
  42296. source = this._findSourceIndex(source);
  42297. if (source < 0) {
  42298. return {
  42299. line: null,
  42300. column: null,
  42301. lastColumn: null
  42302. };
  42303. }
  42304. var needle = {
  42305. source: source,
  42306. originalLine: util.getArg(aArgs, 'line'),
  42307. originalColumn: util.getArg(aArgs, 'column')
  42308. };
  42309. var index = this._findMapping(
  42310. needle,
  42311. this._originalMappings,
  42312. "originalLine",
  42313. "originalColumn",
  42314. util.compareByOriginalPositions,
  42315. util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
  42316. );
  42317. if (index >= 0) {
  42318. var mapping = this._originalMappings[index];
  42319. if (mapping.source === needle.source) {
  42320. return {
  42321. line: util.getArg(mapping, 'generatedLine', null),
  42322. column: util.getArg(mapping, 'generatedColumn', null),
  42323. lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
  42324. };
  42325. }
  42326. }
  42327. return {
  42328. line: null,
  42329. column: null,
  42330. lastColumn: null
  42331. };
  42332. };
  42333. sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
  42334. /**
  42335. * An IndexedSourceMapConsumer instance represents a parsed source map which
  42336. * we can query for information. It differs from BasicSourceMapConsumer in
  42337. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  42338. * input.
  42339. *
  42340. * The first parameter is a raw source map (either as a JSON string, or already
  42341. * parsed to an object). According to the spec for indexed source maps, they
  42342. * have the following attributes:
  42343. *
  42344. * - version: Which version of the source map spec this map is following.
  42345. * - file: Optional. The generated file this source map is associated with.
  42346. * - sections: A list of section definitions.
  42347. *
  42348. * Each value under the "sections" field has two fields:
  42349. * - offset: The offset into the original specified at which this section
  42350. * begins to apply, defined as an object with a "line" and "column"
  42351. * field.
  42352. * - map: A source map definition. This source map could also be indexed,
  42353. * but doesn't have to be.
  42354. *
  42355. * Instead of the "map" field, it's also possible to have a "url" field
  42356. * specifying a URL to retrieve a source map from, but that's currently
  42357. * unsupported.
  42358. *
  42359. * Here's an example source map, taken from the source map spec[0], but
  42360. * modified to omit a section which uses the "url" field.
  42361. *
  42362. * {
  42363. * version : 3,
  42364. * file: "app.js",
  42365. * sections: [{
  42366. * offset: {line:100, column:10},
  42367. * map: {
  42368. * version : 3,
  42369. * file: "section.js",
  42370. * sources: ["foo.js", "bar.js"],
  42371. * names: ["src", "maps", "are", "fun"],
  42372. * mappings: "AAAA,E;;ABCDE;"
  42373. * }
  42374. * }],
  42375. * }
  42376. *
  42377. * The second parameter, if given, is a string whose value is the URL
  42378. * at which the source map was found. This URL is used to compute the
  42379. * sources array.
  42380. *
  42381. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  42382. */
  42383. function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
  42384. var sourceMap = aSourceMap;
  42385. if (typeof aSourceMap === 'string') {
  42386. sourceMap = util.parseSourceMapInput(aSourceMap);
  42387. }
  42388. var version = util.getArg(sourceMap, 'version');
  42389. var sections = util.getArg(sourceMap, 'sections');
  42390. if (version != this._version) {
  42391. throw new Error('Unsupported version: ' + version);
  42392. }
  42393. this._sources = new ArraySet();
  42394. this._names = new ArraySet();
  42395. var lastOffset = {
  42396. line: -1,
  42397. column: 0
  42398. };
  42399. this._sections = sections.map(function (s) {
  42400. if (s.url) {
  42401. // The url field will require support for asynchronicity.
  42402. // See https://github.com/mozilla/source-map/issues/16
  42403. throw new Error('Support for url field in sections not implemented.');
  42404. }
  42405. var offset = util.getArg(s, 'offset');
  42406. var offsetLine = util.getArg(offset, 'line');
  42407. var offsetColumn = util.getArg(offset, 'column');
  42408. if (offsetLine < lastOffset.line ||
  42409. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  42410. throw new Error('Section offsets must be ordered and non-overlapping.');
  42411. }
  42412. lastOffset = offset;
  42413. return {
  42414. generatedOffset: {
  42415. // The offset fields are 0-based, but we use 1-based indices when
  42416. // encoding/decoding from VLQ.
  42417. generatedLine: offsetLine + 1,
  42418. generatedColumn: offsetColumn + 1
  42419. },
  42420. consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
  42421. }
  42422. });
  42423. }
  42424. IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
  42425. IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
  42426. /**
  42427. * The version of the source mapping spec that we are consuming.
  42428. */
  42429. IndexedSourceMapConsumer.prototype._version = 3;
  42430. /**
  42431. * The list of original sources.
  42432. */
  42433. Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
  42434. get: function () {
  42435. var sources = [];
  42436. for (var i = 0; i < this._sections.length; i++) {
  42437. for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
  42438. sources.push(this._sections[i].consumer.sources[j]);
  42439. }
  42440. }
  42441. return sources;
  42442. }
  42443. });
  42444. /**
  42445. * Returns the original source, line, and column information for the generated
  42446. * source's line and column positions provided. The only argument is an object
  42447. * with the following properties:
  42448. *
  42449. * - line: The line number in the generated source. The line number
  42450. * is 1-based.
  42451. * - column: The column number in the generated source. The column
  42452. * number is 0-based.
  42453. *
  42454. * and an object is returned with the following properties:
  42455. *
  42456. * - source: The original source file, or null.
  42457. * - line: The line number in the original source, or null. The
  42458. * line number is 1-based.
  42459. * - column: The column number in the original source, or null. The
  42460. * column number is 0-based.
  42461. * - name: The original identifier, or null.
  42462. */
  42463. IndexedSourceMapConsumer.prototype.originalPositionFor =
  42464. function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
  42465. var needle = {
  42466. generatedLine: util.getArg(aArgs, 'line'),
  42467. generatedColumn: util.getArg(aArgs, 'column')
  42468. };
  42469. // Find the section containing the generated position we're trying to map
  42470. // to an original position.
  42471. var sectionIndex = binarySearch.search(needle, this._sections,
  42472. function(needle, section) {
  42473. var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
  42474. if (cmp) {
  42475. return cmp;
  42476. }
  42477. return (needle.generatedColumn -
  42478. section.generatedOffset.generatedColumn);
  42479. });
  42480. var section = this._sections[sectionIndex];
  42481. if (!section) {
  42482. return {
  42483. source: null,
  42484. line: null,
  42485. column: null,
  42486. name: null
  42487. };
  42488. }
  42489. return section.consumer.originalPositionFor({
  42490. line: needle.generatedLine -
  42491. (section.generatedOffset.generatedLine - 1),
  42492. column: needle.generatedColumn -
  42493. (section.generatedOffset.generatedLine === needle.generatedLine
  42494. ? section.generatedOffset.generatedColumn - 1
  42495. : 0),
  42496. bias: aArgs.bias
  42497. });
  42498. };
  42499. /**
  42500. * Return true if we have the source content for every source in the source
  42501. * map, false otherwise.
  42502. */
  42503. IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
  42504. function IndexedSourceMapConsumer_hasContentsOfAllSources() {
  42505. return this._sections.every(function (s) {
  42506. return s.consumer.hasContentsOfAllSources();
  42507. });
  42508. };
  42509. /**
  42510. * Returns the original source content. The only argument is the url of the
  42511. * original source file. Returns null if no original source content is
  42512. * available.
  42513. */
  42514. IndexedSourceMapConsumer.prototype.sourceContentFor =
  42515. function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
  42516. for (var i = 0; i < this._sections.length; i++) {
  42517. var section = this._sections[i];
  42518. var content = section.consumer.sourceContentFor(aSource, true);
  42519. if (content) {
  42520. return content;
  42521. }
  42522. }
  42523. if (nullOnMissing) {
  42524. return null;
  42525. }
  42526. else {
  42527. throw new Error('"' + aSource + '" is not in the SourceMap.');
  42528. }
  42529. };
  42530. /**
  42531. * Returns the generated line and column information for the original source,
  42532. * line, and column positions provided. The only argument is an object with
  42533. * the following properties:
  42534. *
  42535. * - source: The filename of the original source.
  42536. * - line: The line number in the original source. The line number
  42537. * is 1-based.
  42538. * - column: The column number in the original source. The column
  42539. * number is 0-based.
  42540. *
  42541. * and an object is returned with the following properties:
  42542. *
  42543. * - line: The line number in the generated source, or null. The
  42544. * line number is 1-based.
  42545. * - column: The column number in the generated source, or null.
  42546. * The column number is 0-based.
  42547. */
  42548. IndexedSourceMapConsumer.prototype.generatedPositionFor =
  42549. function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
  42550. for (var i = 0; i < this._sections.length; i++) {
  42551. var section = this._sections[i];
  42552. // Only consider this section if the requested source is in the list of
  42553. // sources of the consumer.
  42554. if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
  42555. continue;
  42556. }
  42557. var generatedPosition = section.consumer.generatedPositionFor(aArgs);
  42558. if (generatedPosition) {
  42559. var ret = {
  42560. line: generatedPosition.line +
  42561. (section.generatedOffset.generatedLine - 1),
  42562. column: generatedPosition.column +
  42563. (section.generatedOffset.generatedLine === generatedPosition.line
  42564. ? section.generatedOffset.generatedColumn - 1
  42565. : 0)
  42566. };
  42567. return ret;
  42568. }
  42569. }
  42570. return {
  42571. line: null,
  42572. column: null
  42573. };
  42574. };
  42575. /**
  42576. * Parse the mappings in a string in to a data structure which we can easily
  42577. * query (the ordered arrays in the `this.__generatedMappings` and
  42578. * `this.__originalMappings` properties).
  42579. */
  42580. IndexedSourceMapConsumer.prototype._parseMappings =
  42581. function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  42582. this.__generatedMappings = [];
  42583. this.__originalMappings = [];
  42584. for (var i = 0; i < this._sections.length; i++) {
  42585. var section = this._sections[i];
  42586. var sectionMappings = section.consumer._generatedMappings;
  42587. for (var j = 0; j < sectionMappings.length; j++) {
  42588. var mapping = sectionMappings[j];
  42589. var source = section.consumer._sources.at(mapping.source);
  42590. source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
  42591. this._sources.add(source);
  42592. source = this._sources.indexOf(source);
  42593. var name = null;
  42594. if (mapping.name) {
  42595. name = section.consumer._names.at(mapping.name);
  42596. this._names.add(name);
  42597. name = this._names.indexOf(name);
  42598. }
  42599. // The mappings coming from the consumer for the section have
  42600. // generated positions relative to the start of the section, so we
  42601. // need to offset them to be relative to the start of the concatenated
  42602. // generated file.
  42603. var adjustedMapping = {
  42604. source: source,
  42605. generatedLine: mapping.generatedLine +
  42606. (section.generatedOffset.generatedLine - 1),
  42607. generatedColumn: mapping.generatedColumn +
  42608. (section.generatedOffset.generatedLine === mapping.generatedLine
  42609. ? section.generatedOffset.generatedColumn - 1
  42610. : 0),
  42611. originalLine: mapping.originalLine,
  42612. originalColumn: mapping.originalColumn,
  42613. name: name
  42614. };
  42615. this.__generatedMappings.push(adjustedMapping);
  42616. if (typeof adjustedMapping.originalLine === 'number') {
  42617. this.__originalMappings.push(adjustedMapping);
  42618. }
  42619. }
  42620. }
  42621. quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
  42622. quickSort(this.__originalMappings, util.compareByOriginalPositions);
  42623. };
  42624. sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  42625. return sourceMapConsumer;
  42626. }
  42627. var sourceNode = {};
  42628. /* -*- Mode: js; js-indent-level: 2; -*- */
  42629. var hasRequiredSourceNode;
  42630. function requireSourceNode () {
  42631. if (hasRequiredSourceNode) return sourceNode;
  42632. hasRequiredSourceNode = 1;
  42633. /*
  42634. * Copyright 2011 Mozilla Foundation and contributors
  42635. * Licensed under the New BSD license. See LICENSE or:
  42636. * http://opensource.org/licenses/BSD-3-Clause
  42637. */
  42638. var SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  42639. var util = /*@__PURE__*/ requireUtil();
  42640. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  42641. // operating systems these days (capturing the result).
  42642. var REGEX_NEWLINE = /(\r?\n)/;
  42643. // Newline character code for charCodeAt() comparisons
  42644. var NEWLINE_CODE = 10;
  42645. // Private symbol for identifying `SourceNode`s when multiple versions of
  42646. // the source-map library are loaded. This MUST NOT CHANGE across
  42647. // versions!
  42648. var isSourceNode = "$$$isSourceNode$$$";
  42649. /**
  42650. * SourceNodes provide a way to abstract over interpolating/concatenating
  42651. * snippets of generated JavaScript source code while maintaining the line and
  42652. * column information associated with the original source code.
  42653. *
  42654. * @param aLine The original line number.
  42655. * @param aColumn The original column number.
  42656. * @param aSource The original source's filename.
  42657. * @param aChunks Optional. An array of strings which are snippets of
  42658. * generated JS, or other SourceNodes.
  42659. * @param aName The original identifier.
  42660. */
  42661. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  42662. this.children = [];
  42663. this.sourceContents = {};
  42664. this.line = aLine == null ? null : aLine;
  42665. this.column = aColumn == null ? null : aColumn;
  42666. this.source = aSource == null ? null : aSource;
  42667. this.name = aName == null ? null : aName;
  42668. this[isSourceNode] = true;
  42669. if (aChunks != null) this.add(aChunks);
  42670. }
  42671. /**
  42672. * Creates a SourceNode from generated code and a SourceMapConsumer.
  42673. *
  42674. * @param aGeneratedCode The generated code
  42675. * @param aSourceMapConsumer The SourceMap for the generated code
  42676. * @param aRelativePath Optional. The path that relative sources in the
  42677. * SourceMapConsumer should be relative to.
  42678. */
  42679. SourceNode.fromStringWithSourceMap =
  42680. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  42681. // The SourceNode we want to fill with the generated code
  42682. // and the SourceMap
  42683. var node = new SourceNode();
  42684. // All even indices of this array are one line of the generated code,
  42685. // while all odd indices are the newlines between two adjacent lines
  42686. // (since `REGEX_NEWLINE` captures its match).
  42687. // Processed fragments are accessed by calling `shiftNextLine`.
  42688. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  42689. var remainingLinesIndex = 0;
  42690. var shiftNextLine = function() {
  42691. var lineContents = getNextLine();
  42692. // The last line of a file might not have a newline.
  42693. var newLine = getNextLine() || "";
  42694. return lineContents + newLine;
  42695. function getNextLine() {
  42696. return remainingLinesIndex < remainingLines.length ?
  42697. remainingLines[remainingLinesIndex++] : undefined;
  42698. }
  42699. };
  42700. // We need to remember the position of "remainingLines"
  42701. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  42702. // The generate SourceNodes we need a code range.
  42703. // To extract it current and last mapping is used.
  42704. // Here we store the last mapping.
  42705. var lastMapping = null;
  42706. aSourceMapConsumer.eachMapping(function (mapping) {
  42707. if (lastMapping !== null) {
  42708. // We add the code from "lastMapping" to "mapping":
  42709. // First check if there is a new line in between.
  42710. if (lastGeneratedLine < mapping.generatedLine) {
  42711. // Associate first line with "lastMapping"
  42712. addMappingWithCode(lastMapping, shiftNextLine());
  42713. lastGeneratedLine++;
  42714. lastGeneratedColumn = 0;
  42715. // The remaining code is added without mapping
  42716. } else {
  42717. // There is no new line in between.
  42718. // Associate the code between "lastGeneratedColumn" and
  42719. // "mapping.generatedColumn" with "lastMapping"
  42720. var nextLine = remainingLines[remainingLinesIndex] || '';
  42721. var code = nextLine.substr(0, mapping.generatedColumn -
  42722. lastGeneratedColumn);
  42723. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  42724. lastGeneratedColumn);
  42725. lastGeneratedColumn = mapping.generatedColumn;
  42726. addMappingWithCode(lastMapping, code);
  42727. // No more remaining code, continue
  42728. lastMapping = mapping;
  42729. return;
  42730. }
  42731. }
  42732. // We add the generated code until the first mapping
  42733. // to the SourceNode without any mapping.
  42734. // Each line is added as separate string.
  42735. while (lastGeneratedLine < mapping.generatedLine) {
  42736. node.add(shiftNextLine());
  42737. lastGeneratedLine++;
  42738. }
  42739. if (lastGeneratedColumn < mapping.generatedColumn) {
  42740. var nextLine = remainingLines[remainingLinesIndex] || '';
  42741. node.add(nextLine.substr(0, mapping.generatedColumn));
  42742. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  42743. lastGeneratedColumn = mapping.generatedColumn;
  42744. }
  42745. lastMapping = mapping;
  42746. }, this);
  42747. // We have processed all mappings.
  42748. if (remainingLinesIndex < remainingLines.length) {
  42749. if (lastMapping) {
  42750. // Associate the remaining code in the current line with "lastMapping"
  42751. addMappingWithCode(lastMapping, shiftNextLine());
  42752. }
  42753. // and add the remaining lines without any mapping
  42754. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  42755. }
  42756. // Copy sourcesContent into SourceNode
  42757. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  42758. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  42759. if (content != null) {
  42760. if (aRelativePath != null) {
  42761. sourceFile = util.join(aRelativePath, sourceFile);
  42762. }
  42763. node.setSourceContent(sourceFile, content);
  42764. }
  42765. });
  42766. return node;
  42767. function addMappingWithCode(mapping, code) {
  42768. if (mapping === null || mapping.source === undefined) {
  42769. node.add(code);
  42770. } else {
  42771. var source = aRelativePath
  42772. ? util.join(aRelativePath, mapping.source)
  42773. : mapping.source;
  42774. node.add(new SourceNode(mapping.originalLine,
  42775. mapping.originalColumn,
  42776. source,
  42777. code,
  42778. mapping.name));
  42779. }
  42780. }
  42781. };
  42782. /**
  42783. * Add a chunk of generated JS to this source node.
  42784. *
  42785. * @param aChunk A string snippet of generated JS code, another instance of
  42786. * SourceNode, or an array where each member is one of those things.
  42787. */
  42788. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  42789. if (Array.isArray(aChunk)) {
  42790. aChunk.forEach(function (chunk) {
  42791. this.add(chunk);
  42792. }, this);
  42793. }
  42794. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42795. if (aChunk) {
  42796. this.children.push(aChunk);
  42797. }
  42798. }
  42799. else {
  42800. throw new TypeError(
  42801. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42802. );
  42803. }
  42804. return this;
  42805. };
  42806. /**
  42807. * Add a chunk of generated JS to the beginning of this source node.
  42808. *
  42809. * @param aChunk A string snippet of generated JS code, another instance of
  42810. * SourceNode, or an array where each member is one of those things.
  42811. */
  42812. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  42813. if (Array.isArray(aChunk)) {
  42814. for (var i = aChunk.length-1; i >= 0; i--) {
  42815. this.prepend(aChunk[i]);
  42816. }
  42817. }
  42818. else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  42819. this.children.unshift(aChunk);
  42820. }
  42821. else {
  42822. throw new TypeError(
  42823. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  42824. );
  42825. }
  42826. return this;
  42827. };
  42828. /**
  42829. * Walk over the tree of JS snippets in this node and its children. The
  42830. * walking function is called once for each snippet of JS and is passed that
  42831. * snippet and the its original associated source's line/column location.
  42832. *
  42833. * @param aFn The traversal function.
  42834. */
  42835. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  42836. var chunk;
  42837. for (var i = 0, len = this.children.length; i < len; i++) {
  42838. chunk = this.children[i];
  42839. if (chunk[isSourceNode]) {
  42840. chunk.walk(aFn);
  42841. }
  42842. else {
  42843. if (chunk !== '') {
  42844. aFn(chunk, { source: this.source,
  42845. line: this.line,
  42846. column: this.column,
  42847. name: this.name });
  42848. }
  42849. }
  42850. }
  42851. };
  42852. /**
  42853. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  42854. * each of `this.children`.
  42855. *
  42856. * @param aSep The separator.
  42857. */
  42858. SourceNode.prototype.join = function SourceNode_join(aSep) {
  42859. var newChildren;
  42860. var i;
  42861. var len = this.children.length;
  42862. if (len > 0) {
  42863. newChildren = [];
  42864. for (i = 0; i < len-1; i++) {
  42865. newChildren.push(this.children[i]);
  42866. newChildren.push(aSep);
  42867. }
  42868. newChildren.push(this.children[i]);
  42869. this.children = newChildren;
  42870. }
  42871. return this;
  42872. };
  42873. /**
  42874. * Call String.prototype.replace on the very right-most source snippet. Useful
  42875. * for trimming whitespace from the end of a source node, etc.
  42876. *
  42877. * @param aPattern The pattern to replace.
  42878. * @param aReplacement The thing to replace the pattern with.
  42879. */
  42880. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  42881. var lastChild = this.children[this.children.length - 1];
  42882. if (lastChild[isSourceNode]) {
  42883. lastChild.replaceRight(aPattern, aReplacement);
  42884. }
  42885. else if (typeof lastChild === 'string') {
  42886. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  42887. }
  42888. else {
  42889. this.children.push(''.replace(aPattern, aReplacement));
  42890. }
  42891. return this;
  42892. };
  42893. /**
  42894. * Set the source content for a source file. This will be added to the SourceMapGenerator
  42895. * in the sourcesContent field.
  42896. *
  42897. * @param aSourceFile The filename of the source file
  42898. * @param aSourceContent The content of the source file
  42899. */
  42900. SourceNode.prototype.setSourceContent =
  42901. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  42902. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  42903. };
  42904. /**
  42905. * Walk over the tree of SourceNodes. The walking function is called for each
  42906. * source file content and is passed the filename and source content.
  42907. *
  42908. * @param aFn The traversal function.
  42909. */
  42910. SourceNode.prototype.walkSourceContents =
  42911. function SourceNode_walkSourceContents(aFn) {
  42912. for (var i = 0, len = this.children.length; i < len; i++) {
  42913. if (this.children[i][isSourceNode]) {
  42914. this.children[i].walkSourceContents(aFn);
  42915. }
  42916. }
  42917. var sources = Object.keys(this.sourceContents);
  42918. for (var i = 0, len = sources.length; i < len; i++) {
  42919. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  42920. }
  42921. };
  42922. /**
  42923. * Return the string representation of this source node. Walks over the tree
  42924. * and concatenates all the various snippets together to one string.
  42925. */
  42926. SourceNode.prototype.toString = function SourceNode_toString() {
  42927. var str = "";
  42928. this.walk(function (chunk) {
  42929. str += chunk;
  42930. });
  42931. return str;
  42932. };
  42933. /**
  42934. * Returns the string representation of this source node along with a source
  42935. * map.
  42936. */
  42937. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  42938. var generated = {
  42939. code: "",
  42940. line: 1,
  42941. column: 0
  42942. };
  42943. var map = new SourceMapGenerator(aArgs);
  42944. var sourceMappingActive = false;
  42945. var lastOriginalSource = null;
  42946. var lastOriginalLine = null;
  42947. var lastOriginalColumn = null;
  42948. var lastOriginalName = null;
  42949. this.walk(function (chunk, original) {
  42950. generated.code += chunk;
  42951. if (original.source !== null
  42952. && original.line !== null
  42953. && original.column !== null) {
  42954. if(lastOriginalSource !== original.source
  42955. || lastOriginalLine !== original.line
  42956. || lastOriginalColumn !== original.column
  42957. || lastOriginalName !== original.name) {
  42958. map.addMapping({
  42959. source: original.source,
  42960. original: {
  42961. line: original.line,
  42962. column: original.column
  42963. },
  42964. generated: {
  42965. line: generated.line,
  42966. column: generated.column
  42967. },
  42968. name: original.name
  42969. });
  42970. }
  42971. lastOriginalSource = original.source;
  42972. lastOriginalLine = original.line;
  42973. lastOriginalColumn = original.column;
  42974. lastOriginalName = original.name;
  42975. sourceMappingActive = true;
  42976. } else if (sourceMappingActive) {
  42977. map.addMapping({
  42978. generated: {
  42979. line: generated.line,
  42980. column: generated.column
  42981. }
  42982. });
  42983. lastOriginalSource = null;
  42984. sourceMappingActive = false;
  42985. }
  42986. for (var idx = 0, length = chunk.length; idx < length; idx++) {
  42987. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  42988. generated.line++;
  42989. generated.column = 0;
  42990. // Mappings end at eol
  42991. if (idx + 1 === length) {
  42992. lastOriginalSource = null;
  42993. sourceMappingActive = false;
  42994. } else if (sourceMappingActive) {
  42995. map.addMapping({
  42996. source: original.source,
  42997. original: {
  42998. line: original.line,
  42999. column: original.column
  43000. },
  43001. generated: {
  43002. line: generated.line,
  43003. column: generated.column
  43004. },
  43005. name: original.name
  43006. });
  43007. }
  43008. } else {
  43009. generated.column++;
  43010. }
  43011. }
  43012. });
  43013. this.walkSourceContents(function (sourceFile, sourceContent) {
  43014. map.setSourceContent(sourceFile, sourceContent);
  43015. });
  43016. return { code: generated.code, map: map };
  43017. };
  43018. sourceNode.SourceNode = SourceNode;
  43019. return sourceNode;
  43020. }
  43021. /*
  43022. * Copyright 2009-2011 Mozilla Foundation and contributors
  43023. * Licensed under the New BSD license. See LICENSE.txt or:
  43024. * http://opensource.org/licenses/BSD-3-Clause
  43025. */
  43026. var hasRequiredSourceMap;
  43027. function requireSourceMap () {
  43028. if (hasRequiredSourceMap) return sourceMap;
  43029. hasRequiredSourceMap = 1;
  43030. sourceMap.SourceMapGenerator = /*@__PURE__*/ requireSourceMapGenerator().SourceMapGenerator;
  43031. sourceMap.SourceMapConsumer = /*@__PURE__*/ requireSourceMapConsumer().SourceMapConsumer;
  43032. sourceMap.SourceNode = /*@__PURE__*/ requireSourceNode().SourceNode;
  43033. return sourceMap;
  43034. }
  43035. var mergeSourceMap;
  43036. var hasRequiredMergeSourceMap;
  43037. function requireMergeSourceMap () {
  43038. if (hasRequiredMergeSourceMap) return mergeSourceMap;
  43039. hasRequiredMergeSourceMap = 1;
  43040. var sourceMap = /*@__PURE__*/ requireSourceMap();
  43041. var SourceMapConsumer = sourceMap.SourceMapConsumer;
  43042. var SourceMapGenerator = sourceMap.SourceMapGenerator;
  43043. mergeSourceMap = merge;
  43044. /**
  43045. * Merge old source map and new source map and return merged.
  43046. * If old or new source map value is falsy, return another one as it is.
  43047. *
  43048. * @param {object|string} [oldMap] old source map object
  43049. * @param {object|string} [newmap] new source map object
  43050. * @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
  43051. */
  43052. function merge(oldMap, newMap) {
  43053. if (!oldMap) return newMap
  43054. if (!newMap) return oldMap
  43055. var oldMapConsumer = new SourceMapConsumer(oldMap);
  43056. var newMapConsumer = new SourceMapConsumer(newMap);
  43057. var mergedMapGenerator = new SourceMapGenerator();
  43058. // iterate on new map and overwrite original position of new map with one of old map
  43059. newMapConsumer.eachMapping(function(m) {
  43060. // pass when `originalLine` is null.
  43061. // It occurs in case that the node does not have origin in original code.
  43062. if (m.originalLine == null) return
  43063. var origPosInOldMap = oldMapConsumer.originalPositionFor({
  43064. line: m.originalLine,
  43065. column: m.originalColumn
  43066. });
  43067. if (origPosInOldMap.source == null) return
  43068. mergedMapGenerator.addMapping({
  43069. original: {
  43070. line: origPosInOldMap.line,
  43071. column: origPosInOldMap.column
  43072. },
  43073. generated: {
  43074. line: m.generatedLine,
  43075. column: m.generatedColumn
  43076. },
  43077. source: origPosInOldMap.source,
  43078. name: origPosInOldMap.name
  43079. });
  43080. });
  43081. var consumers = [oldMapConsumer, newMapConsumer];
  43082. consumers.forEach(function(consumer) {
  43083. consumer.sources.forEach(function(sourceFile) {
  43084. mergedMapGenerator._sources.add(sourceFile);
  43085. var sourceContent = consumer.sourceContentFor(sourceFile);
  43086. if (sourceContent != null) {
  43087. mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
  43088. }
  43089. });
  43090. });
  43091. mergedMapGenerator._sourceRoot = oldMap.sourceRoot;
  43092. mergedMapGenerator._file = oldMap.file;
  43093. return JSON.parse(mergedMapGenerator.toString())
  43094. }
  43095. return mergeSourceMap;
  43096. }
  43097. var mergeSourceMapExports = /*@__PURE__*/ requireMergeSourceMap();
  43098. var merge = /*@__PURE__*/getDefaultExportFromCjs(mergeSourceMapExports);
  43099. var __defProp$5 = Object.defineProperty;
  43100. var __defProps$4 = Object.defineProperties;
  43101. var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
  43102. var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
  43103. var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
  43104. var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
  43105. var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43106. var __spreadValues$5 = (a, b) => {
  43107. for (var prop in b || (b = {}))
  43108. if (__hasOwnProp$5.call(b, prop))
  43109. __defNormalProp$5(a, prop, b[prop]);
  43110. if (__getOwnPropSymbols$5)
  43111. for (var prop of __getOwnPropSymbols$5(b)) {
  43112. if (__propIsEnum$5.call(b, prop))
  43113. __defNormalProp$5(a, prop, b[prop]);
  43114. }
  43115. return a;
  43116. };
  43117. var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
  43118. const scss = (source, map, options, load = require) => {
  43119. const nodeSass = load("sass");
  43120. const { compileString, renderSync } = nodeSass;
  43121. const data = getSource(source, options.filename, options.additionalData);
  43122. let css;
  43123. let dependencies;
  43124. let sourceMap;
  43125. try {
  43126. if (compileString) {
  43127. const { pathToFileURL, fileURLToPath } = load("url");
  43128. const result = compileString(data, __spreadProps$4(__spreadValues$5({}, options), {
  43129. url: pathToFileURL(options.filename),
  43130. sourceMap: !!map
  43131. }));
  43132. css = result.css;
  43133. dependencies = result.loadedUrls.map((url) => fileURLToPath(url));
  43134. sourceMap = map ? result.sourceMap : void 0;
  43135. } else {
  43136. const result = renderSync(__spreadProps$4(__spreadValues$5({}, options), {
  43137. data,
  43138. file: options.filename,
  43139. outFile: options.filename,
  43140. sourceMap: !!map
  43141. }));
  43142. css = result.css.toString();
  43143. dependencies = result.stats.includedFiles;
  43144. sourceMap = map ? JSON.parse(result.map.toString()) : void 0;
  43145. }
  43146. if (map) {
  43147. return {
  43148. code: css,
  43149. errors: [],
  43150. dependencies,
  43151. map: merge(map, sourceMap)
  43152. };
  43153. }
  43154. return { code: css, errors: [], dependencies };
  43155. } catch (e) {
  43156. return { code: "", errors: [e], dependencies: [] };
  43157. }
  43158. };
  43159. const sass = (source, map, options, load) => scss(
  43160. source,
  43161. map,
  43162. __spreadProps$4(__spreadValues$5({}, options), {
  43163. indentedSyntax: true
  43164. }),
  43165. load
  43166. );
  43167. const less = (source, map, options, load = require) => {
  43168. const nodeLess = load("less");
  43169. let result;
  43170. let error = null;
  43171. nodeLess.render(
  43172. getSource(source, options.filename, options.additionalData),
  43173. __spreadProps$4(__spreadValues$5({}, options), { syncImport: true }),
  43174. (err, output) => {
  43175. error = err;
  43176. result = output;
  43177. }
  43178. );
  43179. if (error) return { code: "", errors: [error], dependencies: [] };
  43180. const dependencies = result.imports;
  43181. if (map) {
  43182. return {
  43183. code: result.css.toString(),
  43184. map: merge(map, result.map),
  43185. errors: [],
  43186. dependencies
  43187. };
  43188. }
  43189. return {
  43190. code: result.css.toString(),
  43191. errors: [],
  43192. dependencies
  43193. };
  43194. };
  43195. const styl = (source, map, options, load = require) => {
  43196. const nodeStylus = load("stylus");
  43197. try {
  43198. const ref = nodeStylus(source, options);
  43199. if (map) ref.set("sourcemap", { inline: false, comment: false });
  43200. const result = ref.render();
  43201. const dependencies = ref.deps();
  43202. if (map) {
  43203. return {
  43204. code: result,
  43205. map: merge(map, ref.sourcemap),
  43206. errors: [],
  43207. dependencies
  43208. };
  43209. }
  43210. return { code: result, errors: [], dependencies };
  43211. } catch (e) {
  43212. return { code: "", errors: [e], dependencies: [] };
  43213. }
  43214. };
  43215. function getSource(source, filename, additionalData) {
  43216. if (!additionalData) return source;
  43217. if (isFunction$1(additionalData)) {
  43218. return additionalData(source, filename);
  43219. }
  43220. return additionalData + source;
  43221. }
  43222. const processors = {
  43223. less,
  43224. sass,
  43225. scss,
  43226. styl,
  43227. stylus: styl
  43228. };
  43229. var __defProp$4 = Object.defineProperty;
  43230. var __defProps$3 = Object.defineProperties;
  43231. var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
  43232. var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
  43233. var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
  43234. var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
  43235. var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  43236. var __spreadValues$4 = (a, b) => {
  43237. for (var prop in b || (b = {}))
  43238. if (__hasOwnProp$4.call(b, prop))
  43239. __defNormalProp$4(a, prop, b[prop]);
  43240. if (__getOwnPropSymbols$4)
  43241. for (var prop of __getOwnPropSymbols$4(b)) {
  43242. if (__propIsEnum$4.call(b, prop))
  43243. __defNormalProp$4(a, prop, b[prop]);
  43244. }
  43245. return a;
  43246. };
  43247. var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
  43248. function compileStyle(options) {
  43249. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43250. isAsync: false
  43251. }));
  43252. }
  43253. function compileStyleAsync(options) {
  43254. return doCompileStyle(__spreadProps$3(__spreadValues$4({}, options), {
  43255. isAsync: true
  43256. }));
  43257. }
  43258. function doCompileStyle(options) {
  43259. const {
  43260. filename,
  43261. id,
  43262. scoped = false,
  43263. trim = true,
  43264. isProd = false,
  43265. modules = false,
  43266. modulesOptions = {},
  43267. preprocessLang,
  43268. postcssOptions,
  43269. postcssPlugins
  43270. } = options;
  43271. const preprocessor = preprocessLang && processors[preprocessLang];
  43272. const preProcessedSource = preprocessor && preprocess(options, preprocessor);
  43273. const map = preProcessedSource ? preProcessedSource.map : options.inMap || options.map;
  43274. const source = preProcessedSource ? preProcessedSource.code : options.source;
  43275. const shortId = id.replace(/^data-v-/, "");
  43276. const longId = `data-v-${shortId}`;
  43277. const plugins = (postcssPlugins || []).slice();
  43278. plugins.unshift(cssVarsPlugin({ id: shortId, isProd }));
  43279. if (trim) {
  43280. plugins.push(trimPlugin());
  43281. }
  43282. if (scoped) {
  43283. plugins.push(scopedPlugin(longId));
  43284. }
  43285. let cssModules;
  43286. if (modules) {
  43287. {
  43288. throw new Error(
  43289. "[@vue/compiler-sfc] `modules` option is not supported in the browser build."
  43290. );
  43291. }
  43292. }
  43293. const postCSSOptions = __spreadProps$3(__spreadValues$4({}, postcssOptions), {
  43294. to: filename,
  43295. from: filename
  43296. });
  43297. if (map) {
  43298. postCSSOptions.map = {
  43299. inline: false,
  43300. annotation: false,
  43301. prev: map
  43302. };
  43303. }
  43304. let result;
  43305. let code;
  43306. let outMap;
  43307. const dependencies = new Set(
  43308. preProcessedSource ? preProcessedSource.dependencies : []
  43309. );
  43310. dependencies.delete(filename);
  43311. const errors = [];
  43312. if (preProcessedSource && preProcessedSource.errors.length) {
  43313. errors.push(...preProcessedSource.errors);
  43314. }
  43315. const recordPlainCssDependencies = (messages) => {
  43316. messages.forEach((msg) => {
  43317. if (msg.type === "dependency") {
  43318. dependencies.add(msg.file);
  43319. }
  43320. });
  43321. return dependencies;
  43322. };
  43323. try {
  43324. result = postcss(plugins).process(source, postCSSOptions);
  43325. if (options.isAsync) {
  43326. return result.then((result2) => ({
  43327. code: result2.css || "",
  43328. map: result2.map && result2.map.toJSON(),
  43329. errors,
  43330. modules: cssModules,
  43331. rawResult: result2,
  43332. dependencies: recordPlainCssDependencies(result2.messages)
  43333. })).catch((error) => ({
  43334. code: "",
  43335. map: void 0,
  43336. errors: [...errors, error],
  43337. rawResult: void 0,
  43338. dependencies
  43339. }));
  43340. }
  43341. recordPlainCssDependencies(result.messages);
  43342. code = result.css;
  43343. outMap = result.map;
  43344. } catch (e) {
  43345. errors.push(e);
  43346. }
  43347. return {
  43348. code: code || ``,
  43349. map: outMap && outMap.toJSON(),
  43350. errors,
  43351. rawResult: result,
  43352. dependencies
  43353. };
  43354. }
  43355. function preprocess(options, preprocessor) {
  43356. if (!options.preprocessCustomRequire) {
  43357. throw new Error(
  43358. `[@vue/compiler-sfc] Style preprocessing in the browser build must provide the \`preprocessCustomRequire\` option to return the in-browser version of the preprocessor.`
  43359. );
  43360. }
  43361. return preprocessor(
  43362. options.source,
  43363. options.inMap || options.map,
  43364. __spreadValues$4({
  43365. filename: options.filename
  43366. }, options.preprocessOptions),
  43367. options.preprocessCustomRequire
  43368. );
  43369. }
  43370. const UNKNOWN_TYPE = "Unknown";
  43371. function resolveObjectKey(node, computed) {
  43372. switch (node.type) {
  43373. case "StringLiteral":
  43374. case "NumericLiteral":
  43375. return String(node.value);
  43376. case "Identifier":
  43377. if (!computed) return node.name;
  43378. }
  43379. return void 0;
  43380. }
  43381. function concatStrings(strs) {
  43382. return strs.filter((s) => !!s).join(", ");
  43383. }
  43384. function isLiteralNode(node) {
  43385. return node.type.endsWith("Literal");
  43386. }
  43387. function isCallOf(node, test) {
  43388. return !!(node && test && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : test(node.callee.name)));
  43389. }
  43390. function toRuntimeTypeString(types) {
  43391. return types.length > 1 ? `[${types.join(", ")}]` : types[0];
  43392. }
  43393. function getImportedName(specifier) {
  43394. if (specifier.type === "ImportSpecifier")
  43395. return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
  43396. else if (specifier.type === "ImportNamespaceSpecifier") return "*";
  43397. return "default";
  43398. }
  43399. function getId(node) {
  43400. return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
  43401. }
  43402. const normalize = (path.posix || path).normalize;
  43403. const windowsSlashRE = /\\/g;
  43404. function normalizePath(p) {
  43405. return normalize(p.replace(windowsSlashRE, "/"));
  43406. }
  43407. const joinPaths = (path.posix || path).join;
  43408. const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
  43409. function getEscapedPropName(key) {
  43410. return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
  43411. }
  43412. function analyzeScriptBindings(ast) {
  43413. for (const node of ast) {
  43414. if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ObjectExpression") {
  43415. return analyzeBindingsFromOptions(node.declaration);
  43416. }
  43417. }
  43418. return {};
  43419. }
  43420. function analyzeBindingsFromOptions(node) {
  43421. const bindings = {};
  43422. Object.defineProperty(bindings, "__isScriptSetup", {
  43423. enumerable: false,
  43424. value: false
  43425. });
  43426. for (const property of node.properties) {
  43427. if (property.type === "ObjectProperty" && !property.computed && property.key.type === "Identifier") {
  43428. if (property.key.name === "props") {
  43429. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43430. bindings[key] = "props";
  43431. }
  43432. } else if (property.key.name === "inject") {
  43433. for (const key of getObjectOrArrayExpressionKeys(property.value)) {
  43434. bindings[key] = "options";
  43435. }
  43436. } else if (property.value.type === "ObjectExpression" && (property.key.name === "computed" || property.key.name === "methods")) {
  43437. for (const key of getObjectExpressionKeys(property.value)) {
  43438. bindings[key] = "options";
  43439. }
  43440. }
  43441. } else if (property.type === "ObjectMethod" && property.key.type === "Identifier" && (property.key.name === "setup" || property.key.name === "data")) {
  43442. for (const bodyItem of property.body.body) {
  43443. if (bodyItem.type === "ReturnStatement" && bodyItem.argument && bodyItem.argument.type === "ObjectExpression") {
  43444. for (const key of getObjectExpressionKeys(bodyItem.argument)) {
  43445. bindings[key] = property.key.name === "setup" ? "setup-maybe-ref" : "data";
  43446. }
  43447. }
  43448. }
  43449. }
  43450. }
  43451. return bindings;
  43452. }
  43453. function getObjectExpressionKeys(node) {
  43454. const keys = [];
  43455. for (const prop of node.properties) {
  43456. if (prop.type === "SpreadElement") continue;
  43457. const key = resolveObjectKey(prop.key, prop.computed);
  43458. if (key) keys.push(String(key));
  43459. }
  43460. return keys;
  43461. }
  43462. function getArrayExpressionKeys(node) {
  43463. const keys = [];
  43464. for (const element of node.elements) {
  43465. if (element && element.type === "StringLiteral") {
  43466. keys.push(element.value);
  43467. }
  43468. }
  43469. return keys;
  43470. }
  43471. function getObjectOrArrayExpressionKeys(value) {
  43472. if (value.type === "ArrayExpression") {
  43473. return getArrayExpressionKeys(value);
  43474. }
  43475. if (value.type === "ObjectExpression") {
  43476. return getObjectExpressionKeys(value);
  43477. }
  43478. return [];
  43479. }
  43480. const comma = ','.charCodeAt(0);
  43481. const semicolon = ';'.charCodeAt(0);
  43482. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  43483. const intToChar = new Uint8Array(64); // 64 possible chars.
  43484. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  43485. for (let i = 0; i < chars.length; i++) {
  43486. const c = chars.charCodeAt(i);
  43487. intToChar[i] = c;
  43488. charToInt[c] = i;
  43489. }
  43490. function encodeInteger(builder, num, relative) {
  43491. let delta = num - relative;
  43492. delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
  43493. do {
  43494. let clamped = delta & 0b011111;
  43495. delta >>>= 5;
  43496. if (delta > 0)
  43497. clamped |= 0b100000;
  43498. builder.write(intToChar[clamped]);
  43499. } while (delta > 0);
  43500. return num;
  43501. }
  43502. const bufLength = 1024 * 16;
  43503. // Provide a fallback for older environments.
  43504. const td = typeof TextDecoder !== 'undefined'
  43505. ? /* #__PURE__ */ new TextDecoder()
  43506. : typeof Buffer !== 'undefined'
  43507. ? {
  43508. decode(buf) {
  43509. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  43510. return out.toString();
  43511. },
  43512. }
  43513. : {
  43514. decode(buf) {
  43515. let out = '';
  43516. for (let i = 0; i < buf.length; i++) {
  43517. out += String.fromCharCode(buf[i]);
  43518. }
  43519. return out;
  43520. },
  43521. };
  43522. class StringWriter {
  43523. constructor() {
  43524. this.pos = 0;
  43525. this.out = '';
  43526. this.buffer = new Uint8Array(bufLength);
  43527. }
  43528. write(v) {
  43529. const { buffer } = this;
  43530. buffer[this.pos++] = v;
  43531. if (this.pos === bufLength) {
  43532. this.out += td.decode(buffer);
  43533. this.pos = 0;
  43534. }
  43535. }
  43536. flush() {
  43537. const { buffer, out, pos } = this;
  43538. return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
  43539. }
  43540. }
  43541. function encode(decoded) {
  43542. const writer = new StringWriter();
  43543. let sourcesIndex = 0;
  43544. let sourceLine = 0;
  43545. let sourceColumn = 0;
  43546. let namesIndex = 0;
  43547. for (let i = 0; i < decoded.length; i++) {
  43548. const line = decoded[i];
  43549. if (i > 0)
  43550. writer.write(semicolon);
  43551. if (line.length === 0)
  43552. continue;
  43553. let genColumn = 0;
  43554. for (let j = 0; j < line.length; j++) {
  43555. const segment = line[j];
  43556. if (j > 0)
  43557. writer.write(comma);
  43558. genColumn = encodeInteger(writer, segment[0], genColumn);
  43559. if (segment.length === 1)
  43560. continue;
  43561. sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
  43562. sourceLine = encodeInteger(writer, segment[2], sourceLine);
  43563. sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
  43564. if (segment.length === 4)
  43565. continue;
  43566. namesIndex = encodeInteger(writer, segment[4], namesIndex);
  43567. }
  43568. }
  43569. return writer.flush();
  43570. }
  43571. class BitSet {
  43572. constructor(arg) {
  43573. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  43574. }
  43575. add(n) {
  43576. this.bits[n >> 5] |= 1 << (n & 31);
  43577. }
  43578. has(n) {
  43579. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  43580. }
  43581. }
  43582. class Chunk {
  43583. constructor(start, end, content) {
  43584. this.start = start;
  43585. this.end = end;
  43586. this.original = content;
  43587. this.intro = '';
  43588. this.outro = '';
  43589. this.content = content;
  43590. this.storeName = false;
  43591. this.edited = false;
  43592. {
  43593. this.previous = null;
  43594. this.next = null;
  43595. }
  43596. }
  43597. appendLeft(content) {
  43598. this.outro += content;
  43599. }
  43600. appendRight(content) {
  43601. this.intro = this.intro + content;
  43602. }
  43603. clone() {
  43604. const chunk = new Chunk(this.start, this.end, this.original);
  43605. chunk.intro = this.intro;
  43606. chunk.outro = this.outro;
  43607. chunk.content = this.content;
  43608. chunk.storeName = this.storeName;
  43609. chunk.edited = this.edited;
  43610. return chunk;
  43611. }
  43612. contains(index) {
  43613. return this.start < index && index < this.end;
  43614. }
  43615. eachNext(fn) {
  43616. let chunk = this;
  43617. while (chunk) {
  43618. fn(chunk);
  43619. chunk = chunk.next;
  43620. }
  43621. }
  43622. eachPrevious(fn) {
  43623. let chunk = this;
  43624. while (chunk) {
  43625. fn(chunk);
  43626. chunk = chunk.previous;
  43627. }
  43628. }
  43629. edit(content, storeName, contentOnly) {
  43630. this.content = content;
  43631. if (!contentOnly) {
  43632. this.intro = '';
  43633. this.outro = '';
  43634. }
  43635. this.storeName = storeName;
  43636. this.edited = true;
  43637. return this;
  43638. }
  43639. prependLeft(content) {
  43640. this.outro = content + this.outro;
  43641. }
  43642. prependRight(content) {
  43643. this.intro = content + this.intro;
  43644. }
  43645. reset() {
  43646. this.intro = '';
  43647. this.outro = '';
  43648. if (this.edited) {
  43649. this.content = this.original;
  43650. this.storeName = false;
  43651. this.edited = false;
  43652. }
  43653. }
  43654. split(index) {
  43655. const sliceIndex = index - this.start;
  43656. const originalBefore = this.original.slice(0, sliceIndex);
  43657. const originalAfter = this.original.slice(sliceIndex);
  43658. this.original = originalBefore;
  43659. const newChunk = new Chunk(index, this.end, originalAfter);
  43660. newChunk.outro = this.outro;
  43661. this.outro = '';
  43662. this.end = index;
  43663. if (this.edited) {
  43664. // after split we should save the edit content record into the correct chunk
  43665. // to make sure sourcemap correct
  43666. // For example:
  43667. // ' test'.trim()
  43668. // split -> ' ' + 'test'
  43669. // ✔️ edit -> '' + 'test'
  43670. // ✖️ edit -> 'test' + ''
  43671. // TODO is this block necessary?...
  43672. newChunk.edit('', false);
  43673. this.content = '';
  43674. } else {
  43675. this.content = originalBefore;
  43676. }
  43677. newChunk.next = this.next;
  43678. if (newChunk.next) newChunk.next.previous = newChunk;
  43679. newChunk.previous = this;
  43680. this.next = newChunk;
  43681. return newChunk;
  43682. }
  43683. toString() {
  43684. return this.intro + this.content + this.outro;
  43685. }
  43686. trimEnd(rx) {
  43687. this.outro = this.outro.replace(rx, '');
  43688. if (this.outro.length) return true;
  43689. const trimmed = this.content.replace(rx, '');
  43690. if (trimmed.length) {
  43691. if (trimmed !== this.content) {
  43692. this.split(this.start + trimmed.length).edit('', undefined, true);
  43693. if (this.edited) {
  43694. // save the change, if it has been edited
  43695. this.edit(trimmed, this.storeName, true);
  43696. }
  43697. }
  43698. return true;
  43699. } else {
  43700. this.edit('', undefined, true);
  43701. this.intro = this.intro.replace(rx, '');
  43702. if (this.intro.length) return true;
  43703. }
  43704. }
  43705. trimStart(rx) {
  43706. this.intro = this.intro.replace(rx, '');
  43707. if (this.intro.length) return true;
  43708. const trimmed = this.content.replace(rx, '');
  43709. if (trimmed.length) {
  43710. if (trimmed !== this.content) {
  43711. const newChunk = this.split(this.end - trimmed.length);
  43712. if (this.edited) {
  43713. // save the change, if it has been edited
  43714. newChunk.edit(trimmed, this.storeName, true);
  43715. }
  43716. this.edit('', undefined, true);
  43717. }
  43718. return true;
  43719. } else {
  43720. this.edit('', undefined, true);
  43721. this.outro = this.outro.replace(rx, '');
  43722. if (this.outro.length) return true;
  43723. }
  43724. }
  43725. }
  43726. function getBtoa() {
  43727. if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
  43728. return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
  43729. } else if (typeof Buffer === 'function') {
  43730. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  43731. } else {
  43732. return () => {
  43733. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  43734. };
  43735. }
  43736. }
  43737. const btoa = /*#__PURE__*/ getBtoa();
  43738. class SourceMap {
  43739. constructor(properties) {
  43740. this.version = 3;
  43741. this.file = properties.file;
  43742. this.sources = properties.sources;
  43743. this.sourcesContent = properties.sourcesContent;
  43744. this.names = properties.names;
  43745. this.mappings = encode(properties.mappings);
  43746. if (typeof properties.x_google_ignoreList !== 'undefined') {
  43747. this.x_google_ignoreList = properties.x_google_ignoreList;
  43748. }
  43749. if (typeof properties.debugId !== 'undefined') {
  43750. this.debugId = properties.debugId;
  43751. }
  43752. }
  43753. toString() {
  43754. return JSON.stringify(this);
  43755. }
  43756. toUrl() {
  43757. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  43758. }
  43759. }
  43760. function guessIndent(code) {
  43761. const lines = code.split('\n');
  43762. const tabbed = lines.filter((line) => /^\t+/.test(line));
  43763. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  43764. if (tabbed.length === 0 && spaced.length === 0) {
  43765. return null;
  43766. }
  43767. // More lines tabbed than spaced? Assume tabs, and
  43768. // default to tabs in the case of a tie (or nothing
  43769. // to go on)
  43770. if (tabbed.length >= spaced.length) {
  43771. return '\t';
  43772. }
  43773. // Otherwise, we need to guess the multiple
  43774. const min = spaced.reduce((previous, current) => {
  43775. const numSpaces = /^ +/.exec(current)[0].length;
  43776. return Math.min(numSpaces, previous);
  43777. }, Infinity);
  43778. return new Array(min + 1).join(' ');
  43779. }
  43780. function getRelativePath(from, to) {
  43781. const fromParts = from.split(/[/\\]/);
  43782. const toParts = to.split(/[/\\]/);
  43783. fromParts.pop(); // get dirname
  43784. while (fromParts[0] === toParts[0]) {
  43785. fromParts.shift();
  43786. toParts.shift();
  43787. }
  43788. if (fromParts.length) {
  43789. let i = fromParts.length;
  43790. while (i--) fromParts[i] = '..';
  43791. }
  43792. return fromParts.concat(toParts).join('/');
  43793. }
  43794. const toString = Object.prototype.toString;
  43795. function isObject(thing) {
  43796. return toString.call(thing) === '[object Object]';
  43797. }
  43798. function getLocator(source) {
  43799. const originalLines = source.split('\n');
  43800. const lineOffsets = [];
  43801. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  43802. lineOffsets.push(pos);
  43803. pos += originalLines[i].length + 1;
  43804. }
  43805. return function locate(index) {
  43806. let i = 0;
  43807. let j = lineOffsets.length;
  43808. while (i < j) {
  43809. const m = (i + j) >> 1;
  43810. if (index < lineOffsets[m]) {
  43811. j = m;
  43812. } else {
  43813. i = m + 1;
  43814. }
  43815. }
  43816. const line = i - 1;
  43817. const column = index - lineOffsets[line];
  43818. return { line, column };
  43819. };
  43820. }
  43821. const wordRegex = /\w/;
  43822. class Mappings {
  43823. constructor(hires) {
  43824. this.hires = hires;
  43825. this.generatedCodeLine = 0;
  43826. this.generatedCodeColumn = 0;
  43827. this.raw = [];
  43828. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  43829. this.pending = null;
  43830. }
  43831. addEdit(sourceIndex, content, loc, nameIndex) {
  43832. if (content.length) {
  43833. const contentLengthMinusOne = content.length - 1;
  43834. let contentLineEnd = content.indexOf('\n', 0);
  43835. let previousContentLineEnd = -1;
  43836. // Loop through each line in the content and add a segment, but stop if the last line is empty,
  43837. // else code afterwards would fill one line too many
  43838. while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
  43839. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43840. if (nameIndex >= 0) {
  43841. segment.push(nameIndex);
  43842. }
  43843. this.rawSegments.push(segment);
  43844. this.generatedCodeLine += 1;
  43845. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43846. this.generatedCodeColumn = 0;
  43847. previousContentLineEnd = contentLineEnd;
  43848. contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
  43849. }
  43850. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43851. if (nameIndex >= 0) {
  43852. segment.push(nameIndex);
  43853. }
  43854. this.rawSegments.push(segment);
  43855. this.advance(content.slice(previousContentLineEnd + 1));
  43856. } else if (this.pending) {
  43857. this.rawSegments.push(this.pending);
  43858. this.advance(content);
  43859. }
  43860. this.pending = null;
  43861. }
  43862. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  43863. let originalCharIndex = chunk.start;
  43864. let first = true;
  43865. // when iterating each char, check if it's in a word boundary
  43866. let charInHiresBoundary = false;
  43867. while (originalCharIndex < chunk.end) {
  43868. if (original[originalCharIndex] === '\n') {
  43869. loc.line += 1;
  43870. loc.column = 0;
  43871. this.generatedCodeLine += 1;
  43872. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43873. this.generatedCodeColumn = 0;
  43874. first = true;
  43875. charInHiresBoundary = false;
  43876. } else {
  43877. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  43878. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  43879. if (this.hires === 'boundary') {
  43880. // in hires "boundary", group segments per word boundary than per char
  43881. if (wordRegex.test(original[originalCharIndex])) {
  43882. // for first char in the boundary found, start the boundary by pushing a segment
  43883. if (!charInHiresBoundary) {
  43884. this.rawSegments.push(segment);
  43885. charInHiresBoundary = true;
  43886. }
  43887. } else {
  43888. // for non-word char, end the boundary by pushing a segment
  43889. this.rawSegments.push(segment);
  43890. charInHiresBoundary = false;
  43891. }
  43892. } else {
  43893. this.rawSegments.push(segment);
  43894. }
  43895. }
  43896. loc.column += 1;
  43897. this.generatedCodeColumn += 1;
  43898. first = false;
  43899. }
  43900. originalCharIndex += 1;
  43901. }
  43902. this.pending = null;
  43903. }
  43904. advance(str) {
  43905. if (!str) return;
  43906. const lines = str.split('\n');
  43907. if (lines.length > 1) {
  43908. for (let i = 0; i < lines.length - 1; i++) {
  43909. this.generatedCodeLine++;
  43910. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  43911. }
  43912. this.generatedCodeColumn = 0;
  43913. }
  43914. this.generatedCodeColumn += lines[lines.length - 1].length;
  43915. }
  43916. }
  43917. const n = '\n';
  43918. const warned = {
  43919. insertLeft: false,
  43920. insertRight: false,
  43921. storeName: false,
  43922. };
  43923. class MagicString {
  43924. constructor(string, options = {}) {
  43925. const chunk = new Chunk(0, string.length, string);
  43926. Object.defineProperties(this, {
  43927. original: { writable: true, value: string },
  43928. outro: { writable: true, value: '' },
  43929. intro: { writable: true, value: '' },
  43930. firstChunk: { writable: true, value: chunk },
  43931. lastChunk: { writable: true, value: chunk },
  43932. lastSearchedChunk: { writable: true, value: chunk },
  43933. byStart: { writable: true, value: {} },
  43934. byEnd: { writable: true, value: {} },
  43935. filename: { writable: true, value: options.filename },
  43936. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  43937. sourcemapLocations: { writable: true, value: new BitSet() },
  43938. storedNames: { writable: true, value: {} },
  43939. indentStr: { writable: true, value: undefined },
  43940. ignoreList: { writable: true, value: options.ignoreList },
  43941. offset: { writable: true, value: options.offset || 0 },
  43942. });
  43943. this.byStart[0] = chunk;
  43944. this.byEnd[string.length] = chunk;
  43945. }
  43946. addSourcemapLocation(char) {
  43947. this.sourcemapLocations.add(char);
  43948. }
  43949. append(content) {
  43950. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  43951. this.outro += content;
  43952. return this;
  43953. }
  43954. appendLeft(index, content) {
  43955. index = index + this.offset;
  43956. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43957. this._split(index);
  43958. const chunk = this.byEnd[index];
  43959. if (chunk) {
  43960. chunk.appendLeft(content);
  43961. } else {
  43962. this.intro += content;
  43963. }
  43964. return this;
  43965. }
  43966. appendRight(index, content) {
  43967. index = index + this.offset;
  43968. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  43969. this._split(index);
  43970. const chunk = this.byStart[index];
  43971. if (chunk) {
  43972. chunk.appendRight(content);
  43973. } else {
  43974. this.outro += content;
  43975. }
  43976. return this;
  43977. }
  43978. clone() {
  43979. const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
  43980. let originalChunk = this.firstChunk;
  43981. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  43982. while (originalChunk) {
  43983. cloned.byStart[clonedChunk.start] = clonedChunk;
  43984. cloned.byEnd[clonedChunk.end] = clonedChunk;
  43985. const nextOriginalChunk = originalChunk.next;
  43986. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  43987. if (nextClonedChunk) {
  43988. clonedChunk.next = nextClonedChunk;
  43989. nextClonedChunk.previous = clonedChunk;
  43990. clonedChunk = nextClonedChunk;
  43991. }
  43992. originalChunk = nextOriginalChunk;
  43993. }
  43994. cloned.lastChunk = clonedChunk;
  43995. if (this.indentExclusionRanges) {
  43996. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  43997. }
  43998. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  43999. cloned.intro = this.intro;
  44000. cloned.outro = this.outro;
  44001. return cloned;
  44002. }
  44003. generateDecodedMap(options) {
  44004. options = options || {};
  44005. const sourceIndex = 0;
  44006. const names = Object.keys(this.storedNames);
  44007. const mappings = new Mappings(options.hires);
  44008. const locate = getLocator(this.original);
  44009. if (this.intro) {
  44010. mappings.advance(this.intro);
  44011. }
  44012. this.firstChunk.eachNext((chunk) => {
  44013. const loc = locate(chunk.start);
  44014. if (chunk.intro.length) mappings.advance(chunk.intro);
  44015. if (chunk.edited) {
  44016. mappings.addEdit(
  44017. sourceIndex,
  44018. chunk.content,
  44019. loc,
  44020. chunk.storeName ? names.indexOf(chunk.original) : -1,
  44021. );
  44022. } else {
  44023. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  44024. }
  44025. if (chunk.outro.length) mappings.advance(chunk.outro);
  44026. });
  44027. return {
  44028. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  44029. sources: [
  44030. options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
  44031. ],
  44032. sourcesContent: options.includeContent ? [this.original] : undefined,
  44033. names,
  44034. mappings: mappings.raw,
  44035. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
  44036. };
  44037. }
  44038. generateMap(options) {
  44039. return new SourceMap(this.generateDecodedMap(options));
  44040. }
  44041. _ensureindentStr() {
  44042. if (this.indentStr === undefined) {
  44043. this.indentStr = guessIndent(this.original);
  44044. }
  44045. }
  44046. _getRawIndentString() {
  44047. this._ensureindentStr();
  44048. return this.indentStr;
  44049. }
  44050. getIndentString() {
  44051. this._ensureindentStr();
  44052. return this.indentStr === null ? '\t' : this.indentStr;
  44053. }
  44054. indent(indentStr, options) {
  44055. const pattern = /^[^\r\n]/gm;
  44056. if (isObject(indentStr)) {
  44057. options = indentStr;
  44058. indentStr = undefined;
  44059. }
  44060. if (indentStr === undefined) {
  44061. this._ensureindentStr();
  44062. indentStr = this.indentStr || '\t';
  44063. }
  44064. if (indentStr === '') return this; // noop
  44065. options = options || {};
  44066. // Process exclusion ranges
  44067. const isExcluded = {};
  44068. if (options.exclude) {
  44069. const exclusions =
  44070. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  44071. exclusions.forEach((exclusion) => {
  44072. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  44073. isExcluded[i] = true;
  44074. }
  44075. });
  44076. }
  44077. let shouldIndentNextCharacter = options.indentStart !== false;
  44078. const replacer = (match) => {
  44079. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  44080. shouldIndentNextCharacter = true;
  44081. return match;
  44082. };
  44083. this.intro = this.intro.replace(pattern, replacer);
  44084. let charIndex = 0;
  44085. let chunk = this.firstChunk;
  44086. while (chunk) {
  44087. const end = chunk.end;
  44088. if (chunk.edited) {
  44089. if (!isExcluded[charIndex]) {
  44090. chunk.content = chunk.content.replace(pattern, replacer);
  44091. if (chunk.content.length) {
  44092. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  44093. }
  44094. }
  44095. } else {
  44096. charIndex = chunk.start;
  44097. while (charIndex < end) {
  44098. if (!isExcluded[charIndex]) {
  44099. const char = this.original[charIndex];
  44100. if (char === '\n') {
  44101. shouldIndentNextCharacter = true;
  44102. } else if (char !== '\r' && shouldIndentNextCharacter) {
  44103. shouldIndentNextCharacter = false;
  44104. if (charIndex === chunk.start) {
  44105. chunk.prependRight(indentStr);
  44106. } else {
  44107. this._splitChunk(chunk, charIndex);
  44108. chunk = chunk.next;
  44109. chunk.prependRight(indentStr);
  44110. }
  44111. }
  44112. }
  44113. charIndex += 1;
  44114. }
  44115. }
  44116. charIndex = chunk.end;
  44117. chunk = chunk.next;
  44118. }
  44119. this.outro = this.outro.replace(pattern, replacer);
  44120. return this;
  44121. }
  44122. insert() {
  44123. throw new Error(
  44124. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
  44125. );
  44126. }
  44127. insertLeft(index, content) {
  44128. if (!warned.insertLeft) {
  44129. console.warn(
  44130. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
  44131. );
  44132. warned.insertLeft = true;
  44133. }
  44134. return this.appendLeft(index, content);
  44135. }
  44136. insertRight(index, content) {
  44137. if (!warned.insertRight) {
  44138. console.warn(
  44139. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
  44140. );
  44141. warned.insertRight = true;
  44142. }
  44143. return this.prependRight(index, content);
  44144. }
  44145. move(start, end, index) {
  44146. start = start + this.offset;
  44147. end = end + this.offset;
  44148. index = index + this.offset;
  44149. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  44150. this._split(start);
  44151. this._split(end);
  44152. this._split(index);
  44153. const first = this.byStart[start];
  44154. const last = this.byEnd[end];
  44155. const oldLeft = first.previous;
  44156. const oldRight = last.next;
  44157. const newRight = this.byStart[index];
  44158. if (!newRight && last === this.lastChunk) return this;
  44159. const newLeft = newRight ? newRight.previous : this.lastChunk;
  44160. if (oldLeft) oldLeft.next = oldRight;
  44161. if (oldRight) oldRight.previous = oldLeft;
  44162. if (newLeft) newLeft.next = first;
  44163. if (newRight) newRight.previous = last;
  44164. if (!first.previous) this.firstChunk = last.next;
  44165. if (!last.next) {
  44166. this.lastChunk = first.previous;
  44167. this.lastChunk.next = null;
  44168. }
  44169. first.previous = newLeft;
  44170. last.next = newRight || null;
  44171. if (!newLeft) this.firstChunk = first;
  44172. if (!newRight) this.lastChunk = last;
  44173. return this;
  44174. }
  44175. overwrite(start, end, content, options) {
  44176. options = options || {};
  44177. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  44178. }
  44179. update(start, end, content, options) {
  44180. start = start + this.offset;
  44181. end = end + this.offset;
  44182. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  44183. if (this.original.length !== 0) {
  44184. while (start < 0) start += this.original.length;
  44185. while (end < 0) end += this.original.length;
  44186. }
  44187. if (end > this.original.length) throw new Error('end is out of bounds');
  44188. if (start === end)
  44189. throw new Error(
  44190. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
  44191. );
  44192. this._split(start);
  44193. this._split(end);
  44194. if (options === true) {
  44195. if (!warned.storeName) {
  44196. console.warn(
  44197. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
  44198. );
  44199. warned.storeName = true;
  44200. }
  44201. options = { storeName: true };
  44202. }
  44203. const storeName = options !== undefined ? options.storeName : false;
  44204. const overwrite = options !== undefined ? options.overwrite : false;
  44205. if (storeName) {
  44206. const original = this.original.slice(start, end);
  44207. Object.defineProperty(this.storedNames, original, {
  44208. writable: true,
  44209. value: true,
  44210. enumerable: true,
  44211. });
  44212. }
  44213. const first = this.byStart[start];
  44214. const last = this.byEnd[end];
  44215. if (first) {
  44216. let chunk = first;
  44217. while (chunk !== last) {
  44218. if (chunk.next !== this.byStart[chunk.end]) {
  44219. throw new Error('Cannot overwrite across a split point');
  44220. }
  44221. chunk = chunk.next;
  44222. chunk.edit('', false);
  44223. }
  44224. first.edit(content, storeName, !overwrite);
  44225. } else {
  44226. // must be inserting at the end
  44227. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  44228. // TODO last chunk in the array may not be the last chunk, if it's moved...
  44229. last.next = newChunk;
  44230. newChunk.previous = last;
  44231. }
  44232. return this;
  44233. }
  44234. prepend(content) {
  44235. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  44236. this.intro = content + this.intro;
  44237. return this;
  44238. }
  44239. prependLeft(index, content) {
  44240. index = index + this.offset;
  44241. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44242. this._split(index);
  44243. const chunk = this.byEnd[index];
  44244. if (chunk) {
  44245. chunk.prependLeft(content);
  44246. } else {
  44247. this.intro = content + this.intro;
  44248. }
  44249. return this;
  44250. }
  44251. prependRight(index, content) {
  44252. index = index + this.offset;
  44253. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  44254. this._split(index);
  44255. const chunk = this.byStart[index];
  44256. if (chunk) {
  44257. chunk.prependRight(content);
  44258. } else {
  44259. this.outro = content + this.outro;
  44260. }
  44261. return this;
  44262. }
  44263. remove(start, end) {
  44264. start = start + this.offset;
  44265. end = end + this.offset;
  44266. if (this.original.length !== 0) {
  44267. while (start < 0) start += this.original.length;
  44268. while (end < 0) end += this.original.length;
  44269. }
  44270. if (start === end) return this;
  44271. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44272. if (start > end) throw new Error('end must be greater than start');
  44273. this._split(start);
  44274. this._split(end);
  44275. let chunk = this.byStart[start];
  44276. while (chunk) {
  44277. chunk.intro = '';
  44278. chunk.outro = '';
  44279. chunk.edit('');
  44280. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44281. }
  44282. return this;
  44283. }
  44284. reset(start, end) {
  44285. start = start + this.offset;
  44286. end = end + this.offset;
  44287. if (this.original.length !== 0) {
  44288. while (start < 0) start += this.original.length;
  44289. while (end < 0) end += this.original.length;
  44290. }
  44291. if (start === end) return this;
  44292. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  44293. if (start > end) throw new Error('end must be greater than start');
  44294. this._split(start);
  44295. this._split(end);
  44296. let chunk = this.byStart[start];
  44297. while (chunk) {
  44298. chunk.reset();
  44299. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  44300. }
  44301. return this;
  44302. }
  44303. lastChar() {
  44304. if (this.outro.length) return this.outro[this.outro.length - 1];
  44305. let chunk = this.lastChunk;
  44306. do {
  44307. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  44308. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  44309. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  44310. } while ((chunk = chunk.previous));
  44311. if (this.intro.length) return this.intro[this.intro.length - 1];
  44312. return '';
  44313. }
  44314. lastLine() {
  44315. let lineIndex = this.outro.lastIndexOf(n);
  44316. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  44317. let lineStr = this.outro;
  44318. let chunk = this.lastChunk;
  44319. do {
  44320. if (chunk.outro.length > 0) {
  44321. lineIndex = chunk.outro.lastIndexOf(n);
  44322. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  44323. lineStr = chunk.outro + lineStr;
  44324. }
  44325. if (chunk.content.length > 0) {
  44326. lineIndex = chunk.content.lastIndexOf(n);
  44327. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  44328. lineStr = chunk.content + lineStr;
  44329. }
  44330. if (chunk.intro.length > 0) {
  44331. lineIndex = chunk.intro.lastIndexOf(n);
  44332. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  44333. lineStr = chunk.intro + lineStr;
  44334. }
  44335. } while ((chunk = chunk.previous));
  44336. lineIndex = this.intro.lastIndexOf(n);
  44337. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  44338. return this.intro + lineStr;
  44339. }
  44340. slice(start = 0, end = this.original.length - this.offset) {
  44341. start = start + this.offset;
  44342. end = end + this.offset;
  44343. if (this.original.length !== 0) {
  44344. while (start < 0) start += this.original.length;
  44345. while (end < 0) end += this.original.length;
  44346. }
  44347. let result = '';
  44348. // find start chunk
  44349. let chunk = this.firstChunk;
  44350. while (chunk && (chunk.start > start || chunk.end <= start)) {
  44351. // found end chunk before start
  44352. if (chunk.start < end && chunk.end >= end) {
  44353. return result;
  44354. }
  44355. chunk = chunk.next;
  44356. }
  44357. if (chunk && chunk.edited && chunk.start !== start)
  44358. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  44359. const startChunk = chunk;
  44360. while (chunk) {
  44361. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  44362. result += chunk.intro;
  44363. }
  44364. const containsEnd = chunk.start < end && chunk.end >= end;
  44365. if (containsEnd && chunk.edited && chunk.end !== end)
  44366. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  44367. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  44368. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  44369. result += chunk.content.slice(sliceStart, sliceEnd);
  44370. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  44371. result += chunk.outro;
  44372. }
  44373. if (containsEnd) {
  44374. break;
  44375. }
  44376. chunk = chunk.next;
  44377. }
  44378. return result;
  44379. }
  44380. // TODO deprecate this? not really very useful
  44381. snip(start, end) {
  44382. const clone = this.clone();
  44383. clone.remove(0, start);
  44384. clone.remove(end, clone.original.length);
  44385. return clone;
  44386. }
  44387. _split(index) {
  44388. if (this.byStart[index] || this.byEnd[index]) return;
  44389. let chunk = this.lastSearchedChunk;
  44390. const searchForward = index > chunk.end;
  44391. while (chunk) {
  44392. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  44393. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  44394. }
  44395. }
  44396. _splitChunk(chunk, index) {
  44397. if (chunk.edited && chunk.content.length) {
  44398. // zero-length edited chunks are a special case (overlapping replacements)
  44399. const loc = getLocator(this.original)(index);
  44400. throw new Error(
  44401. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
  44402. );
  44403. }
  44404. const newChunk = chunk.split(index);
  44405. this.byEnd[index] = chunk;
  44406. this.byStart[index] = newChunk;
  44407. this.byEnd[newChunk.end] = newChunk;
  44408. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  44409. this.lastSearchedChunk = chunk;
  44410. return true;
  44411. }
  44412. toString() {
  44413. let str = this.intro;
  44414. let chunk = this.firstChunk;
  44415. while (chunk) {
  44416. str += chunk.toString();
  44417. chunk = chunk.next;
  44418. }
  44419. return str + this.outro;
  44420. }
  44421. isEmpty() {
  44422. let chunk = this.firstChunk;
  44423. do {
  44424. if (
  44425. (chunk.intro.length && chunk.intro.trim()) ||
  44426. (chunk.content.length && chunk.content.trim()) ||
  44427. (chunk.outro.length && chunk.outro.trim())
  44428. )
  44429. return false;
  44430. } while ((chunk = chunk.next));
  44431. return true;
  44432. }
  44433. length() {
  44434. let chunk = this.firstChunk;
  44435. let length = 0;
  44436. do {
  44437. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  44438. } while ((chunk = chunk.next));
  44439. return length;
  44440. }
  44441. trimLines() {
  44442. return this.trim('[\\r\\n]');
  44443. }
  44444. trim(charType) {
  44445. return this.trimStart(charType).trimEnd(charType);
  44446. }
  44447. trimEndAborted(charType) {
  44448. const rx = new RegExp((charType || '\\s') + '+$');
  44449. this.outro = this.outro.replace(rx, '');
  44450. if (this.outro.length) return true;
  44451. let chunk = this.lastChunk;
  44452. do {
  44453. const end = chunk.end;
  44454. const aborted = chunk.trimEnd(rx);
  44455. // if chunk was trimmed, we have a new lastChunk
  44456. if (chunk.end !== end) {
  44457. if (this.lastChunk === chunk) {
  44458. this.lastChunk = chunk.next;
  44459. }
  44460. this.byEnd[chunk.end] = chunk;
  44461. this.byStart[chunk.next.start] = chunk.next;
  44462. this.byEnd[chunk.next.end] = chunk.next;
  44463. }
  44464. if (aborted) return true;
  44465. chunk = chunk.previous;
  44466. } while (chunk);
  44467. return false;
  44468. }
  44469. trimEnd(charType) {
  44470. this.trimEndAborted(charType);
  44471. return this;
  44472. }
  44473. trimStartAborted(charType) {
  44474. const rx = new RegExp('^' + (charType || '\\s') + '+');
  44475. this.intro = this.intro.replace(rx, '');
  44476. if (this.intro.length) return true;
  44477. let chunk = this.firstChunk;
  44478. do {
  44479. const end = chunk.end;
  44480. const aborted = chunk.trimStart(rx);
  44481. if (chunk.end !== end) {
  44482. // special case...
  44483. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  44484. this.byEnd[chunk.end] = chunk;
  44485. this.byStart[chunk.next.start] = chunk.next;
  44486. this.byEnd[chunk.next.end] = chunk.next;
  44487. }
  44488. if (aborted) return true;
  44489. chunk = chunk.next;
  44490. } while (chunk);
  44491. return false;
  44492. }
  44493. trimStart(charType) {
  44494. this.trimStartAborted(charType);
  44495. return this;
  44496. }
  44497. hasChanged() {
  44498. return this.original !== this.toString();
  44499. }
  44500. _replaceRegexp(searchValue, replacement) {
  44501. function getReplacement(match, str) {
  44502. if (typeof replacement === 'string') {
  44503. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  44504. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  44505. if (i === '$') return '$';
  44506. if (i === '&') return match[0];
  44507. const num = +i;
  44508. if (num < match.length) return match[+i];
  44509. return `$${i}`;
  44510. });
  44511. } else {
  44512. return replacement(...match, match.index, str, match.groups);
  44513. }
  44514. }
  44515. function matchAll(re, str) {
  44516. let match;
  44517. const matches = [];
  44518. while ((match = re.exec(str))) {
  44519. matches.push(match);
  44520. }
  44521. return matches;
  44522. }
  44523. if (searchValue.global) {
  44524. const matches = matchAll(searchValue, this.original);
  44525. matches.forEach((match) => {
  44526. if (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. } else {
  44534. const match = this.original.match(searchValue);
  44535. if (match && match.index != null) {
  44536. const replacement = getReplacement(match, this.original);
  44537. if (replacement !== match[0]) {
  44538. this.overwrite(match.index, match.index + match[0].length, replacement);
  44539. }
  44540. }
  44541. }
  44542. return this;
  44543. }
  44544. _replaceString(string, replacement) {
  44545. const { original } = this;
  44546. const index = original.indexOf(string);
  44547. if (index !== -1) {
  44548. this.overwrite(index, index + string.length, replacement);
  44549. }
  44550. return this;
  44551. }
  44552. replace(searchValue, replacement) {
  44553. if (typeof searchValue === 'string') {
  44554. return this._replaceString(searchValue, replacement);
  44555. }
  44556. return this._replaceRegexp(searchValue, replacement);
  44557. }
  44558. _replaceAllString(string, replacement) {
  44559. const { original } = this;
  44560. const stringLength = string.length;
  44561. for (
  44562. let index = original.indexOf(string);
  44563. index !== -1;
  44564. index = original.indexOf(string, index + stringLength)
  44565. ) {
  44566. const previous = original.slice(index, index + stringLength);
  44567. if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
  44568. }
  44569. return this;
  44570. }
  44571. replaceAll(searchValue, replacement) {
  44572. if (typeof searchValue === 'string') {
  44573. return this._replaceAllString(searchValue, replacement);
  44574. }
  44575. if (!searchValue.global) {
  44576. throw new TypeError(
  44577. 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
  44578. );
  44579. }
  44580. return this._replaceRegexp(searchValue, replacement);
  44581. }
  44582. }
  44583. var _a, _b;
  44584. class ScriptCompileContext {
  44585. constructor(descriptor, options) {
  44586. this.descriptor = descriptor;
  44587. this.options = options;
  44588. this.isCE = false;
  44589. this.source = this.descriptor.source;
  44590. this.filename = this.descriptor.filename;
  44591. this.s = new MagicString(this.source);
  44592. this.startOffset = (_a = this.descriptor.scriptSetup) == null ? void 0 : _a.loc.start.offset;
  44593. this.endOffset = (_b = this.descriptor.scriptSetup) == null ? void 0 : _b.loc.end.offset;
  44594. this.userImports = /* @__PURE__ */ Object.create(null);
  44595. // macros presence check
  44596. this.hasDefinePropsCall = false;
  44597. this.hasDefineEmitCall = false;
  44598. this.hasDefineExposeCall = false;
  44599. this.hasDefaultExportName = false;
  44600. this.hasDefaultExportRender = false;
  44601. this.hasDefineOptionsCall = false;
  44602. this.hasDefineSlotsCall = false;
  44603. this.hasDefineModelCall = false;
  44604. this.propsDestructuredBindings = /* @__PURE__ */ Object.create(null);
  44605. // defineModel
  44606. this.modelDecls = /* @__PURE__ */ Object.create(null);
  44607. // codegen
  44608. this.bindingMetadata = {};
  44609. this.helperImports = /* @__PURE__ */ new Set();
  44610. const { script, scriptSetup } = descriptor;
  44611. const scriptLang = script && script.lang;
  44612. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  44613. this.isJS = scriptLang === "js" || scriptLang === "jsx" || scriptSetupLang === "js" || scriptSetupLang === "jsx";
  44614. this.isTS = scriptLang === "ts" || scriptLang === "tsx" || scriptSetupLang === "ts" || scriptSetupLang === "tsx";
  44615. const customElement = options.customElement;
  44616. const filename = this.descriptor.filename;
  44617. if (customElement) {
  44618. this.isCE = typeof customElement === "boolean" ? customElement : customElement(filename);
  44619. }
  44620. const plugins = resolveParserPlugins(
  44621. scriptLang || scriptSetupLang,
  44622. options.babelParserPlugins
  44623. );
  44624. function parse(input, offset) {
  44625. try {
  44626. return libExports.parse(input, {
  44627. plugins,
  44628. sourceType: "module"
  44629. }).program;
  44630. } catch (e) {
  44631. e.message = `[vue/compiler-sfc] ${e.message}
  44632. ${descriptor.filename}
  44633. ${generateCodeFrame(
  44634. descriptor.source,
  44635. e.pos + offset,
  44636. e.pos + offset + 1
  44637. )}`;
  44638. throw e;
  44639. }
  44640. }
  44641. this.scriptAst = descriptor.script && parse(descriptor.script.content, descriptor.script.loc.start.offset);
  44642. this.scriptSetupAst = descriptor.scriptSetup && parse(descriptor.scriptSetup.content, this.startOffset);
  44643. }
  44644. helper(key) {
  44645. this.helperImports.add(key);
  44646. return `_${key}`;
  44647. }
  44648. getString(node, scriptSetup = true) {
  44649. const block = scriptSetup ? this.descriptor.scriptSetup : this.descriptor.script;
  44650. return block.content.slice(node.start, node.end);
  44651. }
  44652. warn(msg, node, scope) {
  44653. warn(generateError(msg, node, this, scope));
  44654. }
  44655. error(msg, node, scope) {
  44656. throw new Error(
  44657. `[@vue/compiler-sfc] ${generateError(msg, node, this, scope)}`
  44658. );
  44659. }
  44660. }
  44661. function generateError(msg, node, ctx, scope) {
  44662. const offset = scope ? scope.offset : ctx.startOffset;
  44663. return `${msg}
  44664. ${(scope || ctx.descriptor).filename}
  44665. ${generateCodeFrame(
  44666. (scope || ctx.descriptor).source,
  44667. node.start + offset,
  44668. node.end + offset
  44669. )}`;
  44670. }
  44671. function resolveParserPlugins(lang, userPlugins, dts = false) {
  44672. const plugins = [];
  44673. if (!userPlugins || !userPlugins.some(
  44674. (p) => p === "importAssertions" || p === "importAttributes" || isArray$3(p) && p[0] === "importAttributes"
  44675. )) {
  44676. plugins.push("importAttributes");
  44677. }
  44678. if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
  44679. plugins.push("jsx");
  44680. } else if (userPlugins) {
  44681. userPlugins = userPlugins.filter((p) => p !== "jsx");
  44682. }
  44683. if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "mtsx") {
  44684. plugins.push(["typescript", { dts }], "explicitResourceManagement");
  44685. if (!userPlugins || !userPlugins.includes("decorators")) {
  44686. plugins.push("decorators-legacy");
  44687. }
  44688. }
  44689. if (userPlugins) {
  44690. plugins.push(...userPlugins);
  44691. }
  44692. return plugins;
  44693. }
  44694. function rewriteDefault(input, as, parserPlugins) {
  44695. const ast = libExports.parse(input, {
  44696. sourceType: "module",
  44697. plugins: resolveParserPlugins("js", parserPlugins)
  44698. }).program.body;
  44699. const s = new MagicString(input);
  44700. rewriteDefaultAST(ast, s, as);
  44701. return s.toString();
  44702. }
  44703. function rewriteDefaultAST(ast, s, as) {
  44704. if (!hasDefaultExport(ast)) {
  44705. s.append(`
  44706. const ${as} = {}`);
  44707. return;
  44708. }
  44709. ast.forEach((node) => {
  44710. if (node.type === "ExportDefaultDeclaration") {
  44711. if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
  44712. const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
  44713. s.overwrite(start, node.declaration.id.start, ` class `);
  44714. s.append(`
  44715. const ${as} = ${node.declaration.id.name}`);
  44716. } else {
  44717. s.overwrite(node.start, node.declaration.start, `const ${as} = `);
  44718. }
  44719. } else if (node.type === "ExportNamedDeclaration") {
  44720. for (const specifier of node.specifiers) {
  44721. if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier" && specifier.exported.name === "default") {
  44722. if (node.source) {
  44723. if (specifier.local.name === "default") {
  44724. s.prepend(
  44725. `import { default as __VUE_DEFAULT__ } from '${node.source.value}'
  44726. `
  44727. );
  44728. const end2 = specifierEnd(s, specifier.local.end, node.end);
  44729. s.remove(specifier.start, end2);
  44730. s.append(`
  44731. const ${as} = __VUE_DEFAULT__`);
  44732. continue;
  44733. } else {
  44734. s.prepend(
  44735. `import { ${s.slice(
  44736. specifier.local.start,
  44737. specifier.local.end
  44738. )} as __VUE_DEFAULT__ } from '${node.source.value}'
  44739. `
  44740. );
  44741. const end2 = specifierEnd(s, specifier.exported.end, node.end);
  44742. s.remove(specifier.start, end2);
  44743. s.append(`
  44744. const ${as} = __VUE_DEFAULT__`);
  44745. continue;
  44746. }
  44747. }
  44748. const end = specifierEnd(s, specifier.end, node.end);
  44749. s.remove(specifier.start, end);
  44750. s.append(`
  44751. const ${as} = ${specifier.local.name}`);
  44752. }
  44753. }
  44754. }
  44755. });
  44756. }
  44757. function hasDefaultExport(ast) {
  44758. for (const stmt of ast) {
  44759. if (stmt.type === "ExportDefaultDeclaration") {
  44760. return true;
  44761. } else if (stmt.type === "ExportNamedDeclaration" && stmt.specifiers.some(
  44762. (spec) => spec.exported.name === "default"
  44763. )) {
  44764. return true;
  44765. }
  44766. }
  44767. return false;
  44768. }
  44769. function specifierEnd(s, end, nodeEnd) {
  44770. let hasCommas = false;
  44771. let oldEnd = end;
  44772. while (end < nodeEnd) {
  44773. if (/\s/.test(s.slice(end, end + 1))) {
  44774. end++;
  44775. } else if (s.slice(end, end + 1) === ",") {
  44776. end++;
  44777. hasCommas = true;
  44778. break;
  44779. } else if (s.slice(end, end + 1) === "}") {
  44780. break;
  44781. }
  44782. }
  44783. return hasCommas ? end : oldEnd;
  44784. }
  44785. var __defProp$3 = Object.defineProperty;
  44786. var __defProps$2 = Object.defineProperties;
  44787. var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
  44788. var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
  44789. var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
  44790. var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
  44791. var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44792. var __spreadValues$3 = (a, b) => {
  44793. for (var prop in b || (b = {}))
  44794. if (__hasOwnProp$3.call(b, prop))
  44795. __defNormalProp$3(a, prop, b[prop]);
  44796. if (__getOwnPropSymbols$3)
  44797. for (var prop of __getOwnPropSymbols$3(b)) {
  44798. if (__propIsEnum$3.call(b, prop))
  44799. __defNormalProp$3(a, prop, b[prop]);
  44800. }
  44801. return a;
  44802. };
  44803. var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
  44804. const normalScriptDefaultVar = `__default__`;
  44805. function processNormalScript(ctx, scopeId) {
  44806. var _a;
  44807. const script = ctx.descriptor.script;
  44808. if (script.lang && !ctx.isJS && !ctx.isTS) {
  44809. return script;
  44810. }
  44811. try {
  44812. let content = script.content;
  44813. let map = script.map;
  44814. const scriptAst = ctx.scriptAst;
  44815. const bindings = analyzeScriptBindings(scriptAst.body);
  44816. const { cssVars } = ctx.descriptor;
  44817. const { genDefaultAs, isProd } = ctx.options;
  44818. if (cssVars.length || genDefaultAs) {
  44819. const defaultVar = genDefaultAs || normalScriptDefaultVar;
  44820. const s = new MagicString(content);
  44821. rewriteDefaultAST(scriptAst.body, s, defaultVar);
  44822. content = s.toString();
  44823. if (cssVars.length && !((_a = ctx.options.templateOptions) == null ? void 0 : _a.ssr)) {
  44824. content += genNormalScriptCssVarsCode(
  44825. cssVars,
  44826. bindings,
  44827. scopeId,
  44828. !!isProd,
  44829. defaultVar
  44830. );
  44831. }
  44832. if (!genDefaultAs) {
  44833. content += `
  44834. export default ${defaultVar}`;
  44835. }
  44836. }
  44837. return __spreadProps$2(__spreadValues$3({}, script), {
  44838. content,
  44839. map,
  44840. bindings,
  44841. scriptAst: scriptAst.body
  44842. });
  44843. } catch (e) {
  44844. return script;
  44845. }
  44846. }
  44847. var __defProp$2 = Object.defineProperty;
  44848. var __defProps$1 = Object.defineProperties;
  44849. var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
  44850. var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
  44851. var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
  44852. var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
  44853. var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  44854. var __spreadValues$2 = (a, b) => {
  44855. for (var prop in b || (b = {}))
  44856. if (__hasOwnProp$2.call(b, prop))
  44857. __defNormalProp$2(a, prop, b[prop]);
  44858. if (__getOwnPropSymbols$2)
  44859. for (var prop of __getOwnPropSymbols$2(b)) {
  44860. if (__propIsEnum$2.call(b, prop))
  44861. __defNormalProp$2(a, prop, b[prop]);
  44862. }
  44863. return a;
  44864. };
  44865. var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
  44866. class TypeScope {
  44867. constructor(filename, source, offset = 0, imports = /* @__PURE__ */ Object.create(null), types = /* @__PURE__ */ Object.create(null), declares = /* @__PURE__ */ Object.create(null)) {
  44868. this.filename = filename;
  44869. this.source = source;
  44870. this.offset = offset;
  44871. this.imports = imports;
  44872. this.types = types;
  44873. this.declares = declares;
  44874. this.isGenericScope = false;
  44875. this.resolvedImportSources = /* @__PURE__ */ Object.create(null);
  44876. this.exportedTypes = /* @__PURE__ */ Object.create(null);
  44877. this.exportedDeclares = /* @__PURE__ */ Object.create(null);
  44878. }
  44879. }
  44880. function resolveTypeElements(ctx, node, scope, typeParameters) {
  44881. const canCache = !typeParameters;
  44882. if (canCache && node._resolvedElements) {
  44883. return node._resolvedElements;
  44884. }
  44885. const resolved = innerResolveTypeElements(
  44886. ctx,
  44887. node,
  44888. node._ownerScope || scope || ctxToScope(ctx),
  44889. typeParameters
  44890. );
  44891. return canCache ? node._resolvedElements = resolved : resolved;
  44892. }
  44893. function innerResolveTypeElements(ctx, node, scope, typeParameters) {
  44894. var _a, _b;
  44895. if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
  44896. return { props: {} };
  44897. }
  44898. switch (node.type) {
  44899. case "TSTypeLiteral":
  44900. return typeElementsToMap(ctx, node.members, scope, typeParameters);
  44901. case "TSInterfaceDeclaration":
  44902. return resolveInterfaceMembers(ctx, node, scope, typeParameters);
  44903. case "TSTypeAliasDeclaration":
  44904. case "TSTypeAnnotation":
  44905. case "TSParenthesizedType":
  44906. return resolveTypeElements(
  44907. ctx,
  44908. node.typeAnnotation,
  44909. scope,
  44910. typeParameters
  44911. );
  44912. case "TSFunctionType": {
  44913. return { props: {}, calls: [node] };
  44914. }
  44915. case "TSUnionType":
  44916. case "TSIntersectionType":
  44917. return mergeElements(
  44918. node.types.map((t) => resolveTypeElements(ctx, t, scope, typeParameters)),
  44919. node.type
  44920. );
  44921. case "TSMappedType":
  44922. return resolveMappedType(ctx, node, scope, typeParameters);
  44923. case "TSIndexedAccessType": {
  44924. const types = resolveIndexType(ctx, node, scope);
  44925. return mergeElements(
  44926. types.map((t) => resolveTypeElements(ctx, t, t._ownerScope)),
  44927. "TSUnionType"
  44928. );
  44929. }
  44930. case "TSExpressionWithTypeArguments":
  44931. // referenced by interface extends
  44932. case "TSTypeReference": {
  44933. const typeName = getReferenceName(node);
  44934. if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
  44935. return resolveExtractPropTypes(
  44936. resolveTypeElements(
  44937. ctx,
  44938. node.typeParameters.params[0],
  44939. scope,
  44940. typeParameters
  44941. ),
  44942. scope
  44943. );
  44944. }
  44945. const resolved = resolveTypeReference(ctx, node, scope);
  44946. if (resolved) {
  44947. let typeParams;
  44948. if ((resolved.type === "TSTypeAliasDeclaration" || resolved.type === "TSInterfaceDeclaration") && resolved.typeParameters && node.typeParameters) {
  44949. typeParams = /* @__PURE__ */ Object.create(null);
  44950. resolved.typeParameters.params.forEach((p, i) => {
  44951. let param = typeParameters && typeParameters[p.name];
  44952. if (!param) param = node.typeParameters.params[i];
  44953. typeParams[p.name] = param;
  44954. });
  44955. }
  44956. return resolveTypeElements(
  44957. ctx,
  44958. resolved,
  44959. resolved._ownerScope,
  44960. typeParams
  44961. );
  44962. } else {
  44963. if (typeof typeName === "string") {
  44964. if (typeParameters && typeParameters[typeName]) {
  44965. return resolveTypeElements(
  44966. ctx,
  44967. typeParameters[typeName],
  44968. scope,
  44969. typeParameters
  44970. );
  44971. }
  44972. if (
  44973. // @ts-expect-error
  44974. SupportedBuiltinsSet.has(typeName)
  44975. ) {
  44976. return resolveBuiltin(
  44977. ctx,
  44978. node,
  44979. typeName,
  44980. scope,
  44981. typeParameters
  44982. );
  44983. } else if (typeName === "ReturnType" && node.typeParameters) {
  44984. const ret = resolveReturnType(
  44985. ctx,
  44986. node.typeParameters.params[0],
  44987. scope
  44988. );
  44989. if (ret) {
  44990. return resolveTypeElements(ctx, ret, scope);
  44991. }
  44992. }
  44993. }
  44994. return ctx.error(
  44995. `Unresolvable type reference or unsupported built-in utility type`,
  44996. node,
  44997. scope
  44998. );
  44999. }
  45000. }
  45001. case "TSImportType": {
  45002. if (getId(node.argument) === "vue" && ((_b = node.qualifier) == null ? void 0 : _b.type) === "Identifier" && node.qualifier.name === "ExtractPropTypes" && node.typeParameters) {
  45003. return resolveExtractPropTypes(
  45004. resolveTypeElements(ctx, node.typeParameters.params[0], scope),
  45005. scope
  45006. );
  45007. }
  45008. const sourceScope = importSourceToScope(
  45009. ctx,
  45010. node.argument,
  45011. scope,
  45012. node.argument.value
  45013. );
  45014. const resolved = resolveTypeReference(ctx, node, sourceScope);
  45015. if (resolved) {
  45016. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45017. }
  45018. break;
  45019. }
  45020. case "TSTypeQuery":
  45021. {
  45022. const resolved = resolveTypeReference(ctx, node, scope);
  45023. if (resolved) {
  45024. return resolveTypeElements(ctx, resolved, resolved._ownerScope);
  45025. }
  45026. }
  45027. break;
  45028. }
  45029. return ctx.error(`Unresolvable type: ${node.type}`, node, scope);
  45030. }
  45031. function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameters) {
  45032. const res = { props: {} };
  45033. for (const e of elements) {
  45034. if (e.type === "TSPropertySignature" || e.type === "TSMethodSignature") {
  45035. if (typeParameters) {
  45036. scope = createChildScope(scope);
  45037. scope.isGenericScope = true;
  45038. Object.assign(scope.types, typeParameters);
  45039. }
  45040. e._ownerScope = scope;
  45041. const name = getId(e.key);
  45042. if (name && !e.computed) {
  45043. res.props[name] = e;
  45044. } else if (e.key.type === "TemplateLiteral") {
  45045. for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
  45046. res.props[key] = e;
  45047. }
  45048. } else {
  45049. ctx.error(
  45050. `Unsupported computed key in type referenced by a macro`,
  45051. e.key,
  45052. scope
  45053. );
  45054. }
  45055. } else if (e.type === "TSCallSignatureDeclaration") {
  45056. (res.calls || (res.calls = [])).push(e);
  45057. }
  45058. }
  45059. return res;
  45060. }
  45061. function mergeElements(maps, type) {
  45062. if (maps.length === 1) return maps[0];
  45063. const res = { props: {} };
  45064. const { props: baseProps } = res;
  45065. for (const { props, calls } of maps) {
  45066. for (const key in props) {
  45067. if (!hasOwn(baseProps, key)) {
  45068. baseProps[key] = props[key];
  45069. } else {
  45070. baseProps[key] = createProperty(
  45071. baseProps[key].key,
  45072. {
  45073. type,
  45074. // @ts-expect-error
  45075. types: [baseProps[key], props[key]]
  45076. },
  45077. baseProps[key]._ownerScope,
  45078. baseProps[key].optional || props[key].optional
  45079. );
  45080. }
  45081. }
  45082. if (calls) {
  45083. (res.calls || (res.calls = [])).push(...calls);
  45084. }
  45085. }
  45086. return res;
  45087. }
  45088. function createProperty(key, typeAnnotation, scope, optional) {
  45089. return {
  45090. type: "TSPropertySignature",
  45091. key,
  45092. kind: "get",
  45093. optional,
  45094. typeAnnotation: {
  45095. type: "TSTypeAnnotation",
  45096. typeAnnotation
  45097. },
  45098. _ownerScope: scope
  45099. };
  45100. }
  45101. function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
  45102. const base = typeElementsToMap(
  45103. ctx,
  45104. node.body.body,
  45105. node._ownerScope,
  45106. typeParameters
  45107. );
  45108. if (node.extends) {
  45109. for (const ext of node.extends) {
  45110. try {
  45111. const { props, calls } = resolveTypeElements(ctx, ext, scope);
  45112. for (const key in props) {
  45113. if (!hasOwn(base.props, key)) {
  45114. base.props[key] = props[key];
  45115. }
  45116. }
  45117. if (calls) {
  45118. ;
  45119. (base.calls || (base.calls = [])).push(...calls);
  45120. }
  45121. } catch (e) {
  45122. ctx.error(
  45123. `Failed to resolve extends base type.
  45124. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
  45125. interface Props extends /* @vue-ignore */ Base {}
  45126. Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
  45127. ext,
  45128. scope
  45129. );
  45130. }
  45131. }
  45132. }
  45133. return base;
  45134. }
  45135. function resolveMappedType(ctx, node, scope, typeParameters) {
  45136. const res = { props: {} };
  45137. let keys;
  45138. if (node.nameType) {
  45139. const { name, constraint } = node.typeParameter;
  45140. scope = createChildScope(scope);
  45141. Object.assign(scope.types, __spreadProps$1(__spreadValues$2({}, typeParameters), { [name]: constraint }));
  45142. keys = resolveStringType(ctx, node.nameType, scope);
  45143. } else {
  45144. keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
  45145. }
  45146. for (const key of keys) {
  45147. res.props[key] = createProperty(
  45148. {
  45149. type: "Identifier",
  45150. name: key
  45151. },
  45152. node.typeAnnotation,
  45153. scope,
  45154. !!node.optional
  45155. );
  45156. }
  45157. return res;
  45158. }
  45159. function resolveIndexType(ctx, node, scope) {
  45160. var _a, _b;
  45161. if (node.indexType.type === "TSNumberKeyword") {
  45162. return resolveArrayElementType(ctx, node.objectType, scope);
  45163. }
  45164. const { indexType, objectType } = node;
  45165. const types = [];
  45166. let keys;
  45167. let resolved;
  45168. if (indexType.type === "TSStringKeyword") {
  45169. resolved = resolveTypeElements(ctx, objectType, scope);
  45170. keys = Object.keys(resolved.props);
  45171. } else {
  45172. keys = resolveStringType(ctx, indexType, scope);
  45173. resolved = resolveTypeElements(ctx, objectType, scope);
  45174. }
  45175. for (const key of keys) {
  45176. const targetType = (_b = (_a = resolved.props[key]) == null ? void 0 : _a.typeAnnotation) == null ? void 0 : _b.typeAnnotation;
  45177. if (targetType) {
  45178. targetType._ownerScope = resolved.props[key]._ownerScope;
  45179. types.push(targetType);
  45180. }
  45181. }
  45182. return types;
  45183. }
  45184. function resolveArrayElementType(ctx, node, scope) {
  45185. if (node.type === "TSArrayType") {
  45186. return [node.elementType];
  45187. }
  45188. if (node.type === "TSTupleType") {
  45189. return node.elementTypes.map(
  45190. (t) => t.type === "TSNamedTupleMember" ? t.elementType : t
  45191. );
  45192. }
  45193. if (node.type === "TSTypeReference") {
  45194. if (getReferenceName(node) === "Array" && node.typeParameters) {
  45195. return node.typeParameters.params;
  45196. } else {
  45197. const resolved = resolveTypeReference(ctx, node, scope);
  45198. if (resolved) {
  45199. return resolveArrayElementType(ctx, resolved, scope);
  45200. }
  45201. }
  45202. }
  45203. return ctx.error(
  45204. "Failed to resolve element type from target type",
  45205. node,
  45206. scope
  45207. );
  45208. }
  45209. function resolveStringType(ctx, node, scope, typeParameters) {
  45210. switch (node.type) {
  45211. case "StringLiteral":
  45212. return [node.value];
  45213. case "TSLiteralType":
  45214. return resolveStringType(ctx, node.literal, scope, typeParameters);
  45215. case "TSUnionType":
  45216. return node.types.map((t) => resolveStringType(ctx, t, scope, typeParameters)).flat();
  45217. case "TemplateLiteral": {
  45218. return resolveTemplateKeys(ctx, node, scope);
  45219. }
  45220. case "TSTypeReference": {
  45221. const resolved = resolveTypeReference(ctx, node, scope);
  45222. if (resolved) {
  45223. return resolveStringType(ctx, resolved, scope, typeParameters);
  45224. }
  45225. if (node.typeName.type === "Identifier") {
  45226. const name = node.typeName.name;
  45227. if (typeParameters && typeParameters[name]) {
  45228. return resolveStringType(
  45229. ctx,
  45230. typeParameters[name],
  45231. scope,
  45232. typeParameters
  45233. );
  45234. }
  45235. const getParam = (index = 0) => resolveStringType(
  45236. ctx,
  45237. node.typeParameters.params[index],
  45238. scope,
  45239. typeParameters
  45240. );
  45241. switch (name) {
  45242. case "Extract":
  45243. return getParam(1);
  45244. case "Exclude": {
  45245. const excluded = getParam(1);
  45246. return getParam().filter((s) => !excluded.includes(s));
  45247. }
  45248. case "Uppercase":
  45249. return getParam().map((s) => s.toUpperCase());
  45250. case "Lowercase":
  45251. return getParam().map((s) => s.toLowerCase());
  45252. case "Capitalize":
  45253. return getParam().map(capitalize);
  45254. case "Uncapitalize":
  45255. return getParam().map((s) => s[0].toLowerCase() + s.slice(1));
  45256. default:
  45257. ctx.error(
  45258. "Unsupported type when resolving index type",
  45259. node.typeName,
  45260. scope
  45261. );
  45262. }
  45263. }
  45264. }
  45265. }
  45266. return ctx.error("Failed to resolve index type into finite keys", node, scope);
  45267. }
  45268. function resolveTemplateKeys(ctx, node, scope) {
  45269. if (!node.expressions.length) {
  45270. return [node.quasis[0].value.raw];
  45271. }
  45272. const res = [];
  45273. const e = node.expressions[0];
  45274. const q = node.quasis[0];
  45275. const leading = q ? q.value.raw : ``;
  45276. const resolved = resolveStringType(ctx, e, scope);
  45277. const restResolved = resolveTemplateKeys(
  45278. ctx,
  45279. __spreadProps$1(__spreadValues$2({}, node), {
  45280. expressions: node.expressions.slice(1),
  45281. quasis: q ? node.quasis.slice(1) : node.quasis
  45282. }),
  45283. scope
  45284. );
  45285. for (const r of resolved) {
  45286. for (const rr of restResolved) {
  45287. res.push(leading + r + rr);
  45288. }
  45289. }
  45290. return res;
  45291. }
  45292. const SupportedBuiltinsSet = /* @__PURE__ */ new Set([
  45293. "Partial",
  45294. "Required",
  45295. "Readonly",
  45296. "Pick",
  45297. "Omit"
  45298. ]);
  45299. function resolveBuiltin(ctx, node, name, scope, typeParameters) {
  45300. const t = resolveTypeElements(
  45301. ctx,
  45302. node.typeParameters.params[0],
  45303. scope,
  45304. typeParameters
  45305. );
  45306. switch (name) {
  45307. case "Partial": {
  45308. const res2 = { props: {}, calls: t.calls };
  45309. Object.keys(t.props).forEach((key) => {
  45310. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: true });
  45311. });
  45312. return res2;
  45313. }
  45314. case "Required": {
  45315. const res2 = { props: {}, calls: t.calls };
  45316. Object.keys(t.props).forEach((key) => {
  45317. res2.props[key] = __spreadProps$1(__spreadValues$2({}, t.props[key]), { optional: false });
  45318. });
  45319. return res2;
  45320. }
  45321. case "Readonly":
  45322. return t;
  45323. case "Pick": {
  45324. const picked = resolveStringType(
  45325. ctx,
  45326. node.typeParameters.params[1],
  45327. scope,
  45328. typeParameters
  45329. );
  45330. const res2 = { props: {}, calls: t.calls };
  45331. for (const key of picked) {
  45332. res2.props[key] = t.props[key];
  45333. }
  45334. return res2;
  45335. }
  45336. case "Omit":
  45337. const omitted = resolveStringType(
  45338. ctx,
  45339. node.typeParameters.params[1],
  45340. scope,
  45341. typeParameters
  45342. );
  45343. const res = { props: {}, calls: t.calls };
  45344. for (const key in t.props) {
  45345. if (!omitted.includes(key)) {
  45346. res.props[key] = t.props[key];
  45347. }
  45348. }
  45349. return res;
  45350. }
  45351. }
  45352. function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
  45353. const canCache = !(scope == null ? void 0 : scope.isGenericScope);
  45354. if (canCache && node._resolvedReference) {
  45355. return node._resolvedReference;
  45356. }
  45357. const resolved = innerResolveTypeReference(
  45358. ctx,
  45359. scope || ctxToScope(ctx),
  45360. name || getReferenceName(node),
  45361. node,
  45362. onlyExported
  45363. );
  45364. return canCache ? node._resolvedReference = resolved : resolved;
  45365. }
  45366. function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
  45367. if (typeof name === "string") {
  45368. if (scope.imports[name]) {
  45369. return resolveTypeFromImport(ctx, node, name, scope);
  45370. } else {
  45371. const lookupSource = node.type === "TSTypeQuery" ? onlyExported ? scope.exportedDeclares : scope.declares : onlyExported ? scope.exportedTypes : scope.types;
  45372. if (lookupSource[name]) {
  45373. return lookupSource[name];
  45374. } else {
  45375. const globalScopes = resolveGlobalScope(ctx);
  45376. if (globalScopes) {
  45377. for (const s of globalScopes) {
  45378. const src = node.type === "TSTypeQuery" ? s.declares : s.types;
  45379. if (src[name]) {
  45380. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(s.filename);
  45381. return src[name];
  45382. }
  45383. }
  45384. }
  45385. }
  45386. }
  45387. } else {
  45388. let ns = innerResolveTypeReference(ctx, scope, name[0], node, onlyExported);
  45389. if (ns) {
  45390. if (ns.type !== "TSModuleDeclaration") {
  45391. ns = ns._ns;
  45392. }
  45393. if (ns) {
  45394. const childScope = moduleDeclToScope(ctx, ns, ns._ownerScope || scope);
  45395. return innerResolveTypeReference(
  45396. ctx,
  45397. childScope,
  45398. name.length > 2 ? name.slice(1) : name[name.length - 1],
  45399. node,
  45400. !ns.declare
  45401. );
  45402. }
  45403. }
  45404. }
  45405. }
  45406. function getReferenceName(node) {
  45407. const ref = node.type === "TSTypeReference" ? node.typeName : node.type === "TSExpressionWithTypeArguments" ? node.expression : node.type === "TSImportType" ? node.qualifier : node.exprName;
  45408. if ((ref == null ? void 0 : ref.type) === "Identifier") {
  45409. return ref.name;
  45410. } else if ((ref == null ? void 0 : ref.type) === "TSQualifiedName") {
  45411. return qualifiedNameToPath(ref);
  45412. } else {
  45413. return "default";
  45414. }
  45415. }
  45416. function qualifiedNameToPath(node) {
  45417. if (node.type === "Identifier") {
  45418. return [node.name];
  45419. } else {
  45420. return [...qualifiedNameToPath(node.left), node.right.name];
  45421. }
  45422. }
  45423. function resolveGlobalScope(ctx) {
  45424. if (ctx.options.globalTypeFiles) {
  45425. const fs = resolveFS(ctx);
  45426. if (!fs) {
  45427. throw new Error("[vue/compiler-sfc] globalTypeFiles requires fs access.");
  45428. }
  45429. return ctx.options.globalTypeFiles.map(
  45430. (file) => fileToScope(ctx, normalizePath(file), true)
  45431. );
  45432. }
  45433. }
  45434. let ts;
  45435. let loadTS;
  45436. function registerTS(_loadTS) {
  45437. loadTS = () => {
  45438. try {
  45439. return _loadTS();
  45440. } catch (err) {
  45441. if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
  45442. throw new Error(
  45443. 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "typescript" is installed as a project dependency.'
  45444. );
  45445. } else {
  45446. throw new Error(
  45447. "Failed to load TypeScript for resolving imported types."
  45448. );
  45449. }
  45450. }
  45451. };
  45452. }
  45453. function resolveFS(ctx) {
  45454. if (ctx.fs) {
  45455. return ctx.fs;
  45456. }
  45457. if (!ts && loadTS) {
  45458. ts = loadTS();
  45459. }
  45460. const fs = ctx.options.fs || (ts == null ? void 0 : ts.sys);
  45461. if (!fs) {
  45462. return;
  45463. }
  45464. return ctx.fs = {
  45465. fileExists(file) {
  45466. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45467. file = file.replace(/\.ts$/, "");
  45468. }
  45469. return fs.fileExists(file);
  45470. },
  45471. readFile(file) {
  45472. if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
  45473. file = file.replace(/\.ts$/, "");
  45474. }
  45475. return fs.readFile(file);
  45476. },
  45477. realpath: fs.realpath
  45478. };
  45479. }
  45480. function resolveTypeFromImport(ctx, node, name, scope) {
  45481. const { source, imported } = scope.imports[name];
  45482. const sourceScope = importSourceToScope(ctx, node, scope, source);
  45483. return resolveTypeReference(ctx, node, sourceScope, imported, true);
  45484. }
  45485. function importSourceToScope(ctx, node, scope, source) {
  45486. let fs;
  45487. try {
  45488. fs = resolveFS(ctx);
  45489. } catch (err) {
  45490. return ctx.error(err.message, node, scope);
  45491. }
  45492. if (!fs) {
  45493. return ctx.error(
  45494. `No fs option provided to \`compileScript\` in non-Node environment. File system access is required for resolving imported types.`,
  45495. node,
  45496. scope
  45497. );
  45498. }
  45499. let resolved = scope.resolvedImportSources[source];
  45500. if (!resolved) {
  45501. if (source.startsWith("..")) {
  45502. const osSpecificJoinFn = joinPaths;
  45503. const filename = osSpecificJoinFn(dirname(scope.filename), source);
  45504. resolved = resolveExt(filename, fs);
  45505. } else if (source[0] === ".") {
  45506. const filename = joinPaths(dirname(scope.filename), source);
  45507. resolved = resolveExt(filename, fs);
  45508. } else {
  45509. {
  45510. return ctx.error(
  45511. `Type import from non-relative sources is not supported in the browser build.`,
  45512. node,
  45513. scope
  45514. );
  45515. }
  45516. }
  45517. if (resolved) {
  45518. resolved = scope.resolvedImportSources[source] = normalizePath(resolved);
  45519. }
  45520. }
  45521. if (resolved) {
  45522. (ctx.deps || (ctx.deps = /* @__PURE__ */ new Set())).add(resolved);
  45523. return fileToScope(ctx, resolved);
  45524. } else {
  45525. return ctx.error(
  45526. `Failed to resolve import source ${JSON.stringify(source)}.`,
  45527. node,
  45528. scope
  45529. );
  45530. }
  45531. }
  45532. function resolveExt(filename, fs) {
  45533. filename = filename.replace(/\.js$/, "");
  45534. const tryResolve = (filename2) => {
  45535. if (fs.fileExists(filename2)) return filename2;
  45536. };
  45537. 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`));
  45538. }
  45539. const tsConfigCache = createCache();
  45540. const tsConfigRefMap = /* @__PURE__ */ new Map();
  45541. const fileToScopeCache = createCache();
  45542. function invalidateTypeCache(filename) {
  45543. filename = normalizePath(filename);
  45544. fileToScopeCache.delete(filename);
  45545. tsConfigCache.delete(filename);
  45546. const affectedConfig = tsConfigRefMap.get(filename);
  45547. if (affectedConfig) tsConfigCache.delete(affectedConfig);
  45548. }
  45549. function fileToScope(ctx, filename, asGlobal = false) {
  45550. const cached = fileToScopeCache.get(filename);
  45551. if (cached) {
  45552. return cached;
  45553. }
  45554. const fs = resolveFS(ctx);
  45555. const source = fs.readFile(filename) || "";
  45556. const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
  45557. const scope = new TypeScope(filename, source, 0, recordImports(body));
  45558. recordTypes(ctx, body, scope, asGlobal);
  45559. fileToScopeCache.set(filename, scope);
  45560. return scope;
  45561. }
  45562. function parseFile(filename, content, fs, parserPlugins) {
  45563. const ext = extname(filename);
  45564. if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
  45565. return libExports.parse(content, {
  45566. plugins: resolveParserPlugins(
  45567. ext.slice(1),
  45568. parserPlugins,
  45569. /\.d\.m?ts$/.test(filename)
  45570. ),
  45571. sourceType: "module"
  45572. }).program.body;
  45573. }
  45574. const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
  45575. const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
  45576. const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
  45577. if (hasArbitraryTypeDeclaration) {
  45578. return libExports.parse(fs.readFile(arbitraryTypeSource), {
  45579. plugins: resolveParserPlugins("ts", parserPlugins, true),
  45580. sourceType: "module"
  45581. }).program.body;
  45582. }
  45583. if (ext === ".vue") {
  45584. const {
  45585. descriptor: { script, scriptSetup }
  45586. } = parse$2(content);
  45587. if (!script && !scriptSetup) {
  45588. return [];
  45589. }
  45590. const scriptOffset = script ? script.loc.start.offset : Infinity;
  45591. const scriptSetupOffset = scriptSetup ? scriptSetup.loc.start.offset : Infinity;
  45592. const firstBlock = scriptOffset < scriptSetupOffset ? script : scriptSetup;
  45593. const secondBlock = scriptOffset < scriptSetupOffset ? scriptSetup : script;
  45594. let scriptContent = " ".repeat(Math.min(scriptOffset, scriptSetupOffset)) + firstBlock.content;
  45595. if (secondBlock) {
  45596. scriptContent += " ".repeat(secondBlock.loc.start.offset - script.loc.end.offset) + secondBlock.content;
  45597. }
  45598. const lang = (script == null ? void 0 : script.lang) || (scriptSetup == null ? void 0 : scriptSetup.lang);
  45599. return libExports.parse(scriptContent, {
  45600. plugins: resolveParserPlugins(lang, parserPlugins),
  45601. sourceType: "module"
  45602. }).program.body;
  45603. }
  45604. return [];
  45605. }
  45606. function ctxToScope(ctx) {
  45607. if (ctx.scope) {
  45608. return ctx.scope;
  45609. }
  45610. const body = "ast" in ctx ? ctx.ast : ctx.scriptAst ? [...ctx.scriptAst.body, ...ctx.scriptSetupAst.body] : ctx.scriptSetupAst.body;
  45611. const scope = new TypeScope(
  45612. ctx.filename,
  45613. ctx.source,
  45614. "startOffset" in ctx ? ctx.startOffset : 0,
  45615. "userImports" in ctx ? Object.create(ctx.userImports) : recordImports(body)
  45616. );
  45617. recordTypes(ctx, body, scope);
  45618. return ctx.scope = scope;
  45619. }
  45620. function moduleDeclToScope(ctx, node, parentScope) {
  45621. if (node._resolvedChildScope) {
  45622. return node._resolvedChildScope;
  45623. }
  45624. const scope = createChildScope(parentScope);
  45625. if (node.body.type === "TSModuleDeclaration") {
  45626. const decl = node.body;
  45627. decl._ownerScope = scope;
  45628. const id = getId(decl.id);
  45629. scope.types[id] = scope.exportedTypes[id] = decl;
  45630. } else {
  45631. recordTypes(ctx, node.body.body, scope);
  45632. }
  45633. return node._resolvedChildScope = scope;
  45634. }
  45635. function createChildScope(parentScope) {
  45636. return new TypeScope(
  45637. parentScope.filename,
  45638. parentScope.source,
  45639. parentScope.offset,
  45640. Object.create(parentScope.imports),
  45641. Object.create(parentScope.types),
  45642. Object.create(parentScope.declares)
  45643. );
  45644. }
  45645. const importExportRE = /^Import|^Export/;
  45646. function recordTypes(ctx, body, scope, asGlobal = false) {
  45647. const { types, declares, exportedTypes, exportedDeclares, imports } = scope;
  45648. const isAmbient = asGlobal ? !body.some((s) => importExportRE.test(s.type)) : false;
  45649. for (const stmt of body) {
  45650. if (asGlobal) {
  45651. if (isAmbient) {
  45652. if (stmt.declare) {
  45653. recordType(stmt, types, declares);
  45654. }
  45655. } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
  45656. for (const s of stmt.body.body) {
  45657. recordType(s, types, declares);
  45658. }
  45659. }
  45660. } else {
  45661. recordType(stmt, types, declares);
  45662. }
  45663. }
  45664. if (!asGlobal) {
  45665. for (const stmt of body) {
  45666. if (stmt.type === "ExportNamedDeclaration") {
  45667. if (stmt.declaration) {
  45668. recordType(stmt.declaration, types, declares);
  45669. recordType(stmt.declaration, exportedTypes, exportedDeclares);
  45670. } else {
  45671. for (const spec of stmt.specifiers) {
  45672. if (spec.type === "ExportSpecifier") {
  45673. const local = spec.local.name;
  45674. const exported = getId(spec.exported);
  45675. if (stmt.source) {
  45676. imports[exported] = {
  45677. source: stmt.source.value,
  45678. imported: local
  45679. };
  45680. exportedTypes[exported] = {
  45681. type: "TSTypeReference",
  45682. typeName: {
  45683. type: "Identifier",
  45684. name: local
  45685. },
  45686. _ownerScope: scope
  45687. };
  45688. } else if (types[local]) {
  45689. exportedTypes[exported] = types[local];
  45690. }
  45691. }
  45692. }
  45693. }
  45694. } else if (stmt.type === "ExportAllDeclaration") {
  45695. const sourceScope = importSourceToScope(
  45696. ctx,
  45697. stmt.source,
  45698. scope,
  45699. stmt.source.value
  45700. );
  45701. Object.assign(scope.exportedTypes, sourceScope.exportedTypes);
  45702. } else if (stmt.type === "ExportDefaultDeclaration" && stmt.declaration) {
  45703. if (stmt.declaration.type !== "Identifier") {
  45704. recordType(stmt.declaration, types, declares, "default");
  45705. recordType(
  45706. stmt.declaration,
  45707. exportedTypes,
  45708. exportedDeclares,
  45709. "default"
  45710. );
  45711. } else if (types[stmt.declaration.name]) {
  45712. exportedTypes["default"] = types[stmt.declaration.name];
  45713. }
  45714. }
  45715. }
  45716. }
  45717. for (const key of Object.keys(types)) {
  45718. const node = types[key];
  45719. node._ownerScope = scope;
  45720. if (node._ns) node._ns._ownerScope = scope;
  45721. }
  45722. for (const key of Object.keys(declares)) {
  45723. declares[key]._ownerScope = scope;
  45724. }
  45725. }
  45726. function recordType(node, types, declares, overwriteId) {
  45727. switch (node.type) {
  45728. case "TSInterfaceDeclaration":
  45729. case "TSEnumDeclaration":
  45730. case "TSModuleDeclaration": {
  45731. const id = overwriteId || getId(node.id);
  45732. let existing = types[id];
  45733. if (existing) {
  45734. if (node.type === "TSModuleDeclaration") {
  45735. if (existing.type === "TSModuleDeclaration") {
  45736. mergeNamespaces(existing, node);
  45737. } else {
  45738. attachNamespace(existing, node);
  45739. }
  45740. break;
  45741. }
  45742. if (existing.type === "TSModuleDeclaration") {
  45743. types[id] = node;
  45744. attachNamespace(node, existing);
  45745. break;
  45746. }
  45747. if (existing.type !== node.type) {
  45748. break;
  45749. }
  45750. if (node.type === "TSInterfaceDeclaration") {
  45751. existing.body.body.push(...node.body.body);
  45752. } else {
  45753. existing.members.push(...node.members);
  45754. }
  45755. } else {
  45756. types[id] = node;
  45757. }
  45758. break;
  45759. }
  45760. case "ClassDeclaration":
  45761. if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
  45762. break;
  45763. case "TSTypeAliasDeclaration":
  45764. types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
  45765. break;
  45766. case "TSDeclareFunction":
  45767. if (node.id) declares[node.id.name] = node;
  45768. break;
  45769. case "VariableDeclaration": {
  45770. if (node.declare) {
  45771. for (const decl of node.declarations) {
  45772. if (decl.id.type === "Identifier" && decl.id.typeAnnotation) {
  45773. declares[decl.id.name] = decl.id.typeAnnotation.typeAnnotation;
  45774. }
  45775. }
  45776. }
  45777. break;
  45778. }
  45779. }
  45780. }
  45781. function mergeNamespaces(to, from) {
  45782. const toBody = to.body;
  45783. const fromBody = from.body;
  45784. if (toBody.type === "TSModuleDeclaration") {
  45785. if (fromBody.type === "TSModuleDeclaration") {
  45786. mergeNamespaces(toBody, fromBody);
  45787. } else {
  45788. fromBody.body.push({
  45789. type: "ExportNamedDeclaration",
  45790. declaration: toBody,
  45791. exportKind: "type",
  45792. specifiers: []
  45793. });
  45794. }
  45795. } else if (fromBody.type === "TSModuleDeclaration") {
  45796. toBody.body.push({
  45797. type: "ExportNamedDeclaration",
  45798. declaration: fromBody,
  45799. exportKind: "type",
  45800. specifiers: []
  45801. });
  45802. } else {
  45803. toBody.body.push(...fromBody.body);
  45804. }
  45805. }
  45806. function attachNamespace(to, ns) {
  45807. if (!to._ns) {
  45808. to._ns = ns;
  45809. } else {
  45810. mergeNamespaces(to._ns, ns);
  45811. }
  45812. }
  45813. function recordImports(body) {
  45814. const imports = /* @__PURE__ */ Object.create(null);
  45815. for (const s of body) {
  45816. recordImport(s, imports);
  45817. }
  45818. return imports;
  45819. }
  45820. function recordImport(node, imports) {
  45821. if (node.type !== "ImportDeclaration") {
  45822. return;
  45823. }
  45824. for (const s of node.specifiers) {
  45825. imports[s.local.name] = {
  45826. imported: getImportedName(s),
  45827. source: node.source.value
  45828. };
  45829. }
  45830. }
  45831. function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false) {
  45832. try {
  45833. switch (node.type) {
  45834. case "TSStringKeyword":
  45835. return ["String"];
  45836. case "TSNumberKeyword":
  45837. return ["Number"];
  45838. case "TSBooleanKeyword":
  45839. return ["Boolean"];
  45840. case "TSObjectKeyword":
  45841. return ["Object"];
  45842. case "TSNullKeyword":
  45843. return ["null"];
  45844. case "TSTypeLiteral":
  45845. case "TSInterfaceDeclaration": {
  45846. const types = /* @__PURE__ */ new Set();
  45847. const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
  45848. for (const m of members) {
  45849. if (isKeyOf) {
  45850. if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
  45851. types.add("Number");
  45852. } else if (m.type === "TSIndexSignature") {
  45853. const annotation = m.parameters[0].typeAnnotation;
  45854. if (annotation && annotation.type !== "Noop") {
  45855. const type = inferRuntimeType(
  45856. ctx,
  45857. annotation.typeAnnotation,
  45858. scope
  45859. )[0];
  45860. if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
  45861. types.add(type);
  45862. }
  45863. } else {
  45864. types.add("String");
  45865. }
  45866. } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
  45867. types.add("Function");
  45868. } else {
  45869. types.add("Object");
  45870. }
  45871. }
  45872. return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
  45873. }
  45874. case "TSPropertySignature":
  45875. if (node.typeAnnotation) {
  45876. return inferRuntimeType(
  45877. ctx,
  45878. node.typeAnnotation.typeAnnotation,
  45879. scope
  45880. );
  45881. }
  45882. break;
  45883. case "TSMethodSignature":
  45884. case "TSFunctionType":
  45885. return ["Function"];
  45886. case "TSArrayType":
  45887. case "TSTupleType":
  45888. return ["Array"];
  45889. case "TSLiteralType":
  45890. switch (node.literal.type) {
  45891. case "StringLiteral":
  45892. return ["String"];
  45893. case "BooleanLiteral":
  45894. return ["Boolean"];
  45895. case "NumericLiteral":
  45896. case "BigIntLiteral":
  45897. return ["Number"];
  45898. default:
  45899. return [UNKNOWN_TYPE];
  45900. }
  45901. case "TSTypeReference": {
  45902. const resolved = resolveTypeReference(ctx, node, scope);
  45903. if (resolved) {
  45904. if (resolved.type === "TSTypeAliasDeclaration" && resolved.typeAnnotation.type === "TSFunctionType") {
  45905. return ["Function"];
  45906. }
  45907. return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
  45908. }
  45909. if (node.typeName.type === "Identifier") {
  45910. if (isKeyOf) {
  45911. switch (node.typeName.name) {
  45912. case "String":
  45913. case "Array":
  45914. case "ArrayLike":
  45915. case "Parameters":
  45916. case "ConstructorParameters":
  45917. case "ReadonlyArray":
  45918. return ["String", "Number"];
  45919. // TS built-in utility types
  45920. case "Record":
  45921. case "Partial":
  45922. case "Required":
  45923. case "Readonly":
  45924. if (node.typeParameters && node.typeParameters.params[0]) {
  45925. return inferRuntimeType(
  45926. ctx,
  45927. node.typeParameters.params[0],
  45928. scope,
  45929. true
  45930. );
  45931. }
  45932. break;
  45933. case "Pick":
  45934. case "Extract":
  45935. if (node.typeParameters && node.typeParameters.params[1]) {
  45936. return inferRuntimeType(
  45937. ctx,
  45938. node.typeParameters.params[1],
  45939. scope
  45940. );
  45941. }
  45942. break;
  45943. case "Function":
  45944. case "Object":
  45945. case "Set":
  45946. case "Map":
  45947. case "WeakSet":
  45948. case "WeakMap":
  45949. case "Date":
  45950. case "Promise":
  45951. case "Error":
  45952. case "Uppercase":
  45953. case "Lowercase":
  45954. case "Capitalize":
  45955. case "Uncapitalize":
  45956. case "ReadonlyMap":
  45957. case "ReadonlySet":
  45958. return ["String"];
  45959. }
  45960. } else {
  45961. switch (node.typeName.name) {
  45962. case "Array":
  45963. case "Function":
  45964. case "Object":
  45965. case "Set":
  45966. case "Map":
  45967. case "WeakSet":
  45968. case "WeakMap":
  45969. case "Date":
  45970. case "Promise":
  45971. case "Error":
  45972. return [node.typeName.name];
  45973. // TS built-in utility types
  45974. // https://www.typescriptlang.org/docs/handbook/utility-types.html
  45975. case "Partial":
  45976. case "Required":
  45977. case "Readonly":
  45978. case "Record":
  45979. case "Pick":
  45980. case "Omit":
  45981. case "InstanceType":
  45982. return ["Object"];
  45983. case "Uppercase":
  45984. case "Lowercase":
  45985. case "Capitalize":
  45986. case "Uncapitalize":
  45987. return ["String"];
  45988. case "Parameters":
  45989. case "ConstructorParameters":
  45990. case "ReadonlyArray":
  45991. return ["Array"];
  45992. case "ReadonlyMap":
  45993. return ["Map"];
  45994. case "ReadonlySet":
  45995. return ["Set"];
  45996. case "NonNullable":
  45997. if (node.typeParameters && node.typeParameters.params[0]) {
  45998. return inferRuntimeType(
  45999. ctx,
  46000. node.typeParameters.params[0],
  46001. scope
  46002. ).filter((t) => t !== "null");
  46003. }
  46004. break;
  46005. case "Extract":
  46006. if (node.typeParameters && node.typeParameters.params[1]) {
  46007. return inferRuntimeType(
  46008. ctx,
  46009. node.typeParameters.params[1],
  46010. scope
  46011. );
  46012. }
  46013. break;
  46014. case "Exclude":
  46015. case "OmitThisParameter":
  46016. if (node.typeParameters && node.typeParameters.params[0]) {
  46017. return inferRuntimeType(
  46018. ctx,
  46019. node.typeParameters.params[0],
  46020. scope
  46021. );
  46022. }
  46023. break;
  46024. }
  46025. }
  46026. }
  46027. break;
  46028. }
  46029. case "TSParenthesizedType":
  46030. return inferRuntimeType(ctx, node.typeAnnotation, scope);
  46031. case "TSUnionType":
  46032. return flattenTypes(ctx, node.types, scope, isKeyOf);
  46033. case "TSIntersectionType": {
  46034. return flattenTypes(ctx, node.types, scope, isKeyOf).filter(
  46035. (t) => t !== UNKNOWN_TYPE
  46036. );
  46037. }
  46038. case "TSEnumDeclaration":
  46039. return inferEnumType(node);
  46040. case "TSSymbolKeyword":
  46041. return ["Symbol"];
  46042. case "TSIndexedAccessType": {
  46043. const types = resolveIndexType(ctx, node, scope);
  46044. return flattenTypes(ctx, types, scope, isKeyOf);
  46045. }
  46046. case "ClassDeclaration":
  46047. return ["Object"];
  46048. case "TSImportType": {
  46049. const sourceScope = importSourceToScope(
  46050. ctx,
  46051. node.argument,
  46052. scope,
  46053. node.argument.value
  46054. );
  46055. const resolved = resolveTypeReference(ctx, node, sourceScope);
  46056. if (resolved) {
  46057. return inferRuntimeType(ctx, resolved, resolved._ownerScope);
  46058. }
  46059. break;
  46060. }
  46061. case "TSTypeQuery": {
  46062. const id = node.exprName;
  46063. if (id.type === "Identifier") {
  46064. const matched = scope.declares[id.name];
  46065. if (matched) {
  46066. return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
  46067. }
  46068. }
  46069. break;
  46070. }
  46071. // e.g. readonly
  46072. case "TSTypeOperator": {
  46073. return inferRuntimeType(
  46074. ctx,
  46075. node.typeAnnotation,
  46076. scope,
  46077. node.operator === "keyof"
  46078. );
  46079. }
  46080. case "TSAnyKeyword": {
  46081. if (isKeyOf) {
  46082. return ["String", "Number", "Symbol"];
  46083. }
  46084. break;
  46085. }
  46086. }
  46087. } catch (e) {
  46088. }
  46089. return [UNKNOWN_TYPE];
  46090. }
  46091. function flattenTypes(ctx, types, scope, isKeyOf = false) {
  46092. if (types.length === 1) {
  46093. return inferRuntimeType(ctx, types[0], scope, isKeyOf);
  46094. }
  46095. return [
  46096. ...new Set(
  46097. [].concat(
  46098. ...types.map((t) => inferRuntimeType(ctx, t, scope, isKeyOf))
  46099. )
  46100. )
  46101. ];
  46102. }
  46103. function inferEnumType(node) {
  46104. const types = /* @__PURE__ */ new Set();
  46105. for (const m of node.members) {
  46106. if (m.initializer) {
  46107. switch (m.initializer.type) {
  46108. case "StringLiteral":
  46109. types.add("String");
  46110. break;
  46111. case "NumericLiteral":
  46112. types.add("Number");
  46113. break;
  46114. }
  46115. }
  46116. }
  46117. return types.size ? [...types] : ["Number"];
  46118. }
  46119. function resolveExtractPropTypes({ props }, scope) {
  46120. const res = { props: {} };
  46121. for (const key in props) {
  46122. const raw = props[key];
  46123. res.props[key] = reverseInferType(
  46124. raw.key,
  46125. raw.typeAnnotation.typeAnnotation,
  46126. scope
  46127. );
  46128. }
  46129. return res;
  46130. }
  46131. function reverseInferType(key, node, scope, optional = true, checkObjectSyntax = true) {
  46132. if (checkObjectSyntax && node.type === "TSTypeLiteral") {
  46133. const typeType = findStaticPropertyType(node, "type");
  46134. if (typeType) {
  46135. const requiredType = findStaticPropertyType(node, "required");
  46136. const optional2 = requiredType && requiredType.type === "TSLiteralType" && requiredType.literal.type === "BooleanLiteral" ? !requiredType.literal.value : true;
  46137. return reverseInferType(key, typeType, scope, optional2, false);
  46138. }
  46139. } else if (node.type === "TSTypeReference" && node.typeName.type === "Identifier") {
  46140. if (node.typeName.name.endsWith("Constructor")) {
  46141. return createProperty(
  46142. key,
  46143. ctorToType(node.typeName.name),
  46144. scope,
  46145. optional
  46146. );
  46147. } else if (node.typeName.name === "PropType" && node.typeParameters) {
  46148. return createProperty(key, node.typeParameters.params[0], scope, optional);
  46149. }
  46150. }
  46151. if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
  46152. for (const t of node.typeParameters.params) {
  46153. const inferred = reverseInferType(key, t, scope, optional);
  46154. if (inferred) return inferred;
  46155. }
  46156. }
  46157. return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
  46158. }
  46159. function ctorToType(ctorType) {
  46160. const ctor = ctorType.slice(0, -11);
  46161. switch (ctor) {
  46162. case "String":
  46163. case "Number":
  46164. case "Boolean":
  46165. return { type: `TS${ctor}Keyword` };
  46166. case "Array":
  46167. case "Function":
  46168. case "Object":
  46169. case "Set":
  46170. case "Map":
  46171. case "WeakSet":
  46172. case "WeakMap":
  46173. case "Date":
  46174. case "Promise":
  46175. return {
  46176. type: "TSTypeReference",
  46177. typeName: { type: "Identifier", name: ctor }
  46178. };
  46179. }
  46180. return { type: `TSNullKeyword` };
  46181. }
  46182. function findStaticPropertyType(node, key) {
  46183. const prop = node.members.find(
  46184. (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
  46185. );
  46186. return prop && prop.typeAnnotation.typeAnnotation;
  46187. }
  46188. function resolveReturnType(ctx, arg, scope) {
  46189. var _a;
  46190. let resolved = arg;
  46191. if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
  46192. resolved = resolveTypeReference(ctx, arg, scope);
  46193. }
  46194. if (!resolved) return;
  46195. if (resolved.type === "TSFunctionType") {
  46196. return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
  46197. }
  46198. if (resolved.type === "TSDeclareFunction") {
  46199. return resolved.returnType;
  46200. }
  46201. }
  46202. function resolveUnionType(ctx, node, scope) {
  46203. if (node.type === "TSTypeReference") {
  46204. const resolved = resolveTypeReference(ctx, node, scope);
  46205. if (resolved) node = resolved;
  46206. }
  46207. let types;
  46208. if (node.type === "TSUnionType") {
  46209. types = node.types.flatMap((node2) => resolveUnionType(ctx, node2, scope));
  46210. } else {
  46211. types = [node];
  46212. }
  46213. return types;
  46214. }
  46215. const DEFINE_MODEL = "defineModel";
  46216. function processDefineModel(ctx, node, declId) {
  46217. if (!isCallOf(node, DEFINE_MODEL)) {
  46218. return false;
  46219. }
  46220. ctx.hasDefineModelCall = true;
  46221. const type = node.typeParameters && node.typeParameters.params[0] || void 0;
  46222. let modelName;
  46223. let options;
  46224. const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0]);
  46225. const hasName = arg0 && arg0.type === "StringLiteral";
  46226. if (hasName) {
  46227. modelName = arg0.value;
  46228. options = node.arguments[1];
  46229. } else {
  46230. modelName = "modelValue";
  46231. options = arg0;
  46232. }
  46233. if (ctx.modelDecls[modelName]) {
  46234. ctx.error(`duplicate model name ${JSON.stringify(modelName)}`, node);
  46235. }
  46236. let optionsString = options && ctx.getString(options);
  46237. let optionsRemoved = !options;
  46238. const runtimeOptionNodes = [];
  46239. if (options && options.type === "ObjectExpression" && !options.properties.some((p) => p.type === "SpreadElement" || p.computed)) {
  46240. let removed = 0;
  46241. for (let i = options.properties.length - 1; i >= 0; i--) {
  46242. const p = options.properties[i];
  46243. const next = options.properties[i + 1];
  46244. const start = p.start;
  46245. const end = next ? next.start : options.end - 1;
  46246. 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"))) {
  46247. optionsString = optionsString.slice(0, start - options.start) + optionsString.slice(end - options.start);
  46248. } else {
  46249. removed++;
  46250. ctx.s.remove(ctx.startOffset + start, ctx.startOffset + end);
  46251. runtimeOptionNodes.push(p);
  46252. }
  46253. }
  46254. if (removed === options.properties.length) {
  46255. optionsRemoved = true;
  46256. ctx.s.remove(
  46257. ctx.startOffset + (hasName ? arg0.end : options.start),
  46258. ctx.startOffset + options.end
  46259. );
  46260. }
  46261. }
  46262. ctx.modelDecls[modelName] = {
  46263. type,
  46264. options: optionsString,
  46265. runtimeOptionNodes,
  46266. identifier: declId && declId.type === "Identifier" ? declId.name : void 0
  46267. };
  46268. ctx.bindingMetadata[modelName] = "props";
  46269. ctx.s.overwrite(
  46270. ctx.startOffset + node.callee.start,
  46271. ctx.startOffset + node.callee.end,
  46272. ctx.helper("useModel")
  46273. );
  46274. ctx.s.appendLeft(
  46275. ctx.startOffset + (node.arguments.length ? node.arguments[0].start : node.end - 1),
  46276. `__props, ` + (hasName ? `` : `${JSON.stringify(modelName)}${optionsRemoved ? `` : `, `}`)
  46277. );
  46278. return true;
  46279. }
  46280. function genModelProps(ctx) {
  46281. if (!ctx.hasDefineModelCall) return;
  46282. const isProd = !!ctx.options.isProd;
  46283. let modelPropsDecl = "";
  46284. for (const [name, { type, options: runtimeOptions }] of Object.entries(
  46285. ctx.modelDecls
  46286. )) {
  46287. let skipCheck = false;
  46288. let codegenOptions = ``;
  46289. let runtimeTypes = type && inferRuntimeType(ctx, type);
  46290. if (runtimeTypes) {
  46291. const hasBoolean = runtimeTypes.includes("Boolean");
  46292. const hasFunction = runtimeTypes.includes("Function");
  46293. const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE);
  46294. if (hasUnknownType) {
  46295. if (hasBoolean || hasFunction) {
  46296. runtimeTypes = runtimeTypes.filter((t) => t !== UNKNOWN_TYPE);
  46297. skipCheck = true;
  46298. } else {
  46299. runtimeTypes = ["null"];
  46300. }
  46301. }
  46302. if (!isProd) {
  46303. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}` + (skipCheck ? ", skipCheck: true" : "");
  46304. } else if (hasBoolean || runtimeOptions && hasFunction) {
  46305. codegenOptions = `type: ${toRuntimeTypeString(runtimeTypes)}`;
  46306. } else ;
  46307. }
  46308. let decl;
  46309. if (codegenOptions && runtimeOptions) {
  46310. decl = ctx.isTS ? `{ ${codegenOptions}, ...${runtimeOptions} }` : `Object.assign({ ${codegenOptions} }, ${runtimeOptions})`;
  46311. } else if (codegenOptions) {
  46312. decl = `{ ${codegenOptions} }`;
  46313. } else if (runtimeOptions) {
  46314. decl = runtimeOptions;
  46315. } else {
  46316. decl = `{}`;
  46317. }
  46318. modelPropsDecl += `
  46319. ${JSON.stringify(name)}: ${decl},`;
  46320. const modifierPropName = JSON.stringify(
  46321. name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
  46322. );
  46323. modelPropsDecl += `
  46324. ${modifierPropName}: {},`;
  46325. }
  46326. return `{${modelPropsDecl}
  46327. }`;
  46328. }
  46329. const DEFINE_PROPS = "defineProps";
  46330. const WITH_DEFAULTS = "withDefaults";
  46331. function processDefineProps(ctx, node, declId, isWithDefaults = false) {
  46332. if (!isCallOf(node, DEFINE_PROPS)) {
  46333. return processWithDefaults(ctx, node, declId);
  46334. }
  46335. if (ctx.hasDefinePropsCall) {
  46336. ctx.error(`duplicate ${DEFINE_PROPS}() call`, node);
  46337. }
  46338. ctx.hasDefinePropsCall = true;
  46339. ctx.propsRuntimeDecl = node.arguments[0];
  46340. if (ctx.propsRuntimeDecl) {
  46341. for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
  46342. if (!(key in ctx.bindingMetadata)) {
  46343. ctx.bindingMetadata[key] = "props";
  46344. }
  46345. }
  46346. }
  46347. if (node.typeParameters) {
  46348. if (ctx.propsRuntimeDecl) {
  46349. ctx.error(
  46350. `${DEFINE_PROPS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46351. node
  46352. );
  46353. }
  46354. ctx.propsTypeDecl = node.typeParameters.params[0];
  46355. }
  46356. if (!isWithDefaults && declId && declId.type === "ObjectPattern") {
  46357. processPropsDestructure(ctx, declId);
  46358. }
  46359. ctx.propsCall = node;
  46360. ctx.propsDecl = declId;
  46361. return true;
  46362. }
  46363. function processWithDefaults(ctx, node, declId) {
  46364. if (!isCallOf(node, WITH_DEFAULTS)) {
  46365. return false;
  46366. }
  46367. if (!processDefineProps(
  46368. ctx,
  46369. node.arguments[0],
  46370. declId,
  46371. true
  46372. )) {
  46373. ctx.error(
  46374. `${WITH_DEFAULTS}' first argument must be a ${DEFINE_PROPS} call.`,
  46375. node.arguments[0] || node
  46376. );
  46377. }
  46378. if (ctx.propsRuntimeDecl) {
  46379. ctx.error(
  46380. `${WITH_DEFAULTS} can only be used with type-based ${DEFINE_PROPS} declaration.`,
  46381. node
  46382. );
  46383. }
  46384. if (declId && declId.type === "ObjectPattern") {
  46385. ctx.warn(
  46386. `${WITH_DEFAULTS}() is unnecessary when using destructure with ${DEFINE_PROPS}().
  46387. Reactive destructure will be disabled when using withDefaults().
  46388. Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(...). `,
  46389. node.callee
  46390. );
  46391. }
  46392. ctx.propsRuntimeDefaults = node.arguments[1];
  46393. if (!ctx.propsRuntimeDefaults) {
  46394. ctx.error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
  46395. }
  46396. ctx.propsCall = node;
  46397. return true;
  46398. }
  46399. function genRuntimeProps(ctx) {
  46400. let propsDecls;
  46401. if (ctx.propsRuntimeDecl) {
  46402. propsDecls = ctx.getString(ctx.propsRuntimeDecl).trim();
  46403. if (ctx.propsDestructureDecl) {
  46404. const defaults = [];
  46405. for (const key in ctx.propsDestructuredBindings) {
  46406. const d = genDestructuredDefaultValue(ctx, key);
  46407. const finalKey = getEscapedPropName(key);
  46408. if (d)
  46409. defaults.push(
  46410. `${finalKey}: ${d.valueString}${d.needSkipFactory ? `, __skip_${finalKey}: true` : ``}`
  46411. );
  46412. }
  46413. if (defaults.length) {
  46414. propsDecls = `/*@__PURE__*/${ctx.helper(
  46415. `mergeDefaults`
  46416. )}(${propsDecls}, {
  46417. ${defaults.join(",\n ")}
  46418. })`;
  46419. }
  46420. }
  46421. } else if (ctx.propsTypeDecl) {
  46422. propsDecls = extractRuntimeProps(ctx);
  46423. }
  46424. const modelsDecls = genModelProps(ctx);
  46425. if (propsDecls && modelsDecls) {
  46426. return `/*@__PURE__*/${ctx.helper(
  46427. "mergeModels"
  46428. )}(${propsDecls}, ${modelsDecls})`;
  46429. } else {
  46430. return modelsDecls || propsDecls;
  46431. }
  46432. }
  46433. function extractRuntimeProps(ctx) {
  46434. const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl);
  46435. if (!props.length) {
  46436. return;
  46437. }
  46438. const propStrings = [];
  46439. const hasStaticDefaults = hasStaticWithDefaults(ctx);
  46440. for (const prop of props) {
  46441. propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults));
  46442. if ("bindingMetadata" in ctx && !(prop.key in ctx.bindingMetadata)) {
  46443. ctx.bindingMetadata[prop.key] = "props";
  46444. }
  46445. }
  46446. let propsDecls = `{
  46447. ${propStrings.join(",\n ")}
  46448. }`;
  46449. if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
  46450. propsDecls = `/*@__PURE__*/${ctx.helper(
  46451. "mergeDefaults"
  46452. )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`;
  46453. }
  46454. return propsDecls;
  46455. }
  46456. function resolveRuntimePropsFromType(ctx, node) {
  46457. const props = [];
  46458. const elements = resolveTypeElements(ctx, node);
  46459. for (const key in elements.props) {
  46460. const e = elements.props[key];
  46461. let type = inferRuntimeType(ctx, e);
  46462. let skipCheck = false;
  46463. if (type.includes(UNKNOWN_TYPE)) {
  46464. if (type.includes("Boolean") || type.includes("Function")) {
  46465. type = type.filter((t) => t !== UNKNOWN_TYPE);
  46466. skipCheck = true;
  46467. } else {
  46468. type = ["null"];
  46469. }
  46470. }
  46471. props.push({
  46472. key,
  46473. required: !e.optional,
  46474. type: type || [`null`],
  46475. skipCheck
  46476. });
  46477. }
  46478. return props;
  46479. }
  46480. function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStaticDefaults) {
  46481. let defaultString;
  46482. const destructured = genDestructuredDefaultValue(ctx, key, type);
  46483. if (destructured) {
  46484. defaultString = `default: ${destructured.valueString}${destructured.needSkipFactory ? `, skipFactory: true` : ``}`;
  46485. } else if (hasStaticDefaults) {
  46486. const prop = ctx.propsRuntimeDefaults.properties.find(
  46487. (node) => {
  46488. if (node.type === "SpreadElement") return false;
  46489. return resolveObjectKey(node.key, node.computed) === key;
  46490. }
  46491. );
  46492. if (prop) {
  46493. if (prop.type === "ObjectProperty") {
  46494. defaultString = `default: ${ctx.getString(prop.value)}`;
  46495. } else {
  46496. defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
  46497. }
  46498. }
  46499. }
  46500. const finalKey = getEscapedPropName(key);
  46501. if (!ctx.options.isProd) {
  46502. return `${finalKey}: { ${concatStrings([
  46503. `type: ${toRuntimeTypeString(type)}`,
  46504. `required: ${required}`,
  46505. skipCheck && "skipCheck: true",
  46506. defaultString
  46507. ])} }`;
  46508. } else if (type.some(
  46509. (el) => el === "Boolean" || (!hasStaticDefaults || defaultString) && el === "Function"
  46510. )) {
  46511. return `${finalKey}: { ${concatStrings([
  46512. `type: ${toRuntimeTypeString(type)}`,
  46513. defaultString
  46514. ])} }`;
  46515. } else {
  46516. if (ctx.isCE) {
  46517. if (defaultString) {
  46518. return `${finalKey}: ${`{ ${defaultString}, type: ${toRuntimeTypeString(
  46519. type
  46520. )} }`}`;
  46521. } else {
  46522. return `${finalKey}: {type: ${toRuntimeTypeString(type)}}`;
  46523. }
  46524. }
  46525. return `${finalKey}: ${defaultString ? `{ ${defaultString} }` : `{}`}`;
  46526. }
  46527. }
  46528. function hasStaticWithDefaults(ctx) {
  46529. return !!(ctx.propsRuntimeDefaults && ctx.propsRuntimeDefaults.type === "ObjectExpression" && ctx.propsRuntimeDefaults.properties.every(
  46530. (node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
  46531. ));
  46532. }
  46533. function genDestructuredDefaultValue(ctx, key, inferredType) {
  46534. const destructured = ctx.propsDestructuredBindings[key];
  46535. const defaultVal = destructured && destructured.default;
  46536. if (defaultVal) {
  46537. const value = ctx.getString(defaultVal);
  46538. const unwrapped = unwrapTSNode(defaultVal);
  46539. if (inferredType && inferredType.length && !inferredType.includes("null")) {
  46540. const valueType = inferValueType(unwrapped);
  46541. if (valueType && !inferredType.includes(valueType)) {
  46542. ctx.error(
  46543. `Default value of prop "${key}" does not match declared type.`,
  46544. unwrapped
  46545. );
  46546. }
  46547. }
  46548. const needSkipFactory = !inferredType && (isFunctionType(unwrapped) || unwrapped.type === "Identifier");
  46549. const needFactoryWrap = !needSkipFactory && !isLiteralNode(unwrapped) && !(inferredType == null ? void 0 : inferredType.includes("Function"));
  46550. return {
  46551. valueString: needFactoryWrap ? `() => (${value})` : value,
  46552. needSkipFactory
  46553. };
  46554. }
  46555. }
  46556. function inferValueType(node) {
  46557. switch (node.type) {
  46558. case "StringLiteral":
  46559. return "String";
  46560. case "NumericLiteral":
  46561. return "Number";
  46562. case "BooleanLiteral":
  46563. return "Boolean";
  46564. case "ObjectExpression":
  46565. return "Object";
  46566. case "ArrayExpression":
  46567. return "Array";
  46568. case "FunctionExpression":
  46569. case "ArrowFunctionExpression":
  46570. return "Function";
  46571. }
  46572. }
  46573. function processPropsDestructure(ctx, declId) {
  46574. if (ctx.options.propsDestructure === "error") {
  46575. ctx.error(`Props destructure is explicitly prohibited via config.`, declId);
  46576. } else if (ctx.options.propsDestructure === false) {
  46577. return;
  46578. }
  46579. ctx.propsDestructureDecl = declId;
  46580. const registerBinding = (key, local, defaultValue) => {
  46581. ctx.propsDestructuredBindings[key] = { local, default: defaultValue };
  46582. if (local !== key) {
  46583. ctx.bindingMetadata[local] = "props-aliased";
  46584. (ctx.bindingMetadata.__propsAliases || (ctx.bindingMetadata.__propsAliases = {}))[local] = key;
  46585. }
  46586. };
  46587. for (const prop of declId.properties) {
  46588. if (prop.type === "ObjectProperty") {
  46589. const propKey = resolveObjectKey(prop.key, prop.computed);
  46590. if (!propKey) {
  46591. ctx.error(
  46592. `${DEFINE_PROPS}() destructure cannot use computed key.`,
  46593. prop.key
  46594. );
  46595. }
  46596. if (prop.value.type === "AssignmentPattern") {
  46597. const { left, right } = prop.value;
  46598. if (left.type !== "Identifier") {
  46599. ctx.error(
  46600. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46601. left
  46602. );
  46603. }
  46604. registerBinding(propKey, left.name, right);
  46605. } else if (prop.value.type === "Identifier") {
  46606. registerBinding(propKey, prop.value.name);
  46607. } else {
  46608. ctx.error(
  46609. `${DEFINE_PROPS}() destructure does not support nested patterns.`,
  46610. prop.value
  46611. );
  46612. }
  46613. } else {
  46614. ctx.propsDestructureRestId = prop.argument.name;
  46615. ctx.bindingMetadata[ctx.propsDestructureRestId] = "setup-reactive-const";
  46616. }
  46617. }
  46618. }
  46619. function transformDestructuredProps(ctx, vueImportAliases) {
  46620. if (ctx.options.propsDestructure === false) {
  46621. return;
  46622. }
  46623. const rootScope = /* @__PURE__ */ Object.create(null);
  46624. const scopeStack = [rootScope];
  46625. let currentScope = rootScope;
  46626. const excludedIds = /* @__PURE__ */ new WeakSet();
  46627. const parentStack = [];
  46628. const propsLocalToPublicMap = /* @__PURE__ */ Object.create(null);
  46629. for (const key in ctx.propsDestructuredBindings) {
  46630. const { local } = ctx.propsDestructuredBindings[key];
  46631. rootScope[local] = true;
  46632. propsLocalToPublicMap[local] = key;
  46633. }
  46634. function pushScope() {
  46635. scopeStack.push(currentScope = Object.create(currentScope));
  46636. }
  46637. function popScope() {
  46638. scopeStack.pop();
  46639. currentScope = scopeStack[scopeStack.length - 1] || null;
  46640. }
  46641. function registerLocalBinding(id) {
  46642. excludedIds.add(id);
  46643. if (currentScope) {
  46644. currentScope[id.name] = false;
  46645. } else {
  46646. ctx.error(
  46647. "registerBinding called without active scope, something is wrong.",
  46648. id
  46649. );
  46650. }
  46651. }
  46652. function walkScope(node, isRoot = false) {
  46653. for (const stmt of node.body) {
  46654. if (stmt.type === "VariableDeclaration") {
  46655. walkVariableDeclaration(stmt, isRoot);
  46656. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  46657. if (stmt.declare || !stmt.id) continue;
  46658. registerLocalBinding(stmt.id);
  46659. } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
  46660. walkVariableDeclaration(stmt.left);
  46661. } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
  46662. walkVariableDeclaration(stmt.declaration, isRoot);
  46663. } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
  46664. walkVariableDeclaration(stmt.body, isRoot);
  46665. }
  46666. }
  46667. }
  46668. function walkVariableDeclaration(stmt, isRoot = false) {
  46669. if (stmt.declare) {
  46670. return;
  46671. }
  46672. for (const decl of stmt.declarations) {
  46673. const isDefineProps = isRoot && decl.init && isCallOf(unwrapTSNode(decl.init), "defineProps");
  46674. for (const id of extractIdentifiers$1(decl.id)) {
  46675. if (isDefineProps) {
  46676. excludedIds.add(id);
  46677. } else {
  46678. registerLocalBinding(id);
  46679. }
  46680. }
  46681. }
  46682. }
  46683. function rewriteId(id, parent, parentStack2) {
  46684. if (parent.type === "AssignmentExpression" && id === parent.left || parent.type === "UpdateExpression") {
  46685. ctx.error(`Cannot assign to destructured props as they are readonly.`, id);
  46686. }
  46687. if (isStaticProperty(parent) && parent.shorthand) {
  46688. if (!parent.inPattern || isInDestructureAssignment(parent, parentStack2)) {
  46689. ctx.s.appendLeft(
  46690. id.end + ctx.startOffset,
  46691. `: ${genPropsAccessExp(propsLocalToPublicMap[id.name])}`
  46692. );
  46693. }
  46694. } else {
  46695. ctx.s.overwrite(
  46696. id.start + ctx.startOffset,
  46697. id.end + ctx.startOffset,
  46698. genPropsAccessExp(propsLocalToPublicMap[id.name])
  46699. );
  46700. }
  46701. }
  46702. function checkUsage(node, method, alias = method) {
  46703. if (isCallOf(node, alias)) {
  46704. const arg = unwrapTSNode(node.arguments[0]);
  46705. if (arg.type === "Identifier" && currentScope[arg.name]) {
  46706. ctx.error(
  46707. `"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
  46708. arg
  46709. );
  46710. }
  46711. }
  46712. }
  46713. const ast = ctx.scriptSetupAst;
  46714. walkScope(ast, true);
  46715. walk$2(ast, {
  46716. enter(node, parent) {
  46717. parent && parentStack.push(parent);
  46718. if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
  46719. return this.skip();
  46720. }
  46721. checkUsage(node, "watch", vueImportAliases.watch);
  46722. checkUsage(node, "toRef", vueImportAliases.toRef);
  46723. if (isFunctionType(node)) {
  46724. pushScope();
  46725. walkFunctionParams(node, registerLocalBinding);
  46726. if (node.body.type === "BlockStatement") {
  46727. walkScope(node.body);
  46728. }
  46729. return;
  46730. }
  46731. if (node.type === "CatchClause") {
  46732. pushScope();
  46733. if (node.param && node.param.type === "Identifier") {
  46734. registerLocalBinding(node.param);
  46735. }
  46736. walkScope(node.body);
  46737. return;
  46738. }
  46739. if (node.type === "BlockStatement" && !isFunctionType(parent)) {
  46740. pushScope();
  46741. walkScope(node);
  46742. return;
  46743. }
  46744. if (node.type === "Identifier") {
  46745. if (isReferencedIdentifier(node, parent, parentStack) && !excludedIds.has(node)) {
  46746. if (currentScope[node.name]) {
  46747. rewriteId(node, parent, parentStack);
  46748. }
  46749. }
  46750. }
  46751. },
  46752. leave(node, parent) {
  46753. parent && parentStack.pop();
  46754. if (node.type === "BlockStatement" && !isFunctionType(parent) || isFunctionType(node) || node.type === "CatchClause") {
  46755. popScope();
  46756. }
  46757. }
  46758. });
  46759. }
  46760. const DEFINE_EMITS = "defineEmits";
  46761. function processDefineEmits(ctx, node, declId) {
  46762. if (!isCallOf(node, DEFINE_EMITS)) {
  46763. return false;
  46764. }
  46765. if (ctx.hasDefineEmitCall) {
  46766. ctx.error(`duplicate ${DEFINE_EMITS}() call`, node);
  46767. }
  46768. ctx.hasDefineEmitCall = true;
  46769. ctx.emitsRuntimeDecl = node.arguments[0];
  46770. if (node.typeParameters) {
  46771. if (ctx.emitsRuntimeDecl) {
  46772. ctx.error(
  46773. `${DEFINE_EMITS}() cannot accept both type and non-type arguments at the same time. Use one or the other.`,
  46774. node
  46775. );
  46776. }
  46777. ctx.emitsTypeDecl = node.typeParameters.params[0];
  46778. }
  46779. ctx.emitDecl = declId;
  46780. return true;
  46781. }
  46782. function genRuntimeEmits(ctx) {
  46783. let emitsDecl = "";
  46784. if (ctx.emitsRuntimeDecl) {
  46785. emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim();
  46786. } else if (ctx.emitsTypeDecl) {
  46787. const typeDeclaredEmits = extractRuntimeEmits(ctx);
  46788. emitsDecl = typeDeclaredEmits.size ? `[${Array.from(typeDeclaredEmits).map((k) => JSON.stringify(k)).join(", ")}]` : ``;
  46789. }
  46790. if (ctx.hasDefineModelCall) {
  46791. let modelEmitsDecl = `[${Object.keys(ctx.modelDecls).map((n) => JSON.stringify(`update:${n}`)).join(", ")}]`;
  46792. emitsDecl = emitsDecl ? `/*@__PURE__*/${ctx.helper(
  46793. "mergeModels"
  46794. )}(${emitsDecl}, ${modelEmitsDecl})` : modelEmitsDecl;
  46795. }
  46796. return emitsDecl;
  46797. }
  46798. function extractRuntimeEmits(ctx) {
  46799. const emits = /* @__PURE__ */ new Set();
  46800. const node = ctx.emitsTypeDecl;
  46801. if (node.type === "TSFunctionType") {
  46802. extractEventNames(ctx, node.parameters[0], emits);
  46803. return emits;
  46804. }
  46805. const { props, calls } = resolveTypeElements(ctx, node);
  46806. let hasProperty = false;
  46807. for (const key in props) {
  46808. emits.add(key);
  46809. hasProperty = true;
  46810. }
  46811. if (calls) {
  46812. if (hasProperty) {
  46813. ctx.error(
  46814. `defineEmits() type cannot mixed call signature and property syntax.`,
  46815. node
  46816. );
  46817. }
  46818. for (const call of calls) {
  46819. extractEventNames(ctx, call.parameters[0], emits);
  46820. }
  46821. }
  46822. return emits;
  46823. }
  46824. function extractEventNames(ctx, eventName, emits) {
  46825. if (eventName.type === "Identifier" && eventName.typeAnnotation && eventName.typeAnnotation.type === "TSTypeAnnotation") {
  46826. const types = resolveUnionType(ctx, eventName.typeAnnotation.typeAnnotation);
  46827. for (const type of types) {
  46828. if (type.type === "TSLiteralType") {
  46829. if (type.literal.type !== "UnaryExpression" && type.literal.type !== "TemplateLiteral") {
  46830. emits.add(String(type.literal.value));
  46831. }
  46832. }
  46833. }
  46834. }
  46835. }
  46836. const DEFINE_EXPOSE = "defineExpose";
  46837. function processDefineExpose(ctx, node) {
  46838. if (isCallOf(node, DEFINE_EXPOSE)) {
  46839. if (ctx.hasDefineExposeCall) {
  46840. ctx.error(`duplicate ${DEFINE_EXPOSE}() call`, node);
  46841. }
  46842. ctx.hasDefineExposeCall = true;
  46843. return true;
  46844. }
  46845. return false;
  46846. }
  46847. const DEFINE_SLOTS = "defineSlots";
  46848. function processDefineSlots(ctx, node, declId) {
  46849. if (!isCallOf(node, DEFINE_SLOTS)) {
  46850. return false;
  46851. }
  46852. if (ctx.hasDefineSlotsCall) {
  46853. ctx.error(`duplicate ${DEFINE_SLOTS}() call`, node);
  46854. }
  46855. ctx.hasDefineSlotsCall = true;
  46856. if (node.arguments.length > 0) {
  46857. ctx.error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
  46858. }
  46859. if (declId) {
  46860. ctx.s.overwrite(
  46861. ctx.startOffset + node.start,
  46862. ctx.startOffset + node.end,
  46863. `${ctx.helper("useSlots")}()`
  46864. );
  46865. }
  46866. return true;
  46867. }
  46868. const DEFINE_OPTIONS = "defineOptions";
  46869. function processDefineOptions(ctx, node) {
  46870. if (!isCallOf(node, DEFINE_OPTIONS)) {
  46871. return false;
  46872. }
  46873. if (ctx.hasDefineOptionsCall) {
  46874. ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node);
  46875. }
  46876. if (node.typeParameters) {
  46877. ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
  46878. }
  46879. if (!node.arguments[0]) return true;
  46880. ctx.hasDefineOptionsCall = true;
  46881. ctx.optionsRuntimeDecl = unwrapTSNode(node.arguments[0]);
  46882. let propsOption = void 0;
  46883. let emitsOption = void 0;
  46884. let exposeOption = void 0;
  46885. let slotsOption = void 0;
  46886. if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
  46887. for (const prop of ctx.optionsRuntimeDecl.properties) {
  46888. if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
  46889. switch (prop.key.name) {
  46890. case "props":
  46891. propsOption = prop;
  46892. break;
  46893. case "emits":
  46894. emitsOption = prop;
  46895. break;
  46896. case "expose":
  46897. exposeOption = prop;
  46898. break;
  46899. case "slots":
  46900. slotsOption = prop;
  46901. break;
  46902. }
  46903. }
  46904. }
  46905. }
  46906. if (propsOption) {
  46907. ctx.error(
  46908. `${DEFINE_OPTIONS}() cannot be used to declare props. Use ${DEFINE_PROPS}() instead.`,
  46909. propsOption
  46910. );
  46911. }
  46912. if (emitsOption) {
  46913. ctx.error(
  46914. `${DEFINE_OPTIONS}() cannot be used to declare emits. Use ${DEFINE_EMITS}() instead.`,
  46915. emitsOption
  46916. );
  46917. }
  46918. if (exposeOption) {
  46919. ctx.error(
  46920. `${DEFINE_OPTIONS}() cannot be used to declare expose. Use ${DEFINE_EXPOSE}() instead.`,
  46921. exposeOption
  46922. );
  46923. }
  46924. if (slotsOption) {
  46925. ctx.error(
  46926. `${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
  46927. slotsOption
  46928. );
  46929. }
  46930. return true;
  46931. }
  46932. function processAwait(ctx, node, needSemi, isStatement) {
  46933. const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
  46934. const startOffset = ctx.startOffset;
  46935. const argumentStr = ctx.descriptor.source.slice(
  46936. argumentStart + startOffset,
  46937. node.argument.end + startOffset
  46938. );
  46939. const containsNestedAwait = /\bawait\b/.test(argumentStr);
  46940. ctx.s.overwrite(
  46941. node.start + startOffset,
  46942. argumentStart + startOffset,
  46943. `${needSemi ? `;` : ``}(
  46944. ([__temp,__restore] = ${ctx.helper(
  46945. `withAsyncContext`
  46946. )}(${containsNestedAwait ? `async ` : ``}() => `
  46947. );
  46948. ctx.s.appendLeft(
  46949. node.end + startOffset,
  46950. `)),
  46951. ${isStatement ? `` : `__temp = `}await __temp,
  46952. __restore()${isStatement ? `` : `,
  46953. __temp`}
  46954. )`
  46955. );
  46956. }
  46957. var __defProp$1 = Object.defineProperty;
  46958. var __defProps = Object.defineProperties;
  46959. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  46960. var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
  46961. var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
  46962. var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
  46963. var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  46964. var __spreadValues$1 = (a, b) => {
  46965. for (var prop in b || (b = {}))
  46966. if (__hasOwnProp$1.call(b, prop))
  46967. __defNormalProp$1(a, prop, b[prop]);
  46968. if (__getOwnPropSymbols$1)
  46969. for (var prop of __getOwnPropSymbols$1(b)) {
  46970. if (__propIsEnum$1.call(b, prop))
  46971. __defNormalProp$1(a, prop, b[prop]);
  46972. }
  46973. return a;
  46974. };
  46975. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  46976. const MACROS = [
  46977. DEFINE_PROPS,
  46978. DEFINE_EMITS,
  46979. DEFINE_EXPOSE,
  46980. DEFINE_OPTIONS,
  46981. DEFINE_SLOTS,
  46982. DEFINE_MODEL,
  46983. WITH_DEFAULTS
  46984. ];
  46985. function compileScript(sfc, options) {
  46986. var _a, _b, _c;
  46987. if (!options.id) {
  46988. warnOnce$1(
  46989. `compileScript now requires passing the \`id\` option.
  46990. Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
  46991. );
  46992. }
  46993. const ctx = new ScriptCompileContext(sfc, options);
  46994. const { script, scriptSetup, source, filename } = sfc;
  46995. const hoistStatic = options.hoistStatic !== false && !script;
  46996. const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
  46997. const scriptLang = script && script.lang;
  46998. const scriptSetupLang = scriptSetup && scriptSetup.lang;
  46999. if (!scriptSetup) {
  47000. if (!script) {
  47001. throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
  47002. }
  47003. return processNormalScript(ctx, scopeId);
  47004. }
  47005. if (script && scriptLang !== scriptSetupLang) {
  47006. throw new Error(
  47007. `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
  47008. );
  47009. }
  47010. if (scriptSetupLang && !ctx.isJS && !ctx.isTS) {
  47011. return scriptSetup;
  47012. }
  47013. const scriptBindings = /* @__PURE__ */ Object.create(null);
  47014. const setupBindings = /* @__PURE__ */ Object.create(null);
  47015. let defaultExport;
  47016. let hasAwait = false;
  47017. let hasInlinedSsrRenderFn = false;
  47018. const startOffset = ctx.startOffset;
  47019. const endOffset = ctx.endOffset;
  47020. const scriptStartOffset = script && script.loc.start.offset;
  47021. const scriptEndOffset = script && script.loc.end.offset;
  47022. function hoistNode(node) {
  47023. const start = node.start + startOffset;
  47024. let end = node.end + startOffset;
  47025. if (node.trailingComments && node.trailingComments.length > 0) {
  47026. const lastCommentNode = node.trailingComments[node.trailingComments.length - 1];
  47027. end = lastCommentNode.end + startOffset;
  47028. }
  47029. while (end <= source.length) {
  47030. if (!/\s/.test(source.charAt(end))) {
  47031. break;
  47032. }
  47033. end++;
  47034. }
  47035. ctx.s.move(start, end, 0);
  47036. }
  47037. function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
  47038. let isUsedInTemplate = needTemplateUsageCheck;
  47039. if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
  47040. isUsedInTemplate = isImportUsed(local, sfc);
  47041. }
  47042. ctx.userImports[local] = {
  47043. isType,
  47044. imported,
  47045. local,
  47046. source: source2,
  47047. isFromSetup,
  47048. isUsedInTemplate
  47049. };
  47050. }
  47051. function checkInvalidScopeReference(node, method) {
  47052. if (!node) return;
  47053. walkIdentifiers(node, (id) => {
  47054. const binding = setupBindings[id.name];
  47055. if (binding && binding !== "literal-const") {
  47056. ctx.error(
  47057. `\`${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.`,
  47058. id
  47059. );
  47060. }
  47061. });
  47062. }
  47063. const scriptAst = ctx.scriptAst;
  47064. const scriptSetupAst = ctx.scriptSetupAst;
  47065. if (scriptAst) {
  47066. for (const node of scriptAst.body) {
  47067. if (node.type === "ImportDeclaration") {
  47068. for (const specifier of node.specifiers) {
  47069. const imported = getImportedName(specifier);
  47070. registerUserImport(
  47071. node.source.value,
  47072. specifier.local.name,
  47073. imported,
  47074. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47075. false,
  47076. !options.inlineTemplate
  47077. );
  47078. }
  47079. }
  47080. }
  47081. }
  47082. for (const node of scriptSetupAst.body) {
  47083. if (node.type === "ImportDeclaration") {
  47084. hoistNode(node);
  47085. let removed = 0;
  47086. const removeSpecifier = (i) => {
  47087. const removeLeft = i > removed;
  47088. removed++;
  47089. const current = node.specifiers[i];
  47090. const next = node.specifiers[i + 1];
  47091. ctx.s.remove(
  47092. removeLeft ? node.specifiers[i - 1].end + startOffset : current.start + startOffset,
  47093. next && !removeLeft ? next.start + startOffset : current.end + startOffset
  47094. );
  47095. };
  47096. for (let i = 0; i < node.specifiers.length; i++) {
  47097. const specifier = node.specifiers[i];
  47098. const local = specifier.local.name;
  47099. const imported = getImportedName(specifier);
  47100. const source2 = node.source.value;
  47101. const existing = ctx.userImports[local];
  47102. if (source2 === "vue" && MACROS.includes(imported)) {
  47103. if (local === imported) {
  47104. warnOnce$1(
  47105. `\`${imported}\` is a compiler macro and no longer needs to be imported.`
  47106. );
  47107. } else {
  47108. ctx.error(
  47109. `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
  47110. specifier
  47111. );
  47112. }
  47113. removeSpecifier(i);
  47114. } else if (existing) {
  47115. if (existing.source === source2 && existing.imported === imported) {
  47116. removeSpecifier(i);
  47117. } else {
  47118. ctx.error(
  47119. `different imports aliased to same local name.`,
  47120. specifier
  47121. );
  47122. }
  47123. } else {
  47124. registerUserImport(
  47125. source2,
  47126. local,
  47127. imported,
  47128. node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
  47129. true,
  47130. !options.inlineTemplate
  47131. );
  47132. }
  47133. }
  47134. if (node.specifiers.length && removed === node.specifiers.length) {
  47135. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47136. }
  47137. }
  47138. }
  47139. const vueImportAliases = {};
  47140. for (const key in ctx.userImports) {
  47141. const { source: source2, imported, local } = ctx.userImports[key];
  47142. if (source2 === "vue") vueImportAliases[imported] = local;
  47143. }
  47144. if (script && scriptAst) {
  47145. for (const node of scriptAst.body) {
  47146. if (node.type === "ExportDefaultDeclaration") {
  47147. defaultExport = node;
  47148. let optionProperties;
  47149. if (defaultExport.declaration.type === "ObjectExpression") {
  47150. optionProperties = defaultExport.declaration.properties;
  47151. } else if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.arguments[0] && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
  47152. optionProperties = defaultExport.declaration.arguments[0].properties;
  47153. }
  47154. if (optionProperties) {
  47155. for (const p of optionProperties) {
  47156. if (p.type === "ObjectProperty" && p.key.type === "Identifier" && p.key.name === "name") {
  47157. ctx.hasDefaultExportName = true;
  47158. }
  47159. if ((p.type === "ObjectMethod" || p.type === "ObjectProperty") && p.key.type === "Identifier" && p.key.name === "render") {
  47160. ctx.hasDefaultExportRender = true;
  47161. }
  47162. }
  47163. }
  47164. const start = node.start + scriptStartOffset;
  47165. const end = node.declaration.start + scriptStartOffset;
  47166. ctx.s.overwrite(start, end, `const ${normalScriptDefaultVar} = `);
  47167. } else if (node.type === "ExportNamedDeclaration") {
  47168. const defaultSpecifier = node.specifiers.find(
  47169. (s) => s.exported.type === "Identifier" && s.exported.name === "default"
  47170. );
  47171. if (defaultSpecifier) {
  47172. defaultExport = node;
  47173. if (node.specifiers.length > 1) {
  47174. ctx.s.remove(
  47175. defaultSpecifier.start + scriptStartOffset,
  47176. defaultSpecifier.end + scriptStartOffset
  47177. );
  47178. } else {
  47179. ctx.s.remove(
  47180. node.start + scriptStartOffset,
  47181. node.end + scriptStartOffset
  47182. );
  47183. }
  47184. if (node.source) {
  47185. ctx.s.prepend(
  47186. `import { ${defaultSpecifier.local.name} as ${normalScriptDefaultVar} } from '${node.source.value}'
  47187. `
  47188. );
  47189. } else {
  47190. ctx.s.appendLeft(
  47191. scriptEndOffset,
  47192. `
  47193. const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
  47194. `
  47195. );
  47196. }
  47197. }
  47198. if (node.declaration) {
  47199. walkDeclaration(
  47200. "script",
  47201. node.declaration,
  47202. scriptBindings,
  47203. vueImportAliases,
  47204. hoistStatic
  47205. );
  47206. }
  47207. } else if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47208. walkDeclaration(
  47209. "script",
  47210. node,
  47211. scriptBindings,
  47212. vueImportAliases,
  47213. hoistStatic
  47214. );
  47215. }
  47216. }
  47217. if (scriptStartOffset > startOffset) {
  47218. if (!/\n$/.test(script.content.trim())) {
  47219. ctx.s.appendLeft(scriptEndOffset, `
  47220. `);
  47221. }
  47222. ctx.s.move(scriptStartOffset, scriptEndOffset, 0);
  47223. }
  47224. }
  47225. for (const node of scriptSetupAst.body) {
  47226. if (node.type === "ExpressionStatement") {
  47227. const expr = unwrapTSNode(node.expression);
  47228. if (processDefineProps(ctx, expr) || processDefineEmits(ctx, expr) || processDefineOptions(ctx, expr) || processDefineSlots(ctx, expr)) {
  47229. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47230. } else if (processDefineExpose(ctx, expr)) {
  47231. const callee = expr.callee;
  47232. ctx.s.overwrite(
  47233. callee.start + startOffset,
  47234. callee.end + startOffset,
  47235. "__expose"
  47236. );
  47237. } else {
  47238. processDefineModel(ctx, expr);
  47239. }
  47240. }
  47241. if (node.type === "VariableDeclaration" && !node.declare) {
  47242. const total = node.declarations.length;
  47243. let left = total;
  47244. let lastNonRemoved;
  47245. for (let i = 0; i < total; i++) {
  47246. const decl = node.declarations[i];
  47247. const init = decl.init && unwrapTSNode(decl.init);
  47248. if (init) {
  47249. if (processDefineOptions(ctx, init)) {
  47250. ctx.error(
  47251. `${DEFINE_OPTIONS}() has no returning value, it cannot be assigned.`,
  47252. node
  47253. );
  47254. }
  47255. const isDefineProps = processDefineProps(ctx, init, decl.id);
  47256. if (ctx.propsDestructureRestId) {
  47257. setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
  47258. }
  47259. const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
  47260. !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
  47261. if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
  47262. if (left === 1) {
  47263. ctx.s.remove(node.start + startOffset, node.end + startOffset);
  47264. } else {
  47265. let start = decl.start + startOffset;
  47266. let end = decl.end + startOffset;
  47267. if (i === total - 1) {
  47268. start = node.declarations[lastNonRemoved].end + startOffset;
  47269. } else {
  47270. end = node.declarations[i + 1].start + startOffset;
  47271. }
  47272. ctx.s.remove(start, end);
  47273. left--;
  47274. }
  47275. } else if (isDefineEmits) {
  47276. ctx.s.overwrite(
  47277. startOffset + init.start,
  47278. startOffset + init.end,
  47279. "__emit"
  47280. );
  47281. } else {
  47282. lastNonRemoved = i;
  47283. }
  47284. }
  47285. }
  47286. }
  47287. let isAllLiteral = false;
  47288. if ((node.type === "VariableDeclaration" || node.type === "FunctionDeclaration" || node.type === "ClassDeclaration" || node.type === "TSEnumDeclaration") && !node.declare) {
  47289. isAllLiteral = walkDeclaration(
  47290. "scriptSetup",
  47291. node,
  47292. setupBindings,
  47293. vueImportAliases,
  47294. hoistStatic,
  47295. !!ctx.propsDestructureDecl
  47296. );
  47297. }
  47298. if (hoistStatic && isAllLiteral) {
  47299. hoistNode(node);
  47300. }
  47301. if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
  47302. const scope = [scriptSetupAst.body];
  47303. walk$2(node, {
  47304. enter(child, parent) {
  47305. if (isFunctionType(child)) {
  47306. this.skip();
  47307. }
  47308. if (child.type === "BlockStatement") {
  47309. scope.push(child.body);
  47310. }
  47311. if (child.type === "AwaitExpression") {
  47312. hasAwait = true;
  47313. const currentScope = scope[scope.length - 1];
  47314. const needsSemi = currentScope.some((n, i) => {
  47315. return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
  47316. });
  47317. processAwait(
  47318. ctx,
  47319. child,
  47320. needsSemi,
  47321. parent.type === "ExpressionStatement"
  47322. );
  47323. }
  47324. },
  47325. exit(node2) {
  47326. if (node2.type === "BlockStatement") scope.pop();
  47327. }
  47328. });
  47329. }
  47330. if (node.type === "ExportNamedDeclaration" && node.exportKind !== "type" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration") {
  47331. ctx.error(
  47332. `<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.`,
  47333. node
  47334. );
  47335. }
  47336. if (ctx.isTS) {
  47337. if (node.type.startsWith("TS") || node.type === "ExportNamedDeclaration" && node.exportKind === "type" || node.type === "VariableDeclaration" && node.declare) {
  47338. if (node.type !== "TSEnumDeclaration") {
  47339. hoistNode(node);
  47340. }
  47341. }
  47342. }
  47343. }
  47344. if (ctx.propsDestructureDecl) {
  47345. transformDestructuredProps(ctx, vueImportAliases);
  47346. }
  47347. checkInvalidScopeReference(ctx.propsRuntimeDecl, DEFINE_PROPS);
  47348. checkInvalidScopeReference(ctx.propsRuntimeDefaults, DEFINE_PROPS);
  47349. checkInvalidScopeReference(ctx.propsDestructureDecl, DEFINE_PROPS);
  47350. checkInvalidScopeReference(ctx.emitsRuntimeDecl, DEFINE_EMITS);
  47351. checkInvalidScopeReference(ctx.optionsRuntimeDecl, DEFINE_OPTIONS);
  47352. for (const { runtimeOptionNodes } of Object.values(ctx.modelDecls)) {
  47353. for (const node of runtimeOptionNodes) {
  47354. checkInvalidScopeReference(node, DEFINE_MODEL);
  47355. }
  47356. }
  47357. if (script) {
  47358. if (startOffset < scriptStartOffset) {
  47359. ctx.s.remove(0, startOffset);
  47360. ctx.s.remove(endOffset, scriptStartOffset);
  47361. ctx.s.remove(scriptEndOffset, source.length);
  47362. } else {
  47363. ctx.s.remove(0, scriptStartOffset);
  47364. ctx.s.remove(scriptEndOffset, startOffset);
  47365. ctx.s.remove(endOffset, source.length);
  47366. }
  47367. } else {
  47368. ctx.s.remove(0, startOffset);
  47369. ctx.s.remove(endOffset, source.length);
  47370. }
  47371. if (scriptAst) {
  47372. Object.assign(ctx.bindingMetadata, analyzeScriptBindings(scriptAst.body));
  47373. }
  47374. for (const [key, { isType, imported, source: source2 }] of Object.entries(
  47375. ctx.userImports
  47376. )) {
  47377. if (isType) continue;
  47378. ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
  47379. }
  47380. for (const key in scriptBindings) {
  47381. ctx.bindingMetadata[key] = scriptBindings[key];
  47382. }
  47383. for (const key in setupBindings) {
  47384. ctx.bindingMetadata[key] = setupBindings[key];
  47385. }
  47386. if (sfc.cssVars.length && // no need to do this when targeting SSR
  47387. !((_a = options.templateOptions) == null ? void 0 : _a.ssr)) {
  47388. ctx.helperImports.add(CSS_VARS_HELPER);
  47389. ctx.helperImports.add("unref");
  47390. ctx.s.prependLeft(
  47391. startOffset,
  47392. `
  47393. ${genCssVarsCode(
  47394. sfc.cssVars,
  47395. ctx.bindingMetadata,
  47396. scopeId,
  47397. !!options.isProd
  47398. )}
  47399. `
  47400. );
  47401. }
  47402. let args = `__props`;
  47403. if (ctx.propsTypeDecl) {
  47404. args += `: any`;
  47405. }
  47406. if (ctx.propsDecl) {
  47407. if (ctx.propsDestructureRestId) {
  47408. ctx.s.overwrite(
  47409. startOffset + ctx.propsCall.start,
  47410. startOffset + ctx.propsCall.end,
  47411. `${ctx.helper(`createPropsRestProxy`)}(__props, ${JSON.stringify(
  47412. Object.keys(ctx.propsDestructuredBindings)
  47413. )})`
  47414. );
  47415. ctx.s.overwrite(
  47416. startOffset + ctx.propsDestructureDecl.start,
  47417. startOffset + ctx.propsDestructureDecl.end,
  47418. ctx.propsDestructureRestId
  47419. );
  47420. } else if (!ctx.propsDestructureDecl) {
  47421. ctx.s.overwrite(
  47422. startOffset + ctx.propsCall.start,
  47423. startOffset + ctx.propsCall.end,
  47424. "__props"
  47425. );
  47426. }
  47427. }
  47428. if (hasAwait) {
  47429. const any = ctx.isTS ? `: any` : ``;
  47430. ctx.s.prependLeft(startOffset, `
  47431. let __temp${any}, __restore${any}
  47432. `);
  47433. }
  47434. const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
  47435. if (ctx.emitDecl) {
  47436. destructureElements.push(`emit: __emit`);
  47437. }
  47438. if (destructureElements.length) {
  47439. args += `, { ${destructureElements.join(", ")} }`;
  47440. }
  47441. let templateMap;
  47442. let returned;
  47443. if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
  47444. const allBindings = __spreadValues$1(__spreadValues$1({}, scriptBindings), setupBindings);
  47445. for (const key in ctx.userImports) {
  47446. if (!ctx.userImports[key].isType && ctx.userImports[key].isUsedInTemplate) {
  47447. allBindings[key] = true;
  47448. }
  47449. }
  47450. returned = `{ `;
  47451. for (const key in allBindings) {
  47452. if (allBindings[key] === true && ctx.userImports[key].source !== "vue" && !ctx.userImports[key].source.endsWith(".vue")) {
  47453. returned += `get ${key}() { return ${key} }, `;
  47454. } else if (ctx.bindingMetadata[key] === "setup-let") {
  47455. const setArg = key === "v" ? `_v` : `v`;
  47456. returned += `get ${key}() { return ${key} }, set ${key}(${setArg}) { ${key} = ${setArg} }, `;
  47457. } else {
  47458. returned += `${key}, `;
  47459. }
  47460. }
  47461. returned = returned.replace(/, $/, "") + ` }`;
  47462. } else {
  47463. if (sfc.template && !sfc.template.src) {
  47464. if (options.templateOptions && options.templateOptions.ssr) {
  47465. hasInlinedSsrRenderFn = true;
  47466. }
  47467. const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate(__spreadProps(__spreadValues$1({
  47468. filename,
  47469. ast: sfc.template.ast,
  47470. source: sfc.template.content,
  47471. inMap: sfc.template.map
  47472. }, options.templateOptions), {
  47473. id: scopeId,
  47474. scoped: sfc.styles.some((s) => s.scoped),
  47475. isProd: options.isProd,
  47476. ssrCssVars: sfc.cssVars,
  47477. compilerOptions: __spreadProps(__spreadValues$1({}, options.templateOptions && options.templateOptions.compilerOptions), {
  47478. inline: true,
  47479. isTS: ctx.isTS,
  47480. bindingMetadata: ctx.bindingMetadata
  47481. })
  47482. }));
  47483. templateMap = map2;
  47484. if (tips.length) {
  47485. tips.forEach(warnOnce$1);
  47486. }
  47487. const err = errors[0];
  47488. if (typeof err === "string") {
  47489. throw new Error(err);
  47490. } else if (err) {
  47491. if (err.loc) {
  47492. err.message += `
  47493. ` + sfc.filename + "\n" + generateCodeFrame(
  47494. source,
  47495. err.loc.start.offset,
  47496. err.loc.end.offset
  47497. ) + `
  47498. `;
  47499. }
  47500. throw err;
  47501. }
  47502. if (preamble) {
  47503. ctx.s.prepend(preamble);
  47504. }
  47505. if (ast && ast.helpers.has(UNREF)) {
  47506. ctx.helperImports.delete("unref");
  47507. }
  47508. returned = code;
  47509. } else {
  47510. returned = `() => {}`;
  47511. }
  47512. }
  47513. if (!options.inlineTemplate && true) {
  47514. ctx.s.appendRight(
  47515. endOffset,
  47516. `
  47517. const __returned__ = ${returned}
  47518. Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
  47519. return __returned__
  47520. }
  47521. `
  47522. );
  47523. } else {
  47524. ctx.s.appendRight(endOffset, `
  47525. return ${returned}
  47526. }
  47527. `);
  47528. }
  47529. const genDefaultAs = options.genDefaultAs ? `const ${options.genDefaultAs} =` : `export default`;
  47530. let runtimeOptions = ``;
  47531. if (!ctx.hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
  47532. const match = filename.match(/([^/\\]+)\.\w+$/);
  47533. if (match) {
  47534. runtimeOptions += `
  47535. __name: '${match[1]}',`;
  47536. }
  47537. }
  47538. if (hasInlinedSsrRenderFn) {
  47539. runtimeOptions += `
  47540. __ssrInlineRender: true,`;
  47541. }
  47542. const propsDecl = genRuntimeProps(ctx);
  47543. if (propsDecl) runtimeOptions += `
  47544. props: ${propsDecl},`;
  47545. const emitsDecl = genRuntimeEmits(ctx);
  47546. if (emitsDecl) runtimeOptions += `
  47547. emits: ${emitsDecl},`;
  47548. let definedOptions = "";
  47549. if (ctx.optionsRuntimeDecl) {
  47550. definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
  47551. }
  47552. const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
  47553. `;
  47554. if (ctx.isTS) {
  47555. const def = (defaultExport ? `
  47556. ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
  47557. ...${definedOptions},` : "");
  47558. ctx.s.prependLeft(
  47559. startOffset,
  47560. `
  47561. ${genDefaultAs} /*@__PURE__*/${ctx.helper(
  47562. `defineComponent`
  47563. )}({${def}${runtimeOptions}
  47564. ${hasAwait ? `async ` : ``}setup(${args}) {
  47565. ${exposeCall}`
  47566. );
  47567. ctx.s.appendRight(endOffset, `})`);
  47568. } else {
  47569. if (defaultExport || definedOptions) {
  47570. ctx.s.prependLeft(
  47571. startOffset,
  47572. `
  47573. ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
  47574. ${hasAwait ? `async ` : ``}setup(${args}) {
  47575. ${exposeCall}`
  47576. );
  47577. ctx.s.appendRight(endOffset, `})`);
  47578. } else {
  47579. ctx.s.prependLeft(
  47580. startOffset,
  47581. `
  47582. ${genDefaultAs} {${runtimeOptions}
  47583. ${hasAwait ? `async ` : ``}setup(${args}) {
  47584. ${exposeCall}`
  47585. );
  47586. ctx.s.appendRight(endOffset, `}`);
  47587. }
  47588. }
  47589. if (ctx.helperImports.size > 0) {
  47590. const runtimeModuleName = (_c = (_b = options.templateOptions) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.runtimeModuleName;
  47591. const importSrc = runtimeModuleName ? JSON.stringify(runtimeModuleName) : `'vue'`;
  47592. ctx.s.prepend(
  47593. `import { ${[...ctx.helperImports].map((h) => `${h} as _${h}`).join(", ")} } from ${importSrc}
  47594. `
  47595. );
  47596. }
  47597. const content = ctx.s.toString();
  47598. let map = options.sourceMap !== false ? ctx.s.generateMap({
  47599. source: filename,
  47600. hires: true,
  47601. includeContent: true
  47602. }) : void 0;
  47603. if (templateMap && map) {
  47604. const offset = content.indexOf(returned);
  47605. const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
  47606. map = mergeSourceMaps(map, templateMap, templateLineOffset);
  47607. }
  47608. return __spreadProps(__spreadValues$1({}, scriptSetup), {
  47609. bindings: ctx.bindingMetadata,
  47610. imports: ctx.userImports,
  47611. content,
  47612. map,
  47613. scriptAst: scriptAst == null ? void 0 : scriptAst.body,
  47614. scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
  47615. deps: ctx.deps ? [...ctx.deps] : void 0
  47616. });
  47617. }
  47618. function registerBinding(bindings, node, type) {
  47619. bindings[node.name] = type;
  47620. }
  47621. function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
  47622. let isAllLiteral = false;
  47623. if (node.type === "VariableDeclaration") {
  47624. const isConst = node.kind === "const";
  47625. isAllLiteral = isConst && node.declarations.every(
  47626. (decl) => decl.id.type === "Identifier" && isStaticNode(decl.init)
  47627. );
  47628. for (const { id, init: _init } of node.declarations) {
  47629. const init = _init && unwrapTSNode(_init);
  47630. const isConstMacroCall = isConst && isCallOf(
  47631. init,
  47632. (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
  47633. );
  47634. if (id.type === "Identifier") {
  47635. let bindingType;
  47636. const userReactiveBinding = userImportAliases["reactive"];
  47637. if ((hoistStatic || from === "script") && (isAllLiteral || isConst && isStaticNode(init))) {
  47638. bindingType = "literal-const";
  47639. } else if (isCallOf(init, userReactiveBinding)) {
  47640. bindingType = isConst ? "setup-reactive-const" : "setup-let";
  47641. } else if (
  47642. // if a declaration is a const literal, we can mark it so that
  47643. // the generated render fn code doesn't need to unref() it
  47644. isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
  47645. ) {
  47646. bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
  47647. } else if (isConst) {
  47648. if (isCallOf(
  47649. init,
  47650. (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
  47651. )) {
  47652. bindingType = "setup-ref";
  47653. } else {
  47654. bindingType = "setup-maybe-ref";
  47655. }
  47656. } else {
  47657. bindingType = "setup-let";
  47658. }
  47659. registerBinding(bindings, id, bindingType);
  47660. } else {
  47661. if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
  47662. continue;
  47663. }
  47664. if (id.type === "ObjectPattern") {
  47665. walkObjectPattern(id, bindings, isConst, isConstMacroCall);
  47666. } else if (id.type === "ArrayPattern") {
  47667. walkArrayPattern(id, bindings, isConst, isConstMacroCall);
  47668. }
  47669. }
  47670. }
  47671. } else if (node.type === "TSEnumDeclaration") {
  47672. isAllLiteral = node.members.every(
  47673. (member) => !member.initializer || isStaticNode(member.initializer)
  47674. );
  47675. bindings[node.id.name] = isAllLiteral ? "literal-const" : "setup-const";
  47676. } else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
  47677. bindings[node.id.name] = "setup-const";
  47678. }
  47679. return isAllLiteral;
  47680. }
  47681. function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
  47682. for (const p of node.properties) {
  47683. if (p.type === "ObjectProperty") {
  47684. if (p.key.type === "Identifier" && p.key === p.value) {
  47685. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47686. registerBinding(bindings, p.key, type);
  47687. } else {
  47688. walkPattern(p.value, bindings, isConst, isDefineCall);
  47689. }
  47690. } else {
  47691. const type = isConst ? "setup-const" : "setup-let";
  47692. registerBinding(bindings, p.argument, type);
  47693. }
  47694. }
  47695. }
  47696. function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
  47697. for (const e of node.elements) {
  47698. e && walkPattern(e, bindings, isConst, isDefineCall);
  47699. }
  47700. }
  47701. function walkPattern(node, bindings, isConst, isDefineCall = false) {
  47702. if (node.type === "Identifier") {
  47703. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47704. registerBinding(bindings, node, type);
  47705. } else if (node.type === "RestElement") {
  47706. const type = isConst ? "setup-const" : "setup-let";
  47707. registerBinding(bindings, node.argument, type);
  47708. } else if (node.type === "ObjectPattern") {
  47709. walkObjectPattern(node, bindings, isConst);
  47710. } else if (node.type === "ArrayPattern") {
  47711. walkArrayPattern(node, bindings, isConst);
  47712. } else if (node.type === "AssignmentPattern") {
  47713. if (node.left.type === "Identifier") {
  47714. const type = isDefineCall ? "setup-const" : isConst ? "setup-maybe-ref" : "setup-let";
  47715. registerBinding(bindings, node.left, type);
  47716. } else {
  47717. walkPattern(node.left, bindings, isConst);
  47718. }
  47719. }
  47720. }
  47721. function canNeverBeRef(node, userReactiveImport) {
  47722. if (isCallOf(node, userReactiveImport)) {
  47723. return true;
  47724. }
  47725. switch (node.type) {
  47726. case "UnaryExpression":
  47727. case "BinaryExpression":
  47728. case "ArrayExpression":
  47729. case "ObjectExpression":
  47730. case "FunctionExpression":
  47731. case "ArrowFunctionExpression":
  47732. case "UpdateExpression":
  47733. case "ClassExpression":
  47734. case "TaggedTemplateExpression":
  47735. return true;
  47736. case "SequenceExpression":
  47737. return canNeverBeRef(
  47738. node.expressions[node.expressions.length - 1],
  47739. userReactiveImport
  47740. );
  47741. default:
  47742. if (isLiteralNode(node)) {
  47743. return true;
  47744. }
  47745. return false;
  47746. }
  47747. }
  47748. function isStaticNode(node) {
  47749. node = unwrapTSNode(node);
  47750. switch (node.type) {
  47751. case "UnaryExpression":
  47752. return isStaticNode(node.argument);
  47753. case "LogicalExpression":
  47754. // 1 > 2
  47755. case "BinaryExpression":
  47756. return isStaticNode(node.left) && isStaticNode(node.right);
  47757. case "ConditionalExpression": {
  47758. return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
  47759. }
  47760. case "SequenceExpression":
  47761. // (1, 2)
  47762. case "TemplateLiteral":
  47763. return node.expressions.every((expr) => isStaticNode(expr));
  47764. case "ParenthesizedExpression":
  47765. return isStaticNode(node.expression);
  47766. case "StringLiteral":
  47767. case "NumericLiteral":
  47768. case "BooleanLiteral":
  47769. case "NullLiteral":
  47770. case "BigIntLiteral":
  47771. return true;
  47772. }
  47773. return false;
  47774. }
  47775. function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
  47776. const generator = new sourceMapExports.SourceMapGenerator();
  47777. const addMapping = (map, lineOffset = 0) => {
  47778. const consumer = new sourceMapExports.SourceMapConsumer(map);
  47779. consumer.sources.forEach((sourceFile) => {
  47780. generator._sources.add(sourceFile);
  47781. const sourceContent = consumer.sourceContentFor(sourceFile);
  47782. if (sourceContent != null) {
  47783. generator.setSourceContent(sourceFile, sourceContent);
  47784. }
  47785. });
  47786. consumer.eachMapping((m) => {
  47787. if (m.originalLine == null) return;
  47788. generator.addMapping({
  47789. generated: {
  47790. line: m.generatedLine + lineOffset,
  47791. column: m.generatedColumn
  47792. },
  47793. original: {
  47794. line: m.originalLine,
  47795. column: m.originalColumn
  47796. },
  47797. source: m.source,
  47798. name: m.name
  47799. });
  47800. });
  47801. };
  47802. addMapping(scriptMap);
  47803. addMapping(templateMap, templateLineOffset);
  47804. generator._sourceRoot = scriptMap.sourceRoot;
  47805. generator._file = scriptMap.file;
  47806. return generator.toJSON();
  47807. }
  47808. var __defProp = Object.defineProperty;
  47809. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  47810. var __hasOwnProp = Object.prototype.hasOwnProperty;
  47811. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  47812. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  47813. var __spreadValues = (a, b) => {
  47814. for (var prop in b || (b = {}))
  47815. if (__hasOwnProp.call(b, prop))
  47816. __defNormalProp(a, prop, b[prop]);
  47817. if (__getOwnPropSymbols)
  47818. for (var prop of __getOwnPropSymbols(b)) {
  47819. if (__propIsEnum.call(b, prop))
  47820. __defNormalProp(a, prop, b[prop]);
  47821. }
  47822. return a;
  47823. };
  47824. const version = "3.5.18";
  47825. const parseCache = parseCache$1;
  47826. const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
  47827. const walk = walk$2;
  47828. const shouldTransformRef = () => false;
  47829. var parse$4 = libExports.parse;
  47830. 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 };